
    h4hG/                    <    d dl mZ ddlmZ ddlmZ  G d d      Zy)    )annotations   )	ImageFont)_Inkc                      e Zd Z	 	 	 	 	 	 d		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
dZddZdddZddZd Z	 	 	 	 	 	 	 	 ddZ	 	 	 d	 	 	 	 	 	 	 ddZ	y)TextNc                    || _         |xs t        j                         | _        || _        || _        || _        || _        || _        d| _	        d| _
        d| _        y)a  
        :param text: String to be drawn.
        :param font: Either an :py:class:`~PIL.ImageFont.ImageFont` instance,
                     :py:class:`~PIL.ImageFont.FreeTypeFont` instance,
                     :py:class:`~PIL.ImageFont.TransposedFont` instance or ``None``. If
                     ``None``, the default font from :py:meth:`.ImageFont.load_default`
                     will be used.
        :param mode: The image mode this will be used with.
        :param spacing: The number of pixels between lines.
        :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 `OpenType docs`_.
                         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`_.
                         Requires libraqm.
        Fr   N)textr   load_defaultfontmodespacing	directionfeatureslanguageembedded_colorstroke_widthstroke_fill)selfr
   r   r   r   r   r   r   s           E/var/www/flask-api/venv/lib/python3.12/site-packages/PIL/ImageText.py__init__zText.__init__   s\    T 	4I224		"  ##$(,    c                H    | j                   dvrd}t        |      d| _        y)z?
        Use embedded color glyphs (COLR, CBDT, SBIX).
        )RGBRGBAz3Embedded color supported only in RGB and RGBA modesTN)r   
ValueErrorr   )r   msgs     r   embed_colorzText.embed_color@   s'     99O+GCS/!"r   c                     || _         || _        y)a  
        :param width: The width of the text stroke.
        :param fill: Color to use for the text stroke when drawing. If not given, will
                     default to the ``fill`` parameter from
                     :py:meth:`.ImageDraw.ImageDraw.text`.
        N)r   r   )r   widthfills      r   strokezText.strokeI   s     "r   c                <    | j                   dv ry| j                  ryy)N)1PIFr$   r   L)r   r   )r   s    r   _get_fontmodezText._get_fontmodeS   s!    99,,  r   c                   t        | j                  t              rdnd}|| j                  v rd}t        |      | j                  j                  | j                  | j                         | j                  | j                  | j                        S )a  
        Returns length (in pixels with 1/64 precision) of text.

        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::

            hello = ImageText.Text("Hello", font).get_length()
            world = ImageText.Text("World", font).get_length()
            helloworld = ImageText.Text("HelloWorld", font).get_length()
            assert hello + world == helloworld

        use::

            hello = (
                ImageText.Text("HelloW", font).get_length() -
                ImageText.Text("W", font).get_length()
            )  # adjusted for kerning
            world = ImageText.Text("World", font).get_length()
            helloworld = ImageText.Text("HelloWorld", font).get_length()
            assert hello + world == helloworld

        or disable kerning with (requires libraqm)::

            hello = ImageText.Text("Hello", font, features=["-kern"]).get_length()
            world = ImageText.Text("World", font, features=["-kern"]).get_length()
            helloworld = ImageText.Text(
                "HelloWorld", font, features=["-kern"]
            ).get_length()
            assert hello + world == helloworld

        :return: Either width for horizontal text, or height for vertical text.
        
   
z&can't measure length of multiline text)

isinstancer
   strr   r   	getlengthr)   r   r   r   )r   split_characterr   s      r   
get_lengthzText.get_length[   ss    T #-TYY"<$%dii':CS/!yy""II NNMMMM
 	
r   c                n   || j                   dk(  rdnd}nt        |      dk7  rd}t        |      t        | j                  t
              r| j                  j                  d      n| j                  j                  d      }t        |      dk(  r||| j                  fgS |d   d	v r| j                   dk7  rd
}t        |      | j                         }| j                  j                  d|d | j                  | j                  | j                        d   | j                  z   | j                  z   }|d   }g }	| j                   dk(  r)|d   }
|D ]  }|	j                  |
|f||f       |
|z  }
 |	S g }d}|D ]\  }| j                  j                  ||| j                   | j                  | j                        }|j                  |       t!        ||      }^ |d   dk(  r|t        |      dz
  |z  dz  z  }n|d   dk(  r|t        |      dz
  |z  z  }d}|D ]  }|d   }
|dz  }|||   z
  }|dv rn&|dk(  r	|
|dz  z  }
n|dk(  r|
|z  }
nd}t        |      |dk(  r|dk7  r|t        |      dz
  k7  rt        |t
              r|j                  d      n|j                  d      }t        |      dkD  r|d   dk(  r	|
|dz  z  }
n|d   dk(  r|
|z  }
|D cg c]?  }| j                  j                  ||| j                   | j                  | j                        A }}d|d   z   }|t#        |      z
  }d}|D ]7  }|	j                  |
|f||f       |
||   |t        |      dz
  z  z   z  }
|dz  }9 ||z  }b|d   dk(  r	|
|dz  z  }
n|d   dk(  r|
|z  }
|	j                  |
|f||f       ||z  } |	S c c}w )Nttbltla   z#anchor must be a 2 character stringr+   r,   r   tbz'anchor not supported for multiline textA   r   mg       @d)leftjustifycenterrightz4align must be "left", "center", "right" or "justify"r>        rl)r   lenr   r-   r
   r.   splitr)   r   getbboxr   r   r   r   appendr/   maxsum)r   xyanchoralignr   linesfontmodeline_spacingtoppartsr=   linewidths	max_width
line_widthidxwidth_differencewordswordword_widthsword_anchoris                         r   _splitzText._split   sb    >!^^u4T$F[A7CS/! $))S) IIOOD!' 	
 u:?+,,!95!8;CS/!%%'II!!    ll	 	 e>>U"a5D %tSk6489$%\ U F I 7!YY00(DNNDMM4==
 j)	:6	7 ayCE
Q,6<<c!E
Q,66C 9$!uq#,vc{#:  //h&,s22Dg%,,DPC$S/) Y&(A-s5zA~- ,6dC+@

3djjQUFV  5zA~!!9+ IO3D#AY#- I-D ).	' !% !II// $ ( $ $ $	' 	' '*F1Io+4s;7G+G($) #D!LL4+{D)IJ KN5EUVW5X$XXDFA# |+  !9#,s22DAY#%,,DtSk6489|#s9$v 9	's   AN2c           
        d}| j                         }| j                  |||      D ]  \  }}}| j                  j                  ||| j                  | j
                  | j                  | j                  |      }|d   |d   z   |d   |d   z   |d   |d   z   |d   |d   z   f}||}t        |d   |d         t        |d   |d         t        |d   |d         t        |d   |d         f} ||d   |d   |d   |d   fS |S )a  
        Returns bounding box (in pixels) of text.

        Use :py:meth:`get_length` 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.

        :param xy: The anchor coordinates of the text.
        :param anchor: The text anchor alignment. Determines the relative location of
                       the anchor to the text. The default alignment is top left,
                       specifically ``la`` for horizontal text and ``lt`` for
                       vertical text. See :ref:`text-anchors` for details.
        :param align: For multiline text, ``"left"``, ``"center"``, ``"right"`` or
                      ``"justify"`` determines the relative alignment of lines. Use the
                      ``anchor`` parameter to specify the alignment to ``xy``.

        :return: ``(left, top, right, bottom)`` bounding box
        Nr   r   r6   r9   )
r)   r^   r   rG   r   r   r   r   minrI   )r   rK   rL   rM   bboxrO   rS   	bbox_lines           r   get_bboxzText.get_bbox  sF   0 :>%%' $B > 	B		))!!I !r!u$!r!u$!r!u$!r!u$	I |  Q1.Q1.Q1.Q1.	'	4 <a5"Q%A1--r   )Nr      NNN)r
   zstr | bytesr   zNImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFont | Noner   r.   r   floatr   
str | Noner   zlist[str] | Noner   rf   returnNone)rg   rh   )r   N)r    re   r!   z_Ink | Nonerg   rh   )rg   r.   )rK   tuple[float, float]rL   rf   rM   r.   rg   z2list[tuple[tuple[float, float], str, str | bytes]]))r   r   Nr=   )rK   ri   rL   rf   rM   r.   rg   z!tuple[float, float, float, float])
__name__
__module____qualname__r   r   r"   r)   r1   r^   rc    r   r   r   r      s      $%)#6-6-	6- 6- 6- 6- #6- 6- 
6-p# 4
lu%u/9uBEu	;ur #)!	66 6 	6
 
+6r   r   N)
__future__r    r   _typingr   r   rm   r   r   <module>rq      s    "  w wr   