ft2font.pyi 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. from enum import Enum, Flag
  2. import sys
  3. from typing import BinaryIO, Literal, TypedDict, final, overload, cast
  4. from typing_extensions import Buffer # < Py 3.12
  5. import numpy as np
  6. from numpy.typing import NDArray
  7. __freetype_build_type__: str
  8. __freetype_version__: str
  9. class FaceFlags(Flag):
  10. SCALABLE = cast(int, ...)
  11. FIXED_SIZES = cast(int, ...)
  12. FIXED_WIDTH = cast(int, ...)
  13. SFNT = cast(int, ...)
  14. HORIZONTAL = cast(int, ...)
  15. VERTICAL = cast(int, ...)
  16. KERNING = cast(int, ...)
  17. FAST_GLYPHS = cast(int, ...)
  18. MULTIPLE_MASTERS = cast(int, ...)
  19. GLYPH_NAMES = cast(int, ...)
  20. EXTERNAL_STREAM = cast(int, ...)
  21. HINTER = cast(int, ...)
  22. CID_KEYED = cast(int, ...)
  23. TRICKY = cast(int, ...)
  24. COLOR = cast(int, ...)
  25. # VARIATION = cast(int, ...) # FT 2.9
  26. # SVG = cast(int, ...) # FT 2.12
  27. # SBIX = cast(int, ...) # FT 2.12
  28. # SBIX_OVERLAY = cast(int, ...) # FT 2.12
  29. class Kerning(Enum):
  30. DEFAULT = cast(int, ...)
  31. UNFITTED = cast(int, ...)
  32. UNSCALED = cast(int, ...)
  33. class LoadFlags(Flag):
  34. DEFAULT = cast(int, ...)
  35. NO_SCALE = cast(int, ...)
  36. NO_HINTING = cast(int, ...)
  37. RENDER = cast(int, ...)
  38. NO_BITMAP = cast(int, ...)
  39. VERTICAL_LAYOUT = cast(int, ...)
  40. FORCE_AUTOHINT = cast(int, ...)
  41. CROP_BITMAP = cast(int, ...)
  42. PEDANTIC = cast(int, ...)
  43. IGNORE_GLOBAL_ADVANCE_WIDTH = cast(int, ...)
  44. NO_RECURSE = cast(int, ...)
  45. IGNORE_TRANSFORM = cast(int, ...)
  46. MONOCHROME = cast(int, ...)
  47. LINEAR_DESIGN = cast(int, ...)
  48. NO_AUTOHINT = cast(int, ...)
  49. COLOR = cast(int, ...)
  50. COMPUTE_METRICS = cast(int, ...) # FT 2.6.1
  51. # BITMAP_METRICS_ONLY = cast(int, ...) # FT 2.7.1
  52. # NO_SVG = cast(int, ...) # FT 2.13.1
  53. # The following should be unique, but the above can be OR'd together.
  54. TARGET_NORMAL = cast(int, ...)
  55. TARGET_LIGHT = cast(int, ...)
  56. TARGET_MONO = cast(int, ...)
  57. TARGET_LCD = cast(int, ...)
  58. TARGET_LCD_V = cast(int, ...)
  59. class StyleFlags(Flag):
  60. NORMAL = cast(int, ...)
  61. ITALIC = cast(int, ...)
  62. BOLD = cast(int, ...)
  63. class _SfntHeadDict(TypedDict):
  64. version: tuple[int, int]
  65. fontRevision: tuple[int, int]
  66. checkSumAdjustment: int
  67. magicNumber: int
  68. flags: int
  69. unitsPerEm: int
  70. created: tuple[int, int]
  71. modified: tuple[int, int]
  72. xMin: int
  73. yMin: int
  74. xMax: int
  75. yMax: int
  76. macStyle: int
  77. lowestRecPPEM: int
  78. fontDirectionHint: int
  79. indexToLocFormat: int
  80. glyphDataFormat: int
  81. class _SfntMaxpDict(TypedDict):
  82. version: tuple[int, int]
  83. numGlyphs: int
  84. maxPoints: int
  85. maxContours: int
  86. maxComponentPoints: int
  87. maxComponentContours: int
  88. maxZones: int
  89. maxTwilightPoints: int
  90. maxStorage: int
  91. maxFunctionDefs: int
  92. maxInstructionDefs: int
  93. maxStackElements: int
  94. maxSizeOfInstructions: int
  95. maxComponentElements: int
  96. maxComponentDepth: int
  97. class _SfntOs2Dict(TypedDict):
  98. version: int
  99. xAvgCharWidth: int
  100. usWeightClass: int
  101. usWidthClass: int
  102. fsType: int
  103. ySubscriptXSize: int
  104. ySubscriptYSize: int
  105. ySubscriptXOffset: int
  106. ySubscriptYOffset: int
  107. ySuperscriptXSize: int
  108. ySuperscriptYSize: int
  109. ySuperscriptXOffset: int
  110. ySuperscriptYOffset: int
  111. yStrikeoutSize: int
  112. yStrikeoutPosition: int
  113. sFamilyClass: int
  114. panose: bytes
  115. ulCharRange: tuple[int, int, int, int]
  116. achVendID: bytes
  117. fsSelection: int
  118. fsFirstCharIndex: int
  119. fsLastCharIndex: int
  120. class _SfntHheaDict(TypedDict):
  121. version: tuple[int, int]
  122. ascent: int
  123. descent: int
  124. lineGap: int
  125. advanceWidthMax: int
  126. minLeftBearing: int
  127. minRightBearing: int
  128. xMaxExtent: int
  129. caretSlopeRise: int
  130. caretSlopeRun: int
  131. caretOffset: int
  132. metricDataFormat: int
  133. numOfLongHorMetrics: int
  134. class _SfntVheaDict(TypedDict):
  135. version: tuple[int, int]
  136. vertTypoAscender: int
  137. vertTypoDescender: int
  138. vertTypoLineGap: int
  139. advanceHeightMax: int
  140. minTopSideBearing: int
  141. minBottomSizeBearing: int
  142. yMaxExtent: int
  143. caretSlopeRise: int
  144. caretSlopeRun: int
  145. caretOffset: int
  146. metricDataFormat: int
  147. numOfLongVerMetrics: int
  148. class _SfntPostDict(TypedDict):
  149. format: tuple[int, int]
  150. italicAngle: tuple[int, int]
  151. underlinePosition: int
  152. underlineThickness: int
  153. isFixedPitch: int
  154. minMemType42: int
  155. maxMemType42: int
  156. minMemType1: int
  157. maxMemType1: int
  158. class _SfntPcltDict(TypedDict):
  159. version: tuple[int, int]
  160. fontNumber: int
  161. pitch: int
  162. xHeight: int
  163. style: int
  164. typeFamily: int
  165. capHeight: int
  166. symbolSet: int
  167. typeFace: bytes
  168. characterComplement: bytes
  169. strokeWeight: int
  170. widthType: int
  171. serifStyle: int
  172. @final
  173. class FT2Font(Buffer):
  174. def __init__(
  175. self,
  176. filename: str | BinaryIO,
  177. hinting_factor: int = ...,
  178. *,
  179. _fallback_list: list[FT2Font] | None = ...,
  180. _kerning_factor: int = ...
  181. ) -> None: ...
  182. if sys.version_info[:2] >= (3, 12):
  183. def __buffer__(self, flags: int) -> memoryview: ...
  184. def _get_fontmap(self, string: str) -> dict[str, FT2Font]: ...
  185. def clear(self) -> None: ...
  186. def draw_glyph_to_bitmap(
  187. self, image: FT2Image, x: int, y: int, glyph: Glyph, antialiased: bool = ...
  188. ) -> None: ...
  189. def draw_glyphs_to_bitmap(self, antialiased: bool = ...) -> None: ...
  190. def get_bitmap_offset(self) -> tuple[int, int]: ...
  191. def get_char_index(self, codepoint: int) -> int: ...
  192. def get_charmap(self) -> dict[int, int]: ...
  193. def get_descent(self) -> int: ...
  194. def get_glyph_name(self, index: int) -> str: ...
  195. def get_image(self) -> NDArray[np.uint8]: ...
  196. def get_kerning(self, left: int, right: int, mode: Kerning) -> int: ...
  197. def get_name_index(self, name: str) -> int: ...
  198. def get_num_glyphs(self) -> int: ...
  199. def get_path(self) -> tuple[NDArray[np.float64], NDArray[np.int8]]: ...
  200. def get_ps_font_info(
  201. self,
  202. ) -> tuple[str, str, str, str, str, int, int, int, int]: ...
  203. def get_sfnt(self) -> dict[tuple[int, int, int, int], bytes]: ...
  204. @overload
  205. def get_sfnt_table(self, name: Literal["head"]) -> _SfntHeadDict | None: ...
  206. @overload
  207. def get_sfnt_table(self, name: Literal["maxp"]) -> _SfntMaxpDict | None: ...
  208. @overload
  209. def get_sfnt_table(self, name: Literal["OS/2"]) -> _SfntOs2Dict | None: ...
  210. @overload
  211. def get_sfnt_table(self, name: Literal["hhea"]) -> _SfntHheaDict | None: ...
  212. @overload
  213. def get_sfnt_table(self, name: Literal["vhea"]) -> _SfntVheaDict | None: ...
  214. @overload
  215. def get_sfnt_table(self, name: Literal["post"]) -> _SfntPostDict | None: ...
  216. @overload
  217. def get_sfnt_table(self, name: Literal["pclt"]) -> _SfntPcltDict | None: ...
  218. def get_width_height(self) -> tuple[int, int]: ...
  219. def load_char(self, charcode: int, flags: LoadFlags = ...) -> Glyph: ...
  220. def load_glyph(self, glyphindex: int, flags: LoadFlags = ...) -> Glyph: ...
  221. def select_charmap(self, i: int) -> None: ...
  222. def set_charmap(self, i: int) -> None: ...
  223. def set_size(self, ptsize: float, dpi: float) -> None: ...
  224. def set_text(
  225. self, string: str, angle: float = ..., flags: LoadFlags = ...
  226. ) -> NDArray[np.float64]: ...
  227. @property
  228. def ascender(self) -> int: ...
  229. @property
  230. def bbox(self) -> tuple[int, int, int, int]: ...
  231. @property
  232. def descender(self) -> int: ...
  233. @property
  234. def face_flags(self) -> FaceFlags: ...
  235. @property
  236. def family_name(self) -> str: ...
  237. @property
  238. def fname(self) -> str: ...
  239. @property
  240. def height(self) -> int: ...
  241. @property
  242. def max_advance_height(self) -> int: ...
  243. @property
  244. def max_advance_width(self) -> int: ...
  245. @property
  246. def num_charmaps(self) -> int: ...
  247. @property
  248. def num_faces(self) -> int: ...
  249. @property
  250. def num_fixed_sizes(self) -> int: ...
  251. @property
  252. def num_glyphs(self) -> int: ...
  253. @property
  254. def num_named_instances(self) -> int: ...
  255. @property
  256. def postscript_name(self) -> str: ...
  257. @property
  258. def scalable(self) -> bool: ...
  259. @property
  260. def style_flags(self) -> StyleFlags: ...
  261. @property
  262. def style_name(self) -> str: ...
  263. @property
  264. def underline_position(self) -> int: ...
  265. @property
  266. def underline_thickness(self) -> int: ...
  267. @property
  268. def units_per_EM(self) -> int: ...
  269. @final
  270. class FT2Image(Buffer):
  271. def __init__(self, width: int, height: int) -> None: ...
  272. def draw_rect_filled(self, x0: int, y0: int, x1: int, y1: int) -> None: ...
  273. if sys.version_info[:2] >= (3, 12):
  274. def __buffer__(self, flags: int) -> memoryview: ...
  275. @final
  276. class Glyph:
  277. @property
  278. def width(self) -> int: ...
  279. @property
  280. def height(self) -> int: ...
  281. @property
  282. def horiBearingX(self) -> int: ...
  283. @property
  284. def horiBearingY(self) -> int: ...
  285. @property
  286. def horiAdvance(self) -> int: ...
  287. @property
  288. def linearHoriAdvance(self) -> int: ...
  289. @property
  290. def vertBearingX(self) -> int: ...
  291. @property
  292. def vertBearingY(self) -> int: ...
  293. @property
  294. def vertAdvance(self) -> int: ...
  295. @property
  296. def bbox(self) -> tuple[int, int, int, int]: ...