
    h                      S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
Jr  SSKJr  SSKJrJrJrJrJrJrJrJr  SSKJr  SSKJr  SS	KJr  SS
KJrJr  / SQr Sr!\!S-   r"S r#S r$ " S S\%5      r& " S S\'5      r( " S S\(5      r) " S S\)5      r* " S S\)5      r+S r,S r-S r.\\/\\0\\0\04   4   4   r1\\/\04   r2 " S S\)5      r3 " S S \)5      r4S! r5 " S" S#\)5      r6 " S$ S%\65      r7 " S& S'\65      r8 " S( S)\)5      r9 " S* S+\)5      r: " S, S-\)5      r; " S. S/\)5      r< " S0 S1\)5      r= " S2 S3\'5      r> " S4 S5\5      r? " S6 S7\\(5      r@S9S8 jrAg):z9
designSpaceDocument

- Read and write designspace files
    )annotationsN)BytesIOStringIO)indent)AnyDictListMutableMappingOptionalTupleUnioncast)etree)plistlib)LogMixin)tobytestostr)AxisDescriptorAxisLabelDescriptorAxisMappingDescriptorBaseDocReaderBaseDocWriterDesignSpaceDocumentDesignSpaceDocumentErrorDiscreteAxisDescriptorInstanceDescriptorLocationLabelDescriptorRangeAxisSubsetDescriptorRuleDescriptorSourceDescriptorValueAxisSubsetDescriptorVariableFontDescriptorz&{http://www.w3.org/XML/1998/namespace}langc                    [         R                  " U R                  [        R                  R
                  5      6 nU R                  S5      (       a  SU-   nU$ U R                  S5      (       a  SU-   nU$ )z<Normalize paths using forward slash to work also on Windows./z\\z//)	posixpathjoinsplitospathsep
startswith)r*   new_paths     S/var/www/html/env/lib/python3.13/site-packages/fontTools/designspaceLib/__init__.pyposixr/   1   s_    ~~tzz"''++67Hs> O 
		(?O    c                2   ^  U 4S jnU 4S jn[        X5      $ )zBGenerate a propery that holds a path always using forward slashes.c                   > [        U T5      $ N)getattr)selfprivate_names    r.   getter"posixpath_property.<locals>.getter@   s    t\**r0   c                <   > Ub  [        U5      n[        U TU5        g r3   )r/   setattr)r5   valuer6   s     r.   setter"posixpath_property.<locals>.setterD   s    %LElE*r0   )property)r6   r7   r<   s   `  r.   posixpath_propertyr?   =   s    ++ F##r0   c                  $    \ rS rSrSS jrS rSrg)r   M   Nc                    Xl         X l        g r3   msgobj)r5   rD   rE   s      r.   __init__!DesignSpaceDocumentError.__init__N   s    r0   c                n    [        U R                  5      U R                  b  SU R                  -  -   $ S-   $ )Nz: %r )strrD   rE   r5   s    r.   __str__ DesignSpaceDocumentError.__str__R   s/    488}TXX5I 1RRrRRr0   rC   r3   )__name__
__module____qualname____firstlineno__rF   rL   __static_attributes__ r0   r.   r   r   M   s    Sr0   r   c                      \ rS rSrS rSrg)AsDictMixinV   c                f   0 nU R                   R                  5        H  u  p#UR                  S5      (       a  M  [        US5      (       a  UR	                  5       nOH[        U[        5      (       a3  U Vs/ s H&  n[        US5      (       a  UR	                  5       OUPM(     nnX1U'   M     U$ s  snf )N_asdict)__dict__itemsr,   hasattrrY   
isinstancelist)r5   dattrr;   vs        r.   rY   AsDictMixin.asdictW   s    ==..0KDs##uh''E4((LQREqwq(';';BERdG 1  Ss   5-B.rS   N)rN   rO   rP   rQ   rY   rR   rS   r0   r.   rU   rU   V   s    
r0   rU   c                  $    \ rS rSrSrS rS rSrg)SimpleDescriptord   z$Containers for a bunch of attributesc                    U R                    H  n [        X5      [        X5      :X  d   eM      g ! [         a%    [        SU[        X5      S[        X5      5         MQ  f = f)Nzfailed attributez!=)_attrsr4   AssertionErrorprint)r5   otherr`   s      r.   compareSimpleDescriptor.comparei   s_    KKD	t*ge.BBBB   " &D'E(s   0+AAc                    U R                    Vs/ s H  o S[        [        X5      5       S3PM     nn[        SR	                  U5      S5      nU R
                  R                   SU S3$ s  snf )N=,
    z(
z
))rg   reprr4   r   r'   	__class__rN   )r5   aattrss      r.   __repr__SimpleDescriptor.__repr__w   si    ;?;;G;a3aWT-./q1;Gtyy'0..))*#eWC88 Hs   #A+rS   N)rN   rO   rP   rQ   __doc__rk   rv   rR   rS   r0   r.   rd   rd   d   s    .9r0   rd   c                      \ rS rSrSrSr/ SQr\" S5      r\" S5      r	SSSSSSSSSSSSSSSSSS	.S
 jr
\S 5       r\R                  SS j5       rSS jrSS jrSS jrSrg)r    }   u  Simple container for data related to the source

.. code:: python

    doc = DesignSpaceDocument()
    s1 = SourceDescriptor()
    s1.path = masterPath1
    s1.name = "master.ufo1"
    s1.font = defcon.Font("master.ufo1")
    s1.location = dict(weight=0)
    s1.familyName = "MasterFamilyName"
    s1.styleName = "MasterStyleNameOne"
    s1.localisedFamilyName = dict(fr="Caractère")
    s1.mutedGlyphNames.append("A")
    s1.mutedGlyphNames.append("Z")
    doc.addSource(s1)

source)filenamer*   name	layerNamelocationcopyLib
copyGroupscopyFeaturesmuteKerningmuteInfomutedGlyphNames
familyName	styleNamelocalisedFamilyName	_filename_pathNF)r|   r*   fontr}   r   designLocationr~   r   r   r   r   copyInfor   r   r   r   r   c               *   Xl          X l         X0l         X@l         Ub  UO
U=(       d    0 U l         Xpl         Xl         Xl         U
=(       d    0 U l         Xl	         Xl
         Xl         Xl         Xl         UU l         U=(       d    / U l        g r3   )r|   r*   r   r}   r   r~   r   r   r   r   r   r   r   r   r   r   )r5   r|   r*   r   r}   r   r   r~   r   r   r   r   r   r   r   r   r   r   s                     r.   rF   SourceDescriptor.__init__   s    * !	 	:			 		 -8Nhn" 		 #	 %	 #	 $7#<" 	 	 !	 %	 )	 '	
 !	
  /4"	r0   c                    U R                   $ )zdict. Axis values for this source, in design space coordinates.

MutatorMath + varLib.

.. deprecated:: 5.0
   Use the more explicit alias for this property :attr:`designLocation`.
r   rK   s    r.   r   SourceDescriptor.location0       """r0   c                $    U=(       d    0 U l         g r3   r   r5   r   s     r.   r   r   ;      &n"r0   c                4    [        U5      U R                  U'   g)z>Setter for :attr:`localisedFamilyName`

.. versionadded:: 5.0
Nr   r   r5   r   languageCodes      r.   setFamilyNameSourceDescriptor.setFamilyName?  s    
 27z1B  .r0   c                8    U R                   R                  U5      $ )z>Getter for :attr:`localisedFamilyName`

.. versionadded:: 5.0
r   getr5   r   s     r.   getFamilyNameSourceDescriptor.getFamilyNameF  s    
 ''++L99r0   c                    0 nUR                    Hk  nUR                  U R                  ;   a'  U R                  UR                     X#R                  '   MD  UR                  UR                  5      X#R                  '   Mm     U$ )zGet the complete design location of this source, from its
:attr:`designLocation` and the document's axis defaults.

.. versionadded:: 5.0
)axesr}   r   map_forwarddefault)r5   docresultaxiss       r.   getFullDesignLocation&SourceDescriptor.getFullDesignLocationM  sf     &(HHDyyD///$($7$7		$Byy!$($4$4T\\$Byy!	 
 r0   )r   r   r   r   r   r   r|   r   r~   r   r   r   r   r}   r*   r   )r   zOptional[SimpleLocationDict]enr   'DesignSpaceDocument'returnSimpleLocationDict)rN   rO   rP   rQ   rx   flavorrg   r?   r|   r*   rF   r>   r   r<   r   r   r   rR   rS   r0   r.   r    r    }   s    & FF" "+.Hg&D
  'HT # # __- -C:r0   r    c                  2    \ rS rSrSr/ SQrSSSS.S jrSrg)r   i\  aw  Represents the rule descriptor element: a set of glyph substitutions to
trigger conditionally in some parts of the designspace.

.. code:: python

    r1 = RuleDescriptor()
    r1.name = "unique.rule.name"
    r1.conditionSets.append([dict(name="weight", minimum=-10, maximum=10), dict(...)])
    r1.conditionSets.append([dict(...), dict(...)])
    r1.subs.append(("a", "a.alt"))

.. code:: xml

    <!-- 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>
r}   conditionSetssubsNc               T    Xl          U=(       d    / U l         U=(       d    / U l        g r3   r   )r5   r}   r   r   s       r.   rF   RuleDescriptor.__init__z  s.    	Y*0b	 JB		r0   )r   r}   r   rN   rO   rP   rQ   rx   rg   rF   rR   rS   r0   r.   r   r   \  s    6 /F#4d  r0   r   c                B   ^ [        U4S jU R                   5       5      $ )zJReturn True if any of the rule's conditionsets matches the given location.c              3  <   >#    U  H  n[        UT5      v   M     g 7fr3   )evaluateConditions).0cr   s     r.   	<genexpr>evaluateRule.<locals>.<genexpr>  s     K8J1!!X..8Js   )anyr   )ruler   s    `r.   evaluateRuler     s    K8J8JKKKr0   c                    U  H`  nXS      nUR                  S5      c  X2S   :  a    gM(  UR                  S5      c  US   U:  a    gMG  US   Us=::  a  US   ::  a  M\     g    g   g)zReturn True if all the conditions matches the given location.

- If a condition has no minimum, check for < maximum.
- If a condition has no maximum, check for > minimum.
r}   minimummaximumFT)r   )
conditionsr   cdr;   s       r.   r   r     s     F$66)$)}$ %VVI&)}u$ %I%82i=8 9  r0   c                    / nU  Hm  n[        XA5      (       d  M  U HN  nSnUR                   H  u  pxXW:X  d  M  Sn  O   U(       a  UR                  W5        M=  UR                  U5        MP     Un/ nMo     U$ )zApply these rules at this location to these glyphnames.

Return a new list of glyphNames with substitutions applied.

- rule order matters
FT)r   r   append)	rulesr   
glyphNamesnewNamesr   r}   swaprt   bs	            r.   processRulesr     s{     H''" IIDAy# & OOA&OOD) # "JH  r0   c                  4    \ rS rSrSrSS/rSSSSS.S jrSrg)	r   i  aI  Represents the axis mapping element: mapping an input location
to an output location in the designspace.

.. code:: python

    m1 = AxisMappingDescriptor()
    m1.inputLocation = {"weight": 900, "width": 150}
    m1.outputLocation = {"weight": 870}

.. code:: xml

    <mappings>
        <mapping>
            <input>
                <dimension name="weight" xvalue="900"/>
                <dimension name="width" xvalue="150"/>
            </input>
            <output>
                <dimension name="weight" xvalue="870"/>
            </output>
        </mapping>
    </mappings>
inputLocationoutputLocationNr   r   descriptiongroupDescriptionc               b    U=(       d    0 U l          U=(       d    0 U l         X0l         X@l        g r3   r   )r5   r   r   r   r   s        r.   rF   AxisMappingDescriptor.__init__  sE     2?1D"	 3A2FB	 '	 !1	r0   )r   r   r   r   r   rS   r0   r.   r   r     s,    0 /0F
 # #r0   r   c                  B   \ rS rSrSrSrSr/ SQr\" S5      r	\" S5      r
SSSSSSSSSSSSSSSSSSS	S	SS
.S jr\S 5       r\R                  SS j5       rSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSSS jjr    SS jr    S S jrS!S jrSrg)"r   i  aH  Simple container for data related to the instance


.. code:: python

    i2 = InstanceDescriptor()
    i2.path = instancePath2
    i2.familyName = "InstanceFamilyName"
    i2.styleName = "InstanceStyleName"
    i2.name = "instance.ufo2"
    # anisotropic location
    i2.designLocation = dict(weight=500, width=(400,300))
    i2.postScriptFontName = "InstancePostscriptName"
    i2.styleMapFamilyName = "InstanceStyleMapFamilyName"
    i2.styleMapStyleName = "InstanceStyleMapStyleName"
    i2.lib['com.coolDesignspaceApp.specimenText'] = 'Hamburgerwhatever'
    doc.addInstance(i2)
instancer   )r|   r*   r}   locationLabelr   userLocationr   r   postScriptFontNamestyleMapFamilyNamestyleMapStyleNamer   localisedStyleNamelocalisedStyleMapFamilyNamelocalisedStyleMapStyleNameglyphskerninginfolibr   r   NT)r|   r*   r   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   c                  Xl          X l         X0l         X@l         X`l         Ub  UO
U=(       d    0 U l         U=(       d    0 U l         Xl         Xl         Xl	         Xl
         Xl         U=(       d    0 U l         U=(       d    0 U l         U=(       d    0 U l         U=(       d    0 U l         U=(       d    0 U l         UU l         UU l         U=(       d    0 U l        g r3   )r|   r*   r   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r5   r|   r*   r   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s                         r.   rF   InstanceDescriptor.__init__5  s?   2 !	
 		 		 		 +		 -8Nx~2 			 1=0B		 %	 #	 #5	 #5	 "3	 $7#<" 	 #5":	 ,G+L"(	 +E*J'	 l	 	 		 9"8r0   c                    U R                   $ )zdict. Axis values for this instance.

MutatorMath + varLib.

.. deprecated:: 5.0
   Use the more explicit alias for this property :attr:`designLocation`.
r   rK   s    r.   r   InstanceDescriptor.location  r   r0   c                $    U=(       d    0 U l         g r3   r   r   s     r.   r   r     r   r0   c                4    [        U5      U R                  U'   g)z8These methods give easier access to the localised names.N)r   r   )r5   r   r   s      r.   setStyleNameInstanceDescriptor.setStyleName  s    05i0@-r0   c                8    U R                   R                  U5      $ r3   )r   r   r   s     r.   getStyleNameInstanceDescriptor.getStyleName  s    &&**<88r0   c                4    [        U5      U R                  U'   g r3   r   r   s      r.   r    InstanceDescriptor.setFamilyName  s    16z1B  .r0   c                8    U R                   R                  U5      $ r3   r   r   s     r.   r    InstanceDescriptor.getFamilyName  s    ''++L99r0   c                4    [        U5      U R                  U'   g r3   )r   r   )r5   r   r   s      r.   setStyleMapStyleName'InstanceDescriptor.setStyleMapStyleName  s    8=>O8P''5r0   c                8    U R                   R                  U5      $ r3   )r   r   r   s     r.   getStyleMapStyleName'InstanceDescriptor.getStyleMapStyleName  s    ..22<@@r0   c                4    [        U5      U R                  U'   g r3   )r   r   )r5   r   r   s      r.   setStyleMapFamilyName(InstanceDescriptor.setStyleMapFamilyName  s    9>?Q9R((6r0   c                8    U R                   R                  U5      $ r3   )r   r   r   s     r.   getStyleMapFamilyName(InstanceDescriptor.getStyleMapFamilyName  s    //33LAAr0   c                    SU l         Uc  0 U l        0 U l        gU R                  c  0 U l        XR                  ;   a  U R                  U	 U R                  c  0 U l        XR                  ;   a  U R                  U	 gg)a  Clear all location-related fields. Ensures that
:attr:``designLocation`` and :attr:``userLocation`` are dictionaries
(possibly empty if clearing everything).

In order to update the location of this instance wholesale, a user
should first clear all the fields, then change the field(s) for which
they have data.

.. code:: python

    instance.clearLocation()
    instance.designLocation = {'Weight': (34, 36.5), 'Width': 100}
    instance.userLocation = {'Opsz': 16}

In order to update a single axis location, the user should only clear
that axis, then edit the values:

.. code:: python

    instance.clearLocation('Weight')
    instance.designLocation['Weight'] = (34, 36.5)

Args:
  axisName: if provided, only clear the location for that axis.

.. versionadded:: 5.0
N)r   r   r   )r5   axisNames     r.   clearLocation InstanceDescriptor.clearLocation  s    8 ""$D "D""*&(#...''1  ($&!,,,%%h/ -r0   c                    U R                   c  gUR                  U R                   5      nUc&  [        SU R                    SU R                   S35      eU$ )zGet the :class:`LocationLabelDescriptor` instance that matches
this instances's :attr:`locationLabel`.

Raises if the named label can't be found.

.. versionadded:: 5.0
NzIInstanceDescriptor.getLocationLabelDescriptor(): unknown location label `z` in instance `z`.)r   getLocationLabelr   r}   )r5   r   labels      r.   getLocationLabelDescriptor-InstanceDescriptor.getLocationLabelDescriptor  sf     %$$T%7%78=*++/+=+=*>odii[XZ\  r0   c                   U R                  U5      nUb  UR                  UR                  5      $ 0 nUR                   H  nUR                  U R
                  ;   a'  U R
                  UR                     X4R                  '   MD  UR                  U R                  ;   a6  UR                  U R                  UR                     5      X4R                  '   M  UR                  UR                  5      X4R                  '   M     U$ )a  Get the complete design location of this instance, by combining data
from the various location fields, default axis values and mappings, and
top-level location labels.

The source of truth for this instance's location is determined for each
axis independently by taking the first not-None field in this list:

- ``locationLabel``: the location along this axis is the same as the
  matching STAT format 4 label. No anisotropy.
- ``designLocation[axisName]``: the explicit design location along this
  axis, possibly anisotropic.
- ``userLocation[axisName]``: the explicit user location along this
  axis. No anisotropy.
- ``axis.default``: default axis value. No anisotropy.

.. versionadded:: 5.0
)r	  r   r   r   r}   r   r   )r5   r   r  r   r   s        r.   r   (InstanceDescriptor.getFullDesignLocation3  s    ( //4??5#5#566*,HHDyyD///$($7$7		$Byy!d///$($4$4T5F5Ftyy5Q$Ryy!$($4$4T\\$Byy!  r0   c                B    UR                  U R                  U5      5      $ )zuGet the complete user location for this instance.

.. seealso:: :meth:`getFullDesignLocation`

.. versionadded:: 5.0
)map_backwardr   )r5   r   s     r.   getFullUserLocation&InstanceDescriptor.getFullUserLocationT  s       : :3 ?@@r0   )r   r   r|   r   r   r   r   r   r   r   r   r   r   r}   r*   r   r   r   r   r   )r   z!Optional[AnisotropicLocationDict]r   r3   )r  zOptional[str])r   r   r   !Optional[LocationLabelDescriptor])r   r   r   AnisotropicLocationDictr   )rN   rO   rP   rQ   rx   r   _defaultLanguageCoderg   r?   r|   r*   rF   r>   r   r<   r   r   r   r   r   r   r   r   r  r	  r   r  rR   rS   r0   r.   r   r     s
   & FF, "+.Hg&D
  $(#'/V9p # # __- -A9C:QASB(0T(	*((	 BAr0   r   c           	         S[        SS94S[        SS94S[        SS94S[        S	S94S
[        SS94S.nU R                  5       U;   a  XR                  5          $ [        U 5      S:  a  U SS[        U 5      -
  -  -   nOU S S nU[        U S94$ )NwghtWeightr   wdthWidthopszzOptical SizeslntSlantitalItalic)weightwidthopticalslantitalic   *)dictlowerlen)r}   namestags      r.   tagForAxisNamer*  ^  s     48,-$'*+DN34$'*+48,-E zz|uZZ\""
4y1}SAD	M**2Ahr0   c                  2    \ rS rSrSrSSSSSSSS.S jrSrg)AbstractAxisDescriptorip  r   NFr)  r}   
labelNameshiddenmapaxisOrdering
axisLabelsc                   Xl          X l         U=(       d    0 U l         X@l         U=(       d    / U l         X`l         U=(       d    / U l        g r3   r-  )r5   r)  r}   r.  r/  r0  r1  r2  s           r.   rF   AbstractAxisDescriptor.__init__s  sj     	 		
 %*	
 	9"	 )	 6@5E2	r0   )r2  r1  r/  r.  r0  r}   r)  )rN   rO   rP   rQ   r   rF   rR   rS   r0   r.   r,  r,  p  s(    F
 8 8r0   r,  c                  `   ^  \ rS rSrSr/ SQrSSSSSSSSSSS.
U 4S jjrS rS	 rS
 r	Sr
U =r$ )r   i  u  Simple container for the axis data.

Add more localisations?

.. code:: python

    a1 = AxisDescriptor()
    a1.minimum = 1
    a1.maximum = 1000
    a1.default = 400
    a1.name = "weight"
    a1.tag = "wght"
    a1.labelNames['fa-IR'] = "قطر"
    a1.labelNames['en'] = "Wéíght"
    a1.map = [(1.0, 10.0), (400.0, 66.0), (1000.0, 990.0)]
    a1.axisOrdering = 1
    a1.axisLabels = [
        AxisLabelDescriptor(name="Regular", userValue=400, elidable=True)
    ]
    doc.addAxis(a1)
)r)  r}   r   r   r   r0  r1  r2  NF)
r)  r}   r.  r   r   r   r/  r0  r1  r2  c       
   
     T   > [         TU ]  UUUUUU	U
S9  X@l         X`l         XPl        g Nr-  )superrF   r   r   r   )r5   r)  r}   r.  r   r   r   r/  r0  r1  r2  rs   s              r.   rF   AxisDescriptor.__init__  sP     	!%! 	 	
 	 	 	r0   c                    [        U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  S9
$ )N)
r)  r}   r.  r   r   r   r/  r0  r1  r2  )r%  r)  r}   r.  r   r   r   r/  r0  r1  r2  rK   s    r.   	serializeAxisDescriptor.serialize  sW    LLLLLL;;**
 	
r0   c           	         SSK Jn  U R                  (       d  U$ U" XR                   VVs0 s H  u  p1X1_M	     snn5      $ s  snnf )z?Maps value from axis mapping's input (user) to output (design).r   piecewiseLinearMap)fontTools.varLib.modelsr?  r0  r5   ra   r?  ks       r.   r   AxisDescriptor.map_forward  s6    >xxH!!xx%@xtqadx%@AA%@s   Ac           	         SSK Jn  [        U[        5      (       a  US   nU R                  (       d  U$ U" XR                   VVs0 s H  u  p1X_M	     snn5      $ s  snnf )z?Maps value from axis mapping's output (design) to input (user).r   r>  )r@  r?  r]   tupler0  rA  s       r.   r  AxisDescriptor.map_backward  sL    >a!AxxH!!xx%@xtqadx%@AA%@s   A)r   r   r   )rN   rO   rP   rQ   rx   rg   rF   r;  r   r  rR   __classcell__rs   s   @r.   r   r     sQ    ,	F & &P
BB Br0   r   c            
      X   ^  \ rS rSrSrSrSrSSSSSSSSSS.	U 4S jjrS	 rS
 r	Sr
U =r$ )r   i  a?  Container for discrete axis data.

Use this for axes that do not interpolate. The main difference from a
continuous axis is that a continuous axis has a ``minimum`` and ``maximum``,
while a discrete axis has a list of ``values``.

Example: an Italic axis with 2 stops, Roman and Italic, that are not
compatible. The axis still allows to bind together the full font family,
which is useful for the STAT table, however it can't become a variation
axis in a VF.

.. code:: python

    a2 = DiscreteAxisDescriptor()
    a2.values = [0, 1]
    a2.default = 0
    a2.name = "Italic"
    a2.tag = "ITAL"
    a2.labelNames['fr'] = "Italique"
    a2.map = [(0, 0), (1, -11)]
    a2.axisOrdering = 2
    a2.axisLabels = [
        AxisLabelDescriptor(name="Roman", userValue=0, elidable=True)
    ]
    doc.addAxis(a2)

.. versionadded:: 5.0
r   )r)  r}   valuesr   r0  r1  r2  NF)	r)  r}   r.  rJ  r   r/  r0  r1  r2  c       	   
     Z   > [         T
U ]  UUUUUUU	S9  XPl         U=(       d    / U l        g r7  )r8  rF   r   rJ  )r5   r)  r}   r.  rJ  r   r/  r0  r1  r2  rs   s             r.   rF   DiscreteAxisDescriptor.__init__;  sJ     	!%! 	 	
 &		 $*<R	r0   c                D   ^ [        U4S jU R                   5       T5      $ )zMaps value from axis mapping's input to output.

Returns value unchanged if no mapping entry is found.

Note: for discrete axes, each value must have its mapping entry, if
you intend that value to be mapped.
c              3  <   >#    U  H  u  pUT:X  d  M  Uv   M     g 7fr3   rS   r   rB  ra   r;   s      r.   r   5DiscreteAxisDescriptor.map_forward.<locals>.<genexpr>i       :841qEzQQ8   	)nextr0  r5   r;   s    `r.   r   "DiscreteAxisDescriptor.map_forwarda  s     :488:EBBr0   c                x   ^ [        T[        5      (       a  TS   m[        U4S jU R                   5       T5      $ )zMaps value from axis mapping's output to input.

Returns value unchanged if no mapping entry is found.

Note: for discrete axes, each value must have its mapping entry, if
you intend that value to be mapped.
r   c              3  <   >#    U  H  u  pUT:X  d  M  Uv   M     g 7fr3   rS   rO  s      r.   r   6DiscreteAxisDescriptor.map_backward.<locals>.<genexpr>u  rQ  rR  )r]   rE  rS  r0  rT  s    `r.   r  #DiscreteAxisDescriptor.map_backwardk  s2     eU##!HE:488:EBBr0   )r   rJ  )rN   rO   rP   rQ   rx   r   rg   rF   r   r  rR   rG  rH  s   @r.   r   r     sN    : FVF
 $ $LC
C 
Cr0   r   c                  V    \ rS rSrSrSrSrSSSSSSS.S jrSS	 jr\	SS
 j5       r
Srg)r   ix  a  Container for axis label data.

Analogue of OpenType's STAT data for a single axis (formats 1, 2 and 3).
All values are user values.
See: `OTSpec STAT Axis value table, format 1, 2, 3 <https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-1>`_

The STAT format of the Axis value depends on which field are filled-in,
see :meth:`getFormat`

.. versionadded:: 5.0
r  userMinimum	userValueuserMaximumr}   elidableolderSiblinglinkedUserValuer.  NF)r\  r^  r_  r`  ra  r.  c                   X0l          X l         X@l         Xl         XPl         X`l         Xpl         U=(       d    0 U l        g r3   r[  )	r5   r}   r]  r\  r^  r_  r`  ra  r.  s	            r.   rF   AxisLabelDescriptor.__init__  sZ     -86 )P,76	G&	 #/	 1@44>4D"	r0   c                V    U R                   b  gU R                  c  U R                  b  gg)u  Determine which format of STAT Axis value to use to encode this label.

===========  =========  ===========  ===========  ===============
STAT Format  userValue  userMinimum  userMaximum  linkedUserValue
===========  =========  ===========  ===========  ===============
1            ✅          ❌            ❌            ❌
2            ✅          ✅            ✅            ❌
3            ✅          ❌            ❌            ✅
===========  =========  ===========  ===========  ===============
         )ra  r\  r^  rK   s    r.   	getFormatAxisLabelDescriptor.getFormat  s0     +'4+;+;+Gr0   c                ^    U R                   R                  S5      =(       d    U R                  $ zDReturn the English name from :attr:`labelNames` or the :attr:`name`.r   r.  r   r}   rK   s    r.   defaultNameAxisLabelDescriptor.defaultName  "     ""4(5DII5r0   )r_  r.  ra  r}   r`  r^  r\  r]  )r   intr   rJ   )rN   rO   rP   rQ   rx   r   rg   rF   rh  r>   rm  rR   rS   r0   r.   r   r   x  sH    
 F	F  #J" 6 6r0   r   c                  P    \ rS rSrSrSrSrSSSS.S jr\SS	 j5       r	SS
 jr
Srg)r   i  a,  Container for location label data.

Analogue of OpenType's STAT data for a free-floating location (format 4).
All values are user values.

See: `OTSpec STAT Axis value table, format 4 <https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-4>`_

.. versionadded:: 5.0
r  )r}   r_  r`  r   r.  FN)r_  r`  r.  c               p    Xl          U=(       d    0 U l         X0l         X@l         U=(       d    0 U l        g r3   r}   r   r_  r`  r.  )r5   r}   r   r_  r`  r.  s         r.   rF    LocationLabelDescriptor.__init__  sJ     	H0<0B	 '	 #/	 +5*:	r0   c                ^    U R                   R                  S5      =(       d    U R                  $ rk  rl  rK   s    r.   rm  #LocationLabelDescriptor.defaultName  ro  r0   c                    UR                    Vs0 s H>  nUR                  U R                  R                  UR                  UR                  5      _M@     sn$ s  snf )zGet the complete user location of this label, by combining data
from the explicit user location and default axis values.

.. versionadded:: 5.0
)r   r}   r   r   r   )r5   r   r   s      r.   r  +LocationLabelDescriptor.getFullUserLocation  sQ     
  IIt((,,TYYEE 
 	
 
s   AA)r_  r.  r}   r`  r   rq  r   )rN   rO   rP   rQ   rx   r   rg   rF   r>   rm  r  rR   rS   r0   r.   r   r     s=     FOF  D 6 6	
r0   r   c                  B    \ rS rSrSrSrSr\" S5      rSSSS.S jr	Sr
g)	r"   i  a  Container for variable fonts, sub-spaces of the Designspace.

Use-cases:

- From a single DesignSpace with discrete axes, define 1 variable font
  per value on the discrete axes. Before version 5, you would have needed
  1 DesignSpace per such variable font, and a lot of data duplication.
- From a big variable font with many axes, define subsets of that variable
  font that only include some axes and freeze other axes at a given location.

.. versionadded:: 5.0
variable-font)r|   axisSubsetsr   r   Nc               b    Xl          X l         U=(       d    / U l         U=(       d    0 U l        g r3   r}   r|   r|  r   )r5   r}   r|   r|  r   s        r.   rF   VariableFontDescriptor.__init__!  s?    		 &	 B 		
 .1YB=r0   )r|  r|   r   r}   )rN   rO   rP   rQ   rx   r   rg   r?   r|   rF   rR   rS   r0   r.   r"   r"     s.     F/F!+.H)-4T > >r0   r"   c                  \    \ rS rSrSrSrSr\R                  * S\R                  S.S jr	Sr
g)	r   i;  zRSubset of a continuous axis to include in a variable font.

.. versionadded:: 5.0
axis-subsetr}   r\  userDefaultr^  N)r\  r  r^  c               :    Xl          X l         X0l         X@l        g r3   r  )r5   r}   r\  r  r^  s        r.   rF   "RangeAxisSubsetDescriptor.__init__D  s1     	<"-	 -8	 #.	r0   )r}   r  r^  r\  )rN   rO   rP   rQ   rx   r   rg   mathinfrF   rR   rS   r0   r.   r   r   ;  s0    
 FBF %)HH9$DHH r0   r   c                  &    \ rS rSrSrSrSrS rSrg)r!   iZ  z`Single value of a discrete or continuous axis to use in a variable font.

.. versionadded:: 5.0
r  r}   r]  c                   Xl          X l        g r3   r  )r5   r}   r]  s      r.   rF   "ValueAxisSubsetDescriptor.__init__c  s    		 !*Jr0   N)	rN   rO   rP   rQ   rx   r   rg   rF   rR   rS   r0   r.   r!   r!   Z  s    
 F"FKr0   r!   c                  N   \ rS rSrSr\r\r\	r
\r\r\r\r\r\r\r\r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r SS jr!SS	 jr"S
 r#SS jr$S r%S r&S r'S r(      SS jr)S r*      S S jr+SSS.   S!S jjr,S r-S r.      S"S jr/S#S jr0S r1Sr2g)$r   il  rq   c                "    U R                  5       $ r3   )axisDescriptorClassclss    r.   getAxisDecriptorBaseDocWriter.getAxisDecriptorz      &&((r0   c                "    U R                  5       $ r3   )axisMappingDescriptorClassr  s    r.   getAxisMappingDescriptor&BaseDocWriter.getAxisMappingDescriptor~  s    --//r0   c                "    U R                  5       $ r3   )sourceDescriptorClassr  s    r.   getSourceDescriptor!BaseDocWriter.getSourceDescriptor  s    ((**r0   c                "    U R                  5       $ r3   )instanceDescriptorClassr  s    r.   getInstanceDescriptor#BaseDocWriter.getInstanceDescriptor  s    **,,r0   c                "    U R                  5       $ r3   )ruleDescriptorClassr  s    r.   getRuleDescriptorBaseDocWriter.getRuleDescriptor  r  r0   c                |    Xl         X l        U R                  5       U l        [        R
                  " S5      U l        g )Ndesignspace)r*   documentObject_getEffectiveFormatTupleeffectiveFormatTupleETElementroot)r5   documentPathr  s      r.   rF   BaseDocWriter.__init__  s.     	,$($A$A$C!JJ}-	r0   c                H
   SR                  S U R                   5       5      U R                  R                  S'   U R                  R
                  (       d2  U R                  R                  (       d  U R                  R                  bk  [        R                  " S5      nU R                  R                  b#  U R                  R                  UR                  S'   U R                  R                  U5        U R                  R
                   H  nU R                  U5        M     U R                  R                  (       a  S n[        5       nU R                  R                   H  n[        USS 5      U:w  ad  Ub-  U R                  R                  S5      S   R                  U5        [        USS 5      n[        R                  " S	5      nUb  XvR                  S
'   U R                  Xh5        M     Ub-  U R                  R                  S5      S   R                  U5        U R                  R                   (       a_  [        R                  " S5      n	U R                  R                    H  n
U R#                  X5        M     U R                  R                  U	5        U R                  R$                  (       aS  [        U R                  SS5      (       a  SS0nO0 nU R                  R                  [        R                  " SU5      5        U R                  R$                   H  nU R'                  U5        M     U R                  R(                  (       a/  U R                  R                  [        R                  " S5      5        U R                  R(                   H  nU R+                  U5        M     U R                  R,                  (       a_  [        R                  " S5      nU R                  R,                   H  nU R/                  X5        M     U R                  R                  U5        U R                  R0                  (       a/  U R                  R                  [        R                  " S5      5        U R                  R0                   H  nU R3                  U5        M     U R                  R4                  (       a1  U R7                  U R                  U R                  R4                  S5        [        R8                  " U R                  5      nUR;                  U R<                  USUUS9  g )N.c              3  8   #    U  H  n[        U5      v   M     g 7fr3   )rJ   r   is     r.   r   &BaseDocWriter.write.<locals>.<genexpr>  s     -X>Wc!ff>W   formatr   elidedfallbacknamer   .axesr   mappingsr   labelsrulesProcessingLastF
processinglastr   sourceszvariable-fonts	instancesrf  xml)encodingmethodxml_declarationpretty_print)r'   r  r  attribr  r   axisMappingselidedFallbackNamer  r  r   _addAxisobjectr4   findall_addAxisMappinglocationLabels_addLocationLabelr   _addRuler  
_addSourcevariableFonts_addVariableFontr  _addInstancer   _addLibElementTreewriter*   )r5   prettyr  r  axesElement
axisObjectmappingsElement	lastGroupmappingObjectlabelsElementlabelObject
attributes
ruleObjectsourceObjectvariableFontsElementvariableFontinstanceObjecttrees                     r.   r  BaseDocWriter.write  s   %(XX-Xd>W>W-X%X		" $$""//""55A**V,K""55A'':: ""#78 II[)--22JMM*% 3 ++"OI!%!4!4!A!A=*<dCyP&2		))'215<<_M '7I4 PI&(jj&<O ,@I..}=$$_D "B *		!!'*1-44_E--JJx0M#22AA&&}B  BII]+$$t**,A5II*F3

IIRZZ<=--33JMM*% 4 &&IIRZZ	23 //77LOOL) 8 ,,#%::.>#?  $ 3 3 A A%%&:I !BII12((IIRZZ45"11;;Nn- < ""LLD$7$7$;$;Q?~~dii(

II+ 	 	
r0   c                   U R                   R                  n[        S U R                   R                   5       5      (       d  U R                   R                  (       dq  [        S U R                   R
                   5       5      (       dF  U R                   R                  (       d+  [        S U R                   R                   5       5      (       a  US:  a  SnU R                   R                  (       a  US:  a  SnU$ )zTry to use the version specified in the document, or a sufficiently
recent version to be able to encode what the document contains.
c              3     #    U  H9  n[        US 5      =(       d!    UR                  SL=(       d    UR                  v   M;     g7f)rJ  N)r\   r1  r2  )r   r   s     r.   r   9BaseDocWriter._getEffectiveFormatTuple.<locals>.<genexpr>  sF       5D h' #$$D0#??# 5s   AAc              3  8   #    U  H  oR                   v   M     g 7fr3   )r   )r   r{   s     r.   r   r    s     X<W&--<Wr  c              3  `   #    U  H$  nUR                   =(       d    UR                  v   M&     g 7fr3   )r   r   )r   r   s     r.   r   r    s+       =H &&?(*?*?? =s   ,.   r   )r  rg  )	r  formatTupler   r   r  r  r  r  r  )r5   
minVersions     r.   r  &BaseDocWriter._getEffectiveFormatTuple  s     ((44
  !//44	   ""11XD<O<O<W<WXXX""00  $ 3 3 = =  
 F"#
++F"#
r0   Nc                V   [         R                  " S5      nUb  X#R                  S'   U R                  R	                  5       nUR                  5        H  u  pVXT;   d  M  XdU'   M     UR                  5        H  u  px[         R                  " S5      n	XyR                  S'   [        U5      [        :X  aC  U R                  US   5      U	R                  S'   U R                  US   5      U	R                  S'   OU R                  U5      U	R                  S'   UR                  U	5        M     X44$ )z+Convert Location dict to a locationElement.r   r}   	dimensionr   xvaluerg  yvalue)
r  r  r  r  newDefaultLocationr[   typerE  
intOrFloatr   )
r5   locationObjectr}   
locElementvalidatedLocationr  	axisValuedimensionNamedimensionValue
dimElements
             r.   _makeLocationElement"BaseDocWriter._makeLocationElement  s   ZZ
+
(,f% //BBD#1#7#7#9H,.7(+ $: .?-D-D-F)MK0J(5f%N#u,.2oonQ>O.P
!!(+.2oonQ>O.P
!!(+.2oon.M
!!(+j) .G ,,r0   c                p    [        U5      U:X  a  SU-  $ SU-  R                  S5      R                  S5      $ )Nz%dz%f0r  )rp  rstrip)r5   nums     r.   r  BaseDocWriter.intOrFloat  s7    s8s?#:s
""3'..s33r0   c                6   [         R                  " S5      nUR                  b  UR                  UR                  S'   UR                   GH0  n[         R                  " S5      nU H  nUR                  S5      c  UR                  S5      c  M)  [         R                  " S5      nUR                  S5      UR                  S'   UR                  S5      b-  U R                  UR                  S5      5      UR                  S'   UR                  S5      b-  U R                  UR                  S5      5      UR                  S'   UR                  U5        M     [        U5      (       d  GM  UR                  U5        GM3     UR                   HN  n[         R                  " S5      nUS   UR                  S'   US	   UR                  S
'   UR                  U5        MP     [        U5      (       a.  U R                  R                  S5      S   R                  U5        g g )Nr   r}   conditionsetr   r   	conditionsubr   rg  with.rules)r  r  r}   r  r   r   r  r   r'  r   r  r  )	r5   r  ruleElementr   conditionsetElementcondconditionElementr  
subElements	            r.   r  BaseDocWriter._addRule  s   jj(??&)3Kv&$22J"$**^"<"88I&.488I3F3N#%::k#: 26((62B ''/88I&29=+:$++I6 88I&29=+:$++I6 $**+;< # &''""#67% 3& ??CE*J(+AJf%(+AJf%z*	 #
 {IIh'*11+> r0   c                B  ^  [         R                  " S5      nUR                  UR                  S'   UR                  UR                  S'   T R                  X!R                  5        UR                  (       ax  UR                   Hh  u  p4[         R                  " S5      nT R                  U5      UR                  S'   T R                  U5      UR                  S'   UR                  U5        Mj     UR                  c  UR                  (       az  [         R                  " S5      nUR                  b"  [        UR                  5      UR                  S'   UR                   H  nT R                  Xg5        M     UR                  U5        [        US	5      (       aQ  T R                  UR                  5      UR                  S	'   T R                  UR                   5      UR                  S
'   OC[        US5      (       a2  SR#                  U 4S jUR$                   5       5      UR                  S'   T R                  UR&                  5      UR                  S'   UR(                  (       a  SUR                  S'   T R*                  R-                  S5      S   R                  U5        g )Nr   r)  r}   r0  inputoutputr  orderingr   r   rJ   c              3  F   >#    U  H  nTR                  U5      v   M     g 7fr3   )r  )r   ra   r5   s     r.   r   )BaseDocWriter._addAxis.<locals>.<genexpr>J  s!      4,=q"",=s   !r   1r/  r  r   )r  r  r)  r  r}   _addLabelNamesr.  r0  r  r   r1  r2  rJ   _addAxisLabelr\   r   r   r'   rJ  r   r/  r  r  )r5   r  axisElement
inputValueoutputValue
mapElementr  r  s   `       r.   r  BaseDocWriter._addAxis4  s
   jj($.NN5!%/__6"K)>)>?>>+5>>'
ZZ.
-1__Z-H
!!'*.2ook.J
!!(+"":.	 ,:
 "".*2G2GJJx0M&&236z7N7N3O$$Z0#..""=8 /}-:y)),0OOJ<N<N,OKy),0OOJ<N<N,OKy)Z**+.88 4,6,=,=4 ,Kx( )-
8J8J(K9%+.Kx(		'"1%,,[9r0   c                    [         R                  " S5      n[        USS 5      b  UR                  UR                  S'   S H  n[        X$S 5      nUc  M  [         R                  " US S 5      nUR                  U5        UR                  5        HX  u  px[         R                  " S5      n	XyR                  S'   U R                  U5      U	R                  S'   UR                  U	5        MZ     M     UR                  U5        g )Nmappingr   )r   r   ir  r}   r  )r  r  r4   r   r  r   r[   r  )
r5   r  r  mappingElementwhat
whatObjectwhatElementr}   r;   dimensionElements
             r.   r  BaseDocWriter._addAxisMappingR  s    I.=-6B3@3L3LN!!-07D d;J!**T#2Y/K!!+.)//1#%::k#: 26''/48OOE4J ''1""#34	  2 8 	~.r0   c                   [         R                  " S5      nU R                  UR                  5      UR                  S'   UR
                  b(  U R                  UR
                  5      UR                  S'   UR                  b(  U R                  UR                  5      UR                  S'   UR                  UR                  S'   UR                  (       a  SUR                  S'   UR                  (       a  SUR                  S'   UR                  b(  U R                  UR                  5      UR                  S	'   U R                  X2R                  5        UR                  U5        g )
Nr  	uservalueuserminimumusermaximumr}   truer_  oldersiblinglinkeduservalue)r  r  r  r]  r  r\  r^  r}   r_  r`  ra  r  r.  r   )r5   r  r  labelElements       r.   r  BaseDocWriter._addAxisLabele  s    zz'*+/??5??+KK((15ARAR1SL.(15ARAR1SL.&+jjF#>>.4L
+28L/  ,59__%%6L 12 	L*:*:;<(r0   c                    [        UR                  5       5       HD  u  p4[        R                  " S5      nX5R                  [
        '   XEl        UR                  U5        MF     g )N	labelname)sortedr[   r  r  r  XML_LANGtextr   )r5   parentElementr.  r   	labelNamelanguageElements         r.   r  BaseDocWriter._addLabelNamesz  sN    '-j.>.>.@'A#L jj5O/;""8,#,   1	 (Br0   c                l   [         R                  " S5      nUR                  UR                  S'   UR                  (       a  SUR                  S'   UR
                  (       a  SUR                  S'   U R                  X2R                  5        U R                  X2R                  S9  UR                  U5        g )Nr  r}   r+  r_  r,  r   )r  r  r}   r  r_  r`  r  r.  _addLocationElementr   r   )r5   r5  r  r.  s       r.   r  BaseDocWriter._addLocationLabel  s     zz'*&+jjF#>>.4L
+28L/L*:*:;  <N<N O\*r0   r   r   c               h   [         R                  " S5      nU R                  R                   GH`  nUb  UR                  U;   a  [         R                  " S5      nUR                  UR
                  S'   X%R                     n[        U[        5      (       aC  U R                  US   5      UR
                  S'   U R                  US   5      UR
                  S'   OU R                  U5      UR
                  S'   UR                  U5        M  Uc  M  UR                  U;   d  M  [         R                  " S5      nUR                  UR
                  S'   X5R                     nU R                  U5      UR
                  S'   UR                  U5        GMc     [        U5      S:  a  UR                  U5        g g )	Nr   r  r}   r   r  rg  r  r(  )r  r  r  r   r}   r  r]   rE  r  r   r'  )r5   r5  r   r   r  r   r  r;   s           r.   r;  !BaseDocWriter._addLocationElement  s\    ZZ
+
'',,D)dii>.IZZ4
,0II
!!&)&yy1eU++26//%(2KJ%%h/26//%(2KJ%%h/26//%2HJ%%h/!!*-)dii<.GZZ4
,0II
!!&)$YY/151G
!!+.!!*-! -" z?Q  , r0   c                   [         R                  " S5      nUR                  b  UR                  UR                  S'   UR                  b  UR                  UR                  S'   UR
                  b  UR
                  UR                  S'   UR                  b  UR                  UR                  S'   UR                  (       a  [        UR                  R                  5       5      nUR                  5         U HZ  nUS:X  a  M  [         R                  " S5      nXER                  [        '   UR                  U5      Ul        UR                  U5        M\     UR                  (       a  [        UR                  R                  5       5      nUR                  5         U HZ  nUS:X  a  M  [         R                  " S5      nXFR                  [        '   UR!                  U5      Ul        UR                  U5        M\     UR"                  (       a  [        UR"                  R                  5       5      nUR                  5         U HZ  nUS:X  a  M  [         R                  " S5      nXGR                  [        '   UR%                  U5      Ul        UR                  U5        M\     UR&                  (       a  [        UR&                  R                  5       5      nUR                  5         U HZ  nUS:X  a  M  [         R                  " S5      nXHR                  [        '   UR)                  U5      Ul        UR                  U5        M\     U R*                  S	:  a3  UR                  c%  U R-                  UUR.                  UR0                  S
9  O@UR2                  b3  U R5                  UR2                  5      u  ol        UR                  U	5        UR6                  b  UR6                  UR                  S'   UR8                  b  UR8                  UR                  S'   UR:                  b  UR:                  UR                  S'   UR<                  b  UR<                  UR                  S'   U R*                  S	:  Ga   UR>                  (       a  URA                  S5      / :X  a'  [         R                  " S5      n
UR                  U
5        URA                  S5      S   n
[C        UR>                  RE                  5       5       H(  u  pU RG                  X!X5      nU
R                  U5        M*     URH                  (       a'  [         R                  " S5      nUR                  U5        URJ                  (       a'  [         R                  " S5      nUR                  U5        U RM                  X!RN                  S5        U RP                  RA                  S5      S   R                  U5        g )Nr   r}   r   
familyname	stylenamer   stylemapstylenamestylemapfamilynamer  r=  r|   postscriptfontnamez.glyphsr   r   r   r   r#  z
.instances))r  r  r}   r  r   r   r   r   r^   keyssortr3  r   r4  r   r   r   r   r   r   r   r  r;  r   r   r   r  r|   r   r   r   r   r  r2  r[   _writeGlyphElementr   r   r  r   r  )r5   r  instanceElementlanguageCodescodelocalisedStyleNameElementlocalisedFamilyNameElement!localisedStyleMapStyleNameElement"localisedStyleMapFamilyNameElementlocationElementglyphsElement	glyphNamedataglyphElementkerningElementinfoElements                   r.   r  BaseDocWriter._addInstance  s   **Z0*-;-@-@O""6*''31?1M1MO"":.$$03A3L3LO""<0##/2@2J2JO"";/,, !B!B!G!G!IJM %4<,.JJ{,C)=A00:1?1L1LT1R).&&'@A & -- !C!C!H!H!JKM %4<-/ZZ-E*>B11(;2@2N2Nt2T*/&&'AB & 44 !J!J!O!O!QRM %4<46JJ?R4S1EI88B"77= 26  &&'HI & 55 !K!K!P!P!RSM %4<57ZZ@T5U2FJ99(C"88> 37  &&'IJ & $$.++3((##1#@#@!/!<!< )  &&2;?;T;T"++<8!8  &&7"".1?1H1HO"":.,,811 ""#78 ,,811 ""#78 ++700 ""#67 $$v-$$"**95;$&JJx$8M#**=9 / 7 7	 B1 E'-n.C.C.I.I.K'LOI#'#:#:'$L "((6	 (M
 %%!#I!6&&~6"" jj0&&{3_&8&8!<		,'*11/Br0   c                `   [         R                  " S5      nUR                  b  UR                  UR                  S'   UR                  b8  UR                  R                  S5      S:w  a  UR                  UR                  S'   UR                  b  UR                  UR                  S'   UR                  b  UR                  UR                  S'   UR                  b  UR                  UR                  S'   UR                  (       a  [        UR                  R                  5       5      nUR                  5         U HZ  nUS	:X  a  M  [         R                  " S5      nXER                  [        '   UR                  U5      Ul        UR!                  U5        M\     UR"                  (       a6  [         R                  " S
5      nSUR                  S'   UR!                  U5        UR$                  (       a6  [         R                  " S5      nSUR                  S'   UR!                  U5        UR&                  (       a6  [         R                  " S5      nSUR                  S'   UR!                  U5        UR(                  (       d  UR*                  (       ag  [         R                  " S5      n	UR(                  (       a  SU	R                  S'   UR*                  (       a  SU	R                  S'   UR!                  U	5        UR,                  (       a6  [         R                  " S5      n
SU
R                  S'   UR!                  U
5        UR.                  (       aW  UR.                   HG  n[         R                  " S5      nXR                  S'   SUR                  S'   UR!                  U5        MI     U R0                  S:  a  U R3                  X!R4                  S9  O3U R7                  UR4                  5      u  ol        UR!                  U5        U R8                  R;                  S5      S   R!                  U5        g )Nr{   r|   temp_masterr   r}   rA  rB  layerr   r   r  copygroupsfeaturesr   muter   glyphr  r   z.sources)r  r  r|   r  r}   findr   r   r~   r   r^   rF  rG  r3  r   r4  r   r   r   r   r   r   r   r   r  r;  r   r  r  r  )r5   r  sourceElementrJ  rK  rM  
libElementgroupsElementfeaturesElementrV  rU  r}   rT  rP  s                 r.   r  BaseDocWriter._addSource  s\   

8,  ,/;/D/DM  ,(  %%m49/;/@/@$$V,"".1=1H1HM  .!!-0<0F0FM  -!!-,8,B,BM  )++ !A!A!F!F!HIM %4<-/ZZ-E*>B11(;2>2L2LT2R*/$$%?@ & E*J(+Jf%  ,""JJx0M+.M  (  /$$ jj4O-0O""6*  1  L$9$9**V,K$$-0""6*$$-0""6*  -##ZZ	2N,/N!!&)  0''$44!zz'2.2##F+.1##F+$$\2	 5
 $$.$$.C.C %  6:5N5N%%62O2   1		*%a(//>r0   c                ~   [         R                  " S5      nUR                  UR                  S'   UR                  b  UR                  UR                  S'   UR
                  (       Ga  [         R                  " S5      nUR
                   GHq  n[         R                  " S5      nUR                  UR                  S'   [        US5      (       a  [        [        U5      nUR                  [        R                  * :w  a(  U R                  UR                  5      UR                  S'   UR                  [        R                  :w  a(  U R                  UR                  5      UR                  S'   UR                  b(  U R                  UR                  5      UR                  S	'   OI[        US
5      (       a8  [        [        U5      nU R                  UR                   5      UR                  S'   UR#                  U5        GMt     UR#                  U5        U R%                  X2R&                  S5        UR#                  U5        g )Nr{  r}   r|   zaxis-subsetsr  r\  r)  r*  userdefaultr]  r(  r#  )r  r  r}   r  r|   r|  r\   r   r   r\  r  r  r  r^  r  r!   r]  r   r  r   )r5   r5  vf	vfElementsubsetsElementsubsetsubsetElements          r.   r  BaseDocWriter._addVariableFontV  s    JJ/	#%77	 ;;"+-;;IZ(>>>ZZ7N.. "

= 9/5{{$$V, 6=11!";VDF))dhhY6>Boo"..?,,]; ))TXX5>Boo"..?,,]; ))5>Boo"..?,,]; V[11!";VDF8<((9M((5 %%m43 )4 ^,Y*Y'r0   c                    U(       d  g [         R                  " S5      nUR                  [        R                  " X#S95        UR                  U5        g )Nr   )indent_level)r  r  r   r   totree)r5   r5  rS  ro  rb  s        r.   r  BaseDocWriter._addLib}  s;    ZZ&
(//$JKZ(r0   c                   [         R                  " S5      nUR                  S5      (       a  SUR                  S'   UR                  S5      bG  SR	                  UR                  S5       Vs/ s H  n[        U5      PM     sn5      UR                  S'   UR                  S5      b6  U R                  UR                  S5      5      u  otS'   UR                  U5        Ub  X5R                  S'   UR                  S	5      b=  [         R                  " S	5      nUR                  S	5      Ul        UR                  U5        UR                  S
5      Gb  [         R                  " S
5      n	UR                  S
5       H  n
[         R                  " S5      nU
R                  S5      b  U
R                  S5      UR                  S'   U
R                  S5      b  U
R                  S5      UR                  S'   U
R                  S5      b6  U R                  U
R                  S5      5      u  ozS'   UR                  U5        U	R                  U5        M     UR                  U	5        U$ s  snf )Nr_  r^  r  unicodesr  unicodeinstanceLocationr}   notemastersmasterrR  	glyphnamer   r{   r   )	r  r  r   r  r'   hexr  r   r4  )r5   rI  r  rR  rS  rT  urP  noteElementmastersElementmmasterElements               r.   rH   BaseDocWriter._writeGlyphElement  s   zz'*88F*-L'88J+-0XX!%*!56!5AQ!56.L	* 88&'38<8Q8Q+,95O"45 0 *3'88F'**V,K#xx/K,88I*ZZ	2NXXi( "

8 455%189k8JM((555=,56UU6]M((255$0595N5Nj)62Oz] "((9%%m4 ) /9 7s   ,I )r  r  r*   r  )r  r   )TUTF-8Tr3   )r  
ET.Elementr  r   r   None)r5  r  r  r   r   r  )r   r  r   r   )r5  r  rh  r"   r   r  )r5  r  rS  r   ro  rp  r   r  )3rN   rO   rP   rQ   _whiteSpacer   r  r   discreteAxisDescriptorClassr   axisLabelDescriptorClassr   r  r   locationLabelDescriptorClassr   r  r    r  r"   variableFontDescriptorClassr!   valueAxisSubsetDescriptorClassr   rangeAxisSubsetDescriptorClassr   r  classmethodr  r  r  r  r  rF   r  r  r  r  r  r  r  r  r  r  r;  r  r  r  r  rH  rR   rS   r0   r.   r   r   l  sm   K("82!6#: (,"8%>"%>"0) ) 0 0 + + - - ) ).I
V6-*4
?@:</&)%).A)	)*2+'+0G+	+" 37+/- 0	-
 )-8hCT@?D%('%(-C%(	%(N)"r0   r   c                      \ rS rSr\r\r\r	\
r\r\r\r\r\r\r\rS r\S 5       rS rS rSS jrS r SS	 jr!S
 r"S r#SS jr$S r%S r&S r'SS jr( SS jr)S r*S r+S r,S r-Sr.g)r   i  c                D   Xl         X l        [        R                  " U R                   5      nUR	                  5       U l        U R
                  R                  R                  SS5      U R                  l        / U l	        / U l
        / U l        / U l        0 U l        SU l        g )Nr  z3.0T)r*   r  r  parsegetrootr  r  r   formatVersion_axesr   r  r  axisDefaults_strictAxisNames)r5   r  r  r  s       r.   rF   BaseDocReader.__init__  s}     	,xx		"LLN	,0II,<,<,@,@5,Q)

 $r0   c                J    [        [        USS95      nU " X25      nS Ul        U$ )Nutf-8)r  )r   r   r*   )r  stringr  fr5   s        r.   
fromstringBaseDocReader.fromstring  s)    GFW561%	r0   c                    U R                  5         U R                  5         U R                  5         U R                  5         U R	                  5         U R                  5         U R                  5         g r3   )readAxes
readLabels	readRulesreadVariableFontsreadSourcesreadInstancesreadLibrK   s    r.   readBaseDocReader.read  sL     r0   c                   / nU R                   R                  S5      nUbD  UR                  R                  SS5      nUS;  a  [	        SU-  5      eUS:H  U R
                  l        U R                   R                  S5       GH1  nU R                  5       nUR                  R                  S5      =oel	        U R                  UU5      nU(       a6  UR                  R                  U5        U R                  R                  S	5        UR                  S
5       H5  nU R                  UU5      n	U	c  M  UR                  R                  U	5        M7     UR                  S5       H=  n
U
R                  S   nU
R                  S   nUR                  R                  X45        M?     UR                  U5        GM4     XR
                  l        g )Nr	  r  first>   r  r  zO<rules> processing attribute value is not valid: %r, expected 'first' or 'last'r  z.rules/ruler}   zWFound stray rule conditions outside a conditionset. Wrapped them in a new conditionset.z.conditionsetz.subr  )r  r`  r  r   r   r  r  r  r  r}   _readConditionElementsr   r   logr   r   r   )r5   r   rulesElementprocessingValuer
  r  ruleNameexternalConditionsconditionSetElementconditionSetr  rt   r   s                r.   r  BaseDocReader.readRules  s   yy~~h/#*1155lGLO&77.13BC  7F6OD399,,];K113J)4););)?)?)GGH!%!<!<" "((//0BC:
 (3':':?'K##::'   +,,33LA (L *11&9
%%f-%%f-&&v. : LL$5 <6 %*!r0   Nc                   / nUR                  S5       H  n0 nUR                  R                  S5      nUb  [        U5      US'   OS US'   UR                  R                  S5      nUb  [        U5      US'   OS US'   UR                  R                  S5      US'   UR                  S5      c.  UR                  S5      c  [	        SUb  SU-  -   5      eS-   5      eUR                  U5        M     U$ )Nz
.conditionr   r   r}   z5condition missing required minimum or maximum in rulez '%s'rI   )r  r  r   floatr   r   )r5   r5  r  cdsr  r   cdMincdMaxs           r.   r  $BaseDocReader._readConditionElements  s    - 5 5l CB$++//	:E  %e9 !%9$++//	:E  %e9 !%9)0044V<BvJvvi (RVVI->-F.K-5-Aw)K GIK  JJrN+ !D, 
r0   c           	     	   U R                   R                  S5      nUb.  SUR                  ;   a  UR                  S   U R                  l        U R                   R                  S5      nU(       d  g U GH  nU R                  R                  S:  a^  SUR                  ;   aN  U R                  5       nUR                  S   R                  S5       Vs/ s H  n[        U5      PM     snUl
        ObU R                  5       n[        UR                  R                  S5      5      Ul        [        UR                  R                  S5      5      Ul        [        UR                  R                  S	5      5      Ul        UR                  R                  S
5      Ul        UR                  R                  SS5      (       a  SUl        UR                  R                  S5      Ul        UR                  S5       HO  n[        UR                  S   5      n[        UR                  S   5      nUR&                  R)                  Xx45        MQ     UR                  S5       HJ  n	U	R+                  5        H3  u  pU
[,        :X  d  M  [/        U	R0                  5      UR2                  U'   M5     ML     UR                  S5      nUbo  SUR                  ;   a  [5        UR                  S   5      Ul        UR                  S5       H-  nUR8                  R)                  U R;                  U5      5        M/     U R                  R<                  R)                  U5        UR                  U R>                  UR                   '   GM      / U R                  l         U R                   R                  S5       GH9  nUR                  R                  S5      nUR                  S5       GH  nUR                  R                  S5      nUR                  S5      nUR                  S5      n0 n0 nUR                  S5       H/  nUR                  S
   n[        UR                  S   5      nUUU'   M1     UR                  S5       H/  nUR                  S
   n[        UR                  S   5      nUUU'   M1     U RC                  UUUUS9nU R                  R@                  R)                  U5        GM     GM<     g s  snf )Nr  r  z
.axes/axisr  rJ  r  r   r   r   r}   r/  FTr)  r0  r  r  r1  z.labelsr  z.labelz.axes/mappingsr   r   
.dimensionr  r   )"r  r`  r  r  r  r  r  r  r(   r  rJ  r  r   r   r   r   r}   r/  r)  r0  r   r[   r3  r   r4  r.  rp  r1  r2  readAxisLabelr   r  r  r  )r5   r  axisElementsr  r  sr  rt   r   labelNameElementkeyr#   r.  r  r  r   r!  r   inputElementoutputElementinputLoc	outputLocr  r}   r;   axisMappingObjects                             r.   r  BaseDocReader.readAxes  sD   iinnW-"';{?Q?Q'Q5@5G5G$6D2 yy((6'K##//69 2 22!==?
&1&8&8&B&H&H&M%&ME!H&M%
! "557
%*;+=+=+A+A)+L%M
"%*;+=+=+A+A)+L%M
"!&{'9'9'='=i'H!IJ)0044V<JO!!%%h66$(
!(//33E:JN)11%8
*++G45*++H56%%qf- 9 %0$7$7$D  "2!7!7!9ICh6;<L<Q<Q6R
--d3 ": %E '++I6L'!4!44.1,2E2Ej2Q.RJ+)11(;E))001C1CE1JK <$$++J71;1C1CDjoo.G (J ,.(#yy001ABO.5599-H"1"9"9)"D,3377F-227; . 3 3H =	"."6"6|"DJ%,,V4D!*"3"3H"=>E%*HTN #E #0"7"7"EJ%,,V4D!*"3"3H"=>E&+IdO #F %)$C$C"*#, +%5	 %D %! ##00778IJ) #E  CA%s   Sc                8   1 Skn[        UR                  5      U-
  nU(       a  [        SSR                  U5       35      eUR	                  S5      nUc  [        S5      eUR	                  S5      nUc  [        S5      e[        U5      nUR	                  S5      nUb  [        U5      OS nUR	                  S	5      n	U	b  [        U	5      OS n
UR	                  S
5      nUb  [        U5      OS nUR	                  S5      S:X  a  SOSnUR	                  S5      S:X  a  SOSnUR                  S5       VVVs0 s H@  nUR                  5         H(  u  nnU[        :X  d  M  UUR                  =(       d    S_M*     MB     nnnnU R                  UUUU
UUUUS9$ s  snnnf )N>   r}   r_  r(  r*  r)  r,  r-  z+label element contains unknown attributes: , r}   )label element must have a name attribute.r(  z.label element must have a uservalue attribute.r)  r*  r-  r_  r+  TFr,  r1  rI   )r}   r]  r\  r^  r_  r`  ra  r.  )setr  r   r'   r   r  r  r[   r3  r4  r  )r5   element	xml_attrsunknown_attrsr}   valueStrr;   
minimumStrr   
maximumStrr   linkedValueStrlinkedValuer_  r`  
label_namer`   r#   r.  s                      r.   r  BaseDocReader.readAxisLabel^  s   
	 GNN+i7*=dii>V=WX  {{6"<*+VWW;;{+*@  h[[/
'1'=%
#4[[/
'1'=%
#4 %67/=/IeN+t";;z2f<4%&{{>:fDt% &ook:
:
(..0
dx (D*//'R'0 : 	 
 ,,%'! - 	
 		

s   4%FFc           
     0   U R                   R                  S:  a  g 1 SknU R                  R                  S5       GHP  n[	        UR
                  5      U-
  nU(       a  [        SSR                  U5       35      eUR                  S5      nUc  [        S5      eU R                  U5      u  pVU(       a  [        SU S	35      eUR                  S
5      S:X  a  SOSnUR                  S5      S:X  a  SOSnUR                  S5       V	V
Vs0 s H>  n	U	R                  5         H&  u  pU
[        :X  d  M  XR                  =(       d    S_M(     M@     nn
n	nU R                  UUUUUS9nU R                   R                  R                  U5        GMS     g s  snn
n	f )Nr  >   r}   r_  r,  z.labels/labelz+Label element contains unknown attributes: r  r}   r  z<label> element "z5" must only have user locations (using uservalue="").r_  r+  TFr,  r1  rI   rt  )r  r  r  r  r  r  r   r'   r   locationFromElementr[   r3  r4  r  r  r   )r5   r  r.  r  r}   r   r   r_  r`  r  r`   r#   r.  r   s                 r.   r  BaseDocReader.readLabels  s   **V38	 II--o>L 3 34y@M.A$))MBZA[\   ##F+D|.?  ,0+C+CL+Q(N.'v-bc   ,//
;vEt5H#/#3#3N#Cv#M4SXL #/"6"6{"C"CJ","2"2"4JD8# ,oo++"4 "C   !==)!)% > M ..55mDE ?&s   
$F
2F
c                   U R                   R                  S:  a  g SS1nU R                  R                  S5       GH/  n[	        UR
                  5      U-
  nU(       a  [        SSR                  U5       35      eUR                  S5      nUc  [        S5      eUR                  S5      nUR                  S5      nUc  [        S	5      e/ nUR                  S
5       H#  nUR                  U R                  U5      5        M%     S n	UR                  S5      n
U
b  [        R                  " U
S   5      n	U R                  UUUU	S9nU R                   R                   R                  U5        GM2     g )Nr  r}   r|   z.variable-fonts/variable-fontz3variable-font element contains unknown attributes: r  z1variable-font element must have a name attribute.z.axis-subsetsz;variable-font element must contain an axis-subsets element.z.axis-subset.libr   r~  )r  r  r  r  r  r  r   r'   r   r`  iterfindr   readAxisSubsetr   fromtreevariableFontsDescriptorClassr  )r5   r  variableFontElementr  r}   r|   axisSubsetsElementr|  
axisSubsetr   rb  r  s               r.   r  BaseDocReader.readVariableFonts  s   **V3Z(	#'99#4#45T#U 3 : :;iGM.I$))TaJbIcd  '**62D|.G  +..z:H!4!9!9/!J!).Q  K099.I
""4#6#6z#BC J C,11&9J%''
16<<!'	 = L --44\BG $Vr0   c                H   SUR                   ;   a  SS1n[        UR                   5      U-
  nU(       a  [        SSR                  U5       35      eUR	                  S5      nUc  [        S5      eUR	                  S5      nUc  [        S5      e[        U5      nU R                  XFS9$ 1 Skn[        UR                   5      U-
  nU(       a  [        SSR                  U5       35      eUR	                  S5      nUc  [        S5      eUR	                  S	5      nUR	                  S
5      nUR	                  S5      n	Ub3  Ub0  U	b-  U R                  U[        U5      [        U5      [        U	5      S9$ [        S XxU	4 5       5      (       a  U R                  US9$ [        S5      e)Nr(  r}   z1axis-subset element contains unknown attributes: r  z/axis-subset element must have a name attribute.zNThe axis-subset element for a discrete subset must have a uservalue attribute.r  >   r}   rg  r*  r)  r)  rg  r*  r  c              3  (   #    U  H  oS L v   M
     g 7fr3   rS   )r   ra   s     r.   r   /BaseDocReader.readAxisSubset.<locals>.<genexpr>	  s     N&M9&Ms   r}   zDaxis-subset element must have min/max/default values or none at all.)	r  r  r   r'   r   r  r  r  all)
r5   r  r  r  r}   userValueStrr]  r\  r  r^  s
             r.   r  BaseDocReader.readAxisSubset  s   '..(-I/);M.G		R_H`Gab  ;;v&D|.E  #;;{3L#.d  l+I66D6VVMI/);M.G		R_H`Gab  ;;v&D|.E  "++m4K!++m4K!++m4K'++:: %k 2 %k 2 %k 2	 ;   N{&MNNN:::EE*V r0   c                   [        U R                  R                  S5      5       GH  u  pUR                  R	                  S5      nUbr  U R
                  be  [        R
                  R                  [        R
                  R                  [        R
                  R                  U R
                  5      U5      5      nOS nUR                  R	                  S5      nUc  SU-  nU R                  5       nXFl        X6l        XVl        UR                  R	                  S5      nUb  Xvl        UR                  R	                  S5      nUb  Xl        UR                  S5       HE  n	U	R                  5        H.  u  pU
[         :X  d  M  U	R"                  nUR%                  X{5        M0     MG     U R'                  U5      u  pU(       a  [)        SU S35      eXl        UR                  R	                  S	5      nUb  Xl        UR                  S
5       H+  nUR                  R	                  S5      S:X  d  M$  SUl        M-     UR                  S5       H+  nUR                  R	                  S5      S:X  d  M$  SUl        M-     UR                  S5       HQ  nUR                  R	                  S5      S:X  a  SUl        UR                  R	                  S5      S:X  d  MJ  SUl        MS     UR                  S5       H+  nUR                  R	                  S5      S:X  d  M$  SUl        M-     UR                  S5       H_  nUR                  R	                  S5      nUc  M#  UR                  R	                  S5      S:X  d  MD  UR8                  R;                  U5        Ma     UR                  S5       H+  nUR                  R	                  S5      S:X  d  M$  SUl        M-     U R>                  R@                  R;                  U5        GM     g )Nz.sources/sourcer|   r}   ztemp_master.%drA  rB  z<source> element "4" must only have design locations (using xvalue="").rZ  r  r[  r  Tz.groupsz.infor^  z	.featuresz.glyphz.kerning)!	enumerater  r  r  r   r*   r)   abspathr'   dirnamer  r|   r}   r   r   r[   r3  r4  r   r  r   r   r~   r   r   r   r   r   r   r   r   r  r  )r5   sourceCountra  r|   
sourcePath
sourceNamer  r   r   familyNameElementr  r#   r   r   r~   rb  rc  rV  rd  rT  rR  rU  s                         r.   r  BaseDocReader.readSources	  sw   *3II/0+
&K %++//
;H#		(=WW__GGLL!;XF
 "
&--11&9J!-=
557L *$,! *&--11,?J%*4'%,,00=I$)2&%2%:%:<%H!!2!8!8!:ICh%6%;%;
$22:D "; &I
 ,0+C+CM+R(N.(4hi  %3!%,,009I$)2&+33F;
$$((0C7+/L( < "/!6!6y!A ''++F3s:.2L+ "B  -44W=%%))&1S8,0L)%%))&1S8,0L)	  >
 $1#8#8#E"))--f5<04L- $F !. 5 5h ?(//33F;	$&&**62c9 0077	B !@ #0"7"7
"C!((,,V4;/3L, #D ''..|<{+
r0   c                ^    SnUR                  S5       H  nU R                  U5      n  U$    U$ )zRead a nested ``<location>`` element inside the given ``element``.

.. versionchanged:: 5.0
   Return a tuple of (designLocation, userLocation)
NNz	.location)r  readLocationElement)r5   r  elementLocationrP  s       r.   r  !BaseDocReader.locationFromElement^	  s=     '&{;O"66GO  < r0   c                   U R                   (       a&  U R                  R                  (       d  [        S5      e0 n0 nUR	                  S5       GH0  nUR
                  R                  S5      nU R                   (       a-  XPR                  ;  a  U R                  R                  SU5        M]  S=n=px UR
                  R                  S5      nUb  [        U5      n UR
                  R                  S5      nUb  [        U5      n UR
                  R                  S
5      nUb  [        U5      nUSs=L a
  Us=:X  a  c  O  O[        SU S35      eUb  Uc  [        SU SU S35      eXx4X5'   GM"  Ub  XsU'   GM,  XbU'   GM3     X24$ ! [         a    U R                  R                  SU5         Nf = f! [         a    U R                  R                  S	U5         Nf = f! [         a    U R                  R                  SU5         Nf = f)zlRead a ``<location>`` element.

.. versionchanged:: 5.0
   Return a tuple of (designLocation, userLocation)
zNo axes definedr  r}   z#Location with undefined axis: "%s".Nr(  z*ValueError in readLocation userValue %3.3fr  z'ValueError in readLocation xValue %3.3fr  z'ValueError in readLocation yValue %3.3fzRExactly one of uservalue="" or xvalue="" must be provided for location dimension ""z.Missing xvalue="" for the location dimension "z"" with yvalue=")r  r  r   r   r  r  r   r  r  warningr  
ValueError)	r5   rP  userLoc	designLocr%  dimNamer]  xValueyValues	            r.   r  !BaseDocReader.readLocationElementj	  s      )<)<)A)A*+<==	 / 7 7 E&--11&9G$$8I8I)I  !FP*..I.,3377D	( %i 0I
T)0044X>%"6]FT)0044X>%"6]F D2F22.hiphqqrs  !>2H	Qabhaiijk  '-%5	"#%+'"#, Q !FR !!=    @)  T  !JFST  T  !JFSTs6   0)F)F1)G&F.-F.1&GG&HHc                p    U R                   R                  S5      nU H  nU R                  UUUUS9  M     g )Nz.instances/instance)
makeGlyphsmakeKerningmakeInfo)r  r  _readSingleInstanceElement)r5   r  r   r  instanceElementsrI  s         r.   r  BaseDocReader.readInstances	  sA    99,,-BC/O++%'!	 ,   0r0   c                   UR                   R                  S5      nUbi  U R                  R                  bR  [        R                  R                  [        R                  R                  U R                  R                  5      U5      nOS nU R                  5       nXgl        XWl        UR                   R                  S5      nUb  Xl	        UR                   R                  S5      n	U	b  Xl
        UR                   R                  S5      n
U
b  Xl        UR                   R                  S5      nUb  Xl        UR                   R                  S5      nUb  Xl        UR                   R                  S5      nUb  Xl        UR                  S5       HG  nUR!                  5        H0  u  nnU["        :X  d  M  UR$                  nUR'                  UU5        M2     MI     UR                  S5       HG  nUR!                  5        H0  u  nnU["        :X  d  M  UR$                  nUR)                  UU5        M2     MI     UR                  S5       HG  nUR!                  5        H0  u  nnU["        :X  d  M  UR$                  nUR+                  UU5        M2     MI     UR                  S5       HG  nUR!                  5        H0  u  nnU["        :X  d  M  UR$                  nUR-                  UU5        M2     MI     U R/                  U5      u  nnUR                   R                  S5      nU(       d  U(       a  Ub  [1        S	5      eUUl        U=(       d    0 Ul        U=(       d    0 Ul        UR                  S
5       H  nU R9                  UU5        M     UR                  S5       H  nU R;                  UU5        M     UR                  S5       H  nU R=                  UU5        M     U R                  R>                  RA                  U5        g )Nr|   r}   rA  rB  rE  rD  rC  r   zeinstance element must have at most one of the location="..." attribute or the nested location elementz.glyphs/glyphr   r   )!r  r   r  r*   r)   r'   r  r  r|   r}   r   r   r   r   r   r  r[   r3  r4  r   r   r   r   r  r   r   r   r   readGlyphElementreadInfoElementreadLibElementr  r   )r5   rI  r  r   r  r|   instancePathr  r}   rA  rB  r   r   r   styleNameElementr  r#   r   r  r   styleMapStyleNameElementstyleMapFamilyNameElementr   r   r   rT  rV  rb  s                               r.   r  (BaseDocReader._readSingleInstanceElement	  s    #))--j9D$7$7$<$<$H77<< 3 3 8 898L  L557*"*%%))&1"&$++//=
!(2%#**..{;	 '0$,33778LM)0B-,33778LM)0B-+22667JK(/@, / 7 7 D-335	T(? 0 5 5I"//	4@ 6 !E
 "1!8!8!F.446	T(?!2!7!7J"00TB 7 "G
 )8(?(?@S(T$5;;=	T(?(@(E(E%"778I4P > )U
 *9)@)@AU)V%6<<>	T(?)B)G)G&"889KTR ? *W
 (,'?'?'P$'..22:>l0I*w  (5$&2&8b#(6(<"%+33ODL!!,? E*226:K  n= ;)11%8J
N; 9%%,,^<r0   c                @    [         R                  " US   5      Ul        g)z,Read the lib element for the given instance.r   N)r   r  r   )r5   rb  r  s      r.   r  BaseDocReader.readLibElement	  s    %..z!}=r0   c                    SUl         g)zRead the info element.TN)r   )r5   rV  r  s      r.   r  BaseDocReader.readInfoElement	  s
    "r0   c                   0 nUR                   R                  S5      nUc  [        S5      eUR                   R                  S5      nUS:X  a  SUS'   UR                   R                  S5      nUb0   UR                  S5       Vs/ s H  n[	        US	5      PM     nnXcS
'   UR                  S5       H  nUR                  US'     O   U R                  U5      u  pU
(       a  [        SU S35      eU	b  XS'   SnUR                  S5       H  nUR                   R                  S5      nU R                  U5      u  pU
(       a  [        SU S35      eUR                   R                  S5      nUc  Un[        XUS9nUc  / nUR                  U5        M     Ub  XS'   X2R                  U'   gs  snf ! [
         a    [        SU-  5      ef = f)a  
Read the glyph element, which could look like either one of these:

.. code-block:: xml

    <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>
r}   Nz#Glyph object without name attributer^  r  Trt  r     rs  z"unicode values %s are not integersz.noterv  z<glyph> element "r  ru  z.masters/masterr{   z<master> element "ry  )r   r   rR  rw  )r  r   r   r(   rp  r  r  r4  r  r%  r   r   )r5   rT  r  	glyphDatarR  r^  rs  r{  r|  r   r   glyphSourcesr  fontSourceNamemasterGlyphNamer_   s                   r.   r  BaseDocReader.readGlyphElement	  s   $ 	 ''++F3	*+PQQ""&&v.3; $If&&**9508s0CD0C1C2J0CD(0*% (//8K + 0 0If 9 (,'?'?'M$*#I;.bc  %,:())112CDM*1155h?N+/+C+CM+R(N.((88lm  ,2266{CO&"+#A #!"! E" ##/i +4i(K E .88C s   1F0 F+F0 +F0 0G	c                    U R                   R                  S5       H+  n[        R                  " US   5      U R                  l        M-     g)z,Read the lib element for the whole document.r  r   N)r  r  r   r  r  r   )r5   rb  s     r.   r  BaseDocReader.readLib:
  s8    ))++F3J&.&7&7
1&FD# 4r0   )	r  r  r  r  r  r*   r  r   r  r3   )r  r  )TTT)/rN   rO   rP   rQ   r   r  r   r  r   r  r   r  r   r  r   r  r    r  r"   r  r!   r  r   r  r   r  rF   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rR   rS   r0   r.   r   r     s    ("82!6#: (,#9 %>"%>"0%  '*R4FKP2
h'ER(CT7r>=@
3"j LPC=J>#B5HGr0   r   c                     \ rS rSrSrS.S jr\S.S j5       r\S.S j5       rS/S jr	S r
S	 rS
 rS rS0S jrS rS1S jrS rS2S jrS rS3S jrS rS4S jrS rS5S jrS rS6S jrS rS r    S7S jrS8S jrS rS r S r!S  r"S9S! jr#S:S" jr$S;S# jr%S<S$ jr&    S=S% jr'S& r(S' r)S( r*S) r+\,S* 5       r-S>S+ jr.S, r/S-r0g)?r   i@
  aE  The DesignSpaceDocument object can read and write ``.designspace`` data.
It imports the axes, sources, variable fonts and instances to very basic
**descriptor** objects that store the data in attributes. Data is added to
the document by creating such descriptor objects, filling them with data
and then adding them to the document. This makes it easy to integrate this
object in different contexts.

The **DesignSpaceDocument** object can be subclassed to work with
different objects, as long as they have the same attributes. Reader and
Writer objects can be subclassed as well.

**Note:** Python attribute names are usually camelCased, the
corresponding `XML <document-xml-structure>`_ attributes are usually
all lowercase.

.. code:: python

    from fontTools.designspaceLib import DesignSpaceDocument
    doc = DesignSpaceDocument.fromfile("some/path/to/my.designspace")
    doc.formatVersion
    doc.elidedFallbackName
    doc.axes
    doc.axisMappings
    doc.locationLabels
    doc.rules
    doc.rulesProcessingLast
    doc.sources
    doc.variableFonts
    doc.instances
    doc.lib

Nc                8   S U l          S U l         S U l         S U l         / U l         / U l         / U l         / U l         SU l         / U l	         / U l
         / U l         0 U l         S U l         Ub  Xl        O[        U l        Ub  X l        g ["        U l        g )NF)r*   r|   r  r  r   r  r  r   r  r  r  r  r   r   readerClassr   writerClassr   )r5   r  r  s      r.   rF   DesignSpaceDocument.__init__b
  s    		 	 -1H15	 JL	+9;4=?	! ,.
,). 	. 02.;=	! 460	 '+	
 "*,D"*,Dr0   c                4    U " X#S9nUR                  U5        U$ )zLRead a designspace file from ``path`` and return a new instance of
:class:.
r  r  )r  )r  r*   r  r  r5   s        r.   fromfileDesignSpaceDocument.fromfile
  s    
 {D		$r0   c                    U " X#S9nUR                   R                  X5      nUR                  5         UR                  (       a  UR	                  5         U$ )Nr!  )r  r  r  r  findDefault)r  r  r  r  r5   readers         r.   r  DesignSpaceDocument.fromstring
  sC    {D!!,,V:<<r0   c                   U[         L d  Ub!  UR                  5       S:X  a  [        5       nSnO&Ub  US:X  a  [        5       nSnSnO[	        SU-  5      eU R                  X 5      nUR                  XS9  UR                  5       $ )z@Returns the designspace as a string. Default encoding ``utf-8``.rt  Fr  r  Tzunsupported encoding: '%s')r  r  )rJ   r&  r   r   r  r  r  getvalue)r5   r  r  r  writers        r.   tostringDesignSpaceDocument.tostring
  s    s?x38HI8U
A#OW!4	AH"O9HDEE!!!*hHzz|r0   c                    [        US5      (       a  UR                  5       nXl        [        R                  R	                  U5      U l        U R                  X5      nUR                  5         U R                  (       a  U R                  5         gg)zZRead a designspace file from ``path`` and populates the fields of
``self`` with the data.

__fspath__N)
r\   r.  r*   r)   basenamer|   r  r  r  r%  )r5   r*   r&  s      r.   r  DesignSpaceDocument.read
  si     4&&??$D	((.!!$-<< r0   c                    [        US5      (       a  UR                  5       nXl        [        R                  R	                  U5      U l        U R                  5         U R                  X5      nUR                  5         g)z#Write this designspace to ``path``.r.  N)	r\   r.  r*   r)   r/  r|   updatePathsr  r  )r5   r*   r*  s      r.   r  DesignSpaceDocument.write
  s[    4&&??$D	((.!!$-r0   c                    [         R                  R                  U[         R                  R                  U R                  5      5      n[	        U5      $ r3   )r)   r*   relpathr  r/   )r5   	otherPathrelatives      r.   _posixRelativePath&DesignSpaceDocument._posixRelativePath
  s1    77??9bggoodii.HIXr0   c                    U R                   c   eU R                  U R                  -    H2  nUR                   c  M  U R                  UR                   5      Ul        M4     g)a=  
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.
N)r*   r  r  r8  r|   )r5   
descriptors     r.   r2  DesignSpaceDocument.updatePaths
  sM    T yy$$$,,7J*&*&=&=joo&N
# 8r0   c                :    U R                   R                  U5        g)z6Add the given ``sourceDescriptor`` to ``doc.sources``.N)r  r   )r5   sourceDescriptors     r.   	addSourceDesignSpaceDocument.addSource)  s    ,-r0   c                `    U R                   R                  " S0 UD6nU R                  U5        U$ )zfInstantiate a new :class:`SourceDescriptor` using the given
``kwargs`` and add it to ``doc.sources``.
rS   )r  r  r?  )r5   kwargsr{   s      r.   addSourceDescriptor'DesignSpaceDocument.addSourceDescriptor-  s.     !!77A&Avr0   c                :    U R                   R                  U5        g)z:Add the given ``instanceDescriptor`` to :attr:`instances`.N)r  r   )r5   instanceDescriptors     r.   addInstanceDesignSpaceDocument.addInstance5  s    01r0   c                `    U R                   R                  " S0 UD6nU R                  U5        U$ )zjInstantiate a new :class:`InstanceDescriptor` using the given
``kwargs`` and add it to :attr:`instances`.
rS   )r  r  rG  )r5   rB  r   s      r.   addInstanceDescriptor)DesignSpaceDocument.addInstanceDescriptor9  s0     ##;;EfE"r0   c                :    U R                   R                  U5        g)z1Add the given ``axisDescriptor`` to :attr:`axes`.N)r   r   )r5   axisDescriptors     r.   addAxisDesignSpaceDocument.addAxisA  s    		(r0   c                    SU;   a  U R                   R                  " S0 UD6nOU R                   R                  " S0 UD6nU R                  U5        U$ )zInstantiate a new :class:`AxisDescriptor` using the given
``kwargs`` and add it to :attr:`axes`.

The axis will be and instance of :class:`DiscreteAxisDescriptor` if
the ``kwargs`` provide a ``value``, or a :class:`AxisDescriptor` otherwise.
rJ  rS   )r  r  r  rN  )r5   rB  r   s      r.   addAxisDescriptor%DesignSpaceDocument.addAxisDescriptorE  sO     v##??I&ID##77A&ADTr0   c                :    U R                   R                  U5        g)z@Add the given ``axisMappingDescriptor`` to :attr:`axisMappings`.N)r  r   )r5   axisMappingDescriptors     r.   addAxisMapping"DesignSpaceDocument.addAxisMappingS  s      !67r0   c                `    U R                   R                  " S0 UD6nU R                  U5        U$ )ziInstantiate a new :class:`AxisMappingDescriptor` using the given
``kwargs`` and add it to :attr:`rules`.
rS   )r  r  rU  )r5   rB  axisMappings      r.   addAxisMappingDescriptor,DesignSpaceDocument.addAxisMappingDescriptorW  s1     &&AAKFKK(r0   c                :    U R                   R                  U5        g)z2Add the given ``ruleDescriptor`` to :attr:`rules`.N)r   r   )r5   ruleDescriptors     r.   addRuleDesignSpaceDocument.addRule_  s    

.)r0   c                `    U R                   R                  " S0 UD6nU R                  U5        U$ )zbInstantiate a new :class:`RuleDescriptor` using the given
``kwargs`` and add it to :attr:`rules`.
rS   )r  r  r]  )r5   rB  r   s      r.   addRuleDescriptor%DesignSpaceDocument.addRuleDescriptorc  s.     33=f=Tr0   c                :    U R                   R                  U5        g)zZAdd the given ``variableFontDescriptor`` to :attr:`variableFonts`.

.. versionadded:: 5.0
N)r  r   )r5   variableFontDescriptors     r.   addVariableFont#DesignSpaceDocument.addVariableFontk  s    
 	!!"89r0   c                `    U R                   R                  " S0 UD6nU R                  U5        U$ )zInstantiate a new :class:`VariableFontDescriptor` using the given
``kwargs`` and add it to :attr:`variableFonts`.

.. versionadded:: 5.0
rS   )r  r  rd  )r5   rB  r  s      r.   addVariableFontDescriptor-DesignSpaceDocument.addVariableFontDescriptorr  s1     ''CCMfM\*r0   c                :    U R                   R                  U5        g)z\Add the given ``locationLabelDescriptor`` to :attr:`locationLabels`.

.. versionadded:: 5.0
N)r  r   )r5   locationLabelDescriptors     r.   addLocationLabel$DesignSpaceDocument.addLocationLabel|  s    
 	""#:;r0   c                `    U R                   R                  " S0 UD6nU R                  U5        U$ )zInstantiate a new :class:`LocationLabelDescriptor` using the given
``kwargs`` and add it to :attr:`locationLabels`.

.. versionadded:: 5.0
rS   )r  r  rk  )r5   rB  r   s      r.   addLocationLabelDescriptor.DesignSpaceDocument.addLocationLabelDescriptor  s1     ((EEOOm,r0   c                    [         R                  " 5       nU R                   H*  nUR                  UR                  5      XR
                  '   M,     U$ )zDReturn a dict with the default location in design space coordinates.)collectionsOrderedDictr   r   r   r}   )r5   locrM  s      r.   r  &DesignSpaceDocument.newDefaultLocation  sI     %%'"iiN'5'A'A&&(C##$ ( 
r0   c                D   ^ [        U4S jU R                   5       S5      $ )zReturn the :class:`LocationLabel` that matches the given
``userLocation``, or ``None`` if no such label exists.

.. versionadded:: 5.0
c              3  L   >#    U  H  nUR                   T:X  d  M  Uv   M     g 7fr3   r:  )r   r  r   s     r.   r   ;DesignSpaceDocument.labelForUserLocation.<locals>.<genexpr>  s(      0E%%5 0s   $	$N)rS  r  )r5   r   s    `r.   labelForUserLocation(DesignSpaceDocument.labelForUserLocation  s*     !00
 
 	
r0   c                   U(       aX  U R                    HH  nUR                  b	  U(       d  M  U R                  c  M(  U R                  UR                  5      Ul        MJ     U(       aY  U R                   HH  nUR                  b	  U(       d  M  U R                  c  M(  U R                  UR                  5      Ul        MJ     gg)zvSet a descriptor filename attr from the path and this document path.

If the filename attribute is not None: skip it.
N)r  r|   r*   r8  r  )r5   rw  r  forcer;  s        r.   updateFilenameFromPath*DesignSpaceDocument.updateFilenameFromPath  s    
 "ll
&&2599(*.*A*A*//*RJ'	 +
 "nn
&&2599(*.*A*A*//*RJ'	 - r0   c                6    U R                   R                  5       $ )z5Ask the writer class to make us a new axisDescriptor.)r  r  rK   s    r.   newAxisDescriptor%DesignSpaceDocument.newAxisDescriptor  s    0022r0   c                6    U R                   R                  5       $ )z7Ask the writer class to make us a new sourceDescriptor.)r  r  rK   s    r.   newSourceDescriptor'DesignSpaceDocument.newSourceDescriptor  s    3355r0   c                6    U R                   R                  5       $ )z9Ask the writer class to make us a new instanceDescriptor.)r  r  rK   s    r.   newInstanceDescriptor)DesignSpaceDocument.newInstanceDescriptor  s    5577r0   c                f    / nU R                    H  nUR                  UR                  5        M      U$ )zJReturn a list of axis names, in the same order as defined in the document.)r   r   r}   )r5   r(  rM  s      r.   getAxisOrder DesignSpaceDocument.getAxisOrder  s,    "iiNLL,,- (r0   c                D   ^ [        U4S jU R                   5       S5      $ )zLReturn the axis with the given ``name``, or ``None`` if no such axis exists.c              3  J   >#    U  H  oR                   T:X  d  M  Uv   M     g 7fr3   r  )r   r   r}   s     r.   r   .DesignSpaceDocument.getAxis.<locals>.<genexpr>  s     Eid993DTTi   #	#NrS  r   )r5   r}   s    `r.   getAxisDesignSpaceDocument.getAxis  s    EdiiEtLLr0   c                D   ^ [        U4S jU R                   5       S5      $ )zKReturn the axis with the given ``tag``, or ``None`` if no such axis exists.c              3  J   >#    U  H  oR                   T:X  d  M  Uv   M     g 7fr3   )r)  )r   r   r)  s     r.   r   3DesignSpaceDocument.getAxisByTag.<locals>.<genexpr>  s     Cid88s?TTir  Nr  )r5   r)  s    `r.   getAxisByTag DesignSpaceDocument.getAxisByTag  s    CdiiCTJJr0   c                R    U R                    H  nUR                  U:X  d  M  Us  $    g)zyReturn the top-level location label with the given ``name``, or
``None`` if no such label exists.

.. versionadded:: 5.0
N)r  r}   )r5   r}   r  s      r.   r  $DesignSpaceDocument.getLocationLabel  s*     ((EzzT! ) r0   c           
         U R                    Vs0 s HC  nUR                  UR                  UR                  UR                  UR                  5      5      _ME     sn$ s  snf )zMap a user location to a design location.

Assume that missing coordinates are at the default location for that axis.

Note: the output won't be anisotropic, only the xvalue is set.

.. versionadded:: 5.0
)r   r}   r   r   r   )r5   r   r   s      r.   r   DesignSpaceDocument.map_forward  sV     		
! IIt''(8(8DLL(QRR!
 	
 
s   A
Ac                    U R                    Vs0 s HG  nUR                  UR                  U;   a  UR                  XR                     5      OUR                  _MI     sn$ s  snf )zMap a design location to a user location.

Assume that missing coordinates are at the default location for that axis.

When the input has anisotropic locations, only the xvalue is used.

.. versionadded:: 5.0
)r   r}   r  r   )r5   r   r   s      r.   r   DesignSpaceDocument.map_backward  sd    " 		
 " II99. !!.";<\\"
 "
 	
 
s   AA c                    SU l         U R                  5       nU R                   H"  nUR                  U 5      U:X  d  M  X l         Us  $    g)a  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.

This function updates the document's :attr:`default` value.

.. versionchanged:: 5.0
   Allow the default source to not specify some of the axis values, and
   they are assumed to be the default.
   See :meth:`SourceDescriptor.getFullDesignLocation()`
N)r   r  r  r   )r5   defaultDesignLocationr>  s      r.   r%  DesignSpaceDocument.findDefault  sO      !% 7 7 9 $55d;?TT/'' !-
 r0   c                d   SSK Jn  0 nU R                   H  nUR                  U;  a  M  XR                     n[	        U[
        5      (       a  US   nUR                  UR                  UR                  4 Vs/ s H  odR                  U5      PM     nnU" XW5      X4R                  '   M     U$ s  snf )z*Return a dict with normalized axis values.r   )normalizeValue)
r@  r  r   r}   r]   rE  r   r   r   r   )r5   r   r  newr   r;   ra   triples           r.   normalizeLocation%DesignSpaceDocument.normalizeLocation  s    :IIDyy(YY'E%''a.2llDLL$,,-W-W  #-W   ,E:C		N  
	s   7B-c                   U R                    H#  nU R                  UR                  5      Ul        M%     U R                   H  nUR                  R                  5        H?  u  p#U R                  US   5      US'   US    H  nU R                  US   5      US'   M     MA     U R                  UR                  5      Ul        M     U R                   GHB  n/ nUR                   HM  u  pxU R                  UR                  U05      R                  UR                  5      n	UR                  Xy45        MO     U(       a  Xel        U R                  UR                  UR                  05      R                  UR                  5      n
U R                  UR                  UR                  05      R                  UR                  5      nU R                  UR                  UR                  05      R                  UR                  5      nXl        Xl        Xl        GME     U R                   H  n/ nUR                   H  n/ nU H  nUR                  S5      b,  U R                  US   US   05      R                  US   5      n
OSn
UR                  S5      b,  U R                  US   US   05      R                  US   5      nOSnUR                  [!        US   XS95        M     UR                  U5        M     Xl        M     g)	z
Normalise the geometry of this designspace:

- scale all the locations of all masters and instances to the -1 - 0 - 1 value.
- we need the axis data to do the scaling, so we do those last.
ru  rw  r   r   Nr}   r   )r}   r   r   )r  r  r   r  r   r[   r   r0  r}   r   r   r   r   r   r   r   r%  )r5   itemrX   r  glyphMasterr   newMapr  r  newOutputValuer   r   r   r   newConditionSetsr   newConditionsr  s                     r.   	normalizeDesignSpaceDocument.normalize0  s    LLD 224==ADM ! NND $ 1 1 3040F0F011	,- $-Y#7K.2.D.D#J//K
+ $8	 !4 !224==ADM # IIDF+/88'
!%!7!7K8P!Q!U!UII" z:;	 ,4
 !,,dii-FGKKDIIVG,,dii-FGKKDIIVG,,dii-FGKKDIIVG"L"L"L# & JJD!"00
 "&Dxx	*6"&"8"8!&\4	?;##d6l+   #'xx	*6"&"8"8!&\4	?;##d6l+   #'!(($v,Q '  !''6% 1& "2+ r0   c                   0 n/ nU R                    H  nUR                  b  UR                  UR                  5        M-  UR                  U;   a  X5R                     Ul        O^UR                  c!  [	        SUR
                  =(       d    S-  5      eU" UR                  40 UD6Ul        UR                  X5R                  '   UR                  UR                  5        M     U$ )a  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)

Args:
    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.
z/Designspace source '%s' has no 'path' attributez	<Unknown>)r  r   r   r*   r   r}   )r5   openerrB  loadedfontsr{   s         r.   loadSourceFonts#DesignSpaceDocument.loadSourceFontsq  s    8 llF{{&V[[){{f$$[[1;;&2I!;;5+7  %V[[;F;&,kk{{#LL% # r0   c                    U R                   c  gS U R                   R                  S5       5       n[        U5      n[        US5      nX#4$ )zNReturn the formatVersion as a tuple of (major, minor).

.. versionadded:: 5.0
r  c              3  8   #    U  H  n[        U5      v   M     g 7fr3   )rp  r  s     r.   r   2DesignSpaceDocument.formatTuple.<locals>.<genexpr>  s     A#@a3q66#@r  r  r   )r  r(   rS  )r5   numbersmajorminors       r.   r  DesignSpaceDocument.formatTuple  sK     %A4#5#5#;#;C#@AWWa ~r0   c                   U R                   (       a  U R                   $ / n/ n/ nU R                   HY  n[        US5      (       a#  [        [        U5      nUR                  U5        M7  UR                  [        UR                  S95        M[     [        R                  " U Vs/ s H  oDR                  PM     sn6 nU GH.  nSnU R                  b/  [        R                  R                  U R                  5      S   S-   nU R                  bL  [        R                  R                  [        R                  R                  U R                  5      5      S   S-   nUc  SnSR!                  [#        X&5       VVs/ s H  u  pHSUR$                   U 3PM     snn5      n	UR                  ['        U U	 3U[#        X&5       VVs/ s H  u  pH[)        UR                  US	9PM     snn-   S
95        GM1     U$ s  snf s  snnf s  snnf )a  Return all variable fonts defined in this document, or implicit
variable fonts that can be built from the document's continuous axes.

In the case of Designspace documents before version 5, the whole
document was implicitly describing a variable font that covers the
whole space.

In version 5 and above documents, there can be as many variable fonts
as there are locations on discrete axes.

.. seealso:: :func:`splitInterpolable`

.. versionadded:: 5.0
rJ  r  Nr   z-VFVFrI   -r  )r}   r|  )r  r   r\   r   r   r   r   r}   	itertoolsproductrJ  r|   r)   r*   splitextr/  r'   zipr)  r"   r!   )
r5   r  discreteAxesrangeAxisSubsetsr   valueCombinationsrJ  r/  r;   	axisNamess
             r.   getVariableFonts$DesignSpaceDocument.getVariableFonts  s    %%%  	 IIDtX&& 2D9##D) ''(Atyy(QR  &--/U/UV'FH}}(77++DMM:1=Eyy$77++BGG,<,<TYY,GHKeS:=l:ST:S;41TXXJug&:STI   &$:i[1 0 ,/|+D+DKD 2tyyER+D!	 (* - 0V Us   !G15G6> G<c                   U R                    Vs/ s H  oR                  PM     nn U R                    H
  nSUl        M     [        R                  " U 5      n[	        UR                   U5       H  u  pXAl        M     U[	        U R                   U5       H  u  pXAl        M     $ s  snf ! [	        U R                   U5       H  u  pXAl        M     f = f)zAllow deep-copying a DesignSpace document without deep-copying
attached UFO fonts or TTFont objects. The :attr:`font` attribute
is shared by reference between the original and the copy.

.. versionadded:: 5.0
N)r  r   r[  deepcopyr  )r5   r{   r  resr   s        r.   deepcopyExceptFonts'DesignSpaceDocument.deepcopyExceptFonts  s     ,0<<8<<8		#,," '--%C #CKK 7" !8 #DLL% 8" !9 9 !$DLL% 8" !9s   B#AB( ('C)r   r  r   r  r|   r  r  r   r  r*   r  r   r  r  r  r  r  r3   )r>  r    )rF  r   )rM  z-Union[AxisDescriptor, DiscreteAxisDescriptor])rT  r   )r\  r   )rc  r"   )rj  r   )r   r   r   r  )TTF)r}   rJ   r   .AxisDescriptor | DiscreteAxisDescriptor | None)r)  rJ   r   r  )r}   rJ   r   r  )r   r   r   r   )r   r  r   r   )r   zList[VariableFontDescriptor])1rN   rO   rP   rQ   rx   rF   r  r"  r  r+  r  r  r8  r2  r?  rC  rG  rJ  rN  rQ  rU  rY  r]  r`  rd  rg  rk  rn  r  rx  r|  r  r  r  r  r  r  r  r   r  r%  r  r  r  r>   r  r  r  rR   rS   r0   r.   r   r   @
  s,   BY-v    .O`.2)8*:<	
.
	*
"S$368MK	

5
	
(4&?2B-^ 
 
6p#r0   r   c                @   U c  SSK nUR                  SS n SSKJn  U" S[        R
                  S9nUR                  S5        UR                  S5        UR                  U 5      n[        R                  UR                  5      nUR                  UR                  5        g)	zARoundtrip .designspace file through the DesignSpaceDocument classNr   rg  )ArgumentParserdesignspaceLib)progr   r  r  )sysargvargparser  mainrx   add_argument
parse_argsr   r"  r  r  r  )argsr  r  parseroptionsdss         r.   r  r    s     |xx|'!1t||LF
 
!%G		%	%gmm	4BHHW^^r0   r3   )Brx   
__future__r   rq  r[  r  r  r)   r&   ior   r   textwrapr   typingr   r   r	   r
   r   r   r   r   fontTools.miscr   r  r   fontTools.misc.loggingToolsr   fontTools.misc.textToolsr   r   __all__XML_NSr3  r/   r?   	Exceptionr   r  rU   rd   r    r   r   r   r   rJ   r  r  r   r   r   r*  r,  r   r   r   r   r"   r   r!   r   r   r   r  rS   r0   r.   <module>r     s   #     	     P P P & # 0 3( 
2F?	$ Sy S& 9{ 92\' \~1% 1hL
&2 sE%ue|1D*D$EEF #u*% >, >BUA) UAp
$;- ;|iB+ iBX[C3 [C|R6* R6j>
. >
B*>- *>Z 0 >K 0 K$zF zzT
GH T
Gnv
#(K v
#rr0   