• Home
Name Date Size #Lines LOC

..--

index.rstD03-May-2024412 1914

readme.rstD03-May-202436.9 KiB1,151877

scripting.rstD03-May-20247.6 KiB254186

readme.rst

1#################################
2DesignSpaceDocument Specification
3#################################
4
5An object to read, write and edit interpolation systems for typefaces. Define sources, axes, rules and instances.
6
7-  `The Python API of the objects <#python-api>`_
8-  `The document XML structure <#document-xml-structure>`_
9
10
11**********
12Python API
13**********
14
15
16
17.. _designspacedocument-object:
18
19DesignSpaceDocument object
20==========================
21
22The DesignSpaceDocument object can read and write ``.designspace`` data.
23It imports the axes, sources and instances to very basic **descriptor**
24objects that store the data in attributes. Data is added to the document
25by creating such descriptor objects, filling them with data and then
26adding them to the document. This makes it easy to integrate this object
27in different contexts.
28
29The **DesignSpaceDocument** object can be subclassed to work with
30different objects, as long as they have the same attributes. Reader and
31Writer objects can be subclassed as well.
32
33**Note:** Python attribute names are usually camelCased, the
34corresponding `XML <#document-xml-structure>`_ attributes are usually
35all lowercase.
36
37.. example-1:
38
39.. code:: python
40
41    from fontTools.designspaceLib import DesignSpaceDocument
42    doc = DesignSpaceDocument()
43    doc.read("some/path/to/my.designspace")
44    doc.axes
45    doc.sources
46    doc.instances
47
48Attributes
49----------
50
51-  ``axes``: list of axisDescriptors
52-  ``sources``: list of sourceDescriptors
53-  ``instances``: list of instanceDescriptors
54-  ``rules``: list if ruleDescriptors
55-  ``readerClass``: class of the reader object
56-  ``writerClass``: class of the writer object
57-  ``lib``: dict for user defined, custom data that needs to be stored
58   in the designspace. Use reverse-DNS notation to identify your own data.
59   Respect the data stored by others.
60-  ``rulesProcessingLast``: This flag indicates whether the substitution rules should be applied before or after other glyph substitution features. False: before, True: after.
61
62Methods
63-------
64
65-  ``read(path)``: read a designspace file from ``path``
66-  ``write(path)``: write this designspace to ``path``
67-  ``addSource(aSourceDescriptor)``: add this sourceDescriptor to
68   ``doc.sources``.
69-  ``addInstance(anInstanceDescriptor)``: add this instanceDescriptor
70   to ``doc.instances``.
71-  ``addAxis(anAxisDescriptor)``: add this instanceDescriptor to ``doc.axes``.
72-  ``newDefaultLocation()``: returns a dict with the default location
73   in designspace coordinates.
74-  ``updateFilenameFromPath(masters=True, instances=True, force=False)``:
75   set a descriptor filename attr from the path and this document.
76-  ``newAxisDescriptor()``: return a new axisDescriptor object.
77-  ``newSourceDescriptor()``: return a new sourceDescriptor object.
78-  ``newInstanceDescriptor()``: return a new instanceDescriptor object.
79-  ``getAxisOrder()``: return a list of axisnames
80-  ``findDefault()``: return the sourceDescriptor that is on the default
81   location. Returns None if there isn't one.
82-  ``normalizeLocation(aLocation)``: return a dict with normalized axis values.
83-  ``normalize()``: normalize the geometry of this designspace: scale all the
84   locations of all masters and instances to the ``-1 - 0 - 1`` value.
85-  ``loadSourceFonts()``: Ensure SourceDescriptor.font attributes are loaded,
86   and return list of fonts.
87-  ``tostring(encoding=None)``: Returns the designspace as a string. Default
88   encoding `utf-8`.
89
90Class Methods
91-------------
92- ``fromfile(path)``
93- ``fromstring(string)``
94
95
96
97
98
99
100SourceDescriptor object
101=======================
102
103Attributes
104----------
105
106-  ``filename``: string. A relative path to the source file, **as it is
107   in the document**. MutatorMath + Varlib.
108-  ``path``: string. Absolute path to the source file, calculated from
109   the document path and the string in the filename attr. MutatorMath +
110   Varlib.
111-  ``layerName``: string. The name of the layer in the source to look for
112   outline data. Default ``None`` which means ``foreground``.
113-  ``font``: Any Python object. Optional. Points to a representation of
114   this source font that is loaded in memory, as a Python object
115   (e.g. a ``defcon.Font`` or a ``fontTools.ttFont.TTFont``). The default
116   document reader will not fill-in this attribute, and the default
117   writer will not use this attribute. It is up to the user of
118   ``designspaceLib`` to either load the resource identified by ``filename``
119   and store it in this field, or write the contents of this field to the
120   disk and make ``filename`` point to that.
121-  ``name``: string. Optional. Unique identifier name for this source,
122   if there is one or more ``instance.glyph`` elements in the document.
123   MutatorMath.
124-  ``location``: dict. Axis values for this source. MutatorMath + Varlib
125-  ``copyLib``: bool. Indicates if the contents of the font.lib need to
126   be copied to the instances. MutatorMath.
127-  ``copyInfo`` bool. Indicates if the non-interpolating font.info needs
128   to be copied to the instances. MutatorMath
129-  ``copyGroups`` bool. Indicates if the groups need to be copied to the
130   instances. MutatorMath.
131-  ``copyFeatures`` bool. Indicates if the feature text needs to be
132   copied to the instances. MutatorMath.
133-  ``muteKerning``: bool. Indicates if the kerning data from this source
134   needs to be muted (i.e. not be part of the calculations).
135   MutatorMath.
136-  ``muteInfo``: bool. Indicated if the interpolating font.info data for
137   this source needs to be muted. MutatorMath.
138-  ``mutedGlyphNames``: list. Glyphnames that need to be muted in the
139   instances. MutatorMath.
140-  ``familyName``: string. Family name of this source. Though this data
141   can be extracted from the font, it can be efficient to have it right
142   here. Varlib.
143-  ``styleName``: string. Style name of this source. Though this data
144   can be extracted from the font, it can be efficient to have it right
145   here. Varlib.
146
147.. code:: python
148
149    doc = DesignSpaceDocument()
150    s1 = SourceDescriptor()
151    s1.path = masterPath1
152    s1.name = "master.ufo1"
153    s1.font = defcon.Font("master.ufo1")
154    s1.copyLib = True
155    s1.copyInfo = True
156    s1.copyFeatures = True
157    s1.location = dict(weight=0)
158    s1.familyName = "MasterFamilyName"
159    s1.styleName = "MasterStyleNameOne"
160    s1.mutedGlyphNames.append("A")
161    s1.mutedGlyphNames.append("Z")
162    doc.addSource(s1)
163
164.. _instance-descriptor-object:
165
166InstanceDescriptor object
167=========================
168
169.. attributes-1:
170
171
172Attributes
173----------
174
175-  ``filename``: string. Relative path to the instance file, **as it is
176   in the document**. The file may or may not exist. MutatorMath.
177-  ``path``: string. Absolute path to the source file, calculated from
178   the document path and the string in the filename attr. The file may
179   or may not exist. MutatorMath.
180-  ``name``: string. Unique identifier name of the instance, used to
181   identify it if it needs to be referenced from elsewhere in the
182   document.
183-  ``location``: dict. Axis values for this source. MutatorMath +
184   Varlib.
185-  ``familyName``: string. Family name of this instance. MutatorMath +
186   Varlib.
187-  ``localisedFamilyName``: dict. A dictionary of localised family name
188   strings, keyed by language code.
189-  ``styleName``: string. Style name of this source. MutatorMath +
190   Varlib.
191-  ``localisedStyleName``: dict. A dictionary of localised stylename
192   strings, keyed by language code.
193-  ``postScriptFontName``: string. Postscript fontname for this
194   instance. MutatorMath.
195-  ``styleMapFamilyName``: string. StyleMap familyname for this
196   instance. MutatorMath.
197-  ``localisedStyleMapFamilyName``: A dictionary of localised style map
198   familyname strings, keyed by language code.
199-  ``localisedStyleMapStyleName``: A dictionary of localised style map
200   stylename strings, keyed by language code.
201-  ``styleMapStyleName``: string. StyleMap stylename for this instance.
202   MutatorMath.
203-  ``glyphs``: dict for special master definitions for glyphs. If glyphs
204   need special masters (to record the results of executed rules for
205   example). MutatorMath.
206-  ``kerning``: bool. Indicates if this instance needs its kerning
207   calculated. MutatorMath.
208-  ``info``: bool. Indicated if this instance needs the interpolating
209   font.info calculated.
210-  ``lib``: dict. Custom data associated with this instance.
211
212Methods
213-------
214
215These methods give easier access to the localised names.
216
217-  ``setStyleName(styleName, languageCode="en")``
218-  ``getStyleName(languageCode="en")``
219-  ``setFamilyName(familyName, languageCode="en")``
220-  ``getFamilyName(self, languageCode="en")``
221-  ``setStyleMapStyleName(styleMapStyleName, languageCode="en")``
222-  ``getStyleMapStyleName(languageCode="en")``
223-  ``setStyleMapFamilyName(styleMapFamilyName, languageCode="en")``
224-  ``getStyleMapFamilyName(languageCode="en")``
225
226Example
227-------
228
229.. code:: python
230
231    i2 = InstanceDescriptor()
232    i2.path = instancePath2
233    i2.familyName = "InstanceFamilyName"
234    i2.styleName = "InstanceStyleName"
235    i2.name = "instance.ufo2"
236    # anisotropic location
237    i2.location = dict(weight=500, width=(400,300))
238    i2.postScriptFontName = "InstancePostscriptName"
239    i2.styleMapFamilyName = "InstanceStyleMapFamilyName"
240    i2.styleMapStyleName = "InstanceStyleMapStyleName"
241    glyphMasters = [dict(font="master.ufo1", glyphName="BB", location=dict(width=20,weight=20)), dict(font="master.ufo2", glyphName="CC", location=dict(width=900,weight=900))]
242    glyphData = dict(name="arrow", unicodeValue=1234)
243    glyphData['masters'] = glyphMasters
244    glyphData['note'] = "A note about this glyph"
245    glyphData['instanceLocation'] = dict(width=100, weight=120)
246    i2.glyphs['arrow'] = glyphData
247    i2.glyphs['arrow2'] = dict(mute=False)
248    i2.lib['com.coolDesignspaceApp.specimenText'] = 'Hamburgerwhatever'
249    doc.addInstance(i2)
250
251.. _axis-descriptor-object:
252
253AxisDescriptor object
254=====================
255
256-  ``tag``: string. Four letter tag for this axis. Some might be
257   registered at the `OpenType
258   specification <https://www.microsoft.com/typography/otspec/fvar.htm#VAT>`__.
259   Privately-defined axis tags must begin with an uppercase letter and
260   use only uppercase letters or digits.
261-  ``name``: string. Name of the axis as it is used in the location
262   dicts. MutatorMath + Varlib.
263-  ``labelNames``: dict. When defining a non-registered axis, it will be
264   necessary to define user-facing readable names for the axis. Keyed by
265   xml:lang code. Values are required to be ``unicode`` strings, even if
266   they only contain ASCII characters.
267-  ``minimum``: number. The minimum value for this axis in user space.
268   MutatorMath + Varlib.
269-  ``maximum``: number. The maximum value for this axis in user space.
270   MutatorMath + Varlib.
271-  ``default``: number. The default value for this axis, i.e. when a new
272   location is created, this is the value this axis will get in user
273   space. MutatorMath + Varlib.
274-  ``map``: list of input / output values that can describe a warp
275   of user space to design space coordinates. If no map values are present, it is assumed user space is the same as design space, as
276   in [(minimum, minimum), (maximum, maximum)]. Varlib.
277
278.. code:: python
279
280    a1 = AxisDescriptor()
281    a1.minimum = 1
282    a1.maximum = 1000
283    a1.default = 400
284    a1.name = "weight"
285    a1.tag = "wght"
286    a1.labelNames[u'fa-IR'] = u"قطر"
287    a1.labelNames[u'en'] = u"Wéíght"
288    a1.map = [(1.0, 10.0), (400.0, 66.0), (1000.0, 990.0)]
289
290RuleDescriptor object
291=====================
292
293-  ``name``: string. Unique name for this rule. Can be used to
294   reference this rule data.
295-  ``conditionSets``: a list of conditionsets
296-  Each conditionset is a list of conditions.
297-  Each condition is a dict with ``name``, ``minimum`` and ``maximum`` keys.
298-  ``subs``: list of substitutions
299-  Each substitution is stored as tuples of glyphnames, e.g. ("a", "a.alt").
300-  Note: By default, rules are applied first, before other text shaping/OpenType layout, as they are part of the `Required Variation Alternates OpenType feature <https://docs.microsoft.com/en-us/typography/opentype/spec/features_pt#-tag-rvrn>`_. See `5.0 rules element`_ § Attributes.
301
302Evaluating rules
303----------------
304
305-  ``evaluateRule(rule, location)``: Return True if any of the rule's conditionsets
306   matches the given location.
307-  ``evaluateConditions(conditions, location)``: Return True if all the conditions
308   matches the given location.
309-  ``processRules(rules, location, glyphNames)``: Apply all the rules to the list
310   of glyphNames. Return a new list of glyphNames with substitutions applied.
311
312.. code:: python
313
314    r1 = RuleDescriptor()
315    r1.name = "unique.rule.name"
316    r1.conditionSets.append([dict(name="weight", minimum=-10, maximum=10), dict(...)])
317    r1.conditionSets.append([dict(...), dict(...)])
318    r1.subs.append(("a", "a.alt"))
319
320
321.. _subclassing-descriptors:
322
323Subclassing descriptors
324=======================
325
326The DesignSpaceDocument can take subclassed Reader and Writer objects.
327This allows you to work with your own descriptors. You could subclass
328the descriptors. But as long as they have the basic attributes the
329descriptor does not need to be a subclass.
330
331.. code:: python
332
333    class MyDocReader(BaseDocReader):
334        ruleDescriptorClass = MyRuleDescriptor
335        axisDescriptorClass = MyAxisDescriptor
336        sourceDescriptorClass = MySourceDescriptor
337        instanceDescriptorClass = MyInstanceDescriptor
338
339    class MyDocWriter(BaseDocWriter):
340        ruleDescriptorClass = MyRuleDescriptor
341        axisDescriptorClass = MyAxisDescriptor
342        sourceDescriptorClass = MySourceDescriptor
343        instanceDescriptorClass = MyInstanceDescriptor
344
345    myDoc = DesignSpaceDocument(KeyedDocReader, KeyedDocWriter)
346
347**********************
348Document xml structure
349**********************
350
351-  The ``axes`` element contains one or more ``axis`` elements.
352-  The ``sources`` element contains one or more ``source`` elements.
353-  The ``instances`` element contains one or more ``instance`` elements.
354-  The ``rules`` element contains one or more ``rule`` elements.
355-  The ``lib`` element contains arbitrary data.
356
357.. code:: xml
358
359    <?xml version='1.0' encoding='utf-8'?>
360    <designspace format="3">
361        <axes>
362            <!-- define axes here -->
363            <axis../>
364        </axes>
365        <sources>
366            <!-- define masters here -->
367            <source../>
368        </sources>
369        <instances>
370            <!-- define instances here -->
371            <instance../>
372        </instances>
373        <rules>
374            <!-- define rules here -->
375            <rule../>
376        </rules>
377        <lib>
378            <dict>
379                <!-- store custom data here -->
380            </dict>
381        </lib>
382    </designspace>
383
384.. 1-axis-element:
385
3861. axis element
387===============
388
389-  Define a single axis
390-  Child element of ``axes``
391
392.. attributes-2:
393
394Attributes
395----------
396
397-  ``name``: required, string. Name of the axis that is used in the
398   location elements.
399-  ``tag``: required, string, 4 letters. Some axis tags are registered
400   in the OpenType Specification.
401-  ``minimum``: required, number. The minimum value for this axis, in user space coordinates.
402-  ``maximum``: required, number. The maximum value for this axis, in user space coordinates.
403-  ``default``: required, number. The default value for this axis, in user space coordinates.
404-  ``hidden``: optional, 0 or 1. Records whether this axis needs to be
405   hidden in interfaces.
406
407.. code:: xml
408
409    <axis name="weight" tag="wght" minimum="1" maximum="1000" default="400">
410
411.. 11-labelname-element:
412
4131.1 labelname element
414=====================
415
416-  Defines a human readable name for UI use.
417-  Optional for non-registered axis names.
418-  Can be localised with ``xml:lang``
419-  Child element of ``axis``
420
421.. attributes-3:
422
423Attributes
424----------
425
426-  ``xml:lang``: required, string. `XML language
427   definition <https://www.w3.org/International/questions/qa-when-xmllang.en>`__
428
429Value
430-----
431
432-  The natural language name of this axis.
433
434.. example-2:
435
436Example
437-------
438
439.. code:: xml
440
441    <labelname xml:lang="fa-IR">قطر</labelname>
442    <labelname xml:lang="en">Wéíght</labelname>
443
444.. 12-map-element:
445
4461.2 map element
447===============
448
449-  Defines a single node in a series of input value (user space coordinate)
450   to output value (designspace coordinate) pairs.
451-  Together these values transform the designspace.
452-  Child of ``axis`` element.
453
454.. example-3:
455
456Example
457-------
458
459.. code:: xml
460
461    <map input="1.0" output="10.0" />
462    <map input="400.0" output="66.0" />
463    <map input="1000.0" output="990.0" />
464
465Example of all axis elements together:
466--------------------------------------
467
468.. code:: xml
469
470        <axes>
471            <axis default="1" maximum="1000" minimum="0" name="weight" tag="wght">
472                <labelname xml:lang="fa-IR">قطر</labelname>
473                <labelname xml:lang="en">Wéíght</labelname>
474            </axis>
475            <axis default="100" maximum="200" minimum="50" name="width" tag="wdth">
476                <map input="50.0" output="10.0" />
477                <map input="100.0" output="66.0" />
478                <map input="200.0" output="990.0" />
479            </axis>
480        </axes>
481
482.. 2-location-element:
483
4842. location element
485===================
486
487-  Defines a coordinate in the design space.
488-  Dictionary of axisname: axisvalue
489-  Used in ``source``, ``instance`` and ``glyph`` elements.
490
491.. 21-dimension-element:
492
4932.1 dimension element
494=====================
495
496-  Child element of ``location``
497
498.. attributes-4:
499
500Attributes
501----------
502
503-  ``name``: required, string. Name of the axis.
504-  ``xvalue``: required, number. The value on this axis.
505-  ``yvalue``: optional, number. Separate value for anisotropic
506   interpolations.
507
508.. example-4:
509
510Example
511-------
512
513.. code:: xml
514
515    <location>
516        <dimension name="width" xvalue="0.000000" />
517        <dimension name="weight" xvalue="0.000000" yvalue="0.003" />
518    </location>
519
520.. 3-source-element:
521
5223. source element
523=================
524
525-  Defines a single font or layer that contributes to the designspace.
526-  Child element of ``sources``
527-  Location in designspace coordinates.
528
529.. attributes-5:
530
531Attributes
532----------
533
534-  ``familyname``: optional, string. The family name of the source font.
535   While this could be extracted from the font data itself, it can be
536   more efficient to add it here.
537-  ``stylename``: optional, string. The style name of the source font.
538-  ``name``: required, string. A unique name that can be used to
539   identify this font if it needs to be referenced elsewhere.
540-  ``filename``: required, string. A path to the source file, relative
541   to the root path of this document. The path can be at the same level
542   as the document or lower.
543-  ``layer``: optional, string. The name of the layer in the source file.
544   If no layer attribute is given assume the foreground layer should be used.
545
546.. 31-lib-element:
547
5483.1 lib element
549===============
550
551There are two meanings for the ``lib`` element:
552
5531. Source lib
554    -  Example: ``<lib copy="1" />``
555    -  Child element of ``source``
556    -  Defines if the instances can inherit the data in the lib of this
557       source.
558    -  MutatorMath only
559
5602. Document and instance lib
561    - Example:
562
563      .. code:: xml
564
565        <lib>
566            <dict>
567                <key>...</key>
568                <string>The contents use the PLIST format.</string>
569            </dict>
570        </lib>
571
572    - Child element of ``designspace`` and ``instance``
573    - Contains arbitrary data about the whole document or about a specific
574      instance.
575    - Items in the dict need to use **reverse domain name notation** <https://en.wikipedia.org/wiki/Reverse_domain_name_notation>__
576
577.. 32-info-element:
578
5793.2 info element
580================
581
582-  ``<info copy="1" />``
583-  Child element of ``source``
584-  Defines if the instances can inherit the non-interpolating font info
585   from this source.
586-  MutatorMath
587
588.. 33-features-element:
589
5903.3 features element
591====================
592
593-  ``<features copy="1" />``
594-  Defines if the instances can inherit opentype feature text from this
595   source.
596-  Child element of ``source``
597-  MutatorMath only
598
599.. 34-glyph-element:
600
6013.4 glyph element
602=================
603
604-  Can appear in ``source`` as well as in ``instance`` elements.
605-  In a ``source`` element this states if a glyph is to be excluded from
606   the calculation.
607-  MutatorMath only
608
609.. attributes-6:
610
611Attributes
612----------
613
614-  ``mute``: optional attribute, number 1 or 0. Indicate if this glyph
615   should be ignored as a master.
616-  ``<glyph mute="1" name="A"/>``
617-  MutatorMath only
618
619.. 35-kerning-element:
620
6213.5 kerning element
622===================
623
624-  ``<kerning mute="1" />``
625-  Can appear in ``source`` as well as in ``instance`` elements.
626
627.. attributes-7:
628
629Attributes
630----------
631
632-  ``mute``: required attribute, number 1 or 0. Indicate if the kerning
633   data from this source is to be excluded from the calculation.
634-  If the kerning element is not present, assume ``mute=0``, yes,
635   include the kerning of this source in the calculation.
636-  MutatorMath only
637
638.. example-5:
639
640Example
641-------
642
643.. code:: xml
644
645    <source familyname="MasterFamilyName" filename="masters/masterTest1.ufo" name="master.ufo1" stylename="MasterStyleNameOne">
646        <lib copy="1" />
647        <features copy="1" />
648        <info copy="1" />
649        <glyph mute="1" name="A" />
650        <glyph mute="1" name="Z" />
651        <location>
652            <dimension name="width" xvalue="0.000000" />
653            <dimension name="weight" xvalue="0.000000" />
654        </location>
655    </source>
656
657.. 4-instance-element:
658
6594. instance element
660===================
661
662-  Defines a single font that can be calculated with the designspace.
663-  Child element of ``instances``
664-  For use in Varlib the instance element really only needs the names
665   and the location. The ``glyphs`` element is not required.
666-  MutatorMath uses the ``glyphs`` element to describe how certain
667   glyphs need different masters, mainly to describe the effects of
668   conditional rules in Superpolator.
669-  Location in designspace coordinates.
670
671.. attributes-8:
672
673Attributes
674----------
675
676-  ``familyname``: required, string. The family name of the instance
677   font. Corresponds with ``font.info.familyName``
678-  ``stylename``: required, string. The style name of the instance font.
679   Corresponds with ``font.info.styleName``
680-  ``name``: required, string. A unique name that can be used to
681   identify this font if it needs to be referenced elsewhere.
682-  ``filename``: string. Required for MutatorMath. A path to the
683   instance file, relative to the root path of this document. The path
684   can be at the same level as the document or lower.
685-  ``postscriptfontname``: string. Optional for MutatorMath. Corresponds
686   with ``font.info.postscriptFontName``
687-  ``stylemapfamilyname``: string. Optional for MutatorMath. Corresponds
688   with ``styleMapFamilyName``
689-  ``stylemapstylename``: string. Optional for MutatorMath. Corresponds
690   with ``styleMapStyleName``
691
692Example for varlib
693------------------
694
695.. code:: xml
696
697    <instance familyname="InstanceFamilyName" filename="instances/instanceTest2.ufo" name="instance.ufo2" postscriptfontname="InstancePostscriptName" stylemapfamilyname="InstanceStyleMapFamilyName" stylemapstylename="InstanceStyleMapStyleName" stylename="InstanceStyleName">
698    <location>
699        <dimension name="width" xvalue="400" yvalue="300" />
700        <dimension name="weight" xvalue="66" />
701    </location>
702    <kerning />
703    <info />
704    <lib>
705        <dict>
706            <key>com.coolDesignspaceApp.specimenText</key>
707            <string>Hamburgerwhatever</string>
708        </dict>
709    </lib>
710    </instance>
711
712.. 41-glyphs-element:
713
7144.1 glyphs element
715==================
716
717-  Container for ``glyph`` elements.
718-  Optional
719-  MutatorMath only.
720
721.. 42-glyph-element:
722
7234.2 glyph element
724=================
725
726-  Child element of ``glyphs``
727-  May contain a ``location`` element.
728
729.. attributes-9:
730
731Attributes
732----------
733
734-  ``name``: string. The name of the glyph.
735-  ``unicode``: string. Unicode values for this glyph, in hexadecimal.
736   Multiple values should be separated with a space.
737-  ``mute``: optional attribute, number 1 or 0. Indicate if this glyph
738   should be supressed in the output.
739
740.. 421-note-element:
741
7424.2.1 note element
743==================
744
745-  String. The value corresponds to glyph.note in UFO.
746
747.. 422-masters-element:
748
7494.2.2 masters element
750=====================
751
752-  Container for ``master`` elements
753-  These ``master`` elements define an alternative set of glyph masters
754   for this glyph.
755
756.. 4221-master-element:
757
7584.2.2.1 master element
759======================
760
761-  Defines a single alternative master for this glyph.
762
7634.3 Localised names for instances
764=================================
765
766Localised names for instances can be included with these simple elements
767with an ``xml:lang`` attribute:
768`XML language definition <https://www.w3.org/International/questions/qa-when-xmllang.en>`__
769
770-  stylename
771-  familyname
772-  stylemapstylename
773-  stylemapfamilyname
774
775.. example-6:
776
777Example
778-------
779
780.. code:: xml
781
782    <stylename xml:lang="fr">Demigras</stylename>
783    <stylename xml:lang="ja">半ば</stylename>
784    <familyname xml:lang="fr">Montserrat</familyname>
785    <familyname xml:lang="ja">モンセラート</familyname>
786    <stylemapstylename xml:lang="de">Standard</stylemapstylename>
787    <stylemapfamilyname xml:lang="de">Montserrat Halbfett</stylemapfamilyname>
788    <stylemapfamilyname xml:lang="ja">モンセラート SemiBold</stylemapfamilyname>
789
790.. attributes-10:
791
792Attributes
793----------
794
795-  ``glyphname``: the name of the alternate master glyph.
796-  ``source``: the identifier name of the source this master glyph needs
797   to be loaded from
798
799.. example-7:
800
801Example
802-------
803
804.. code:: xml
805
806    <instance familyname="InstanceFamilyName" filename="instances/instanceTest2.ufo" name="instance.ufo2" postscriptfontname="InstancePostscriptName" stylemapfamilyname="InstanceStyleMapFamilyName" stylemapstylename="InstanceStyleMapStyleName" stylename="InstanceStyleName">
807    <location>
808        <dimension name="width" xvalue="400" yvalue="300" />
809        <dimension name="weight" xvalue="66" />
810    </location>
811    <glyphs>
812        <glyph name="arrow2" />
813        <glyph name="arrow" unicode="0x4d2 0x4d3">
814        <location>
815            <dimension name="width" xvalue="100" />
816            <dimension name="weight" xvalue="120" />
817        </location>
818        <note>A note about this glyph</note>
819        <masters>
820            <master glyphname="BB" source="master.ufo1">
821            <location>
822                <dimension name="width" xvalue="20" />
823                <dimension name="weight" xvalue="20" />
824            </location>
825            </master>
826        </masters>
827        </glyph>
828    </glyphs>
829    <kerning />
830    <info />
831    <lib>
832        <dict>
833            <key>com.coolDesignspaceApp.specimenText</key>
834            <string>Hamburgerwhatever</string>
835        </dict>
836    </lib>
837    </instance>
838
839.. 50-rules-element:
840
8415.0 rules element
842=================
843
844-  Container for ``rule`` elements
845-  The rules are evaluated in this order.
846
847Rules describe designspace areas in which one glyph should be replaced by another.
848A rule has a name and a number of conditionsets. The rule also contains a list of
849glyphname pairs: the glyphs that need to be substituted. For a rule to be triggered
850**only one** of the conditionsets needs to be true, ``OR``. Within a conditionset
851**all** conditions need to be true, ``AND``.
852
853.. attributes-11:
854
855Attributes
856----------
857
858-  ``processing``: flag, optional. Valid values are [``first``, ``last``]. This flag indicates whether the substitution rules should be applied before or after other glyph substitution features.
859-  If no ``processing`` attribute is given, interpret as ``first``, and put the substitution rule in the `rvrn` feature.
860-  If ``processing`` is ``last``, put it in `rclt`.
861
862.. 51-rule-element:
863
8645.1 rule element
865================
866
867-  Defines a named rule.
868-  Each ``rule`` element contains one or more ``conditionset`` elements.
869-  **Only one** ``conditionset`` needs to be true to trigger the rule.
870-  **All** conditions in a ``conditionset`` must be true to make the ``conditionset`` true.
871-  For backwards compatibility a ``rule`` can contain ``condition`` elements outside of a conditionset. These are then understood to be part of a single, implied, ``conditionset``. Note: these conditions should be written wrapped in a conditionset.
872-  A rule element needs to contain one or more ``sub`` elements in order to be compiled to a variable font.
873-  Rules without sub elements should be ignored when compiling a font.
874-  For authoring tools it might be necessary to save designspace files without ``sub`` elements just because the work is incomplete.
875
876.. attributes-11:
877
878Attributes
879----------
880
881-  ``name``: optional, string. A unique name that can be used to
882   identify this rule if it needs to be referenced elsewhere. The name
883   is not important for compiling variable fonts.
884
8855.1.1 conditionset element
886=======================
887
888-  Child element of ``rule``
889-  Contains one or more ``condition`` elements.
890
891.. 512-condition-element:
892
8935.1.2 condition element
894=======================
895
896-  Child element of ``conditionset``
897-  Between the ``minimum`` and ``maximum`` this condition is ``True``.
898-  ``minimum`` and ``maximum`` are in designspace coordinates.
899-  If ``minimum`` is not available, assume it is ``axis.minimum``, mapped to designspace coordinates.
900-  If ``maximum`` is not available, assume it is ``axis.maximum``, mapped to designspace coordinates.
901-  The condition must contain at least a minimum or maximum or both.
902
903.. attributes-12:
904
905Attributes
906----------
907
908-  ``name``: string, required. Must match one of the defined ``axis``
909   name attributes.
910-  ``minimum``: number, required*. The low value, in designspace coordinates.
911-  ``maximum``: number, required*. The high value, in designspace coordinates.
912
913.. 513-sub-element:
914
9155.1.3 sub element
916=================
917
918-  Child element of ``rule``.
919-  Defines which glyph to replace when the rule evaluates to **True**.
920-  The ``sub`` element contains a pair of glyphnames. The ``name`` attribute is the glyph that should be visible when the rule evaluates to **False**. The ``with`` attribute is the glyph that should be visible when the rule evaluates to **True**.
921
922Axis values in Conditions are in designspace coordinates.
923
924.. attributes-13:
925
926Attributes
927----------
928
929-  ``name``: string, required. The name of the glyph this rule looks
930   for.
931-  ``with``: string, required. The name of the glyph it is replaced
932   with.
933
934.. example-8:
935
936Example
937-------
938
939Example with an implied ``conditionset``. Here the conditions are not
940contained in a conditionset.
941
942.. code:: xml
943
944    <rules processing="last">
945        <rule name="named.rule.1">
946            <condition minimum="250" maximum="750" name="weight" />
947            <condition minimum="50" maximum="100" name="width" />
948            <sub name="dollar" with="dollar.alt"/>
949        </rule>
950    </rules>
951
952Example with ``conditionsets``. All conditions in a conditionset must be true.
953
954.. code:: xml
955
956    <rules>
957        <rule name="named.rule.2">
958            <conditionset>
959                <condition minimum="250" maximum="750" name="weight" />
960                <condition minimum="50" maximum="100" name="width" />
961            </conditionset>
962            <conditionset>
963                <condition ... />
964                <condition ... />
965            </conditionset>
966            <sub name="dollar" with="dollar.alt"/>
967        </rule>
968    </rules>
969
970.. 6-notes:
971
9726 Notes
973=======
974
975Paths and filenames
976-------------------
977
978A designspace file needs to store many references to UFO files.
979
980-  designspace files can be part of versioning systems and appear on
981   different computers. This means it is not possible to store absolute
982   paths.
983-  So, all paths are relative to the designspace document path.
984-  Using relative paths allows designspace files and UFO files to be
985   **near** each other, and that they can be **found** without enforcing
986   one particular structure.
987-  The **filename** attribute in the ``SourceDescriptor`` and
988   ``InstanceDescriptor`` classes stores the preferred relative path.
989-  The **path** attribute in these objects stores the absolute path. It
990   is calculated from the document path and the relative path in the
991   filename attribute when the object is created.
992-  Only the **filename** attribute is written to file.
993-  Both **filename** and **path** must use forward slashes (``/``) as
994   path separators, even on Windows.
995
996Right before we save we need to identify and respond to the following
997situations:
998
999In each descriptor, we have to do the right thing for the filename
1000attribute. Before writing to file, the ``documentObject.updatePaths()``
1001method prepares the paths as follows:
1002
1003**Case 1**
1004
1005::
1006
1007    descriptor.filename == None
1008    descriptor.path == None
1009
1010**Action**
1011
1012-  write as is, descriptors will not have a filename attr. Useless, but
1013   no reason to interfere.
1014
1015**Case 2**
1016
1017::
1018
1019    descriptor.filename == "../something"
1020    descriptor.path == None
1021
1022**Action**
1023
1024-  write as is. The filename attr should not be touched.
1025
1026**Case 3**
1027
1028::
1029
1030    descriptor.filename == None
1031    descriptor.path == "~/absolute/path/there"
1032
1033**Action**
1034
1035-  calculate the relative path for filename. We're not overwriting some
1036   other value for filename, it should be fine.
1037
1038**Case 4**
1039
1040::
1041
1042    descriptor.filename == '../somewhere'
1043    descriptor.path == "~/absolute/path/there"
1044
1045**Action**
1046
1047-  There is a conflict between the given filename, and the path. The
1048   difference could have happened for any number of reasons. Assuming
1049   the values were not in conflict when the object was created, either
1050   could have changed. We can't guess.
1051-  Assume the path attribute is more up to date. Calculate a new value
1052   for filename based on the path and the document path.
1053
1054Recommendation for editors
1055--------------------------
1056
1057-  If you want to explicitly set the **filename** attribute, leave the
1058   path attribute empty.
1059-  If you want to explicitly set the **path** attribute, leave the
1060   filename attribute empty. It will be recalculated.
1061-  Use ``documentObject.updateFilenameFromPath()`` to explicitly set the
1062   **filename** attributes for all instance and source descriptors.
1063
1064.. 7-common-lib-key-registry:
1065
10667 Common Lib Key Registry
1067=========================
1068
1069public.skipExportGlyphs
1070-----------------------
1071
1072This lib key works the same as the UFO lib key with the same name. The
1073difference is that applications using a Designspace as the corner stone of the
1074font compilation process should use the lib key in that Designspace instead of
1075any of the UFOs. If the lib key is empty or not present in the Designspace, all
1076glyphs should be exported, regardless of what the same lib key in any of the
1077UFOs says.
1078
1079.. 8-implementation-and-differences:
1080
1081
10828 Implementation and differences
1083================================
1084
1085The designspace format has gone through considerable development.
1086
1087 -  the format was originally written for MutatorMath.
1088 -  the format is now also used in fontTools.varlib.
1089 -  not all values are be required by all implementations.
1090
10918.1 Varlib vs. MutatorMath
1092--------------------------
1093
1094There are some differences between the way MutatorMath and fontTools.varlib handle designspaces.
1095
1096 -  Varlib does not support anisotropic interpolations.
1097 -  MutatorMath will extrapolate over the boundaries of
1098    the axes. Varlib can not (at the moment).
1099 -  Varlib requires much less data to define an instance than
1100    MutatorMath.
1101 -  The goals of Varlib and MutatorMath are different, so not all
1102    attributes are always needed.
1103
11048.2 Older versions
1105------------------
1106
1107-  In some implementations that preceed Variable Fonts, the `copyInfo`
1108   flag in a source indicated the source was to be treated as the default.
1109   This is no longer compatible with the assumption that the default font
1110   is located on the default value of each axis.
1111-  Older implementations did not require axis records to be present in
1112   the designspace file. The axis extremes for instance were generated
1113   from the locations used in the sources. This is no longer possible.
1114
11158.3 Rules and generating static UFO instances
1116---------------------------------------------
1117
1118When making instances as UFOs from a designspace with rules, it can
1119be useful to evaluate the rules so that the characterset of the ufo
1120reflects, as much as possible, the state of a variable font when seen
1121at the same location. This can be done by some swapping and renaming of
1122glyphs.
1123
1124While useful for proofing or development work, it should be noted that
1125swapping and renaming leaves the UFOs with glyphnames that are no longer
1126descriptive. For instance, after a swap `dollar.bar` could contain a shape
1127without a bar. Also, when the swapped glyphs are part of other GSUB variations
1128it can become complex very quickly. So proceed with caution.
1129
1130 -  Assuming `rulesProcessingLast = True`:
1131 -  We need to swap the glyphs so that the original shape is still available.
1132    For instance, if a rule swaps ``a`` for ``a.alt``, a glyph
1133    that references ``a`` in a component would then show the new ``a.alt``.
1134 -  But that can lead to unexpected results, the two glyphs may have different
1135    widths or height. So, glyphs that are not specifically referenced in a rule
1136    **should not change appearance**. That means that the implementation that swaps
1137    ``a`` and ``a.alt`` also swap all components that reference these
1138    glyphs in order to preserve their appearance.
1139 -  The swap function also needs to take care of swapping the names in
1140    kerning data and any GPOS code.
1141
1142
1143.. 9-this-document
1144
11459 This document
1146===============
1147
1148-  Changes are to be expected.
1149
1150
1151