
    hT3                    X   S SK Jr  S SKJrJrJrJr  S SKrS SKrS SK	J
r
JrJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  \(       a  S SKJr  S/r " S S\R>                  5      r  " S S\ 5      r! " S S\ 5      r"SSS jjr#SS jr$SS jr%SS jr& " S S\5      r'g)    )annotations)castAnyOptionalTYPE_CHECKINGN)MText
DXFGraphic	Textstyle)TextEntityAlignment)Drawing)Matrix44)fonts)text_layout)MTextContext)AbstractMTextRenderer)GenericLayoutTypeMTextExplodec                  j    \ rS rSrSS jr S           S	S jjr S           S
S jjrSrg)FrameRenderer   c                    Xl         X l        g N)line_attribslayout)selfattribsr   s      D/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/mtxpl.py__init__FrameRenderer.__init__   s    #    Nc                    U R                   R                  X4X44X24X4/SU R                  S9nU(       a  UR                  U5        g g )NT)close
dxfattribs)r   add_lwpolyliner   	transform)r   leftbottomrighttopmplines          r   renderFrameRenderer.render   sS     **[5,$H(( + 

 OOA r    c                    U R                   R                  X4X44U R                  S9nU(       a  UR                  U5        g g Nr#   )r   add_liner   r%   )r   x1y1x2y2r*   lines          r   r6   FrameRenderer.line-   s=     {{##RHrh4CTCT#UNN1 r    )r   r   )r   dictr   r   r   )r&   floatr'   r9   r(   r9   r)   r9   r*   r   returnNone)r2   r9   r3   r9   r4   r9   r5   r9   r*   r   r:   r;   )__name__
__module____qualname____firstlineno__r   r,   r6   __static_attributes__ r    r   r   r      s       	
   
" IM"(-38=E	 r    r   c                  z   ^  \ rS rSr    S           SU 4S jjjr S           SU 4S jjjrSrU =r$ )	ColumnBackgroundRenderer5   c                   > [         TU ]  X5        S U l        Ub  [        U5      U l        X0R                  S'   O!Ub  [        U5      U l        X@R                  S'   XPl        X`l        g Ncolor
true_color)superr   solid_attribsr8   offsethas_text_frame)r   r   r   bg_acibg_true_colorrK   
text_frame	__class__s          r   r   !ColumnBackgroundRenderer.__init__6   se     	)!!%gD*0w'&!%gD/<|,(r    c                &  > U R                   nX-  nX6-  nXF-  nX&-  nU R                  bD  U R                  R                  X4X44X4X24/U R                  S9nU(       a  UR	                  U5        U R
                  (       a  [        TU ]  XX4U5        g g r/   )rK   rJ   r   	add_solidr%   rL   rI   r,   )	r   r&   r'   r(   r)   r*   rK   solidrP   s	           r   r,   ColumnBackgroundRenderer.renderJ   s     )KK))ulTNUOL-- * E
 "GN4Q7 r    )rL   rK   rJ   )NNr   F)r   r8   r   r   rM   Optional[int]rN   rV   rK   r9   rO   boolr   )r&   r9   r'   r9   r(   r9   r)   r9   r*   Optional[Matrix44]r:   r;   )r<   r=   r>   r?   r   r,   r@   __classcell__rP   s   @r   rC   rC   5   s    
 !%'+ )) ") 	)
 %) ) ) )4 !%88 8 	8
 8 8 
8 8r    rC   c                  b   ^  \ rS rSrSr        SU 4S jjr S         SS jjrSrU =r$ )	TextRenderere   zText content renderer.c                <   > [         TU ]  X45        Xl        X l        g r   )rI   r   texttext_attribs)r   r_   r`   r   r   rP   s        r   r   TextRenderer.__init__h   s     	.	(r    c                    U R                   R                  U R                  U R                  S9nUR	                  X4[
        R                  S9  U(       a  UR                  U5        gg)zCreate/render the text contentr0   alignN)r   add_textr_   r`   set_placementr   LEFTr%   )r   r&   r'   r(   r)   r*   r_   s          r   r,   TextRenderer.renders   sW     {{##DII$:K:K#LD>1D1I1IJNN1 r    )r_   r`   )r_   strr`   r8   r   r8   r   r   r   )
r&   r9   r'   r9   r(   r9   r)   r9   r*   rX   )	r<   r=   r>   r?   __doc__r   r,   r@   rY   rZ   s   @r   r\   r\   e   sp     	)	) 	) 		)
 "	)" !%  	
   r    r\   c                N   U R                   (       a  Uc  U R                   nUc   S5       eSnU R                  R                  S5      (       a  U R                  R                  n[        R
                  " 5       nU(       a  Ub  [        [        UR                  R                  U5      5      nUR                  5       u  pVnU(       a-  U(       a  SOSnU(       a  SOSn	[        R
                  " XXU	S9nU$ UR                  R                  n
U
(       a  [        R                  " U
5      nU$ )	a  Returns the :class:`~ezdxf.tools.fonts.FontFace` defined by the
associated text style. Returns the default font face if the `entity` does
not have or support the DXF attribute "style".

Pass a DXF document as argument `doc` to resolve text styles for virtual
entities which are not assigned to a DXF document. The argument `doc`
always overrides the DXF document to which the `entity` is assigned to.

zvalid DXF document required styleItalicRegulari  i  )familyrm   weight)docdxfis_supportedrm   r   FontFacer   r
   stylesgetget_extended_font_datafontget_font_face)entityrr   
style_name	font_facerm   rp   italicbold
text_styletext_weightttfs              r   rz   rz      s     zzckjj?999?J zzw''ZZ%%
 IcoY

z :;$;;=%+J!%#3KI  ))..C!//4	r    c                    SU R                   0nU R                  b#  [        R                  " U R                  5      US'   U$ rF   )acirgbezdxfrgb2int)ctxr   s     r   get_color_attribsr      s6     G
ww %cgg 6Nr    c           	        [        U 5      nU R                  nUR                  SS5      nS nS nSnSnU(       a  UR                  UR                  SS5      S-
  -  nU[        R
                  R                  -  (       aS  UR                  S5      (       a  UR                  nUR                  S5      (       a  S nUR                  nUS	-  S	:X  a  S nS nU[        R
                  R                  -  (       a  S
n[        UUUUUUS9$ )Nbg_fillr   Fbox_fill_scaleg      ?   bg_fill_colorbg_fill_true_color   T)rM   rN   rK   rO   )get_base_attribsrs   rw   char_heightr   constMTEXT_BG_COLORhasattrr   r   MTEXT_TEXT_FRAMErC   )	mtextr   r   rs   r   rM   rN   rL   rK   s	            r   make_bg_rendererr      s    u%G
))Cggi#GFMNF CGG,<c$BQ$FGU[[///{{?++**{{/00 # 6 6!!  $U[[111!N##! r    c                P    U R                   nUR                  UR                  S.nU$ )N)layerrG   )rs   r   rG   )r   rs   r   s      r   r   r      s'    
))CG Nr    c                     ^  \ rS rSrSr  S     SU 4S jjjrSU 4S jjrSS jrSS jrSS jr	SS jr
S	 rS
 rSS jrSS jrSS jrSSS jjrS rSS jrSrU =r$ )r      a  The :class:`MTextExplode` class is a tool to disassemble MTEXT entities
into single line TEXT entities and additional LINE entities if required to
emulate strokes.

The `layout` argument defines the target layout  for "exploded" parts of the
MTEXT entity. Use argument `doc` if the target layout has no DXF document assigned
like virtual layouts.  The `spacing_factor` argument is an advanced tuning parameter
to scale the size of space chars.

c                   > [         TU ]  5         Xl        X l        [	        U5      U l        0 U l        [        5       U l        g r   )	rI   r   r   _docr9   _spacing_factor_required_text_stylesr8   current_base_attribs)r   r   rr   spacing_factorrP   s       r   r   MTextExplode.__init__   s9     	)/	$^4@B"48F!r    c                B   > [        U5      U l        [        TU ]  U5      $ r   )r   r   rI   layout_engine)r   r   rP   s     r   r   MTextExplode.layout_engine   s     $4U$;!w$U++r    c                   [        U R                  =(       d    0 5      nUR                  [        U5      5        [        U5      nUR                  U R	                  U5      5        [
        R                  " U R                  U5      R                  U5      UR                  [
        R                  " UR                  5      U R                  U5      [        XX0R                  5      S9$ )N)widthheightvalignstrokerenderer)r8   r   updater   get_text_attribstlTextget_font
text_width
cap_heightCellAlignmentrd   
get_stroker\   r   )r   r_   r   r   r`   s        r   wordMTextExplode.word  s    D55;<-c23L)D11#67ww--$//5>>##CII.??3'!$lKKP
 	
r    c           	         Uu  p4nU(       ab  [         R                  " U R                  X25      U R                  XB5      U R                  U5      [	        U R
                  U R                  5      S9$ U R                  X25      $ )N)r)   r'   stackingr   )r   Fractionr   get_stackingr   r   r   )r   datar   uprlwrtype_s         r   fractionMTextExplode.fraction  sj    %;;IIc'yy***51&t'@'@$++N  99S&&r    c                    [        U5      $ r   )rz   r   r   s     r   rz   MTextExplode.get_font_face  s    U##r    c                ,    [        XR                  5      $ r   )r   r   r   s     r   r   MTextExplode.make_bg_renderer  s    {{33r    c                    U $ r   rA   )r   s    r   	__enter__MTextExplode.__enter__#  s    r    c                $    U R                  5         g r   )finalize)r   exc_typeexc_valexc_tbs       r   __exit__MTextExplode.__exit__&  s    r    c                    SnUR                   (       a  US-  nUR                  (       a  US-  nUS:  a  [        U5      OSnSUR                   3U-   nXR                  U'   U$ )Nr   r      rl   MtXpl_)is_bold	is_italicri   rp   r   )r   r}   rm   	style_strr   s        r   mtext_exploded_text_style&MTextExplode.mtext_exploded_text_style)  sh    QJEQJE"'!)CJ	i../09<
1:"":.r    c                $   [         R                  " UR                  5      nX!R                  UR                  4nU R
                  R                  U5      nUc9  [         R                  " X!R                  UR                  5      nX@R
                  U'   U$ r   )r   find_font_file_namer}   r   width_factor_font_cacherw   	make_font)r   r   r   keyry   s        r   r   MTextExplode.get_font5  sr    ''6NNC$4$45##C(<??38H8HID$(S!r    c                   UR                   U R                  UR                  5      S.n[        R                  " UR
                  S5      (       d  UR
                  US'   [        UR                  5      S:  a  UR                  US'   U$ )N)r   rm         ?r   gư>oblique)r   r   r}   mathiscloser   absr   )r   r   r   s      r   r   MTextExplode.get_text_attribs>  so    nn33CMMB
 ||C,,c22"//GGs{{d"!$GIr    c                   [         R                  " UR                  R                  5      nU R	                  U5      nUR                  US9  UR                  UR                  5       R                  5        U(       a  UR                  5         gg)zQExplode `mtext` and destroy the source entity if argument `destroy`
is ``True``.
rc   N)
r   LayoutAlignmentrs   attachment_pointr   placer,   ucsmatrixdestroy)r   r   r   rd   r   s        r   explodeMTextExplode.explodeI  sj     ""599#=#=>**51%(UYY[//0MMO r    c                    U R                   nUc  U R                  R                  nUc  [        R                  " S5      eUR
                  nU R                  5        H  n UR                  U5        M     g! [        R                   a     M1  f = f)zCreate required text styles. This method is called automatically if
the class is used as context manager. This method does not work with virtual
layouts if no document was assigned at initialization!
NzsDXF document required, finalize() does not work with virtual layouts if no document was assigned at initialization.)	r   r   rr   r   DXFValueErrorrv   !make_required_style_table_entries	add_entryDXFTableEntryError)r   rr   text_stylesrm   s       r   r   MTextExplode.finalizeT  s     ii;++//C;%%A  jj;;=E%%e, > ++ s   A55BBc                D   SS jn/ nU R                   R                  5        Hz  u  p4U" U5      n[        R                  " UUS.S9nUR	                  S5      (       d/  UR                  UR                  UR                  UR                  S9  UR                  U5        M|     U$ )Nc                    U R                   nU(       d  [        R                  " U 5      nU$ [        R                  " U5      nU(       a  UnU$ r   )filenamer   r   map_ttf_to_shx)r}   r   shxs      r   ttf_path@MTextExplode.make_required_style_table_entries.<locals>.ttf_pathj  sF    $$C//	: J **3/CJr    )namery   r0   z.SHX)r~   r   r}   fonts.FontFacer:   ri   )
r   itemsr
   newendswithset_extended_font_datarp   r   r   append)r   r   r   r   r}   r   rm   s          r   r   .MTextExplode.make_required_style_table_entriesi  s    
	 (*#99??AOD9%CMM. E <<'',,$$$.."** - 
 u%  B r    )r   r   r   r   r   )Nr   )r   r   rr   zOptional[Drawing]r   r9   )r   r   r:   z	tl.Layout)r_   ri   r   r   r:   tl.ContentCell)r   tupler   r   r:   r  )r   r   r:   r   )r   r   r:   ztl.ContentRendererr   )r   r   r:   zfonts.AbstractFontr   r   r:   r8   )T)r   r   )r:   zlist[Textstyle])r<   r=   r>   r?   rj   r   r   r   r   rz   r   r   r   r   r   r   r   r   r   r@   rY   rZ   s   @r   r   r      s|    	 "& #	;!; ; 	; ; ,
'$4

		* r    r   )r{   r	   r:   r   r	  )r   r   r   r   )r   r   r:   r8   )(
__future__r   typingr   r   r   r   r   r   ezdxf.entitiesr   r	   r
   ezdxf.enumsr   ezdxf.documentr   
ezdxf.mathr   ezdxf.fontsr   ezdxf.toolsr   r   ezdxf.tools.textr   $ezdxf.render.abstract_mtext_rendererr   ezdxf.eztypesr   __all__ContentRendererr   rC   r\   rz   r   r   r   r   rA   r    r   <module>r     s    # 5 5   7 7 + #   ) ) F/
B&& :-8} -8`= <"J&Rc( cr    