
    h                     |   S SK Jr  S SKJr  S SKJr  S SKJr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  S SKJrJr  S S	KJrJrJr  S S
KrS S
KrS S
Kr\R:                  " \5      r " S S\ 5      r! " S S\ 5      r"S r#0 r$S!S jr%S r&S r'S r(S r)S r*S r+S r,S r-S r.S r// SQr0/ SQr1S!S jr2S"S jr3S r4S#S  jr5g
)$    )Config)	xmlWriter)AbstractConfig)Tagbyteordtostr)deprecateArgument)
TTLibError)_TTGlyph_TTGlyphSetCFF_TTGlyphSetGlyf_TTGlyphSetVARC)
SFNTReader
SFNTWriter)BytesIOStringIOUnsupportedOperationNc                   p   \ rS rSrSrSSSSSSS\SSSSSS0 4S	 jrS
 rS rS r	S0S jr
S1S jrS2S jr        S3S jrS4S jrS1S jrS rS r\rS rS1S jrS rS rS rS rS rS1S jrS rS rS r\S  5       rS! r S" r!S# r"S$ r#S% r$S& r%S5S' jr&S( r'S1S) jr(S* r) S6S+ jr*S, r+ S7S- jr,S. r-S/r.g)8TTFont   aS  Represents a TrueType font.

The object 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.

Example usage:

.. code-block:: pycon

    >>>
    >> from fontTools import ttLib
    >> tt = ttLib.TTFont("afont.ttf") # Load an existing font file
    >> tt['maxp'].numGlyphs
    242
    >> tt['OS/2'].achVendID
    'B&H '
    >> tt['head'].unitsPerEm
    2048

For details of the objects returned when accessing each table, see the
:doc:`tables </ttLib/tables>` documentation.
To add a table to the font, use the :py:func:`newTable` function:

.. code-block:: pycon

    >>>
    >> os2 = newTable("OS/2")
    >> os2.version = 4
    >> # set other attributes
    >> font["OS/2"] = os2

TrueType fonts can also be serialized to and from XML format (see also the
:doc:`ttx </ttx>` binary):

.. code-block:: pycon

    >>
    >> tt.saveXML("afont.ttx")
    Dumping 'LTSH' table...
    Dumping 'OS/2' table...
    [...]

    >> tt2 = ttLib.TTFont() # Create a new font object
    >> tt2.importXML("afont.ttx")
    >> tt2['maxp'].numGlyphs
    242

The TTFont object may be used as a context manager; this will cause the file
reader to be closed after the context ``with`` block is exited::

        with TTFont(filename) as f:
                # Do stuff

Args:
        file: When reading a font from disk, either a pathname pointing to a file,
                or a readable file object.
        res_name_or_index: If running on a Macintosh, either a sfnt resource name or
                an sfnt resource index number. If the index number is zero, TTLib will
                autodetect whether the file is a flat file or a suitcase. (If it is a suitcase,
                only the first 'sfnt' resource will be read.)
        sfntVersion (str): When constructing a font object from scratch, sets the four-byte
                sfnt magic number to be used. Defaults to ``   `` (TrueType). To create
                an OpenType file, use ``OTTO``.
        flavor (str): Set this to ``woff`` when creating a WOFF file or ``woff2`` for a WOFF2
                file.
        checkChecksums (int): How checksum data should be treated. Default is 0
                (no checking). Set to 1 to check and warn on wrong checksums; set to 2 to
                raise an exception if any wrong checksums are found.
        recalcBBoxes (bool): If true (the default), recalculates ``glyf``, ``CFF ``,
                ``head`` bounding box values and ``hhea``/``vhea`` min/max values on save.
                Also compiles the glyphs on importing, which saves memory consumption and
                time.
        ignoreDecompileErrors (bool): If true, exceptions raised during table decompilation
                will be ignored, and the binary data will be returned for those tables instead.
        recalcTimestamp (bool): If true (the default), sets the ``modified`` timestamp in
                the ``head`` table on save.
        fontNumber (int): The index of the font in a TrueType Collection file.
        lazy (bool): 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.
Nz   r   TFc                    S H8  n[        5       R                  U5      nUb  [        US5        [        U UU5        M:     Xl        Xpl        Xl        0 U l        S U l        [        U[        5      (       a  UR                  5       O
[        U5      U l        Xl        U(       d  X0l        X@l        S U l        g Sn[%        US5      (       df  SnUbT  SSKJn  US:X  a6  UR+                  U5      (       a  UR-                  US5      nOs[/        US5      nOfUR-                  X5      nOT[/        US5      nOGS	n[%        US
5      (       a  UR1                  5       nO#[%        US5      (       a   UR3                  S5        U R                  (       dm  U(       a  UR3                  S5        [7        UR9                  5       5      n[%        US5      (       a  UR:                  Ul        U(       a  UR=                  5         UnOU(       d  [?        S5      eXl         [C        XUS9U l        U R                  R                  U l        U R                  R                   U l        U R                  R"                  U l        g ! [4         a    S	n GNf = f)N)verbosequietconfigure logging insteadTread   )macUtilsr   rbFseekableseeknamez*Input file must be seekable when lazy=True)
fontNumber)"localsgetr	   setattrlazyrecalcBBoxesrecalcTimestamptablesreader
isinstancer   copyr   cfgignoreDecompileErrorssfntVersionflavor
flavorDatahasattr r   getSFNTResIndicesSFNTResourceReaderopenr    r!   r   r   r   r"   closer
   _tableCacher   )selffileres_name_or_indexr0   r1   checkChecksumsr   r(   allowVIDr/   r)   r#   r'   r   r9   r.   r"   valr    closeStreamr   tmps                         H/var/www/html/env/lib/python3.13/site-packages/fontTools/ttLib/ttFont.py__init__TTFont.__init__j   s   $ )D(,,t$C!$(CDD$$	 ) 	(.!+C!@!@388:fSk%:"* K"DOtV$$K ,&$)11$77'::4C#D$/#66tODD$'  K tZ((==?v&&%IIaL yy		!$))+&CtV$$99

DIJJ& *M;;22kk((++00) , %$H%s   $I, ,I<;I<c                     U $ N r:   s    rB   	__enter__TTFont.__enter__   s        c                 $    U R                  5         g rF   )r8   )r:   typevalue	tracebacks       rB   __exit__TTFont.__exit__   s    

rK   c                 T    U R                   b  U R                   R                  5         gg)z+If we still have a reader object, close it.N)r+   r8   rH   s    rB   r8   TTFont.close   s!    ;;"KK #rK   c                    [        US5      (       dC  U R                  (       a/  U R                  R                  R                  U:X  a  [        S5      eSnOSn[        5       nU R                  U5      nUb|  U(       du  USL a  U R                  bc  USL a$  [        U R                  R                  5       5      nOSnUR                  5         [        5       n[        XGU5        UR                  5         UnU(       a5  [        US5       nUR                  UR                  5       5        SSS5        OUR                  UR                  5       5        UR                  5         g! , (       d  f       N= f)a  Save the font to disk.

Args:
        file: Similarly to the constructor, can be either a pathname or a writable
                file object.
        reorderTables (Option[bool]): If true (the default), reorder the tables,
                sorting them by tag (recommended by the OpenType specification). If
                false, retain the original font order. If None, reorder by table
                dependency (fastest).
writez4Can't overwrite TTFont when 'lazy' attribute is TrueTFNwb)r3   r'   r+   r;   r"   r
   r   _savelistkeysflushreorderFontTablesr8   r7   rU   getvalue)r:   r;   reorderTablescreateStreamrA   writer_reordersTables
tableOrdertmp2s           rB   saveTTFont.save   s    tW%%yyT[[--22d: !WXXL !Li $

3 !$&4;;+>%!$++"2"2"45
 "
IIK9Dc4IIKCdD!T

3<<>* "! JJs||~&		 "!s    E
E+c                    U R                   (       a  SU ;   a  U S     [        U R                  5       5      nSU;   a  UR                  S5        [	        U5      n[        XU R                  U R                  U R                  5      n/ nU H  nU R                  XuXb5        M     UR                  5         UR                  5       $ )zAInternal function, to be shared by save() and TTCollection.save()head
GlyphOrder)r)   rX   rY   removelenr   r0   r1   r2   _writeTabler8   reordersTables)r:   r;   
tableCachetags	numTableswriterdonetags           rB   rW   TTFont._save   s     FdN DIIK 4KK%I	T--t{{DOO
 CS$;  	$$&&rK   c                 r    [         R                  " XS9nU R                  " U40 UD6  UR                  5         g)az  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_saveXMLr8   )r:   
fileOrPathrt   kwargsrn   s        rB   saveXMLTTFont.saveXML  s.     $$ZGf''rK   c
                 @   Ub  [        SS5        Xl        Xl        U(       dM  [        U R	                  5       5      nSU;  a  S/U-   nU(       a!  U H  n
X;   d  M
  UR                  U
5        M     [        U5      nU(       aZ  SSKJn  SR                  UR                  S5      S S 5      nUR                  S[        [        U R                  5      5      S	S
 US9  O/UR                  S[        [        U R                  5      5      S	S
 S9  UR                  5         U=(       d    UnU(       d  UR                  5         O+[         R"                  R%                  UR&                  5      u  p[)        U5       GH  nXO   n
U(       a  WS-   [+        U
5      -   W-   n[,        R.                  " UUR0                  S9nUR                  SWS9  UR                  5         UR                  5         UR3                  [5        U
5      [         R"                  R7                  U5      S9  UR                  5         OUnU R9                  UXS9  U(       d  M  UR;                  S5        UR                  5         UR=                  5         GM     UR;                  S5        UR                  5         g )Nr   r   rf   r   )version.   ttFontr   r   )r0   ttLibVersion)r0   rs   )r   )srcsplitGlyphs)r	   disassembleInstructionsbitmapGlyphDataFormatrX   rY   rg   rh   	fontToolsr|   joinsplitbegintagreprr   r0   newlineospathsplitextfilenamerangetagToIdentifierr   ru   rt   	simpletagtagToXMLbasename_tableToXMLendtagr8   )r:   rn   writeVersionr   r*   
skipTablessplitTablesr   r   r   rp   rm   r|   r   exti	tablePathtableWriters                     rB   rv   TTFont._saveXML$  s2    g'BC'>$%:"$))+&F6)&&0%C}c* & K	)hhw}}S1"156GOO t'7'7!89!B?$   OOH$uT=M=M7N2OPQRT2UOV "0[NN((9IDy!A)C 3J)==C	'11&*;*; $$XG$D##%##%  #BGG4D4DY4O P $[#G{""8,##%!!#% "& 	hrK   c                    Ub  [        SS5        X ;   a
  X   nSU-  nOSU-  n[        R                  U5        X ;  a  g [        U5      n[	        5       n[        WS5      (       a  SUS'   SSKJn	  UR                  U	:X  a  S	US
'   UR                  " U40 UD6  UR                  5         US:X  a  UR                  XUS9  OUR                  X5        UR                  U5        UR                  5         UR                  5         g )Nr   r   zDumping '%s' table...zNo '%s' table found.ERRORzdecompilation errorr   DefaultTableTrawglyfr   )r	   loginfor   dictr3   tables.DefaultTabler   	__class__r   r   toXMLr   )
r:   rn   rp   r   r   tablereportxmlTagattrsr   s
             rB   r   TTFont._tableToXMLj  s    g'BC;IE,s2F+c1F?#5'""2E'N5??l*E%L(%(&=KK+K>KK%frK   c                     Ub  [        SS5        SU ;   a  SU ;   a  U R                  5         SSKJn  UR	                  X5      nUR                  5         g)zOImport 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   )r:   rw   r   r   r+   s        rB   	importXMLTTFont.importXML  sL     g'BCT>fn
  ,$$Z6rK   c                     XR                   ;   $ )zZReturn true if the table identified by ``tag`` has been
decompiled and loaded into memory.r*   r:   rp   s     rB   isLoadedTTFont.isLoaded  s     kk!!rK   c                     U R                  U5      (       a  gU R                  (       a  XR                  ;   a  gUS:X  a  gg)zTest if the table identified by ``tag`` is present in the font.

As well as this method, ``tag in font`` can also be used to determine the
presence of the table.Trf   F)r   r+   r   s     rB   has_keyTTFont.has_key  s7    
 ==[[SKK/L rK   c                 >   [        U R                  R                  5       5      nU R                  (       aB  [        U R                  R                  5       5       H  nX!;  d  M
  UR	                  U5        M     SU;   a  UR                  S5        [        U5      nS/U-   $ )zSReturns the list of tables in the font, along with the ``GlyphOrder`` pseudo-table.rf   )rX   r*   rY   r+   appendrg   sortedTagList)r:   rY   keys      rB   rY   TTFont.keys  sz    DKK$$&';;DKK,,./?KK$ 0 4KK%T"~$$rK   c                     U R                  5        HC  nX   nUc  U R                  SLnU(       d  M!  [        US5      (       d  M4  UR                  US9  ME     SU l        g)zEDecompile all the tables, even if a TTFont was opened in 'lazy' mode.NFensureDecompiled)recurse)rY   r'   r3   r   )r:   r   rp   r   s       rB   r   TTFont.ensureDecompiled  sX    99;CIE))50w75*<==&&w&7  	rK   c                 F    [        [        U R                  5       5      5      $ rF   )rh   rX   rY   rH   s    rB   __len__TTFont.__len__  s    4		$%%rK   c                     [        U5      nU R                  R                  U5      nUcO  US:X  a  [        U5      nX R                  U'   U$ U R                  b  U R                  U5      nU$ [        SU-  5      eU$ )Nrf   '%s' table not found)r   r*   r%   rf   r+   
_readTableKeyErrorr:   rp   r   s      rB   __getitem__TTFont.__getitem__  s    #h$=l""3#(C 
 	 (,  5;<<rK   c                    [         R                  SU5        U R                  U   nU R                  b!  U R                  R	                  X45      nUb  U$ [        U5      nU" U5      nX0R                  U'   [         R                  SU5         UR                  X 5        U R                  b  X0R                  X4'   U$ ! [         a    U R                  (       d  e [         R                  SU5        SSKJn  [        5       n[        R                  " US9  U" U5      nUR!                  5       Ul        X0R                  U'   UR                  X 5         Nf = f)NReading '%s' table from diskzDecompiling '%s' tablez@An exception occurred during the decompilation of the '%s' tabler   r   )r;   )r   debugr+   r9   r%   getTableClassr*   	decompile	Exceptionr/   	exceptionr   r   r   rO   	print_excr\   r   )r:   rp   datar   
tableClassr   r;   s          rB   r   TTFont._readTable  s(   		0#6{{3'$$((#5E "3'
3 C		*C0	(OOD'  ',1c[)#  	(--MMRTW ::DT* %E--/EK$KKOOD'	(s   B; ;BEEc                 2    X R                   [        U5      '   g rF   )r*   r   r   s      rB   __setitem__TTFont.__setitem__  s     %CHrK   c                     X;  a  [        SU-  5      eXR                  ;   a  U R                  U	 U R                  (       a  XR                  ;   a  U R                  U	 g g g )Nr   )r   r*   r+   r   s     rB   __delitem__TTFont.__delitem__  sQ    ?1C788++C ;;3++-C  .;rK   c                 0     X   $ ! [          a    Us $ f = f)zGReturns the table if it exists or (optionally) a default if it doesn't.)r   )r:   rp   defaults      rB   r%   
TTFont.get  s#    	9 	N	s    c                     Xl         [        U S5      (       a  U ?U R                  S5      (       a  U S   R	                  U5        gg)zUSet the glyph order

Args:
        glyphOrder ([str]): List of glyph names in order.
_reverseGlyphOrderDictr   N)
glyphOrderr3   r   r   setGlyphOrder)r:   r   s     rB   r   TTFont.setGlyphOrder  sC     %4122+==  L&&z2 !rK   c                     U R                   $ ! [         a     Of = fSU ;   a&  U S   nUR                  5       U l         U R                   $ SU ;   a  U S   R                  5       nUc  U R                  5         U R                   $ [	        U5      U S   R
                  :  a1  [        R                  S5        U R                  5         U R                   $ X l          U R                   $ U R                  5         U R                   $ )zDReturns a list of glyph names ordered by their position in the font.CFF r   r   zMNot enough names found in the 'post' table, generating them from cmap instead)r   AttributeErrorr   _getGlyphNamesFromCmaprh   	numGlyphsr   warning)r:   cffr   s      rB   r   TTFont.getGlyphOrder  s    	??" 		T>v,C!//1DO2 1 t^f335J! ++-  Z4<#9#99 c ++-
  #-  '')s    
c                 N   U R                  S5      (       a  U R                  S   nU R                  S	 OS n[        U S   R                  5      n[	        U5       Vs/ s H  nSU-  PM
     nnSUS'   X@l        SU ;   a  U S   R                  5       nO0 n0 n[	        U5       HM  nXC   nXu;   d  M  U R                  XW   5      nUR                  US5      S-   =oU'   U	S:  a	  SXS-
  4-  nXU'   MO     SU ;   a*  U R                  S	 X@l        U(       a  XR                  S'   g g g s  snf )Ncmapr   	glyph%.5dz.notdefr   r   z%s.alt%d)	r   r*   intr   r   r   buildReversedMin_makeGlyphNamer%   )
r:   cmapLoadingr   r   r   reversecmapuseCounttempName	glyphNamenumUsess
             rB   r   TTFont._getGlyphNamesFromCmap7  sH    ==   ++f-KF#K V../	/4Y/?@/?!kAo/?
@!
1 % T>v,779KKy!A!}H& !//0EF	08Y0JQ0NN9-Q; *i1-E EI )1 " T> F#(O '2F#  7 As   D"c                 j    SSK Jn  XR                  ;   a  UR                  U    $ U S::  a  SU -  $ SU -  $ )Nr   )agli  zuni%04Xzu%X)r   r  UV2AGL)	codepointr  s     rB   r   TTFont._makeGlyphNamey  s<    !

"::i((& y((9$$rK   c                 8    [        U R                  5       5      nU$ )z1Get a list of glyph names, sorted alphabetically.)sortedr   )r:   
glyphNamess     rB   getGlyphNamesTTFont.getGlyphNames  s    D..01
rK   c                 L    SSK Jn  UR                  U R                  5       5      $ )zJGet a list of glyph names, sorted alphabetically,
but not case sensitive.
r   )	textTools)r   r  caselessSortr   )r:   r  s     rB   getGlyphNames2TTFont.getGlyphNames2  s!     	-%%d&8&8&:;;rK   c                 T     U R                  5       U   $ ! [         a    SU-  s $ f = f)zReturns the name for the glyph with the given ID.

If no name is available, synthesises one with the form ``glyphXXXXX``` where
```XXXXX`` is the zero-padded glyph ID.
r   )r   
IndexError)r:   glyphIDs     rB   getGlyphNameTTFont.getGlyphName  s5    	)%%'00 	)((	)s    ''c                     U R                  5       n[        U5      nU Vs/ s H  oDU:  a  X$   OSU-  PM     sn$ s  snf )z8Converts a list of glyph IDs into a list of glyph names.r   )r   rh   )r:   lstr   cntgids        rB   getGlyphNameManyTTFont.getGlyphNameMany  sA    '')
*oORSs9
+2CCsSSSs   ;c                      U R                  5       U   $ ! [         a;    USS S:X  a0   [        USS 5      s $ ! [        [        4 a    [        U5      ef = fe f = f)z0Returns the ID of the glyph with the given name.N   glyph)getReverseGlyphMapr   r   	NameError
ValueError)r:   r   s     rB   
getGlyphIDTTFont.getGlyphID  sp    	**,Y77 	!}'.y}--!:. ."9--.	s    A9AAAc                     U R                  5       n U Vs/ s H  o2U   PM	     sn$ s  snf ! [         a-    U R                  nU Vs/ s H
  o4" U5      PM     Os  snf sns $ f = f)z8Converts a list of glyph names into a list of glyph IDs.)r  r   r"  )r:   r  dr   r"  s        rB   getGlyphIDManyTTFont.getGlyphIDMany  sd    ##%	@256#YiL#666 	@J;>?3iJy)3??	@s'   , ', , A#A	A#"A#c                 j    U(       d  [        U S5      (       d  U R                  5         U R                  $ )z.Returns a mapping of glyph names to glyph IDs.r   )r3   _buildReverseGlyphOrderDictr   )r:   rebuilds     rB   r  TTFont.getReverseGlyphMap  s*    '$(@AA,,.***rK   c                 d    0 =U l         n[        U R                  5       5       H	  u  p#X!U'   M     U$ rF   )r   	enumerater   )r:   r%  r  r   s       rB   r)  "TTFont._buildReverseGlyphOrderDict  s7    *,,#a"+D,>,>,@"AG"iL #BrK   c                    X;   a  g[        U5      nUR                   H4  nXc;  d  M
  X`;   a  U R                  XbX45        M#  UR                  U5        M6     UR                  U5        U R	                  U5      nUbG  UR                  [        U5      U45      nUb(  [        R                  SU5        UR                  X5        g[        R                  SU5        XrU'   Ub  X!   U[        U5      U4'   gg)zSInternal helper function for self.save(). Keeps track of
inter-table dependencies.
Nzreusing '%s' tablezWriting '%s' table to disk)
r   dependenciesri   r   getTableDatar%   r   r   r   setEntry)	r:   rp   rn   ro   rk   r   masterTable	tabledataentrys	            rB   ri   TTFont._writeTable  s     ;"3'
%22K&&$$[$KKK, 3 	C%%c*	!NNCHi#89E 		.4+		.4s!06JC),- "rK   c                 L   [        U5      nU R                  U5      (       a4  [        R                  SU5        U R                  U   R                  U 5      $ U R                  (       a4  XR                  ;   a%  [        R                  SU5        U R                  U   $ [        U5      e)zReturns the binary representation of a table.

If the table is currently loaded and in memory, the data is compiled to
binary and returned; if it is not currently loaded, the binary data is
read from the font file and returned.
zCompiling '%s' tabler   )r   r   r   r   r*   compiler+   r   r   s     rB   r1  TTFont.getTableData  s}     #h==II,c2;;s#++D11[[SKK/II4c:;;s##3-rK   c                    U(       a  SU ;  a  SnU(       a  U(       d  U R                  U5      nSnSU ;   d  SU ;   a  U(       d  SU ;  a  [        X5      nOSU ;   a  [        XUS9nO[        S5      eSU ;   a  [	        XU5      nU$ )	a  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.

If the ``location`` parameter is set, it should be a dictionary mapping
four-letter variation tags to their float values, and the returned
glyph-set will represent an instance of a variable font at that
location.

If the ``normalized`` variable is set to True, that location is
interpreted as in the normalized (-1..+1) space, otherwise it is in the
font's defined axes space.
fvarNr   CFF2r   )recalcBoundszFont contains no outlinesVARC)normalizeLocationr   r   r
   r   )r:   	preferCFFlocation
normalizedr=  glyphSets         rB   getGlyphSetTTFont.getGlyphSet  s    4 d*HJ--h7HdNfn9d@R%d5Ht^&tLQH899T>&tx@HrK   c                     SSK Jn  SU ;  a  [        S5      eU S   R                  5       nU" X5      nSU ;   a  U S   R	                  X5      nU$ )ag  Normalize a ``location`` from the font's defined axes space (also
known as user space) into the normalized (-1..+1) space. It applies
``avar`` mapping if the font contains an ``avar`` table.

The ``location`` parameter should be a dictionary mapping four-letter
variation tags to their float values.

Raises ``TTLibError`` if the font is not a variable font.
r   )r?  r;  zNot a variable fontavar)fontTools.varLib.modelsr?  r
   getAxesrenormalizeLocation)r:   rA  r?  axess       rB   r?  TTFont.normalizeLocation  sW     	>233F|##%$X4T>F|77GHrK   c                 &    U S   R                  US9$ )a  Returns 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 in order::

                (3, 10), # Windows Unicode full repertoire
                (0, 6),  # Unicode full repertoire (format 13 subtable)
                (0, 4),  # Unicode 2.0 full repertoire
                (3, 1),  # Windows Unicode BMP
                (0, 3),  # Unicode 2.0 BMP
                (0, 2),  # Unicode ISO/IEC 10646
                (0, 1),  # Unicode 1.1
                (0, 0)   # Unicode 1.0

This particular order matches what HarfBuzz uses to choose what
subtable to use by default. This order prefers the largest-repertoire
subtable, and among those, prefers the Windows-platform over the
Unicode-platform as the former has wider support.

This order can be customized via the ``cmapPreferences`` argument.
r   )cmapPreferences)getBestCmap)r:   rN  s     rB   rO  TTFont.getBestCmap,  s    F F|'''HHrK   c                      SSK J n  U" X5        g )Nr   reorderGlyphsrR  )r:   new_glyph_orderrS  s      rB   rS  TTFont.reorderGlyphsQ  s    0d,rK   )r   r9   r   r.   r   r1   r2   r   r/   r'   r+   r(   r)   r0   r*   )TrF   )
)TNNNFFTr   NF)F)TNFT)))   
   )r      )r      )rX  r   )r   rX  )r   r~   )r   r   )r   r   )/__name__
__module____qualname____firstlineno____doc__NotImplementedrC   rI   rP   r8   rb   rW   ry   rv   r   r   r   r   __contains__rY   r   r   r   r   r   r   r%   r   r   r   staticmethodr   r
  r  r  r  r"  r&  r  r)  ri   r1  rD  r?  rO  rS  __static_attributes__rG   rK   rB   r   r      s@   Qj &#!V1p 
/b'2   $#DL:&"
 L%&@&!
3!F@2D % %
<	)T
@+<4 $ MQ'R.	
#IJ-rK   r   c                   .    \ rS rSrSrSS jrS rS rSrg)	rf   iW  z~A 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                     g rF   rG   r   s     rB   rC   GlyphOrder.__init__\  s    rK   c                     UR                  5       nUR                  S5        UR                  5         [        [	        U5      5       H'  nX4   nUR                  SXES9  UR                  5         M)     g )NzAThe 'id' attribute is only for humans; it is ignored when parsed.GlyphID)idr"   )r   commentr   r   rh   r   )r:   rn   r   r   r   r   s         rB   r   GlyphOrder.toXML_  sb    ))+
R	
 	s:'A"IY1=NN (rK   c                     [        U S5      (       d  / U l        US:X  a  U R                  R                  US   5        UR                  U R                  5        g )Nr   ri  r"   )r3   r   r   r   )r:   r"   r   contentr   s        rB   fromXMLGlyphOrder.fromXMLj  sF    t\** DO9OO""5=1T__-rK   )r   rF   )	r\  r]  r^  r_  r`  rC   r   ro  rd  rG   rK   rB   rf   rf   W  s    	.rK   rf   c                     SSK Jn  [        U 5      n [        SU-   5        [	        X5      $ ! [
         a*  n[        U5      R                  U5      S:  a   SnAgUeSnAff = f)zSFetch the packer/unpacker module for a table.
Return None when no module is found.
r   r   zfontTools.ttLib.tables.r   N)r4   r*   r   
__import__getattrImportErrorstrfind)rp   r*   pyTagerrs       rB   getTableModulery  r  sb     C E&,u45 v%%  
 s8==1$Is   , 
A AAA c                 :    Uc  S[        U 5      -   nX4[        U '   g)aJ  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
:py:class:`fontTools.ttLib.tables.DefaultTable.DefaultTable`
Ntable_)r   _customTableRegistry)rp   
moduleName	classNames      rB   registerCustomTableClassr    s'     s33	!+ 7rK   c                     [         U 	 g)z8Unregister the custom packer/unpacker class for a table.N)r|  rp   s    rB   unregisterCustomTableClassr    s
    S!rK   c                 n    U [         ;  a  gSSKn[         U    u  p#UR                  U5      n[        XC5      $ )zwReturn the custom table class for tag, if one has been registered
with 'registerCustomTableClass()'. Else return None.
Nr   )r|  	importlibimport_modulers  )rp   r  r}  r~  modules        rB   getCustomTableClassr    s;     &&05J$$Z0F6%%rK   c                     [        U 5      nUb  U$ [        U 5      nUc  SSKJn  U$ [	        U 5      n[        USU-   5      nU$ )z,Fetch the packer/unpacker class for a table.r   r   r{  )r  ry  r   r   r   rs  )rp   r   r  r   rw  s        rB   r   r     sQ    $S)JC F~5C EE!12JrK   c                 P    U R                   nUSS S:X  d   eUSS n[        U5      $ )z'Fetch the table tag for a class object.NrZ  r{  )r\  identifierToTag)klassr"   s     rB   getClassTagr    s5    >>D8x8D4  rK   c                 (    [        U 5      nU" U 5      $ )z!Return a new instance of a table.)r   )rp   r   s     rB   newTabler    s    s#Jc?rK   c                     SSK nUR                  SU 5      (       a  SU -   $ UR                  SU 5      (       a  U S-   $ [        [        U 5      5      SS $ )z%Helper function for tagToIdentifier()r   Nz[a-z0-9]_z[A-Z]r~   )rematchhexr   )cr  s     rB   _escapecharr    sN    	xx
AQw	'1		3w71:qr""rK   c                 8   SSK n[        U 5      n U S:X  a  U $ [        U 5      S:X  d   S5       e[        U 5      S:  a(  U S   S:X  a  U SS n [        U 5      S:  a  U S   S:X  a  M  S	nU  H  nU[        U5      -   nM     UR	                  S
U5      (       a  SU-   nU$ )a  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:
.. code-block:: pycon

    >>>
    >> tagToIdentifier('glyf')
    '_g_l_y_f'
    >> tagToIdentifier('cvt ')
    '_c_v_t'
    >> tagToIdentifier('OS/2')
    'O_S_2f_2'
r   Nrf   r[  ztag should be 4 characters longr   r    r4   z[0-9]r  )r  r   rh   r  r  )rp   r  identr  s       rB   r   r     s    & 
c(C
l
s8q=;;;=
c(Q,3r7c>#2h c(Q,3r7c>EA& 	xxeLrK   c           
         U S:X  a  U $ [        U 5      S-  (       a  U S   S:X  a  U SS n [        U 5      S-  (       a   eSn[        S[        U 5      S5       HH  nX   S:X  a  XUS-      -   nM  XS-      S:X  a	  XU   -   nM+  U[        [        XUS-    S5      5      -   nMJ     US	[        U5      -
  S
-  -   n[	        U5      $ )z!the opposite of tagToIdentifier()rf   r~   r   r  r   Nr4      r[  r  )rh   r   chrr   r   )r  rp   r   s      rB   r  r    s    
5zA~%(c/ab	E
Q
C1c%j!$8s?a!e$Cq5\S a.C C!a% 0"566C % SX$
$Cs8OrK   c                     SSK n[        U 5      n U S:X  a  gU S:X  a  U $ UR                  SU 5      (       a  U R                  5       $ [	        U 5      $ )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_2rf   z[A-Za-z_][A-Za-z_0-9]* *$)r  r   r  stripr   )rp   r  s     rB   r   r     sP    
 
c(C
f}		
	xx+S11yy{s##rK   c                     U S:X  a  [        S5      $ [        U 5      S:X  a  [        U 5      $ [        U SS[        U 5      -
  -  -   5      $ )zThe opposite of tagToXML()r  r     r  r[  )r   rh   r  r  s    rB   xmlToTagr  "  sF    
f}6{
3x1}s##3CH--..rK   )re   hhear   r  hmtxLTSHVDMXhdmxr   fpgmprepzcvt locar   kernr"   r   gaspPCLT)re   r  r   r  r"   r   r   r   c                 "   [        U 5      n Uc;  SU ;   a"  U R                  S5        U R                  S5        SU ;   a  [        nO[        n/ nU H,  nX0;   d  M
  UR                  U5        U R                  U5        M.     UR                  U 5        U$ )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.
DSIGr   )r  rg   r   OTFTableOrderTTFTableOrderextend)tagListr`   orderedTablesrp   s       rB   r   r   F  s    
 WoGWNN6"NN6"W&J&JM>  %NN3  !rK   c                 \   U R                  S5        UR                  S5        [        XS9n[        U[        UR                  5      UR
                  UR                  UR                  5      n[        UR                  5       5      n[        Xb5       H	  nXG   XW'   M     UR                  5         g)z[Rewrite a font file, ordering the tables as recommended by the
OpenType specification 1.4.
r   )r=   N)r!   r   r   rh   r*   r0   r1   r2   rX   rY   r   r8   )inFileoutFiler`   r=   r+   rn   r*   rp   s           rB   r[   r[   ^  s     KKNLLO>FFMMF &++- FV0k 1
LLNrK   c                 X    SnU (       a  U S-	  n US-   nU (       a  M  [        US-
  S5      $ )zWReturn the highest exponent of two, so that
(2 ** exponent) <= x.  Return 0 if x is 0.
r   r   )max)xexponents     rB   maxPowerOfTwor  r  s8     H
Fa< ! x!|QrK   c                 V    [        U 5      nSU-  U-  nUn[        SX-  U-
  5      nX4U4$ )z1Calculate searchRange, entrySelector, rangeShift.r~   r   )r  r  )nitemSizer  searchRangeentrySelector
rangeShifts         rB   getSearchRanger  }  s?     QHh;(*KMQ{23Jz11rK   rF   rW  )r  )6fontTools.configr   r   r   fontTools.misc.configToolsr   fontTools.misc.textToolsr   r   r   fontTools.misc.loggingToolsr	   fontTools.ttLibr
   fontTools.ttLib.ttGlyphSetr   r   r   r   fontTools.ttLib.sfntr   r   ior   r   r   r   loggingrO   	getLoggerr\  r   objectr   rf   ry  r|  r  r  r  r   r  r  r  r   r  r   r  r  r  r   r[   r  r  rG   rK   rB   <module>r     s    # $ 5 8 8 9 &  8 6 6 	  !~-V ~-B. .6&2  8"

&!	# F*$$/, Q0( 2rK   