Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #172 from adobe-type-tools/hash-dflt-layer
Browse files Browse the repository at this point in the history
Hashing with --write-default-layer option
  • Loading branch information
khaledhosny authored Jun 3, 2019
2 parents 9fa41cf + 9ca5a58 commit cc99949
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
33 changes: 25 additions & 8 deletions python/psautohint/ufoFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,17 +429,18 @@ def save(self, path):

writer = UFOWriter(path, self._reader.formatVersion, validate=False)

if self.hashMapChanged:
self.writeHashMap(writer)
self.hashMapChanged = False

layer = PROCESSED_LAYER_NAME
if self.writeToDefaultLayer:
layer = None

# Write layer contents.
layers = writer.layerContents.copy()
if self.processedLayerGlyphMap or not self.writeToDefaultLayer:
if self.writeToDefaultLayer and PROCESSED_LAYER_NAME in layers:
# Delete processed glyphs directory
writer.deleteGlyphSet(PROCESSED_LAYER_NAME)
# Remove entry from 'layercontents.plist' file
del layers[PROCESSED_LAYER_NAME]
elif self.processedLayerGlyphMap or not self.writeToDefaultLayer:
layers[PROCESSED_LAYER_NAME] = PROCESSED_GLYPHS_DIRNAME
writer.layerContents.update(layers)
writer.writeLayerContents()
Expand All @@ -451,10 +452,17 @@ def save(self, path):
if not self.writeToDefaultLayer and \
name in self.processedLayerGlyphMap:
filename = self.processedLayerGlyphMap[name]
# Recalculate glyph hashes
if self.writeToDefaultLayer:
self.recalcHashEntry(name, glyph)
glyphset.contents[name] = filename
glyphset.writeGlyph(name, glyph, glyph.drawPoints)
glyphset.writeContents()

# Write hashmap
if self.hashMapChanged:
self.writeHashMap(writer)

@property
def hashMap(self):
if self._hashmap is None:
Expand Down Expand Up @@ -486,10 +494,8 @@ def writeHashMap(self, writer):
if not hashMap:
return # no glyphs were processed.

hasMapKeys = hashMap.keys()
hasMapKeys = sorted(hasMapKeys)
data = ["{"]
for gName in hasMapKeys:
for gName in sorted(hashMap.keys()):
data.append("'%s': %s," % (gName, hashMap[gName]))
data.append("}")
data.append("")
Expand All @@ -508,6 +514,17 @@ def updateHashEntry(self, glyphName):
if AUTOHINT_NAME not in historyList:
historyList.append(AUTOHINT_NAME)

def recalcHashEntry(self, glyphName, glyph):
hashBefore, historyList = self.hashMap[glyphName]

hash_pen = HashPointPen(glyph)
glyph.drawPoints(hash_pen)
hashAfter = hash_pen.getHash()

if hashAfter != hashBefore:
self.hashMap[glyphName] = [tostr(hashAfter), historyList]
self.hashMapChanged = True

def checkSkipGlyph(self, glyphName, newSrcHash, doAll):
skip = False
if self.log_only:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/data
Submodule data updated 27 files
+0 −4 dummy/defaultlayer.ufo/layercontents.plist
+39 −0 dummy/hashmap_dflt_layer.ufo/fontinfo.plist
+12 −0 dummy/hashmap_dflt_layer.ufo/glyphs/a.glif
+7 −0 dummy/hashmap_dflt_layer.ufo/glyphs/after.glif
+7 −0 dummy/hashmap_dflt_layer.ufo/glyphs/before.glif
+12 −0 dummy/hashmap_dflt_layer.ufo/glyphs/contents.plist
+10 −0 dummy/hashmap_dflt_layer.ufo/layercontents.plist
+12 −0 dummy/hashmap_dflt_layer.ufo/lib.plist
+10 −0 dummy/hashmap_dflt_layer.ufo/metainfo.plist
+6 −0 dummy/hashmap_dflt_layer_hinted.ufo/data/com.adobe.type.processedHashMap
+39 −0 dummy/hashmap_dflt_layer_hinted.ufo/fontinfo.plist
+33 −0 dummy/hashmap_dflt_layer_hinted.ufo/glyphs/a.glif
+33 −0 dummy/hashmap_dflt_layer_hinted.ufo/glyphs/after.glif
+33 −0 dummy/hashmap_dflt_layer_hinted.ufo/glyphs/before.glif
+12 −0 dummy/hashmap_dflt_layer_hinted.ufo/glyphs/contents.plist
+10 −0 dummy/hashmap_dflt_layer_hinted.ufo/layercontents.plist
+12 −0 dummy/hashmap_dflt_layer_hinted.ufo/lib.plist
+10 −0 dummy/hashmap_dflt_layer_hinted.ufo/metainfo.plist
+6 −0 dummy/hashmap_dflt_layer_rehinted.ufo/data/com.adobe.type.processedHashMap
+39 −0 dummy/hashmap_dflt_layer_rehinted.ufo/fontinfo.plist
+33 −0 dummy/hashmap_dflt_layer_rehinted.ufo/glyphs/a.glif
+33 −0 dummy/hashmap_dflt_layer_rehinted.ufo/glyphs/after.glif
+33 −0 dummy/hashmap_dflt_layer_rehinted.ufo/glyphs/before.glif
+12 −0 dummy/hashmap_dflt_layer_rehinted.ufo/glyphs/contents.plist
+10 −0 dummy/hashmap_dflt_layer_rehinted.ufo/layercontents.plist
+12 −0 dummy/hashmap_dflt_layer_rehinted.ufo/lib.plist
+10 −0 dummy/hashmap_dflt_layer_rehinted.ufo/metainfo.plist
26 changes: 26 additions & 0 deletions tests/integration/test_hint.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,32 @@ def test_hashmap_advance(tmpdir):
assert differ([path, out])


def test_hashmap_dflt_layer(tmpdir):
path = "%s/dummy/hashmap_dflt_layer.ufo" % DATA_DIR
rslt = "%s/dummy/hashmap_dflt_layer_hinted.ufo" % DATA_DIR
out = str(tmpdir / basename(path)) + ".out"
options = Options(path, out)
options.writeToDefaultLayer = True

hintFiles(options)

assert differ([rslt, out])


def test_hashmap_dflt_layer_rehint(tmpdir):
path = "%s/dummy/hashmap_dflt_layer.ufo" % DATA_DIR
rslt = "%s/dummy/hashmap_dflt_layer_rehinted.ufo" % DATA_DIR
out = str(tmpdir / basename(path)) + ".out"
options = Options(path, out)
options.writeToDefaultLayer = False
hintFiles(options)
options2 = Options(out, out)
options2.writeToDefaultLayer = True
hintFiles(options2)

assert differ([rslt, out])


def test_hashmap_transform(tmpdir):
path = "%s/dummy/hashmap_transform.ufo" % DATA_DIR
out = str(tmpdir / basename(path)) + ".out"
Expand Down

0 comments on commit cc99949

Please sign in to comment.