[go: up one dir, main page]

Skip to content
This repository has been archived by the owner on Aug 23, 2021. It is now read-only.

Commit

Permalink
Port this script to Python 3
Browse files Browse the repository at this point in the history
My Python 2 unicodedata module does not properly support some higher
blocks, so I ported to Python 3 and FontTools in the process.
  • Loading branch information
khaledhosny committed Jan 20, 2014
1 parent 07fd06f commit 8ecb540
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ DOCSRC=$(DOC)/$(DOC)-$(SRC)
DIST=$(NAME)-$(VERSION)

PY=python
PY3=python3
BUILD=$(TOOLS)/build.py
POSTPROCESS=$(TOOLS)/postprocess.py
COVERAGE=$(TOOLS)/fontcoverage.py
Expand Down Expand Up @@ -49,9 +50,9 @@ $(DOC)/%.pdf: $(DOCSRC)/%.tex
@echo "Building $@"
@context --nonstopmode --result=$@ $< 1>/dev/null

FONTLOG.txt: FONTLOG.txt.in $(COVERAGE)
FONTLOG.txt: FONTLOG.txt.in $(COVERAGE) $(OTF)
@echo "Generating $@"
@$(PY) $(COVERAGE) tools/Blocks.txt $< $(SFD) > $@
@$(PY3) $(COVERAGE) tools/Blocks.txt $< $(OTF) $@

dist: $(OTF) $(PDF) FONTLOG.txt
@echo "Making dist tarball"
Expand Down
28 changes: 14 additions & 14 deletions tools/fontcoverage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python
from __future__ import division
import sys
import fontforge
import unicodedata
from fontTools.ttLib import TTFont

# Unicode blocks file from: http://www.unicode.org/Public/UNIDATA/Blocks.txt

Expand All @@ -19,9 +17,11 @@
log = logfile.read()
logfile.close()

for fontfile in sys.argv[3:]:
font = fontforge.open(fontfile)
font.encoding = "UnicodeFull"
for fontfile in sys.argv[3:-1]:
font = TTFont(fontfile)
cmap = font['cmap'].getcmap(3, 10)
if cmap is None:
cmap = font['cmap'].getcmap(3, 1)
found = [ ]

for block in blocks:
Expand All @@ -30,20 +30,18 @@
start, end = int(block[1][0], 16), int(block[1][1], 16)
i = start
while (i <= end):
category = unicodedata.category(unichr(i))
category = unicodedata.category(chr(i))
if category != "Cc" and category!= "Cn":
try:
glyph = font[i]
if i in cmap.cmap:
f += 1
except TypeError:
pass
t += 1
i += 1
if f:
found.append((name, (t,f)))

fullname = str(font['name'].getName(4, 1, 0).string, encoding='ascii')
coverage = ""
coverage += "* %s:\n" %font.fullname
coverage += "* %s:\n" %fullname
for f in found:
for b in blocks:
if b[0] == f[0]:
Expand All @@ -53,6 +51,8 @@
percent = present/total*100
coverage += " %s (U+%s-%s): %s/%s (%.2f%%)\n" %(name, start, end, present, total, percent)

log = log.replace("%%{%s}" %font.fullname, coverage)
log = log.replace("%%{%s}" %fullname, coverage)

print log
outfile = open(sys.argv[-1], "w")
outfile.write(log)
outfile.close()

0 comments on commit 8ecb540

Please sign in to comment.