sketch out localisable names following ideas from #9

This commit is contained in:
Erik van Blokland 2017-04-23 15:39:17 +02:00
parent 29a6ac029a
commit 3b27469c04

View File

@ -151,6 +151,7 @@ def processRules(rules, location, glyphNames):
class InstanceDescriptor(SimpleDescriptor): class InstanceDescriptor(SimpleDescriptor):
"""Simple container for data related to the instance""" """Simple container for data related to the instance"""
flavor = "instance" flavor = "instance"
_defaultLanguageCode = "en"
_attrs = ['path', 'name', _attrs = ['path', 'name',
'location', 'familyName', 'location', 'familyName',
'styleName', 'postScriptFontName', 'styleName', 'postScriptFontName',
@ -172,6 +173,25 @@ class InstanceDescriptor(SimpleDescriptor):
self.kerning = True self.kerning = True
self.info = True self.info = True
def setStyleName(self, styleName, languageCode="en"):
self.localisedStyleName[self._defaultLanguageCode] = styleName
def getStyleName(self, languageCode="en"):
return self.localisedStyleName.get(self._defaultLanguageCode)
def setFamilyName(self, familyName, languageCode="en"):
self.localisedFamilyName[self._defaultLanguageCode] = familyName
def getFamilyName(self, languageCode="en"):
return self.localisedFamilyName.get(self._defaultLanguageCode)
def setStyleMapStyleName(self, styleMapStyleName, languageCode="en"):
self.localisedStyleMapStyleName[self._defaultLanguageCode] = styleMapStyleName
def getStyleMapStyleName(self, languageCode="en"):
return self.localisedStyleMapStyleName.get(self._defaultLanguageCode)
def setStyleMapFamilyName(self, styleMapFamilyName, languageCode="en"):
self.localisedStyleMapFamilyName[self._defaultLanguageCode] = styleMapFamilyName
def getStyleMapFamilyName(self, languageCode="en"):
return self.localisedStyleMapFamilyName.get(self._defaultLanguageCode)
def tagForAxisName(name): def tagForAxisName(name):
# try to find or make a tag name for this axis name # try to find or make a tag name for this axis name
@ -192,7 +212,9 @@ def tagForAxisName(name):
class AxisDescriptor(SimpleDescriptor): class AxisDescriptor(SimpleDescriptor):
"""Simple container for the axis data""" """ Simple container for the axis data
Add more localisations?
"""
flavor = "axis" flavor = "axis"
_attrs = ['tag', 'name', 'maximum', 'minimum', 'default', 'map'] _attrs = ['tag', 'name', 'maximum', 'minimum', 'default', 'map']
@ -363,9 +385,21 @@ class BaseDocWriter(object):
if instanceObject.name is not None: if instanceObject.name is not None:
instanceElement.attrib['name'] = instanceObject.name instanceElement.attrib['name'] = instanceObject.name
if instanceObject.familyName is not None: if instanceObject.familyName is not None:
instanceElement.attrib['familyname'] = instanceObject.familyName print("xxx", instanceObject)
instanceElement.attrib['familyname'] = instanceObject.getFamilyName()
if instanceObject.styleName is not None: if instanceObject.styleName is not None:
instanceElement.attrib['stylename'] = instanceObject.styleName instanceElement.attrib['stylename'] = instanceObject.getStyleName()
# add localisations
if instanceObject.localisedStyleName:
languageCodes = instanceObject.localisedStyleName.keys()
languageCodes.sort()
for code in languageCodes:
if code == "en": continue
localisedStyleNameElement = ET.Element('stylename')
localisedStyleNameElement.attrib["xml:lang"] = code
localisedStyleNameElement.text = instanceObject.getStyleName(code)
instanceObject.append(localisedStyleNameElement)
if instanceObject.location is not None: if instanceObject.location is not None:
locationElement, instanceObject.location = self._makeLocationElement(instanceObject.location) locationElement, instanceObject.location = self._makeLocationElement(instanceObject.location)
instanceElement.append(locationElement) instanceElement.append(locationElement)