From dd4b6563cb396b47333fd7bf1d8934d67f6d6474 Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Wed, 22 Apr 2015 15:09:49 -0700 Subject: Add anchor extraction script and README note. --- src/v2/README.md | 6 +++++ src/v2/get_dropped_anchors.py | 61 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/v2/get_dropped_anchors.py diff --git a/src/v2/README.md b/src/v2/README.md index 62cc8d5..b2362d6 100644 --- a/src/v2/README.md +++ b/src/v2/README.md @@ -17,3 +17,9 @@ wine [path-to-vfb2ufo]/exe/vfb2ufo.exe [roboto]/src/v2/Roboto_Bold.vfb The converter should work both ways, so it is possible to convert altered UFOs back into VFBs which can be opened in FontLab. + +**Note:** There is currently an issue when converting via vfb2ufo, in which +some anchors are dropped from glyphs. For now it is also necessary to run the +script `get_dropped_anchors.py` through FontLab after updating the VFBs, in +order to extract these dropped anchors into an external resource which is then +re-incorporated into the masters during the build. diff --git a/src/v2/get_dropped_anchors.py b/src/v2/get_dropped_anchors.py new file mode 100644 index 0000000..4d4a19c --- /dev/null +++ b/src/v2/get_dropped_anchors.py @@ -0,0 +1,61 @@ +# Copyright 2015 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from FL import * + +import json +import os + + +def main(): + """Extract anchors which will be dropped during conversion via vfb2ufo. + + Specifically, these are the anchors belonging to glyphs containing + components but no contours. This script exports them to json files. + """ + + path = "" # CHANGE THIS TO LOCAL ROBOTO PATH + if not path: + print "Please change the 'path' variable to your local roboto location" + return + + # list of input fonts (master VFBs) with their respective weights + fonts = ( + (os.path.join(path, "src", "v2", "Roboto_Thin.vfb"), "thin"), + (os.path.join(path, "src", "v2", "Roboto_Regular.vfb"), "regular"), + (os.path.join(path, "src", "v2", "Roboto_Bold.vfb"), "bold")) + + # extract the anchors which will be dropped + for fontpath, weight in fonts: + fontData = {} + font = Font(fontpath) + for i in range(len(font)): + glyph = font[i] + if glyph.anchors and glyph.components and not glyph.nodes: + glyphData = {} + for anchor in glyph.anchors: + glyphData[anchor.name] = [anchor.x, anchor.y] + fontData[glyph.name] = glyphData + + # write the data as json + outpath = os.path.join(path, "res", "anchors_%s.json" % weight) + with open(outpath, "w") as outfile: + json.dump(fontData, outfile, sort_keys=True, indent=4, + separators=(',', ': ')) + print "Wrote " + outpath + print "Done" + + +main() -- cgit v1.2.3