Skip to content

Commit 611e4b0

Browse files
committed
Intermediate changes
commit_hash:694a59b7c082431d781edd4484f72ab37faca2cd
1 parent e49a9cd commit 611e4b0

File tree

5 files changed

+98
-11
lines changed

5 files changed

+98
-11
lines changed

contrib/python/fonttools/.dist-info/METADATA

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.4
22
Name: fonttools
3-
Version: 4.58.1
3+
Version: 4.58.2
44
Summary: Tools to manipulate font files
55
Home-page: http://github.com/fonttools/fonttools
66
Author: Just van Rossum
@@ -388,6 +388,12 @@ Have fun!
388388
Changelog
389389
~~~~~~~~~
390390

391+
4.58.2 (released 2025-06-06)
392+
----------------------------
393+
394+
- [ttLib.reorderGlyphs] Handle CFF2 when reordering glyphs (#3852)
395+
- [subset] Copy name IDs in use before scrapping or scrambling them for webfonts (#3853)
396+
391397
4.58.1 (released 2025-05-28)
392398
----------------------------
393399

contrib/python/fonttools/fontTools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
log = logging.getLogger(__name__)
55

6-
version = __version__ = "4.58.1"
6+
version = __version__ = "4.58.2"
77

88
__all__ = ["version", "log", "configLogger"]

contrib/python/fonttools/fontTools/subset/__init__.py

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# Google Author(s): Behdad Esfahbod
44

5+
from __future__ import annotations
6+
57
from fontTools import config
68
from fontTools.misc.roundTools import otRound
79
from fontTools import ttLib
@@ -15,7 +17,7 @@
1517
from fontTools.subset.cff import *
1618
from fontTools.subset.svg import *
1719
from fontTools.varLib import varStore, multiVarStore # For monkey-patching
18-
from fontTools.ttLib.tables._n_a_m_e import NameRecordVisitor
20+
from fontTools.ttLib.tables._n_a_m_e import NameRecordVisitor, makeName
1921
from fontTools.unicodedata import mirrored
2022
import sys
2123
import struct
@@ -3004,6 +3006,9 @@ def prune_pre_subset(self, font, options):
30043006
return True
30053007

30063008

3009+
NAME_IDS_TO_OBFUSCATE = {1, 2, 3, 4, 6, 16, 17, 18}
3010+
3011+
30073012
@_add_method(ttLib.getTableClass("name"))
30083013
def prune_post_subset(self, font, options):
30093014
visitor = NameRecordVisitor()
@@ -3022,6 +3027,11 @@ def prune_post_subset(self, font, options):
30223027
self.names = [n for n in self.names if n.langID in options.name_languages]
30233028
if options.obfuscate_names:
30243029
namerecs = []
3030+
# Preserve names to be scrambled or dropped elsewhere so that other
3031+
# parts of the font don't break.
3032+
needRemapping = visitor.seen.intersection(NAME_IDS_TO_OBFUSCATE)
3033+
if needRemapping:
3034+
_remap_select_name_ids(font, needRemapping)
30253035
for n in self.names:
30263036
if n.nameID in [1, 4]:
30273037
n.string = ".\x7f".encode("utf_16_be") if n.isUnicode() else ".\x7f"
@@ -3036,6 +3046,76 @@ def prune_post_subset(self, font, options):
30363046
return True # Required table
30373047

30383048

3049+
def _remap_select_name_ids(font: ttLib.TTFont, needRemapping: set[int]) -> None:
3050+
"""Remap a set of IDs so that the originals can be safely scrambled or
3051+
dropped.
3052+
3053+
For each name record whose name id is in the `needRemapping` set, make a copy
3054+
and allocate a new unused name id in the font-specific range (> 255).
3055+
3056+
Finally update references to these in the `fvar` and `STAT` tables.
3057+
"""
3058+
3059+
if "fvar" not in font and "STAT" not in font:
3060+
return
3061+
3062+
name = font["name"]
3063+
3064+
# 1. Assign new IDs for names to be preserved.
3065+
existingIds = {record.nameID for record in name.names}
3066+
remapping = {}
3067+
nextId = name._findUnusedNameID() - 1 # Should skip gaps in name IDs.
3068+
for nameId in needRemapping:
3069+
nextId += 1 # We should have complete freedom until 32767.
3070+
assert nextId not in existingIds, "_findUnusedNameID did not skip gaps"
3071+
if nextId > 32767:
3072+
raise ValueError("Ran out of name IDs while trying to remap existing ones.")
3073+
remapping[nameId] = nextId
3074+
3075+
# 2. Copy records to use the new ID. We can't rewrite them in place, because
3076+
# that could make IDs 1 to 6 "disappear" from code that follows. Some
3077+
# tools that produce EOT fonts expect them to exist, even when they're
3078+
# scrambled. See https://github.com/fonttools/fonttools/issues/165.
3079+
copiedRecords = []
3080+
for record in name.names:
3081+
if record.nameID not in needRemapping:
3082+
continue
3083+
recordCopy = makeName(
3084+
record.string,
3085+
remapping[record.nameID],
3086+
record.platformID,
3087+
record.platEncID,
3088+
record.langID,
3089+
)
3090+
copiedRecords.append(recordCopy)
3091+
name.names.extend(copiedRecords)
3092+
3093+
# 3. Rewrite the corresponding IDs in other tables. For now, care only about
3094+
# STAT and fvar. If more tables need to be changed, consider adapting
3095+
# NameRecordVisitor to rewrite IDs wherever it finds them.
3096+
fvar = font.get("fvar")
3097+
if fvar is not None:
3098+
for axis in fvar.axes:
3099+
axis.axisNameID = remapping.get(axis.axisNameID, axis.axisNameID)
3100+
for instance in fvar.instances:
3101+
nameID = instance.subfamilyNameID
3102+
instance.subfamilyNameID = remapping.get(nameID, nameID)
3103+
nameID = instance.postscriptNameID
3104+
instance.postscriptNameID = remapping.get(nameID, nameID)
3105+
3106+
stat = font.get("STAT")
3107+
if stat is None:
3108+
return
3109+
elidedNameID = stat.table.ElidedFallbackNameID
3110+
stat.table.ElidedFallbackNameID = remapping.get(elidedNameID, elidedNameID)
3111+
if stat.table.DesignAxisRecord:
3112+
for axis in stat.table.DesignAxisRecord.Axis:
3113+
axis.AxisNameID = remapping.get(axis.AxisNameID, axis.AxisNameID)
3114+
if stat.table.AxisValueArray:
3115+
for value in stat.table.AxisValueArray.AxisValue:
3116+
value.ValueNameID = remapping.get(value.ValueNameID, value.ValueNameID)
3117+
3118+
30393119
@_add_method(ttLib.getTableClass("head"))
30403120
def prune_post_subset(self, font, options):
30413121
# Force re-compiling head table, to update any recalculated values.

contrib/python/fonttools/fontTools/ttLib/reorderGlyphs.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,11 @@ def reorderGlyphs(font: ttLib.TTFont, new_glyph_order: List[str]):
275275
for reorder in _REORDER_RULES.get(reorder_key, []):
276276
reorder.apply(font, value)
277277

278-
if "CFF " in font:
279-
cff_table = font["CFF "]
280-
charstrings = cff_table.cff.topDictIndex[0].CharStrings.charStrings
281-
cff_table.cff.topDictIndex[0].charset = new_glyph_order
282-
cff_table.cff.topDictIndex[0].CharStrings.charStrings = {
283-
k: charstrings.get(k) for k in new_glyph_order
284-
}
278+
for tag in ["CFF ", "CFF2"]:
279+
if tag in font:
280+
cff_table = font[tag]
281+
charstrings = cff_table.cff.topDictIndex[0].CharStrings.charStrings
282+
cff_table.cff.topDictIndex[0].charset = new_glyph_order
283+
cff_table.cff.topDictIndex[0].CharStrings.charStrings = {
284+
k: charstrings.get(k) for k in new_glyph_order
285+
}

contrib/python/fonttools/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
PY3_LIBRARY()
44

5-
VERSION(4.58.1)
5+
VERSION(4.58.2)
66

77
LICENSE(MIT)
88

0 commit comments

Comments
 (0)