|
5 | 5 |
|
6 | 6 | from fontTools.cu2qu.ufo import fonts_to_quadratic |
7 | 7 | from fontTools import varLib |
| 8 | +from fontTools.varLib.stat import buildVFStatTable |
8 | 9 | from fontTools.ttLib import TTFont |
9 | 10 |
|
10 | 11 | from fontPens.transformPointPen import TransformPointPen |
|
20 | 21 |
|
21 | 22 | class GenerateVariableFont: |
22 | 23 |
|
23 | | - def __init__(self, operator, destinationPath, autohint=False, fitToExtremes=False, releaseMode=True, glyphOrder=None, report=None, debug=False): |
| 24 | + def __init__(self, operator, destinationPath, designspace=None, discreteAxisName=None, autohint=False, fitToExtremes=False, releaseMode=True, glyphOrder=None, report=None, debug=False): |
24 | 25 | # this must be an operator with no discrete axes. |
25 | 26 | # split the designspace first first |
26 | 27 | if report is None: |
27 | 28 | report = Report() |
28 | 29 | self.operator = operator |
29 | 30 | self.destinationPath = destinationPath |
| 31 | + self.designspace = designspace |
| 32 | + self.discreteAxisName = discreteAxisName |
30 | 33 | self.binaryFormat = os.path.splitext(self.destinationPath)[-1][1:].lower() |
31 | 34 | self.autohint = autohint |
32 | 35 | self.fitToExtremes = fitToExtremes |
@@ -369,7 +372,7 @@ def makeLayerSource(self): |
369 | 372 | self.operator.fonts[sourceDescriptor.name] = layeredSource |
370 | 373 | self.generatedFiles.add(sourceDescriptor.path) |
371 | 374 |
|
372 | | - def generate(self): |
| 375 | + def generate(self, ): |
373 | 376 | dirname = os.path.dirname(self.destinationPath) |
374 | 377 |
|
375 | 378 | # fontCompiler settings |
@@ -451,6 +454,9 @@ def generate(self): |
451 | 454 | try: |
452 | 455 | # let varLib build the variation font |
453 | 456 | varFont, _, _ = varLib.build(self.operator.doc) |
| 457 | + if self.designspace and self.discreteAxisName: |
| 458 | + # build the stat table from the full designspace and according discrete axis |
| 459 | + buildVFStatTable(varFont, self.designspace, self.discreteAxisName) |
454 | 460 | # save the variation font |
455 | 461 | varFont.save(self.destinationPath) |
456 | 462 | except Exception: |
@@ -506,6 +512,8 @@ def build(root, generateOptions, settings, progress, report): |
506 | 512 | GenerateVariableFont( |
507 | 513 | operator=interpolableOperator, |
508 | 514 | destinationPath=os.path.join(fontDir, tempFileName), |
| 515 | + designspace=operator.doc, |
| 516 | + discreteAxisName=name, |
509 | 517 | autohint=settings["variableFontsAutohint"], |
510 | 518 | fitToExtremes=settings["variableFontsInterpolateToFitAxesExtremes"], |
511 | 519 | releaseMode=False, |
|
0 commit comments