Skip to content

Commit

Permalink
Remove trailing space
Browse files Browse the repository at this point in the history
  • Loading branch information
moi15moi committed Apr 28, 2024
1 parent 4ec00ab commit 567b0c1
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 61 deletions.
4 changes: 2 additions & 2 deletions font_collector/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def main() -> None:
if font_result.need_faux_bold or font_result.mismatch_bold or font_result.mismatch_italic:
_logger.warning(f"Used on lines: {' '.join(str(line) for line in usage_data.ordered_lines)}")


missing_glyphs = font_result.font_face.get_missing_glyphs(usage_data.characters_used)
if len(missing_glyphs) > 0:
_logger.warning(f"'{style.fontname}' is missing the following glyphs used: {missing_glyphs}")
Expand All @@ -67,7 +67,7 @@ def main() -> None:
_logger.info(f"All fonts found")
else:
_logger.info(f"{nbr_font_not_found} fonts could not be found.")

fonts_file_found: Set[FontFile] = set()

for font_result in font_results:
Expand Down
10 changes: 5 additions & 5 deletions font_collector/ass/abc_ass_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def get_line_text(self, i: int) -> str:
"""
self.__verify_if_line_exist(i)
return self._get_line_text(i)


@abstractmethod
def _is_line_dialogue(self, i: int) -> bool:
Expand All @@ -152,8 +152,8 @@ def is_line_dialogue(self, i: int) -> bool:
"""
self.__verify_if_line_exist(i)
return self._is_line_dialogue(i)


def get_sub_styles(self) -> Dict[str, AssStyle]:
"""
Returns:
Expand Down Expand Up @@ -206,7 +206,7 @@ def is_ascii_digit(s: str) -> bool:
sub_styles[style_name] = ass_style

return sub_styles


def __set_used_styles(
self,
Expand Down Expand Up @@ -332,7 +332,7 @@ def get_used_style(self, collect_draw_fonts: bool = False) -> Dict[AssStyle, Usa

for i in range(self.get_nbr_line()):
if self.is_line_dialogue(i):

original_line_style = sub_styles.get(self.get_line_style_name(i), None)
tags = parse_line(self.get_line_text(i))

Expand Down
4 changes: 2 additions & 2 deletions font_collector/ass/ass_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _get_sub_wrap_style(self) -> Optional[WrapStyle]:
sub_wrap_style = WrapStyle(self.subtitle.wrap_style)
except KeyError:
sub_wrap_style = None

return sub_wrap_style


Expand Down Expand Up @@ -68,7 +68,7 @@ def _get_line_style_name(self, i: int) -> str:
def _get_line_text(self, i: int) -> str:
text: str = self.subtitle.events[i].text
return text


def _is_line_dialogue(self, i: int) -> bool:
return isinstance(self.subtitle.events[i], Dialogue)
20 changes: 10 additions & 10 deletions font_collector/font/abc_font_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def family_names(self) -> List[Name]:
@abstractmethod
def exact_names(self) -> List[Name]:
pass

@property
@abstractmethod
def weight(self) -> int:
Expand All @@ -79,12 +79,12 @@ def weight(self) -> int:
@abstractmethod
def is_italic(self) -> bool:
pass

@property
@abstractmethod
def is_glyph_emboldened(self) -> bool:
pass

@property
@abstractmethod
def font_type(self) -> FontType:
Expand All @@ -108,7 +108,7 @@ def __eq__(self, other: object) -> bool:
@abstractmethod
def __hash__(self) -> int:
pass


@abstractmethod
def __repr__(self) -> str:
Expand All @@ -120,7 +120,7 @@ def get_family_name_from_lang(self, lang_code: str, exact_match: bool = False) -
See the doc of _get_name_from_lang
"""
return self._get_name_from_lang(self.family_names, lang_code, exact_match)


def get_best_family_name(self) -> Name:
"""
Expand All @@ -134,7 +134,7 @@ def get_exact_name_from_lang(self, lang_code: str, exact_match: bool = False) ->
See the doc of _get_name_from_lang
"""
return self._get_name_from_lang(self.exact_names, lang_code, exact_match)


def get_best_exact_name(self) -> Name:
"""
Expand Down Expand Up @@ -172,10 +172,10 @@ def _get_best_name(names: List[Name]) -> Name:
result = ABCFontFace._get_name_from_lang(names, "en", False)
if result is not None:
return result

return names[0]


@staticmethod
def _get_name_from_lang(names: List[Name], lang_code: str, exact_match: bool) -> Optional[Name]:
"""
Expand All @@ -194,7 +194,7 @@ def _get_name_from_lang(names: List[Name], lang_code: str, exact_match: bool) ->
"""
if not tag_is_valid(lang_code):
raise InvalidLanguageCode(f"The language code \"{lang_code}\" does not conform to IETF BCP-47")

requested_lang = Language.get(lang_code)
is_requested_chinese = requested_lang.language == "zh"
if is_requested_chinese:
Expand All @@ -209,7 +209,7 @@ def _get_name_from_lang(names: List[Name], lang_code: str, exact_match: bool) ->
if name.lang_code.language == requested_lang.language:
is_territory_equal = name.lang_code.territory == requested_lang.territory
is_script_equal = name.lang_code.script == requested_lang.script

if is_territory_equal and is_script_equal:
best_name = name
break
Expand Down
4 changes: 2 additions & 2 deletions font_collector/font/factory_abc_font_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def __create_font(ttFont: TTFont, font_path: Path, font_index: int) -> NormalFon
cmaps = FontParser.get_supported_cmaps(ttFont)
if len(cmaps) == 0:
raise InvalidNormalFontFaceException(f"The font doesn't contain any valid cmap.")

cmap_platform_id = cmaps[0].platform_id
family_names = FontParser.get_filtered_names(ttFont["name"].names, platformID=cmap_platform_id, nameID=NameID.FAMILY_NAME)

font_type = FontType.from_font(ttFont)
if font_type == FontType.TRUETYPE:
exact_names = FontParser.get_filtered_names(ttFont["name"].names, platformID=cmap_platform_id, nameID=NameID.FULL_NAME)
Expand Down
4 changes: 2 additions & 2 deletions font_collector/font/font_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
self.use_generated_fonts = use_generated_fonts
self.additional_fonts = additional_fonts


def __iter__(self) -> Generator[FontFile, None, None]:
for font in self.fonts:
yield font
Expand Down Expand Up @@ -133,7 +133,7 @@ def get_used_font_by_style(self, style: AssStyle, strategy: FontSelectionStrateg

font_result = FontResult(selected_font_face, mismatch_bold, need_faux_bold, mismatch_italic)
return font_result


def __eq__(self, other: object) -> bool:
if not isinstance(other, FontCollection):
Expand Down
2 changes: 1 addition & 1 deletion font_collector/font/font_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def filename(self) -> Path:
@property
def font_faces(self) -> List[ABCFontFace]:
return self.__font_faces

@property
def is_collection_font(self) -> bool:
return self.__is_collection_font
Expand Down
2 changes: 1 addition & 1 deletion font_collector/font/font_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def load_system_fonts() -> List[FontFile]:
# Remove font that aren't anymore installed
removed_path = cached_paths.difference(fonts_paths)
system_fonts = list(filter(lambda item: item.filename not in removed_path, cached_fonts))

# Update font that have been updated since last execution
has_updated_font = False
for cached_font in system_fonts:
Expand Down
14 changes: 7 additions & 7 deletions font_collector/font/font_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def is_valid_variable_font(font: TTFont) -> bool:

if font["STAT"].table is None:
return False

if font["STAT"].table.DesignAxisRecord is None:
raise InvalidVariableFontFaceException("The font has a stat table, but it doesn't have any DesignAxisRecord")

Expand Down Expand Up @@ -87,7 +87,7 @@ def get_var_font_family_prefix(names: List[NameRecord], platform_id: PlatformID)
A list of Name objects representing variable font family prefix names.
"""
family_prefix = FontParser.get_filtered_names(names, platformID=platform_id, nameID=NameID.TYPOGRAPHIC_FAMILY_NAME)

if not family_prefix:
family_prefix = FontParser.get_filtered_names(names, platformID=platform_id, nameID=NameID.FAMILY_NAME)

Expand Down Expand Up @@ -145,7 +145,7 @@ def get_distance_between_axis_value_and_coordinates(
def get_axis_value_from_coordinates(font: TTFont, coordinates: Dict[str, float]) -> List[Any]:
"""Retrieve AxisValue objects linked to the specified coordinates in the fvar table.
Ensure to call FontParser.is_valid_variable_font() before using this method.
Args:
font: A fontTools object representing the font.
coordinates: The coordinates of a NamedInstance in the fvar table.
Expand Down Expand Up @@ -287,7 +287,7 @@ def get_axis_value_table_property(

family_name: List[Name] = []
fullname: List[Name] = []

# Generate family_name an fullname
for item in product(*axis_values_names):
langs: Set[Language] = set()
Expand All @@ -304,7 +304,7 @@ def get_axis_value_table_property(
# Fallback if all the element have the flag ELIDABLE_AXIS_VALUE_NAME
if hasattr(font['STAT'].table, "ElidedFallbackNameID"):
elided_fallback_name = FontParser.get_filtered_names(font['name'].names, platformID=PlatformID.MICROSOFT, nameID=font['STAT'].table.ElidedFallbackNameID)

if elided_fallback_name:
fullname = elided_fallback_name
else:
Expand Down Expand Up @@ -486,7 +486,7 @@ def get_symbol_cmap_encoding(face: FT_Face) -> Optional[str]:
for code_page, glyph_names in UNIQUE_ADOBE_GLYPH_NAME_BY_CODE_PAGE.items():
count = sum(1 for font_glyph_name in font_glyph_names if font_glyph_name in glyph_names)
count_codepage[code_page] = count

if len(count_codepage) == 0:
return None
# If there is a tie, prefer codepage different then cp1252
Expand Down Expand Up @@ -542,7 +542,7 @@ def get_cmap_encoding(platform_id: int, encoding_id: int) -> Optional[str]:
if platform_id in FontParser.CMAP_ENCODING_MAP:
return FontParser.CMAP_ENCODING_MAP[PlatformID(platform_id)].get(encoding_id, None)
return None


# The Chinese (cp936 or cp950) and Korean (cp949) aren't in this dict since they doesn't have any unique char.
# This dict have been generated with "proof/[Symbol Font] Find unique char by ansi code page.py"
Expand Down
2 changes: 1 addition & 1 deletion font_collector/font/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_name_record_encoding(name: NameRecord) -> Optional[str]:

return None


@staticmethod
def get_decoded_name_record(name: NameRecord) -> str:
"""
Expand Down
8 changes: 4 additions & 4 deletions font_collector/font/normal_font_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ def family_names(self) -> List[Name]:
def exact_names(self) -> List[Name]:
# if the font is a TrueType, it will be the "full_name". if the font is a OpenType, it will be the "postscript name"
return self.__exact_names

@property
def weight(self) -> int:
return self.__weight

@property
def is_italic(self) -> bool:
return self.__is_italic

@property
def is_glyph_emboldened(self) -> bool:
return self.__is_glyph_emboldened

@property
def font_type(self) -> FontType:
return self.__font_type
Expand All @@ -78,7 +78,7 @@ def link_face_to_a_font_file(self, value: FontFile) -> None:
# Since there is a circular reference between FontFile and this class, we need to be able to set the value
self.__font_file = value


def __eq__(self, other: object) -> bool:
if not isinstance(other, NormalFontFace):
return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def is_font_name_match(self, font_face: ABCFontFace, style_font_name: str) -> bo

if not family_name_match:
exact_name_match = any(style_font_name.casefold() == exact_name.value.casefold() for exact_name in font_face.exact_names)

return family_name_match or exact_name_match


Expand All @@ -45,7 +45,7 @@ def get_similarity_score(self, font_face: ABCFontFace, style: AssStyle) -> float
weight_compare += 120

score += (73 * abs(weight_compare - style.weight)) // 256

# This is NOT part of the actual GDI algorith, BUT if we don't prefer Normal font over variable font,
# when a user call VariableFontFace.variable_font_to_collection, the created font will have the same score has
# the variable font AND since the variable font is older than the font collection, it will prefer the variable font
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def __trunc_name(self, name: str) -> bytes:
return trunc_utf16_bytes


def is_font_name_match(self, font_face: ABCFontFace, style_font_name: str) -> bool:
def is_font_name_match(self, font_face: ABCFontFace, style_font_name: str) -> bool:
family_name_match = any(self.__trunc_name(style_font_name.casefold()) == self.__trunc_name(family_name.value.casefold()) for family_name in font_face.family_names)

if not family_name_match:
exact_name_match = any(self.__trunc_name(style_font_name.casefold()) == self.__trunc_name(exact_name.value.casefold()) for exact_name in font_face.exact_names)

return family_name_match or exact_name_match
12 changes: 6 additions & 6 deletions font_collector/font/variable_font_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def family_names(self) -> List[Name]:
lang_code = item[1].lang_code
family_names.append(Name(value, lang_code))
return family_names

@family_names.setter
def family_names(self, value: Any) -> None:
raise AttributeError("You cannot set the family name for an variable font. It is automatically generated by the families_prefix and the families_suffix.")
Expand All @@ -99,23 +99,23 @@ def exact_names(self) -> List[Name]:
@exact_names.setter
def exact_names(self, value: Any) -> None:
raise AttributeError("You cannot set the exact name for an variable font. It is automatically generated by the families_prefix and the exact_names_suffix.")

@property
def weight(self) -> int:
return self.__weight

@property
def is_italic(self) -> bool:
return self.__is_italic

@property
def is_glyph_emboldened(self) -> bool:
return self.weight > 400

@is_glyph_emboldened.setter
def is_glyph_emboldened(self, value: Any) -> None:
raise AttributeError("You cannot set is_glyph_emboldened for an variable font. It is automatically generated by the weight.")

@property
def font_type(self) -> FontType:
return self.__font_type
Expand Down Expand Up @@ -177,7 +177,7 @@ def variable_font_to_collection(self, save_path: Path, cache_generated_font: boo

font_collection = TTCollection()
ttFont = TTFont(self.font_file.filename, fontNumber=self.font_index)

# Only conserve the right font_index
fonts_face: List[VariableFontFace] = [
font for font in self.font_file.font_faces
Expand All @@ -195,7 +195,7 @@ def variable_font_to_collection(self, save_path: Path, cache_generated_font: boo
for cmap in cmaps:
for family_name in font_face.family_names:
generated_font_face["name"].setName(family_name.value, NameID.FAMILY_NAME, cmap.platform_id, cmap.platform_enc_id, family_name.get_lang_id_from_platform_id(cmap.platform_id))

for exact_name in font_face.exact_names:
generated_font_face["name"].setName(exact_name.value, NameID.FULL_NAME, cmap.platform_id, cmap.platform_enc_id, exact_name.get_lang_id_from_platform_id(cmap.platform_id))
generated_font_face["name"].setName(exact_name.value, NameID.POSTSCRIPT_NAME, cmap.platform_id, cmap.platform_enc_id, exact_name.get_lang_id_from_platform_id(cmap.platform_id))
Expand Down
Loading

0 comments on commit 567b0c1

Please sign in to comment.