
    Og                    D   d dl mZ d dlmZmZ d dlZd dlZd dlmZm	Z	 d dl
mZ d dlmZmZ ddlmZ erd d	lmZ ej&                  ej(                  ej*                  hZej.                  ej0                  ej2                  hZ G d
 dej6                        Z G d de      Zy)    )annotations)TYPE_CHECKINGAnyN)MTextEntityAlignmentMAP_MTEXT_ALIGN_TO_FLAGS)const)UVecVec3   )SubscriptAttributes)GenericLayoutTypec                      e Zd ZdZdZdZy)Mirrorr         N)__name__
__module____qualname__NONEMIRROR_XMIRROR_Y     `/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/addons/mtextsurrogate.pyr   r       s    DHHr   r   c            
         e Zd ZdZej
                  Zej                  Zej                  Zde	j                  dddddej
                  dej                  f
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZedd       Zdd	Zdd
ZddZddZy)MTextSurrogatea\  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                   |j                  d      | _        t        |      | _        t	        |      | _        t        |t              sJ || _        t	        |      | _	        t        |      | _        t	        |      | _        t	        |      | _        t	        |	      | _        t        |
      | _        t        |      | _        t        |      | _        y )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+   r,   r-   r.   r0   r1   r2   s                r   __init__zMTextSurrogate.__init__J   s     #'**T"26l!,/%!5666
 -Z
W~h!,/&kZ
Z
r   c                4    | j                   | j                  z  S )z'Absolute line spacing in drawing units.)r)   r&   )r3   s    r   line_heightzMTextSurrogate.line_heighth   s     $"3"333r   c                   | j                   }t        |      dkD  rt| j                  t        j                  z  r|j                          t        |      D ]8  \  }}| j                  |      }|j                  || j                  |             : yt        |      dk(  r0|j                  |d   | j                  | j                               yy)zkRender the multi-line content as separated TEXT entities into the
        given `layout` instance.
        r   )
dxfattribsr   N)r#   lenr0   r   r   reverse	enumerate_get_align_pointadd_text_dxfattribsr$   )r3   layout
text_linesline_numberr4   align_points         r   renderzMTextSurrogate.renderm   s     \\
z?Q{{U^^+""$%.z%: !T"33K@#//<    _!OO1++DKK8   "r   c                &   | j                   j                  }| j                   j                  }	 | j                   j                  }| j
                  t        v r||| j                  z  z  }n}| j
                  t        v r@|| j                  z  }t        | j                        dz
  | j                  z  }||dz  |z
  z  }n+|t        | j                        dz
  |z
  | j                  z  z  }| j                  t        |||            S # t        $ r d}Y w xY w)z7Calculate the align-point depending on the line number.r   r   r   )r$   xyz
IndexErrorr(   	TOP_ALIGNr7   MIDDLE_ALIGNr:   r#   _rotater
   )r3   rB   rF   rG   rH   y0full_heights          r   r=   zMTextSurrogate._get_align_point   s    KKMMKKMM	A
 ::"t////AZZ<'t///Bt||,q0D4D4DDK+/R''A#dll#a'+59I9IIIA||DAqM**  	A	s   D DDc                B   |j                   | j                  j                   z
  }|j                  | j                  j                  z
  }t        j                  | j
                        }| j                  j                   |t        j                  |      z  z   |t        j                  |      z  z
  }| j                  j                  |t        j                  |      z  z   |t        j                  |      z  z   }t        t        |d      t        |d      |j                        S )z?Rotate `alignpoint` around insert-point about rotation degrees.   )rF   r$   rG   mathradiansr-   cossinr
   roundrH   )r3   
alignpointdxdybetarF   rG   s          r   rL   zMTextSurrogate._rotate   s    \\DKKMM)\\DKKMM)||DMM*KKMMB$//"txx~2EEKKMMB$//"txx~2EEE!QKq!jll;;r   c                    t         | j                     \  }}||| j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  ||dS )z1Build keyword arguments for TEXT entity creation.)r$   rC   r1   r2   r+   heightwidthtext_generation_flagr-   r,   halignvalign)
r   r(   r1   r2   r+   r)   r.   r0   r-   r,   )r3   rC   r^   r_   s       r   r?   zMTextSurrogate._dxfattribs   sf    1$**=!&ZZZZZZ&&&&$(KK||
 	
r   N)r4   r*   r$   r	   r&   r%   r)   r%   r,   r%   r-   r%   r.   r%   r2   r/   )returnr%   )r@   r   r`   None)rB   r/   r`   r
   )rV   r
   r`   r
   )rC   r
   r`   zdict[str, Any])r   r   r   __doc__r   r   MIRROR_NONEr   r   r   TOP_LEFTr   BYLAYERr5   propertyr7   rD   r=   rL   r?   r   r   r   r   r   &   s    > ++KHH ""++ !{{]]     	           < 4 4(+(<
r   r   )
__future__r   typingr   r   rQ   enumezdxf.enumsr   r   ezdxf.lldxfr   
ezdxf.mathr	   r
   mixinsr   ezdxf.eztypesr   rd   	TOP_RIGHT
TOP_CENTERrJ   MIDDLE_LEFTMIDDLE_CENTERMIDDLE_RIGHTrK   IntEnumr   r   r   r   r   <module>ru      s    # %    ! '/ !!""##	 $$&&%%T\\ H
( H
r   