From 653455b68e328ed97887bcc44ef087cacee45459 Mon Sep 17 00:00:00 2001 From: Jens Kutilek Date: Wed, 4 Sep 2024 15:22:13 +0200 Subject: [PATCH] Handle rounding of component transforms when calculating glyph hashes --- Lib/extractor/formats/opentype.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/extractor/formats/opentype.py b/Lib/extractor/formats/opentype.py index 8b9845d..6abbe7b 100644 --- a/Lib/extractor/formats/opentype.py +++ b/Lib/extractor/formats/opentype.py @@ -1,6 +1,8 @@ import time +from fontTools.misc.fixedTools import floatToFixedToFloat from fontTools.pens.boundsPen import ControlBoundsPen from fontTools.pens.hashPointPen import HashPointPen +from fontTools.pens.roundingPen import RoundingPointPen from fontTools.ttLib import TTFont, TTLibError from fontTools.ttLib.tables._g_l_y_f import ( OVERLAP_COMPOUND, @@ -8,6 +10,7 @@ USE_MY_METRICS, ) from fontTools.ttLib.tables._h_e_a_d import mac_epoch_diff +from functools import partial from extractor.exceptions import ExtractorError from extractor.stream import InstructionStream from extractor.tools import RelaxedInfo, copyAttr @@ -157,7 +160,11 @@ def extractGlyphPrograms(source, destination): continue hash_pen = HashPointPen(dest_glyph.width, destination) - dest_glyph.drawPoints(hash_pen) + round_pen = RoundingPointPen( + hash_pen, + transformRoundFunc=partial(floatToFixedToFloat, precisionBits=14) + ) + dest_glyph.drawPoints(round_pen) lib = dest_glyph.lib[TRUETYPE_INSTRUCTIONS_KEY] = { "formatVersion": "1", "id": hash_pen.hash,