
    <`                        d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZmZ d dlZd dlZd dlZ ej        e          Z G d d	e          Z G d
 de          Z G d de          Z G d de          Z G d de          Z G d de          Zd Zi Zd(dZd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)g d Z*g d!Z+d(d"Z,d)d$Z-d% Z.d*d'Z/dS )+    )	xmlWriter)Tagbyteordtostr)deprecateArgument)
TTLibError)
SFNTReader
SFNTWriter)BytesIOStringIONc                      e Zd ZdZ	 	 	 	 	 d+dZd	 Zd
 Zd Zd,dZd-dZ	d-dZ
	 	 	 	 d.dZd/dZd-dZd Zd ZeZd Zd Zd Zd Zd Zd Zd-dZd Zd Zd Zed             Zd  Zd! Zd0d"Zd0d#Z d0d$Z!d% Z"d-d&Z#d' Z$d,d(Z%d1d*Z&dS )2TTFontzThe main font object. It manages file input and output, and offers
	a convenient way of accessing tables.
	Tables will be only decompiled when necessary, ie. when they're actually
	accessed. This means that simple operations can be extremely fast.
	N   r   TFc                    dD ]F}t                                          |          }|t          |d           t          | ||           G|| _        || _        |
| _        i | _        d| _        d| _	        i | _
        i | _        || _        |	| _        |s|| _        || _        d| _        dS t#          |d          sud}|`ddlm} |d	k    r=|                    |          r|                    |d          }nPt-          |d
          }n?|                    ||          }n(t-          |d
          }nd}|                    d	           | j        sj|                    d	           t1          |                                          }t#          |d          r|j        |_        |r|                                 |}|| _        t;          |||          | _        | j        j        | _        | j        j        | _        | j        j        | _        dS )a
  The constructor can be called with a few different arguments.
		When reading a font from disk, 'file' should be either a pathname
		pointing to a file, or a readable file object.

		It we're running on a Macintosh, 'res_name_or_index' maybe an sfnt
		resource name or an sfnt resource index number or zero. The latter
		case will cause TTLib to autodetect whether the file is a flat file
		or a suitcase. (If it's a suitcase, only the first 'sfnt' resource
		will be read!)

		The 'checkChecksums' argument is used to specify how sfnt
		checksums are treated upon reading a file from disk:
			0: don't check (default)
			1: check, print warnings if a wrong checksum is found
			2: check, raise an exception if a wrong checksum is found.

		The TTFont constructor can also be called without a 'file'
		argument: this is the way to create a new empty font.
		In this case you can optionally supply the 'sfntVersion' argument,
		and a 'flavor' which can be None, 'woff', or 'woff2'.

		If the recalcBBoxes argument is false, a number of things will *not*
		be recalculated upon save/compile:
			1) 'glyf' glyph bounding boxes
			2) 'CFF ' font bounding box
			3) 'head' font bounding box
			4) 'hhea' min/max values
			5) 'vhea' min/max values
		(1) is needed for certain kinds of CJK fonts (ask Werner Lemberg ;-).
		Additionally, upon importing an TTX file, this option cause glyphs
		to be compiled right away. This should reduce memory consumption
		greatly, and therefore should have some impact on the time needed
		to parse/compile large fonts.

		If the recalcTimestamp argument is false, the modified timestamp in the
		'head' table will *not* be recalculated upon save/compile.

		If the allowVID argument is set to true, then virtual GID's are
		supported. Asking for a glyph ID with a glyph name or GID that is not in
		the font will return a virtual GID.   This is valid for GSUB and cmap
		tables. For SING glyphlets, the cmap table is used to specify Unicode
		values for virtual GI's used in GSUB/GPOS rules. If the gid N is requested
		and does not exist in the font, or the glyphname has the form glyphN
		and does not exist in the font, then N is used as the virtual GID.
		Else, the first virtual GID is assigned as 0x1000 -1; for subsequent new
		virtual GIDs, the next is one less than the previous.

		If ignoreDecompileErrors is set to True, exceptions raised in
		individual tables during decompilation will be ignored, falling
		back to the DefaultTable implementation, which simply keeps the
		binary data.

		If lazy is set to True, many data structures are loaded lazily, upon
		access only.  If it is set to False, many data structures are loaded
		immediately.  The default is lazy=None which is somewhere in between.
		)verbosequietNconfigure logging insteadi  readT   )macUtilsr   rbFname)
fontNumber)localsgetr   setattrlazyrecalcBBoxesrecalcTimestamptablesreaderlast_vidreverseVIDDictVIDDictallowVIDignoreDecompileErrorssfntVersionflavor
flavorDatahasattr r   getSFNTResIndicesSFNTResourceReaderopenseekr   r   r   close_tableCacher	   )selffileres_name_or_indexr(   r)   checkChecksumsr   r   r&   r'   r    r   r   r   r2   r   valcloseStreamr   tmps                       6lib/python3.11/site-packages/fontTools/ttLib/ttFont.py__init__zTTFont.__init__   s$   ~ #  d	d		3	od7888
4s$)"$($$+$+ $-$$,$-4$	 
!44;4?	6	v		 ;#A""4(( ((q11dd$dd''.?@@TTdDD ;99Q<<<	 	99Q<<<			3dF yCH JJLLL
4 $4JGGG$+[,$"$+K*$///    c                     | S N r3   s    r:   	__enter__zTTFont.__enter__   s    	+r<   c                 .    |                                   d S r>   )r1   )r3   typevalue	tracebacks       r:   __exit__zTTFont.__exit__   s    **,,,,,r<   c                 J    | j         | j                                          dS dS )z+If we still have a reader object, close it.N)r"   r1   r@   s    r:   r1   zTTFont.close   s,    	[; r<   c                    t          |d          s.| j        r$| j        j        j        |k    rt          d          d}nd}t                      }|                     |          }||s|du r| j        v|du r't          | j        	                                          }nd}|
                                 t                      }t          |||           |                                 |}|rPt          |d          5 }|                    |                                           ddd           n# 1 swxY w Y   n'|                    |                                           |                                 dS )zSave the font to disk. Similarly to the constructor,
		the 'file' argument can be either a pathname or a writable
		file object.
		writez4Can't overwrite TTFont when 'lazy' attribute is TrueTFNwb)r+   r   r"   r4   r   r   r   _savelistkeysflushreorderFontTablesr1   r/   rI   getvalue)r3   r4   reorderTablescreateStreamr9   writer_reordersTables
tableOrdertmp2s           r:   savezTTFont.save   s   
 
w		 
i =DK$)T11
;= = =<< <		#**S//

#8
e 3udk&&(())JJ J99;;;
))4S$
+++99;;;	3 T4 DJJs||~~               ::cllnn))+++++s   ;(D//D36D3c                    | j         rd| v r| d          t          |                                           }d|v r|                    d           t	          |          }t          ||| j        | j        | j                  }g }|D ]}| 	                    ||||           |
                                 |                                S )zAInternal function, to be shared by save() and TTCollection.save()head
GlyphOrder)r    rL   rM   removelenr
   r(   r)   r*   _writeTabler1   reordersTables)r3   r4   
tableCachetags	numTableswriterdonetags           r:   rK   zTTFont._save   s     
 fnn<<	diikk		$T;;|$ii)dIt'7doVV&	$ 3 3cCz2222,,...				 	  r<   c                 v    t          j        ||          } | j        |fi | |                                 dS )a  Export the font as TTX (an XML-based text file), or as a series of text
		files when splitTables is true. In the latter case, the 'fileOrPath'
		argument should be a path to a directory.
		The 'tables' argument must either be false (dump all tables) or a
		list of tables to dump. The 'skipTables' argument may be a list of tables
		to skip, but only when the 'tables' argument is false.
		
newlinestrN)r   	XMLWriter_saveXMLr1   )r3   
fileOrPathrf   kwargsra   s        r:   saveXMLzTTFont.saveXML   sD     zjAAA&$-!!&!!!,,.....r<   rawc
                    |t          dd           || _        |	| _        |sKt          |                                           }d|vrdg|z   }|r|D ]}
|
|v r|                    |
           t          |          }|rvddlm} d	                    |
                    d          d d                   }|                    dt          t          | j                            d	d
         |           n>|                    dt          t          | j                            d	d
                    |                                 |p|}|s|                                 n/t           j                            |j                  \  }}|dz   |z   }t)          |          D ](}||         }
|r|t+          |
          z  }t-          j        ||j                  }|                    d|           |                                 |                                 |                    t5          |
          t           j                            |                     |                                 n|}|                     ||
|           |r=|                    d           |                                 |                                 *|                    d           |                                 d S )Nr   r   rY   r   )version.   ttFontr   r   )r(   ttLibVersion)r(   z.%sre   )rr   )srcsplitGlyphs)r   disassembleInstructionsbitmapGlyphDataFormatrL   rM   rZ   r[   	fontToolsrn   joinsplitbegintagreprr   r(   newlineospathsplitextfilenamerangetagToIdentifierr   rg   rf   	simpletagtagToXMLbasename_tableToXMLendtagr1   )r3   ra   writeVersionr   r!   
skipTablessplitTablesru   rv   rw   rc   r`   rn   r   extfileNameTemplatei	tablePathtableWriters                      r:   rh   zTTFont._saveXML   s    W9:::!8$4$	 6&  ^f$F   vmmC&kk) N      XXgmmC((!,--7	??8eD4D.E.E)F)Fqt)L      
??8eD4D.E.E)F)Fqt)L?MMM.. *{+	 )	>>w0094UlS(  a	3 
 ?3#7#77I%i"$ $ $K888
Xc]](8(8(C(CDDD
NNKK+>>> x   --..r<   c                 P   |t          dd           || v r| |         }d|z  }nd|z  }t                              |           || vrd S t          |          }t	                      }t          |d          rd|d<   ddlm}	 |j        |	k    rd	|d
<    |j	        |fi | |
                                 |dk    r|                    || |           n|                    ||            |                    |           |
                                 |
                                 d S )Nr   r   zDumping '%s' table...zNo '%s' table found.ERRORzdecompilation errorr   DefaultTableTrl   glyfrt   )r   loginfor   dictr+   tables.DefaultTabler   	__class__r{   r}   toXMLr   )
r3   ra   rc   r   ru   tablereportxmlTagattrsr   s
             r:   r   zTTFont._tableToXML#  sR   
W9:::D[[95#c)66"S(6((6__	6C==&
&&%UG *)5>//////
_$$5<&/&""E"""..F]];;vt;5555;;vt--....r<   c                     |t          dd           d| v rd| v r|                                  ddlm} |                    ||           }|                                 dS )zSImport a TTX file (an XML-based text format), so as to recreate
		a font object.
		Nr   r   maxppostr   )	xmlReader)r   getGlyphOrderfontTools.miscr   	XMLReaderr   )r3   ri   r   r   r"   s        r:   	importXMLzTTFont.importXML?  sx     W9:::t^^$
 &&&&&&z400&++-----r<   c                     || j         v S )zZReturn true if the table identified by 'tag' has been
		decompiled and loaded into memory.r!   r3   rc   s     r:   isLoadedzTTFont.isLoadedR  s     
	r<   c                 h    |                      |          rdS | j        r|| j        v rdS |dk    rdS dS )NTrY   F)r   r"   r   s     r:   has_keyzTTFont.has_keyW  sK    	]]3 
${ sdk))
$
l
$
%r<   c                 <   t          | j                                                  }| j        rBt          | j                                                  D ]}||vr|                    |           d|v r|                    d           t          |          }dg|z   S )NrY   )rL   r!   rM   r"   appendrZ   sortedTagList)r3   rM   keys      r:   rM   zTTFont.keysc  s    	dk  	!	!$	[ 4;##%%&&  s
$	[[T;;|	t		$
$	r<   c                 ^    t          t          |                                                     S r>   )r[   rL   rM   r@   s    r:   __len__zTTFont.__len__o  s     	T$))++		r<   c                     t          |          }| j                            |          }|O|dk    rt          |          }|| j        |<   n/| j        |                     |          }nt          d|z            |S )NrY   '%s' table not found)r   r!   r   rY   r"   
_readTableKeyErrorr3   rc   r   s      r:   __getitem__zTTFont.__getitem__r  s~    C#
+//#

%
]	\sOOEDKOOC  EE
)C/
0
00	,r<   c                    t                               d|           | j        |         }| j         | j                            ||f          }||S t          |          } ||          }|| j        |<   t                               d|           	 |                    ||            n# t          $ r | j	        s t           
                    d|           ddlm} t                      }t          j        |            ||          }|                                |_        || j        |<   |                    ||            Y nw xY w| j        || j        ||f<   |S )NReading '%s' table from diskzDecompiling '%s' tablez@An exception occurred during the decompilation of the '%s' tabler   r   )r4   )r   debugr"   r2   r   getTableClassr!   	decompile	Exceptionr'   	exceptionr   r   r   rE   	print_excrP   r   )r3   rc   datar   
tableClassr   r4   s          r:   r   zTTFont._readTable  s   ))*C000	S	$	!d,,5LS!!*
*S//%$+c))$c***??4	   

$ 
	==FM M M000000
**4D!!!!<55;4;s??4 
!#(4S$K 	,s   B' 'BEEc                 4    || j         t          |          <   d S r>   )r!   r   r   s      r:   __setitem__zTTFont.__setitem__  s    $+c#hhr<   c                     || vrt          d|z            || j        v r| j        |= | j        r|| j        v r| j        |= d S d S d S )Nr   )r   r!   r"   r   s     r:   __delitem__zTTFont.__delitem__  sl    __	(3.	/	//DK{3	[ SDK''{3 ''r<   c                 8    	 | |         S # t           $ r |cY S w xY wr>   r   )r3   rc   defaults      r:   r   z
TTFont.get  s5    
s)	   
>>>   
 c                     || _         d S r>   )
glyphOrder)r3   r   s     r:   setGlyphOrderzTTFont.setGlyphOrder  s    $///r<   c                 .   	 | j         S # t          $ r Y nw xY wd| v r"| d         }|                                | _         nQd| v r9| d                                         }||                                  n|| _         n|                                  | j         S )NCFF r   )r   AttributeErrorr   _getGlyphNamesFromCmap)r3   cffr   s      r:   r   zTTFont.getGlyphOrder  s    
/	   4t^^	f3&&((4??~~V**,,: 	!!!! DOO   	s   	 
c                 l   |                      d          r| j        d         }| j        d= nd }t          | d         j                  }d g|z  }d|d<   t	          d|          D ]
}d|z  ||<   || _        d| v r| d                                         }ni }i }t	          |          D ]i}||         }||v r[|                     t          ||                             }|	                    |d          dz   x}	||<   |	dk    r
d||	dz
  fz  }|||<   jd| v r| j        d= || _        |r|| j        d<   d S d S d S )Ncmapr   z.notdefr   r   	glyph%.5dz%s.alt%d)
r   r!   int	numGlyphsr   r   buildReversed_makeGlyphNameminr   )
r3   cmapLoadingr   r   r   reversecmapuseCounttempName	glyphNamenumUsess
             r:   r   zTTFont._getGlyphNamesFromCmap  s    
]]6  V$;{6; $v,()))v	!**Q-I # #a?:a== $/ t^^f++--;;;( 
 
am8+ ##CH(=$>$>??I$,LLA$>$>$BBGhy!{{y'A+66YJqMt^^ {64? & &DK ^
& &r<   c                 Z    ddl m} | |j        v r|j        |          S | dk    rd| z  S d| z  S )Nr   )agli  zuni%04Xzu%X)rx   r   UV2AGL)	codepointr   s     r:   r   zTTFont._makeGlyphName  sO    #*
*Y
F
i

)
r<   c                 H    t          |                                           }|S )z1Get a list of glyph names, sorted alphabetically.)sortedr   )r3   
glyphNamess     r:   getGlyphNameszTTFont.getGlyphNames  s!    d((**++*	r<   c                 \    ddl m} |                    |                                           S )zNGet a list of glyph names, sorted alphabetically,
		but not case sensitive.
		r   )	textTools)r   r   caselessSortr   )r3   r   s     r:   getGlyphNames2zTTFont.getGlyphNames2  s6     '&&&&&			 2 2 4 4	5	55r<   c                     	 |                                  |         S # t          $ rg |s| j        sd|z  cY S 	 | j        |         }nC# t          $ r6 d|z  }t          || j                  | _        || j        |<   || j        |<   Y nw xY w|cY S w xY w)Nr   )r   
IndexErrorr&   r%   r   r   r#   r$   )r3   glyphIDrequireRealr   s       r:   getGlyphNamezTTFont.getGlyphName#  s    




w
''	          'g&YY ' ' 'w&Y$-11T]&-T#&T\'	'
 s2    BAB=BBBBBc                 8   t          | d          s|                                  |                                 }| j        }||vr||v r)|                                  |                     |          S |rt          |          | j        sK|d d         dk    r<	 t          |dd                    S # t          t          f$ r t          |          w xY wn	 | j
        |         }nw# t
          $ rj |d d         dk    r2	 t          |dd                    }n# t          t          f$ r d }Y nw xY w|| j        dz
  }|| _        || j
        |<   || j        |<   Y nw xY w|S ||         }|||         k    r)|                                  |                     |          S |S )N_reverseGlyphOrderDict   glyphr   )r+   _buildReverseGlyphOrderDictr   r   
getGlyphIDr   r&   r   	NameError
ValueErrorr$   r#   r%   )r3   r   r   r   dr   s         r:   r   zTTFont.getGlyphID6  s   	/	0	0 &##%%%!!##*
!!a:$$&&&??9%%% I] "1"  !)ABB-   $ ! ! !i   ! 	!(#I.gg ( ( (	2A2'	!	!im$$*%   	!wt}'.d)$'dl7( ^iL'*W%%%##%%%
//)
$
$$	.sB   B0 0!CC$ $E=DED+(E*D++*EEc                 \    |st          | d          s|                                  | j        S )Nr   )r+   r   r   )r3   rebuilds     r:   getReverseGlyphMapzTTFont.getReverseGlyphMapa  s7     &GD":;; &##%%%		$$r<   c                     i x| _         }|                                 }t          t          |                    D ]}||||         <   d S r>   )r   r   r   r[   )r3   r   r   r   s       r:   r   z"TTFont._buildReverseGlyphOrderDictf  sY    $&&$!!##*s:'' $ $g#1Z$ $r<   c                 6   ||v rdS t          |          }|j        D ]8}||vr2|| v r|                     ||||           #|                    |           9|                    |           |                     |          }|Y|                    t          |          |f          }|3t                              d|           |	                    ||           dS t                              d|           |||<   |||         |t          |          |f<   dS dS )zWInternal helper function for self.save(). Keeps track of
		inter-table dependencies.
		Nzreusing '%s' tablezWriting '%s' table to disk)
r   dependenciesr\   r   getTableDatar   r   r   r   setEntry)	r3   rc   ra   rb   r^   r   masterTable	tabledataentrys	            r:   r\   zTTFont._writeTablel  s=    	D[[	6S!!*,  kd	k64<<<<	[[++c$$)>>3s88Y/005II"C(((
OOC
F))(#...&+'-c{:s3xx#$$$ r<   c                 N   t          |          }|                     |          r;t                              d|           | j        |                             |           S | j        r1|| j        v r(t                              d|           | j        |         S t          |          )zGReturns raw table data, whether compiled or directly read from disk.
		zCompiling '%s' tabler   )r   r   r   r   r!   compiler"   r   r   s     r:   r  zTTFont.getTableData  s     	C#	]]3 99#S)))
+c

"
"4
(
(({ sdk))99+S111
+c
	#r<   c                     d}|rt           fddD                       sd vrnt           fddD                       rSd v rdnd}t           t           |         j                                                  d         j        t                    }| d v rt            d         t                    }|t          d	          |S )
aS  Return a generic GlyphSet, which is a dict-like object
		mapping glyph names to glyph objects. The returned glyph objects
		have a .draw() method that supports the Pen protocol, and will
		have an attribute named 'width'.

		If the font is CFF-based, the outlines will be taken from the 'CFF ' or
		'CFF2' tables. Otherwise the outlines will be taken from the 'glyf' table.
		If the font contains both a 'CFF '/'CFF2' and a 'glyf' table, you can use
		the 'preferCFF' argument to specify which one should be taken. If the
		font contains both a 'CFF ' and a 'CFF2' table, the latter is taken.
		Nc              3       K   | ]}|v V  	d S r>   r?   .0tbr3   s     r:   	<genexpr>z%TTFont.getGlyphSet.<locals>.<genexpr>  s'      >>rd
>>>>>>r<   )r   CFF2r   c              3       K   | ]}|v V  	d S r>   r?   r  s     r:   r  z%TTFont.getGlyphSet.<locals>.<genexpr>  s'       G Gt G G G G G Gr<   r  r   r   zFont contains no outlines)	any_TTGlyphSetrL   r   valuesCharStrings_TTGlyphCFF_TTGlyphGlyfr   )r3   	preferCFFglyphs	table_tags   `   r:   getGlyphSetzTTFont.getGlyphSet  s     & GC>>>>-=>>>>> GDS G G G G6F G G GGG4vvV9DO&&(())!,8+G G6 ^$d6lL996^	/	0	00	-r<   )   
   )r      )r      )r  r   )r   r  )r   rp   )r   r   )r   r   c                 :    | d                              |          S )aF  Return the 'best' unicode cmap dictionary available in the font,
		or None, if no unicode cmap subtable is available.

		By default it will search for the following (platformID, platEncID)
		pairs:
			(3, 10), (0, 6), (0, 4), (3, 1), (0, 3), (0, 2), (0, 1), (0, 0)
		This can be customized via the cmapPreferences argument.
		r   )cmapPreferences)getBestCmap)r3   r!  s     r:   r"  zTTFont.getBestCmap  s     
f	!	!/	!	B	BBr<   )NNr   Nr   NTFFTr   NNN)Tr>   )TNNNFFTrl   NF)F)r  )'__name__
__module____qualname____doc__r;   rA   rF   r1   rV   rK   rk   rh   r   r   r   r   __contains__rM   r   r   r   r   r   r   r   r   r   staticmethodr   r   r   r   r   r   r   r\   r  r  r"  r?   r<   r:   r   r      s         26?@JO9=	z+ z+ z+ z+x      
' ' ' 'R! ! ! !*    =B26"	: : : :x   8   &  
   
 
 
         <              0B& B& B&H   ,  
6 6 6   &) ) ) )V% % % %
$ $ $3 3 3 34     6	C 	C 	C 	C 	C 	Cr<   r   c                   <    e Zd ZdZd Zd Zd ZeZd Zd Z	d	dZ
dS )
r  zfGeneric dict-like GlyphSet class that pulls metrics from hmtx and
	glyph shape from TrueType or CFF.
	c                 b    || _         |d         | _        d|v r|d         nd| _        || _        dS )zConstruct a new glyphset.

		Args:
			font (TTFont): The font object (used to get metrics).
			glyphs (dict): A dictionary mapping glyph names to ``_TTGlyph`` objects.
			glyphType (class): Either ``_TTGlyphCFF`` or ``_TTGlyphGlyf``.
		hmtxvmtxN)_glyphs_hmtx_vmtx
_glyphType)r3   rq   r  	glyphTypes       r:   r;   z_TTGlyphSet.__init__  s:     $,f~$*!'6!1!1vf~~t$*$///r<   c                 N    t          | j                                                  S r>   )rL   r.  rM   r@   s    r:   rM   z_TTGlyphSet.keys  s    	dl!!	"	""r<   c                     || j         v S r>   )r.  )r3   r   s     r:   r   z_TTGlyphSet.has_key  s    	dl	""r<   c                     | j         |         }| j        r| j        |         nd }|                     | | j        |         ||          S r>   )r/  r0  r1  r.  )r3   r   horizontalMetricsverticalMetricss       r:   r   z_TTGlyphSet.__getitem__  sQ    j+-1ZADJy))T/	i	 "3_
F 
F Fr<   c                 *    t          | j                  S r>   )r[   r.  r@   s    r:   r   z_TTGlyphSet.__len__  s    	T\		r<   Nc                 8    	 | |         S # t           $ r |cY S w xY wr>   r   )r3   r   r   s      r:   r   z_TTGlyphSet.get  s5    
y/	   
>>>r   r>   )r$  r%  r&  r'  r;   rM   r   r(  r   r   r   r?   r<   r:   r  r    s           # # ## # # F F F       r<   r  c                   &    e Zd ZdZddZd Zd ZdS )_TTGlyphaQ  Wrapper for a TrueType glyph that supports the Pen protocol, meaning
	that it has .draw() and .drawPoints() methods that take a pen object as
	their only argument. Additionally there are 'width' and 'lsb' attributes,
	read from the 'hmtx' table.

	If the font contains a 'vmtx' table, there will also be 'height' and 'tsb'
	attributes.
	Nc                     || _         || _        |\  | _        | _        |r|\  | _        | _        dS d\  | _        | _        dS )zConstruct a new _TTGlyph.

		Args:
			glyphset (_TTGlyphSet): A glyphset object used to resolve components.
			glyph (ttLib.tables._g_l_y_f.Glyph): The glyph object.
			horizontalMetrics (int, int): The glyph's width and left sidebearing.
		)NNN)	_glyphset_glyphwidthlsbheighttsb)r3   glyphsetr   r6  r7  s        r:   r;   z_TTGlyph.__init__  sL     $.$+*$*dh &*4;%4;r<   c                 :    | j                             |           dS )zXDraw the glyph onto ``pen``. See fontTools.pens.basePen for details
		how that works.
		N)r>  drawr3   pens     r:   rE  z_TTGlyph.draw  s      +3r<   c                     t                      r>   )NotImplementedErrorrF  s     r:   
drawPointsz_TTGlyph.drawPoints  s    r<   r>   )r$  r%  r&  r'  r;   rE  rJ  r?   r<   r:   r;  r;    sP         & & & &       r<   r;  c                       e Zd ZdS )r  N)r$  r%  r&  r?   r<   r:   r  r  	  s        r<   r  c                       e Zd Zd Zd ZdS )r  c                     | j         j        }| j        }t          |d          r| j        |j        z
  nd}|                    |||           dS )zTDraw the glyph onto Pen. See fontTools.pens.basePen for details
		how that works.
		xMinr   N)r=  r.  r>  r+   r@  rN  rE  r3   rG  	glyfTabler   offsets        r:   rE  z_TTGlyphGlyf.draw  sS     n$)
+%$+E6$:$:A48ej  &**S)V$$$$$r<   c                     | j         j        }| j        }t          |d          r| j        |j        z
  nd}|                    |||           dS )zZDraw the glyph onto PointPen. See fontTools.pens.pointPen
		for details how that works.
		rN  r   N)r=  r.  r>  r+   r@  rN  rJ  rO  s        r:   rJ  z_TTGlyphGlyf.drawPoints  sU     n$)
+%$+E6$:$:A48ej  &3	6*****r<   N)r$  r%  r&  rE  rJ  r?   r<   r:   r  r    s2        % % %+ + + + +r<   r  c                   &    e Zd ZdZddZd Zd ZdS )rY   zA pseudo table. The glyph order isn't in the font as a separate
	table, but it's nice to present it as such in the TTX format.
	Nc                     d S r>   r?   r   s     r:   r;   zGlyphOrder.__init__'  s    $r<   c                 &   |                                 }|                    d           |                                 t          t	          |                    D ]6}||         }|                    d||           |                                 7d S )NzAThe 'id' attribute is only for humans; it is ignored when parsed.GlyphID)idr   )r   commentr}   r   r[   r   )r3   ra   rq   r   r   r   s         r:   r   zGlyphOrder.toXML*  s    ##%%*.. ! " " "..Z!!  a!}9	I!)444	>> r<   c                     t          | d          s!g | _        |                    | j                   |dk    r"| j                            |d                    d S d S )Nr   rV  r   )r+   r   r   r   )r3   r   r   contentrq   s        r:   fromXMLzGlyphOrder.fromXML4  sd    	|	$	$ )4?	(((	Y?%-((((( r<   r>   )r$  r%  r&  r'  r;   r   r[  r?   r<   r:   rY   rY   !  sP              ) ) ) ) )r<   rY   c                     ddl m} t          |           }	 t          d|z              t	          ||          S # t
          $ r3}t          |                              |          dk    rY d}~dS |d}~ww xY w)zUFetch the packer/unpacker module for a table.
	Return None when no module is found.
	r   r   zfontTools.ttLib.tables.r   N)r,   r!   r   
__import__getattrImportErrorstrfind)rc   r!   pyTagerrs       r:   getTableModulerd  <  s     			 &./// 
		 	   
 	XX]]5Q
$$$$$	9s   9 
A6&A1/A11A6c                 F    |dt          |           z   }||ft          | <   dS )a?  Register a custom packer/unpacker class for a table.
	The 'moduleName' must be an importable module. If no 'className'
	is given, it is derived from the tag, for example it will be
	table_C_U_S_T_ for a 'CUST' tag.

	The registered table class should be a subclass of
	fontTools.ttLib.tables.DefaultTable.DefaultTable
	Ntable_)r   _customTableRegistry)rc   
moduleName	classNames      r:   registerCustomTableClassrj  W  s2     ---)()4cr<   c                     t           | = dS )z8Unregister the custom packer/unpacker class for a table.N)rg  rc   s    r:   unregisterCustomTableClassrm  e  s    #r<   c                     | t           vrdS ddl}t           |          \  }}|                    |          }t          ||          S )zyReturn the custom table class for tag, if one has been registered
	with 'registerCustomTableClass()'. Else return None.
	Nr   )rg  	importlibimport_moduler^  )rc   ro  rh  ri  modules        r:   getCustomTableClassrr  j  sS     ###	-c2Y

!
!*
-
-	"""r<   c                     t          |           }||S t          |           }|ddlm} |S t	          |           }t          |d|z             }|S )z,Fetch the packer/unpacker class for a table.Nr   r   rf  )rr  rd  r   r   r   r^  )rc   r   rq  r   rb  s        r:   r   r   v  sl    !#&&	



N//////				fh.//r<   c                 b    | j         }|dd         dk    sJ |dd         }t          |          S )z'Fetch the table tag for a class object.Nr  rf  )r$  identifierToTag)klassr   s     r:   getClassTagrw    s=    RaRHQRRr<   c                 6    t          |           } ||           S )z!Return a new instance of a table.)r   )rc   r   s     r:   newTablery    s    C  
3r<   c                     ddl }|                    d|           rd| z   S |                    d|           r| dz   S t          t          |                     dd         S )z%Helper function for tagToIdentifier()r   Nz[a-z0-9]_z[A-Z]rp   )rematchhexr   )cr|  s     r:   _escapecharr    sd    
HHZ 	q.hhw 	
S.	WQZZ	r<   c                 n   ddl }t          |           } | dk    r| S t          |           dk    s
J d            t          |           dk    r5| d         dk    r)| dd         } t          |           dk    r| d         dk    )d	}| D ]}|t          |          z   }|                    d
|          rd|z   }|S )a4  Convert a table tag to a valid (but UGLY) python identifier,
	as well as a filename that's guaranteed to be unique even on a
	caseless file system. Each character is mapped to two characters.
	Lowercase letters get an underscore before the letter, uppercase
	letters get an underscore after the letter. Trailing spaces are
	trimmed. Illegal characters are escaped as two hex bytes. If the
	result starts with a number (as the result of a hex escape), an
	extra underscore is prepended. Examples:
		'glyf' -> '_g_l_y_f'
		'cvt ' -> '_c_v_t'
		'OS/2' -> 'O_S_2f_2'
	r   NrY   r  ztag should be 4 characters longr   r    r,   z[0-9]r{  )r|  r   r[   r  r}  )rc   r|  identr  s       r:   r   r     s     
3xx<	*CA8
3xx!||B3CRC# 3xx!||B3	
 ! !Q
+a..
 %%HHWe 
+%r<   c           
         | dk    r| S t          |           dz  r| d         dk    r
| dd         } t          |           dz  rJ d}t          dt          |           d          D ]c}| |         dk    r|| |dz            z   }| |dz            dk    r|| |         z   }8|t          t          | ||dz            d                    z   }d|d	t          |          z
  d
z  z   }t	          |          S )z!the opposite of tagToIdentifier()rY   rp   r   r{  r   Nr,      r  r  )r[   r   chrr   r   )r  rc   r   s      r:   ru  ru    s   	\	,JJN uQx3
)%ZZ!^	
3u::q
!
! * *Q
1X__	uQqSz	33QqSzS	uQx33 
s3uQqsU|R(())	)33
a#c((lc!!Cr<   c                     ddl }t          |           } | dk    rdS | dk    r| S |                    d|           r|                                 S t	          |           S )zSimilarly to tagToIdentifier(), this converts a TT tag
	to a valid XML element name. Since XML element names are
	case sensitive, this is a fairly simple/readable translation.
	r   NOS/2OS_2rY   z[A-Za-z_][A-Za-z_0-9]* *$)r|  r   r}  stripr   )rc   r|  s     r:   r   r     si    
 
3xx6MM		\	*HH(#.. 				r<   c                     | dk    rt          d          S t          |           dk    rt          |           S t          | ddt          |           z
  z  z             S )zThe opposite of tagToXML()r  r     r  r  )r   r[   ru  rl  s    r:   xmlToTagr    sV    6MM	VHHMM				S3!c#hh,''	(	((r<   )rX   hhear   r  r,  LTSHVDMXhdmxr   fpgmprepzcvt locar   kernr   r   gaspPCLT)rX   r  r   r  r   r   r   r   c                 >   t          |           } |Ad| v r*|                     d           |                     d           d| v rt          }nt          }g }|D ]0}|| v r*|                    |           |                     |           1|                    |            |S )zReturn a sorted copy of tagList, sorted according to the OpenType
	specification, or according to a custom tableOrder. If given and not
	None, tableOrder needs to be a list of tag names.
	NDSIGr   )r   rZ   r   OTFTableOrderTTFTableOrderextend)tagListrT   orderedTablesrc   s       r:   r   r     s    
 '??w
>>&
>>&w:::  SG^^
>>#gr<   Fc                    |                      d           |                     d           t          | |          }t          |t          |j                  |j        |j        |j                  }t          |	                                          }t          ||          D ]}||         ||<   |                                 dS )z]Rewrite a font file, ordering the tables as recommended by the
	OpenType specification 1.4.
	r   )r6   N)r0   r	   r
   r[   r!   r(   r)   r*   rL   rM   r   r1   )inFileoutFilerT   r6   r"   ra   r!   rc   s           r:   rO   rO   
  s     Qa
VN
;
;
;
Wc&-00&2DfmU[Uf
g
g
v{{}}

&*--  Ss&++r<   c                 H    d}| r| dz	  } |dz   }| t          |dz
  d          S )zYReturn the highest exponent of two, so that
	(2 ** exponent) <= x.  Return 0 if x is 0.
	r   r   )max)xexponents     r:   maxPowerOfTwor    sC      1f!\( 	  	HqL!r<   r  c                 j    t          |           }d|z  |z  }|}t          d| |z  |z
            }|||fS )z3Calculate searchRange, entrySelector, rangeShift.
	rp   r   )r  r  )nitemSizer  searchRangeentrySelector
rangeShifts         r:   getSearchRanger  #  sI    
 !X)!Q\K/00]J..r<   r>   r#  )r  )0r   r   fontTools.misc.py23r   r   r   fontTools.misc.loggingToolsr   fontTools.ttLibr   fontTools.ttLib.sfntr	   r
   ior   r   r~   loggingrE   	getLoggerr$  r   objectr   r  r;  r  r  rY   rd  rg  rj  rm  rr  r   rw  ry  r  r   ru  r   r  r  r  r   rO   r  r  r?   r<   r:   <module>r     s    $ $ $ $ $ $ 3 3 3 3 3 3 3 3 3 3 9 9 9 9 9 9 & & & & & & 7 7 7 7 7 7 7 7                 				     g!!j
C j
C j
C j
C j
CV j
C j
C j
CZ( ( ( ( (& ( ( (T# # # # #v # # #J    (   + + + + +8 + + +*) ) ) ) ) ) ) )6     0  5 5 5 5  
	# 	# 	#          8  *  ") ) ), , ,     0     	/ 	/ 	/ 	/ 	/ 	/r<   