Add skew and italic metrics for ttfs

Summary:
Add the ability to base the metrics for a TTF character on the metrics
from one of the TFM characters.

Test Plan:
 - Make sure the tests still work
 - Make sure huxley tests didn't change

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D13217
This commit is contained in:
Emily Eisenberg 2014-09-16 17:40:20 -07:00
parent e6b3cbe7c1
commit b7e55607cc
2 changed files with 38 additions and 24 deletions

View File

@ -4,25 +4,32 @@ import fontforge
import sys
import json
# map of characters to extract
metrics_to_extract = {
"Main-Regular": [
u"\u2260", # \neq
u"\u2245", # \cong
u"\u0020", # space
u"\u00a0", # nbsp
u"\u2026", # \ldots
u"\u22ef", # \cdots
u"\u22f1", # \ddots
u"\u22ee", # \vdots
],
"Size1-Regular": [
u"\u222c", # \iint
u"\u222d", # \iiint
],
"Size2-Regular": [
u"\u222c", # \iint
u"\u222d", # \iiint
]
# Font name
"Main-Regular": {
# Skew and italic metrics can't be easily parsed from the TTF. Instead,
# we map each character to a "base character", which is a character
# from the same font with correct italic and skew metrics. A character
# maps to None if it doesn't have a base.
u"\u2260": None, # \neq
u"\u2245": None, # \cong
u"\u0020": None, # space
u"\u00a0": None, # nbsp
u"\u2026": None, # \ldots
u"\u22ef": None, # \cdots
u"\u22f1": None, # \ddots
u"\u22ee": None, # \vdots
},
"Size1-Regular": {
u"\u222c": u"\u222b", # \iint, based on \int
u"\u222d": u"\u222b", # \iiint, based on \int
},
"Size2-Regular": {
u"\u222c": u"\u222b", # \iint, based on \int
u"\u222d": u"\u222b", # \iiint, based on \int
},
}
@ -43,15 +50,22 @@ def main():
depth = -depth
# TODO(emily): Figure out a real way to calculate this
italic = 0
skew = 0
base_char = chars[char]
if base_char:
base_char_str = str(ord(base_char))
base_metrics = start_json[font][base_char_str]
italic = base_metrics["italic"]
skew = base_metrics["skew"]
else:
italic = 0
skew = 0
start_json[font][ord(char)] = {
"height": height / fontInfo.em,
"depth": depth / fontInfo.em,
"italic": italic / fontInfo.em,
"skew": skew / fontInfo.em,
"italic": italic,
"skew": skew,
}
sys.stdout.write(

File diff suppressed because one or more lines are too long