Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust-axes action: make remap sources optional #1190

Merged
merged 4 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions src/fontra/workflow/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ async def processGlyph(self, glyph: VariableGlyph) -> VariableGlyph:
@dataclass(kw_only=True)
class DropAxisMappingAction(BaseFilterAction):
axes: list[str] | None = None
_axisValueMapFunctions: dict | None = None

_axisValueMapFunctions: dict | None = field(init=False, default=None)

async def _getAxisValueMapFunctions(self) -> dict:
if self._axisValueMapFunctions is None:
Expand Down Expand Up @@ -419,8 +420,12 @@ def _dropAxisMapping(axis, mapFuncs):
@dataclass(kw_only=True)
class AdjustAxesAction(BaseFilterAction):
axes: dict[str, dict[str, Any]]
_adjustedAxes: list[GlobalAxis | GlobalDiscreteAxis] | None = None
_axisValueMapFunctions: dict | None = None
remapSources: bool = True

_adjustedAxes: list[GlobalAxis | GlobalDiscreteAxis] | None = field(
init=False, default=None
)
_axisValueMapFunctions: dict | None = field(init=False, default=None)

async def _ensureSetup(self) -> None:
if self._adjustedAxes is not None:
Expand All @@ -436,21 +441,24 @@ async def _ensureSetup(self) -> None:
names = {"minValue", "defaultValue", "maxValue"}
newValues = {k: v for k, v in newValues.items() if k in names}
newAxis = replace(axis, **newValues)
mapping = [
(axis.minValue, newAxis.minValue),
(axis.defaultValue, newAxis.defaultValue),
(axis.maxValue, newAxis.maxValue),
]
mapFunc = partial(
piecewiseLinearMap,
mapping=dict(mapping),
)
if newAxis.mapping:
newAxis.mapping = [
[mapFunc(user), source] for user, source in newAxis.mapping

if self.remapSources:
mapping = [
(axis.minValue, newAxis.minValue),
(axis.defaultValue, newAxis.defaultValue),
(axis.maxValue, newAxis.maxValue),
]
else:
mapFuncs[axis.name] = mapFunc
mapFunc = partial(
piecewiseLinearMap,
mapping=dict(mapping),
)
if newAxis.mapping:
newAxis.mapping = [
[mapFunc(user), source] for user, source in newAxis.mapping
]
else:
mapFuncs[axis.name] = mapFunc

axis = newAxis
adjustedAxes.append(axis)
self._adjustedAxes = adjustedAxes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"unitsPerEm": 1000,
"customData": {},
"axes": [
{
"name": "width",
"label": "width",
"tag": "wdth",
"minValue": 0.0,
"defaultValue": 0.0,
"maxValue": 1000.0
},
{
"name": "weight",
"label": "weight",
"tag": "wght",
"minValue": 200,
"defaultValue": 400,
"maxValue": 800
},
{
"name": "italic",
"label": "italic",
"tag": "ital",
"values": [
0.0,
1.0
],
"defaultValue": 0.0
}
],
"sources": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
glyph name;code points
A;U+0041,U+0061
Loading