mirror of
https://github.com/rsms/inter.git
synced 2024-09-11 10:55:24 +03:00
adjusted tools for v4 website
This commit is contained in:
parent
5e4c3fa964
commit
c2452dee3a
@ -41,16 +41,18 @@ def localDateTimeToUTCStr(localstr, pattern='%Y/%m/%d %H:%M:%S'):
|
|||||||
return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.localtime(ts))
|
return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.localtime(ts))
|
||||||
|
|
||||||
|
|
||||||
def processGlyph(g, ucd, seenGlyphnames):
|
def include_glyph(g):
|
||||||
name = g.name
|
|
||||||
if name in seenGlyphnames:
|
|
||||||
return None
|
|
||||||
seenGlyphnames.add(name)
|
|
||||||
|
|
||||||
# not exported?
|
|
||||||
if 'com.schriftgestaltung.Glyphs.Export' in g.lib:
|
if 'com.schriftgestaltung.Glyphs.Export' in g.lib:
|
||||||
if not g.lib['com.schriftgestaltung.Glyphs.Export']:
|
if not g.lib['com.schriftgestaltung.Glyphs.Export']:
|
||||||
return None
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
NAME_TO_ID_RE = re.compile(r'([A-Z_])')
|
||||||
|
|
||||||
|
|
||||||
|
def processGlyph(g, ucd):
|
||||||
|
name = g.name
|
||||||
|
|
||||||
# color
|
# color
|
||||||
color = None
|
color = None
|
||||||
@ -62,6 +64,8 @@ def processGlyph(g, ucd, seenGlyphnames):
|
|||||||
if not g.bounds or g.bounds[3] == 0:
|
if not g.bounds or g.bounds[3] == 0:
|
||||||
isEmpty = 1
|
isEmpty = 1
|
||||||
|
|
||||||
|
id = NAME_TO_ID_RE.sub(r'\1_', name).lower()
|
||||||
|
|
||||||
# name, isEmpty, unicode, unicodeName, color
|
# name, isEmpty, unicode, unicodeName, color
|
||||||
glyph = None
|
glyph = None
|
||||||
ucs = g.unicodes
|
ucs = g.unicodes
|
||||||
@ -72,27 +76,30 @@ def processGlyph(g, ucd, seenGlyphnames):
|
|||||||
# ucName = '[private use %04X]' % uc
|
# ucName = '[private use %04X]' % uc
|
||||||
ucstr = '%04X' % uc
|
ucstr = '%04X' % uc
|
||||||
if color:
|
if color:
|
||||||
glyph = [name, isEmpty, ucstr, ucName, color]
|
glyph = [id, name, isEmpty, ucstr, ucName, color]
|
||||||
elif ucName:
|
elif ucName:
|
||||||
glyph = [name, isEmpty, ucstr, ucName]
|
glyph = [id, name, isEmpty, ucstr, ucName]
|
||||||
else:
|
else:
|
||||||
glyph = [name, isEmpty, ucstr]
|
glyph = [id, name, isEmpty, ucstr]
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
if color:
|
if color:
|
||||||
glyph = [name, isEmpty, None, None, color]
|
glyph = [id, name, isEmpty, None, None, color]
|
||||||
else:
|
else:
|
||||||
glyph = [name, isEmpty]
|
glyph = [id, name, isEmpty]
|
||||||
|
|
||||||
return glyph
|
return glyph
|
||||||
|
|
||||||
|
|
||||||
def glyphSortFun(g):
|
def glyphSortFun(g):
|
||||||
if len(g) > 2 and g[2] is not None:
|
if len(g) > 3 and g[3] is not None:
|
||||||
return g[2]
|
return g[3]
|
||||||
elif len(g) > 0:
|
elif len(g) > 0:
|
||||||
return g[0]
|
return g[1]
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argparser = ArgumentParser(
|
argparser = ArgumentParser(
|
||||||
description='Generate info on name, unicodes and color mark for all glyphs')
|
description='Generate info on name, unicodes and color mark for all glyphs')
|
||||||
@ -111,23 +118,23 @@ def main():
|
|||||||
ucd = parseUnicodeDataFile(args.ucdFile)
|
ucd = parseUnicodeDataFile(args.ucdFile)
|
||||||
|
|
||||||
glyphs = [] # contains final glyph data printed as JSON
|
glyphs = [] # contains final glyph data printed as JSON
|
||||||
seenGlyphnames = set()
|
|
||||||
|
|
||||||
for name in font.lib['public.glyphOrder']:
|
|
||||||
g = font[name]
|
|
||||||
glyph = processGlyph(g, ucd, seenGlyphnames)
|
|
||||||
if glyph is not None:
|
|
||||||
glyphs.append(glyph)
|
|
||||||
|
|
||||||
unorderedGlyphs = []
|
unorderedGlyphs = []
|
||||||
|
seenGlyphs = set()
|
||||||
|
for name in font.lib['public.glyphOrder']:
|
||||||
|
if name not in font:
|
||||||
|
print(f'warning: glyph "{name}" (in public.glyphOrder) does not exist',
|
||||||
|
file=sys.stderr)
|
||||||
|
continue
|
||||||
|
g = font[name]
|
||||||
|
seenGlyphs.add(g)
|
||||||
|
if include_glyph(g):
|
||||||
|
glyphs.append(processGlyph(g, ucd))
|
||||||
for g in font:
|
for g in font:
|
||||||
glyph = processGlyph(g, ucd, seenGlyphnames)
|
if include_glyph(g) and g not in seenGlyphs:
|
||||||
if glyph is not None:
|
unorderedGlyphs.append(processGlyph(g, ucd))
|
||||||
unorderedGlyphs.append(glyph)
|
|
||||||
|
|
||||||
if unorderedGlyphs:
|
# append unorderedGlyphs, sorted by unicode
|
||||||
# sort by unicode
|
glyphs = glyphs + sorted(unorderedGlyphs, key=glyphSortFun)
|
||||||
glyphs = glyphs + sorted(unorderedGlyphs, key=glyphSortFun)
|
|
||||||
|
|
||||||
print('{"glyphs":[')
|
print('{"glyphs":[')
|
||||||
prefix = ' '
|
prefix = ' '
|
||||||
|
@ -30,7 +30,6 @@ def num(s):
|
|||||||
return int(s) if s.find('.') == -1 else float(s)
|
return int(s) if s.find('.') == -1 else float(s)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def glyphToSVGPath(g, yMul):
|
def glyphToSVGPath(g, yMul):
|
||||||
pen = SVGPathPen(g.getParent(), yMul)
|
pen = SVGPathPen(g.getParent(), yMul)
|
||||||
g.draw(pen)
|
g.draw(pen)
|
||||||
@ -233,6 +232,11 @@ argparser.add_argument('-scale', dest='scale', metavar='<scale>', type=str,
|
|||||||
argparser.add_argument('ufopath', metavar='<ufopath>', type=str,
|
argparser.add_argument('ufopath', metavar='<ufopath>', type=str,
|
||||||
help='Path to UFO packages')
|
help='Path to UFO packages')
|
||||||
|
|
||||||
|
argparser.add_argument('jsonfile', metavar='<jsonfile>', type=str,
|
||||||
|
help='Output JSON file')
|
||||||
|
argparser.add_argument('htmlfile', metavar='<htmlfile>', type=str,
|
||||||
|
help='Path to HTML file to patch')
|
||||||
|
|
||||||
argparser.add_argument('glyphs', metavar='<glyphname>', type=str, nargs='*',
|
argparser.add_argument('glyphs', metavar='<glyphname>', type=str, nargs='*',
|
||||||
help='Only generate specific glyphs.')
|
help='Only generate specific glyphs.')
|
||||||
|
|
||||||
@ -249,10 +253,6 @@ ufopath = args.ufopath.rstrip('/')
|
|||||||
ufo = Font(ufopath)
|
ufo = Font(ufopath)
|
||||||
effectiveAscender = max(ufo.info.ascender, ufo.info.unitsPerEm)
|
effectiveAscender = max(ufo.info.ascender, ufo.info.unitsPerEm)
|
||||||
|
|
||||||
|
|
||||||
deleteNames.add('.notdef')
|
|
||||||
deleteNames.add('.null')
|
|
||||||
|
|
||||||
glyphnames = args.glyphs if len(args.glyphs) else ufo.keys()
|
glyphnames = args.glyphs if len(args.glyphs) else ufo.keys()
|
||||||
glyphnameSet = set(glyphnames)
|
glyphnameSet = set(glyphnames)
|
||||||
|
|
||||||
@ -296,10 +296,8 @@ for glyphname in glyphnames:
|
|||||||
svgtext = '\n'.join(svgLines)
|
svgtext = '\n'.join(svgLines)
|
||||||
# print(svgtext)
|
# print(svgtext)
|
||||||
|
|
||||||
glyphsHtmlFilename = os.path.join(BASEDIR, 'docs', 'glyphs', 'index.html')
|
|
||||||
|
|
||||||
html = u''
|
html = u''
|
||||||
with open(glyphsHtmlFilename, 'r', encoding="utf-8") as f:
|
with open(args.htmlfile, 'r', encoding="utf-8") as f:
|
||||||
html = f.read()
|
html = f.read()
|
||||||
|
|
||||||
startMarker = u'<div id="svgs">'
|
startMarker = u'<div id="svgs">'
|
||||||
@ -308,7 +306,7 @@ startPos = html.find(startMarker)
|
|||||||
endMarker = u'</div><!--END-SVGS'
|
endMarker = u'</div><!--END-SVGS'
|
||||||
endPos = html.find(endMarker, startPos + len(startMarker))
|
endPos = html.find(endMarker, startPos + len(startMarker))
|
||||||
|
|
||||||
relfilename = os.path.relpath(glyphsHtmlFilename, os.getcwd())
|
relfilename = os.path.relpath(args.htmlfile, os.getcwd())
|
||||||
|
|
||||||
if startPos == -1 or endPos == -1:
|
if startPos == -1 or endPos == -1:
|
||||||
msg = 'Could not find `<div id="svgs">...</div><!--END-SVGS` in %s'
|
msg = 'Could not find `<div id="svgs">...</div><!--END-SVGS` in %s'
|
||||||
@ -325,14 +323,13 @@ metaJson += '}'
|
|||||||
html = html[:startPos + len(startMarker)] + '\n' + svgtext + '\n' + html[endPos:]
|
html = html[:startPos + len(startMarker)] + '\n' + svgtext + '\n' + html[endPos:]
|
||||||
|
|
||||||
print('write', relfilename)
|
print('write', relfilename)
|
||||||
with open(glyphsHtmlFilename, 'w', encoding="utf-8") as f:
|
with open(args.htmlfile, 'w', encoding="utf-8") as f:
|
||||||
f.write(html)
|
f.write(html)
|
||||||
|
|
||||||
# JSON
|
# JSON
|
||||||
jsonFilename = os.path.join(BASEDIR, 'docs', 'glyphs', 'metrics.json')
|
jsonFilenameRel = os.path.relpath(args.jsonfile, os.getcwd())
|
||||||
jsonFilenameRel = os.path.relpath(jsonFilename, os.getcwd())
|
|
||||||
print('write', jsonFilenameRel)
|
print('write', jsonFilenameRel)
|
||||||
with open(jsonFilename, 'w', encoding="utf-8") as f:
|
with open(args.jsonfile, 'w', encoding="utf-8") as f:
|
||||||
f.write(metaJson)
|
f.write(metaJson)
|
||||||
|
|
||||||
metaJson
|
metaJson
|
Loading…
Reference in New Issue
Block a user