-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from googlefonts/compile-fontmake
Add fontmake output action
- Loading branch information
Showing
8 changed files
with
5,497 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mypy==1.8.0 | ||
pre-commit==3.3.3 | ||
pytest==7.3.2 | ||
types-PyYAML==6.0.12.12 | ||
mypy==1.9.0 | ||
pre-commit==3.6.2 | ||
pytest==8.1.1 | ||
types-PyYAML==6.0.12.20240311 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
fonttools==4.43.0 | ||
fonttools==4.50.0 | ||
fontmake==3.8.1 | ||
git+https://github.com/googlefonts/fontra.git | ||
git+https://github.com/googlefonts/fontra-rcjk.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os | ||
import pathlib | ||
import subprocess | ||
import tempfile | ||
from contextlib import aclosing, asynccontextmanager | ||
from dataclasses import dataclass, field | ||
from typing import AsyncGenerator | ||
|
||
from fontra.backends import newFileSystemBackend | ||
from fontra.backends.copy import copyFont | ||
from fontra.core.protocols import ReadableFontBackend | ||
from fontra.workflow.actions import OutputActionProtocol, registerActionClass | ||
|
||
|
||
@registerActionClass("compile-fontmake") | ||
@dataclass(kw_only=True) | ||
class CompileFontMakeAction: | ||
destination: str | ||
options: dict[str, str] = field(default_factory=dict) | ||
input: ReadableFontBackend | None = field(init=False, default=None) | ||
|
||
@asynccontextmanager | ||
async def connect( | ||
self, input: ReadableFontBackend | ||
) -> AsyncGenerator[ReadableFontBackend | OutputActionProtocol, None]: | ||
self.input = input | ||
try: | ||
yield self | ||
finally: | ||
self.input = None | ||
|
||
async def process(self, outputDir: os.PathLike = pathlib.Path()) -> None: | ||
assert self.input is not None | ||
outputDir = pathlib.Path(outputDir) | ||
outputFontPath = outputDir / self.destination | ||
|
||
with tempfile.TemporaryDirectory() as tmpDirName: | ||
tmpDir = pathlib.Path(tmpDirName) | ||
|
||
designspacePath = tmpDir / "temp.designspace" | ||
|
||
dsBackend = newFileSystemBackend(designspacePath) | ||
|
||
async with aclosing(dsBackend): | ||
await copyFont(self.input, dsBackend) | ||
|
||
# assert 0, [p.name for p in tmpDir.iterdir()] | ||
command = [ | ||
"fontmake", | ||
"-m", | ||
os.fspath(designspacePath), | ||
"-o", | ||
"variable", | ||
"--output-path", | ||
os.fspath(outputFontPath), | ||
] | ||
|
||
for option, value in self.options.items(): | ||
command.append(f"--{option}") | ||
if value: | ||
command.append(value) | ||
|
||
subprocess.run(command, check=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.