font_manager.pyi 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. from dataclasses import dataclass
  2. import os
  3. from matplotlib._afm import AFM
  4. from matplotlib import ft2font
  5. from pathlib import Path
  6. from collections.abc import Iterable
  7. from typing import Any, Literal
  8. font_scalings: dict[str | None, float]
  9. stretch_dict: dict[str, int]
  10. weight_dict: dict[str, int]
  11. font_family_aliases: set[str]
  12. MSFolders: str
  13. MSFontDirectories: list[str]
  14. MSUserFontDirectories: list[str]
  15. X11FontDirectories: list[str]
  16. OSXFontDirectories: list[str]
  17. def get_fontext_synonyms(fontext: str) -> list[str]: ...
  18. def list_fonts(directory: str, extensions: Iterable[str]) -> list[str]: ...
  19. def win32FontDirectory() -> str: ...
  20. def _get_fontconfig_fonts() -> list[Path]: ...
  21. def findSystemFonts(
  22. fontpaths: Iterable[str | os.PathLike | Path] | None = ..., fontext: str = ...
  23. ) -> list[str]: ...
  24. @dataclass
  25. class FontEntry:
  26. fname: str = ...
  27. name: str = ...
  28. style: str = ...
  29. variant: str = ...
  30. weight: str | int = ...
  31. stretch: str = ...
  32. size: str = ...
  33. def _repr_html_(self) -> str: ...
  34. def _repr_png_(self) -> bytes: ...
  35. def ttfFontProperty(font: ft2font.FT2Font) -> FontEntry: ...
  36. def afmFontProperty(fontpath: str, font: AFM) -> FontEntry: ...
  37. class FontProperties:
  38. def __init__(
  39. self,
  40. family: str | Iterable[str] | None = ...,
  41. style: Literal["normal", "italic", "oblique"] | None = ...,
  42. variant: Literal["normal", "small-caps"] | None = ...,
  43. weight: int | str | None = ...,
  44. stretch: int | str | None = ...,
  45. size: float | str | None = ...,
  46. fname: str | os.PathLike | Path | None = ...,
  47. math_fontfamily: str | None = ...,
  48. ) -> None: ...
  49. def __hash__(self) -> int: ...
  50. def __eq__(self, other: object) -> bool: ...
  51. def get_family(self) -> list[str]: ...
  52. def get_name(self) -> str: ...
  53. def get_style(self) -> Literal["normal", "italic", "oblique"]: ...
  54. def get_variant(self) -> Literal["normal", "small-caps"]: ...
  55. def get_weight(self) -> int | str: ...
  56. def get_stretch(self) -> int | str: ...
  57. def get_size(self) -> float: ...
  58. def get_file(self) -> str | bytes | None: ...
  59. def get_fontconfig_pattern(self) -> dict[str, list[Any]]: ...
  60. def set_family(self, family: str | Iterable[str] | None) -> None: ...
  61. def set_style(
  62. self, style: Literal["normal", "italic", "oblique"] | None
  63. ) -> None: ...
  64. def set_variant(self, variant: Literal["normal", "small-caps"] | None) -> None: ...
  65. def set_weight(self, weight: int | str | None) -> None: ...
  66. def set_stretch(self, stretch: int | str | None) -> None: ...
  67. def set_size(self, size: float | str | None) -> None: ...
  68. def set_file(self, file: str | os.PathLike | Path | None) -> None: ...
  69. def set_fontconfig_pattern(self, pattern: str) -> None: ...
  70. def get_math_fontfamily(self) -> str: ...
  71. def set_math_fontfamily(self, fontfamily: str | None) -> None: ...
  72. def copy(self) -> FontProperties: ...
  73. # Aliases
  74. set_name = set_family
  75. get_slant = get_style
  76. set_slant = set_style
  77. get_size_in_points = get_size
  78. def json_dump(data: FontManager, filename: str | Path | os.PathLike) -> None: ...
  79. def json_load(filename: str | Path | os.PathLike) -> FontManager: ...
  80. class FontManager:
  81. __version__: int
  82. default_size: float | None
  83. defaultFamily: dict[str, str]
  84. afmlist: list[FontEntry]
  85. ttflist: list[FontEntry]
  86. def __init__(self, size: float | None = ..., weight: str = ...) -> None: ...
  87. def addfont(self, path: str | Path | os.PathLike) -> None: ...
  88. @property
  89. def defaultFont(self) -> dict[str, str]: ...
  90. def get_default_weight(self) -> str: ...
  91. @staticmethod
  92. def get_default_size() -> float: ...
  93. def set_default_weight(self, weight: str) -> None: ...
  94. def score_family(
  95. self, families: str | list[str] | tuple[str], family2: str
  96. ) -> float: ...
  97. def score_style(self, style1: str, style2: str) -> float: ...
  98. def score_variant(self, variant1: str, variant2: str) -> float: ...
  99. def score_stretch(self, stretch1: str | int, stretch2: str | int) -> float: ...
  100. def score_weight(self, weight1: str | float, weight2: str | float) -> float: ...
  101. def score_size(self, size1: str | float, size2: str | float) -> float: ...
  102. def findfont(
  103. self,
  104. prop: str | FontProperties,
  105. fontext: Literal["ttf", "afm"] = ...,
  106. directory: str | None = ...,
  107. fallback_to_default: bool = ...,
  108. rebuild_if_missing: bool = ...,
  109. ) -> str: ...
  110. def get_font_names(self) -> list[str]: ...
  111. def is_opentype_cff_font(filename: str) -> bool: ...
  112. def get_font(
  113. font_filepaths: Iterable[str | Path | bytes] | str | Path | bytes,
  114. hinting_factor: int | None = ...,
  115. ) -> ft2font.FT2Font: ...
  116. fontManager: FontManager
  117. def findfont(
  118. prop: str | FontProperties,
  119. fontext: Literal["ttf", "afm"] = ...,
  120. directory: str | None = ...,
  121. fallback_to_default: bool = ...,
  122. rebuild_if_missing: bool = ...,
  123. ) -> str: ...
  124. def get_font_names() -> list[str]: ...