Skip to content

Commit

Permalink
[font] get_missing_glyphs - Add support_only_ascii_char_for_symbol_fo…
Browse files Browse the repository at this point in the history
…nt param
  • Loading branch information
moi15moi committed Oct 8, 2023
1 parent 5f2a9e0 commit ecdb59a
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions font_collector/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,19 @@ def __hash__(self):
def __repr__(self):
return f'Filename: "{self.filename}" Family_names: "{self.family_names}", Weight: "{self.weight}", Italic: "{self.italic}, Exact_names: "{self.exact_names}", Named_instance_coordinates: "{self.named_instance_coordinates}"'

def get_missing_glyphs(self, text: Sequence[str]) -> Set[str]:
def get_missing_glyphs(
self,
text: Sequence[str],
support_only_ascii_char_for_symbol_font: bool = False
) -> Set[str]:
"""
Parameters:
text (Sequence[str]): Text
support_only_ascii_char_for_symbol_font (bool):
Libass only support ascii character for symbol font, but VSFilter can support more character.
If you wish to use libass, we recommand you to set this param to True.
If you wish to use VSFilter, we recommand you to set this param to False.
For more detail, see the issue: https://github.com/libass/libass/issues/319
Returns:
A set of all the character that the font cannot display.
"""
Expand Down Expand Up @@ -302,15 +311,18 @@ def get_missing_glyphs(self, text: Sequence[str]) -> Set[str]:
if cmap_encoding == "unicode":
codepoint = ord(char)
else:
if cmap_encoding == "unknown" and platform_id == 3 and encoding_id == 0:
cmap_encoding = FontParser.get_symbol_cmap_encoding(face)

if cmap_encoding is None:
# Fallback if guess fails
cmap_encoding = "cp1252"
else:
# cmap not supported
continue
if cmap_encoding == "unknown":
if platform_id == 3 and encoding_id == 0:
if support_only_ascii_char_for_symbol_font and not char.isascii():
continue
cmap_encoding = FontParser.get_symbol_cmap_encoding(face)

if cmap_encoding is None:
# Fallback if guess fails
cmap_encoding = "cp1252"
else:
# cmap not supported
continue

try:
codepoint = int.from_bytes(char.encode(cmap_encoding), "big")
Expand Down

0 comments on commit ecdb59a

Please sign in to comment.