Skip to content

Commit

Permalink
A sketch for fontmake issue #552.
Browse files Browse the repository at this point in the history
When building a mutator, accept the warp data to make benders. But don't apply them to the master and instance locations.
Add test file from @anthrotype
  • Loading branch information
LettError committed May 28, 2019
1 parent 10318fc commit 5576f9d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Lib/mutatorMath/objects/mutator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,28 @@ def buildMutator(items, axes=None, bias=None):
items = [(Location(loc),obj) for loc, obj in items]
m = Mutator()
if axes is not None:
# make a Bender object
# but do not transform the locations from the items
bender = Bender(axes)
m.setBender(bender)
else:
bender = noBend
# the order itself does not matter, but we should always build in the same order.
items = sorted(items)
if not bias:
bias = biasFromLocations([bender(loc) for loc, obj in items], True)
else:
# note: this means that the actual bias might be different from the initial value.
bias = bender(bias)
bias = biasFromLocations([loc for loc, obj in items], True)
m.setBias(bias)
n = None
ofx = []
onx = []
for loc, obj in items:
loc = bender(loc)
if (loc-bias).isOrigin():
m.setNeutral(obj)
break
if m.getNeutral() is None:
raise MutatorError("Did not find a neutral for this system", m)
for loc, obj in items:
locbent = bender(loc)
lb = locbent-bias
lb = loc-bias
if lb.isOrigin(): continue
if lb.isOnAxis():
onx.append((lb, obj-m.getNeutral()))
Expand Down Expand Up @@ -113,7 +110,6 @@ def addDelta(self, location, aMathObject, deltaName = None, punch=False, axisOn
* True: add the difference with the instance value at that location and the delta
* False: just add the delta.
"""
#location = self._bender(location)
if punch:
r = self.getInstance(location, axisOnly=axisOnly)
if r is not None:
Expand Down
37 changes: 37 additions & 0 deletions fontmake_#552/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from mutatorMath.objects.mutator import buildMutator
from mutatorMath.objects.location import Location

# source locations implicitly specified in internal, design location.
# the second item is master's value at given location. I use numbers for simplicity
# but it can be any object that supports addition and multiplication (fontMath objects)
masters = [
(Location(Width=70), 0),
(Location(Width=100), 100),
]

axes = {
'Width': {
'tag': 'wdth',
'name': 'Width',
# min/default/max are always in user-space coordinates
'minimum': 62.5,
'default': 100.0,
'maximum': 100.0,
# first item (input) is user-space coordinate, second item (output) is internal design coordinate
'map': [(62.5, 70.0), (75.0, 79.0), (87.5, 89.0), (100.0, 100.0)],
#'map': [(70.0, 62.5), (79.0, 75.0), (89.0, 87.5), (100.0, 100.0)],
}
}

_, mut = buildMutator(masters, axes)

# instance locations are also specified in internal design coordinates (at least varLib assumes they are)
instance_location = Location(Width=79)

instance = mut.makeInstance(Location(Width=79), bend=False)
# the result is 27.642276422764223, but it should have been 30.0
print(instance)

instance = mut.makeInstance(Location(Width=75), bend=True)
# the result is 27.642276422764223, but it should have been 30.0
print(instance)

0 comments on commit 5576f9d

Please sign in to comment.