Skip to content

Commit

Permalink
initial batch scripting api
Browse files Browse the repository at this point in the history
  • Loading branch information
typemytype committed May 24, 2024
1 parent 2257444 commit e4ac1e3
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 10 deletions.
10 changes: 6 additions & 4 deletions source/lib/batchGenerators/desktopFontsGenerator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os
from mojo.roboFont import RFont

from batchGenerators.batchTools import removeTree, generatePaths, postProcessCollector


def build(root, generateOptions, settings, progress, report):
def build(root, generateOptions, settings, progress, report, subFolder="Desktop"):
binaryFormats = []
if generateOptions.get("desktopFontGenerate_OTF"):
binaryFormats.append(("otf", postProcessCollector()))
Expand All @@ -21,8 +20,11 @@ def build(root, generateOptions, settings, progress, report):
report.writeTitle("Batch Generated Desktop Fonts:")
progress.setText("Collecting Data...")

desktopFontsRoot = os.path.join(root, "Desktop")
removeTree(desktopFontsRoot)
if subFolder:
desktopFontsRoot = os.path.join(root, subFolder)
removeTree(desktopFontsRoot)
else:
desktopFontsRoot = root

generatePaths(
ufoPaths=generateOptions["sourceUFOPaths"],
Expand Down
9 changes: 6 additions & 3 deletions source/lib/batchGenerators/variableFontsGenerator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def generate(self):
print(result)


def build(root, generateOptions, settings, progress, report):
def build(root, generateOptions, settings, progress, report, subFolder="Variable"):

binaryFormats = []
if generateOptions["variableFontGenerate_OTF"]:
Expand All @@ -416,8 +416,11 @@ def build(root, generateOptions, settings, progress, report):
if not binaryFormats:
return

variableFontsRoot = os.path.join(root, "Variable")
removeTree(variableFontsRoot)
if subFolder:
variableFontsRoot = os.path.join(root, subFolder)
removeTree(variableFontsRoot)
else:
variableFontsRoot = root

for sourceDesignspacePath in generateOptions["sourceDesignspacePaths"]:
operator = BatchEditorOperator(sourceDesignspacePath)
Expand Down
9 changes: 6 additions & 3 deletions source/lib/batchGenerators/webFontsGenerator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def wrapper(sourcePath, destinationPath):
return wrapper


def build(root, generateOptions, settings, progress, report):
def build(root, generateOptions, settings, progress, report, subFolder="Web"):
if settings["webFontsAutohint"]:
autohintFunc = autohintBuilder(settings, report)
else:
Expand Down Expand Up @@ -103,8 +103,11 @@ def build(root, generateOptions, settings, progress, report):
if not binaryFormats:
return

webFontsRoot = os.path.join(root, "Web")
removeTree(webFontsRoot)
if subFolder:
webFontsRoot = os.path.join(root, subFolder)
removeTree(webFontsRoot)
else:
webFontsRoot = root

report.writeTitle("Batch Generated Web Fonts:")
progress.update("Collecting Data...")
Expand Down
111 changes: 111 additions & 0 deletions source/lib/batchScripting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
from batchGenerators.batchTools import Report
import batchGenerators
import batchSettings


def generateDesktopFonts(ufoPaths, destinationRoot, format="ttf", decompose=True, removeOverlap=True, autohint=False, releaseMode=True, suffix=""):
if isinstance(ufoPaths, str):
ufoPaths = [ufoPaths]
report = Report()
generateOptions = dict(
sourceUFOPaths=ufoPaths,
)
settings = dict(batchSettings.defaultSettings)
settings.update(
dict(
batchSettingExportInSubFolders=False,
desktopFontsAutohint=autohint,
desktopFontsDecompose=decompose,
desktopFontsReleaseMode=releaseMode,
desktopFontsRemoveOverlap=removeOverlap,
desktopFontsSuffix=suffix
)
)
if format == "ttf":
generateOptions["desktopFontGenerate_TTF"] = True
if format == "otf":
generateOptions["desktopFontGenerate_OTF"] = True

batchGenerators.desktopFontsGenerator.build(
root=destinationRoot,
generateOptions=generateOptions,
settings=settings,
progress=None,
report=report
)
return report.get()


def generateWebFonts(ufoPaths, destinationRoot, format="ttf", woff=False, decompose=True, removeOverlap=True, autohint=False, releaseMode=True, suffix="", html=False, htmlPreview=None):
if isinstance(ufoPaths, str):
ufoPaths = [ufoPaths]
report = Report()
generateOptions = dict(
sourceUFOPaths=ufoPaths,
)
settings = dict(batchSettings.defaultSettings)
settings.update(
dict(
batchSettingExportInSubFolders=False,
webFontsAutohint=autohint,
webFontsDecompose=decompose,
webFontsGenerateHTML=html,
webFontsReleaseMode=releaseMode,
webFontsRemoveOverlap=removeOverlap,
webFontsSuffix=suffix
)
)
if htmlPreview:
settings["webFontsHtmlPreview"] = htmlPreview
if format == "ttf" and woff:
generateOptions["webFontGenerate_TTFWOFF2"] = True
if format == "otf" and woff:
generateOptions["webFontGenerate_OTFWOFF2"] = True
if format == "ttf" and not woff:
generateOptions["webFontGenerate_TTF"] = True
if format == "otf" and not woff:
generateOptions["webFontGenerate_OTF"] = True

batchGenerators.webFontsGenerator.build(
root=destinationRoot,
generateOptions=generateOptions,
settings=settings,
progress=None,
report=report
)
return report.get()


def generateVariableFonts(designspacePaths, destinationRoot, format="ttf", woff=False, autohint=False, fitToExtremes=False, suffix=""):
if isinstance(designspacePaths, str):
designspacePaths = [designspacePaths]
report = Report()
generateOptions = dict(
sourceDesignspacePaths=designspacePaths,
)
settings = dict(batchSettings.defaultSettings)
settings.update(
dict(
batchSettingExportInSubFolders=False,
variableFontsAutohint=autohint,
variableFontsInterpolateToFitAxesExtremes=fitToExtremes,
variableFontsSuffix=suffix
)
)
if format == "ttf" and woff:
generateOptions["variableFontGenerate_TTFWOFF2"] = True
if format == "otf" and woff:
generateOptions["variableFontGenerate_OTFWOFF2"] = True
if format == "ttf" and not woff:
generateOptions["variableFontGenerate_TTF"] = True
if format == "otf" and not woff:
generateOptions["variableFontGenerate_OTF"] = True

batchGenerators.variableFontsGenerator.build(
root=destinationRoot,
generateOptions=generateOptions,
settings=settings,
progress=None,
report=report
)
return report.get()

0 comments on commit e4ac1e3

Please sign in to comment.