designspaceLib¶
MutatorMath started out with its own reader and writer for designspaces. Since then the use of designspace has broadened and it would be useful to have a reader and writer that are independent of a specific system.
-
class
fontTools.designspaceLib.
AxisDescriptor
(*, tag=None, name=None, labelNames=None, minimum=None, default=None, maximum=None, hidden=False, map=None)[source]¶ Simple container for the axis data Add more localisations?
-
asdict
()¶
-
compare
(other)¶
-
flavor
= 'axis'¶
-
-
class
fontTools.designspaceLib.
BaseDocReader
(documentPath, documentObject)[source]¶ -
axisDescriptorClass
¶ alias of
AxisDescriptor
-
instanceDescriptorClass
¶ alias of
InstanceDescriptor
-
property
log
¶
-
readGlyphElement
(glyphElement, instanceObject)[source]¶ - Read the glyph element.
<glyph name=”b” unicode=”0x62”/> <glyph name=”b”/> <glyph name=”b”>
<master location=”location-token-bbb” source=”master-token-aaa2”/> <master glyphname=”b.alt1” location=”location-token-ccc” source=”master-token-aaa3”/> <note>
This is an instance from an anisotropic interpolation.
</note>
</glyph>
-
ruleDescriptorClass
¶ alias of
RuleDescriptor
-
sourceDescriptorClass
¶ alias of
SourceDescriptor
-
-
class
fontTools.designspaceLib.
BaseDocWriter
(documentPath, documentObject)[source]¶ -
axisDescriptorClass
¶ alias of
AxisDescriptor
-
instanceDescriptorClass
¶ alias of
InstanceDescriptor
-
ruleDescriptorClass
¶ alias of
RuleDescriptor
-
sourceDescriptorClass
¶ alias of
SourceDescriptor
-
-
class
fontTools.designspaceLib.
DesignSpaceDocument
(readerClass=None, writerClass=None)[source]¶ Read, write data from the designspace file
-
asdict
()¶
-
filename
¶ String, optional. When the document is read from the disk, this is its original file name, i.e. the last part of its path.
When the document is produced by a Python script and still only exists in memory, the producing script can write here an indication of a possible “good” filename, in case one wants to save the file somewhere.
-
findDefault
()[source]¶ Set and return SourceDescriptor at the default location or None.
The default location is the set of all default values in user space of all axes.
-
lib
¶ Custom data associated with the whole document.
-
loadSourceFonts
(opener, **kwargs)[source]¶ Ensure SourceDescriptor.font attributes are loaded, and return list of fonts.
Takes a callable which initializes a new font object (e.g. TTFont, or defcon.Font, etc.) from the SourceDescriptor.path, and sets the SourceDescriptor.font attribute. If the font attribute is already not None, it is not loaded again. Fonts with the same path are only loaded once and shared among SourceDescriptors.
For example, to load UFO sources using defcon:
designspace = DesignSpaceDocument.fromfile(“path/to/my.designspace”) designspace.loadSourceFonts(defcon.Font)
Or to load masters as FontTools binary fonts, including extra options:
designspace.loadSourceFonts(ttLib.TTFont, recalcBBoxes=False)
- Parameters
opener (Callable) – takes one required positional argument, the source.path, and an optional list of keyword arguments, and returns a new font object loaded from the path.
**kwargs – extra options passed on to the opener function.
- Returns
List of font objects in the order they appear in the sources list.
-
property
log
¶
-
updatePaths
()[source]¶ Right before we save we need to identify and respond to the following situations: In each descriptor, we have to do the right thing for the filename attribute.
case 1. descriptor.filename == None descriptor.path == None
– action: write as is, descriptors will not have a filename attr. useless, but no reason to interfere.
case 2. descriptor.filename == “../something” descriptor.path == None
– action: write as is. The filename attr should not be touched.
case 3. descriptor.filename == None descriptor.path == “~/absolute/path/there”
– action: calculate the relative path for filename. We’re not overwriting some other value for filename, it should be fine
case 4. descriptor.filename == ‘../somewhere’ descriptor.path == “~/absolute/path/there”
– action: there is a conflict between the given filename, and the path. So we know where the file is relative to the document. Can’t guess why they’re different, we just choose for path to be correct and update filename.
-
-
exception
fontTools.designspaceLib.
DesignSpaceDocumentError
(msg, obj=None)[source]¶ -
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
fontTools.designspaceLib.
InstanceDescriptor
(*, filename=None, path=None, font=None, name=None, location=None, familyName=None, styleName=None, postScriptFontName=None, styleMapFamilyName=None, styleMapStyleName=None, localisedFamilyName=None, localisedStyleName=None, localisedStyleMapFamilyName=None, localisedStyleMapStyleName=None, glyphs=None, kerning=True, info=True, lib=None)[source]¶ Simple container for data related to the instance
-
asdict
()¶
-
compare
(other)¶
-
property
filename
¶
-
flavor
= 'instance'¶
-
lib
¶ Custom data associated with this instance.
-
property
path
¶
-
-
class
fontTools.designspaceLib.
RuleDescriptor
(*, name=None, conditionSets=None, subs=None)[source]¶ <!– optional: list of substitution rules –> <rules>
- <rule name=”vertical.bars”>
- <conditionset>
<condition minimum=”250.000000” maximum=”750.000000” name=”weight”/> <condition minimum=”100” name=”width”/> <condition minimum=”10” maximum=”40” name=”optical”/>
</conditionset> <sub name=”cent” with=”cent.alt”/> <sub name=”dollar” with=”dollar.alt”/>
</rule>
</rules>
-
asdict
()¶
-
compare
(other)¶
-
class
fontTools.designspaceLib.
SourceDescriptor
(*, filename=None, path=None, font=None, name=None, location=None, layerName=None, familyName=None, styleName=None, copyLib=False, copyInfo=False, copyGroups=False, copyFeatures=False, muteKerning=False, muteInfo=False, mutedGlyphNames=None)[source]¶ Simple container for data related to the source
-
asdict
()¶
-
compare
(other)¶
-
property
filename
¶ The original path as found in the document.
-
flavor
= 'source'¶
-
font
¶ Any Python object. Optional. Points to a representation of this source font that is loaded in memory, as a Python object (e.g. a
defcon.Font
or afontTools.ttFont.TTFont
).The default document reader will not fill-in this attribute, and the default writer will not use this attribute. It is up to the user of
designspaceLib
to either load the resource identified byfilename
and store it in this field, or write the contents of this field to the disk and make`filename
point to that.
-
property
path
¶ The absolute path, calculated from filename.
-