Skip to content
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
4 changes: 2 additions & 2 deletions Lib/mutatorMath/test/ufo/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test1():
... familyName="TestFamily",
... styleName="TestStyleName",
... location=dict(width=(0.2, 0.8)))
>>> doc.writeGlyph("M", unicodeValue=0xff, location=dict(width=0.9), masters=None, note="testnote123")
>>> doc.writeGlyph("M", unicodes=[0xff], location=dict(width=0.9), masters=None, note="testnote123")
>>> doc.writeGlyph("N", location=dict(width=0.7), masters=glyphMasters)
>>> doc.endInstance()
>>> doc.save()
Expand Down Expand Up @@ -106,7 +106,7 @@ def test1():
# note: the next assertion will fail if the calculations were made with the
# pre-ufo3 fontMath.

>>> assert instance['M'].unicode == 0xff
>>> assert instance['M'].unicodes == [0xff]

# check the groups
>>> list(instance.groups.items())
Expand Down
24 changes: 12 additions & 12 deletions Lib/mutatorMath/ufo/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ def endInstance(self):

def writeGlyph(self,
name,
unicodeValue=None,
unicodes=None,
location=None,
masters=None,
note=None,
mute=False,
):
""" Add a new glyph to the current instance.
* name: the glyph name. Required.
* unicodeValue: unicode value for this glyph if it needs to be different from the unicode value associated with this glyph name in the masters.
* unicodes: unicode values for this glyph if it needs to be different from the unicode values associated with this glyph name in the masters.
* location: a design space location for this glyph if it needs to be different from the instance location.
* masters: a list of masters and locations for this glyph if they need to be different from the masters specified for this instance.
* note: a note for this glyph
Expand All @@ -255,8 +255,8 @@ def writeGlyph(self,
glyphElement = ET.Element('glyph')
if mute:
glyphElement.attrib['mute'] = "1"
if unicodeValue is not None:
glyphElement.attrib['unicode'] = hex(unicodeValue)
if unicodes is not None:
glyphElement.attrib['unicode'] = " ".join([hex(u) for u in unicodes])
if location is not None:
locationElement = self._makeLocationElement(location)
glyphElement.append(locationElement)
Expand Down Expand Up @@ -667,9 +667,9 @@ def _readSingleInstanceElement(self, instanceElement, makeGlyphs=True, makeKerni
# step 1: generate all glyphs we have mutators for.
names = instanceObject.getAvailableGlyphnames()
for n in names:
unicodeValue = self.unicodeMap.get(n, None)
unicodes = self.unicodeMap.get(n, None)
try:
instanceObject.addGlyph(n, unicodeValue)
instanceObject.addGlyph(n, unicodes)
except AssertionError:
if self.verbose and self.logger:
self.logger.info("Problem making glyph %s, skipping.", n)
Expand Down Expand Up @@ -798,14 +798,14 @@ def readGlyphElement(self, glyphElement, instanceObject):
return

# unicode
unicodeValue = glyphElement.attrib.get('unicode')
if unicodeValue == None:
unicodeValue = self.unicodeMap.get(glyphName, None)
unicodes = glyphElement.attrib.get('unicode')
if unicodes == None:
unicodes = self.unicodeMap.get(glyphName, None)
else:
try:
unicodeValue = int(unicodeValue, 16)
unicodes = [int(u, 16) for u in unicodes.split(" ")]
except ValueError:
raise MutatorError("unicode value %s is not integer"%unicodeValue)
raise MutatorError("unicode values %s are not integers" % unicodes)

# note
note = None
Expand Down Expand Up @@ -838,7 +838,7 @@ def readGlyphElement(self, glyphElement, instanceObject):
glyphSources = []
glyphSources.append(d)
# calculate the glyph
instanceObject.addGlyph(glyphName, unicodeValue, instanceLocation, glyphSources, note=note)
instanceObject.addGlyph(glyphName, unicodes, instanceLocation, glyphSources, note=note)

def _instantiateFont(self, path):
"""
Expand Down
15 changes: 5 additions & 10 deletions Lib/mutatorMath/ufo/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,13 @@ def makeUnicodeMapFromSources(self):
for u in glyph.unicodes:
values[glyph.name][u] = 1
for name, u in values.items():
if len(u) > 1:
msg = u", ".join([str(v) for v in u.keys()])
if self.verbose and self.logger:
self.logger.info("\tMultiple unicode values for glyph %s: %s"%(name, msg))
continue
if len(u) == 0:
# only report missing unicodes if the name has no extension
if "." not in name:
self._missingUnicodes.append(name)
continue
k = list(u.keys())
self.unicodeValues[name] = k[0]
self.unicodeValues[name] = k
return self.unicodeValues

def getAvailableGlyphnames(self):
Expand Down Expand Up @@ -309,12 +304,12 @@ def addKerning(self, instanceLocation=None, sources=None):
instanceObject.round()
instanceObject.extractKerning(self.font)

def addGlyph(self, glyphName, unicodeValue=None, instanceLocation=None, sources=None, note=None):
def addGlyph(self, glyphName, unicodes=None, instanceLocation=None, sources=None, note=None):
"""
Calculate a new glyph and add it to this instance.

* glyphName: The name of the glyph
* unicodeValue: The unicode value for this glyph (optional)
* unicodes: The unicode values for this glyph (optional)
* instanceLocation: Location for this glyph
* sources: List of sources for this glyph.
* note: Note for this glyph.
Expand All @@ -324,8 +319,8 @@ def addGlyph(self, glyphName, unicodeValue=None, instanceLocation=None, sources=
if note is not None:
glyphObject.note = note
# why does this not save?
if unicodeValue is not None:
glyphObject.unicode = unicodeValue
if unicodes is not None:
glyphObject.unicodes = unicodes
if instanceLocation is None:
instanceLocation = self.locationObject
glyphMasters = []
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ designspace.
field. Optional.

- **endInstance**\ () Finishes the current instance.
- **writeGlyph**\ (name, unicodeValue, location, masters) Add a new
- **writeGlyph**\ (name, unicodes, location, masters) Add a new
glyph to the current instance.

- **name**: the glyph name. Required.
- **unicodeValue**: unicode value for this glyph if it needs to be
different from the unicode value associated with this glyph name
- **unicodes**: unicode values for this glyph if it needs to be
different from the unicode values associated with this glyph name
in the masters.
- **location**: a design space location for this glyph if it needs
to be different from the instance location.
Expand Down