CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
ImageText.cpython-310.pyc143 linesDownload Raw Back to __pycache__
1o

2��Yi�0�@s6ddlmZddlmZddlmZGdd�d�ZdS)�)�annotations�)�	ImageFont)�_Inkc@sjeZdZ						d-d.dd�Zd/dd�Zd0d1dd�Zd2dd�Zd3dd �Zd4d&d'�Z	(		)d5d6d+d,�Z	dS)7�TextN�RGB��text�str | bytes�font�NImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFont | None�mode�str�spacing�float�	direction�3str | None�features�list[str] | None�language�return�NonecCsH||_|pt��|_||_||_||_||_||_d|_	d|_4d|_dS)a�5        :param text: String to be drawn.6        :param font: Either an :py:class:`~PIL.ImageFont.ImageFont` instance,7                     :py:class:`~PIL.ImageFont.FreeTypeFont` instance,8                     :py:class:`~PIL.ImageFont.TransposedFont` instance or ``None``. If9                     ``None``, the default font from :py:meth:`.ImageFont.load_default`10                     will be used.11        :param mode: The image mode this will be used with.12        :param spacing: The number of pixels between lines.13        :param direction: Direction of the text. It can be ``"rtl"`` (right to left),14                          ``"ltr"`` (left to right) or ``"ttb"`` (top to bottom).15                          Requires libraqm.16        :param features: A list of OpenType font features to be used during text17                         layout. This is usually used to turn on optional font features18                         that are not enabled by default, for example ``"dlig"`` or19                         ``"ss01"``, but can be also used to turn off default font20                         features, for example ``"-liga"`` to disable ligatures or21                         ``"-kern"`` to disable kerning.  To get all supported22                         features, see `OpenType docs`_.23                         Requires libraqm.24        :param language: Language of the text. Different languages may use25                         different glyph shapes or ligatures. This parameter tells26                         the font which language the text is in, and to apply the27                         correct substitutions as appropriate, if available.28                         It should be a `BCP 47 language code`_.29                         Requires libraqm.30        FrN)r	rZload_defaultrr
rrrr�embedded_color�stroke_width�stroke_fill)�selfr	rr
rrrr�r�wE:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\PIL/ImageText.py�__init__s*31z
Text.__init__cCs |jdvrd}t|��d|_dS)z?32        Use embedded color glyphs (COLR, CBDT, SBIX).33        )r�RGBAz3Embedded color supported only in RGB and RGBA modesTN)r
�34ValueErrorr)r�msgrrr�embed_color@s3536zText.embed_colorr�width�fill�_Ink | NonecCs||_||_dS)a37        :param width: The width of the text stroke.38        :param fill: Color to use for the text stroke when drawing. If not given, will39                     default to the ``fill`` parameter from40                     :py:meth:`.ImageDraw.ImageDraw.text`.41        N)rr)rr#r$rrr�strokeIs42zText.strokecCs|jdvrdS|jrdSdS)N)�1�P�I�Fr'r�L)r
r)rrrr�
_get_fontmodeSs4344zText._get_fontmodecCsRt|jt�rd|jv}nd|jv}|rd}t|��|j�|j|��|j|j|j	�S)a�45        Returns length (in pixels with 1/64 precision) of text.46 47        This is the amount by which following text should be offset.48        Text bounding box may extend past the length in some fonts,49        e.g. when using italics or accents.50 51        The result is returned as a float; it is a whole number if using basic layout.52 53        Note that the sum of two lengths may not equal the length of a concatenated54        string due to kerning. If you need to adjust for kerning, include the following55        character and subtract its length.56 57        For example, instead of::58 59            hello = ImageText.Text("Hello", font).get_length()60            world = ImageText.Text("World", font).get_length()61            helloworld = ImageText.Text("HelloWorld", font).get_length()62            assert hello + world == helloworld63 64        use::65 66            hello = (67                ImageText.Text("HelloW", font).get_length() -68                ImageText.Text("W", font).get_length()69            )  # adjusted for kerning70            world = ImageText.Text("World", font).get_length()71            helloworld = ImageText.Text("HelloWorld", font).get_length()72            assert hello + world == helloworld73 74        or disable kerning with (requires libraqm)::75 76            hello = ImageText.Text("Hello", font, features=["-kern"]).get_length()77            world = ImageText.Text("World", font, features=["-kern"]).get_length()78            helloworld = ImageText.Text(79                "HelloWorld", font, features=["-kern"]80            ).get_length()81            assert hello + world == helloworld82 83        :return: Either width for horizontal text, or height for vertical text.84        �85�86z&can't measure length of multiline text)8788isinstancer	rr r�	getlengthr,rrr)r�	multiliner!rrr�89get_length[s*90�zText.get_length�xy�tuple[float, float]�anchor�align�2list[tuple[tuple[float, float], str, str | bytes]]csT|dur�jdkrdnd}nt|�dkrd}t|��t�jt�r&�j�d�n�j�d�}t|�dkr9||�jfgS|dd	vrJ�jdkrJd91}t|�������j�	d�d�j92�j�j�d�j�j
}|d}g}�jdkr�|d
}	|D]}93|�|	|f||94f�|	|7}	qu|Sg}d
}|D]}95�j�|96��j�j97�j�}
|�|
�t||
�}q�|ddkr�|t|�d|d8}n|ddkr�|t|�d|8}d}|D]�}98|d
}	|d7}|||}|dvr�n|dkr�|	|d7}	n|dkr�|	|7}	nd}t|��|dk�r�|d
k�r�|t|�dk�r�t|99t��r|100�d�n|101�d�}t|�dk�r�|d
dk�r6|	|d8}	n|d
dk�rA|	|8}	��fdd�|D�}d|d}|t|�}d
}|D]}|�|	|f||f�|	|||t|�d7}	|d7}�q[||7}q�|d
dk�r�|	|d8}	n|d
dk�r�|	|8}	|�|	|f||102f�||7}q�|S)NZttb�ltZla�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"rA� � �rc	s&g|]}�j�|��j�j�j��qSr)rr0rrr)�.0�word��fontmoderrr�103<listcomp>�s���zText._split.<locals>.<listcomp>�l)r�lenr r/r	r�splitr,r�getbboxrrrr�appendr0�max�sum)rr3r5r6r!�linesZline_spacing�top�partsr@�line�widths�	max_widthZ104line_width�idxZwidth_difference�wordsZword_widthsZword_anchor�irHrrIr�_split�s�105�106����	��
107108L��109110111112��113114zText._split�rrr@�!tuple[float, float, float, float]c115Cs�d}|��}|�|||�D]\\}}}|j�|||j|j|j|j|�}|d|d|d|d|d|d|d|df}|durG|}q
t|d|d�t|d|d�t	|d|d�t	|d|d�f}q
|duspJ�|S)a�116        Returns bounding box (in pixels) of text.117 118        Use :py:meth:`get_length` to get the offset of following text with 1/64 pixel119        precision. The bounding box includes extra margins for some fonts, e.g. italics120        or accents.121 122        :param xy: The anchor coordinates of the text.123        :param anchor: The text anchor alignment. Determines the relative location of124                       the anchor to the text. The default alignment is top left,125                       specifically ``la`` for horizontal text and ``lt`` for126                       vertical text. See :ref:`text-anchors` for details.127        :param align: For multiline text, ``"left"``, ``"center"``, ``"right"`` or128                      ``"justify"`` determines the relative alignment of lines. Use the129                      ``anchor`` parameter to specify the alignment to ``xy``.130 131        :return: ``(left, top, right, bottom)`` bounding box132        Nrrr9r<)133r,r\rrOrrrr�minrQ)rr3r5r6ZbboxrJrVZ	bbox_linerrr�get_bboxs4�134��z
Text.get_bbox)NrrNNN)r	r135rrr
rrrrrrrrrrr)rr)rN)r#rr$r%rr)rr)rr)r3r4r5rr6rrr7)r]Nr@)r3r4r5rr6rrr^)136�__name__�137__module__�__qualname__rr"r&r,r2r\r`rrrrrs"	�1388	139 140 1411429y�rN)�143__future__r�rZ_typingrrrrrr�<module>s
Aluode/PerceptionLabPortable · CoolFace