Skip to content

Commit

Permalink
WIP use new designSpaceLib API
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledhosny committed Jun 1, 2023
1 parent a83741d commit d5c7fd6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 49 deletions.
Binary file modified fonts/Raqq.ttf
Binary file not shown.
67 changes: 18 additions & 49 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,54 +442,6 @@ def addSVG(fb):
SVG.docList.append((svg.tostring(), gid, gid))


def addAvar(vf):
from fontTools.misc.fixedTools import floatToFixed as fl2fi
from fontTools.ttLib.tables import otTables
from fontTools.varLib import models, varStore

assert "avar" not in vf

axisTags = [a.axisTag for a in vf["fvar"].axes]

derived = [
{"jstf": +0.0},
{"jstf": +0.9},
{"jstf": +1.0},
{"jstf": -0.5},
{"jstf": -1.0},
]

source = [
{"SPAC": +0.0, "MSHQ": +0.0},
{"SPAC": +0.0, "MSHQ": +1.0},
{"SPAC": +1.0, "MSHQ": +1.0},
{"SPAC": -0.0, "MSHQ": -1.0},
{"SPAC": -1.0, "MSHQ": -1.0},
]

model = models.VariationModel(derived, axisTags)
builder = varStore.OnlineVarStoreBuilder(axisTags)
builder.setModel(model)
varIdxes = {
t: builder.storeMasters([fl2fi(m.get(t, 0), 14) for m in source])[1]
for t in axisTags
}
store = builder.finish()
optimized = store.optimize()
varIdxes = {axis: optimized[value] for axis, value in varIdxes.items()}

varIdxMap = otTables.DeltaSetIndexMap()
varIdxMap.Format = 1
varIdxMap.mapping = [varIdxes[t] for t in axisTags]

avar = vf["avar"] = newTable("avar")
avar.majorVersion = 2
avar.segments = {t: {} for t in axisTags}
avar.table = otTables.avar()
avar.table.VarIdxMap = varIdxMap
avar.table.VarStore = store


def buildMaster(font, master, args):
colorLayers = {}

Expand Down Expand Up @@ -773,8 +725,25 @@ def build(font, instance, args):
source.location = {a.name: master.axes[i] for i, a in enumerate(ds.axes)}
ds.addSource(source)

inputs = [
{"Justification": 0},
{"Justification": 90},
{"Justification": 100},
{"Justification": -50},
{"Justification": -100},
]

outputs = [
{"Spacing": 0, "Mashq": 10},
{"Spacing": 0, "Mashq": 100},
{"Spacing": 125, "Mashq": 100},
{"Spacing": 0, "Mashq": 0},
{"Spacing": -100, "Mashq": 0},
]
for input, output in zip(inputs, outputs):
ds.addAxisMappingDescriptor(inputLocation=input, outputLocation=output)

vf, _, _ = merge(ds)
addAvar(vf)

otf = buildBase(font, instance, vf, args)
return otf
Expand Down

0 comments on commit d5c7fd6

Please sign in to comment.