
    h                    N   S SK Jr  S SKJrJr  S SKrS SKrS SKJrJ	r	  S SK
Jr  S SKJrJr  SSKJr  \(       a  S S	KJr  \R&                  \R(                  \R*                  1r\R.                  \R0                  \R2                  1r " S
 S\R6                  5      r " S S\5      rg)    )annotations)TYPE_CHECKINGAnyN)MTextEntityAlignmentMAP_MTEXT_ALIGN_TO_FLAGS)const)UVecVec3   )SubscriptAttributes)GenericLayoutTypec                       \ rS rSrSrSrSrSrg)Mirror    r          N)__name__
__module____qualname____firstlineno__NONEMIRROR_XMIRROR_Y__static_attributes__r       M/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/mtextsurrogate.pyr   r       s    DHHr   r   c            
         \ rS rSrSr\R                  r\R                  r\R                  r	S\
R                  SSSSS\R                  S\R                  4
               SS jjr\SS	 j5       rSS
 jrSS jrSS jrSS jrSrg)MTextSurrogate&   a  MTEXT surrogate for DXF R12 build up by TEXT Entities. This add-on was
added to simplify the transition from :mod:`dxfwrite` to :mod:`ezdxf`.

The rich-text formatting capabilities for the regular MTEXT entity are not
supported, if these features are required use the regular MTEXT entity and
the :class:`~ezdxf.addons.MTextExplode` add-on to explode the MTEXT entity
into DXF primitives.

.. important::

    The align-point is always the insert-point, there is no need for
    a second align-point because the horizontal alignments FIT, ALIGN,
    BASELINE_MIDDLE are not supported.

Args:
    text: content as string
    insert: insert location in drawing units
    line_spacing: line spacing in percent of height, 1.5 = 150% = 1+1/2 lines
    align: text alignment as :class:`~ezdxf.enums.MTextEntityAlignment` enum
    char_height: text height in drawing units
    style: :class:`~ezdxf.entities.Textstyle` name as string
    oblique: oblique angle in degrees, where 0 is vertical
    rotation: text rotation angle in degrees
    width_factor: text width factor as float
    mirror: :attr:`MTextSurrogate.MIRROR_X` to mirror the text horizontal
        or :attr:`MTextSurrogate.MIRROR_Y` to mirror the text vertical
    layer: layer name as string
    color: :ref:`ACI`

g      ?g      ?STANDARD        0c                   UR                  S5      U l        [        U5      U l        [	        U5      U l        [        U[        5      (       d   eX@l        [	        U5      U l	        [        U5      U l        [	        U5      U l        [	        U5      U l        [	        U	5      U l        [        U
5      U l        [        U5      U l        [        U5      U l        g )N
)splitcontentr
   insertfloatline_spacing
isinstancer   alignchar_heightstrstyleobliquerotationwidth_factorintmirrorlayercolor)selftextr(   r*   r,   r-   r/   r0   r1   r2   r4   r5   r6   s                r   __init__MTextSurrogate.__init__J   s     #'**T"26l!,/%!56666
 -Z
W~h!,/&kZ
Z
r   c                4    U R                   U R                  -  $ )z'Absolute line spacing in drawing units.)r-   r*   )r7   s    r   line_heightMTextSurrogate.line_heighth   s     $"3"333r   c                   U R                   n[        U5      S:  aw  U R                  [        R                  -  (       a  UR                  5         [        U5       H5  u  p4U R                  U5      nUR                  UU R                  U5      S9  M7     g[        U5      S:X  a-  UR                  US   U R                  U R                  5      S9  gg)z[Render the multi-line content as separated TEXT entities into the
given `layout` instance.
r   )
dxfattribsr   N)r'   lenr4   r   r   reverse	enumerate_get_align_pointadd_text_dxfattribsr(   )r7   layout
text_linesline_numberr8   align_points         r   renderMTextSurrogate.renderm   s     \\
z?Q{{U^^+""$%.z%:!"33K@#//<    &; _!OO1++DKK8   "r   c                (   U R                   R                  nU R                   R                  n U R                   R                  nU R
                  [        ;   a  X1U R                  -  -  nO}U R
                  [        ;   a>  XR                  -  n[        U R                  5      S-
  U R                  -  nX6S-  U-
  -  nO+U[        U R                  5      S-
  U-
  U R                  -  -  nU R                  [        X#U5      5      $ ! [         a    Sn Nf = f)z7Calculate the align-point depending on the line number.r"   r   r   )r(   xyz
IndexErrorr,   	TOP_ALIGNr<   MIDDLE_ALIGNr@   r'   _rotater
   )r7   rH   rM   rN   rO   y0full_heights          r   rC   MTextSurrogate._get_align_point   s    KKMMKKMM	A
 ::"t////AZZ<'///Bt||,q0D4D4DDK/R''A#dll#a'+59I9IIIA||DqM**  	A	s   D DDc                L   UR                   U R                  R                   -
  nUR                  U R                  R                  -
  n[        R                  " U R
                  5      nU R                  R                   U[        R                  " U5      -  -   U[        R                  " U5      -  -
  nU R                  R                  U[        R                  " U5      -  -   U[        R                  " U5      -  -   n[        [        US5      [        US5      UR                  5      $ )z?Rotate `alignpoint` around insert-point about rotation degrees.   )rM   r(   rN   mathradiansr1   cossinr
   roundrO   )r7   
alignpointdxdybetarM   rN   s          r   rS   MTextSurrogate._rotate   s    \\DKKMM)\\DKKMM)||DMM*KKMMB$//"txx~2EEKKMMB$//"txx~2EEE!QKq!jll;;r   c                    [         U R                     u  p#UUU R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  UUS.$ )z1Build keyword arguments for TEXT entity creation.)r(   rI   r5   r6   r/   heightwidthtext_generation_flagr1   r0   halignvalign)
r   r,   r5   r6   r/   r-   r2   r4   r1   r0   )r7   rI   rg   rh   s       r   rE   MTextSurrogate._dxfattribs   sd    1$**=!&ZZZZZZ&&&&$(KK||
 	
r   )r,   r-   r6   r'   r(   r5   r*   r4   r0   r1   r/   r2   N)r8   r.   r(   r	   r*   r)   r-   r)   r0   r)   r1   r)   r2   r)   r6   r3   )returnr)   )rF   r   rj   None)rH   r3   rj   r
   )r^   r
   rj   r
   )rI   r
   rj   zdict[str, Any])r   r   r   r   __doc__r   r   MIRROR_NONEr   r   r   TOP_LEFTr   BYLAYERr9   propertyr<   rJ   rC   rS   rE   r   r   r   r   r   r   &   s    > ++KHH ""++ !{{]]     	           < 4 4(+(<
r   r   )
__future__r   typingr   r   rY   enumezdxf.enumsr   r   ezdxf.lldxfr   
ezdxf.mathr	   r
   mixinsr   ezdxf.eztypesr   rn   	TOP_RIGHT
TOP_CENTERrQ   MIDDLE_LEFTMIDDLE_CENTERMIDDLE_RIGHTrR   IntEnumr   r   r   r   r   <module>r      s    # %    ! '/ !!""##	 $$&&%%T\\ H
( H
r   