
    h                    Z   S SK J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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Qr\" SS9 " S S5      5       r\" SS9 " S S5      5       rSS jr S     SS jjr " S S\5      r " S S\R<                  5      r " S S\5      r g)    )annotations)SequenceOptional)	dataclass)Matrix44Vec2)TextMTextget_font_name)fonts)text_layout)MTextContext)AbstractMTextRenderer)estimate_mtext_extents)	text_size
mtext_sizeTextSize	MTextSizeWordSizeDetectorr   T)frozenc                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg)r      floatwidth
cap_heighttotal_height N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r       G/var/www/html/env/lib/python3.13/site-packages/ezdxf/tools/text_size.pyr   r      s    Lr$   r   c                  \    \ rS rSr% S\S'   S\S'   S\S'   S\S'   S\S'   \SS	 j5       rS
rg)r   #   r   total_widthr   column_widthgutter_widthzSequence[float]column_heightsc                ,    [        U R                  5      $ N)lenr+   selfs    r%   column_countMTextSize.column_count.   s    4&&''r$   r   N)returnint)r   r   r    r!   r"   propertyr1   r#   r   r$   r%   r   r   #   s4    ##
 ( (r$   r   c                   U R                   R                  S5      nSnU R                   R                  S5      n[        R                  " X15      nU R                  b"  [        U 5      n[        R                  " XSU5      nUR                  R                  nU R                  5       nU(       a  UR                  U5      n[        X#U5      $ )al  Returns the measured text width, the font cap-height and the font
total-height for a :class:`~ezdxf.entities.Text` entity.
This function uses the optional `Matplotlib` package if available to measure
the final rendering width and font-height for the :class:`Text` entity as
close as possible. This function does not measure the real char height!
Without access to the `Matplotlib` package the
:class:`~ezdxf.tools.fonts.MonospaceFont` is used and the measurements are
very inaccurate.

See the :mod:`~ezdxf.addons.text2path` add-on for more tools to work
with the text path objects created by the `Matplotlib` package.

r           height)dxfget_defaultr   MonospaceFontdocr   	make_fontmeasurementsr   
plain_text
text_widthr   )textwidth_factorr@   r   font	font_namer   contents           r%   r   r   3   s     ((..w7LJ,,X6J$22:LDxx!$'	ylC$$11LooG__W-
JL99r$   Nc           	        U=(       d
    [        5       nS/nSnSnU R                  (       ab  [        UR                  U 5      5      n[	        U5      (       a8  US   nUR
                  nUR                  nU Vs/ s H  owR                  PM     nn[	        U5      n[        XH-  X8S-
  -  -   [        U5      UU[        U5      S9$ s  snf )a&  Returns the total-width, -height and columns information for a
:class:`~ezdxf.entities.MText` entity.

This function uses the optional `Matplotlib` package if available to do
font measurements and the internal text layout engine to determine the final
rendering size for the :class:`MText` entity as close as possible.
Without access to the `Matplotlib` package the :class:`~ezdxf.tools.fonts.MonospaceFont`
is used and the measurements are very inaccurate.

Attention: The required full layout calculation is slow!

The first call to this function with `Matplotlib` support is very slow,
because `Matplotlib` lookup all available fonts on the system. To speedup
the calculation and accepting inaccurate results you can disable the
`Matplotlib` support manually::

    ezdxf.option.use_matplotlib = False

r7   r      )r(   r   r)   r*   r+   )MTextSizeDetectorrA   listmeasurer.   r(   gutterr   r   maxtuple)	mtexttoolr+   r*   r)   columnsfirst_columncolumncounts	            r%   r   r   P   s    , &$&D#&%NLLzz#'U(;#<w<<"1:L'33L'..L@GHf11NHE (<19+EE(!!^,  Is   7Cc                  `   ^  \ rS rSrU 4S jrS rS
S jrSS jrSS jrSS jr	SS jr
S	rU =r$ )rH   }   c                x   > [         TU ]  5         [        R                  " 5       U l        U R                  U l        g r-   )super__init__tlDoNothingRenderer
do_nothingrenderer)r0   	__class__s    r%   rX   MTextSizeDetector.__init__~   s)    ..0r$   c                    g r-   r   r/   s    r%   resetMTextSizeDetector.reset   s    r$   c                    [         R                  " U R                  U5      R                  U5      UR                  [         R
                  " UR                  5      U R                  S9$ )N)r   r8   valignr\   )rY   r	   get_fontr@   r   CellAlignmentalignr\   )r0   rA   ctxs      r%   wordMTextSizeDetector.word   sJ    ww--$//5>>##CII.]]
 	
r$   c                    Uu  p4nU(       aN  [         R                  " U R                  X25      U R                  XB5      U R                  U5      U R                  S9$ U R                  X25      $ )N)topbottomstackingr\   )rY   Fractionrh   get_stackingr\   )r0   datarg   uprlwrtype_s         r%   fractionMTextSizeDetector.fraction   s]    %;;IIc'yy***51	  99S&&r$   c                .    [         R                  " U5      $ r-   )r   get_entity_font_facer0   rN   s     r%   get_font_faceMTextSizeDetector.get_font_face   s    ))%00r$   c                    U R                   $ r-   )r[   rx   s     r%   make_bg_renderer"MTextSizeDetector.make_bg_renderer   s    r$   c                h    U R                  5         U R                  U5      nUR                  5         U$ r-   )r`   layout_engineplace)r0   rN   layouts      r%   rJ   MTextSizeDetector.measure   s)    

##E*r$   )r[   r\   )rA   strrg   r   r3   tl.ContentCell)rp   rM   rg   r   r3   r   )rN   r
   r3   zfonts.FontFace)rN   r
   r3   ztl.ContentRendererrN   r
   r3   z	tl.Layout)r   r   r    r!   rX   r`   rh   rt   ry   r|   rJ   r#   __classcell__r]   s   @r%   rH   rH   }   s+    (


'1 r$   rH   c                  H    \ rS rSrSrSS jr S           S	S jjrSrg)
WordSizeCollector   zrCollects word sizes as tuples of the lower left corner and the upper
right corner as Vec2 objects, ignores lines.
c                    / U l         g r-   
word_boxesr/   s    r%   rX   WordSizeCollector.__init__   s	    35r$   Nc                b    U R                   R                  [        X5      [        X45      45        g r-   )r   appendr   )r0   leftrl   rightrk   ms         r%   renderWordSizeCollector.render   s%     	T 2D4DEFr$   r   )r3   Noner-   )r   r   rl   r   r   r   rk   r   r   zOptional[Matrix44]r3   r   )r   r   r    r!   __doc__rX   r   r#   r   r$   r%   r   r      s]    6 !%GG G 	G
 G G 
G Gr$   r   c                  <   ^  \ rS rSrS rSU 4S jjrSS jrSrU =r$ )r      c                "    [        5       U l        g r-   )r   r\   r/   s    r%   r`   WordSizeDetector.reset   s    )+r$   c                F   > [         TU ]  U5      nUR                  5         U$ r-   )rW   rJ   r   )r0   rN   r   r]   s      r%   rJ   WordSizeDetector.measure   s    'r$   c                .    U R                   R                  $ r-   )r\   r   r/   s    r%   r   WordSizeDetector.word_boxes   s    }}'''r$   )r\   r   )r3   zlist[tuple[Vec2, Vec2]])	r   r   r    r!   r`   rJ   r   r#   r   r   s   @r%   r   r      s    ,
( (r$   r   )rA   r	   r3   r   r-   )rN   r
   rO   zOptional[MTextSizeDetector]r3   r   )!
__future__r   typingr   r   dataclassesr   
ezdxf.mathr   r   ezdxf.entitiesr	   r
   r   ezdxf.fontsr   ezdxf.toolsr   rY   ezdxf.tools.textr   $ezdxf.render.abstract_mtext_rendererr   r   __all__r   r   r   r   rH   rZ   r   r   r   r$   r%   <module>r      s    # % ! % 5 5  ) ) F 3	 $   $( ( (:< 7;**3**Z(- (VG,, G&
(( 
(r$   