Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
ImageText.cpython-313.pyc210 linesDownload Raw Back to __pycache__
1�

2v�j�J����SSKJr SSKrSSKrSSKJrJrJr SSKJ	r	 SSK3Jr \	R\	R-\	R-r"SS\5r"S	S4\\5r"SS\\5rg)
�)�annotationsN)�AnyStr�Generic�5NamedTuple�)�	ImageFont)�_Inkc�>�\rSrSr%S\S'S\S'S\S'S\S'S	rg6)�_Line�
�float�x�y�str�anchor�str | bytes�text�N)�__name__�7__module__�__qualname__�__firstlineno__�__annotations__�__static_attributes__r��SD:\code\apps\devtools\python\user_packages\Python313\site-packages\PIL/ImageText.pyrr
s���H��H��K�8�rrc�Z�\rSrSr%/rS\S'SrSrS	S9SjjrSSjr	Sr10g)�_Wrap�zlist[AnyStr]�linesrNc�8�XlX lX0lX@lURRn[	U[115(aSOSnUn[R"[	U[125(aSOSU5GHsn[R"[	U[135(aSOSU5n	U	(ayURU5(d GO>[U	5HOup�U14S:waURU5(d O0U=R[U5-
sl15U[U5SnMQ UnXx-nURRX�R5SU::aUnM�U(aURU5(d O�[U5nUR5nU[U5-16UlURRX�R5SU:�aUc
S	n
[U
5e OUnGMv U(aURU5 XPRSUlg)17N�rz\s*\S+s\s*\S+z18[^\S\n]*\ns19[^\S\n]*\nr�zWord does not fit within line)r�width�height�font�20isinstancer�re�findall�add_line�	enumerate�position�len�	_get_bbox�lstrip�offset�21ValueError�remaining_text)�selfrr$r%r&�22input_text�emptystring�line�word�newlines�i�new_line�original_length�msgs              r�__init__�_Wrap.__init__s���#'�	��23����	��Y�Y�^�^�24�&�z�3�7�7�b�S�����J�J�#�J��4�4�I�*�j�25�D��z�z�!+�J��!<�!<�
�.�RV��H���}�}�T�*�*��(��2�G�A��A�v�d�m�m�K�&@�&@���M�M�S��Y�.�M���D�	��,�D�	 3�26#���{�H��y�y�"�"�8�Y�Y�7��:�e�C�����D�M�M�$�/�/��!�$�i�O��;�;�=�D�)�C��I�5�D�K��y�y�"�"�4���3�A�6��>��<�9�C�$�S�/�)���D�G27�J��
�
�d�#�&0����&A��rc�p�URU/-nURbaURRUS9SRnURRXR5SnX4-UR:�agX lU=R[U5UR--
slSUl	g)N)r ������FrT)28r r%r�_splitrr.r&r,r-r0)r3r6r �last_line_y�last_line_heights     rr*�_Wrap.add_lineRs����29�30�d�V�#���;�;�"��)�)�*�*��*�7��;�=�=�K�#�y�y�2�2�4���C�A�F���-����;���31��
�
��T��T�[�[�0�0�
����r)r&r%r r0r2rr$�NN)32rzText[AnyStr]r$�intr%�33int | Noner&�Font | None�return�None)r6rrJ�bool)rrrrr rr,r0r=r*rrrrrrs_���E�<���H�
�F�"� �7B��7B��7B��	7B�34�7B�35�
7B�rrrc��\rSrSrS
SSjjrSSjrSSSjjrSSjrSSSjjrSSjr	SSS	jjr36SSS37jjrSSSjjrSr
g)�Text�`Nc��XlU=(d [R"5UlX0lX@lXPlX`lXplSUl	SUl38SUlg)a39:param text: String to be drawn.40:param font: Either an :py:class:`~PIL.ImageFont.ImageFont` instance,41             :py:class:`~PIL.ImageFont.FreeTypeFont` instance,42             :py:class:`~PIL.ImageFont.TransposedFont` instance or ``None``. If43             ``None``, the default font from :py:meth:`.ImageFont.load_default`44             will be used.45:param mode: The image mode this will be used with.46:param spacing: The number of pixels between lines.47:param direction: Direction of the text. It can be ``"rtl"`` (right to left),48                  ``"ltr"`` (left to right) or ``"ttb"`` (top to bottom).49                  Requires libraqm.50:param features: A list of OpenType font features to be used during text51                 layout. This is usually used to turn on optional font features52                 that are not enabled by default, for example ``"dlig"`` or53                 ``"ss01"``, but can be also used to turn off default font54                 features, for example ``"-liga"`` to disable ligatures or55                 ``"-kern"`` to disable kerning.  To get all supported56                 features, see `OpenType docs`_.57                 Requires libraqm.58:param language: Language of the text. Different languages may use59                 different glyph shapes or ligatures. This parameter tells60                 the font which language the text is in, and to apply the61                 correct substitutions as appropriate, if available.62                 It should be a `BCP 47 language code`_.63                 Requires libraqm.64FrN)rr�load_defaultr&�mode�spacing�	direction�features�language�embedded_color�stroke_width�stroke_fill)r3rr&rRrSrTrUrVs        rr=�
Text.__init__asP��J!�	��4�I�2�2�4��	��	���"�� �
� �
�#���#$���(,��rc�L�URS;a
Sn[U5eSUlg)z/65Use embedded color glyphs (COLR, CBDT, SBIX).66)�RGB�RGBAz3Embedded color supported only in RGB and RGBA modesTN)rRr1rW)r3r<s  r�embed_color�Text.embed_color�s'���9�9�O�+�G�C��S�/�!�"��rc��XlX lg)z�67:param width: The width of the text stroke.68:param fill: Color to use for the text stroke when drawing. If not given, will69             default to the ``fill`` parameter from70             :py:meth:`.ImageDraw.ImageDraw.text`.71N)rXrY)r3r$�fills   r�stroke�Text.stroke�s��"���rc�J�URS;agUR(agg)N)�1�P�I�Frer]�L)rRrW)r3s r�
_get_fontmode�Text._get_fontmode�s!���9�9�,�,��
�
 �
 ��rc72��[UR[R5(a
Sn[	U5eUR73S;a
Sn[	U5eUc[
XU5nGO[UR[R5(d
Sn[	U5eUc
Sn[	U5e[U[5(aSnOUup6URn[
XX'5nUS:Xa�UR(dg[R"UR5nUR(aZU[US5:Xa
S	n[	U5eUS-nURRUS749n[
XX'5nUR(aMZXplO�UR(a
S	n[	U5e[R"UR5nUR(dQX�:Xa
S	n[	U5eUS-
nURRUS759nUn	[
XX'5nUR(dMQUS-nX�RR:waURRUS769UlW	nUR(a�[!URURUR"UR$UR77UR&UR(S9n78UR*U79lUR,U80lUR.U81lOSn82[UR0[5(aSOS
nUR3UR45UlU83$)a/84Wrap text to fit within a given width.85 86:param width: The width to fit within.87:param height: An optional height limit. Any text that does not fit within this88               will be returned as a new :py:class:`.Text` object.89:param scaling: An optional directive to scale the text, either "grow" as much90                as possible within the given dimensions, or "shrink" until it91                fits. It can also be a tuple of (direction, limit), with an92                integer limit to stop scaling at.93 94:returns: An :py:class:`.Text` object, or None.95zTransposedFont not supported)N�ltrzOnly ltr direction supportedNz$'scaling' only supports FreeTypeFontz'scaling' requires 'height'r�shrinkzText could not be scaled)�size)rr&rRrSrTrUrV�96�97)r'r&r�TransposedFontr1rTr�FreeTypeFontrr2�math�ceilro�max�font_variant�floorrNrRrSrUrVrWrXrYr�joinr )r3r$r%�scalingr<�wrap�limitr&ro�	last_wrapr�newlines            rr{�	Text.wrap�s���&�d�i�i��!9�!9�:�:�0�C��S�/�!��>�>��.�0�C��S�/�!��?���f�-�D��d�i�i��)?�)?�@�@�<�� ��o�%��~�3�� ��o�%��'�3�'�'���!(����9�9�D���f�3�D��(�"��*�*���y�y����+���)�)��s�5�!�}�,�8��(��o�-��A�I�D��9�9�1�1�t�1�<�D� ��f�;�D�
�)�)�)�!�	��&�&�4�C�$�S�/�)��z�z�$�)�)�,���-�-��}�8��(��o�-��A�I�D��9�9�1�1�t�1�<�D� $�I� ��f�;�D��-�-�-���	���9�9�>�>�)� $�	�	� 6� 6�D� 6� A�D�I� �������(�(��Y�Y��Y�Y�����.�.��������D�#'�"5�"5�D�� $� 1� 1�D��#�/�/�D���D�$�T�Y�Y��4�4�$�%���L�L����,��	��rc�P�[UR[5(aSUR;nOSUR;nU(a
Sn[U5eURRURUR
5URURUR5$)a�98Returns length (in pixels with 1/64 precision) of text.99 100This is the amount by which following text should be offset.101Text bounding box may extend past the length in some fonts,102e.g. when using italics or accents.103 104The result is returned as a float; it is a whole number if using basic layout.105 106Note that the sum of two lengths may not equal the length of a concatenated107string due to kerning. If you need to adjust for kerning, include the following108character and subtract its length.109 110For example, instead of::111 112    hello = ImageText.Text("Hello", font).get_length()113    world = ImageText.Text("World", font).get_length()114    helloworld = ImageText.Text("HelloWorld", font).get_length()115    assert hello + world == helloworld116 117use::118 119    hello = (120        ImageText.Text("HelloW", font).get_length() -121        ImageText.Text("W", font).get_length()122    )  # adjusted for kerning123    world = ImageText.Text("World", font).get_length()124    helloworld = ImageText.Text("HelloWorld", font).get_length()125    assert hello + world == helloworld126 127or disable kerning with (requires libraqm)::128 129    hello = ImageText.Text("Hello", font, features=["-kern"]).get_length()130    world = ImageText.Text("World", font, features=["-kern"]).get_length()131    helloworld = ImageText.Text(132        "HelloWorld", font, features=["-kern"]133    ).get_length()134    assert hello + world == helloworld135 136:return: Either width for horizontal text, or height for vertical text.137rprqz&can't measure length of multiline text)138r'rrr1r&�	getlengthrjrTrUrV)r3�	multiliner<s   r�139get_length�Text.get_lengths���T�d�i�i��%�%���	�	�)�I�����*�I��:�C��S�/�!��y�y�"�"��I�I���� ��N�N��M�M��M�M�140�	141rc���UcURS:XaSOSnO[U5S:wa
Sn[U5eUcU[UR[1425(aURR
S5OURR
S5n[U5S:Xa[US	USX$S	5/$USS143;aURS:wa
Sn[U5eUR5nURRSUSURURUR5S
UR-UR-nUSn/n	URS:Xa/US	n144UH"nU	R[X�X+55 X�-
n145M$ U	$/nS	n
UH[nURR!X�URURUR5nURU5 [#X�5n
M] USS:XaU[U5S-146U-S--nOUSS:XaU[U5S-147U--nSnUGH�nUS	n148US-
nX�U-149nUS;aO(US:Xa	U150US--
n151OUS:XaU152U-
n153O
Sn[U5eUS:XGa.US	:wGa'U[U5S-154:wGa[U[1555(aUR
S5OUR
S5n[U5S:�a�US	S:XaX�S--n156O
US	S:XaX�-n157UVs/sH@nURR!UUURURUR5PMB nnSUS-nU
[%U5-158nS	nUH>nU	R[X�UU55 U159UUU[U5S-160---
n161US-
nM@ X�-
nGMyUS	S:Xa	U162US--n163OUS	S:XaU164U-n165U	R[X�X+55 X�-
nGM� U	$s snf)N�ttb�lt�lar#z#anchor must be a 2 character stringrprqrr�tbz'anchor not supported for multiline text�ArA�mg@�dr@)�left�justify�center�rightz4align must be "left", "center", "right" or "justify"r�� � �r�l)rTr-r1r'rr�splitrrjr&�getbboxrUrVrXrS�appendr�rv�sum)r3�xyr�alignr r<�fontmode�line_spacing�top�partsr�r6�widths�	max_width�166line_width�idx�width_difference�wordsr7�word_widths�word_anchorr9s                      rrB�Text._splitGsN���>�!�^�^�u�4�T�$�F�
��[�A�
�7�C��S�/�!��=��d�i�i��-�-��	�	����%��Y�Y�_�_�U�+�
�167�u�:��?��"�Q�%��A���a��9�:�:��!�9������5�!8�;�C��S�/�!��%�%�'���I�I�������
�
��
�
��!�!�

��
����
 ��l�l�	
�	���e�����>�>�U�"��a�5�D������U�4�f�;�<��$���\��U�F� �I���!�Y�Y�0�0��D�N�N�D�M�M�4�=�=��168��
�
�j�)��	�6�	���a�y�C����E�169�Q��,�6��<�<�����c�!���E�170�Q��,�6�6���C����!�u���q���#,�c�{�#:� ��/�/���h�&��,�s�2�2�D��g�%��,�,�D�P�C�$�S�/�)��Y�&�(�A�-��s�5�z�A�~�-�,6�d�C�+@�+@��171�172�3��d�j�j�QU�FV���5�z�A�~�!�!�9��+� ��O�3�D�#�A�Y�#�-� �-�D�).�	'�).��!�I�I�/�/� $� (� $��� $�
�
� $�
�
��).�$�	'�'*�F�1�I�o��+4�s�;�7G�+G�(���$)�D�!�L�L��t�+�t�)L�M� �K��N�5E��U��VW��5X�$X�X�D���F�A�%*��+�� ��!�9��#��,�s�2�2�D��A�Y�#�%��,�,�D����U�4�f�;�<��#��s�v���9	's�>AO0c	���U=(d URRUUR5URURUR173URU5$)N)r&r�rjrTrUrVrX)r3rr&rs    rr.�Text._get_bbox�sP���!��	�	�*�*����� ��N�N��M�M��M�M�����174�	175rc	�@�SnURXU5H�upVp'URXrS9nUSU-USU-USU-USU-4nUcUnM:[USUS5[USUS5[USUS5[USUS54nM� UceU$)a?176Returns bounding box (in pixels) of text.177 178Use :py:meth:`get_length` to get the offset of following text with 1/64 pixel179precision. The bounding box includes extra margins for some fonts, e.g. italics180or accents.181 182:param xy: The anchor coordinates of the text.183:param anchor: The text anchor alignment. Determines the relative location of184               the anchor to the text. The default alignment is top left,185               specifically ``la`` for horizontal text and ``lt`` for186               vertical text. See :ref:`text-anchors` for details.187:param align: For multiline text, ``"left"``, ``"center"``, ``"right"`` or188              ``"justify"`` determines the relative alignment of lines. Use the189              ``anchor`` parameter to specify the alignment to ``xy``.190 191:return: ``(left, top, right, bottom)`` bounding box192N)rrrr#rA)rBr.�minrv)	r3r�rr��bboxrrr�	bbox_lines	         r�get_bbox�
Text.get_bbox�s���0:>��"&�+�+�b�%�"@��A�&����t��;�I��!��q� ��!��q� ��!��q� ��!��q� �	�I��|� ����Q���1��.���Q���1��.���Q���1��.���Q���1��.�	��#A�$�����r)193rTrWrUr&rVrRrSrYrXr)Nr\�NNN)rrr&rIrRrrSr
rT�194str | NonerUzlist[str] | NonerVr�rJrK)rJrK)rN)r$r
raz_Ink | NonerJrK)rJrrF)r$rGr%rHrzzstr | tuple[str, int] | NonerJzText[AnyStr] | None)rJr
)�rrNr�N)195r��tuple[float, float]rr�r�rr zlist[str] | list[bytes] | NonerJzlist[_Line])rrr&rIrr�rJ�!tuple[float, float, float, float])r�Nr�)r�r�rr�r�rrJr�)rrrrr=r^rbrjr{r�rBr.r�rrrrrNrN`si��!��� $�%)�#�1-��1-��1-��	1-�196�1-��
1-�#�1-��1-�197�1-�f#� ��"�04�	]��]��]�.�	]�198199�]�~7200�v#)�!��04�z��z��z��	z�201.�z�202�
z�zQU�203��204�'2�205�CM�206�	*�207�#)�!��	,��,��,��	,�208209+�,�,rrN)�210__future__rrtr(�typingrrrr"r�_typingr	rsrr�FontrrrNrrr�<module>r�sl��"��	�.�.������Y�3�3�3�i�6N�6N�N���J��I�G�F�O�I�X\�7�6�?�\r
codekingpro/portable-devtools · Team Ai