Files
intellecton/venv/lib/python3.12/site-packages/PIL/__pycache__/ImageText.cpython-312.pyc
T

213 lines
20 KiB
Plaintext
Raw Normal View History

Ë
ß¼jHãóæddlmZddlZddlZddlmZmZmZddlm Z ddl
m Z e je jze jzZGdde«ZGd „d
ee«ZGd d ee«Zy)
é)Ú annotationsN)ÚAnyStrÚGenericÚ
NamedTupleé)Ú ImageFont)Ú_Inkcó6eZdZUded<ded<ded<ded<y) Ú_LineÚfloatÚstrÚanchorú str | bytesÚtextN)Ú__name__Ú
__module__Ú __qualname__Ú__annotations__©óúP/home/antigravity/intellecton/venv/lib/python3.12/site-packages/PIL/ImageText.pyr r
sØ ƒHØ ƒHØ ƒKØ
Ôrr cóLeZdZUgZded<dZdZ d ddZd dZy)
Ú_Wrapz list[AnyStr]ÚlinesrNcóÚ||_||_||_||_|jj}t |t
«rdnd}|}t
jt |t
«rdnd|«D]P}t
jt |t
«rdnd|«} | rm|j|«sn%t| «D]I\}
}|
dk7r|j|«sn.|xjt|«z
c_
|t|«d}ŒK|}||z} |jj| |j«d|kr| }ŒÏ|r|j|«snƒt|«} |j«}| t|«z
|_|jj||j«d|kDr|
d }
t|
«n|}ŒS|r|j|«||jd|_y)
rz\s*\S+s\s*\S+z
[^\S\n]*\ns
[^\S\n]*\nrézWord does not fit within line)rÚwidthÚheightÚfontÚ
isinstancerÚreÚfindallÚadd_lineÚ enumerateÚpositionÚlenÚ _get_bboxÚlstripÚoffsetÚ
ValueErrorÚremaining_text)Úselfrr r!r"Ú
input_textÚ emptystringÚlineÚwordÚnewlinesÚnew_lineÚoriginal_lengthÚmsgs rÚ__init__z_Wrap.__init__ð#'ˆŒ ؈Œ
؈Œ ؈Œ à—Y‘Y—^‘^ˆ
Ü& z´3Ô7‘b¸Sˆ ؈ä—J‘JÜ# J´Ô4‰I¸*Àjó
ó& $ˆ—zzÜ!+¨J¼Ô!<
À.ÐRVóˆHñØ—}‘} TÔÜÓ-‘GA˜Av d§m¡m°KÔ&@ÙØ—MM¤S¨£YÑ.•Mؤ D£   Ð,
#à˜d{ˆy‰y×" 8¨T¯Y©YÓ7¸Ñ:¸Øñ˜DŸM™M¨$Ôä! $›iˆOØ—;‘;“=ˆDØ)¬C°«IÑ5ˆDŒKày‰y×" ¯©Ó3°AÑ6¸Ò9$ SØŠDðG& $ñJØ
˜#Ø&0°·±°Ð&AˆÕrcóx|j|gz}|je|jj|¬«dj}|jj ||j «d}||z|jkDry||_|xjt|«|jzz
c_d|_ y)N)réÿÿÿÿéFrT)
rr!rÚ_splitrr*r"r(r)r,)r/r2rÚ last_line_yÚlast_line_heights rr&z_Wrap.add_lineRØ
˜d˜#ˆØ ;‰;Ð Ÿ)™)×ÐÑ=ˆKØ#Ÿy™y×2°4¸¿¹ÓCÀAÑ ØÐ· ± ÒàˆŒ
Ø
Š
œ˜T› T§[¡[Ñ0
؈Œ Ør©NN)
rz Text[AnyStr]r Úintr!ú
int | Noner"ú Font | NoneÚreturnÚNone)r2rrDÚbool) rrrrrr(r,r9r&rrrrrs_Ø€EˆØ€HØ
€Fð  ð 7Bàð7Bðð7Bðð 7Bð
ð 7Bð
ó
7Bôr rrcóÚeZdZ d d dZd
dZdddZddZ d ddZddZ d ddZ d dd „Z
d dd
Z y)ÚTextNcó¼||_|xstj«|_||_||_||_||_||_d|_ d|_
d|_ y)
: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.
FrN) rrÚ load_defaultr"ÚmodeÚspacingÚ directionÚfeaturesÚlanguageÚembedded_colorÚ stroke_widthÚ stroke_fill)r/rr"rKrLrMrNrOs rr9z
Text.__init__as\ðJ!ˆŒ ØÒ4œI׌ àˆŒ ؈Œ ØŒØ ˆŒ
Ø ˆŒ
àÔà#$ˆÔØ(,ˆÕrcóH|jdvr
d}t|«d|_y)z?
Use embedded color glyphs (COLR, CBDT, SBIX).
)ÚRGBÚRGBAz3Embedded color supported only in RGB and RGBA modesTN)rKr-rP)r/r8s rÚ embed_colorzText.embed_color”s'ð 9‰9˜ Gˆ˜S“/Ð "ˆÕrcó ||_||_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)rQrR)r/r Úfills rÚstrokez Text.strokesð"ˆÔ؈Õrcó<|jdvry|jryy)N)ÚFr[rUÚL)rKrP)r/s rÚ
_get_fontmodezText._get_fontmode§s!Ø 9‰9Ð Ø
×
Ò
Øàrc ó8t|jtj«r
d}t |«|j
dvr
d}t |«|t
|||«}nät|jtj«s
d}t |«|
d}t |«t|t«rd}n|\}}|j}t
||||«}|dk(r˜|jsytj|j«}|jrX|t|d«k(r
d }t |«|dz}|jj|¬
«}t
||||«}|jrŒX||_nÕ|jr
d }t |«tj|j«}|jsP||k(r
d }t |«|dz
}|jj|¬
«}|} t
||||«}|jsŒP|dz}||jjk7r!|jj|¬
«|_ }|jrŒt!|j|j|j"|j$|j
|j&|j(¬ «}
|j*|
_|j,|
_|j.|
_nd}
t|j0t«rd nd
} | j3|j4«|_|
S)a
Wrap text to fit within a given width.
:param width: The width to fit within.
:param height: An optional height limit. Any text that does not fit within this
will be returned as a new :py:class:`.Text` object.
:param scaling: An optional directive to scale the text, either "grow" as much
as possible within the given dimensions, or "shrink" until it
fits. It can also be a tuple of (direction, limit), with an
integer limit to stop scaling at.
:returns: An :py:class:`.Text` object, or None.
zTransposedFont not supported)ltrzOnly ltr direction supportedNz$'scaling' only supports FreeTypeFontz'scaling' requires 'height'rÚshrinkzText could not be scaled)Úsize)rr"rKrLrMrNrOú
ó
)r#r"rÚTransposedFontr-rMrÚ FreeTypeFontrr.ÚmathÚceilrdÚmaxÚ font_variantÚfloorrHrKrLrNrOrPrQrRrÚjoinr) r/r r!Úscalingr8ÚwrapÚlimitr"rdÚ last_wraprÚnewlines rrpz Text.wrap¯ô& d—i×!9Ñ!9Ô 0ˆ˜S“/Ð >‰> Ñ 0ˆ˜S“/Ð ˆ?ܘ˜u fÓ-ŠDä˜dŸi™i¬×)?Ñ)?Ô<Ü  “oЈ~Ø3Ü  “oИ'¤3Ôà!(˜à—9‘9ˆDܘ˜u f¨dÓ3ˆ˜×ä—y‘y §¡Ó+Ø×œs 5¨!›}ÒÜ›oИA‘IŸ9™9×1°tÐ<   u¨f°dÓ;
×!• à×4$ S—z‘z $§)¡)Ó,Ø×˜u’}ØÜ›oИA‘IŸ9™9×1°tÐ<DØ $   u¨f°dÓ;טؘ4Ÿ9™9Ÿ>™>Ò)Ø $§ ¡ × 6Ñ 6¸DÐ 6Ó AD”IØ à × Ò ÜØ×—Y‘YØ—Y‘YØŸ ØŸ.™.؟؟ôˆ#'×"5Ñ"5ˆ Ø $× 1Ñ 1ˆ Ø/ˆDÕ àˆDä$ T§Y¡Y´Ô4‘$¸%ˆØ—L‘L §¡ÓŒ ؈ rcó8t|jt«rd|jv}nd|jv}|r
d}t|«|jj |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.
rerfz&can't measure length of multiline text)
r#rrr-r"Ú getlengthr`rMrNrO)r/Ú multiliner8s rÚ
get_lengthzText.get_lengths€ôT d—i‘i¤Ô  § ¡ Ð)‰Ià §¡Ð*ˆIÙ Ø:ˆCܘS“/Ð y‰y× I‰IØ × Ñ Ó Ø N‰NØ M‰MØ M‰Mó 
ð
rc ó¬||jdk(rdnd}nt|«dk7r
d}t|«|€Pt|jt
«r|jj
d«n|jj
d«}t|«dk(rt|d |d||d «gS|dd
vr|jdk7r
d }t|«|j«}|jjd |d|j|j|j«d
|jz|jz}|d}g} |jdk(r0|d }
|D]$} | jt|
||| ««|
|z
}
Œ&| Sg} d }
|D]\} |jj!| ||j|j|j«}| j|«t#|
|«}
Œ^|ddk(r|t|«dz
|zdz z}n|ddk(r|t|«dz
|zz}d}|D} |d }
|dz
}|
| |z
}|dvrn&|dk(r |
|dz z
}
n|dk(r|
|z
}
n
d}t|«|dk(r"|d k7r|t|«dz
k7r
t| t
«r| j
d«n| j
d«}t|«dkDrÊ|d dk(r |