
    h                   >   S r SSKJr  SSKrSSKrSSKJ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Jr  SSKJr  SSKJrJr  SS	KJr  SS
KJr  SSKJrJrJrJrJrJrJ r   SSKJ!r!  SSK"J#r#J$r$  SSK%J&r&J'r'  / SQr(\RR                  " \*5      r+Sr,Sr- " S S\.\'\R^                  5      r0\'Rb                  \0l1         " S S5      r2 " S S\#5      r3S r4    SVS jr5     SWS jr6    SVS jr7S r8S r9S r:S  r;S! r<S" r=S# r>S$ r?\@" \A\S%9\@" \@\S%9S&.rBS' rCS( rDS) rES* rFSS\0R                  5       S4S+ jrH SXS, jrI SYS- jrJ\0R                  \I\0R                  \J0rMS. rNS/ rOS0 rPS1 rQS2 rRS31rS1 S4krT\TS31-  rU1 S5krV\VS31-  rWS6S71rX1 S8krYS9 rZS: r[S; r\S< r]S= r^S> r_S? r`S@ raSA rb SZSB jrcSC rdSD re " SE SF\f5      rg " SG SH5      rhSI ri " SJ SK\h5      rjSL rk " SM SN\h5      rlSO rm " SP SQ\h5      rn/ SRQro " SS ST\5      rp\*SU:X  a  SSKqrq\qR                  " 5         gg)[a  
glifLib.py -- Generic module for reading and writing the .glif format.

More info about the .glif format (GLyphInterchangeFormat) can be found here:

        http://unifiedfontobject.org

The main class in this module is GlyphSet. It manages a set of .glif files
in a folder. It offers two ways to read glyph data, and one way to write
glyph data. See the class doc string for details.
    )annotationsN)warn)OrderedDict)tobytes)plistlib)AbstractPointPenPointToSegmentPen)GlifLibError)userNameToFileName)genericTypeValidatorcolorValidatorguidelinesValidatoranchorsValidatoridentifierValidatorimageValidatorglyphLibValidator)etree)
_UFOBaseIOUFOFormatVersion)numberTypes_VersionTupleEnumMixin)GlyphSetr
   readGlyphFromStringwriteGlyphToStringglyphNameToFileNamezcontents.plistzlayerinfo.plistc                  X   ^  \ rS rSrSrSr\SU 4S jj5       r\SU 4S jj5       rSr	U =r
$ )GLIFFormatVersion>   )   r   )   r   c                Z   > Ub  [        U R                  U5      5      $ [        TU ]  5       $ N)maxsupported_versionssuperdefault)clsufoFormatVersion	__class__s     J/var/www/html/env/lib/python3.13/site-packages/fontTools/ufoLib/glifLib.pyr&   GLIFFormatVersion.defaultB   s-    's--.>?@@w      c                   > Uc  [         TU ]  5       $ U R                  1nU[        R                  :  a  UR                  U R                  5        [        U5      $ r"   )r%   r$   
FORMAT_1_0r   
FORMAT_3_0add
FORMAT_2_0	frozenset)r'   r(   versionsr)   s      r*   r$   $GLIFFormatVersion.supported_versionsH   sM    #7-//NN#/:::LL(""r,    r"   )__name__
__module____qualname____firstlineno__r.   r1   classmethodr&   r$   __static_attributes____classcell__r)   s   @r*   r   r   >   s3    JJ! !
 # #r,   r   c                  .    \ rS rSrSrS rSS jrS rSrg)	Glyph]   zv
Minimal glyph object. It has no glyph attributes until either
the draw() or the drawPoints() method has been called.
c                    Xl         X l        g r"   	glyphNameglyphSet)selfrC   rD   s      r*   __init__Glyph.__init__c   s    " r,   c                8    [        XS9nU R                  U5        g)z)
Draw this glyph onto a *FontTools* Pen.
)outputImpliedClosingLineN)r	   
drawPoints)rE   penrI   pointPens       r*   draw
Glyph.drawg   s     %
 	!r,   c                P    U R                   R                  U R                  X5        g)z"
Draw this glyph onto a PointPen.
N)rD   	readGlyphrC   )rE   rL   s     r*   rJ   Glyph.drawPointsp   s     	?r,   rB   N)F)	r6   r7   r8   r9   __doc__rF   rM   rJ   r;   r5   r,   r*   r?   r?   ]   s    
!"@r,   r?   c                      \ rS rSrSr\r     SS jrSS jrS r	S r
SS jrSS	 jrS
 rS rSS jr    SS jrS rS rS r\rS rS rSS jrSS jrSS jrS rS rS rSrg)r   |   a(  
GlyphSet manages a set of .glif files inside one directory.

GlyphSet's constructor takes a path to an existing directory as it's
first argument. Reading glyph data can either be done through the
readGlyph() method, or by using GlyphSet's dictionary interface, where
the keys are glyph names and the values are (very) simple glyph objects.

To write a glyph to the glyph set, you use the writeGlyph() method.
The simple glyph objects returned through the dict interface do not
support writing, they are just a convenient way to get at the glyph data.
Nc                    [        U5      n[	        US5      (       a  UR                  5       n[        U[        5      (       a(   [        R                  R                  U5      n	SU l        Oe[        U[        R                  R                   5      (       a  Un	 U	R#                  5         S	U l        O!['        S
[)        U5      R*                  -  5      e U	R-                  S5      n[        R0                  R3                  U5      S   U l        Xl        U	R7                  [8        5      U l        U(       a#  U R:                  (       d  [        [8         S35      eUR<                  U l        X0l         Uc  [B        nX l!        X@l"        XPl#        SU l$        SU l%        U RM                  5         g! [         a  nSSKJn  U" SU< 35      UeSnAff = f! [        R                  R                   a    [        SU-  5      ef = f! [        R                  R$                   a    [        SU	-  5      ef = f! [        R                  R.                   a    [        U	5      n GNsf = f)a+  
'path' should be a path (string) to an existing local directory, or
an instance of fs.base.FS class.

The optional 'glyphNameToFileNameFunc' argument must be a callback
function that takes two arguments: a glyph name and a list of all
existing filenames (if any exist). It should return a file name
(including the .glif extension). The glyphNameToFileName function
is called whenever a file name is created for a given glyph name.

``validateRead`` will validate read operations. Its default is ``True``.
``validateWrite`` will validate write operations. Its default is ``True``.
``expectContentsFile`` will raise a GlifLibError if a contents.plist file is
not found on the glyph set file system. This should be set to ``True`` if you
are reading an existing UFO and ``False`` if you create a fresh glyph set.
r   )UnsupportedUFOFormatzUnsupported UFO format: N
__fspath__zNo glyphs directory '%s'Tzthe filesystem '%s' is closedFz-Expected a path string or fs object, found %s/z is missing.)'r   
ValueErrorfontTools.ufoLib.errorsrV   hasattrrW   
isinstancestrfsosfsOSFSerrorsCreateFailedr
   _shouldClosebaseFScheckFilesystemClosed	TypeErrortyper6   
getsyspath	NoSysPathpathpartsdirNameexistsCONTENTS_FILENAME_havePreviousFilemajorr(   ufoFormatVersionTupler   _validateRead_validateWrite_existingFileNames_reverseContentsrebuildContents)
rE   rm   glyphNameToFileNameFuncr(   validateReadvalidateWriteexpectContentsFileerV   
filesystems
             r*   rF   GlyphSet.__init__   s   2	/0@A 4&&??$DdC  FWW\\$/
 !%Dbggjj))JQ  " !&D?$t*BUBUU 	#((-D ww}}T*2.!+!2!23D!Ed&<&<"3!4LABB 0 6 6%5""*&9##: )+37 $i  	D&*+;*>?	 99)) F"#=#DEEF 99-- Q"#BZ#OPPQ yy"" 	#z?D	#sA   F$ G	 G9 H) $
G.GG	-G69-H&))IIc                   Uc  U R                   nU R                  [        0 5      nU(       a  Sn[        U[        5      (       d  SnOUR                  5        Hk  u  pE[        U[        5      (       d  Sn[        U[        5      (       d  SnM5  U R                  R                  U5      (       a  MW  [        [        < SU< 35      e   U(       a  [        S[        -  5      eX l
        SU l        SU l        g)z
Rebuild the contents dict by loading contents.plist.

``validateRead`` will validate the data, by default it is set to the
class's ``validateRead`` value, can be overridden.
NFTz( references a file that does not exist: z%s is not properly formatted)ru   	_getPlistrq   r]   dictitemsr^   r_   rp   r
   contentsrw   rx   )rE   r{   r   invalidFormatnamefileNames         r*   ry   GlyphSet.rebuildContents   s     --L>>"3R8!Mh-- $&.nn&6ND%dC00(,%h44(,!WW^^H55*0(<  '7 "#ADU#UVV "& $r,   c                    U R                   c=  0 nU R                  R                  5        H  u  p#X!UR                  5       '   M     Xl         U R                   $ )at  
Return a reversed dict of self.contents, mapping file names to
glyph names. This is primarily an aid for custom glyph name to file
name schemes that want to make sure they don't generate duplicate
file names. The file names are converted to lowercase so we can
reliably check for duplicates that only differ in case, which is
important for case-insensitive file systems.
)rx   r   r   lower)rE   dkvs       r*   getReverseContentsGlyphSet.getReverseContents   sM       (A++- !'') .$%!$$$r,   c                D    U R                  [        U R                  5        g)z^
Write the contents.plist file out to disk. Call this method when
you're done writing glyphs.
N)_writePlistrq   r   rE   s    r*   writeContentsGlyphSet.writeContents  s    
 	*DMM:r,   c                6   Uc  U R                   nU R                  [        0 5      nU(       a+  [        U[        5      (       d  [        S5      e[        U5      nUR                  5        H  u  pE [        XU5        M     g! [         a    [        SU-  5      ef = f)zy
``validateRead`` will validate the data, by default it is set to the
class's ``validateRead`` value, can be overridden.
Nz*layerinfo.plist is not properly formatted.zSThe supplied layer info object does not support setting a necessary attribute (%s).)
ru   r   LAYERINFO_FILENAMEr]   r   r
   validateLayerInfoVersion3Datar   setattrAttributeError)rE   infor{   infoDictattrvalues         r*   readLayerInfoGlyphSet.readLayerInfo  s    
 --L>>"4b9h--"#OPP4X>H#>>+KDE* , " "i s   .A??Bc                   Uc  U R                   nU R                  R                  S:  a"  [        SU R                  R                  -  5      e0 n[        R                  5        H7  n[        X5      (       d  M   [        X5      nUb  US:X  a	  U(       d  M3  XSU'   M9     U(       a)  U(       a  [        U5      nU R                  [        U5        gU R                  (       aE  U R                  R                  [        5      (       a   U R                  R                  [        5        ggg! [         a    [        SU-  5      ef = f)z{
``validateWrite`` will validate the data, by default it is set to the
class's ``validateWrite`` value, can be overridden.
N   z)layerinfo.plist is not allowed in UFO %d.zMThe supplied info object does not support getting a necessary attribute (%s).lib)rv   rt   rs   r
   layerInfoVersion3ValueDatakeysr\   getattrr   r   r   r   rr   r_   rp   remove)rE   r   r|   infoDatar   r   s         r*   writeLayerInfoGlyphSet.writeLayerInfo,  s   
   //M%%++a/;,,223 
 .335Dt""#D/E =TU]5!& 6 8B/:##7I(J(JGGNN-. )K# & &g s   8D$$D=c           	         U R                   U   n U R                  R                  U5      $ ! [        R                  R                   a"    [        SU< SU< SU R                  < 35      ef = f)a  
Get the raw GLIF text for a given glyph name. This only works
for GLIF files that are already on disk.

This method is useful in situations when the raw XML needs to be
read from a glyph set for a particular glyph before fully parsing
it into an object structure via the readGlyph method.

Raises KeyError if 'glyphName' is not in contents.plist, or
GlifLibError if the file associated with can't be found.
z
The file 'z' associated with glyph 'z&' in contents.plist does not exist on )r   r_   	readbytesrb   ResourceNotFoundr
   rE   rC   r   s      r*   getGLIFGlyphSet.getGLIFP  sc     ==+	77$$X..yy)) 	*2ItwwH 	s
   , A A,c                B    U R                   U   nU R                  U5      $ )a?  
Returns the modification time for the GLIF file with 'glyphName', as
a floating point number giving the number of seconds since the epoch.
Return None if the associated file does not exist or the underlying
filesystem does not support getting modified times.
Raises KeyError if the glyphName is not in contents.plist.
)r   getFileModificationTimer   s      r*   getGLIFModificationTime GlyphSet.getGLIFModificationTimee  s#     ==+++H55r,   c                   Uc  U R                   nU R                  U5      n [        U5      n[        R	                  U R
                  5      n[        UUUUUS9  g! [         a  nU R                  U   n	 SU R                  R                  U	5       S3n
O@! [        R                  R                   a    SU	 S[        U R                  5       S3n
 Of = fUR                  SU SU
 S35        e SnAff = f)a@  
Read a .glif file for 'glyphName' from the glyph set. The
'glyphObject' argument can be any kind of object (even None);
the readGlyph() method will attempt to set the following
attributes on it:

width
        the advance width of the glyph
height
        the advance height of the glyph
unicodes
        a list of unicode values for this glyph
note
        a string
lib
        a dictionary containing custom data
image
        a dictionary containing image data
guidelines
        a list of guideline data dictionaries
anchors
        a list of anchor data dictionaries

All attributes are optional, in two ways:

1) An attribute *won't* be set if the .glif file doesn't
   contain data for it. 'glyphObject' will have to deal
   with default values itself.
2) If setting the attribute fails with an AttributeError
   (for example if the 'glyphObject' attribute is read-
   only), readGlyph() will not propagate that exception,
   but ignore that attribute.

To retrieve outline information, you need to pass an object
conforming to the PointPen protocol as the 'pointPen' argument.
This argument may be None if you don't need the outline data.

readGlyph() will raise KeyError if the glyph is not present in
the glyph set.

``validate`` will validate the data, by default it is set to the
class's ``validateRead`` value, can be overridden.
NformatVersionsvalidate'z' from 'zThe issue is in glyph 'z', located in .)ru   r   _glifTreeFromStringr   r$   rt   _readGlyphFromTreer
   r   r_   rk   rb   rl   r^   	_add_note)rE   rC   glyphObjectrL   r   texttreer   glifLibErrorr   glifLocations              r*   rP   GlyphSet.readGlyphr  s   X ))H||I&	&t,D.AA**N -!  	 }}Y/HE!"477#5#5h#?"@B99&& E "#8*HS\N!DE
 ""))N<.PQR 	s;   7A 
C2$C-4BC-:CC-CC--C2c                   Uc   [         R                  U R                  5      nO [        U5      nU[         R                  U R                  5      ;  a!  SSKJn  U" SU< SU R                  < S35      eUc  U R                  nU R                  R                  U5      nUc  U R                  c=  U R                  R                  5        Vs1 s H  oR                  5       iM     snU l
        U R                  XR                  5      nXR                  U'   U R                  R                  UR                  5       5        U R                  b  XR                  UR                  5       '   [!        UUUUUS9n	U R"                  (       a?  U R$                  R'                  U5      (       a  XR$                  R)                  U5      :X  a  gU R$                  R+                  X5        g! [         a  nSSKJn  U" SU< 35      UeSnAff = fs  snf )	a&  
Write a .glif file for 'glyphName' to the glyph set. The
'glyphObject' argument can be any kind of object (even None);
the writeGlyph() method will attempt to get the following
attributes from it:

width
        the advance width of the glyph
height
        the advance height of the glyph
unicodes
        a list of unicode values for this glyph
note
        a string
lib
        a dictionary containing custom data
image
        a dictionary containing image data
guidelines
        a list of guideline data dictionaries
anchors
        a list of anchor data dictionaries

All attributes are optional: if 'glyphObject' doesn't
have the attribute, it will simply be skipped.

To write outline data to the .glif file, writeGlyph() needs
a function (any callable object actually) that will take one
argument: an object that conforms to the PointPen protocol.
The function will be called by writeGlyph(); it has to call the
proper PointPen methods to transfer the outline to the .glif file.

The GLIF format version will be chosen based on the ufoFormatVersion
passed during the creation of this object. If a particular format
version is desired, it can be passed with the formatVersion argument.
The formatVersion argument accepts either a tuple of integers for
(major, minor), or a single integer for the major digit only (with
minor digit implied as 0).

An UnsupportedGLIFFormat exception is raised if the requested GLIF
formatVersion is not supported.

``validate`` will validate the data, by default it is set to the
class's ``validateWrite`` value, can be overridden.
Nr   UnsupportedGLIFFormatz!Unsupported GLIF format version: z!Unsupported GLIF format version (z) for UFO format version r   )formatVersionr   )r   r&   rt   rZ   r[   r   r$   rv   r   getrw   valuesr   r   r0   rx   _writeGlyphToBytesrr   r_   rp   r   
writebytes)
rE   rC   r   drawPointsFuncr   r   r~   r   r   datas
             r*   
writeGlyphGlyphSet.writeGlyph  s   j  -55d6P6PQM 1- @  1 D D&&!
 
 F'3M3D E**.*D*D)GqJ  **H==$$Y/&&.59]]5I5I5K+5KNN$5K+' //	;R;RSH'/MM)$##''(89$$0:C%%hnn&67!'
 ""x(())(338*S  I+77HI(+s   G 
H
H)G<<Hc                .   U R                   U   nU R                  R                  U5        U R                  b)  U R                  R                  UR	                  5       5        U R
                  b  U R
                  UR	                  5       	 U R                   U	 g)z{Permanently delete the glyph from the glyph set on disk. Will
raise KeyError if the glyph is not present in the glyph set.
N)r   r_   r   rw   r   rx   r   s      r*   deleteGlyphGlyphSet.deleteGlyph"  sv     ==+x "".##**8>>+;<  ,%%hnn&67MM)$r,   c                H    [        U R                  R                  5       5      $ r"   )listr   r   r   s    r*   r   GlyphSet.keys0  s    DMM&&())r,   c                    XR                   ;   $ r"   )r   rE   rC   s     r*   has_keyGlyphSet.has_key3  s    MM))r,   c                ,    [        U R                  5      $ r"   )lenr   r   s    r*   __len__GlyphSet.__len__8  s    4==!!r,   c                X    XR                   ;  a  [        U5      eU R                  X5      $ r"   )r   KeyError
glyphClassr   s     r*   __getitem__GlyphSet.__getitem__;  s&    MM)9%%y//r,   c                    0 nUc  U R                   R                  5       nU H!  nU R                  U5      n[        U5      X#'   M#     U$ )a  
Return a dictionary that maps glyph names to lists containing
the unicode value[s] for that glyph, if any. This parses the .glif
files partially, so it is a lot faster than parsing all files completely.
By default this checks all glyphs, but a subset can be passed with glyphNames.
)r   r   r   _fetchUnicodes)rE   
glyphNamesunicodesrC   r   s        r*   getUnicodesGlyphSet.getUnicodesB  sM     ++-J#I<<	*D"0"6H $ r,   c                    0 nUc  U R                   R                  5       nU H!  nU R                  U5      n[        U5      X#'   M#     U$ )a  
Return a dictionary that maps glyph names to lists containing the
base glyph name of components in the glyph. This parses the .glif
files partially, so it is a lot faster than parsing all files completely.
By default this checks all glyphs, but a subset can be passed with glyphNames.
)r   r   r   _fetchComponentBases)rE   r   
componentsrC   r   s        r*   getComponentReferencesGlyphSet.getComponentReferencesQ  sN     
++-J#I<<	*D$8$>J! $ r,   c                    0 nUc  U R                   R                  5       nU H!  nU R                  U5      n[        U5      X#'   M#     U$ )a  
Return a dictionary that maps glyph names to the file name of the image
referenced by the glyph. This parses the .glif files partially, so it is a
lot faster than parsing all files completely.
By default this checks all glyphs, but a subset can be passed with glyphNames.
)r   r   r   _fetchImageFileName)rE   r   imagesrC   r   s        r*   getImageReferencesGlyphSet.getImageReferences`  sM     ++-J#I<<	*D 3D 9F $ r,   c                \    U R                   (       a  U R                  R                  5         g g r"   )rd   r_   closer   s    r*   r   GlyphSet.closeo  s    GGMMO r,   c                    U $ r"   r5   r   s    r*   	__enter__GlyphSet.__enter__s  s    r,   c                $    U R                  5         g r"   )r   )rE   exc_type	exc_valueexc_tbs       r*   __exit__GlyphSet.__exit__v  s    

r,   )rw   rr   rx   rd   ru   rv   r   ro   r_   r   r(   rt   )NNTTFr"   NNNNNNN)r6   r7   r8   r9   rR   r?   r   rF   ry   r   r   r   r   r   r   rP   r   r   r   r   __contains__r   r   r   r   r   r   r   r   r;   r5   r,   r*   r   r   |   s     J
 !% Ob%@% ;,"/H*	6I\ c+J
%** L"0r,   r   c                0    Uc
  [        5       n[        XSS9$ )z
Wrapper around the userNameToFileName function in filenames.py

Note that existingFileNames should be a set for large glyphsets
or performance will suffer.
z.glif)existingsuffix)setr   )rC   existingFileNamess     r*   r   r     s      EiGTTr,   Tc                F   [        U 5      nUc  [        R                  5       nOO[        5       [        5       pvU H   n [        U5      n	UR	                  U	5        M"     U(       d  [        SU< 35      e[        UUUUUS9  g! [
         a    UR	                  U5         Mf  f = f)a  
Read .glif data from a string into a glyph object.

The 'glyphObject' argument can be any kind of object (even None);
the readGlyphFromString() method will attempt to set the following
attributes on it:

width
        the advance width of the glyph
height
        the advance height of the glyph
unicodes
        a list of unicode values for this glyph
note
        a string
lib
        a dictionary containing custom data
image
        a dictionary containing image data
guidelines
        a list of guideline data dictionaries
anchors
        a list of anchor data dictionaries

All attributes are optional, in two ways:

1) An attribute *won't* be set if the .glif file doesn't
   contain data for it. 'glyphObject' will have to deal
   with default values itself.
2) If setting the attribute fails with an AttributeError
   (for example if the 'glyphObject' attribute is read-
   only), readGlyphFromString() will not propagate that
   exception, but ignore that attribute.

To retrieve outline information, you need to pass an object
conforming to the PointPen protocol as the 'pointPen' argument.
This argument may be None if you don't need the outline data.

The formatVersions optional argument define the GLIF format versions
that are allowed to be read.
The type is Optional[Iterable[Tuple[int, int], int]]. It can contain
either integers (for the major versions to be allowed, with minor
digits defaulting to 0), or tuples of integers to specify both
(major, minor) versions.
By default when formatVersions is None all the GLIF format versions
currently defined are allowed to be read.

``validate`` will validate the read data. It is set to ``True`` by default.
Nz9None of the requested GLIF formatVersions are supported: r   )r   r   r$   r  r0   rZ   r   )
aStringr   rL   r   r   r   validFormatVersionsinvalidFormatVersionsr   r   s
             r*   r   r     s    p w'D/BBD58UCE2A7 1! 4 $''6   #K!$& 
 *  -%))!,-s   BB B c                    [        U5      nU(       a   [	        U [
        5      (       d  [        S5      eU(       a  [        U 5      S:X  a  [        S5      e[        SU 4S[        UR                  5      4/5      nUR                  S:w  a  [        UR                  5      US'   [        R                  " S	U5      n[        5       n	[        XU5        [!        US
S5      (       a  [#        XU5        [!        USS5      (       a  [%        XU5        UR                  S:  a  [!        USS5      (       a  ['        XU5        UR                  S:  a  [!        USS5      (       a  [)        XX5        [!        USS5      n
UR                  S:  a  U
(       a  [+        XX5        Ubc  [        R,                  " US5      n[/        XUS9nU" U5        UR                  S:X  a  U
(       a  [1        XU5        [        U5      (       d  SUl        [!        USS5      (       a  [5        XU5        [        R6                  " USSSS9nU$ ! [         a    SSKJn  U" S5      ef = f)z>Return .glif data for a glyph as a UTF-8 encoded bytes string.r   r   z2Unsupported GLIF format version: {formatVersion!r}z)The glyph name is not properly formatted.zThe glyph name is empty.r   formatformatMinorglyphr   Nnoter    image
guidelinesanchorsoutline)identifiersr   r   
  r   zUTF-8T)encodingxml_declarationpretty_print)r   rZ   r[   r   r]   r^   r
   r   r   reprrs   minorr   Elementr  _writeAdvancer   _writeUnicodes
_writeNote_writeImage_writeGuidelines_writeAnchors
SubElementGLIFPointPen_writeAnchorsFormat1r   	_writeLibtostring)rC   r   r   writerr   r   r   
glyphAttrsrootr  r  r  rK   r   s                 r*   r   r     s   
)-8 
9c22FGGC	Na'566
)	xm.A.A)BCDJ a$()<)<$=
=!==*-D%K+X.{J--{(3{FD));h/aGK$$G$GKx0aGKt$L$LKBk9d3GaGk?!""437hOs!# x87||!GL{E4((+X.>>w4D Kk  
A#@
 	

s   H3 3Ic                >    [        U UUUUS9nUR                  S5      $ )a@  
Return .glif data for a glyph as a string. The XML declaration's
encoding is always set to "UTF-8".
The 'glyphObject' argument can be any kind of object (even None);
the writeGlyphToString() method will attempt to get the following
attributes from it:

width
        the advance width of the glyph
height
        the advance height of the glyph
unicodes
        a list of unicode values for this glyph
note
        a string
lib
        a dictionary containing custom data
image
        a dictionary containing image data
guidelines
        a list of guideline data dictionaries
anchors
        a list of anchor data dictionaries

All attributes are optional: if 'glyphObject' doesn't
have the attribute, it will simply be skipped.

To write outline data to the .glif file, writeGlyphToString() needs
a function (any callable object actually) that will take one
argument: an object that conforms to the PointPen protocol.
The function will be called by writeGlyphToString(); it has to call the
proper PointPen methods to transfer the outline to the .glif file.

The GLIF format version can be specified with the formatVersion argument.
This accepts either a tuple of integers for (major, minor), or a single
integer for the major digit only (with minor digit implied as 0).
By default when formatVesion is None the latest GLIF format version will
be used; currently it's 2.0, which is equivalent to formatVersion=(2, 0).

An UnsupportedGLIFFormat exception is raised if the requested UFO
formatVersion is not supported.

``validate`` will validate the written data. It is set to ``True`` by default.
)r   r   r   r   utf-8)r   decode)rC   r   r   r   r   r   s         r*   r   r   '  s/    f %#D ;;wr,   c                0   [        U SS 5      nUb/  U(       a   [        U[        5      (       d  [        S5      eUS:X  a  S n[        U SS 5      nUb/  U(       a   [        U[        5      (       d  [        S5      eUS:X  a  S nUb=  Ub:  [        R
                  " US[        S[        U5      4S[        U5      4/5      5        g Ub)  [        R
                  " US[        [        U5      S95        g Ub)  [        R
                  " US[        [        U5      S95        g g )	Nwidthz$width attribute must be int or floatr   heightz%height attribute must be int or floatadvance)r.  )r/  )	r   r]   r   r
   r   r"  r   r  r   )r   elementr   r.  r/  s        r*   r  r  d  s    K$/EJuk::EFFA:E[(D1FJv{;;FGGQ;FV/(DL1GT%[3IJK	

 
	)TU-DE		)Tf-FG 
r,   c           	     H   [        U SS 5      nU(       a  [        U[        5      (       a  U/n[        5       nU Hf  nU(       a   [        U[        5      (       d  [	        S5      eXT;   a  M1  UR                  U5        SU-  n[        R                  " US[        US95        Mh     g )Nr   zunicode values must be intz%04Xunicode)hex)	r   r]   intr  r
   r0   r   r"  r   )r   r1  r   r   seencodehexCodes          r*   r  r  }  s    {J5HJx--:5DJtS11;<<<4-)Tg->? r,   c                    [        U SS 5      nU(       a   [        U[        5      (       d  [        S5      eUR	                  5       nSU-   S-   nU[
        R                  " US5      l        g )Nr  znote attribute must be str
)r   r]   r^   r
   stripr   r"  r   )r   r1  r   r  s       r*   r  r    sY    ;-D
4--788::<D$;D-1EWf%*r,   c                L   [        U SS 5      nU(       a  [        U5      (       d  [        S5      e[        SUS   4/5      n[         H*  u  pVUR                  XV5      nXv:w  d  M  [        U5      XE'   M,     UR                  S5      nUb  XS'   [        R                  " USU5        g )Nr  zMimage attribute must be a dict or dict-like object with the proper structure.r   color)	r   r   r
   r   _transformationInfor   r  r   r"  )	r   r1  r   r  attrsr   r&   r   r=  s	            r*   r  r    s    K$/Eu--[
 	
 *eJ&789:E,		$(u+EK - IIgEg	Wgu-r,   c                l   [        U S/ 5      nU(       a  [        U5      (       d  [        S5      eU H  n[        5       nUR	                  S5      nUb  [        U5      US'   UR	                  S5      nUb  [        U5      US'   UR	                  S5      n	U	b  [        U	5      US'   UR	                  S5      n
U
b  XS'   UR	                  S5      nUb  XS'   UR	                  S5      nUb/  U(       a  X;   a  [        S	U-  5      eXS'   UR                  U5        [        R                  " US
U5        GM     g )Nr  z8guidelines attribute does not have the proper structure.xyangler   r=  
identifier"identifier used more than once: %s	guideline)	r   r   r
   r   r   r  r0   r   r"  )r   r1  r  r   r  rF  r?  rA  rB  rC  r   r=  rD  s                r*   r   r     s%   lB7J+J77UVV	MM#=aE#JMM#=aE#Jg&!%[E'N}}V$ &Mg&"'N]]<0
!J5"#G*#TUU",,OOJ'+u5/  r,   c                >   U(       a  [        U5      (       d  [        S5      eU Hu  n0 nUS   n[        U5      US'   US   n[        U5      US'   UR                  S5      nUb  XtS'   U R	                  5         U R                  XV4SUS9  U R                  5         Mw     g )N5anchors attribute does not have the proper structure.rA  rB  r   move)segmentTyper   )r   r
   r  r   	beginPathaddPointendPath)rK   r  r   anchorr?  rA  rB  r   s           r*   r$  r$    s    (11RSS3K!Wc
3K!Wc
zz&! &MaVd; r,   c                   [        U S/ 5      nU(       a  [        U5      (       d  [        S5      eU H  n[        5       nUS   n[	        U5      US'   US   n[	        U5      US'   UR                  S5      n	U	b  XS'   UR                  S5      n
U
b  XS'   UR                  S5      nUb/  U(       a  X;   a  [        SU-  5      eXS'   UR                  U5        [        R                  " US	U5        M     g )
Nr  rH  rA  rB  r   r=  rD  rE  rN  )	r   r   r
   r   r  r   r0   r   r"  )r   r1  r  r   r  rN  r?  rA  rB  r   r=  rD  s               r*   r!  r!    s    k9b1G(11RSS3K!Wc
3K!Wc
zz&! &M

7#"'NZZ-
!J5"#G*#TUU",,OOJ'(E2% r,   c                0   [        U SS 5      nU(       d  g U(       a  [        U5      u  pEU(       d  [        U5      e[        U[        5      (       d  [	        U5      n[
        R                  " USS9n[        R                  " US5      R                  U5        g )Nr   r    )indent_level)
r   r   r
   r]   r   r   totreer   r"  append)r   r1  r   r   validmessager~   s          r*   r%  r%    st    
+ud
+C*3/w''c4  3i!,A	We$++A.r,   )rj   valueValidator)r=  r   c                    U [         ;  a  g[         U    nUR                  S5      nUR                  S5      nUR                  S5      nUb
  U" X5      nU$ U[        :X  a
  U" X5      nU$ U" U5      nU$ )a  
This performs very basic validation of the value for attribute
following the UFO 3 fontinfo.plist specification. The results
of this should not be interpretted as *correct* for the font
that they are part of. This merely indicates that the value
is of the proper type and, where the specification defines
a set range of possible values for an attribute, that the
value is in the accepted range.
Frj   rV  valueOptions)r   r   r   )r   r   dataValidationDict	valueType	validatorrX  isValidValues          r*   *validateLayerInfoVersion3ValueForAttributer]    s     --3D9"&&v.I"&&'78I%)).9L 5 	 ,,$U6L  %U+Lr,   c                    U R                  5        HB  u  pU[        ;  a  [        SU-  5      e[        X5      nU(       a  M1  [        SU SU< S35      e   U $ )a  
This performs very basic validation of the value for infoData
following the UFO 3 layerinfo.plist specification. The results
of this should not be interpretted as *correct* for the font
that they are part of. This merely indicates that the values
are of the proper type and, where the specification defines
a set range of possible values for an attribute, that the
value is in the accepted range.
zUnknown attribute %s.zInvalid value for attribute z (z).)r   r   r
   r]  )r   r   r   r\  s       r*   r   r   $  sb      ~~'116=>>A$N|!=dV2eYbQRR ( Or,   c                v   [         R                  (       a(  [         R                  " U [         R                  " SS9S9nO[         R                  " U 5      nUR	                  5       nUR
                  S:w  a  [        S5      eUR                  (       a)  UR                  R                  5       S:w  a  [        S5      eU$ )NTremove_commentsparserr  #The GLIF is not properly formatted. Invalid GLIF structure.)	r   
_have_lxmlparse	XMLParsergetroottagr
   r   r;  )aFiler   r)  s      r*   _glifTreeFromFilerm  <  s    {{5)NO{{5!<<>Dxx7@AAyyTYY__&",455Kr,   c                   [        U SS9n [        R                  (       a(  [        R                  " U[        R                  " SS9S9nO[        R                  " U5      n UR                  S:w  a  [        S5      eUR                  (       a)  UR                  R                  5       S	:w  a  [        S
5      eU$ ! [
         a  n[        S5      UeS nAff = f)Nr+  )r  Tr`  rb  zGLIF contains invalid XML.r  rd  re  rf  )
r   r   rg  
fromstringri  	Exceptionr
   rk  r   r;  )r  r   r)  etree_exceptions       r*   r   r   I  s    7W-DN##DQU1VWD##D)D xx7@AAyyTYY__&",455K  N78oMNs   <B7 	B7 7
CCCc                   U R                  S5      nU(       a  Uc  [        S5      eU R                  SS5      n [        [        U5      [        U5      45      nU(       a  Xs;  a  [        S	U< 35      e [        U   nU" U UUUUR                  S
9  g ! [         aU  nSU< SU< 3n	U(       a  SSKJn
  U
" U	5      Ue[        R                  5       n[        R                  SU	U5         S nANS nAff = f! [         a    [        U5      ef = f)Nr  z#Unspecified format version in GLIF.r  r   zUnsupported GLIF format: r   r   z_%s. Assuming the latest supported version (%s). Some data may be skipped or parsed incorrectly.zForbidden GLIF format version: )r   r   rL   r   r  )r   r
   r   r5  rZ   r[   r   r&   loggerwarning_READ_GLYPH_FROM_TREE_FUNCSr   NotImplementedErrorr  )r   r   rL   r   r   formatVersionMajorformatVersionMinorr   r~   msgr   readGlyphFromTrees               r*   r   r   Z  s"    (+&.@AA-3
)#$c*<&=>
* M7<]<MNOO17F !''5  

 E',!3)113>		
 	

.  1!-001s$   B 5	C5 
C2AC--C25Dc                   [        XU5        / nS=n=n=pU  GH  n
U
R                  S:X  a  U(       ah  U(       a  [        S5      eU
R                  (       a  [        S5      eU
R                  (       a)  U
R                  R                  5       S:w  a  [        S5      eSn[        XX5        M  Uc  M  U
R                  S:X  a(  U(       a  U(       a  [        S	5      eSn[        X5        M  U
R                  S
:X  aH  U
R                  S5      nUc  [        S5      e [        US5      nX;  a  UR                  U5        GM%  GM(  U
R                  S:X  a)  U(       a  U	(       a  [        S5      eSn	[        X5        GMa  U
R                  S:X  a*  U(       a  U(       a  [        S5      eSn[        XU5        GM  [        SU
-  5      e   U(       a  [        USU5        g g ! [         a    [        S5      ef = f)NFr  *The outline element occurs more than once.0The outline element contains unknown attributes.re  Invalid outline structure.Tr0  *The advance element occurs more than once.r3  r4  8A unicode element is missing its required hex attribute.   3Illegal value for hex attribute of unicode element.r  'The note element occurs more than once.r   &The lib element occurs more than once.Unknown element in GLIF: %sr   )	_readNamerk  r
   attribr   r;  buildOutlineFormat1_readAdvancer   r5  rS  rZ   	_readNote_readLib_relaxedSetattr)r   r   rL   r   kwargsr   haveSeenAdvancehaveSeenOutlinehaveSeenLibhaveSeenNoter1  r   s               r*   _readGlyphFromTreeFormat1r    s    k*HEJJOJoJ;;)#"&'STT>>&J  <<GLL$6$6$8B$>&'CDD"OwI [[I%O"#OPP"O.[[I%E"Ay"N 2J$OOA& % [[F"L"#LMMLk+[[E!K"#KLLK[84<wFGG[ ^ Z: #  "I s   "GG/c                   [        XU5        / n/ n/ nS=n=n	=n
=p[        5       nU  GH  nUR                  S:X  a  U(       ah  U
(       a  [        S5      eUR                  (       a  [        S5      eUR
                  (       a)  UR
                  R                  5       S:w  a  [        S5      eSn
Ub  [        XXU5        M  M  Uc  M  UR                  S:X  a(  U(       a  U(       a  [        S	5      eSn[        X5        M  UR                  S
:X  aH  UR                  S5      nUc  [        S5      e [        US5      nX;  a  UR                  U5        GM+  GM.  UR                  S:X  am  U(       a  [        U5      (       a  [        S5      e[        UR                  5      nS H  nUU;   d  M  [        UU   5      UU'   M     UR                  U5        GM  UR                  S:X  aw  U(       a  [        U5      (       a  [        S5      e[        UR                  5      nS H&  nUUR                  ;   d  M  [        UU   5      UU'   M(     UR                  U5        GM2  UR                  S:X  aE  U(       a-  U	(       a  [        S5      e[        U5      (       a  [        S5      eSn	[!        XU5        GM  UR                  S:X  a)  U(       a  U(       a  [        S5      eSn[#        X5        GM  UR                  S:X  a*  U(       a  U(       a  [        S5      eSn[%        XU5        GM  [        SU-  5      e   U(       a  ['        USU5        U(       a/  U(       a  [)        Xm5      (       d  [        S5      e['        USU5        U(       a0  U(       a  [+        X}5      (       d  [        S 5      e['        US!U5        g g ! [         a    [        S5      ef = f)"NFr  r|  r}  re  r~  Tr0  r  r3  r4  r  r  r  rF  z&Unknown children in guideline element.)rA  rB  rC  rN  z#Unknown children in anchor element.rA  rB  r  z(The image element occurs more than once.z"Unknown children in image element.r  r  r   r  r  r   z(The guidelines are improperly formatted.r  z%The anchors are improperly formatted.r  )r  r  rk  r
   r  r   r;  buildOutlineFormat2r  r   r5  rS  rZ   r   r   _number
_readImager  r  r  r   r   )r   r   rL   r   r  r   r  r  r  haveSeenImager  r  r  r  r1  r   r  r   s                     r*   _readGlyphFromTreeFormat2r    sY    k*HJGO m o  %K;;)#"&'STT>>&J  <<GLL$6$6$8B$>&'CDD"O##7 $  [[I%O"#OPP"O.[[I%E"Ay"N 2J$OOA& % [[K'CLL"#KLL'..)F+6>#*6$<#8F4L , f%[[H$CLL"#HII'..)F"7>>)#*6$<#8F4L # NN6"[[G# &'QRRw<<&'KLL M{X6[[F"L"#LMMLk+[[E!K"#KLLK[84<wFGGQ T Z:/
HHIJJ\:>,WBBFGGY8 c  "I s   ."N44O
c                    UR                  S5      nU(       a  U(       d  [        S5      eU(       a  U b  [        U SU5        g g g )Nr   zEmpty glyph name in GLIF.)r   r
   r  )r   r)  r   rC   s       r*   r  r  3  s<     I	677[,VY7 -yr,   c                    [        UR                  SS5      5      n[        U SU5        [        UR                  SS5      5      n[        U SU5        g )Nr.  r   r/  )r  r   r  )r   r0  r.  r/  s       r*   r  r  ;  sD    GKK+,EK%0W[[1-.FK62r,   c                    UR                   R                  S5      nSR                  S U 5       5      n[        U SU5        g )Nr:  c              3  n   #    U  H+  oR                  5       (       d  M  UR                  5       v   M-     g 7fr"   )r;  ).0lines     r*   	<genexpr>_readNote.<locals>.<genexpr>D  s      Dedzz|\TZZ\\es   55r  )r   splitjoinr  )r   r  liness      r*   r  r  B  s4    IIOOD!E99DeDDDK.r,   c                    [        U5      S:X  d   eUS   n[        R                  " U5      nU(       a  [        U5      u  pVU(       d  [	        U5      e[        U SU5        g )Nr   r   r   )r   r   fromtreer   r
   r  )r   r   r   childplistrT  rU  s          r*   r  r  H  sT    s8q==FEe$E*51w''K.r,   c                    [        UR                  5      n[         H#  u  pEUR                  XE5      n[	        U5      X4'   M%     U(       a  [        U5      (       d  [        S5      e[        U SU5        g )Nz,The image element is not properly formatted.r  )r   r  r>  r   r  r   r
   r  )r   r  r   	imageDatar   r&   r   s          r*   r  r  S  s\    U\\"I,d,!%.	 - y11IJJK)4r,   rD  >   re   xScaleyScalexOffsetxyScaleyOffsetyxScale>   rA  rB  r   rj   smoothnoyes>   r  rI  curveqcurveoffcurvec                   / nU H  nUR                   S:X  aX  [        U5      S:X  a6  US   nUR                   S:X  a!  [        Xc5      nUb  UR                  U5        MX  Ub  [	        XU5        Mi  Mk  UR                   S:X  a  Ub  [        XU5        M  M  [        SU-  5      e   U b8  U(       a0  U(       a  [        U5      (       d  [        S5      e[        U SU5        g g g )	Ncontourr   r   point	component&Unknown element in outline element: %sz*GLIF 1 anchors are not properly formatted.r  )	rk  r   _buildAnchorFormat1rS  _buildOutlineContourFormat1_buildOutlineComponentFormat1r
   r   r  )r   rK   r  r   r  r1  r  rN  s           r*   r  r  t  s    G;;)#7|q 
99'0AF)v. +C(C [[K'-cHE  G'QRR   7,W55KLLY8 $+r,   c                4   U R                  S5      S:w  a  g U R                  S5      nUc  g U R                  S5      nU R                  S5      nU(       a  Uc  [        S5      eU(       a  Uc  [        S5      e[        U5      n[        U5      n[        X4US9nU$ )	Nrj   rI  r   rA  rB  z1Required x attribute is missing in point element.z1Required y attribute is missing in point element.)rA  rB  r   )r   r
   r  r   )r  r   r   rA  rB  rN  s         r*   r  r    s    yyF"99VD|		#A		#AAINOOAINOO
A
AA&FMr,   c                    U(       a  UR                   (       a  [        S5      eU R                  5         [        U5      (       a  [	        U[
        SUS9n[        X5        U R                  5         g )Nz&Unknown attributes in contour element.T)openContourOffCurveLeniencyr   )r  r
   rK  r   "_validateAndMassagePointStructurespointAttributesFormat1_buildOutlinePointsFormat1rM  )rK   r  r   massageds       r*   r  r    sR    GNNCDDMMO
7||5"(,	
 	#31KKMr,   c                l    U H.  nUS   nUS   nUS   nUS   nUS   nU R                  X44XVUS9  M0     g )NrA  rB  rJ  r  r   rJ  r  r   )rL  )rK   r  r  rA  rB  rJ  r  r   s           r*   r  r    sN    #J#JM*xV}aV$O r,   c                   U(       aT  [        U5      (       a  [        S5      eUR                  R                  5        H  nU[        ;  d  M  [        SU-  5      e   UR                  S5      nU(       a  Uc  [        S5      e/ n[         H8  u  p6UR                  U5      nUc  UnO[        U5      nUR                  U5        M:     U R                  U[        U5      5        g )N,Unknown child elements of component element.*Unknown attribute in component element: %sre   3The base attribute is not defined in the component.)r   r
   r  r   componentAttributesFormat1r   r>  r  rS  addComponenttuple)rK   r  r   r   baseGlyphNametransformationr&   r   s           r*   r  r    s    y>>MNN$$))+D55"#ORV#VWW , MM&)MM)PQQN,d#=EENEe$ - ]E.$9:r,   c                    U HU  nUR                   S:X  a  [        XX45        M!  UR                   S:X  a  [        XX45        M?  [        SUR                   -  5      e   g )Nr  r  r  )rk  _buildOutlineContourFormat2_buildOutlineComponentFormat2r
   )r   rK   r  r  r   r1  s         r*   r  r    sM    ;;)#'kL[[K')#NG'++UVV r,   c                4   U(       a9  UR                   R                  5        H  nU[        ;  d  M  [        SU-  5      e   UR	                  S5      nUbI  U(       a1  XR;   a  [        SU-  5      e[        U5      (       d  [        SU-  5      eUR                  U5         U R                  US9  [        U5      (       a  [        U[        US9n[        XX#5        U R                  5         g ! [         a#    U R                  5         [        S[        5         Nhf = f)Nz(Unknown attribute in contour element: %srD  )The identifier %s is used more than once.z'The contour identifier %s is not valid.rD  zbThe beginPath method needs an identifier kwarg. The contour's identifier value has been discarded.)r   )r  r   contourAttributesFormat2r
   r   r   r0   rK  ri   r   DeprecationWarningr   r  pointAttributesFormat2_buildOutlinePointsFormat2rM  )rK   r  r  r   r   rD  r  s          r*   r  r    s   NN'')D33"#MPT#TUU * \*J("?*L  'z22"=
J  	
#
, 7||5+h
 	#3+HKKM  
p	

s   C* **DDc           	        U H  nUS   nUS   nUS   nUS   nUS   n	UR                  S5      n
U
bI  U(       a1  X;   a  [        SU
-  5      e[        U
5      (       d  [        SU
-  5      eUR                  U
5         U R	                  XV4UUU	U
S	9  M     g ! [
         a&    U R	                  XV4XxU	S
9  [        S[        5         M  f = f)NrA  rB  rJ  r  r   rD  r  The identifier %s is not valid.)rJ  r  r   rD  r  z_The addPoint method needs an identifier kwarg. The point's identifier value has been discarded.)r   r
   r   r0   rL  ri   r   r  )rK   r  r  r   r  rA  rB  rJ  r  r   rD  s              r*   r  r    s    #J#JM*xV}YY|,
!,&CjP  +:66&'H:'UVVOOJ'	LL'%  # 0  	LL![dLSq"	s   =B,CCc                   U(       aT  [        U5      (       a  [        S5      eUR                  R                  5        H  nU[        ;  d  M  [        SU-  5      e   UR                  S5      nU(       a  Uc  [        S5      e/ n[         H8  u  pGUR                  U5      nUc  UnO[        U5      nUR                  U5        M:     UR                  S5      n	U	bP  U(       a8  X;   a  [        SU	-  5      eU(       a  [        U	5      (       d  [        SU	-  5      eUR                  U	5         U R                  U[        U5      U	S9  g ! [         a.    U R                  U[        U5      5        [        S	[        5         g f = f)
Nr  r  re   r  rD  r  r  r  zgThe addComponent method needs an identifier kwarg. The component's identifier value has been discarded.)r   r
   r  r   componentAttributesFormat2r   r>  r  rS  r   r0   r  r  ri   r   r  )
rK   r  r  r   r   r  r  r&   r   rD  s
             r*   r  r    sd   y>>MNN$$))+D55"#ORV#VWW , MM&)MM)PQQN,d#=EENEe$ - |,J("?*L   3J ? ?"#Dz#QRR
#
n(=*U 
n(=>u	

s   +E 5E>=E>c                >   [        U 5      (       d  g S nSn/ n[        U 5       GH  u  pxUR                  S:w  a  [        SUR                  -  5      e[	        UR
                  5      n	UR                  U	5        U(       aE  U	R                  5        H  n
X;  d  M
  [        SU
-  5      e   [        U5      (       a  [        S5      eS H  n
 [        X   5      X'   M     U	R                  S	S
5      nU(       a  U[        ;  a  [        SU-  5      eUS
:X  a  S nXS'   Uc  SnOUnU(       a  US:X  a  US:w  a  [        S5      eU	R                  SS5      nU(       a  Ub  U[        ;  a  [        SU-  5      eUS:H  nXS'   U(       a  U(       a  Uc  [        S5      eSUR
                  ;  d  GM  S U	S'   GM     U(       a:  US   S   S:X  a.  Sn[        U5       H  n	U	S   c  US-  nM    O   U(       a  US U*  nU(       a~  U(       aw  Ubt  [        U5      S-
  U-
  nU H]  n	U	S   nUc  US-  nM  U(       aB  US:X  a  [        S5      eUS:X  a  [        S5      eUS:X  a  US:  a  [        S5      eOUS:X  a  O SnM_     U$ ! [         a  n[        SU
 S35      UeS nAff = f)NFr  z.Unknown child element (%s) of contour element.z&Unknown attribute in point element: %sz(Unknown child elements in point element.r  z	Required z' attribute is missing in point element.rj   r  zUnknown point type: %srJ  TrI  r   z9A move point occurs after the first point in the contour.r  r  zUnknown point smooth value: %sr  z*smooth attribute set in an offcurve point.r   r   zmove can not have an offcurve.r  zline can not have an offcurve.r  r    z%Too many offcurves defined for curve.r  )r   	enumeraterk  r
   r   r  rS  r   r  r   poppointTypeOptionsr   pointSmoothOptionsreversed)r  pointAttributesr  r   lastOnCurvePointhaveOffCurvePointr  indexr1  r  r   r~   	pointTyper  countoffCurvesCountrJ  s                    r*   r  r  D  s    w<<H#G,;;'!@7;;N  W^^$

.&'ORV'VWW % 7||"#MNND%ek2  IIfj1		)997)CDD
"I(m $$	V+
K  8T**//"#Cf#LMM5 h9#4KLL' E&Mi -j # A;}%/E!(+'/QJE	 ,
 #GeV,%*:*F X*-==E.K"!#!"f,*+KLL$.*+KLL$/)A-"./V"WW .$0 !") * OO  "v%LMs   	I==
JJJc                >     [        XU5        g ! [         a     g f = fr"   )r   r   )objectr   r   s      r*   r  r    s#    e$ s    
c                     [        U 5      nU$ ! [         a     Of = f [        U 5      nU$ ! [         a    [        SU -  5      ef = f)ak  
Given a numeric string, return an integer or a float, whichever
the string indicates. _number("1") will return the integer 1,
_number("1.0") will return the float 1.0.

>>> _number("1")
1
>>> _number("1.0")
1.0
>>> _number("a")  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
GlifLibError: Could not convert a to an int or float.
z(Could not convert %s to an int or float.)r5  rZ   floatr
   )sns     r*   r  r    s]    F K!H KEIJJKs    
- Ac                      \ rS rSrSrg)_DoneParsingi  r5   N)r6   r7   r8   r9   r;   r5   r,   r*   r  r    s    r,   r  c                  ,    \ rS rSrS rS rS rS rSrg)_BaseParseri  c                    / U l         g r"   _elementStackr   s    r*   rF   _BaseParser.__init__  s
    r,   c                    SSK Jn  U" 5       nU R                  Ul        U R                  Ul        UR                  US5        g )Nr   )ParserCreater   )xml.parsers.expatr  startElementHandlerStartElementHandlerendElementHandlerEndElementHandlerParse)rE   r   r  rc  s       r*   rh  _BaseParser.parse  s6    2%)%=%="#'#9#9 T1r,   c                :    U R                   R                  U5        g r"   )r  rS  )rE   r   r?  s      r*   r  _BaseParser.startElementHandler  s    !!$'r,   c                H    U R                   R                  S5      nX!:X  d   eg )NrY   )r  r  )rE   r   others      r*   r  _BaseParser.endElementHandler  s"    ""&&r*}}r,   r  N)	r6   r7   r8   r9   rF   rh  r  r  r;   r5   r,   r*   r  r    s     (r,   r  c                P    [        5       nUR                  U 5        UR                  $ )z(
Get a list of unicodes listed in glif.
)_FetchUnicodesParserrh  r   glifrc  s     r*   r   r     s"     "#F
LL??r,   c                  4   ^  \ rS rSrU 4S jrU 4S jrSrU =r$ )r	  i  c                0   > / U l         [        TU ]	  5         g r"   )r   r%   rF   rE   r)   s    r*   rF   _FetchUnicodesParser.__init__  s    r,   c                .  > US:X  ao  U R                   (       a^  U R                   S   S:X  aK  UR                  S5      nUb7   [        US5      nX0R                  ;  a  U R                  R	                  U5        [        TU ]  X5        g ! [
         a     Nf = f)Nr3  rY   r  r4  r  )r  r   r5  r   rS  rZ   r%   r  )rE   r   r?  r   r)   s       r*   r  (_FetchUnicodesParser.startElementHandler  s    I""""2&'1IIe$E rNEMM1,,U3 	#D0 " s   6B 
BB)r   r6   r7   r8   r9   rF   r  r;   r<   r=   s   @r*   r	  r	    s    1 1r,   r	  c                    [        5       n UR                  U 5        UR                  $ ! [         a     UR                  $ f = f)z)
The image file name (if any) from glif.
)_FetchImageFileNameParserrh  r  r   r
  s     r*   r   r     sG     '(FT ??  ??s   ) 
A Ac                  4   ^  \ rS rSrU 4S jrU 4S jrSrU =r$ )r  i#  c                0   > S U l         [        TU ]	  5         g r"   )r   r%   rF   r  s    r*   rF   "_FetchImageFileNameParser.__init__$  s    r,   c                   > US:X  a@  U R                   (       a/  U R                   S   S:X  a  UR                  S5      U l        [        e[        TU ]  X5        g )Nr  rY   r  r   )r  r   r   r  r%   r  )rE   r   r?  r)   s      r*   r  -_FetchImageFileNameParser.startElementHandler(  sH    7?t11d6H6H6LPW6W!IIj1DM#D0r,   )r   r  r=   s   @r*   r  r  #  s    1 1r,   r  c                    [        5       n UR                  U 5        [        UR                  5      $ ! [         a     N!f = f)z5
Get a list of component base glyphs listed in glif.
)_FetchComponentBasesParserrh  r  r   basesr
  s     r*   r   r   2  sB     ()FT   s   2 
??c                  @   ^  \ rS rSrU 4S jrU 4S jrU 4S jrSrU =r$ )r  i>  c                0   > / U l         [        TU ]	  5         g r"   )r  r%   rF   r  s    r*   rF   #_FetchComponentBasesParser.__init__?  s    
r,   c                   > US:X  aS  U R                   (       aB  U R                   S   S:X  a/  UR                  S5      nUb  U R                  R                  U5        [        TU ]  X5        g )Nr  rY   r  re   )r  r   r  rS  r%   r  )rE   r   r?  re   r)   s       r*   r  ._FetchComponentBasesParser.startElementHandlerC  sZ    K""""2&)399V$D

!!$'#D0r,   c                <   > US:X  a  [         e[        TU ]	  U5        g )Nr  )r  r%   r  )rE   r   r)   s     r*   r  ,_FetchComponentBasesParser.endElementHandlerN  s    9!$'r,   )r  )	r6   r7   r8   r9   rF   r  r  r;   r<   r=   s   @r*   r  r  >  s    	1( (r,   r  ))r  r   )r  r   )r  r   )r  r   )r  r   )r  r   c                  H    \ rS rSrSrS
S jrSS jrS r SS jrSS jr	S	r
g)r#  ic  zV
Helper class using the PointPen protocol to write the <outline>
part of .glif files.
Nc                    Uc
  [        5       n[        U5      U l        X0l        Xl        S U l        SU l        / U l        X@l        g )Nr   )	r  r   r   r  r  r  prevOffCurveCountprevPointTypesr   )rE   r1  r   r  r   s        r*   rF   GLIFPointPen.__init__i  sC    %K.}=&!"  r,   c                   [        5       nUb  U R                  R                  S:  ak  U R                  (       a;  XR                  ;   a  [        SU-  5      e[        U5      (       d  [        SU-  5      eXS'   U R                  R                  U5        [        R                  " U R                  SU5      U l        SU l        g )Nr    rE  %identifier not formatted properly: %srD  r  r   )r   r   rs   r   r  r
   r   r0   r   r"  r  r  r&  )rE   rD  r  r?  s       r*   rK  GLIFPointPen.beginPatht  s    !d&8&8&>&>!&C}}!1!11&<zI  +:66&?*L  #-,  ,''iG!"r,   c                8   U R                   (       aB  U R                   S   S:X  a/  U R                  (       a  U R                   S   S:X  a  [        S5      e[        U R                  5      (       d  SU R                  l        S U l        S U l        SU l        / U l         g )Nr   rI  rY   r  z%open contour has loose offcurve pointr  )r'  r   r
   r   r  r   prevPointTyper&  r   s    r*   rM  GLIFPointPen.endPath  s|    4#6#6q#9V#C}}!4!4R!8J!F"#JKK4<<   &DLL!!" r,   c                L   [        5       nUb\  U R                  (       a)  U H#  n[        U[        5      (       a  M  [	        S5      e   [        US   5      US'   [        US   5      US'   US:X  a  S nU R                  (       a{  US:X  a  U R                  (       a  [	        S5      eUS	;   a2  U R                  (       a!  U R                  S
   S:X  a  [	        SU-  5      eUS:X  a  U R                  S:  a  [	        S5      eUb  X'S'   OSnUS:X  a  U =R                  S-  sl        OSU l        U R                  R                  U5        U(       a'  U R                  (       a  US:X  a  [	        S5      eSUS'   Ub  XGS'   Ub  U R                  R                  S:  ak  U R                  (       a;  XPR                  ;   a  [	        SU-  5      e[        U5      (       d  [	        SU-  5      eXWS'   U R                  R                  U5        [        R                  " U R                   SU5        g )Nz coordinates must be int or floatr   rA  r   rB  r  rI  z@move occurs after a point has already been added to the contour.)rI  r  rY   z offcurve occurs before %s point.r  r    z,too many offcurve points before curve point.rj   z&can't set smooth in an offcurve point.r  r  r   rE  r*  rD  r  )r   r   r]   r   r
   r  r'  r&  rS  r   rs   r  r   r0   r   r"  r  )	rE   ptrJ  r  r   rD  r  r?  coords	            r*   rL  GLIFPointPen.addPoint  s    >}}E%e[99*+MNN   beE#JbeE#J*$K==f$)<)<"V  //''''+z9"#E#STTg%$*@*@1*D"#QRR"'&M$K*$""a'"%&D""";/}}
!:"#KLL#E(O &M!d&8&8&>&>!&C}}!1!11&<zI  +:66&?*L  #-,  ,w6r,   c                X   [        SU4/5      n[        [        U5       HM  u  u  pgnU R                  (       a   [	        U[
        5      (       d  [        S5      eX:w  d  M@  [        U5      XV'   MO     Ub  U R                  R                  S:  a|  U R                  (       aL  X0R                  ;   a  [        SU-  5      eU R                  (       a  [        U5      (       d  [        SU-  5      eX5S'   U R                  R                  U5        [        R                  " U R                  SU5        g )Nre   z*transformation values must be int or floatr    rE  r*  rD  r  )r   zipr>  r   r]   r   r
   r  r   rs   r  r   r0   r   r"  r  )	rE   rC   r  rD  r  r?  r   r&   r   s	            r*   r  GLIFPointPen.addComponent  s    fi012&)*=~&N"OTU}}Z{%C%C"#OPP"5k	 'O
 !d&8&8&>&>!&C}}!1!11&<zI  ==)<Z)H)H&?*L  #-,  ,{E:r,   )r  r   r  r  r&  r-  r'  r   )NNTr"   r   )r6   r7   r8   r9   rR   rF   rK  rM  rL  r  r;   r5   r,   r*   r#  r#  c  s(    
	!#"
! HL:7x;r,   r#  __main__)NNNT)NNNNTr   )NNNr   )FT)srR   
__future__r   loggingenumwarningsr   collectionsr   r_   fs.base	fs.errorsfs.osfsfs.pathfontTools.misc.textToolsr   fontTools.miscr   fontTools.pens.pointPenr   r	   r[   r
   fontTools.ufoLib.filenamesr   fontTools.ufoLib.validatorsr   r   r   r   r   r   r   r   fontTools.ufoLibr   r   fontTools.ufoLib.utilsr   r   __all__	getLoggerr6   rs  rq   r   r  Enumr   __str__r?   r   r   r   r   r   r  r  r  r  r   r$  r!  r%  r   r^   r   r]  r   rm  r   r$   r   r  r  r.   r1   ru  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rp  r  r  r   r	  r   r  r   r  r>  r#  doctesttestmodr5   r,   r*   <module>rM     s  
 #    # 	     , # G 0 9   ! 9 F 
		8	$ % & #5tyy #. 3::  @ @>{z {F	U& Ql @J : zH2@2."6<"32/* s>:T*>? 80
& $7790h 598;x GHb9L   ";  "; 83//5 )>   8<.H = /<.@ E] B 
90$P;0WBB#
T KOeZKD	9 	 .1; 12		1 	1	( (4 };# };@ zOO r,   