ImageFont.py 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. #
  2. # The Python Imaging Library.
  3. # $Id$
  4. #
  5. # PIL raster font management
  6. #
  7. # History:
  8. # 1996-08-07 fl created (experimental)
  9. # 1997-08-25 fl minor adjustments to handle fonts from pilfont 0.3
  10. # 1999-02-06 fl rewrote most font management stuff in C
  11. # 1999-03-17 fl take pth files into account in load_path (from Richard Jones)
  12. # 2001-02-17 fl added freetype support
  13. # 2001-05-09 fl added TransposedFont wrapper class
  14. # 2002-03-04 fl make sure we have a "L" or "1" font
  15. # 2002-12-04 fl skip non-directory entries in the system path
  16. # 2003-04-29 fl add embedded default font
  17. # 2003-09-27 fl added support for truetype charmap encodings
  18. #
  19. # Todo:
  20. # Adapt to PILFONT2 format (16-bit fonts, compressed, single file)
  21. #
  22. # Copyright (c) 1997-2003 by Secret Labs AB
  23. # Copyright (c) 1996-2003 by Fredrik Lundh
  24. #
  25. # See the README file for information on usage and redistribution.
  26. #
  27. import base64
  28. import os
  29. import sys
  30. import warnings
  31. from enum import IntEnum
  32. from io import BytesIO
  33. from . import Image
  34. from ._util import is_directory, is_path
  35. class Layout(IntEnum):
  36. BASIC = 0
  37. RAQM = 1
  38. MAX_STRING_LENGTH = 1_000_000
  39. try:
  40. from . import _imagingft as core
  41. except ImportError as ex:
  42. from ._util import DeferredError
  43. core = DeferredError(ex)
  44. def _string_length_check(text):
  45. if MAX_STRING_LENGTH is not None and len(text) > MAX_STRING_LENGTH:
  46. msg = "too many characters in string"
  47. raise ValueError(msg)
  48. # FIXME: add support for pilfont2 format (see FontFile.py)
  49. # --------------------------------------------------------------------
  50. # Font metrics format:
  51. # "PILfont" LF
  52. # fontdescriptor LF
  53. # (optional) key=value... LF
  54. # "DATA" LF
  55. # binary data: 256*10*2 bytes (dx, dy, dstbox, srcbox)
  56. #
  57. # To place a character, cut out srcbox and paste at dstbox,
  58. # relative to the character position. Then move the character
  59. # position according to dx, dy.
  60. # --------------------------------------------------------------------
  61. class ImageFont:
  62. """PIL font wrapper"""
  63. def _load_pilfont(self, filename):
  64. with open(filename, "rb") as fp:
  65. image = None
  66. for ext in (".png", ".gif", ".pbm"):
  67. if image:
  68. image.close()
  69. try:
  70. fullname = os.path.splitext(filename)[0] + ext
  71. image = Image.open(fullname)
  72. except Exception:
  73. pass
  74. else:
  75. if image and image.mode in ("1", "L"):
  76. break
  77. else:
  78. if image:
  79. image.close()
  80. msg = "cannot find glyph data file"
  81. raise OSError(msg)
  82. self.file = fullname
  83. self._load_pilfont_data(fp, image)
  84. image.close()
  85. def _load_pilfont_data(self, file, image):
  86. # read PILfont header
  87. if file.readline() != b"PILfont\n":
  88. msg = "Not a PILfont file"
  89. raise SyntaxError(msg)
  90. file.readline().split(b";")
  91. self.info = [] # FIXME: should be a dictionary
  92. while True:
  93. s = file.readline()
  94. if not s or s == b"DATA\n":
  95. break
  96. self.info.append(s)
  97. # read PILfont metrics
  98. data = file.read(256 * 20)
  99. # check image
  100. if image.mode not in ("1", "L"):
  101. msg = "invalid font image mode"
  102. raise TypeError(msg)
  103. image.load()
  104. self.font = Image.core.font(image.im, data)
  105. def getmask(self, text, mode="", *args, **kwargs):
  106. """
  107. Create a bitmap for the text.
  108. If the font uses antialiasing, the bitmap should have mode ``L`` and use a
  109. maximum value of 255. Otherwise, it should have mode ``1``.
  110. :param text: Text to render.
  111. :param mode: Used by some graphics drivers to indicate what mode the
  112. driver prefers; if empty, the renderer may return either
  113. mode. Note that the mode is always a string, to simplify
  114. C-level implementations.
  115. .. versionadded:: 1.1.5
  116. :return: An internal PIL storage memory instance as defined by the
  117. :py:mod:`PIL.Image.core` interface module.
  118. """
  119. return self.font.getmask(text, mode)
  120. def getbbox(self, text, *args, **kwargs):
  121. """
  122. Returns bounding box (in pixels) of given text.
  123. .. versionadded:: 9.2.0
  124. :param text: Text to render.
  125. :param mode: Used by some graphics drivers to indicate what mode the
  126. driver prefers; if empty, the renderer may return either
  127. mode. Note that the mode is always a string, to simplify
  128. C-level implementations.
  129. :return: ``(left, top, right, bottom)`` bounding box
  130. """
  131. _string_length_check(text)
  132. width, height = self.font.getsize(text)
  133. return 0, 0, width, height
  134. def getlength(self, text, *args, **kwargs):
  135. """
  136. Returns length (in pixels) of given text.
  137. This is the amount by which following text should be offset.
  138. .. versionadded:: 9.2.0
  139. """
  140. _string_length_check(text)
  141. width, height = self.font.getsize(text)
  142. return width
  143. ##
  144. # Wrapper for FreeType fonts. Application code should use the
  145. # <b>truetype</b> factory function to create font objects.
  146. class FreeTypeFont:
  147. """FreeType font wrapper (requires _imagingft service)"""
  148. def __init__(self, font=None, size=10, index=0, encoding="", layout_engine=None):
  149. # FIXME: use service provider instead
  150. self.path = font
  151. self.size = size
  152. self.index = index
  153. self.encoding = encoding
  154. if layout_engine not in (Layout.BASIC, Layout.RAQM):
  155. layout_engine = Layout.BASIC
  156. if core.HAVE_RAQM:
  157. layout_engine = Layout.RAQM
  158. elif layout_engine == Layout.RAQM and not core.HAVE_RAQM:
  159. warnings.warn(
  160. "Raqm layout was requested, but Raqm is not available. "
  161. "Falling back to basic layout."
  162. )
  163. layout_engine = Layout.BASIC
  164. self.layout_engine = layout_engine
  165. def load_from_bytes(f):
  166. self.font_bytes = f.read()
  167. self.font = core.getfont(
  168. "", size, index, encoding, self.font_bytes, layout_engine
  169. )
  170. if is_path(font):
  171. if sys.platform == "win32":
  172. font_bytes_path = font if isinstance(font, bytes) else font.encode()
  173. try:
  174. font_bytes_path.decode("ascii")
  175. except UnicodeDecodeError:
  176. # FreeType cannot load fonts with non-ASCII characters on Windows
  177. # So load it into memory first
  178. with open(font, "rb") as f:
  179. load_from_bytes(f)
  180. return
  181. self.font = core.getfont(
  182. font, size, index, encoding, layout_engine=layout_engine
  183. )
  184. else:
  185. load_from_bytes(font)
  186. def __getstate__(self):
  187. return [self.path, self.size, self.index, self.encoding, self.layout_engine]
  188. def __setstate__(self, state):
  189. path, size, index, encoding, layout_engine = state
  190. self.__init__(path, size, index, encoding, layout_engine)
  191. def getname(self):
  192. """
  193. :return: A tuple of the font family (e.g. Helvetica) and the font style
  194. (e.g. Bold)
  195. """
  196. return self.font.family, self.font.style
  197. def getmetrics(self):
  198. """
  199. :return: A tuple of the font ascent (the distance from the baseline to
  200. the highest outline point) and descent (the distance from the
  201. baseline to the lowest outline point, a negative value)
  202. """
  203. return self.font.ascent, self.font.descent
  204. def getlength(self, text, mode="", direction=None, features=None, language=None):
  205. """
  206. Returns length (in pixels with 1/64 precision) of given text when rendered
  207. in font with provided direction, features, and language.
  208. This is the amount by which following text should be offset.
  209. Text bounding box may extend past the length in some fonts,
  210. e.g. when using italics or accents.
  211. The result is returned as a float; it is a whole number if using basic layout.
  212. Note that the sum of two lengths may not equal the length of a concatenated
  213. string due to kerning. If you need to adjust for kerning, include the following
  214. character and subtract its length.
  215. For example, instead of ::
  216. hello = font.getlength("Hello")
  217. world = font.getlength("World")
  218. hello_world = hello + world # not adjusted for kerning
  219. assert hello_world == font.getlength("HelloWorld") # may fail
  220. use ::
  221. hello = font.getlength("HelloW") - font.getlength("W") # adjusted for kerning
  222. world = font.getlength("World")
  223. hello_world = hello + world # adjusted for kerning
  224. assert hello_world == font.getlength("HelloWorld") # True
  225. or disable kerning with (requires libraqm) ::
  226. hello = draw.textlength("Hello", font, features=["-kern"])
  227. world = draw.textlength("World", font, features=["-kern"])
  228. hello_world = hello + world # kerning is disabled, no need to adjust
  229. assert hello_world == draw.textlength("HelloWorld", font, features=["-kern"])
  230. .. versionadded:: 8.0.0
  231. :param text: Text to measure.
  232. :param mode: Used by some graphics drivers to indicate what mode the
  233. driver prefers; if empty, the renderer may return either
  234. mode. Note that the mode is always a string, to simplify
  235. C-level implementations.
  236. :param direction: Direction of the text. It can be 'rtl' (right to
  237. left), 'ltr' (left to right) or 'ttb' (top to bottom).
  238. Requires libraqm.
  239. :param features: A list of OpenType font features to be used during text
  240. layout. This is usually used to turn on optional
  241. font features that are not enabled by default,
  242. for example 'dlig' or 'ss01', but can be also
  243. used to turn off default font features for
  244. example '-liga' to disable ligatures or '-kern'
  245. to disable kerning. To get all supported
  246. features, see
  247. https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist
  248. Requires libraqm.
  249. :param language: Language of the text. Different languages may use
  250. different glyph shapes or ligatures. This parameter tells
  251. the font which language the text is in, and to apply the
  252. correct substitutions as appropriate, if available.
  253. It should be a `BCP 47 language code
  254. <https://www.w3.org/International/articles/language-tags/>`_
  255. Requires libraqm.
  256. :return: Either width for horizontal text, or height for vertical text.
  257. """
  258. _string_length_check(text)
  259. return self.font.getlength(text, mode, direction, features, language) / 64
  260. def getbbox(
  261. self,
  262. text,
  263. mode="",
  264. direction=None,
  265. features=None,
  266. language=None,
  267. stroke_width=0,
  268. anchor=None,
  269. ):
  270. """
  271. Returns bounding box (in pixels) of given text relative to given anchor
  272. when rendered in font with provided direction, features, and language.
  273. Use :py:meth:`getlength()` to get the offset of following text with
  274. 1/64 pixel precision. The bounding box includes extra margins for
  275. some fonts, e.g. italics or accents.
  276. .. versionadded:: 8.0.0
  277. :param text: Text to render.
  278. :param mode: Used by some graphics drivers to indicate what mode the
  279. driver prefers; if empty, the renderer may return either
  280. mode. Note that the mode is always a string, to simplify
  281. C-level implementations.
  282. :param direction: Direction of the text. It can be 'rtl' (right to
  283. left), 'ltr' (left to right) or 'ttb' (top to bottom).
  284. Requires libraqm.
  285. :param features: A list of OpenType font features to be used during text
  286. layout. This is usually used to turn on optional
  287. font features that are not enabled by default,
  288. for example 'dlig' or 'ss01', but can be also
  289. used to turn off default font features for
  290. example '-liga' to disable ligatures or '-kern'
  291. to disable kerning. To get all supported
  292. features, see
  293. https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist
  294. Requires libraqm.
  295. :param language: Language of the text. Different languages may use
  296. different glyph shapes or ligatures. This parameter tells
  297. the font which language the text is in, and to apply the
  298. correct substitutions as appropriate, if available.
  299. It should be a `BCP 47 language code
  300. <https://www.w3.org/International/articles/language-tags/>`_
  301. Requires libraqm.
  302. :param stroke_width: The width of the text stroke.
  303. :param anchor: The text anchor alignment. Determines the relative location of
  304. the anchor to the text. The default alignment is top left.
  305. See :ref:`text-anchors` for valid values.
  306. :return: ``(left, top, right, bottom)`` bounding box
  307. """
  308. _string_length_check(text)
  309. size, offset = self.font.getsize(
  310. text, mode, direction, features, language, anchor
  311. )
  312. left, top = offset[0] - stroke_width, offset[1] - stroke_width
  313. width, height = size[0] + 2 * stroke_width, size[1] + 2 * stroke_width
  314. return left, top, left + width, top + height
  315. def getmask(
  316. self,
  317. text,
  318. mode="",
  319. direction=None,
  320. features=None,
  321. language=None,
  322. stroke_width=0,
  323. anchor=None,
  324. ink=0,
  325. start=None,
  326. ):
  327. """
  328. Create a bitmap for the text.
  329. If the font uses antialiasing, the bitmap should have mode ``L`` and use a
  330. maximum value of 255. If the font has embedded color data, the bitmap
  331. should have mode ``RGBA``. Otherwise, it should have mode ``1``.
  332. :param text: Text to render.
  333. :param mode: Used by some graphics drivers to indicate what mode the
  334. driver prefers; if empty, the renderer may return either
  335. mode. Note that the mode is always a string, to simplify
  336. C-level implementations.
  337. .. versionadded:: 1.1.5
  338. :param direction: Direction of the text. It can be 'rtl' (right to
  339. left), 'ltr' (left to right) or 'ttb' (top to bottom).
  340. Requires libraqm.
  341. .. versionadded:: 4.2.0
  342. :param features: A list of OpenType font features to be used during text
  343. layout. This is usually used to turn on optional
  344. font features that are not enabled by default,
  345. for example 'dlig' or 'ss01', but can be also
  346. used to turn off default font features for
  347. example '-liga' to disable ligatures or '-kern'
  348. to disable kerning. To get all supported
  349. features, see
  350. https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist
  351. Requires libraqm.
  352. .. versionadded:: 4.2.0
  353. :param language: Language of the text. Different languages may use
  354. different glyph shapes or ligatures. This parameter tells
  355. the font which language the text is in, and to apply the
  356. correct substitutions as appropriate, if available.
  357. It should be a `BCP 47 language code
  358. <https://www.w3.org/International/articles/language-tags/>`_
  359. Requires libraqm.
  360. .. versionadded:: 6.0.0
  361. :param stroke_width: The width of the text stroke.
  362. .. versionadded:: 6.2.0
  363. :param anchor: The text anchor alignment. Determines the relative location of
  364. the anchor to the text. The default alignment is top left.
  365. See :ref:`text-anchors` for valid values.
  366. .. versionadded:: 8.0.0
  367. :param ink: Foreground ink for rendering in RGBA mode.
  368. .. versionadded:: 8.0.0
  369. :param start: Tuple of horizontal and vertical offset, as text may render
  370. differently when starting at fractional coordinates.
  371. .. versionadded:: 9.4.0
  372. :return: An internal PIL storage memory instance as defined by the
  373. :py:mod:`PIL.Image.core` interface module.
  374. """
  375. return self.getmask2(
  376. text,
  377. mode,
  378. direction=direction,
  379. features=features,
  380. language=language,
  381. stroke_width=stroke_width,
  382. anchor=anchor,
  383. ink=ink,
  384. start=start,
  385. )[0]
  386. def getmask2(
  387. self,
  388. text,
  389. mode="",
  390. direction=None,
  391. features=None,
  392. language=None,
  393. stroke_width=0,
  394. anchor=None,
  395. ink=0,
  396. start=None,
  397. *args,
  398. **kwargs,
  399. ):
  400. """
  401. Create a bitmap for the text.
  402. If the font uses antialiasing, the bitmap should have mode ``L`` and use a
  403. maximum value of 255. If the font has embedded color data, the bitmap
  404. should have mode ``RGBA``. Otherwise, it should have mode ``1``.
  405. :param text: Text to render.
  406. :param mode: Used by some graphics drivers to indicate what mode the
  407. driver prefers; if empty, the renderer may return either
  408. mode. Note that the mode is always a string, to simplify
  409. C-level implementations.
  410. .. versionadded:: 1.1.5
  411. :param direction: Direction of the text. It can be 'rtl' (right to
  412. left), 'ltr' (left to right) or 'ttb' (top to bottom).
  413. Requires libraqm.
  414. .. versionadded:: 4.2.0
  415. :param features: A list of OpenType font features to be used during text
  416. layout. This is usually used to turn on optional
  417. font features that are not enabled by default,
  418. for example 'dlig' or 'ss01', but can be also
  419. used to turn off default font features for
  420. example '-liga' to disable ligatures or '-kern'
  421. to disable kerning. To get all supported
  422. features, see
  423. https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist
  424. Requires libraqm.
  425. .. versionadded:: 4.2.0
  426. :param language: Language of the text. Different languages may use
  427. different glyph shapes or ligatures. This parameter tells
  428. the font which language the text is in, and to apply the
  429. correct substitutions as appropriate, if available.
  430. It should be a `BCP 47 language code
  431. <https://www.w3.org/International/articles/language-tags/>`_
  432. Requires libraqm.
  433. .. versionadded:: 6.0.0
  434. :param stroke_width: The width of the text stroke.
  435. .. versionadded:: 6.2.0
  436. :param anchor: The text anchor alignment. Determines the relative location of
  437. the anchor to the text. The default alignment is top left.
  438. See :ref:`text-anchors` for valid values.
  439. .. versionadded:: 8.0.0
  440. :param ink: Foreground ink for rendering in RGBA mode.
  441. .. versionadded:: 8.0.0
  442. :param start: Tuple of horizontal and vertical offset, as text may render
  443. differently when starting at fractional coordinates.
  444. .. versionadded:: 9.4.0
  445. :return: A tuple of an internal PIL storage memory instance as defined by the
  446. :py:mod:`PIL.Image.core` interface module, and the text offset, the
  447. gap between the starting coordinate and the first marking
  448. """
  449. _string_length_check(text)
  450. if start is None:
  451. start = (0, 0)
  452. im = None
  453. size = None
  454. def fill(mode, im_size):
  455. nonlocal im, size
  456. size = im_size
  457. if Image.MAX_IMAGE_PIXELS is not None:
  458. pixels = max(1, size[0]) * max(1, size[1])
  459. if pixels > 2 * Image.MAX_IMAGE_PIXELS:
  460. return
  461. im = Image.core.fill(mode, size)
  462. return im
  463. offset = self.font.render(
  464. text,
  465. fill,
  466. mode,
  467. direction,
  468. features,
  469. language,
  470. stroke_width,
  471. anchor,
  472. ink,
  473. start[0],
  474. start[1],
  475. )
  476. Image._decompression_bomb_check(size)
  477. return im, offset
  478. def font_variant(
  479. self, font=None, size=None, index=None, encoding=None, layout_engine=None
  480. ):
  481. """
  482. Create a copy of this FreeTypeFont object,
  483. using any specified arguments to override the settings.
  484. Parameters are identical to the parameters used to initialize this
  485. object.
  486. :return: A FreeTypeFont object.
  487. """
  488. if font is None:
  489. try:
  490. font = BytesIO(self.font_bytes)
  491. except AttributeError:
  492. font = self.path
  493. return FreeTypeFont(
  494. font=font,
  495. size=self.size if size is None else size,
  496. index=self.index if index is None else index,
  497. encoding=self.encoding if encoding is None else encoding,
  498. layout_engine=layout_engine or self.layout_engine,
  499. )
  500. def get_variation_names(self):
  501. """
  502. :returns: A list of the named styles in a variation font.
  503. :exception OSError: If the font is not a variation font.
  504. """
  505. try:
  506. names = self.font.getvarnames()
  507. except AttributeError as e:
  508. msg = "FreeType 2.9.1 or greater is required"
  509. raise NotImplementedError(msg) from e
  510. return [name.replace(b"\x00", b"") for name in names]
  511. def set_variation_by_name(self, name):
  512. """
  513. :param name: The name of the style.
  514. :exception OSError: If the font is not a variation font.
  515. """
  516. names = self.get_variation_names()
  517. if not isinstance(name, bytes):
  518. name = name.encode()
  519. index = names.index(name) + 1
  520. if index == getattr(self, "_last_variation_index", None):
  521. # When the same name is set twice in a row,
  522. # there is an 'unknown freetype error'
  523. # https://savannah.nongnu.org/bugs/?56186
  524. return
  525. self._last_variation_index = index
  526. self.font.setvarname(index)
  527. def get_variation_axes(self):
  528. """
  529. :returns: A list of the axes in a variation font.
  530. :exception OSError: If the font is not a variation font.
  531. """
  532. try:
  533. axes = self.font.getvaraxes()
  534. except AttributeError as e:
  535. msg = "FreeType 2.9.1 or greater is required"
  536. raise NotImplementedError(msg) from e
  537. for axis in axes:
  538. axis["name"] = axis["name"].replace(b"\x00", b"")
  539. return axes
  540. def set_variation_by_axes(self, axes):
  541. """
  542. :param axes: A list of values for each axis.
  543. :exception OSError: If the font is not a variation font.
  544. """
  545. try:
  546. self.font.setvaraxes(axes)
  547. except AttributeError as e:
  548. msg = "FreeType 2.9.1 or greater is required"
  549. raise NotImplementedError(msg) from e
  550. class TransposedFont:
  551. """Wrapper for writing rotated or mirrored text"""
  552. def __init__(self, font, orientation=None):
  553. """
  554. Wrapper that creates a transposed font from any existing font
  555. object.
  556. :param font: A font object.
  557. :param orientation: An optional orientation. If given, this should
  558. be one of Image.Transpose.FLIP_LEFT_RIGHT, Image.Transpose.FLIP_TOP_BOTTOM,
  559. Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_180, or
  560. Image.Transpose.ROTATE_270.
  561. """
  562. self.font = font
  563. self.orientation = orientation # any 'transpose' argument, or None
  564. def getmask(self, text, mode="", *args, **kwargs):
  565. im = self.font.getmask(text, mode, *args, **kwargs)
  566. if self.orientation is not None:
  567. return im.transpose(self.orientation)
  568. return im
  569. def getbbox(self, text, *args, **kwargs):
  570. # TransposedFont doesn't support getmask2, move top-left point to (0, 0)
  571. # this has no effect on ImageFont and simulates anchor="lt" for FreeTypeFont
  572. left, top, right, bottom = self.font.getbbox(text, *args, **kwargs)
  573. width = right - left
  574. height = bottom - top
  575. if self.orientation in (Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_270):
  576. return 0, 0, height, width
  577. return 0, 0, width, height
  578. def getlength(self, text, *args, **kwargs):
  579. if self.orientation in (Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_270):
  580. msg = "text length is undefined for text rotated by 90 or 270 degrees"
  581. raise ValueError(msg)
  582. _string_length_check(text)
  583. return self.font.getlength(text, *args, **kwargs)
  584. def load(filename):
  585. """
  586. Load a font file. This function loads a font object from the given
  587. bitmap font file, and returns the corresponding font object.
  588. :param filename: Name of font file.
  589. :return: A font object.
  590. :exception OSError: If the file could not be read.
  591. """
  592. f = ImageFont()
  593. f._load_pilfont(filename)
  594. return f
  595. def truetype(font=None, size=10, index=0, encoding="", layout_engine=None):
  596. """
  597. Load a TrueType or OpenType font from a file or file-like object,
  598. and create a font object.
  599. This function loads a font object from the given file or file-like
  600. object, and creates a font object for a font of the given size.
  601. Pillow uses FreeType to open font files. On Windows, be aware that FreeType
  602. will keep the file open as long as the FreeTypeFont object exists. Windows
  603. limits the number of files that can be open in C at once to 512, so if many
  604. fonts are opened simultaneously and that limit is approached, an
  605. ``OSError`` may be thrown, reporting that FreeType "cannot open resource".
  606. A workaround would be to copy the file(s) into memory, and open that instead.
  607. This function requires the _imagingft service.
  608. :param font: A filename or file-like object containing a TrueType font.
  609. If the file is not found in this filename, the loader may also
  610. search in other directories, such as the :file:`fonts/`
  611. directory on Windows or :file:`/Library/Fonts/`,
  612. :file:`/System/Library/Fonts/` and :file:`~/Library/Fonts/` on
  613. macOS.
  614. :param size: The requested size, in pixels.
  615. :param index: Which font face to load (default is first available face).
  616. :param encoding: Which font encoding to use (default is Unicode). Possible
  617. encodings include (see the FreeType documentation for more
  618. information):
  619. * "unic" (Unicode)
  620. * "symb" (Microsoft Symbol)
  621. * "ADOB" (Adobe Standard)
  622. * "ADBE" (Adobe Expert)
  623. * "ADBC" (Adobe Custom)
  624. * "armn" (Apple Roman)
  625. * "sjis" (Shift JIS)
  626. * "gb " (PRC)
  627. * "big5"
  628. * "wans" (Extended Wansung)
  629. * "joha" (Johab)
  630. * "lat1" (Latin-1)
  631. This specifies the character set to use. It does not alter the
  632. encoding of any text provided in subsequent operations.
  633. :param layout_engine: Which layout engine to use, if available:
  634. :data:`.ImageFont.Layout.BASIC` or :data:`.ImageFont.Layout.RAQM`.
  635. If it is available, Raqm layout will be used by default.
  636. Otherwise, basic layout will be used.
  637. Raqm layout is recommended for all non-English text. If Raqm layout
  638. is not required, basic layout will have better performance.
  639. You can check support for Raqm layout using
  640. :py:func:`PIL.features.check_feature` with ``feature="raqm"``.
  641. .. versionadded:: 4.2.0
  642. :return: A font object.
  643. :exception OSError: If the file could not be read.
  644. """
  645. def freetype(font):
  646. return FreeTypeFont(font, size, index, encoding, layout_engine)
  647. try:
  648. return freetype(font)
  649. except OSError:
  650. if not is_path(font):
  651. raise
  652. ttf_filename = os.path.basename(font)
  653. dirs = []
  654. if sys.platform == "win32":
  655. # check the windows font repository
  656. # NOTE: must use uppercase WINDIR, to work around bugs in
  657. # 1.5.2's os.environ.get()
  658. windir = os.environ.get("WINDIR")
  659. if windir:
  660. dirs.append(os.path.join(windir, "fonts"))
  661. elif sys.platform in ("linux", "linux2"):
  662. lindirs = os.environ.get("XDG_DATA_DIRS")
  663. if not lindirs:
  664. # According to the freedesktop spec, XDG_DATA_DIRS should
  665. # default to /usr/share
  666. lindirs = "/usr/share"
  667. dirs += [os.path.join(lindir, "fonts") for lindir in lindirs.split(":")]
  668. elif sys.platform == "darwin":
  669. dirs += [
  670. "/Library/Fonts",
  671. "/System/Library/Fonts",
  672. os.path.expanduser("~/Library/Fonts"),
  673. ]
  674. ext = os.path.splitext(ttf_filename)[1]
  675. first_font_with_a_different_extension = None
  676. for directory in dirs:
  677. for walkroot, walkdir, walkfilenames in os.walk(directory):
  678. for walkfilename in walkfilenames:
  679. if ext and walkfilename == ttf_filename:
  680. return freetype(os.path.join(walkroot, walkfilename))
  681. elif not ext and os.path.splitext(walkfilename)[0] == ttf_filename:
  682. fontpath = os.path.join(walkroot, walkfilename)
  683. if os.path.splitext(fontpath)[1] == ".ttf":
  684. return freetype(fontpath)
  685. if not ext and first_font_with_a_different_extension is None:
  686. first_font_with_a_different_extension = fontpath
  687. if first_font_with_a_different_extension:
  688. return freetype(first_font_with_a_different_extension)
  689. raise
  690. def load_path(filename):
  691. """
  692. Load font file. Same as :py:func:`~PIL.ImageFont.load`, but searches for a
  693. bitmap font along the Python path.
  694. :param filename: Name of font file.
  695. :return: A font object.
  696. :exception OSError: If the file could not be read.
  697. """
  698. for directory in sys.path:
  699. if is_directory(directory):
  700. if not isinstance(filename, str):
  701. filename = filename.decode("utf-8")
  702. try:
  703. return load(os.path.join(directory, filename))
  704. except OSError:
  705. pass
  706. msg = "cannot find font file"
  707. raise OSError(msg)
  708. def load_default(size=None):
  709. """If FreeType support is available, load a version of Aileron Regular,
  710. https://dotcolon.net/font/aileron, with a more limited character set.
  711. Otherwise, load a "better than nothing" font.
  712. .. versionadded:: 1.1.4
  713. :param size: The font size of Aileron Regular.
  714. .. versionadded:: 10.1.0
  715. :return: A font object.
  716. """
  717. if core.__class__.__name__ == "module" or size is not None:
  718. f = truetype(
  719. BytesIO(
  720. base64.b64decode(
  721. b"""
  722. AAEAAAAPAIAAAwBwRkZUTYwDlUAAADFoAAAAHEdERUYAqADnAAAo8AAAACRHUE9ThhmITwAAKfgAA
  723. AduR1NVQnHxefoAACkUAAAA4k9TLzJovoHLAAABeAAAAGBjbWFw5lFQMQAAA6gAAAGqZ2FzcP//AA
  724. MAACjoAAAACGdseWYmRXoPAAAGQAAAHfhoZWFkE18ayQAAAPwAAAA2aGhlYQboArEAAAE0AAAAJGh
  725. tdHjjERZ8AAAB2AAAAdBsb2NhuOexrgAABVQAAADqbWF4cAC7AEYAAAFYAAAAIG5hbWUr+h5lAAAk
  726. OAAAA6Jwb3N0D3oPTQAAJ9wAAAEKAAEAAAABGhxJDqIhXw889QALA+gAAAAA0Bqf2QAAAADhCh2h/
  727. 2r/LgOxAyAAAAAIAAIAAAAAAAAAAQAAA8r/GgAAA7j/av9qA7EAAQAAAAAAAAAAAAAAAAAAAHQAAQ
  728. AAAHQAQwAFAAAAAAACAAAAAQABAAAAQAAAAAAAAAADAfoBkAAFAAgCigJYAAAASwKKAlgAAAFeADI
  729. BPgAAAAAFAAAAAAAAAAAAAAcAAAAAAAAAAAAAAABVS1dOAEAAIPsCAwL/GgDIA8oA5iAAAJMAAAAA
  730. AhICsgAAACAAAwH0AAAAAAAAAU0AAADYAAAA8gA5AVMAVgJEAEYCRAA1AuQAKQKOAEAAsAArATsAZ
  731. AE7AB4CMABVAkQAUADc/+EBEgAgANwAJQEv//sCRAApAkQAggJEADwCRAAtAkQAIQJEADkCRAArAk
  732. QAMgJEACwCRAAxANwAJQDc/+ECRABnAkQAUAJEAEQB8wAjA1QANgJ/AB0CcwBkArsALwLFAGQCSwB
  733. kAjcAZALGAC8C2g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gYVFBYzMjY1IwGP90wfPnWTprSSf48LAVYCIqJofHllVG+hAU3+s3hARsicn8uAagoKpq
  800. N/gaN1XAAAAAEAZAAAAowCsgALAAABESMRIREjETMRIRECjFb+hFZWAXwCsv1OAS7+0gKy/sQBPAA
  801. AAAABAGQAAAC6ArIAAwAAMyMRM7pWVgKyAAABADf/8gHoArIAEwAAAREUBw4BIyImLwEzFxYzMjc2
  802. NREB6AIFcGpgbQIBVgIHfXQKAQKy/lYxIltob2EpKYyEFD0BpwAAAAABAGQAAAJ0ArIACwAACQEjA
  803. wcVIxEzEQEzATsBJ3ntQlZWAVVlAWH+nwEnR+ACsv6RAW8AAQBkAAACLwKyAAUAACUVIREzEQIv/j
  804. VWRkYCsv2UAAABAGQAAAMUArIAFAAAAREjETQ3BgcDIwMmJxYVESMRMxsBAxRWAiMxemx8NxsCVo7
  805. MywKy/U4BY7ZLco7+nAFmoFxLtP6dArL9lwJpAAAAAAEAZAAAAoACsgANAAAhIwEWFREjETMBJjUR
  806. MwKAhP67A1aEAUUDVAJeeov+pwKy/aJ5jAFZAAAAAgAv//ICuwLAAAkAEwAAEiAWFRQGICY1NBIyN
  807. jU0JiIGFRTbATSsrP7MrNrYenrYegLAxaKhxsahov47nIeIm5uIhwACAGQAAAJHArIADgAYAAABHg
  808. EVFAYHBisBESMRMzITNjQnJisBETMyAZRUX2VOHzuAVtY7GlxcGDWIiDUCrgtnVlVpCgT+5gKy/rU
  809. V1BUF/vgAAAACAC//zAK9AsAAEgAcAAAlFhcHJiMiBwYjIiY1NDYgFhUUJRQWMjY1NCYiBgI9PUMx
  810. UDcfKh8omqysATSs/dR62Hp62HpICTg7NgkHxqGixcWitbWHnJyHiJubAAIAZAAAAlgCsgAXACMAA
  811. CUWFyMmJyYnJisBESMRMzIXHgEVFAYHFiUzMjc+ATU0JyYrAQIqDCJfGQwNWhAhglbiOx9QXEY1Tv
  812. 6bhDATMj1lGSyMtYgtOXR0BwH+1wKyBApbU0BSESRAAgVAOGoQBA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bDiwUUXBUXowf
  826. J8c9SjRORzYSgVwAAAAAAgBK//ICRQLfABEAHgAAATIWFRQGIyImLwEVIxEzETc2EzI2NTQmIyIGH
  827. QEUFgFUcYCVbiNJEyNWVigySElcU01JXmECIJd4i5QTEDRJAt/+3jkq/hRuZV55ZWsdX14AAQAe//
  828. IB9wIgABgAAAEyFhcjJiMiBhUUFjMyNjczDgEjIiY1NDYBF152DFocbEJXU0A1Rw1aE3pbaoKQAiB
  829. oWH5qZm1tPDlaXYuLgZcAAAACAB7/8gIZAt8AEQAeAAABESM1BwYjIiY1NDYzMhYfAREDMjY9ATQm
  830. IyIGFRQWAhlWKDJacYCVbiNJEyOnSV5hQUlcUwLf/SFVOSqXeIuUExA0ARb9VWVrHV9ebmVeeQACA
  831. B7/8gH9AiAAFQAbAAABFAchHgEzMjY3Mw4BIyImNTQ2MzIWJyIGByEmAf0C/oAGUkA1SwlaD4FXbI
  832. WObmt45UBVBwEqDQEYFhNjWD84W16Oh3+akU9aU60AAAEAFQAAARoC8gAWAAATBh0BMxUjESMRIzU
  833. zNTQ3PgEzMhcVJqcDbW1WOTkDB0k8Hx5oAngVITRC/jQBzEIsJRs5PwVHEwAAAAIAHv8uAhkCIAAi
  834. AC8AAAERFAcOASMiLwEzFx4BMzI2NzY9AQcGIyImNTQ2MzIWHwE1AzI2PQE0JiMiBhUUFgIZAQSEd
  835. NwRAVcBBU5DTlUDASgyWnGAlW4jSRMjp0leYUFJXFMCEv5wSh1zeq8KCTI8VU0ZIQk5Kpd4i5QTED
  836. RJ/iJlax1fXm5lXnkAAQBKAAACCgLkABcAAAEWFREjETQnLgEHDgEdASMRMxE3NjMyFgIIAlYCBDs
  837. 6RVRWViE5UVViAYUbQP7WASQxGzI7AQJyf+kC5P7TPSxUAAACAD4AAACsAsAABwALAAASMhYUBiIm
  838. NBMjETNeLiAgLiBiVlYCwCAuICAu/WACEgAC//P/LgCnAsAABwAVAAASMhYUBiImNBcRFAcGIyInN
  839. RY3NjURWS4gIC4gYgMLcRwNSgYCAsAgLiAgLo79wCUbZAJGBzMOHgJEAAAAAQBKAAACCALfAAsAAC
  840. EnBxUjETMREzMHEwGTwTJWVvdu9/rgN6kC3/4oAQv6/ugAAQBG//wA3gLfAA8AABMRFBceATcVBiM
  841. iJicmNRGcAQIcIxkkKi4CAQLf/bkhERoSBD4EJC8SNAJKAAAAAQBKAAADEAIgACQAAAEWFREjETQn
  842. JiMiFREjETQnJiMiFREjETMVNzYzMhYXNzYzMhYDCwVWBAxedFYEDF50VlYiJko7ThAvJkpEVAGfI
  843. jn+vAEcQyRZ1v76ARxDJFnW/voCEk08HzYtRB9HAAAAAAEASgAAAgoCIAAWAAABFhURIxE0JyYjIg
  844. YdASMRMxU3NjMyFgIIAlYCCXBEVVZWITlRVWIBhRtA/tYBJDEbbHR/6QISWz0sVAAAAAACAB7/8gI
  845. sAiAABwARAAASIBYUBiAmNBIyNjU0JiIGFRSlAQCHh/8Ah7ieWlqeWgIgn/Cfn/D+s3ZfYHV1YF8A
  846. AgBK/zwCRQIgABEAHgAAATIWFRQGIyImLwERIxEzFTc2EzI2NTQmIyIGHQEUFgFUcYCVbiNJEyNWV
  847. igySElcU01JXmECIJd4i5QTEDT+8wLWVTkq/hRuZV55ZWsdX14AAgAe/zwCGQIgABEAHgAAAREjEQ
  848. cGIyImNTQ2MzIWHwE1AzI2PQE0JiMiBhUUFgIZVigyWnGAlW4jSRMjp0leYUFJXFMCEv0qARk5Kpd
  849. 4i5QTEDRJ/iJlax1fXm5lXnkAAQBKAAABPgIeAA0AAAEyFxUmBhURIxEzFTc2ARoWDkdXVlYwIwIe
  850. B0EFVlf+0gISU0cYAAEAGP/yAa0CIAAjAAATMhYXIyYjIgYVFBYXHgEVFAYjIiYnMxYzMjY1NCYnL
  851. gE1NDbkV2MJWhNdKy04PF1XbVhWbgxaE2ktOjlEUllkAiBaS2MrJCUoEBlPQkhOVFZoKCUmLhIWSE
  852. BIUwAAAAEAFP/4ARQCiQAXAAATERQXHgE3FQYjIiYnJjURIzUzNTMVMxWxAQMmMx8qMjMEAUdHVmM
  853. BzP7PGw4mFgY/BSwxDjQBNUJ7e0IAAAABAEL/8gICAhIAFwAAAREjNQcGIyImJyY1ETMRFBceATMy
  854. Nj0BAgJWITlRT2EKBVYEBkA1RFECEv3uWj4qTToiOQE+/tIlJC43c4DpAAAAAAEAAQAAAfwCEgAGA
  855. AABAyMDMxsBAfzJaclfop8CEv3uAhL+LQHTAAABAAEAAAMLAhIADAAAAQMjCwEjAzMbATMbAQMLqW
  856. Z2dmapY3t0a3Z7AhL97gG+/kICEv5AAcD+QwG9AAAB//oAAAHWAhIACwAAARMjJwcjEwMzFzczARq
  857. 8ZIuKY763ZoWFYwEO/vLV1QEMAQbNzQAAAQAB/y4B+wISABEAAAEDDgEjIic1FjMyNj8BAzMbAQH7
  858. 2iFZQB8NDRIpNhQH02GenQIS/cFVUAJGASozEwIt/i4B0gABABQAAAGxAg4ACQAAJRUhNQEhNSEVA
  859. QGx/mMBNP7iAYL+zkREQgGIREX+ewAAAAABAED/sAEOAwwALAAAASMiBhUUFxYVFAYHHgEVFAcGFR
  860. QWOwEVIyImNTQ3NjU0JzU2NTQnJjU0NjsBAQ4MKiMLDS4pKS4NCyMqDAtERAwLUlILDERECwLUGBk
  861. WTlsgKzUFBTcrIFtOFhkYOC87GFVMIkUIOAhFIkxVGDsvAAAAAAEAYP84AJoDIAADAAAXIxEzmjo6
  862. yAPoAAEAIf+wAO8DDAAsAAATFQYVFBcWFRQGKwE1MzI2NTQnJjU0NjcuATU0NzY1NCYrATUzMhYVF
  863. AcGFRTvUgsMREQLDCojCw0uKSkuDQsjKgwLREQMCwF6OAhFIkxVGDsvOBgZFk5bICs1BQU3KyBbTh
  864. YZGDgvOxhVTCJFAAABAE0A3wH2AWQAEwAAATMUIyImJyYjIhUjNDMyFhcWMzIBvjhuGywtQR0xOG4
  865. bLC1BHTEBZIURGCNMhREYIwAAAwAk/94DIgLoAAcAEQApAAAAIBYQBiAmECQgBhUUFiA2NTQlMhYX
  866. IyYjIgYUFjMyNjczDgEjIiY1NDYBAQFE3d3+vN0CB/7wubkBELn+xVBnD1wSWDo+QTcqOQZcEmZWX
  867. HN2Aujg/rbg4AFKpr+Mjb6+jYxbWEldV5ZZNShLVn5na34AAgB4AFIB9AGeAAUACwAAAQcXIyc3Mw
  868. cXIyc3AUqJiUmJifOJiUmJiQGepqampqampqYAAAIAHAHSAQ4CwAAHAA8AABIyFhQGIiY0NiIGFBY
  869. yNjRgakREakSTNCEhNCECwEJqQkJqCiM4IyM4AAAAAAIAUAAAAfQCCwALAA8AAAEzFSMVIzUjNTM1
  870. MxMhNSEBP7W1OrW1OrX+XAGkAVs4tLQ4sP31OAAAAQB0AkQBAQKyAAMAABMjNzOsOD1QAkRuAAAAA
  871. AEAIADsAKoBdgAHAAASMhYUBiImNEg6KCg6KAF2KDooKDoAAAIAOQBSAbUBngAFAAsAACUHIzcnMw
  872. UHIzcnMwELiUmJiUkBM4lJiYlJ+KampqampqYAAAABADYB5QDhAt8ABAAAEzczByM2Xk1OXQHv8Po
  873. AAQAWAeUAwQLfAAQAABMHIzczwV5NTl0C1fD6AAIANgHlAYsC3wAEAAkAABM3MwcjPwEzByM2Xk1O
  874. XapeTU5dAe/w+grw+gAAAgAWAeUBawLfAAQACQAAEwcjNzMXByM3M8FeTU5dql5NTl0C1fD6CvD6A
  875. AADACX/8gI1AHIABwAPABcAADYyFhQGIiY0NjIWFAYiJjQ2MhYUBiImNEk4JCQ4JOw4JCQ4JOw4JC
  876. Q4JHIkOCQkOCQkOCQkOCQkOCQkOAAAAAEAeABSAUoBngAFAAABBxcjJzcBSomJSYmJAZ6mpqamAAA
  877. AAAEAOQBSAQsBngAFAAAlByM3JzMBC4lJiYlJ+KampgAAAf9qAAABgQKyAAMAACsBATM/VwHAVwKy
  878. AAAAAAIAFAHIAdwClAAHABQAABMVIxUjNSM1BRUjNwcjJxcjNTMXN9pKMkoByDICKzQqATJLKysCl
  879. CmjoykBy46KiY3Lm5sAAQAVAAABvALyABgAAAERIxEjESMRIzUzNTQ3NjMyFxUmBgcGHQEBvFbCVj
  880. k5AxHHHx5iVgcDAg798gHM/jQBzEIOJRuWBUcIJDAVIRYAAAABABX//AHkAvIAJQAAJR4BNxUGIyI
  881. mJyY1ESYjIgcGHQEzFSMRIxEjNTM1NDc2MzIXERQBowIcIxkkKi4CAR4nXgwDbW1WLy8DEbNdOmYa
  882. EQQ/BCQvEjQCFQZWFSEWQv40AcxCDiUblhP9uSEAAAAAAAAWAQ4AAQAAAAAAAAATACgAAQAAAAAAA
  883. QAHAEwAAQAAAAAAAgAHAGQAAQAAAAAAAwAaAKIAAQAAAAAABAAHAM0AAQAAAAAABQA8AU8AAQAAAA
  884. AABgAPAawAAQAAAAAACAALAdQAAQAAAAAACQALAfgAAQAAAAAACwAXAjQAAQAAAAAADAAXAnwAAwA
  885. BBAkAAAAmAAAAAwABBAkAAQAOADwAAwABBAkAAgAOAFQAAwABBAkAAwA0AGwAAwABBAkABAAOAL0A
  886. AwABBAkABQB4ANUAAwABBAkABgAeAYwAAwABBAkACAAWAbwAAwABBAkACQAWAeAAAwABBAkACwAuA
  887. gQAAwABBAkADAAuAkwATgBvACAAUgBpAGcAaAB0AHMAIABSAGUAcwBlAHIAdgBlAGQALgAATm8gUm
  888. lnaHRzIFJlc2VydmVkLgAAQQBpAGwAZQByAG8AbgAAQWlsZXJvbgAAUgBlAGcAdQBsAGEAcgAAUmV
  889. ndWxhcgAAMQAuADEAMAAyADsAVQBLAFcATgA7AEEAaQBsAGUAcgBvAG4ALQBSAGUAZwB1AGwAYQBy
  890. AAAxLjEwMjtVS1dOO0FpbGVyb24tUmVndWxhcgAAQQBpAGwAZQByAG8AbgAAQWlsZXJvbgAAVgBlA
  891. HIAcwBpAG8AbgAgADEALgAxADAAMgA7AFAAUwAgADAAMAAxAC4AMQAwADIAOwBoAG8AdABjAG8Abg
  892. B2ACAAMQAuADAALgA3ADAAOwBtAGEAawBlAG8AdABmAC4AbABpAGIAMgAuADUALgA1ADgAMwAyADk
  893. AAFZlcnNpb24gMS4xMDI7UFMgMDAxLjEwMjtob3Rjb252IDEuMC43MDttYWtlb3RmLmxpYjIuNS41
  894. ODMyOQAAQQBpAGwAZQByAG8AbgAtAFIAZQBnAHUAbABhAHIAAEFpbGVyb24tUmVndWxhcgAAUwBvA
  895. HIAYQAgAFMAYQBnAGEAbgBvAABTb3JhIFNhZ2FubwAAUwBvAHIAYQAgAFMAYQBnAGEAbgBvAABTb3
  896. JhIFNhZ2FubwAAaAB0AHQAcAA6AC8ALwB3AHcAdwAuAGQAbwB0AGMAbwBsAG8AbgAuAG4AZQB0AAB
  897. odHRwOi8vd3d3LmRvdGNvbG9uLm5ldAAAaAB0AHQAcAA6AC8ALwB3AHcAdwAuAGQAbwB0AGMAbwBs
  898. AG8AbgAuAG4AZQB0AABodHRwOi8vd3d3LmRvdGNvbG9uLm5ldAAAAAACAAAAAAAA/4MAMgAAAAAAA
  899. AAAAAAAAAAAAAAAAAAAAHQAAAABAAIAAwAEAAUABgAHAAgACQAKAAsADAANAA4ADwAQABEAEgATAB
  900. QAFQAWABcAGAAZABoAGwAcAB0AHgAfACAAIQAiACMAJAAlACYAJwAoACkAKgArACwALQAuAC8AMAA
  901. xADIAMwA0ADUANgA3ADgAOQA6ADsAPAA9AD4APwBAAEEAQgBDAEQARQBGAEcASABJAEoASwBMAE0A
  902. TgBPAFAAUQBSAFMAVABVAFYAVwBYAFkAWgBbAFwAXQBeAF8AYABhAIsAqQCDAJMAjQDDAKoAtgC3A
  903. LQAtQCrAL4AvwC8AIwAwADBAAAAAAAB//8AAgABAAAADAAAABwAAAACAAIAAwBxAAEAcgBzAAIABA
  904. AAAAIAAAABAAAACgBMAGYAAkRGTFQADmxhdG4AGgAEAAAAAP//AAEAAAAWAANDQVQgAB5NT0wgABZ
  905. ST00gABYAAP//AAEAAAAA//8AAgAAAAEAAmxpZ2EADmxvY2wAFAAAAAEAAQAAAAEAAAACAAYAEAAG
  906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AAAAAAAAAAA
  932. AAAAAAAAAAAAAAAAAAAAAAAAAAAP/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/6AAAAAAAAAA
  933. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAkAFAAEAAAAAQACwAAABcA
  934. BgAAAAAAAAAIAA4AAAAAAAsAEgAAAAAAAAATABkAAwANAAAAAQAJAAAAAAAAAAAAAAAAAAAAGAAAA
  935. AAABwAAAAAAAAAAAAAAFQAFAAAAAAAYABgAAAAUAAAACgAAAAwAAgAPABEAFgAAAAAAAAAAAAAAAA
  936. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAEAEQBdAAYAAAAAAAAAAAAAAAAAAAAAAAA
  937. AAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAcAAAAAAAAABwAAAAAACAAAAAAAAAAAAAcAAAAHAAAAEwAJ
  938. ABUADgAPAAAACwAQAAAAAAAAAAAAAAAAAAUAGAACAAIAAgAAAAIAGAAXAAAAGAAAABYAFgACABYAA
  939. gAWAAAAEQADAAoAFAAMAA0ABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASAAAAEgAGAAEAHgAkAC
  940. YAJwApACoALQAuAC8AMgAzADcAOAA5ADoAPAA9AEUASABOAE8AUgBTAFUAVwBZAFoAWwBcAF0AcwA
  941. AAAAAAQAAAADa3tfFAAAAANAan9kAAAAA4QodoQ==
  942. """
  943. )
  944. ),
  945. 10 if size is None else size,
  946. layout_engine=Layout.BASIC,
  947. )
  948. else:
  949. f = ImageFont()
  950. f._load_pilfont_data(
  951. # courB08
  952. BytesIO(
  953. base64.b64decode(
  954. b"""
  955. UElMZm9udAo7Ozs7OzsxMDsKREFUQQoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  956. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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B//kABAAB
  970. ACEAAAAkAAgABgAAAAD/+QAE//0AJAAAACgABAAGAAAAAP/6AAX//wAoAAAALQAFAAYAAAAB//8A
  971. BAACAC0AAAAwAAMABgAAAAD//AAF//0AMAAAADUAAQAGAAAAAf//AAMAAAA1AAAANwABAAYAAAAB
  972. //kABQABADcAAAA7AAgABgAAAAD/+QAFAAAAOwAAAEAABwAGAAAAAP/5AAYAAABAAAAARgAHAAYA
  973. AAAA//kABQAAAEYAAABLAAcABgAAAAD/+QAFAAAASwAAAFAABwAGAAAAAP/5AAYAAABQAAAAVgAH
  974. AAYAAAAA//kABQAAAFYAAABbAAcABgAAAAD/+QAFAAAAWwAAAGAABwAGAAAAAP/5AAUAAABgAAAA
  975. ZQAHAAYAAAAA//kABQAAAGUAAABqAAcABgAAAAD/+QAFAAAAagAAAG8ABwAGAAAAAf/8AAMAAABv
  976. AAAAcQAEAAYAAAAA//wAAwACAHEAAAB0AAYABgAAAAD/+gAE//8AdAAAAHgABQAGAAAAAP/7AAT/
  977. /gB4AAAAfAADAAYAAAAB//oABf//AHwAAACAAAUABgAAAAD/+gAFAAAAgAAAAIUABgAGAAAAAP/5
  978. AAYAAQCFAAAAiwAIAAYAAP////oABgAAAIsAAACSAAYABgAA////+gAFAAAAkgAAAJgABgAGAAAA
  979. AP/6AAUAAACYAAAAnQAGAAYAAP////oABQAAAJ0AAACjAAYABgAA////+gAFAAAAowAAAKkABgAG
  980. AAD////6AAUAAACpAAAArwAGAAYAAAAA//oABQAAAK8AAAC0AAYABgAA////+gAGAAAAtAAAALsA
  981. BgAGAAAAAP/6AAQAAAC7AAAAvwAGAAYAAP////oABQAAAL8AAADFAAYABgAA////+gAGAAAAxQAA
  982. AMwABgAGAAD////6AAUAAADMAAAA0gAGAAYAAP////oABQAAANIAAADYAAYABgAA////+gAGAAAA
  983. 2AAAAN8ABgAGAAAAAP/6AAUAAADfAAAA5AAGAAYAAP////oABQAAAOQAAADqAAYABgAAAAD/+gAF
  984. AAEA6gAAAO8ABwAGAAD////6AAYAAADvAAAA9gAGAAYAAAAA//oABQAAAPYAAAD7AAYABgAA////
  985. +gAFAAAA+wAAAQEABgAGAAD////6AAYAAAEBAAABCAAGAAYAAP////oABgAAAQgAAAEPAAYABgAA
  986. ////+gAGAAABDwAAARYABgAGAAAAAP/6AAYAAAEWAAABHAAGAAYAAP////oABgAAARwAAAEjAAYA
  987. BgAAAAD/+gAFAAABIwAAASgABgAGAAAAAf/5AAQAAQEoAAABKwAIAAYAAAAA//kABAABASsAAAEv
  988. AAgABgAAAAH/+QAEAAEBLwAAATIACAAGAAAAAP/5AAX//AEyAAABNwADAAYAAAAAAAEABgACATcA
  989. AAE9AAEABgAAAAH/+QAE//wBPQAAAUAAAwAGAAAAAP/7AAYAAAFAAAABRgAFAAYAAP////kABQAA
  990. AUYAAAFMAAcABgAAAAD/+wAFAAABTAAAAVEABQAGAAAAAP/5AAYAAAFRAAABVwAHAAYAAAAA//sA
  991. BQAAAVcAAAFcAAUABgAAAAD/+QAFAAABXAAAAWEABwAGAAAAAP/7AAYAAgFhAAABZwAHAAYAAP//
  992. //kABQAAAWcAAAFtAAcABgAAAAD/+QAGAAABbQAAAXMABwAGAAAAAP/5AAQAAgFzAAABdwAJAAYA
  993. AP////kABgAAAXcAAAF+AAcABgAAAAD/+QAGAAABfgAAAYQABwAGAAD////7AAUAAAGEAAABigAF
  994. AAYAAP////sABQAAAYoAAAGQAAUABgAAAAD/+wAFAAABkAAAAZUABQAGAAD////7AAUAAgGVAAAB
  995. mwAHAAYAAAAA//sABgACAZsAAAGhAAcABgAAAAD/+wAGAAABoQAAAacABQAGAAAAAP/7AAYAAAGn
  996. AAABrQAFAAYAAAAA//kABgAAAa0AAAGzAAcABgAA////+wAGAAABswAAAboABQAGAAD////7AAUA
  997. AAG6AAABwAAFAAYAAP////sABgAAAcAAAAHHAAUABgAAAAD/+wAGAAABxwAAAc0ABQAGAAD////7
  998. AAYAAgHNAAAB1AAHAAYAAAAA//sABQAAAdQAAAH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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAB
  1012. //sAAwACAecAAAHpAAcABgAAAAD/+QAFAAEB6QAAAe4ACAAGAAAAAP/5AAYAAAHuAAAB9AAHAAYA
  1013. AAAA//oABf//AfQAAAH5AAUABgAAAAD/+QAGAAAB+QAAAf8ABwAGAAAAAv/5AAMAAgH/AAACAAAJ
  1014. AAYAAAAA//kABQABAgAAAAIFAAgABgAAAAH/+gAE//sCBQAAAggAAQAGAAAAAP/5AAYAAAIIAAAC
  1015. DgAHAAYAAAAB//kABf/+Ag4AAAISAAUABgAA////+wAGAAACEgAAAhkABQAGAAAAAP/7AAX//gIZ
  1016. AAACHgADAAYAAAAA//wABf/9Ah4AAAIjAAEABgAAAAD/+QAHAAACIwAAAioABwAGAAAAAP/6AAT/
  1017. +wIqAAACLgABAAYAAAAA//kABP/8Ai4AAAIyAAMABgAAAAD/+gAFAAACMgAAAjcABgAGAAAAAf/5
  1018. AAT//QI3AAACOgAEAAYAAAAB//kABP/9AjoAAAI9AAQABgAAAAL/+QAE//sCPQAAAj8AAgAGAAD/
  1019. ///7AAYAAgI/AAACRgAHAAYAAAAA//kABgABAkYAAAJMAAgABgAAAAH//AAD//0CTAAAAk4AAQAG
  1020. AAAAAf//AAQAAgJOAAACUQADAAYAAAAB//kABP/9AlEAAAJUAAQABgAAAAH/+QAF//4CVAAAAlgA
  1021. BQAGAAD////7AAYAAAJYAAACXwAFAAYAAP////kABgAAAl8AAAJmAAcABgAA////+QAGAAACZgAA
  1022. Am0ABwAGAAD////5AAYAAAJtAAACdAAHAAYAAAAA//sABQACAnQAAAJ5AAcABgAA////9wAGAAAC
  1023. eQAAAoAACQAGAAD////3AAYAAAKAAAAChwAJAAYAAP////cABgAAAocAAAKOAAkABgAA////9wAG
  1024. AAACjgAAApUACQAGAAD////4AAYAAAKVAAACnAAIAAYAAP////cABgAAApwAAAKjAAkABgAA////
  1025. +gAGAAACowAAAqoABgAGAAAAAP/6AAUAAgKqAAACrwAIAAYAAP////cABQAAAq8AAAK1AAkABgAA
  1026. ////9wAFAAACtQAAArsACQAGAAD////3AAUAAAK7AAACwQAJAAYAAP////gABQAAAsEAAALHAAgA
  1027. BgAAAAD/9wAEAAACxwAAAssACQAGAAAAAP/3AAQAAALLAAACzwAJAAYAAAAA//cABAAAAs8AAALT
  1028. AAkABgAAAAD/+AAEAAAC0wAAAtcACAAGAAD////6AAUAAALXAAAC3QAGAAYAAP////cABgAAAt0A
  1029. AALkAAkABgAAAAD/9wAFAAAC5AAAAukACQAGAAAAAP/3AAUAAALpAAAC7gAJAAYAAAAA//cABQAA
  1030. Au4AAALzAAkABgAAAAD/9wAFAAAC8wAAAvgACQAGAAAAAP/4AAUAAAL4AAAC/QAIAAYAAAAA//oA
  1031. Bf//Av0AAAMCAAUABgAA////+gAGAAADAgAAAwkABgAGAAD////3AAYAAAMJAAADEAAJAAYAAP//
  1032. //cABgAAAxAAAAMXAAkABgAA////9wAGAAADFwAAAx4ACQAGAAD////4AAYAAAAAAAoABwASAAYA
  1033. AP////cABgAAAAcACgAOABMABgAA////+gAFAAAADgAKABQAEAAGAAD////6AAYAAAAUAAoAGwAQ
  1034. AAYAAAAA//gABgAAABsACgAhABIABgAAAAD/+AAGAAAAIQAKACcAEgAGAAAAAP/4AAYAAAAnAAoA
  1035. LQASAAYAAAAA//gABgAAAC0ACgAzABIABgAAAAD/+QAGAAAAMwAKADkAEQAGAAAAAP/3AAYAAAA5
  1036. AAoAPwATAAYAAP////sABQAAAD8ACgBFAA8ABgAAAAD/+wAFAAIARQAKAEoAEQAGAAAAAP/4AAUA
  1037. AABKAAoATwASAAYAAAAA//gABQAAAE8ACgBUABIABgAAAAD/+AAFAAAAVAAKAFkAEgAGAAAAAP/5
  1038. AAUAAABZAAoAXgARAAYAAAAA//gABgAAAF4ACgBkABIABgAAAAD/+AAGAAAAZAAKAGoAEgAGAAAA
  1039. AP/4AAYAAABqAAoAcAASAAYAAAAA//kABgAAAHAACgB2ABEABgAAAAD/+AAFAAAAdgAKAHsAEgAG
  1040. AAD////4AAYAAAB7AAoAggASAAYAAAAA//gABQAAAIIACgCHABIABgAAAAD/+AAFAAAAhwAKAIwA
  1041. EgAGAAAAAP/4AAUAAACMAAoAkQASAAYAAAAA//gABQAAAJEACgCWABIABgAAAAD/+QAFAAAAlgAK
  1042. AJsAEQAGAAAAAP/6AAX//wCbAAoAoAAPAAYAAAAA//oABQABAKAACgClABEABgAA////+AAGAAAA
  1043. pQAKAKwAEgAGAAD////4AAYAAACsAAoAswASAAYAAP////gABgAAALMACgC6ABIABgAA////+QAG
  1044. AAAAugAKAMEAEQAGAAD////4AAYAAgDBAAoAyAAUAAYAAP////kABQACAMgACgDOABMABgAA////
  1045. +QAGAAIAzgAKANUAEw==
  1046. """
  1047. )
  1048. ),
  1049. Image.open(
  1050. BytesIO(
  1051. base64.b64decode(
  1052. b"""
  1053. iVBORw0KGgoAAAANSUhEUgAAAx4AAAAUAQAAAAArMtZoAAAEwElEQVR4nABlAJr/AHVE4czCI/4u
  1054. Mc4b7vuds/xzjz5/3/7u/n9vMe7vnfH/9++vPn/xyf5zhxzjt8GHw8+2d83u8x27199/nxuQ6Od9
  1055. M43/5z2I+9n9ZtmDBwMQECDRQw/eQIQohJXxpBCNVE6QCCAAAAD//wBlAJr/AgALyj1t/wINwq0g
  1056. LeNZUworuN1cjTPIzrTX6ofHWeo3v336qPzfEwRmBnHTtf95/fglZK5N0PDgfRTslpGBvz7LFc4F
  1057. IUXBWQGjQ5MGCx34EDFPwXiY4YbYxavpnhHFrk14CDAAAAD//wBlAJr/AgKqRooH2gAgPeggvUAA
  1058. Bu2WfgPoAwzRAABAAAAAAACQgLz/3Uv4Gv+gX7BJgDeeGP6AAAD1NMDzKHD7ANWr3loYbxsAD791
  1059. NAADfcoIDyP44K/jv4Y63/Z+t98Ovt+ub4T48LAAAAD//wBlAJr/AuplMlADJAAAAGuAphWpqhMx
  1060. in0A/fRvAYBABPgBwBUgABBQ/sYAyv9g0bCHgOLoGAAAAAAAREAAwI7nr0ArYpow7aX8//9LaP/9
  1061. SjdavWA8ePHeBIKB//81/83ndznOaXx379wAAAD//wBlAJr/AqDxW+D3AABAAbUh/QMnbQag/gAY
  1062. AYDAAACgtgD/gOqAAAB5IA/8AAAk+n9w0AAA8AAAmFRJuPo27ciC0cD5oeW4E7KA/wD3ECMAn2tt
  1063. y8PgwH8AfAxFzC0JzeAMtratAsC/ffwAAAD//wBlAJr/BGKAyCAA4AAAAvgeYTAwHd1kmQF5chkG
  1064. ABoMIHcL5xVpTfQbUqzlAAAErwAQBgAAEOClA5D9il08AEh/tUzdCBsXkbgACED+woQg8Si9VeqY
  1065. lODCn7lmF6NhnAEYgAAA/NMIAAAAAAD//2JgjLZgVGBg5Pv/Tvpc8hwGBjYGJADjHDrAwPzAjv/H
  1066. /Wf3PzCwtzcwHmBgYGcwbZz8wHaCAQMDOwMDQ8MCBgYOC3W7mp+f0w+wHOYxO3OG+e376hsMZjk3
  1067. AAAAAP//YmCMY2A4wMAIN5e5gQETPD6AZisDAwMDgzSDAAPjByiHcQMDAwMDg1nOze1lByRu5/47
  1068. c4859311AYNZzg0AAAAA//9iYGDBYihOIIMuwIjGL39/fwffA8b//xv/P2BPtzzHwCBjUQAAAAD/
  1069. /yLFBrIBAAAA//9i1HhcwdhizX7u8NZNzyLbvT97bfrMf/QHI8evOwcSqGUJAAAA//9iYBB81iSw
  1070. pEE170Qrg5MIYydHqwdDQRMrAwcVrQAAAAD//2J4x7j9AAMDn8Q/BgYLBoaiAwwMjPdvMDBYM1Tv
  1071. oJodAAAAAP//Yqo/83+dxePWlxl3npsel9lvLfPcqlE9725C+acfVLMEAAAA//9i+s9gwCoaaGMR
  1072. evta/58PTEWzr21hufPjA8N+qlnBwAAAAAD//2JiWLci5v1+HmFXDqcnULE/MxgYGBj+f6CaJQAA
  1073. AAD//2Ji2FrkY3iYpYC5qDeGgeEMAwPDvwQBBoYvcTwOVLMEAAAA//9isDBgkP///0EOg9z35v//
  1074. Gc/eeW7BwPj5+QGZhANUswMAAAD//2JgqGBgYGBgqEMXlvhMPUsAAAAA//8iYDd1AAAAAP//AwDR
  1075. w7IkEbzhVQAAAABJRU5ErkJggg==
  1076. """
  1077. )
  1078. )
  1079. ),
  1080. )
  1081. return f