a
    Sicɾ                     @   s  d dl Z d dlZd dlZd dlZd dlmZ d dlmZ ddlm	Z	 ddl
mZ ddlmZmZ G dd	 d	eZd
d ZG dd dZzddlmZ W n ey   e ZY n0 e ZG dd dZG dd dZG dd dZdd ZdddZdd Zdd ZdS )     N)IntEnum)BytesIO   )Image)	deprecate)is_directoryis_pathc                   @   s   e Zd ZdZdZdS )Layoutr   r   N)__name__
__module____qualname__BASICRAQM r   r   I/var/www/html/django/DPS/env/lib/python3.9/site-packages/PIL/ImageFont.pyr	   (   s   r	   c                 C   s   t di D ]X\}}| |r| t|d  } | |jv rt| |  d|j d|   ||    S qtdt d|  dd S )NZLAYOUT_
   .zmodule 'z' has no attribute '')r	   items
startswithlen__members__r   r
   AttributeError)nameenumprefixr   r   r   __getattr__-   s    

 r   c                   @   s   e Zd Zdd ZdS )_ImagingFtNotInstalledc                 C   s   t dd S )Nz(The _imagingft C module is not installed)ImportError)selfidr   r   r   r   9   s    z"_ImagingFtNotInstalled.__getattr__N)r
   r   r   r   r   r   r   r   r   7   s   r   )
_imagingftc                   @   sB   e Zd ZdZdd Zdd Zdd Zdd	d
Zdd Zdd Z	dS )	ImageFontzPIL font wrapperc              
   C   s   t |d}d }dD ]X}|r$|  z"tj|d | }t |}W n tyX   Y q0 |r|jdv r qq|rz|  td|| _	| 
|| |  W d    n1 s0    Y  d S )Nrb)z.pngz.gifz.pbmr   1Lzcannot find glyph data file)opencloseospathsplitextr   	ExceptionmodeOSErrorfile_load_pilfont_data)r   filenamefpimageextfullnamer   r   r   _load_pilfontY   s$    zImageFont._load_pilfontc                 C   s   |  dkrtd|  d g | _|  }|rL|dkr>qL| j| q(|d}|jdvrhtd|  t	j
|j|| _d S )Ns   PILfont
zNot a PILfont file   ;s   DATA
i   r$   zinvalid font image mode)readlineSyntaxErrorsplitinfoappendreadr-   	TypeErrorloadr   corefontim)r   r/   r3   sdatar   r   r   r0   r   s    

zImageFont._load_pilfont_datac                 O   s   t ddd | j|S )z
        .. deprecated:: 9.2.0

        Use :py:meth:`.getbbox` or :py:meth:`.getlength` instead.

        Returns width and height (in pixels) of given text.

        :param text: Text to measure.

        :return: (width, height)
        getsizer   getbbox or getlengthr   rA   rE   r   textargskwargsr   r   r   rE      s    zImageFont.getsize c                 O   s   | j ||S )a  
        Create a bitmap for the text.

        If the font uses antialiasing, the bitmap should have mode ``L`` and use a
        maximum value of 255. Otherwise, it should have mode ``1``.

        :param text: Text to render.
        :param mode: Used by some graphics drivers to indicate what mode the
                     driver prefers; if empty, the renderer may return either
                     mode. Note that the mode is always a string, to simplify
                     C-level implementations.

                     .. versionadded:: 1.1.5

        :return: An internal PIL storage memory instance as defined by the
                 :py:mod:`PIL.Image.core` interface module.
        )rA   getmask)r   rI   r-   rJ   rK   r   r   r   rM      s    zImageFont.getmaskc                 O   s   | j |\}}dd||fS )a  
        Returns bounding box (in pixels) of given text.

        .. versionadded:: 9.2.0

        :param text: Text to render.
        :param mode: Used by some graphics drivers to indicate what mode the
                     driver prefers; if empty, the renderer may return either
                     mode. Note that the mode is always a string, to simplify
                     C-level implementations.

        :return: ``(left, top, right, bottom)`` bounding box
        r   rA   rE   r   rI   rJ   rK   widthheightr   r   r   getbbox   s    zImageFont.getbboxc                 O   s   | j |\}}|S )z
        Returns length (in pixels) of given text.
        This is the amount by which following text should be offset.

        .. versionadded:: 9.2.0
        rN   rO   r   r   r   	getlength   s    zImageFont.getlengthN)rL   )
r
   r   r   __doc__r6   r0   rE   rM   rR   rS   r   r   r   r   r"   V   s   
r"   c                   @   s   e Zd ZdZd+ddZdd	 Zd
d Zdd Zdd Zdd Z	d,ddZ
d-ddZd.ddZd/ddZdd Zd0ddZdeddddddfdd Zd1d!d"Zd#d$ Zd%d& Zd'd( Zd)d* ZdS )2FreeTypeFontz3FreeType font wrapper (requires _imagingft service)Nr   r   rL   c           	         s  |_ __ _tjtjfvr<tjtjr\tjn tjkr\tjs\t	
d tj_ fdd}t|rtjdkrt|tr|n| }z|d W nF ty   t|d}|| W d    n1 s0    Y  Y d S 0 tj| d_n|| d S )NzSRaqm layout was requested, but Raqm is not available. Falling back to basic layout.c                    s&   |   _td j_d S )NrL   )r=   
font_bytesr@   getfontrA   fencodingindexlayout_enginer   sizer   r   load_from_bytes   s    
z.FreeTypeFont.__init__.<locals>.load_from_byteswin32asciir#   )r]   )r*   r^   r\   r[   r	   r   r   r@   Z	HAVE_RAQMwarningswarnr]   r   sysplatform
isinstancebytesencodedecodeUnicodeDecodeErrorr'   rW   rA   )	r   rA   r^   r\   r[   r]   r_   Zfont_bytes_pathrY   r   rZ   r   __init__   s8    

&

zFreeTypeFont.__init__c                 C   s   | j | j| j| j| jgS N)r*   r^   r\   r[   r]   r   r   r   r   __getstate__   s    zFreeTypeFont.__getstate__c                 C   s$   |\}}}}}|  ||||| d S rl   )rk   )r   stater*   r^   r\   r[   r]   r   r   r   __setstate__   s    zFreeTypeFont.__setstate__c                 C   s   t |trdnd}||S )N
   
)rf   strr:   )r   rI   split_characterr   r   r   _multiline_split  s    zFreeTypeFont._multiline_splitc                 C   s   | j j| j jfS )zq
        :return: A tuple of the font family (e.g. Helvetica) and the font style
            (e.g. Bold)
        )rA   familystylerm   r   r   r   getname  s    zFreeTypeFont.getnamec                 C   s   | j j| j jfS )z
        :return: A tuple of the font ascent (the distance from the baseline to
            the highest outline point) and descent (the distance from the
            baseline to the lowest outline point, a negative value)
        )rA   Zascentdescentrm   r   r   r   
getmetrics  s    zFreeTypeFont.getmetricsc                 C   s   | j |||||d S )ar  
        Returns length (in pixels with 1/64 precision) of given text when rendered
        in font with provided direction, features, and language.

        This is the amount by which following text should be offset.
        Text bounding box may extend past the length in some fonts,
        e.g. when using italics or accents.

        The result is returned as a float; it is a whole number if using basic layout.

        Note that the sum of two lengths may not equal the length of a concatenated
        string due to kerning. If you need to adjust for kerning, include the following
        character and subtract its length.

        For example, instead of

        .. code-block:: python

          hello = font.getlength("Hello")
          world = font.getlength("World")
          hello_world = hello + world  # not adjusted for kerning
          assert hello_world == font.getlength("HelloWorld")  # may fail

        use

        .. code-block:: python

          hello = font.getlength("HelloW") - font.getlength("W")  # adjusted for kerning
          world = font.getlength("World")
          hello_world = hello + world  # adjusted for kerning
          assert hello_world == font.getlength("HelloWorld")  # True

        or disable kerning with (requires libraqm)

        .. code-block:: python

          hello = draw.textlength("Hello", font, features=["-kern"])
          world = draw.textlength("World", font, features=["-kern"])
          hello_world = hello + world  # kerning is disabled, no need to adjust
          assert hello_world == draw.textlength("HelloWorld", font, features=["-kern"])

        .. versionadded:: 8.0.0

        :param text: Text to measure.
        :param mode: Used by some graphics drivers to indicate what mode the
                     driver prefers; if empty, the renderer may return either
                     mode. Note that the mode is always a string, to simplify
                     C-level implementations.

        :param direction: Direction of the text. It can be 'rtl' (right to
                          left), 'ltr' (left to right) or 'ttb' (top to bottom).
                          Requires libraqm.

        :param features: A list of OpenType font features to be used during text
                         layout. This is usually used to turn on optional
                         font features that are not enabled by default,
                         for example 'dlig' or 'ss01', but can be also
                         used to turn off default font features for
                         example '-liga' to disable ligatures or '-kern'
                         to disable kerning.  To get all supported
                         features, see
                         https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
                         Requires libraqm.

        :param language: Language of the text. Different languages may use
                         different glyph shapes or ligatures. This parameter tells
                         the font which language the text is in, and to apply the
                         correct substitutions as appropriate, if available.
                         It should be a `BCP 47 language code
                         <https://www.w3.org/International/articles/language-tags/>`_
                         Requires libraqm.

        :return: Width for horizontal, height for vertical text.
        @   )rA   rS   )r   rI   r-   	directionfeatureslanguager   r   r   rS     s    KzFreeTypeFont.getlengthc                 C   sj   | j ||||||\}}	|	d | |	d |  }
}|d d|  |d d|   }}|
||
| || fS )a	  
        Returns bounding box (in pixels) of given text relative to given anchor
        when rendered in font with provided direction, features, and language.

        Use :py:meth:`getlength()` to get the offset of following text with
        1/64 pixel precision. The bounding box includes extra margins for
        some fonts, e.g. italics or accents.

        .. versionadded:: 8.0.0

        :param text: Text to render.
        :param mode: Used by some graphics drivers to indicate what mode the
                     driver prefers; if empty, the renderer may return either
                     mode. Note that the mode is always a string, to simplify
                     C-level implementations.

        :param direction: Direction of the text. It can be 'rtl' (right to
                          left), 'ltr' (left to right) or 'ttb' (top to bottom).
                          Requires libraqm.

        :param features: A list of OpenType font features to be used during text
                         layout. This is usually used to turn on optional
                         font features that are not enabled by default,
                         for example 'dlig' or 'ss01', but can be also
                         used to turn off default font features for
                         example '-liga' to disable ligatures or '-kern'
                         to disable kerning.  To get all supported
                         features, see
                         https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
                         Requires libraqm.

        :param language: Language of the text. Different languages may use
                         different glyph shapes or ligatures. This parameter tells
                         the font which language the text is in, and to apply the
                         correct substitutions as appropriate, if available.
                         It should be a `BCP 47 language code
                         <https://www.w3.org/International/articles/language-tags/>`_
                         Requires libraqm.

        :param stroke_width: The width of the text stroke.

        :param anchor:  The text anchor alignment. Determines the relative location of
                        the anchor to the text. The default alignment is top left.
                        See :ref:`text-anchors` for valid values.

        :return: ``(left, top, right, bottom)`` bounding box
        r   r      rN   )r   rI   r-   r|   r}   r~   stroke_widthanchorr^   offsetlefttoprP   rQ   r   r   r   rR   d  s    9"zFreeTypeFont.getbboxc                 C   sL   t ddd | j|d|||\}}|d |d  |d |d  |d  fS )as	  
        .. deprecated:: 9.2.0

        Use :py:meth:`getlength()` to measure the offset of following text with
        1/64 pixel precision.
        Use :py:meth:`getbbox()` to get the exact bounding box based on an anchor.

        Returns width and height (in pixels) of given text if rendered in font with
        provided direction, features, and language.

        .. note:: For historical reasons this function measures text height from
            the ascender line instead of the top, see :ref:`text-anchors`.
            If you wish to measure text height from the top, it is recommended
            to use the bottom value of :meth:`getbbox` with ``anchor='lt'`` instead.

        :param text: Text to measure.

        :param direction: Direction of the text. It can be 'rtl' (right to
                          left), 'ltr' (left to right) or 'ttb' (top to bottom).
                          Requires libraqm.

                          .. versionadded:: 4.2.0

        :param features: A list of OpenType font features to be used during text
                         layout. This is usually used to turn on optional
                         font features that are not enabled by default,
                         for example 'dlig' or 'ss01', but can be also
                         used to turn off default font features for
                         example '-liga' to disable ligatures or '-kern'
                         to disable kerning.  To get all supported
                         features, see
                         https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
                         Requires libraqm.

                         .. versionadded:: 4.2.0

        :param language: Language of the text. Different languages may use
                         different glyph shapes or ligatures. This parameter tells
                         the font which language the text is in, and to apply the
                         correct substitutions as appropriate, if available.
                         It should be a `BCP 47 language code
                         <https://www.w3.org/International/articles/language-tags/>`_
                         Requires libraqm.

                         .. versionadded:: 6.0.0

        :param stroke_width: The width of the text stroke.

                         .. versionadded:: 6.2.0

        :return: (width, height)
        rE   r   rF   r&   r   r   r   rG   )r   rI   r|   r}   r~   r   r^   r   r   r   r   rE     s
    <zFreeTypeFont.getsize   c              	   C   s   t ddd d}| |}t ^ tjdtd | jd|dd	 | }	|D ]$}
| |
||||\}}t||}qLW d
   n1 s0    Y  |t||	 | fS )a  
        .. deprecated:: 9.2.0

        Use :py:meth:`.ImageDraw.multiline_textbbox` instead.

        Returns width and height (in pixels) of given text if rendered in font
        with provided direction, features, and language, while respecting
        newline characters.

        :param text: Text to measure.

        :param direction: Direction of the text. It can be 'rtl' (right to
                          left), 'ltr' (left to right) or 'ttb' (top to bottom).
                          Requires libraqm.

        :param spacing: The vertical gap between lines, defaulting to 4 pixels.

        :param features: A list of OpenType font features to be used during text
                         layout. This is usually used to turn on optional
                         font features that are not enabled by default,
                         for example 'dlig' or 'ss01', but can be also
                         used to turn off default font features for
                         example '-liga' to disable ligatures or '-kern'
                         to disable kerning.  To get all supported
                         features, see
                         https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
                         Requires libraqm.

        :param language: Language of the text. Different languages may use
                         different glyph shapes or ligatures. This parameter tells
                         the font which language the text is in, and to apply the
                         correct substitutions as appropriate, if available.
                         It should be a `BCP 47 language code
                         <https://www.w3.org/International/articles/language-tags/>`_
                         Requires libraqm.

                         .. versionadded:: 6.0.0

        :param stroke_width: The width of the text stroke.

                         .. versionadded:: 6.2.0

        :return: (width, height)
        getsize_multiliner   zImageDraw.multiline_textbboxr   ignorecategoryA)r   r   N)	r   ru   rb   catch_warningsfilterwarningsDeprecationWarningrE   maxr   )r   rI   r|   spacingr}   r~   r   	max_widthlinesline_spacingline
line_widthline_heightr   r   r   r     s    5


*zFreeTypeFont.getsize_multilinec                 C   s   t ddd | j|d S )a  
        .. deprecated:: 9.2.0

        Use :py:meth:`.getbbox` instead.

        Returns the offset of given text. This is the gap between the
        starting coordinate and the first marking. Note that this gap is
        included in the result of :py:func:`~PIL.ImageFont.FreeTypeFont.getsize`.

        :param text: Text to measure.

        :return: A tuple of the x and y offset
        	getoffsetr   rR   r   rG   )r   rI   r   r   r   r   ,  s    zFreeTypeFont.getoffsetc	           	   
   C   s   | j ||||||||dd S )a  
        Create a bitmap for the text.

        If the font uses antialiasing, the bitmap should have mode ``L`` and use a
        maximum value of 255. If the font has embedded color data, the bitmap
        should have mode ``RGBA``. Otherwise, it should have mode ``1``.

        :param text: Text to render.
        :param mode: Used by some graphics drivers to indicate what mode the
                     driver prefers; if empty, the renderer may return either
                     mode. Note that the mode is always a string, to simplify
                     C-level implementations.

                     .. versionadded:: 1.1.5

        :param direction: Direction of the text. It can be 'rtl' (right to
                          left), 'ltr' (left to right) or 'ttb' (top to bottom).
                          Requires libraqm.

                          .. versionadded:: 4.2.0

        :param features: A list of OpenType font features to be used during text
                         layout. This is usually used to turn on optional
                         font features that are not enabled by default,
                         for example 'dlig' or 'ss01', but can be also
                         used to turn off default font features for
                         example '-liga' to disable ligatures or '-kern'
                         to disable kerning.  To get all supported
                         features, see
                         https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
                         Requires libraqm.

                         .. versionadded:: 4.2.0

        :param language: Language of the text. Different languages may use
                         different glyph shapes or ligatures. This parameter tells
                         the font which language the text is in, and to apply the
                         correct substitutions as appropriate, if available.
                         It should be a `BCP 47 language code
                         <https://www.w3.org/International/articles/language-tags/>`_
                         Requires libraqm.

                         .. versionadded:: 6.0.0

        :param stroke_width: The width of the text stroke.

                         .. versionadded:: 6.2.0

        :param anchor:  The text anchor alignment. Determines the relative location of
                        the anchor to the text. The default alignment is top left.
                        See :ref:`text-anchors` for valid values.

                         .. versionadded:: 8.0.0

        :param ink: Foreground ink for rendering in RGBA mode.

                         .. versionadded:: 8.0.0

        :return: An internal PIL storage memory instance as defined by the
                 :py:mod:`PIL.Image.core` interface module.
        )r|   r}   r~   r   r   inkr   )getmask2)	r   rI   r-   r|   r}   r~   r   r   r   r   r   r   rM   =  s    H	zFreeTypeFont.getmaskc
              
   O   s   |t u rtjj}n
tdd | j||||||\}}|d |d  |d |d  f}|d | |d | f}t| ||dkrdnd|d}| j||j	||||||	 ||fS )an  
        Create a bitmap for the text.

        If the font uses antialiasing, the bitmap should have mode ``L`` and use a
        maximum value of 255. If the font has embedded color data, the bitmap
        should have mode ``RGBA``. Otherwise, it should have mode ``1``.

        :param text: Text to render.
        :param mode: Used by some graphics drivers to indicate what mode the
                     driver prefers; if empty, the renderer may return either
                     mode. Note that the mode is always a string, to simplify
                     C-level implementations.

                     .. versionadded:: 1.1.5

        :param fill: Optional fill function. By default, an internal Pillow function
                     will be used.

                     Deprecated. This parameter will be removed in Pillow 10
                     (2023-07-01).

        :param direction: Direction of the text. It can be 'rtl' (right to
                          left), 'ltr' (left to right) or 'ttb' (top to bottom).
                          Requires libraqm.

                          .. versionadded:: 4.2.0

        :param features: A list of OpenType font features to be used during text
                         layout. This is usually used to turn on optional
                         font features that are not enabled by default,
                         for example 'dlig' or 'ss01', but can be also
                         used to turn off default font features for
                         example '-liga' to disable ligatures or '-kern'
                         to disable kerning.  To get all supported
                         features, see
                         https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
                         Requires libraqm.

                         .. versionadded:: 4.2.0

        :param language: Language of the text. Different languages may use
                         different glyph shapes or ligatures. This parameter tells
                         the font which language the text is in, and to apply the
                         correct substitutions as appropriate, if available.
                         It should be a `BCP 47 language code
                         <https://www.w3.org/International/articles/language-tags/>`_
                         Requires libraqm.

                         .. versionadded:: 6.0.0

        :param stroke_width: The width of the text stroke.

                         .. versionadded:: 6.2.0

        :param anchor:  The text anchor alignment. Determines the relative location of
                        the anchor to the text. The default alignment is top left.
                        See :ref:`text-anchors` for valid values.

                         .. versionadded:: 8.0.0

        :param ink: Foreground ink for rendering in RGBA mode.

                         .. versionadded:: 8.0.0

        :return: A tuple of an internal PIL storage memory instance as defined by the
                 :py:mod:`PIL.Image.core` interface module, and the text offset, the
                 gap between the starting coordinate and the first marking
        fillr   r   r   r   RGBAr&   )
_UNSPECIFIEDr   r@   r   r   rA   rE   _decompression_bomb_checkrenderr    )r   rI   r-   r   r|   r}   r~   r   r   r   rJ   rK   r^   r   rB   r   r   r   r     s    R

 
zFreeTypeFont.getmask2c                 C   sr   |du r0zt | j}W n ty.   | j}Y n0 t||du rB| jn||du rR| jn||du rb| jn||pl| jdS )a  
        Create a copy of this FreeTypeFont object,
        using any specified arguments to override the settings.

        Parameters are identical to the parameters used to initialize this
        object.

        :return: A FreeTypeFont object.
        N)rA   r^   r\   r[   r]   )	r   rV   r   r*   rU   r^   r\   r[   r]   )r   rA   r^   r\   r[   r]   r   r   r   font_variant  s    zFreeTypeFont.font_variantc              
   C   sL   z| j  }W n. ty< } ztd|W Y d}~n
d}~0 0 dd |D S )z
        :returns: A list of the named styles in a variation font.
        :exception OSError: If the font is not a variation font.
        %FreeType 2.9.1 or greater is requiredNc                 S   s   g | ]}| d dqS )        )replace).0r   r   r   r   
<listcomp>  r   z4FreeTypeFont.get_variation_names.<locals>.<listcomp>)rA   Zgetvarnamesr   NotImplementedError)r   nameser   r   r   get_variation_names  s
     z FreeTypeFont.get_variation_namesc                 C   sN   |   }t|ts| }||}|t| ddkr8dS || _| j| dS )zv
        :param name: The name of the style.
        :exception OSError: If the font is not a variation font.
        _last_variation_indexN)	r   rf   rg   rh   r\   getattrr   rA   Z
setvarname)r   r   r   r\   r   r   r   set_variation_by_name  s    

z"FreeTypeFont.set_variation_by_namec              
   C   s`   z| j  }W n. ty< } ztd|W Y d}~n
d}~0 0 |D ]}|d dd|d< qB|S )z
        :returns: A list of the axes in a variation font.
        :exception OSError: If the font is not a variation font.
        r   Nr   r   r   )rA   Z
getvaraxesr   r   r   )r   axesr   axisr   r   r   get_variation_axes)  s     zFreeTypeFont.get_variation_axesc              
   C   sD   z| j | W n. ty> } ztd|W Y d}~n
d}~0 0 dS )z
        :param axes: A list of values for each axis.
        :exception OSError: If the font is not a variation font.
        r   N)rA   Z
setvaraxesr   r   )r   r   r   r   r   r   set_variation_by_axes6  s    z"FreeTypeFont.set_variation_by_axes)Nr   r   rL   N)rL   NNN)rL   NNNr   N)NNNr   )Nr   NNr   )rL   NNNr   Nr   )NNNNN)r
   r   r   rT   rk   rn   rp   ru   rx   rz   rS   rR   rE   r   r   rM   r   r   r   r   r   r   r   r   r   r   r   rU      sd   
,
P      
C    
H     
C       
V
c 
rU   c                   @   s<   e Zd ZdZdddZdd Zddd	Zd
d Zdd ZdS )TransposedFontz,Wrapper for writing rotated or mirrored textNc                 C   s   || _ || _dS )a  
        Wrapper that creates a transposed font from any existing font
        object.

        :param font: A font object.
        :param orientation: An optional orientation.  If given, this should
            be one of Image.Transpose.FLIP_LEFT_RIGHT, Image.Transpose.FLIP_TOP_BOTTOM,
            Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_180, or
            Image.Transpose.ROTATE_270.
        N)rA   orientation)r   rA   r   r   r   r   rk   D  s    zTransposedFont.__init__c                 O   sx   t ddd t . tjdtd | j|\}}W d   n1 sH0    Y  | jtj	j
tj	jfv rp||fS ||fS )zj
        .. deprecated:: 9.2.0

        Use :py:meth:`.getbbox` or :py:meth:`.getlength` instead.
        rE   r   rF   r   r   N)r   rb   r   r   r   rA   rE   r   r   	Transpose	ROTATE_90
ROTATE_270)r   rI   rJ   rK   whr   r   r   rE   R  s    
.zTransposedFont.getsizerL   c                 O   s6   | j j||g|R i |}| jd ur2|| jS |S rl   )rA   rM   r   	transpose)r   rI   r-   rJ   rK   rB   r   r   r   rM   `  s    
zTransposedFont.getmaskc           
      O   s`   | j j|g|R i |\}}}}|| }|| }	| jtjjtjjfv rTdd|	|fS dd||	fS )Nr   )rA   rR   r   r   r   r   r   )
r   rI   rJ   rK   r   r   rightbottomrP   rQ   r   r   r   rR   f  s    "zTransposedFont.getbboxc                 O   s8   | j tjjtjjfv rtd| jj|g|R i |S )Nz>text length is undefined for text rotated by 90 or 270 degrees)r   r   r   r   r   
ValueErrorrA   rS   rH   r   r   r   rS   p  s
    zTransposedFont.getlength)N)rL   )	r
   r   r   rT   rk   rE   rM   rR   rS   r   r   r   r   r   A  s   


r   c                 C   s   t  }||  |S )a
  
    Load a font file.  This function loads a font object from the given
    bitmap font file, and returns the corresponding font object.

    :param filename: Name of font file.
    :return: A font object.
    :exception OSError: If the file could not be read.
    )r"   r6   )r1   rY   r   r   r   r?   x  s    	
r?   r   rL   c                    s   fdd}z
|| W S  t y   t| s6 tj| }g }tjdkrvtjd}|r|	tj
|d nZtjdv rtjdd}	|	sd	}	|d
d |	dD 7 }n tjdkr|ddtjdg7 }tj|d }
d}|D ]}t|D ]\}}}|D ]}|
r:||kr:|tj
||       Y S |
stj|d |krtj
||}tj|d dkr||       Y S |
s|du r|}qqq|r|| Y S  Y n0 dS )a{	  
    Load a TrueType or OpenType font from a file or file-like object,
    and create a font object.
    This function loads a font object from the given file or file-like
    object, and creates a font object for a font of the given size.

    Pillow uses FreeType to open font files. If you are opening many fonts
    simultaneously on Windows, be aware that Windows limits the number of files
    that can be open in C at once to 512. If you approach that limit, an
    ``OSError`` may be thrown, reporting that FreeType "cannot open resource".

    This function requires the _imagingft service.

    :param font: A filename or file-like object containing a TrueType font.
                 If the file is not found in this filename, the loader may also
                 search in other directories, such as the :file:`fonts/`
                 directory on Windows or :file:`/Library/Fonts/`,
                 :file:`/System/Library/Fonts/` and :file:`~/Library/Fonts/` on
                 macOS.

    :param size: The requested size, in pixels.
    :param index: Which font face to load (default is first available face).
    :param encoding: Which font encoding to use (default is Unicode). Possible
                     encodings include (see the FreeType documentation for more
                     information):

                     * "unic" (Unicode)
                     * "symb" (Microsoft Symbol)
                     * "ADOB" (Adobe Standard)
                     * "ADBE" (Adobe Expert)
                     * "ADBC" (Adobe Custom)
                     * "armn" (Apple Roman)
                     * "sjis" (Shift JIS)
                     * "gb  " (PRC)
                     * "big5"
                     * "wans" (Extended Wansung)
                     * "joha" (Johab)
                     * "lat1" (Latin-1)

                     This specifies the character set to use. It does not alter the
                     encoding of any text provided in subsequent operations.
    :param layout_engine: Which layout engine to use, if available:
                     :data:`.ImageFont.Layout.BASIC` or :data:`.ImageFont.Layout.RAQM`.

                     You can check support for Raqm layout using
                     :py:func:`PIL.features.check_feature` with ``feature="raqm"``.

                     .. versionadded:: 4.2.0
    :return: A font object.
    :exception OSError: If the file could not be read.
    c                    s   t |  S rl   )rU   )rA   r[   r\   r]   r^   r   r   freetype  s    ztruetype.<locals>.freetyper`   WINDIRfonts)linuxZlinux2XDG_DATA_DIRSrL   z
/usr/sharec                 S   s   g | ]}t j|d qS )r   )r)   r*   join)r   Zlindirr   r   r   r     r   ztruetype.<locals>.<listcomp>:darwinz/Library/Fontsz/System/Library/Fontsz~/Library/Fontsr   Nr   z.ttf)r.   r   r)   r*   basenamerd   re   environgetr<   r   r:   
expanduserr+   walk)rA   r^   r\   r[   r]   r   Zttf_filenamedirswindirZlindirsr4   Z%first_font_with_a_different_extension	directoryZwalkrootZwalkdirZwalkfilenamesZwalkfilenamefontpathr   r   r   truetype  sN    5




"r   c              	   C   s`   t jD ]L}t|rt| ts&| d} zttj|| W   S  t	yP   Y q0 qt	ddS )z
    Load font file. Same as :py:func:`~PIL.ImageFont.load`, but searches for a
    bitmap font along the Python path.

    :param filename: Name of font file.
    :return: A font object.
    :exception OSError: If the file could not be read.
    zutf-8zcannot find font fileN)
rd   r*   r   rf   rs   ri   r?   r)   r   r.   )r1   r   r   r   r   	load_path  s    	


r   c               	   C   s0   t  } | ttdtttd | S )zi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AAYAAAAL
AAgABgAAAAD/+AAFAAEACwAAABAACQAGAAAAAP/5AAUAAAAQAAAAFQAHAAYAAP////oABQAAABUA
AAAbAAYABgAAAAH/+QAE//wAGwAAAB4AAwAGAAAAAf/5AAQAAQAeAAAAIQAIAAYAAAAB//kABAAB
ACEAAAAkAAgABgAAAAD/+QAE//0AJAAAACgABAAGAAAAAP/6AAX//wAoAAAALQAFAAYAAAAB//8A
BAACAC0AAAAwAAMABgAAAAD//AAF//0AMAAAADUAAQAGAAAAAf//AAMAAAA1AAAANwABAAYAAAAB
//kABQABADcAAAA7AAgABgAAAAD/+QAFAAAAOwAAAEAABwAGAAAAAP/5AAYAAABAAAAARgAHAAYA
AAAA//kABQAAAEYAAABLAAcABgAAAAD/+QAFAAAASwAAAFAABwAGAAAAAP/5AAYAAABQAAAAVgAH
AAYAAAAA//kABQAAAFYAAABbAAcABgAAAAD/+QAFAAAAWwAAAGAABwAGAAAAAP/5AAUAAABgAAAA
ZQAHAAYAAAAA//kABQAAAGUAAABqAAcABgAAAAD/+QAFAAAAagAAAG8ABwAGAAAAAf/8AAMAAABv
AAAAcQAEAAYAAAAA//wAAwACAHEAAAB0AAYABgAAAAD/+gAE//8AdAAAAHgABQAGAAAAAP/7AAT/
/gB4AAAAfAADAAYAAAAB//oABf//AHwAAACAAAUABgAAAAD/+gAFAAAAgAAAAIUABgAGAAAAAP/5
AAYAAQCFAAAAiwAIAAYAAP////oABgAAAIsAAACSAAYABgAA////+gAFAAAAkgAAAJgABgAGAAAA
AP/6AAUAAACYAAAAnQAGAAYAAP////oABQAAAJ0AAACjAAYABgAA////+gAFAAAAowAAAKkABgAG
AAD////6AAUAAACpAAAArwAGAAYAAAAA//oABQAAAK8AAAC0AAYABgAA////+gAGAAAAtAAAALsA
BgAGAAAAAP/6AAQAAAC7AAAAvwAGAAYAAP////oABQAAAL8AAADFAAYABgAA////+gAGAAAAxQAA
AMwABgAGAAD////6AAUAAADMAAAA0gAGAAYAAP////oABQAAANIAAADYAAYABgAA////+gAGAAAA
2AAAAN8ABgAGAAAAAP/6AAUAAADfAAAA5AAGAAYAAP////oABQAAAOQAAADqAAYABgAAAAD/+gAF
AAEA6gAAAO8ABwAGAAD////6AAYAAADvAAAA9gAGAAYAAAAA//oABQAAAPYAAAD7AAYABgAA////
+gAFAAAA+wAAAQEABgAGAAD////6AAYAAAEBAAABCAAGAAYAAP////oABgAAAQgAAAEPAAYABgAA
////+gAGAAABDwAAARYABgAGAAAAAP/6AAYAAAEWAAABHAAGAAYAAP////oABgAAARwAAAEjAAYA
BgAAAAD/+gAFAAABIwAAASgABgAGAAAAAf/5AAQAAQEoAAABKwAIAAYAAAAA//kABAABASsAAAEv
AAgABgAAAAH/+QAEAAEBLwAAATIACAAGAAAAAP/5AAX//AEyAAABNwADAAYAAAAAAAEABgACATcA
AAE9AAEABgAAAAH/+QAE//wBPQAAAUAAAwAGAAAAAP/7AAYAAAFAAAABRgAFAAYAAP////kABQAA
AUYAAAFMAAcABgAAAAD/+wAFAAABTAAAAVEABQAGAAAAAP/5AAYAAAFRAAABVwAHAAYAAAAA//sA
BQAAAVcAAAFcAAUABgAAAAD/+QAFAAABXAAAAWEABwAGAAAAAP/7AAYAAgFhAAABZwAHAAYAAP//
//kABQAAAWcAAAFtAAcABgAAAAD/+QAGAAABbQAAAXMABwAGAAAAAP/5AAQAAgFzAAABdwAJAAYA
AP////kABgAAAXcAAAF+AAcABgAAAAD/+QAGAAABfgAAAYQABwAGAAD////7AAUAAAGEAAABigAF
AAYAAP////sABQAAAYoAAAGQAAUABgAAAAD/+wAFAAABkAAAAZUABQAGAAD////7AAUAAgGVAAAB
mwAHAAYAAAAA//sABgACAZsAAAGhAAcABgAAAAD/+wAGAAABoQAAAacABQAGAAAAAP/7AAYAAAGn
AAABrQAFAAYAAAAA//kABgAAAa0AAAGzAAcABgAA////+wAGAAABswAAAboABQAGAAD////7AAUA
AAG6AAABwAAFAAYAAP////sABgAAAcAAAAHHAAUABgAAAAD/+wAGAAABxw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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAB
//sAAwACAecAAAHpAAcABgAAAAD/+QAFAAEB6QAAAe4ACAAGAAAAAP/5AAYAAAHuAAAB9AAHAAYA
AAAA//oABf//AfQAAAH5AAUABgAAAAD/+QAGAAAB+QAAAf8ABwAGAAAAAv/5AAMAAgH/AAACAAAJ
AAYAAAAA//kABQABAgAAAAIFAAgABgAAAAH/+gAE//sCBQAAAggAAQAGAAAAAP/5AAYAAAIIAAAC
DgAHAAYAAAAB//kABf/+Ag4AAAISAAUABgAA////+wAGAAACEgAAAhkABQAGAAAAAP/7AAX//gIZ
AAACHgADAAYAAAAA//wABf/9Ah4AAAIjAAEABgAAAAD/+QAHAAACIwAAAioABwAGAAAAAP/6AAT/
+wIqAAACLgABAAYAAAAA//kABP/8Ai4AAAIyAAMABgAAAAD/+gAFAAACMgAAAjcABgAGAAAAAf/5
AAT//QI3AAACOgAEAAYAAAAB//kABP/9AjoAAAI9AAQABgAAAAL/+QAE//sCPQAAAj8AAgAGAAD/
///7AAYAAgI/AAACRgAHAAYAAAAA//kABgABAkYAAAJMAAgABgAAAAH//AAD//0CTAAAAk4AAQAG
AAAAAf//AAQAAgJOAAACUQADAAYAAAAB//kABP/9AlEAAAJUAAQABgAAAAH/+QAF//4CVAAAAlgA
BQAGAAD////7AAYAAAJYAAACXwAFAAYAAP////kABgAAAl8AAAJmAAcABgAA////+QAGAAACZgAA
Am0ABwAGAAD////5AAYAAAJtAAACdAAHAAYAAAAA//sABQACAnQAAAJ5AAcABgAA////9wAGAAAC
eQAAAoAACQAGAAD////3AAYAAAKAAAAChwAJAAYAAP////cABgAAAocAAAKOAAkABgAA////9wAG
AAACjgAAApUACQAGAAD////4AAYAAAKVAAACnAAIAAYAAP////cABgAAApwAAAKjAAkABgAA////
+gAGAAACowAAAqoABgAGAAAAAP/6AAUAAgKqAAACrwAIAAYAAP////cABQAAAq8AAAK1AAkABgAA
////9wAFAAACtQAAArsACQAGAAD////3AAUAAAK7AAACwQAJAAYAAP////gABQAAAsEAAALHAAgA
BgAAAAD/9wAEAAACxwAAAssACQAGAAAAAP/3AAQAAALLAAACzwAJAAYAAAAA//cABAAAAs8AAALT
AAkABgAAAAD/+AAEAAAC0wAAAtcACAAGAAD////6AAUAAALXAAAC3QAGAAYAAP////cABgAAAt0A
AALkAAkABgAAAAD/9wAFAAAC5AAAAukACQAGAAAAAP/3AAUAAALpAAAC7gAJAAYAAAAA//cABQAA
Au4AAALzAAkABgAAAAD/9wAFAAAC8wAAAvgACQAGAAAAAP/4AAUAAAL4AAAC/QAIAAYAAAAA//oA
Bf//Av0AAAMCAAUABgAA////+gAGAAADAgAAAwkABgAGAAD////3AAYAAAMJAAADEAAJAAYAAP//
//cABgAAAxAAAAMXAAkABgAA////9wAGAAADFwAAAx4ACQAGAAD////4AAYAAAAAAAoABwASAAYA
AP////cABgAAAAcACgAOABMABgAA////+gAFAAAADgAKABQAEAAGAAD////6AAYAAAAUAAoAGwAQ
AAYAAAAA//gABgAAABsACgAhABIABgAAAAD/+AAGAAAAIQAKACcAEgAGAAAAAP/4AAYAAAAnAAoA
LQASAAYAAAAA//gABgAAAC0ACgAzABIABgAAAAD/+QAGAAAAMwAKADkAEQAGAAAAAP/3AAYAAAA5
AAoAPwATAAYAAP////sABQAAAD8ACgBFAA8ABgAAAAD/+wAFAAIARQAKAEoAEQAGAAAAAP/4AAUA
AABKAAoATwASAAYAAAAA//gABQAAAE8ACgBUABIABgAAAAD/+AAFAAAAVAAKAFkAEgAGAAAAAP/5
AAUAAABZAAoAXgARAAYAAAAA//gABgAAAF4ACgBkABIABgAAAAD/+AAGAAAAZAAKAGoAEgAGAAAA
AP/4AAYAAABqAAoAcAASAAYAAAAA//kABgAAAHAACgB2ABEABgAAAAD/+AAFAAAAdgAKAHsAEgAG
AAD////4AAYAAAB7AAoAggASAAYAAAAA//gABQAAAIIACgCHABIABgAAAAD/+AAFAAAAhwAKAIwA
EgAGAAAAAP/4AAUAAACMAAoAkQASAAYAAAAA//gABQAAAJEACgCWABIABgAAAAD/+QAFAAAAlgAK
AJsAEQAGAAAAAP/6AAX//wCbAAoAoAAPAAYAAAAA//oABQABAKAACgClABEABgAA////+AAGAAAA
pQAKAKwAEgAGAAD////4AAYAAACsAAoAswASAAYAAP////gABgAAALMACgC6ABIABgAA////+QAG
AAAAugAKAMEAEQAGAAD////4AAYAAgDBAAoAyAAUAAYAAP////kABQACAMgACgDOABMABgAA////
+QAGAAIAzgAKANUAEw==
s  
iVBORw0KGgoAAAANSUhEUgAAAx4AAAAUAQAAAAArMtZoAAAEwElEQVR4nABlAJr/AHVE4czCI/4u
Mc4b7vuds/xzjz5/3/7u/n9vMe7vnfH/9++vPn/xyf5zhxzjt8GHw8+2d83u8x27199/nxuQ6Od9
M43/5z2I+9n9ZtmDBwMQECDRQw/eQIQohJXxpBCNVE6QCCAAAAD//wBlAJr/AgALyj1t/wINwq0g
LeNZUworuN1cjTPIzrTX6ofHWeo3v336qPzfEwRmBnHTtf95/fglZK5N0PDgfRTslpGBvz7LFc4F
IUXBWQGjQ5MGCx34EDFPwXiY4YbYxavpnhHFrk14CDAAAAD//wBlAJr/AgKqRooH2gAgPeggvUAA
Bu2WfgPoAwzRAABAAAAAAACQgLz/3Uv4Gv+gX7BJgDeeGP6AAAD1NMDzKHD7ANWr3loYbxsAD791
NAADfcoIDyP44K/jv4Y63/Z+t98Ovt+ub4T48LAAAAD//wBlAJr/AuplMlADJAAAAGuAphWpqhMx
in0A/fRvAYBABPgBwBUgABBQ/sYAyv9g0bCHgOLoGAAAAAAAREAAwI7nr0ArYpow7aX8//9LaP/9
SjdavWA8ePHeBIKB//81/83ndznOaXx379wAAAD//wBlAJr/AqDxW+D3AABAAbUh/QMnbQag/gAY
AYDAAACgtgD/gOqAAAB5IA/8AAAk+n9w0AAA8AAAmFRJuPo27ciC0cD5oeW4E7KA/wD3ECMAn2tt
y8PgwH8AfAxFzC0JzeAMtratAsC/ffwAAAD//wBlAJr/BGKAyCAA4AAAAvgeYTAwHd1kmQF5chkG
ABoMIHcL5xVpTfQbUqzlAAAErwAQBgAAEOClA5D9il08AEh/tUzdCBsXkbgACED+woQg8Si9VeqY
lODCn7lmF6NhnAEYgAAA/NMIAAAAAAD//2JgjLZgVGBg5Pv/Tvpc8hwGBjYGJADjHDrAwPzAjv/H
/Wf3PzCwtzcwHmBgYGcwbZz8wHaCAQMDOwMDQ8MCBgYOC3W7mp+f0w+wHOYxO3OG+e376hsMZjk3
AAAAAP//YmCMY2A4wMAIN5e5gQETPD6AZisDAwMDgzSDAAPjByiHcQMDAwMDg1nOze1lByRu5/47
c4859311AYNZzg0AAAAA//9iYGDBYihOIIMuwIjGL39/fwffA8b//xv/P2BPtzzHwCBjUQAAAAD/
/yLFBrIBAAAA//9i1HhcwdhizX7u8NZNzyLbvT97bfrMf/QHI8evOwcSqGUJAAAA//9iYBB81iSw
pEE170Qrg5MIYydHqwdDQRMrAwcVrQAAAAD//2J4x7j9AAMDn8Q/BgYLBoaiAwwMjPdvMDBYM1Tv
oJodAAAAAP//Yqo/83+dxePWlxl3npsel9lvLfPcqlE9725C+acfVLMEAAAA//9i+s9gwCoaaGMR
evta/58PTEWzr21hufPjA8N+qlnBwAAAAAD//2JiWLci5v1+HmFXDqcnULE/MxgYGBj+f6CaJQAA
AAD//2Ji2FrkY3iYpYC5qDeGgeEMAwPDvwQBBoYvcTwOVLMEAAAA//9isDBgkP///0EOg9z35v//
Gc/eeW7BwPj5+QGZhANUswMAAAD//2JgqGBgYGBgqEMXlvhMPUsAAAAA//8iYDd1AAAAAP//AwDR
w7IkEbzhVQAAAABJRU5ErkJggg==
)r"   r0   r   base64	b64decoder   r'   rX   r   r   r   load_default  s"    a r   )Nr   r   rL   N)r   r)   rd   rb   r   r   ior   rL   r   
_deprecater   _utilr   r   r	   r   r   r!   r@   r   objectr   r"   rU   r   r?   r   r   r   r   r   r   r   <module>   s6   
x    w7
g