FontIndexList
ClassSource
FontIndexList()
The internal font list maintained by the FontLocator.
This list is designed for fast query.
Arguments
No argument is needed.
Methods
add_font
self.add_font(font: FontInfo, names_for_query: Mapping[FontLanguage, Sequence[str]])
Add a font to this index list.
Requires
| Name | Type | Required | |
|---|---|---|---|
font | FontInfo | The font information that can be used for retrieving the font. | |
names_for_query | Mapping[FontLanguage, Sequence[str]] | All names that can be used for querying this font. Some fonts may have more than one name for a specific language, that's because such font may have a different name compared to the full name. |
from_file
v_1: Self = FontIndexList.from_file(fobj: str | PathLike[str] | IO[str])
Load the cached data as this font index list.
Requires
| Name | Type | Required | |
|---|---|---|---|
fobj | str | PathLike[str] | IO[str] | The path to the output file or a file-like object used for saving the file. |
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The font index list loaded from the file. |
list_fonts_of_lang
v_1: list[FontInfo] = self.list_fonts_of_lang(lang: str | FontLanguage)
List all fonts supporting a specific language.
Requires
| Name | Type | Required | |
|---|---|---|---|
lang | str | FontLanguage | The language used for searching the font name. If this value is |
Returns
| Name | Type | |
|---|---|---|
v_1 | list[FontInfo] | A list of all fonts supporting this language. |
query
v_1: list[tuple[FontInfo, str, float]] = self.query(
name: str, lang: str | FontLanguage = FontLanguage.en, threshold: float = 70.0
)
Query the font.
Requires
| Name | Type | Required | |
|---|---|---|---|
name | str | The name used for querying the font. Usually, the name is related to the language. | |
lang | str | FontLanguage | The language of the font name. It will limit the searching scope of the fonts. The If this value is | |
threshold | float | The threshold for the matching rate. Any matched result with a score lower than this threshold will be filtered out. |
Returns
| Name | Type | |
|---|---|---|
v_1 | list[tuple[FontInfo, str, float]] | A list of queried results. The results will be sorted by the matching rate. If no font can be found, will return an empty list. Each item include:
Will not return more than five candidates. |
query_best
v_1: tuple[FontInfo, str, float] | None = self.query_best(
name: str, lang: str | FontLanguage = FontLanguage.en, threshold: float = 70.0
)
Query only one font.
Requires
| Name | Type | Required | |
|---|---|---|---|
name | str | The name used for querying the font. Usually, the name is related to the language. | |
lang | str | FontLanguage | The language of the font name. It will limit the searching scope of the fonts. The If this value is | |
threshold | float | The threshold for the matching rate. If the best matched font has a score lower than this value, will return None. |
Returns
| Name | Type | |
|---|---|---|
v_1 | tuple[FontInfo, str, float] | None | The best matched font. If no font can be found, will return The returned values are
|
to_file
self.to_file(fobj: str | PathLike[str] | IO[str])
Serialize this index list as a file.
Requires
| Name | Type | Required | |
|---|---|---|---|
fobj | str | PathLike[str] | IO[str] | The path to the output file or a file-like object used for saving the file. |
Properties
fonts
fonts: list[FontInfo] = self.fonts
List of all indexed fonts.
lang_stats
lang_stats: dict[FontLanguage, int] = self.lang_stats
Get the count of fonts for each language.
langs
langs: list[FontLanguage] = self.langs
Get the supported languages.
n_fonts
n_fonts: int = self.n_fonts
Number of fonts.