o
    h                     @   s   d Z ddl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
 ddlmZmZmZ eeZee_G dd	 d	Zddd
ddZdS )a   
A module for parsing a subset of the TeX math syntax and rendering it to a
Matplotlib backend.

For a tutorial of its usage, see :ref:`mathtext`.  This
document is primarily concerned with implementation details.

The module uses pyparsing_ to parse the TeX expression.

.. _pyparsing: https://pypi.org/project/pyparsing/

The Bakoma distribution of the TeX Computer Modern fonts, and STIX
fonts are supported.  There is experimental support for using
arbitrary fonts, but results may vary without proper tweaking and
metrics for those fonts.
    N)_api	_mathtext)	LoadFlags)FontProperties   )RasterParseVectorParseget_unicode_indexc                   @   sX   e Zd ZdZejejejejej	ej
dZdd ZdddddZed	d
d ZdS )MathTextParserN)cmdejavuserif
dejavusansstixstixsanscustomc                 C   s    t jdddd| d| _dS )a	  
        Create a MathTextParser for the given backend *output*.

        Parameters
        ----------
        output : {"path", "agg"}
            Whether to return a `VectorParse` ("path") or a
            `RasterParse` ("agg", or its synonym "macosx").
        vectorraster)pathaggmacosx)outputN)r   check_getitemlower_output_type)selfr    r   g/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/matplotlib/mathtext.py__init__0   s   

zMathTextParser.__init__H   antialiasedc                C   sT   |dur|  nd}t|d}ddlm} tj| d| j }| 	|||||S )a  
        Parse the given math expression *s* at the given *dpi*.  If *prop* is
        provided, it is a `.FontProperties` object specifying the "default"
        font to use in the math expression, used for all non-math text.

        The results are cached, so multiple calls to `parse`
        with the same expression should be fast.

        Depending on the *output* type, this returns either a `VectorParse` or
        a `RasterParse`.
        Nztext.antialiasedr   )backend_agg)r   r   )
copympl
_val_or_rcmatplotlib.backendsr!   r   
NO_HINTINGget_hinting_flagr   _parse_cached)r   sdpipropr    r!   load_glyph_flagsr   r   r   parse>   s   zMathTextParser.parse2   c                 C   s   |d u rt  }tj| j| d}|||}| }| jd u r%t | j	_| j
||||}	t|	}
| jdkr<|
 S | jdkrG|
j|dS d S )N)fontsetr   r   r   )r   r   r   _font_type_mappingget_math_fontfamilyget_size_in_points_parserr   Parser	__class__r-   shipr   	to_vector	to_raster)r   r)   r*   r+   r    r,   fontset_classr/   fontsizeboxr   r   r   r   r(   X   s    





zMathTextParser._parse_cached)r   N)__name__
__module____qualname__r3   r   BakomaFontsDejaVuSerifFontsDejaVuSansFonts	StixFontsStixSansFontsUnicodeFontsr0   r   r-   	functools	lru_cacher(   r   r   r   r   r
   %   s    	r
   )colorc                C   sr   ddl m} td}|j| d|d\}}	}
}}|j|d |	d fd}|jd|
|	 | ||d |j|||d	 |
S )
a  
    Given a math expression, renders it in a closely-clipped bounding
    box to an image file.

    Parameters
    ----------
    s : str
        A math expression.  The math portion must be enclosed in dollar signs.
    filename_or_obj : str or path-like or file-like
        Where to write the image data.
    prop : `.FontProperties`, optional
        The size and style of the text.
    dpi : float, optional
        The output dpi.  If not set, the dpi is determined as for
        `.Figure.savefig`.
    format : str, optional
        The output format, e.g., 'svg', 'pdf', 'ps' or 'png'.  If not set, the
        format is determined as for `.Figure.savefig`.
    color : str, optional
        Foreground color, defaults to :rc:`text.color`.
    r   )figurer   r   )r*   r+   g      R@)figsize)fontpropertiesrG   )r*   format)
matplotlibrH   r
   r-   Figuretextsavefig)r)   filename_or_objr+   r*   rK   rG   rH   parserwidthheightdepth_figr   r   r   math_to_imagel   s   rW   )NNN)__doc__rE   loggingrL   r#   r   r   matplotlib.ft2fontr   matplotlib.font_managerr   r   r   r	   	getLoggerr<   _logr=   r
   rW   r   r   r   r   <module>   s    
G