
    OgH              
      f   d dl mZ d dlmZmZ d dlmZ d dlZd dlZd dl	Z	d dl
mZmZmZ erd dlmZ  G d dej"                        Zi d	d
dej&                  fdddej&                  fdddej&                  fdddej&                  fdddej&                  fdddej(                  fdddej(                  fdddej(                  fdddej(                  fdddej(                  fdd d!ej(                  fd"d#d ej(                  fd$d%d#ej(                  fd&d'd(ej(                  fd)ddej(                  fd*d+dej(                  fZej&                  d,ej,                  d-ej(                  d.ej.                  d/ej0                  d0iZ G d1 d2ej"                        Z G d3 d4e      Ze	j8                   G d5 d6             Ze	j8                   G d7 d8             Z G d9 d:      ZdFd;Z	 	 	 	 	 	 	 	 	 	 dGd<Z dHd=Z!ejD                  d>f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dId?Z#dJd@Z$dJdAZ%dJdBZ&dJdCZ'dJdDZ(dJdEZ)y)K    )annotations)
NamedTupleTYPE_CHECKING)SelfN)Vec2BoundingBox2dMatrix44)Layoutc                  $    e Zd ZdZdZdZdZdZdZy)UnitszPage units as enum.

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

                   N)	__name__
__module____qualname____doc__inchpxptmmcm     `/var/www/html/public_html/myphp/venv/lib/python3.12/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                  4    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
Zy)PageAlignmentzPage 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            	   N)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/   r/   B   s6     HJIKMLKMLr   r/   c                  f    e Zd ZU dZded<   ded<   ded<   ded<   edd       Zedd       Zdd	Zy
)MarginsznPage margins definition class

    Attributes:
        top:
        left:
        bottom:
        right:

    floattoprightbottomleftc                     | ||||      S )z@Returns a page margins definition class with four equal margins.r   )clsmargins     r   allzMargins.allm   s     666622r   c                     | ||||      S )zfReturns a page margins definition class with equal top-bottom and
        left-right margins.
        r   )rE   
top_bottom
left_rights      r   all2zMargins.all2r   s    
 :z:zBBr   c                    | j                  | j                  |z  | j                  |z  | j                  |z  | j                  |z        S N)	__class__r@   rA   rB   rC   )selffactors     r   scalezMargins.scalez   sC    ~~HHvJJKK& II	
 	
r   N)rF   r?   returnr   )rI   r?   rJ   r?   rR   r   )rP   r?   rR   r   )	r   r   r   r   __annotations__classmethodrG   rK   rQ   r   r   r   r>   r>   ]   sJ     
JLM
K3 3 C C
r   r>   c                  R   e Zd ZU dZded<   ded<   ej                  Zded<   ej                  d      Z
ded	<   d
Zded<   d
Zded<   d Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       ZddZddZdd dZed!d       Zy)"Pagean  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

    r?   widthheightr   unitsr   r>   margins        	max_width
max_heightc                    t        | j                  t              sJ d       t        | j                  t              sJ d       y )Nzunits require type <Units>zmargins require type <Margins>)
isinstancerY   r   rZ   r>   rO   s    r   __post_init__zPage.__post_init__   s6    $**e,J.JJ,$,,0R2RR0r   c                (    t         | j                     S rM   )UNITS_TO_MMrY   r`   s    r   to_mm_factorzPage.to_mm_factor   s    4::&&r   c                H    t        | j                  | j                  z  d      S )zReturns the page width in mm.r   )roundrW   rd   r`   s    r   width_in_mmzPage.width_in_mm   s      TZZ$"3"33Q77r   c                H    t        | j                  | j                  z  d      S )zReturns max page width in mm.r   )rf   r\   rd   r`   s    r   max_width_in_mmzPage.max_width_in_mm   s      T^^d&7&77;;r   c                H    t        | j                  | j                  z  d      S )zReturns the page height in mm.r   )rf   rX   rd   r`   s    r   height_in_mmzPage.height_in_mm   s      T[[4#4#44a88r   c                H    t        | j                  | j                  z  d      S )zReturns max page height in mm.r   )rf   r]   rd   r`   s    r   max_height_in_mmzPage.max_height_in_mm   s      T__t'8'88!<<r   c                L    | j                   j                  | j                        S )zReturns the page margins in mm.)rZ   rQ   rd   r`   s    r   margins_in_mmzPage.margins_in_mm   s     ||!!$"3"344r   c                4    | j                   | j                  kD  S )z7Returns ``True`` if the page has landscape orientation.rW   rX   r`   s    r   is_landscapezPage.is_landscape   s     zzDKK''r   c                4    | j                   | j                  k  S )zKReturns ``True`` if the page has portrait orientation. (square is portrait)rq   r`   s    r   is_portraitzPage.is_portrait   s     zzT[[((r   c                d    | j                   r$| j                  | j                  c| _        | _        yy)z+Converts the page to landscape orientation.N)rt   rX   rW   r`   s    r   to_landscapezPage.to_landscape   s(    &*kk4::#DJ r   c                d    | j                   r$| j                  | j                  c| _        | _        yy)z*Converts the page to portrait orientation.N)rr   rX   rW   r`   s    r   to_portraitzPage.to_portrait   s(    &*kk4::#DJ r   c                \   | j                   }| j                  |j                  z
  }| j                  }|r=t	        |j
                  |j                        }t	        |||j                  z
        }||fS t	        |j
                  |j                        }t	        |||j                  z
        }||fS )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.
        )ro   rg   rA   rk   r   rC   r@   rB   )rO   
top_originrZ   right_marginpage_heightbottom_left	top_rights          r   get_margin_rectzPage.get_margin_rect   s    
 $$'''--7''w||W[[9K\;+GHI I%% w||W^^<K\;+DEII%%r   c                   t        |j                  j                  d      }t        |j                  j                  d      }t        |j                  j                  d      }t        |j                  j
                  d      }t        |j                  j                  d      }t        |j                  j                  d      }|j                  j                  }|dk(  r' | ||t        j                  t        ||||            S |dk(  r' | ||t        j                  t        ||||            S |dk(  r' | ||t        j                  t        ||||            S  | ||t        j                  t        ||||            S )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   )r@   rA   rB   rC   )rZ   r   r   )rf   dxfpaper_widthpaper_height
top_marginr{   bottom_marginleft_marginplot_rotationr   r   r>   )	rE   layoutrW   rX   r@   rA   rB   rC   rotations	            r   from_dxf_layoutzPage.from_dxf_layout   sR    fjj,,a0vzz..2FJJ))1-fjj--q1vzz//3VZZ++Q/::++q=E3O	  ]F$sO	  ]DEO	  HH5dK	
 	
r   N)rR   r?   )rR   r>   )rR   boolrR   None)T)rR   ztuple[Vec2, Vec2])r   	DXFLayoutrR   r   )r   r   r   r   rS   r   r   rY   r>   rG   rZ   r\   r]   ra   propertyrd   rg   ri   rk   rm   ro   rr   rt   rv   rx   r   rT   r   r   r   r   rV   rV      s    LM88E5{{1~GW%IuJS ' ' 8 8 < < 9 9 = = 5 5 ( ( ) )>
>
&  +
 +
r   rV   c                      e Zd ZU dZdZded<   dZded<   dZd	ed
<   ej                  Z
ded<   dZded<   dZd	ed<   dZd	ed<   dZd	ed<   dZd	ed<   dZded<   ddZddZy)Settingsa  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_pager-   r?   rQ   r/   page_alignmentFcrop_at_marginsgMbP?max_stroke_widthg?min_stroke_widthg333333?fixed_stroke_widthi@B output_coordinate_spaceoutput_layersc                R    | j                   dvrt        d| j                    d      y )Nr   Z        zinvalid content rotation z, expected: 0, 90, 180, 270)r   
ValueErrorr`   s    r   ra   zSettings.__post_init__G  s<      (99+D,A,A+B C, -  :r   c                |    	 | j                   t        |j                  |j                        z  S # t        $ r Y yw xY w)zfReturns the scaling factor to map page coordinates in mm to output space
        coordinates.
        r-   )r   maxrg   rk   ZeroDivisionError)rO   pages     r   page_output_scale_factorz!Settings.page_output_scale_factorN  sF    	//#  $"3"33   ! 		s   ,/ 	;;Nr   )r   rV   rR   r?   )r   r   r   r   r   rS   r   rQ   r/   r8   r   r   r   r   r   r   r   ra   r   r   r   r   r   r     s     D cHdE5$1$?$?NM?!OT! $e#"e" !%$ &/U.M4	r   r   c                  X     e Zd Zdd fdZd	dZd
dZddZ e       df	 	 	 ddZ xZ	S )r
   c                F    t         |           |rdnd| _        || _        y )N      r-   )super__init__flip_y
render_box)rO   r   r   rN   s      r   r   zLayout.__init__[  s     %+T$r   c                    |j                   dvrt        d      |j                   }| j                  dk(  r|dk(  rd}|S |dk(  rd}|S )Nr   z2content rotation must be 0, 90, 180 or 270 degreesr   r   r   )r   r   r   )rO   settingsr   s      r   get_rotationzLayout.get_rotation`  sZ    $$,==QRR,,;;$2~  Sr   c                z    | j                   j                  }|dv r t        |j                  |j                        }|S )N)r   r   )r   sizer   yx)rO   r   content_sizes      r   get_content_sizezLayout.get_content_sizek  s3    ++y ?Lr   c                `    | j                  |      }| j                  |      }t        |||      S rM   )r   r   final_page_size)rO   r   r   r   r   s        r   get_final_pagezLayout.get_final_pager  s1    $$X.,,X6|T8<<r   Tc           
        | j                  |      }| j                  |      }||j                  z  }|j                  r|t	        ||      z  }	 |j
                  |j
                  z  }|j                  |      }||z  }	t        | j                  |	|	| j                  z  |||j                  |j                  |      }
|
S # t        $ r d}Y cw xY w)Nr-   )sxsyr   r   r   r   rz   )r   r   rQ   r   fit_to_pager   r   r   placement_matrixr   r   r   r   )rO   r   r   rz   r   r   content_size_mmscale_dxf_to_mmscale_mm_to_output_spacerQ   ms              r   get_placement_matrixzLayout.get_placement_matrixw  s     $$X.,,X6&7{?DAAO	"-//,..@O $,#D#DT#J "::OOt{{"$,$D$D#22!	
  ! 	"!O	"s   B= =C
C)F)r   r   rR   r   )r   r   rR   r   )r   r   rR   r   )r   rV   r   r   rR   rV   )r   rV   rR   r	   )
r   r   r   r   r   r   r   r   r   __classcell__)rN   s   @r   r
   r
   Z  s5    %
	= $,:$	r   r
   c                   |j                   }|j                  }|j                  }|j                  }|dk(  r)|| j                  z  |j
                  z   |j                  z   }|dk(  r)|| j                  z  |j                  z   |j                  z   }t        |||j                  |j                        \  }}t        t        |d      t        |d      t        j                   |      S )Nr[   r   )rQ   rg   rk   ro   r   rC   rA   r   r@   rB   limit_page_sizeri   rm   rV   rf   r   r   )r   r   r   rQ   rW   rX   rZ   s          r   r   r     s    NNEEF  G|&5E}''++5F#vt++T-B-BME6 eQvq!1588WEEr   c                    	 | |z  }|rt        ||      }||z  } |r| |kD  rt        ||       } | |z  }| |fS # t         $ r | |fcY S w xY wrM   )r   min)rW   rX   r\   r]   ars        r   r   r     sn    V^ Z(UY&Iu%&=  f}s   6 AAc                   |j                   }	 |j                  |j                  z
  |j                  z
  | j                  z  }|j
                  |j                  z
  |j                  z
  | j                  z  }t        ||      S # t        $ r Y yw xY w)Nr-   )ro   rg   rC   rA   r   rk   r@   rB   r   r   r   )r   r   rZ   r   r   s        r   r   r     s      G-=ARARR'++->/BSBSS r2;  s   A&B   	BBTc                   	 |t        |j                  |j                        z  }|j                  }	t        |      dk  rd}t        |      dk  rd}t        j                  ||d      }
|r+|
t        j                  t        j                  |            z  }
|
j                  | j                               }t        |      }|j                  \  }}|j                  |	j                  z
  |	j                   z
  |z  }|j                  |	j"                  z
  |	j$                  z
  |z  }||j&                  j(                  z
  }||j&                  j*                  z
  }|	j                  |z  }|r|	j"                  |z  }n|	j$                  |z  }t-        |      r	||dz  z  }nt/        |      r||z  }t1        |      r	||dz  z  }nt3        |      r|r||z  }n|s||z  }|
t        j4                  | |z   | |z   d      z  S # t        $ r d}Y w xY w)zdReturns a matrix to place the bbox in the first quadrant of the coordinate
    system (+x, +y).
    r-   g&.>r   r   )r   rg   rk   r   ro   absr	   rQ   z_rotatemathradianstransform_verticesrect_verticesr   extminrC   rA   r@   rB   r   r   r   is_center_alignedis_right_alignedis_middle_alignedis_bottom_aligned	translate)bboxr   r   r   r   r   r   rz   scale_mm_to_vbrZ   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~r2s#A	Xt||H566 ""4#5#5#78G7#F ]]FB 	7<<''--7 	GKK''..8 
fkkmm	+B	fkkmm	+B||n,H;;/>>N2(BF	.	)B(BF	>	*NHNHx!!2#.2#.!DDD_  s   #G6 6HHc                d    | t         j                  t         j                  t         j                  fv S rM   )r/   r4   r7   r:   aligns    r   is_left_alignedr     s/    !!!!  r   c                d    | t         j                  t         j                  t         j                  fv S rM   )r/   r5   r8   r;   r   s    r   r   r     s/      ####  r   c                d    | t         j                  t         j                  t         j                  fv S rM   )r/   r6   r9   r<   r   s    r   r   r     s/    """"  r   c                d    | t         j                  t         j                  t         j                  fv S rM   )r/   r4   r5   r6   r   s    r   is_top_alignedr     s/        r   c                d    | t         j                  t         j                  t         j                  fv S rM   )r/   r7   r8   r9   r   s    r   r   r   $  /    !!##""  r   c                d    | t         j                  t         j                  t         j                  fv S rM   )r/   r:   r;   r<   r   s    r   r   r   ,  r   r   )r   r   r   rV   r   r   rR   rV   )
rW   r?   rX   r?   r\   r?   r]   r?   rR   ztuple[float, float])r   r   r   rV   rR   r?   )r   r   r   r?   r   r?   r   r?   r   rV   r   r?   r   r/   rR   r	   )r   r/   rR   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   rc   r/   r>   	dataclassrV   r   r   r   r   r8   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   