Skip to content

Commit

Permalink
Extract Vmetfix to separate class of Fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyvolkov committed Dec 23, 2014
1 parent 1d029af commit 9ea53c3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
7 changes: 3 additions & 4 deletions bakery_cli/pipe/autofix.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
import os.path as op

from fontTools.ttLib import TTFont
from bakery_cli.scripts.vmet import metricview, metricfix
from bakery_cli.scripts.vmet import metricview
from bakery_cli.scripts import SpecCharsForASCIIFixer, CreateDSIGFixer, \
ResetFSTypeFlagFixer, AddSPUAByGlyphIDToCmap, NbspAndSpaceSameWidth, \
GaspFixer
GaspFixer, Vmet
from bakery_cli.scripts import opentype
from bakery_cli.scripts import gasp
from bakery_cli.utils import shutil
from bakery_cli.utils import UpstreamDirectory

Expand Down Expand Up @@ -158,7 +157,7 @@ def fix_metrics(testcase):
if hasattr(testcase, 'operator'):
testcase.operator.debug(command)

metricfix(paths)
Vmet.fix(paths)

for path in paths:
try:
Expand Down
28 changes: 28 additions & 0 deletions bakery_cli/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,31 @@ def show(self):
print(self.font['gasp'].gaspRange[65535])
except IndexError:
print('no index 65535', file=sys.stderr)


class Vmet(object):

@staticmethod
def fix(fonts):
from bakery_cli.ttfont import Font
ymin = 0
ymax = 0

for f in fonts:
metrics = Font(f)
font_ymin, font_ymax = metrics.get_bounding()
ymin = min(font_ymin, ymin)
ymax = max(font_ymax, ymax)

for f in fonts:
VmetFixer(f).apply()


class VmetFixer(Fixer):

def fix(self, ymin, ymax):
from bakery_cli.ttfont import AscentGroup, DescentGroup, LineGapGroup
AscentGroup(self.font).set(ymax)
DescentGroup(self.font).set(ymin)
LineGapGroup(self.font).set(0)
return True
2 changes: 1 addition & 1 deletion bakery_cli/scripts/stem_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def distribute_equal(min_val, max_val, n):
def distribute_pablo(min_val, max_val, n):
es = distribute_equal(min_val, max_val, n)
ls = distribute_lucas(min_val, max_val, n)
return [l*(1-i/(n-1)) + e*(i/(n-1)) for (i, e, l) in zip(range(n), es, ls)]
return [l*(1-i/(n-1)) + e*(i/(n-1)) for (i, e, l) in zip(range(n), es, ls)]
19 changes: 0 additions & 19 deletions bakery_cli/scripts/vmet.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,6 @@ def get_metric_view(fonts):
return view


def metricfix(fonts):
from bakery_cli.ttfont import Font
ymin = 0
ymax = 0

for f in fonts:
metrics = Font(f)
font_ymin, font_ymax = metrics.get_bounding()
ymin = min(font_ymin, ymin)
ymax = max(font_ymax, ymax)

for f in fonts:
metrics = Font(f)
metrics.ascents.set(ymax)
metrics.descents.set(ymin)
metrics.linegaps.set(0)
metrics.save(f + '.fix')


class TextMetricsView(object):

def __init__(self):
Expand Down
4 changes: 2 additions & 2 deletions tools/fontbakery-fix-vertical-metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from fontTools.ttLib import TTLibError

from bakery_cli.ttfont import Font
from bakery_cli.scripts import vmet
from bakery_cli.scripts import vmet, Vmet


parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -112,6 +112,6 @@
metrics.save(f + '.fix')

elif options.autofix:
vmet.metricfix(fonts)
Vmet.fix(fonts)
else:
print(vmet.metricview(fonts))

0 comments on commit 9ea53c3

Please sign in to comment.