Skip to content

Commit

Permalink
Use name_id 16 for Config.for_font_name
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kojiishi committed Aug 27, 2021
1 parent 888529a commit c665977
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion east_asian_spacing/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions east_asian_spacing/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit c665977

Please sign in to comment.