L iݞtddlmZddlmZddlmZddlmZmZm Z ddl m Z ddl m Z ddlmZmZmZmZddlmZmZdd lmZmZmZdd lZdd lZdd lZej:eZGd d e Z!Gd de Z"dZ#iZ$d!dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/gdZ0gdZ1d!dZ2d"dZ3dZ4d#d Z5y )$)Config) xmlWriter)AbstractConfig)Tagbyteordtostr)deprecateArgument) TTLibError)_TTGlyph_TTGlyphSetCFF_TTGlyphSetGlyf_TTGlyphSetVARC) SFNTReader SFNTWriter)BytesIOStringIOUnsupportedOperationNcNeZdZdZdddddddeddddddifdZd Zd Zd Zd.d Z d/d Z d0dZ d1dZ d2dZ d/dZdZdZeZdZd/dZdZdZdZdZdZd/dZdZdZdZedZd Zd!Z d"Z!d#Z"d$Z#d%Z$d3d&Z%d'Z&d/d(Z'd)Z( d4d*Z)d+Z* d5d,Z+d-Z,y)6TTFonta_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 ` 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 ` 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. NzrTFcdD]6}tj|}| t|dt|||8| |_||_| |_i|_d|_t|tr|jn t||_ | |_|s||_||_d|_yd}t%|ds`d}|Oddlm}|dk(r1|j+|r|j-|d}njt/|d}n]|j-||}nJt/|d}n=d }t%|d r|j1}nt%|d r |j3d|js^|r|j3dt7|j9}t%|d r|j:|_|r|j=|}n |s t?d ||_ tC||| |_|jj|_|jj |_|jj"|_y#t4$rd }YwxYw)N)verbosequietconfigure logging insteadTread)macUtilsrrbFseekableseeknamez*Input file must be seekable when lazy=True) fontNumber)"localsgetr setattrlazy recalcBBoxesrecalcTimestamptablesreader isinstancercopyrcfgignoreDecompileErrors sfntVersionflavor flavorDatahasattrrgetSFNTResIndicesSFNTResourceReaderopenrr rrrr!closer _tableCacher)selffileres_name_or_indexr/r0checkChecksumsrr'allowVIDr.r(r"r&rr8r-r!valr closeStreamrtmps \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fontTools/ttLib/ttFont.py__init__zTTFont.__init__js $) %D(,,t$C!$(CD D$ $  %  (.  !+C!@388:fSk%:"*D  DK"DO tV$K ,&$)11$7'::4C#D$/#66t=NODD$' KtZ(==?v&%IIaLyy ! $))+&CtV$99 DIJ J& ~*M ;;22kk(( ++00),%$H%sH<< I  I c|SNr9s rA __enter__zTTFont.__enter__s c$|jyrD)r7)r9typevalue tracebacks rA__exit__zTTFont.__exit__s  rHcR|j|jjyy)z+If we still have a reader object, close it.N)r*r7rFs rAr7z TTFont.closes! ;; " KK    #rHct|ds=|jr.|jjj|k(r t dd}nd}t }|j|}|u|ss|dur |jc|dur$t|jj}nd}|jt }t||||j|}|r5t|d5}|j|jdddn|j|j|jy#1swYxYw)aSave 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 TrueTFNwb)r2r&r*r:r!r r_savelistkeysflushreorderFontTablesr7r6rPgetvalue)r9r: reorderTables createStreamr@writer_reordersTables tableOrdertmp2s rAsavez TTFont.savestW%yyT[[--22d: !WXXL!Li $ 3  !$&4;;+>%!$++"2"2"45 " IIK9D c4 4 IIKC dD! +T 3<<>* + + JJs||~ &  + +s , EEcX|jr d|vr|d|j}|jdt|}t |||j |j |j}g}|D]}|j|||||j|jS)zAInternal function, to be shared by save() and TTCollection.save()headr) r(rTpoplenrr/r0r1 _writeTabler7reordersTables)r9r: tableCachetags numTableswriterdonetags rArRz TTFont._saves   FdN  yy{  I  )T--t{{DOO  $%:"YY[F)/I#3j3H#II  )hhw}}S1"156G OO t'7'7!89!B?$   OOH$uT=M=M7N2OPQRT2UO V"0[  NN ((9ID# $C 3J)==C '11&*;*; $$XG$D##%##%  #BGG4D4DY4O P $   [#;  G""8,##%!!## $$  hUJs IIc| tdd||vr ||}d|z}nd|z}tj|||vryt|}t }t drd|d<ddlm} |j| k(rd |d <|j|fi||j|d k(r|j||| n|j|||j||j|jy) NrrzDumping '%s' table...zNo '%s' table found.ERRORzdecompilation errorr DefaultTableTrawglyfry) r loginfordictr2tables.DefaultTabler __class__rrtoXMLr) r9rgrirrztablereportxmlTagattrsrs rArzTTFont._tableToXMLcs   g'B C $;IE,s2F+c1F  d? # 5' "2E'N5 ??l *E%L(%( &= KK+K > KK % frHc| tddd|vrd|vr|jddlm}|j ||}|j y)z_Import a TTX file (an XML-based text format), so as to recreate a font object. Nrrmaxppostr) xmlReader)r getGlyphOrderfontTools.miscr XMLReaderr)r9rorrr*s rA importXMLzTTFont.importXMLsN   g'B C T>fn    ,$$Z6 rHc||jvS)zbReturn true if the table identified by ``tag`` has been decompiled and loaded into memory.r)r9ris rAisLoadedzTTFont.isLoadedsdkk!!rHcj|j|ry|jr||jvry|dk(ryy)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.T GlyphOrderF)rr*rs rAhas_keyzTTFont.has_keys6 ==  [[SDKK/ L rHc(t|jj}|jr>t|jjD]}||vs|j |d|vr|j dt |}dg|zS)zSReturns the list of tables in the font, along with the ``GlyphOrder`` pseudo-table.r)rSr)rTr*appendremove sortedTagList)r9rTkeys rArTz TTFont.keyssDKK$$&' ;;DKK,,./ %d?KK$ % 4  KK %T"~$$rHc|jD]9}||}||jdu}|st|ds(|j|;d|_y)zEDecompile all the tables, even if a TTFont was opened in 'lazy' mode.NFensureDecompiled)recurse)rTr&r2r)r9rrirs rArzTTFont.ensureDecompiledsZ99; 8CIE))5075*<=&&w&7  8  rHcFtt|jSrD)rarSrTrFs rA__len__zTTFont.__len__s4 $%%rHct|}|jj|}|N|dk(rt|}||j|<|S|j|j |}|St d|z|S)Nr'%s' table not found)rr)r$rr* _readTableKeyErrorr9rirs rA __getitem__zTTFont.__getitem__s#h $ =l""3#( C  (, 5;<< rHctjd||j|}|j!|jj ||f}||St |}||}||j |<tjd| |j|||j||j||f<|S#t$r|jstjd|ddl m }t}tj|||}|j!|_||j |<|j||YwxYw)NReading '%s' table from diskzDecompiling '%s' tablez@An exception occurred during the decompilation of the '%s' tablerr)r:)rdebugr*r8r$ getTableClassr) decompile Exceptionr. exceptionrrrrL print_excrWr)r9ridatar tableClassrr:s rArzTTFont._readTables6 0#6{{3    '$$((#t5E  "3' 3  C *C0 ( OOD$ '    ',1D  c4[ ) # (-- MMRTW  ::D   T * %E--/EK$DKK  OOD$ ' (s B==BEEc4||jt|<yrD)r)rrs rA __setitem__zTTFont.__setitem__s % CHrHc||vrtd|z||jvr |j|=|jr||jvr|j|=yyy)Nr)rr)r*rs rA __delitem__zTTFont.__delitem__sW d?1C78 8 $++  C ;;3$++- C .;rHc0 ||S#t$r|cYSwxYw)zGReturns the table if it exists or (optionally) a default if it doesn't.)r)r9ridefaults rAr$z TTFont.gets% 9  N s  cz||_t|dr|`|jdr|dj |yy)zmSet the glyph order Args: glyphOrder ([str]): List of glyph names in order. _reverseGlyphOrderDictrN) glyphOrderr2rr setGlyphOrder)r9rs rArzTTFont.setGlyphOrders? % 41 2+ == L & &z 2 !rHc |jS#t$rYnwxYwd|vr&|d}|j|_|jSd|vr|dj}||j|jSt ||dj kr1t jd|j|jS||_|jS|j|jS)zDReturns a list of glyph names ordered by their position in the font.CFF rrzMNot enough names found in the 'post' table, generating them from cmap instead)rAttributeErrorr_getGlyphNamesFromCmapra numGlyphsrwarning)r9cffrs rArzTTFont.getGlyphOrder s ?? "    T>v,C!//1DO21t^f335J! ++-Z4<#9#99  c++- #-  ' ' )s  c.|jdr|jd}|jd=nd}t|dj}t |Dcgc]}d|z }}d|d<||_d|vr|dj }ni}i}t|D]L\}}||vs |j||}|j|ddzx} ||<| dkDr d|| dz fz}|||<Nd|vr'|jd=||_|r||jd<yyycc}w)Ncmapr glyph%.5dz.notdefrrz%s.alt%d) rr)intrrangerbuildReversedMin enumerate_makeGlyphNamer$) r9 cmapLoadingrir reversecmapuseCounttempName glyphNamenumUsess rArzTTFont._getGlyphNamesFromCmap0sT == ++f-K F#KV ../ /4Y/?@!kAo@ @! 1 % T>v,779KK$Z0 *KAx;&!// H0EF 08 Y0JQ0NN(9-Q; *i1-E EI ) 1  * T> F#(DO'2 F# 5As Dcfddlm}||jvr|j|S|dkrd|zSd|zS)Nr)aglizuni%04Xzu%X)r}rUV2AGL) codepointrs rArzTTFont._makeGlyphNameqs>!  "::i( ( & y( (9$ $rHc8t|j}|S)z1Get a list of glyph names, sorted alphabetically.)sortedr)r9 glyphNamess rA getGlyphNameszTTFont.getGlyphNames|sD..01 rHcLddlm}|j|jS)zZGet a list of glyph names, sorted alphabetically, but not case sensitive. r) textTools)rr caselessSortr)r9rs rAgetGlyphNames2zTTFont.getGlyphNames2s! -%%d&8&8&:;;rHcR |j|S#t$rd|zcYSwxYw)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)r9glyphIDs rA getGlyphNamezTTFont.getGlyphNames5  )%%'0 0 )( ( )s &&c||j}t|}|Dcgc]}||kr||nd|zc}Scc}w)z8Converts a list of glyph IDs into a list of glyph names.r)rra)r9lstrcntgids rAgetGlyphNameManyzTTFont.getGlyphNameManysA'') *oORS39 3+2CCSSSs9c |j|S#t$r9|dddk(r/ t|ddcYS#ttf$r t|wxYwwxYw)z0Returns the ID of the glyph with the given name.Nglyph)getReverseGlyphMaprr NameError ValueError)r9rs rA getGlyphIDzTTFont.getGlyphIDsp **,Y7 7 !}'.y}--!:.."9--.   sA 7AAAc|j} |Dcgc]}|| c}Scc}w#t$r+|j}|Dcgc] }|| ncc}wc}cYSwxYw)z8Converts a list of glyph names into a list of glyph IDs.)rrr)r9rdrrs rAgetGlyphIDManyzTTFont.getGlyphIDManysa  # # % @256YAiL6 66 @J;>?iJy)?? ? @s'* %**AA AAcV|s t|ds|j|jS)z.Returns a mapping of glyph names to glyph IDs.r)r2_buildReverseGlyphOrderDictr)r9rebuilds rArzTTFont.getReverseGlyphMaps' '$(@A  , , .***rHcdix|_}t|jD] \}}|||< |SrD)rrr)r9r rrs rAr z"TTFont._buildReverseGlyphOrderDicts?*,,#a"+D,>,>,@"A # GY"AiL #rHc||vryt|}|jD]1}||vs||vr|j||||!|j|3|j||j |}|G|j t ||f}|)tjd||j||ytjd||||<||||t ||f<yy)zcInternal helper function for self.save(). Keeps track of inter-table dependencies. Nzreusing '%s' tablezWriting '%s' table to disk) r dependenciesrbr getTableDatar$rrrsetEntry) r9rirgrhrdr masterTable tabledataentrys rArbzTTFont._writeTables $; "3' %22 -K$&$&$$[&$ KKK ,  - C%%c*  !NNCHi#89E  .4U+ .4s  !06s JC), - "rHc6t|}|j|r4tjd||j|j |S|j r3||j vr%tjd||j |St|)aReturns 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. zCompiling '%s' tabler)rrrrr)compiler*rrs rArzTTFont.getTableDatas|#h ==  II,c 2;;s#++D1 1 [[SDKK/ II4c :;;s# #3- rHc|rd|vrd}|r|s|j|}d}d|vsd|vr|sd|vr t||}nd|vrt|||}n tdd|vr t |||}|S) abReturn 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. fvarNrCFF2r) recalcBoundszFont contains no outlinesVARC)normalizeLocationr r r r)r9 preferCFFlocation normalizedrglyphSets rA getGlyphSetzTTFont.getGlyphSets4 d*H J--h7H dNfn9d@R%dH5H t^&tXLQH89 9 T>&tXx@HrHcddlm}d|vr td|dj}|||}d|vr|dj ||}|S)aNormalize 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)rrzNot a variable fontavar)fontTools.varLib.modelsrr getAxesrenormalizeLocation)r9rraxess rArzTTFont.normalizeLocations[ >  23 3F|##%$Xt4 T>F|77$GHrHc,|dj|S)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)r9r*s rAr+zTTFont.getBestCmap$sFF|'''HHrHc"ddlm}|||y)Nr reorderGlyphsr-)r9new_glyph_orderr.s rAr.zTTFont.reorderGlyphsIs0dO,rH)TrD) )TNNNFFTrNF)F)TNFT))) )r)r)r2r)rr2)rru)rr)rr)-__name__ __module__ __qualname____doc__NotImplementedrBrGrMr7r]rRrqrnrrrr __contains__rTrrrrrrr$rrr staticmethodrrrrrrr rr rbrr"rr+r.rErHrArrs>Qj&#  !V1p /b'0   $#>@:&" L %& @&! 3!F?2B%% < )T @+  <4 $MQ'R.  #IJ-rHrc$eZdZdZddZdZdZy)rzA 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. NcyrDrErs rArBzGlyphOrder.__init__Ts rHc|j}|jd|jt|D])\}}|j d|||j+y)NzAThe 'id' attribute is only for humans; it is ignored when parsed.GlyphID)idr!)rcommentrrr)r9rgrvrrrs rArzGlyphOrder.toXMLWsb))+  R  %j1 LAy   Y19  = NN  rHct|dsg|_|dk(r|jj|d|j|jy)Nrr@r!)r2rrr)r9r!rcontentrvs rAfromXMLzGlyphOrder.fromXMLasCt\* DO 9  OO " "5= 1T__-rHrD)r6r7r8r9rBrrErErHrArrOs .rHrcddlm}t|} td|zt ||S#t $r)}t |j|dk\rYd}~y|d}~wwxYw)z[Fetch the packer/unpacker module for a table. Return None when no module is found. rrzfontTools.ttLib.tables.rN)r3r)r __import__getattr ImportErrorstrfind)rir)pyTagerrs rAgetTableModulerNisd C E &,u45vu%%  s8== 1 $Is- AAAAc:|dt|z}||ft|<y)abRegister 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` Ntable_)r_customTableRegistry)ri moduleName classNames rAregisterCustomTableClassrTs)s33 !+Y 7rHct|=y)z8Unregister the custom packer/unpacker class for a table.N)rQris rAunregisterCustomTableClassrWs S!rHcn|tvryddl}t|\}}|j|}t||S)zReturn the custom table class for tag, if one has been registered with 'registerCustomTableClass()'. Else return None. Nr)rQ importlib import_modulerH)rirYrRrSmodules rAgetCustomTableClassr\s? &&05J  $ $Z 0F 69 %%rHct|}||St|}|ddlm}|St |}t |d|z}|S)z,Fetch the packer/unpacker class for a table.rrrP)r\rNrrrrH)rirr[rrLs rArrsQ$S)J C F ~5 C EE!12J rHcN|j}|dddk(sJ|dd}t|S)z'Fetch the table tag for a class object.Nr4rP)r6identifierToTag)klassr!s rA getClassTagras5 >>D 8x   8D 4  rHc(t|}||S)z!Return a new instance of a table.)r)rirs rAnewTablercss#J c?rHcddl}|jd|rd|zS|jd|r|dzStt|ddS)z%Helper function for tagToIdentifier()rNz[a-z0-9]_z[A-Z]ru)rematchhexr)crfs rA _escapecharrjsH  xx AQw '1 3w71:qr""rHcddl}t|}|dk(r|St|dk(sJdt|dkDr$|ddk(r|dd}t|dkDr |ddk(rd }|D]}|t|z}|j d |rd |z}|S) aConvert 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' rNrr5ztag should be 4 characters longrr r3z[0-9]re)rfrrarjrg)rirfidentris rArrs& c(C l s8q=;;;= c(Q,3r7c>#2h c(Q,3r7c> E ' A&' xxe  LrHc j|dk(r|St|dzr |ddk(r|dd}t|dzrJd}tdt|dD]H}||dk(r |||dzz}||dzdk(r |||z}+|tt|||dzdz}J|d t|z d zz}t |S) z!the opposite of tagToIdentifier()rrurrerNr3r5rl)rarchrrr)rmrirs rAr_r_s   5zA~%(c/ab E Q  C 1c%j! $7 8s?a!e $C 1q5\S a.CCa!a% 0"566C7 SX$ $C s8OrHcddl}t|}|dk(ry|dk(r|S|jd|r|jSt |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. rNOS/2OS_2rz[A-Za-z_][A-Za-z_0-9]* *$)rfrrgstripr)rirfs rArrsM  c(C f}   xx+S1yy{s##rHc|dk(r tdSt|dk(r t|St|ddt|z zzS)zThe opposite of tagToXML()rsrrrlr5)rrar_rVs rAxmlToTagrwsF f}6{ 3x1}s##3CH --..rH)r_hhearrrhmtxLTSHVDMXhdmxrfpgmprepzcvt locarkernr!rgaspPCLT)r_rxrrrr!rrrct|}|7d|vr"|jd|jdd|vrt}nt}g}|D])}||vs|j||j|+|j ||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. DSIGr)rrr OTFTableOrder TTFTableOrderextend)tagListr[ orderedTablesris rArr=s WoG W  NN6 " NN6 " W &J&JM  '>   % NN3  ! rHcf|jd|jdt||}t|t|j|j |j |j}t|j}t||D] }||||< |jy)zcRewrite a font file, ordering the tables as recommended by the OpenType specification 1.4. r)r<N) r rrrar)r/r0r1rSrTrr7)inFileoutFiler[r<r*rgr)ris rArVrVUs KKN LLO ~ >F  FMM  F&++- FVZ0"Sks " LLNrHcBd}|r |dz }|dz}|r t|dz dS)z_Return the highest exponent of two, so that (2 ** exponent) <= x. Return 0 if x is 0. rr)max)xexponents rA maxPowerOfTworis6H Fa<  x!|Q rHcZt|}d|z|z}|}td||z|z }|||fS)z1Calculate searchRange, entrySelector, rangeShift.rur)rr)nitemSizer searchRange entrySelector rangeShifts rAgetSearchRangertsCQHh;(*KMQH {23J  z 11rHrDr1)ro)6fontTools.configrrrfontTools.misc.configToolsrfontTools.misc.textToolsrrrfontTools.misc.loggingToolsr fontTools.ttLibr fontTools.ttLib.ttGlyphSetr r r rfontTools.ttLib.sfntrriorrrrloggingrL getLoggerr6robjectrrrNrQrTrWr\rrarcrjrr_rrwrrrrVrrrErHrArs#$5889& 866 g!v -Vv -r..4&2 8" & ! # F*$$/ ,Q 0( 2rH