diff options
author | James Godfrey-Kittle <jamesgk@google.com> | 2015-05-11 09:26:40 -0700 |
---|---|---|
committer | James Godfrey-Kittle <jamesgk19@gmail.com> | 2015-05-11 09:26:40 -0700 |
commit | 51a104941b097a959c5d806d567115d99051fcc1 (patch) | |
tree | 9250adb3ddaf15a0bfff3d3fad0bfb4d5a1ff74f /scripts | |
parent | d2ac8019271ecd84b6a4ee36056d59ff2f3fcb18 (diff) | |
parent | 05d020abc4a8d5c11b449f738b95c4190998d111 (diff) |
Merge pull request #34 from google/anchor-fix
Fix bug causing inaccurate anchor coordinates.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/fontbuild/anchors.py | 6 | ||||
-rw-r--r-- | scripts/lib/fontbuild/generateGlyph.py | 18 | ||||
-rw-r--r-- | scripts/lib/fontbuild/mix.py | 15 |
3 files changed, 18 insertions, 21 deletions
diff --git a/scripts/lib/fontbuild/anchors.py b/scripts/lib/fontbuild/anchors.py index 9b8095d..622d52a 100644 --- a/scripts/lib/fontbuild/anchors.py +++ b/scripts/lib/fontbuild/anchors.py @@ -39,9 +39,9 @@ def moveMarkAnchors(f, g, anchorName, accentName, dx, dy): anchors = f[accentName].anchors for anchor in anchors: if "mkmkbottom_acc" == anchor.name: - for anchor in g.anchors: - if anchor.name == "bottom": - g.removeAnchor(anchor) + for anc in g.anchors: + if anc.name == "bottom": + g.removeAnchor(anc) break x = anchor.x + int(dx) for anc in anchors: diff --git a/scripts/lib/fontbuild/generateGlyph.py b/scripts/lib/fontbuild/generateGlyph.py index ccfeef1..c674c38 100644 --- a/scripts/lib/fontbuild/generateGlyph.py +++ b/scripts/lib/fontbuild/generateGlyph.py @@ -13,6 +13,7 @@ # limitations under the License. +import re from anchors import alignComponentsToAnchors @@ -65,6 +66,7 @@ def generateGlyph(f,gname,glyphList={}): for componentName in baseName.split("_"): g.appendComponent(componentName, (g.width, 0)) g.width += f[componentName].width + setUnicodeValue(g, glyphList) else: if not f.has_key(glyphName): @@ -75,16 +77,24 @@ def generateGlyph(f,gname,glyphList={}): "anchor not found in glyph '%s'" % (gname, e, baseName)) return g = f[glyphName] + setUnicodeValue(g, glyphList) copyMarkAnchors(f, g, baseName, offset[1] + offset[0]) if offset[0] != 0 or offset[1] != 0: g.width += offset[1] + offset[0] - g.move((offset[0], 0)) + g.move((offset[0], 0), anchors=False) if len(accentNames) > 0: alignComponentsToAnchors(f, glyphName, baseName, accentNames) else: print ("Existing glyph '%s' found in font, ignoring composition " "rule '%s'" % (glyphName, gname)) - # try to ensure every glyph has a unicode value -- used by FDK to make OTFs - if glyphName in glyphList: - f[glyphName].unicode = int(glyphList[glyphName], 16) + +def setUnicodeValue(glyph, glyphList): + """Try to ensure glyph has a unicode value -- used by FDK to make OTFs.""" + + if glyph.name in glyphList: + glyph.unicode = int(glyphList[glyph.name], 16) + else: + uvNameMatch = re.match("uni([\dA-F]{4})$", glyph.name) + if uvNameMatch: + glyph.unicode = int(uvNameMatch.group(1), 16) diff --git a/scripts/lib/fontbuild/mix.py b/scripts/lib/fontbuild/mix.py index bd396ed..7123213 100644 --- a/scripts/lib/fontbuild/mix.py +++ b/scripts/lib/fontbuild/mix.py @@ -260,20 +260,7 @@ class Master: if anchorPath: anchorData = json.load(open(anchorPath)) for glyphName, anchors in anchorData.items(): - - # another bug: some entire glyphs are dropped during conversion. - # example: gbar_uni1ABE - try: - glyph = self.font[glyphName] - except KeyError: - continue - - # another bug: some glyphs are decomposed during conversion, in - # which case they unexpectedly don't drop anchors. - # examples: uni04BA, Gbar (partially decomposed) - if glyph.anchors: - continue - + glyph = self.font[glyphName] for name, (x, y) in anchors.items(): glyph.appendAnchor(str(name), (x, y)) |