
    Og                    `   d dl m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mZmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ g dZ ed       G d d             Z ed       G d d             ZddZ	 d	 	 	 	 	 ddZ G d de      Z G d dej<                        Z G d de      Z y)    )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                  ,    e Zd ZU ded<   ded<   ded<   y)r   floatwidth
cap_heighttotal_heightN)__name__
__module____qualname____annotations__     Z/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/tools/text_size.pyr   r      s    Lr!   r   c                  R    e Zd ZU ded<   ded<   ded<   ded<   ded<   ed
d       Zy	)r   r   total_widthr   column_widthgutter_widthzSequence[float]column_heightsc                ,    t        | j                        S N)lenr'   selfs    r"   column_countzMTextSize.column_count.   s    4&&''r!   N)returnint)r   r   r   r   propertyr-   r    r!   r"   r   r   #   s4    ##
 ( (r!   r   c                   | j                   j                  d      }d}| j                   j                  d      }t        j                  ||      }| j                  "t        |       }t        j                  |||      }|j                  j                  }| j                         }|r|j                  |      }t        |||      S )a  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!$'	y*lC$$11LooG__W-
J
L99r!   Nc           	     v   |xs
 t               }dg}d}d}| j                  r[t        |j                  |             }t	        |      r6|d   }|j
                  }|j                  }|D cg c]  }|j                   }}t	        |      }t        ||z  ||dz
  z  z   t        |      ||t        |            S c c}w )aZ  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

    r2   r      )r$   r   r%   r&   r'   )MTextSizeDetectorr<   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Hff11HNHE 5(<519+EE(!!^,  Is   (B6c                  L     e Zd Z fdZd ZddZd	dZd
dZddZddZ	 xZ
S )rC   c                v    t         |           t        j                         | _        | j                  | _        y r)   )super__init__tlDoNothingRenderer
do_nothingrenderer)r,   	__class__s    r"   rR   zMTextSizeDetector.__init__~   s)    ..0r!   c                     y r)   r    r+   s    r"   resetzMTextSizeDetector.reset   s    r!   c                    t        j                  | j                  |      j                  |      |j                  t        j
                  |j                        | j                        S )N)r   r3   valignrV   )rS   r	   get_fontr;   r   CellAlignmentalignrV   )r,   r<   ctxs      r"   wordzMTextSizeDetector.word   sJ    ww--$//5>>##CII.]]
 	
r!   c                    |\  }}}|rRt        j                  | j                  ||      | j                  ||      | j                  |      | j                        S | j                  ||      S )N)topbottomstackingrV   )rS   Fractionr`   get_stackingrV   )r,   datar_   uprlwrtype_s         r"   fractionzMTextSizeDetector.fraction   se    S%;;IIc3'yyc***51	  99S#&&r!   c                ,    t        j                  |      S r)   )r   get_entity_font_facer,   rI   s     r"   get_font_facezMTextSizeDetector.get_font_face   s    ))%00r!   c                    | j                   S r)   )rU   rn   s     r"   make_bg_rendererz"MTextSizeDetector.make_bg_renderer   s    r!   c                h    | j                          | j                  |      }|j                          |S r)   )rY   layout_engineplace)r,   rI   layouts      r"   rE   zMTextSizeDetector.measure   s)    

##E*r!   )r<   strr_   r   r.   tl.ContentCell)rg   rH   r_   r   r.   rw   )rI   r
   r.   zfonts.FontFace)rI   r
   r.   ztl.ContentRendererrI   r
   r.   z	tl.Layout)r   r   r   rR   rY   r`   rk   ro   rq   rE   __classcell__rW   s   @r"   rC   rC   }   s&    (


'1r!   rC   c                  :    e Zd ZdZddZ	 d	 	 	 	 	 	 	 	 	 	 	 ddZy)WordSizeCollectorzzCollects word sizes as tuples of the lower left corner and the upper
    right corner as Vec2 objects, ignores lines.
    c                    g | _         y r)   )
word_boxesr+   s    r"   rR   zWordSizeCollector.__init__   s	    35r!   Nc                f    | j                   j                  t        ||      t        ||      f       y r)   )r~   appendr   )r,   leftrc   rightrb   ms         r"   renderzWordSizeCollector.render   s)     	T6 2D4DEFr!   )r.   Noner)   )r   r   rc   r   r   r   rb   r   r   zOptional[Matrix44]r.   r   )r   r   r   __doc__rR   r   r    r!   r"   r|   r|      sW    6 !%GG G 	G
 G G 
Gr!   r|   c                  .     e Zd Zd Zd fdZddZ xZS )r   c                "    t               | _        y r)   )r|   rV   r+   s    r"   rY   zWordSizeDetector.reset   s    )+r!   c                F    t         |   |      }|j                          |S r)   )rQ   rE   r   )r,   rI   ru   rW   s      r"   rE   zWordSizeDetector.measure   s    'r!   c                .    | j                   j                  S r)   )rV   r~   r+   s    r"   r~   zWordSizeDetector.word_boxes   s    }}'''r!   rx   )r.   zlist[tuple[Vec2, Vec2]])r   r   r   rY   rE   r~   ry   rz   s   @r"   r   r      s    ,
(r!   r   )r<   r	   r.   r   r)   )rI   r
   rJ   zOptional[MTextSizeDetector]r.   r   )!
__future__r   typingr   r   dataclassesr   
ezdxf.mathr   r   ezdxf.entitiesr	   r
   r   ezdxf.fontsr   ezdxf.toolsr   rS   ezdxf.tools.textr   $ezdxf.render.abstract_mtext_rendererr   r   __all__r   r   r   r   rC   rT   r|   r   r    r!   r"   <module>r      s    # % ! % 5 5  ) ) F 3	 $   $( ( (:< 7;**3**Z(- (VG,, G&
(( 
(r!   