
    hH              
         S SK Jr  S SKJrJr  S SKJr  S SKrS SKrS SK	r	S SK
JrJrJr  \(       a  S SKJr   " S S\R"                  5      r0 S	S
S\R&                  4_SSS\R&                  4_SSS\R&                  4_SSS\R&                  4_SSS\R&                  4_SSS\R(                  4_SSS\R(                  4_SSS\R(                  4_SSS\R(                  4_SSS\R(                  4_SS S!\R(                  4_S"S#S \R(                  4_S$S%S#\R(                  4_S&S'S(\R(                  4_S)SS\R(                  4_S*S+S\R(                  4_r\R&                  S,\R,                  S-\R(                  S.\R.                  S/\R0                  S00r " S1 S2\R"                  5      r " S3 S4\5      r\	R8                   " S5 S65      5       r\	R8                   " S7 S85      5       r " S9 S:5      rSFS; jr          SGS< jr SHS= jr!\RD                  S>4               SIS? jjr#SJS@ jr$SJSA jr%SJSB jr&SJSC jr'SJSD jr(SJSE jr)g)K    )annotations)
NamedTupleTYPE_CHECKING)SelfN)Vec2BoundingBox2dMatrix44)Layoutc                  ,    \ rS rSrSrSrSrSrSrSr	Sr
g	)
Units   zhPage units as enum.

Attributes:
    inch: 25.4 mm
    px: 1/96 inch
    pt: 1/72 inch
    mm:
    cm:

                N)__name__
__module____qualname____firstlineno____doc__inchpxptmmcm__static_attributes__r       M/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/drawing/layout.pyr   r      s"    	 D	
B	
B	
B	
Br   r   zISO A0i  iI  zISO A1iR  zISO A2i  zISO A3i)  zISO A4   zANSI A   g      !@zANSI B   zANSI C   zANSI D"   zANSI E,   zARCH C      zARCH D$   zARCH E0   zARCH E1*      LetterLegal         ?g      $@gffffff9@g?g>>?c                  <    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrg)PageAlignmentB   zPage alignment of content as enum.

Attributes:
    TOP_LEFT:
    TOP_CENTER:
    TOP_RIGHT:
    MIDDLE_LEFT:
    MIDDLE_CENTER:
    MIDDLE_RIGHT:
    BOTTOM_LEFT:
    BOTTOM_CENTER:
    BOTTOM_RIGHT:

r   r   r   r   r            	   r   N)r   r   r   r   r   TOP_LEFT
TOP_CENTER	TOP_RIGHTMIDDLE_LEFTMIDDLE_CENTERMIDDLE_RIGHTBOTTOM_LEFTBOTTOM_CENTERBOTTOM_RIGHTr   r   r   r    r2   r2   B   s6     HJIKMLKMLr   r2   c                  t    \ rS rSr% SrS\S'   S\S'   S\S'   S\S'   \SS j5       r\SS	 j5       rSS
 jr	Sr
g)Margins]   zVPage margins definition class

Attributes:
    top:
    left:
    bottom:
    right:

floattoprightbottomleftc                    U " XX5      $ )z@Returns a page margins definition class with four equal margins.r   )clsmargins     r    allMargins.allm   s     6622r   c                    U " XX5      $ )zVReturns a page margins definition class with equal top-bottom and
left-right margins.
r   )rJ   
top_bottom
left_rights      r    all2Margins.all2r   s    
 ::BBr   c                    U R                  U R                  U-  U R                  U-  U R                  U-  U R                  U-  5      $ N)	__class__rE   rF   rG   rH   )selffactors     r    scaleMargins.scalez   sC    ~~HHvJJKK& II	
 	
r   r   N)rK   rD   returnr   )rO   rD   rP   rD   rZ   r   )rW   rD   rZ   r   )r   r   r   r   r   __annotations__classmethodrL   rQ   rX   r   r   r   r    rB   rB   ]   sJ     
JLM
K3 3 C C
r   rB   c                  t   \ rS rSr% SrS\S'   S\S'   \R                  rS\S'   \	R                  S5      rS	\S
'   SrS\S'   SrS\S'   S r\SS j5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       rS S jrS S jrS!S"S jjr\S#S j5       rSrg)$Page   aN  Page definition class

Attributes:

    width: page width, 0 for auto-detect
    height: page height, 0 for auto-detect
    units: page units as enum :class:`Units`
    margins: page margins in page units
    max_width: limit width for auto-detection, 0 for unlimited
    max_height: limit height for auto-detection, 0 for unlimited

rD   widthheightr   unitsr   rB   margins        	max_width
max_heightc                    [        U R                  [        5      (       d   S5       e[        U R                  [        5      (       d   S5       eg )Nzunits require type <Units>zmargins require type <Margins>)
isinstancerb   r   rc   rB   rV   s    r    __post_init__Page.__post_init__   s<    $**e,,J.JJ,$,,00R2RR0r   c                (    [         U R                     $ rT   )UNITS_TO_MMrb   ri   s    r    to_mm_factorPage.to_mm_factor   s    4::&&r   c                H    [        U R                  U R                  -  S5      $ )zReturns the page width in mm.r   )roundr`   rn   ri   s    r    width_in_mmPage.width_in_mm   s      TZZ$"3"33Q77r   c                H    [        U R                  U R                  -  S5      $ )zReturns max page width in mm.r   )rq   re   rn   ri   s    r    max_width_in_mmPage.max_width_in_mm   s      T^^d&7&77;;r   c                H    [        U R                  U R                  -  S5      $ )zReturns the page height in mm.r   )rq   ra   rn   ri   s    r    height_in_mmPage.height_in_mm   s      T[[4#4#44a88r   c                H    [        U R                  U R                  -  S5      $ )zReturns max page height in mm.r   )rq   rf   rn   ri   s    r    max_height_in_mmPage.max_height_in_mm   s      T__t'8'88!<<r   c                L    U R                   R                  U R                  5      $ )zReturns the page margins in mm.)rc   rX   rn   ri   s    r    margins_in_mmPage.margins_in_mm   s     ||!!$"3"344r   c                4    U R                   U R                  :  $ )z7Returns ``True`` if the page has landscape orientation.r`   ra   ri   s    r    is_landscapePage.is_landscape   s     zzDKK''r   c                4    U R                   U R                  :*  $ )zKReturns ``True`` if the page has portrait orientation. (square is portrait)r   ri   s    r    is_portraitPage.is_portrait   s     zzT[[((r   c                n    U R                   (       a$  U R                  U R                  sU l        U l        gg)z+Converts the page to landscape orientation.N)r   ra   r`   ri   s    r    to_landscapePage.to_landscape   s(    &*kk4::#DJ r   c                n    U R                   (       a$  U R                  U R                  sU l        U l        gg)z*Converts the page to portrait orientation.N)r   ra   r`   ri   s    r    to_portraitPage.to_portrait   s(    &*kk4::#DJ r   c                ^   U R                   nU R                  UR                  -
  nU R                  nU(       a;  [	        UR
                  UR                  5      n[	        X4UR                  -
  5      nXV4$ [	        UR
                  UR                  5      n[	        X4UR                  -
  5      nXV4$ )zReturns the bottom-left and the top-right corner of the page margins in mm.
The origin (0, 0) is the top-left corner of the page if `top_origin` is
``True`` or in the bottom-left corner otherwise.
)r~   rr   rF   rx   r   rH   rE   rG   )rV   
top_originrc   right_marginpage_heightbottom_left	top_rights          r    get_margin_rectPage.get_margin_rect   s    
 $$'''--7''w||W[[9K\+GHI %% w||W^^<K\+DEI%%r   c                   [        UR                  R                  S5      n[        UR                  R                  S5      n[        UR                  R                  S5      n[        UR                  R
                  S5      n[        UR                  R                  S5      n[        UR                  R                  S5      nUR                  R                  nUS:X  a  U " UU[        R                  [        XVXtS9S9$ US:X  a  U " UU[        R                  [        XgXES9S9$ US:X  a  U " UU[        R                  [        XtXVS9S9$ U " UU[        R                  [        XEXgS9S9$ )zReturns the :class:`Page` based on the DXF attributes stored in the LAYOUT 
entity. The modelspace layout often **doesn't** have usable page settings!

Args:
    layout: any paperspace layout or the modelspace layout

r   )rE   rF   rG   rH   )rc   r   r   )rq   dxfpaper_widthpaper_height
top_marginr   bottom_marginleft_marginplot_rotationr   r   rB   )	rJ   layoutr`   ra   rE   rF   rG   rH   rotations	            r    from_dxf_layoutPage.from_dxf_layout   sB    fjj,,a0vzz..2FJJ))1-fjj--q1vzz//3VZZ++Q/::++q=EO	  ]FsO	  ]DEO	  HHK	
 	
r   )ra   r`   N)rZ   rD   )rZ   rB   )rZ   boolrZ   None)T)rZ   ztuple[Vec2, Vec2])r   	DXFLayoutrZ   r   )r   r   r   r   r   r[   r   r   rb   rB   rL   rc   re   rf   rj   propertyrn   rr   ru   rx   r{   r~   r   r   r   r   r   r\   r   r   r   r   r    r^   r^      s    LM88E5{{1~GW%IuJS ' ' 8 8 < < 9 9 = = 5 5 ( ( ) )>
>
&  +
 +
r   r^   c                      \ rS rSr% SrSrS\S'   SrS\S'   S	rS
\S'   \	R                  rS\S'   SrS\S'   SrS
\S'   SrS
\S'   SrS
\S'   SrS
\S'   SrS\S'   SS jrSS jrSrg)Settingsi  a\  The Layout settings.

Attributes:
    content_rotation: Rotate content about 0, 90,  180 or 270 degrees
    fit_page: Scale content to fit the page.
    page_alignment: Supported by backends that use the :class:`Page` class to define
        the size of the output media, default alignment is :attr:`PageAlignment.MIDDLE_CENTER`
    crop_at_margins: crops the content at the page margins if ``True``, when
        supported by the backend, default is ``False``
    scale: Factor to scale the DXF units of model- or paperspace, to represent 1mm
        in the rendered output drawing. Only uniform scaling is supported.

        e.g. scale 1:100 and DXF units are meters, 1m = 1000mm corresponds 10mm in
        the output drawing = 10 / 1000 = 0.01;

        e.g. scale 1:1; DXF units are mm = 1 / 1 = 1.0 the default value

        The value is ignored if the page size is defined and the content fits the page and
        the value is also used to determine missing page sizes (width or height).
    max_stroke_width: Used for :class:`LineweightPolicy.RELATIVE` policy,
        :attr:`max_stroke_width` is defined as percentage of the content extents,
        e.g. 0.001 is 0.1% of max(page-width, page-height)
    min_stroke_width: Used for :class:`LineweightPolicy.RELATIVE` policy,
        :attr:`min_stroke_width` is defined as percentage of :attr:`max_stroke_width`,
        e.g. 0.05 is 5% of :attr:`max_stroke_width`
    fixed_stroke_width: Used for :class:`LineweightPolicy.RELATIVE_FIXED` policy,
        :attr:`fixed_stroke_width` is defined as percentage of :attr:`max_stroke_width`,
        e.g. 0.15 is 15% of :attr:`max_stroke_width`
    output_coordinate_space: expert feature to map the DXF coordinates to the
        output coordinate system [0, output_coordinate_space]
    output_layers: For supported backends, separate the entities into 'layers' in the output

r   intcontent_rotationTr   fit_pager0   rD   rX   r2   page_alignmentFcrop_at_marginsgMbP?max_stroke_widthg?min_stroke_widthg333333?fixed_stroke_widthi@B output_coordinate_spaceoutput_layersc                V    U R                   S;  a  [        SU R                    S35      eg )Nr   Z        zinvalid content rotation z, expected: 0, 90, 180, 270)r   
ValueErrorri   s    r    rj   Settings.__post_init__G  s<      (99+D,A,A+B C, -  :r   c                ~     U R                   [        UR                  UR                  5      -  $ ! [         a     gf = f)zVReturns the scaling factor to map page coordinates in mm to output space
coordinates.
r0   )r   maxrr   rx   ZeroDivisionError)rV   pages     r    page_output_scale_factor!Settings.page_output_scale_factorN  sF    	//#  $"3"33   ! 		s   ,/ 
<<r   Nr   )r   r^   rZ   rD   )r   r   r   r   r   r   r[   r   rX   r2   r<   r   r   r   r   r   r   r   rj   r   r   r   r   r    r   r     s     D cHdE5$1$?$?NM?!OT! $e#"e" !%$ &/U.M4	r   r   c                  p   ^  \ rS rSrS	S
U 4S jjjrSS jrSS jrSS jr\" 5       S4   SS jjr	Sr
U =r$ )r
   iZ  c                N   > [         TU ]  5         U(       a  SOSU l        Xl        g )N      r0   )super__init__flip_y
render_box)rV   r   r   rU   s      r    r   Layout.__init__[  s    %+T$r   c                    UR                   S;  a  [        S5      eUR                   nU R                  S:X  a  US:X  a  SnU$ US:X  a  SnU$ )Nr   z2content rotation must be 0, 90, 180 or 270 degreesr   r   r   )r   r   r   )rV   settingsr   s      r    get_rotationLayout.get_rotation`  sZ    $$,==QRR,,;;$2~  Sr   c                ~    U R                   R                  nUS;   a   [        UR                  UR                  5      nU$ )N)r   r   )r   sizer   yx)rV   r   content_sizes      r    get_content_sizeLayout.get_content_sizek  s3    ++y ?Lr   c                ^    U R                  U5      nU R                  U5      n[        XAU5      $ rT   )r   r   final_page_size)rV   r   r   r   r   s        r    get_final_pageLayout.get_final_pager  s/    $$X.,,X6|8<<r   Tc                   U R                  U5      nU R                  U5      nXRR                  -  nUR                  (       a  U[	        Xa5      -  n UR
                  UR
                  -  nUR                  U5      nXx-  n	[        U R                  U	XR                  -  UUUR                  UR                  US9n
U
$ ! [         a    Sn N_f = f)Nr0   )sxsyr   r   r   r   r   )r   r   rX   r   fit_to_pager   r   r   placement_matrixr   r   r   r   )rV   r   r   r   r   r   content_size_mmscale_dxf_to_mmscale_mm_to_output_spacerX   ms              r    get_placement_matrixLayout.get_placement_matrixw  s     $$X.,,X6&7{?AAO	"-//,..@O $,#D#DT#J :OO{{"$,$D$D#22!	
  ! 	"!O	"s   B; ;C
	C
)r   r   )F)r   r   rZ   r   )r   r   rZ   r   )r   r   rZ   r   )r   r^   r   r   rZ   r^   )r   r^   rZ   r	   )r   r   r   r   r   r   r   r   r   r   r   __classcell__)rU   s   @r    r
   r
   Z  s?    % %
	= $,:$	 r   r
   c                   UR                   nUR                  nUR                  nUR                  nUS:X  a(  X0R                  -  UR
                  -   UR                  -   nUS:X  a(  X0R                  -  UR                  -   UR                  -   n[        XEUR                  UR                  5      u  pE[        [        US5      [        US5      [        R                   U5      $ )Nrd   r   )rX   rr   rx   r~   r   rH   rF   r   rE   rG   limit_page_sizeru   r{   r^   rq   r   r   )r   r   r   rX   r`   ra   rc   s          r    r   r     s    NNEEF  G|&5E}''++5F#t++T-B-BME eQvq!1588WEEr   c                     X-  nU(       a  [        X15      nX-  n U(       a  X:  a  [        X 5      n X-  nX4$ ! [          a    X4s $ f = frT   )r   min)r`   ra   re   rf   ars        r    r   r     s^    ^ Z(U&I%=  }s   : A
	A
c                   UR                   n UR                  UR                  -
  UR                  -
  U R                  -  nUR
                  UR                  -
  UR                  -
  U R                  -  n[        X45      $ ! [         a     gf = f)Nr0   )r~   rr   rH   rF   r   rx   rE   rG   r   r   r   )r   r   rc   r   r   s        r    r   r     s      G-=ARARR'++->/BSBSS r;  s   A&A? ?
BBTc                h    U[        UR                  UR                  5      -  nUR                  n	[        U5      S:  a  Sn[        U5      S:  a  Sn[        R                  " XS5      n
U(       a-  U
[        R                  " [        R                  " U5      5      -  n
U
R                  U R                  5       5      n[        U5      nUR                  u  pUR                  U	R                  -
  U	R                   -
  U-  nUR                  U	R"                  -
  U	R$                  -
  U-  nXR&                  R(                  -
  nUUR&                  R*                  -
  nU	R                  U-  nU(       a  U	R"                  U-  nOU	R$                  U-  n[-        U5      (       a	  UUS-  -  nO[/        U5      (       a  UU-  n[1        U5      (       a	  UUS-  -  nO)[3        U5      (       a  U(       a  UU-  nOU(       d  UU-  nU
[        R4                  " U* U-   U* U-   S5      -  $ ! [         a    Sn GNf = f)z\Returns a matrix to place the bbox in the first quadrant of the coordinate
system (+x, +y).
r0   g&.>r   r   )r   rr   rx   r   r~   absr	   rX   z_rotatemathradianstransform_verticesrect_verticesr   extminrH   rF   rE   rG   r   r   r   is_center_alignedis_right_alignedis_middle_alignedis_bottom_aligned	translate)bboxr   r   r   r   r   r   r   scale_mm_to_vbrc   r   cornerscanvastxtyview_box_content_xview_box_content_ydxdyoffset_xoffset_ys                        r    r   r     s   03d//4
 

   G 2w~
2w~rs#A	Xt||H566 ""4#5#5#78G7#F ]]FB 	7<<''--7 	GKK''..8 
kkmm	+B	fkkmm	+B||n,H;;/>>N2((BF	.	)	)B((BF	>	*	*NHNHx!!2#.2#.!DDD_  s   #H! !H10H1c                f    U [         R                  [         R                  [         R                  4;   $ rT   )r2   r8   r;   r>   aligns    r    is_left_alignedr    s/    !!!!  r   c                f    U [         R                  [         R                  [         R                  4;   $ rT   )r2   r9   r<   r?   r  s    r    r   r     s/      ####  r   c                f    U [         R                  [         R                  [         R                  4;   $ rT   )r2   r:   r=   r@   r  s    r    r   r     s/    """"  r   c                f    U [         R                  [         R                  [         R                  4;   $ rT   )r2   r8   r9   r:   r  s    r    is_top_alignedr    s/        r   c                f    U [         R                  [         R                  [         R                  4;   $ rT   )r2   r;   r<   r=   r  s    r    r   r   $  /    !!##""  r   c                f    U [         R                  [         R                  [         R                  4;   $ rT   )r2   r>   r?   r@   r  s    r    r   r   ,  r
  r   )r   r   r   r^   r   r   rZ   r^   )
r`   rD   ra   rD   re   rD   rf   rD   rZ   ztuple[float, float])r   r   r   r^   rZ   rD   )r   r   r   rD   r   rD   r   rD   r   r^   r   rD   r   r2   rZ   r	   )r  r2   rZ   r   )*
__future__r   typingr   r   typing_extensionsr   r   enumdataclasses
ezdxf.mathr   r   r	   ezdxf.layouts.layoutr
   r   IntEnumr   r   r   
PAGE_SIZESr   r   r   rm   r2   rB   	dataclassr^   r   r   r   r   r<   r   r  r   r   r  r   r   r   r   r    <module>r     s   # , "    4 48DLL *tS%((#sC" sC" sC"	
 sC" r3

# r2uzz" r2uzz" r2uzz" r2uzz" r2uzz" r2uzz" r2uzz" B

# r3

#  b#uzz"!
* 
HHc	HHd	JJ	HHk	HHkDLL 6#
j #
L F
 F
 F
R I I IX8 8vF ,1?D " %2$?$? BE
BEBE 	BE 	BE
 BE #BE "BE BEJr   