From c665977a4d30be89a3cf4b8a186abea66446d39a Mon Sep 17 00:00:00 2001 From: Koji Ishii Date: Sat, 28 Aug 2021 04:36:13 +0900 Subject: [PATCH] Use name_id 16 for `Config.for_font_name` The name ID 1 may contain style variations. The spec[1] recommends using name IDs 16 and 17. [1] https://docs.microsoft.com/en-us/typography/opentype/spec/name#name-ids --- east_asian_spacing/config.py | 5 ++++- east_asian_spacing/font.py | 9 ++++++--- pyproject.toml | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/east_asian_spacing/config.py b/east_asian_spacing/config.py index cc6c1d5..de61de0 100644 --- a/east_asian_spacing/config.py +++ b/east_asian_spacing/config.py @@ -66,7 +66,10 @@ def clone_if_is(self, other): def for_font(self, font): """Returns a tweaked copy if the `font` needs special treatments. Otherwise returns `self`.""" - name = font.debug_name(1) + # Prefer Typographic Family name (16) if the font has it. + # Otherwise fallback to Font Family name (1). + # https://docs.microsoft.com/en-us/typography/opentype/spec/name#name-ids + name = font.debug_name(16, 1) if name: return self.for_font_name(name, font.is_vertical) return self diff --git a/east_asian_spacing/font.py b/east_asian_spacing/font.py index 382c9d9..8e86680 100755 --- a/east_asian_spacing/font.py +++ b/east_asian_spacing/font.py @@ -3,7 +3,7 @@ import itertools import logging import pathlib -from typing import Any +from typing import Any, Iterable, Optional from typing import Generator from fontTools.ttLib import newTable @@ -240,12 +240,15 @@ def hbfont(self): self._hbfont = hb.Font(hbface) return self._hbfont - def debug_name(self, name_id): + def debug_name(self, *name_ids: int) -> Optional[str]: # name_id: # https://docs.microsoft.com/en-us/typography/opentype/spec/name#name-id-examples if self.ttfont: name = self.tttable("name") - return name.getDebugName(name_id) + for name_id in name_ids: + result = name.getDebugName(name_id) + if result: + return result return None def __str__(self): diff --git a/pyproject.toml b/pyproject.toml index 8cd0100..4846204 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "east_asian_spacing" -version = "1.3.3" +version = "1.3.4" description = "East Asian Contextual Spacing Build Tools" authors = ["Koji Ishii "] readme = "README.md"