-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand the glyph name list and remove duplicates
Fixes #88
- Loading branch information
Showing
2 changed files
with
66 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,41 @@ | ||
f = open("glyphlist-extended.txt") | ||
lines = f.readlines() | ||
import re | ||
glyphlist = [] | ||
for l in lines: | ||
if l[0] == '#' or l[0] == '\n': | ||
continue | ||
name, code = re.split('[; ]+', l)[0:2] | ||
glyphlist.append((name,int(code,16))) | ||
glyphs_seen = {} | ||
def read_glyphs(name): | ||
f = open(name) | ||
lines = f.readlines() | ||
import re | ||
for l in lines: | ||
if l[0] == '#' or l[0] == '\n': | ||
continue | ||
split = re.split('[; ,]+', l) | ||
name = split[0] | ||
val = int(split[1], 16) | ||
if val > 0xffff: | ||
val = int(split[-1], 16) | ||
if val == 0xf766 and name != "Fsmall": | ||
continue | ||
if name in glyphs_seen: | ||
continue | ||
glyphs_seen[name] = True | ||
glyphlist.append((name,val)) | ||
read_glyphs("glyphlist-extended.txt") | ||
read_glyphs("texglyphlist.txt") | ||
read_glyphs("additional.txt") | ||
# there are some conflicts between these files | ||
# e.g. tildewide=0x02dc, vs tildewide=0x0303 | ||
# for now we just ignore the subsequent ones | ||
glyphlist.append(('mapsto', 0x21A6)) | ||
glyphlist = list(set(glyphlist)) | ||
glyphlist.sort() | ||
print "/* Autogenerated from https://github.com/michal-h21/htfgen/commits/master/glyphlist-extended.txt */" | ||
print "/* Autogenerated from:" | ||
print " https://github.com/michal-h21/htfgen/commits/master/glyphlist-extended.txt" | ||
print " https://github.com/2ion/lcdf-typetools/blob/master/texglyphlist.txt" | ||
print " https://github.com/apache/pdfbox/blob/trunk/pdfbox/src/main/resources/org/apache/pdfbox/resources/glyphlist/additional.txt" | ||
print " */" | ||
print "pub fn name_to_unicode(name: &str) -> Option<u16> {" | ||
print " let names = [" | ||
print ",\n".join('(\"%s\", 0x%04x)' % (g[0], g[1]) for g in glyphlist) | ||
print " ];" | ||
print " let result = names.binary_search_by_key(&name, |&(name,code)| &name);" | ||
print " let result = names.binary_search_by_key(&name, |&(name,_code)| &name);" | ||
print " result.ok().map(|indx| names[indx].1)" | ||
print "}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters