Skip to content

Commit

Permalink
Support new codepage ranges syntax #530
Browse files Browse the repository at this point in the history
  • Loading branch information
black7375 committed Jan 28, 2025
1 parent b0fc3bc commit 1e16762
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
1 change: 0 additions & 1 deletion Lib/glyphsLib/builder/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@
"IRI": 0x083C,
"ISL": 0x040F,
"ITA": 0x0410,
"ITA": 0x0410,
"IWR": 0x040D,
"JPN": 0x0411,
"KAN": 0x044B,
Expand Down
30 changes: 29 additions & 1 deletion Lib/glyphsLib/builder/custom_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def to_ufo(self, builder, glyphs, ufo):
if codepages is None:
return

ufo_codepage_bits = [CODEPAGE_RANGES[v] for v in codepages]
ufo_codepage_bits = self._convert_to_bits(codepages)
unsupported_codepage_bits = glyphs.get_custom_value(
"codePageRangesUnsupportedBits"
)
Expand All @@ -501,6 +501,34 @@ def to_ufo(self, builder, glyphs, ufo):

ufo.set_info_value("openTypeOS2CodePageRanges", sorted(ufo_codepage_bits))

@staticmethod
def _convert_to_bits(codepages):
ufo_codepage_bits = []
for codepage in codepages:
if isinstance(codepage, int):
ufo_codepage_bits.append(CODEPAGE_RANGES[codepage])

elif isinstance(codepage, str):
if codepage.isdigit():
ufo_codepage_bits.append(CODEPAGE_RANGES[int(codepage)])
elif codepage.startswith("bit "):
try:
ufo_codepage_bits.append(int(codepage[4:]))
except ValueError as err:
raise ValueError(
f"'{codepage}' is not in correct format. "
"A number must follow after 'bit '."
) from err
else:
raise ValueError(
f"'{codepage}'is neither a number nor 'bit ' format."
)

else:
raise TypeError(f"Unsupported type: {type(codepage)}")

return ufo_codepage_bits


register(OS2CodePageRangesParamHandler())

Expand Down
2 changes: 1 addition & 1 deletion Lib/glyphsLib/builder/glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _clone_layer(layer, paths=None, components=None):
# And this forum post:
# https://forum.glyphsapp.com/t/unicode-variation-selector-u-fe01/21701
USV_MAP = {
f".uv{i+1:03}": f"{c:04X}"
f".uv{i + 1:03}": f"{c:04X}"
for i, c in enumerate(
itertools.chain(range(0xFE00, 0xFE0F + 1), range(0xE0100, 0xE01EF + 1))
)
Expand Down
2 changes: 0 additions & 2 deletions Lib/glyphsLib/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,14 +1357,12 @@ def _serialize_to_plist(self, writer):
_CUSTOM_INTLIST_PARAMS = frozenset(
(
"fsType",
"openTypeOS2CodePageRanges",
"openTypeOS2FamilyClass",
"openTypeOS2Panose",
"openTypeOS2Type",
"openTypeOS2UnicodeRanges",
"panose",
"unicodeRanges",
"codePageRanges",
"openTypeHeadFlags",
)
)
Expand Down

0 comments on commit 1e16762

Please sign in to comment.