Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
3 2øªj¯zã@s¨ddlmZddlmZmZmZddlmZddlm Z ddl m Z m Z ddl mZmZddlZddlZddlZejeƒZGdd „d eƒZGd d „d eƒZGd d „d eƒZGdd„deƒZGdd„deƒZGdd„deƒZdd„ZiZdJdd„Zdd„Z dd„Z!dd„Z"dd„Z#d d!„Z$d"d#„Z%d$d%„Z&d&d'„Z'd(d)„Z(d*d+„Z)d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dgZ*d,d-d.d/d;d4dd?„Z!d@dA„Z"dBdC„Z#d]dDdE„Z$dFdG„Z%d^dHdI„Z&dJdK„Z'd_dLdM„Z(didSdT„Z)dS)jÚTTFontzùThe 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. NzrTFécCshx6dD].}tƒj|ƒ}|dk r(t|dƒt|||ƒqW| |_||_| |_i|_d|_| |_ |sv||_ ||_ d|_ dSt |dƒsÞd}|dk rÒddlm}|d krÄ|j|ƒr¸|j|dƒ}qÐt|d ƒ}qÜ|j||ƒ}qìt|d ƒ}nd }|jd ƒ|j�s0|jd ƒt|jƒƒ}t |d ƒ�r|j|_|�r,|jƒ|}||_t||| d �|_|jj |_ |jj |_ |jj |_ dS)aBThe 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 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ÚquietNzconfigure logging insteadÚreadTr )ÚmacUtilsrÚrbFÚname)Ú fontNumber)rr)ÚlocalsÚgetrÚsetattrÚlazyÚ recalcBBoxesÚrecalcTimestampÚtablesÚreaderÚignoreDecompileErrorsÚ sfntVersionÚflavorÚ flavorDataÚhasattrÚrZgetSFNTResIndicesZSFNTResourceReaderÚopenÚseekr rrÚcloseÚ _tableCacher)ÚselfÚfileZres_name_or_indexrrÚcheckChecksumsrrZallowVIDrrrrrr&rÚvalZ closeStreamrÚtmp©r,ú;/tmp/pip-build-_d5lkt3n/fonttools/fontTools/ttLib/ttFont.pyÚ__init__sR5              zTTFont.__init__cCs|S)Nr,)r'r,r,r-Ú __enter__�szTTFont.__enter__cCs |jƒdS)N)r%)r'ÚtypeÚvalueÚ tracebackr,r,r-Ú__exit__„szTTFont.__exit__cCs|jdk r|jjƒdS)z+If we still have a reader object, close it.N)rr%)r'r,r,r-r%‡s z TTFont.closec Csät|dƒs,|jr&|jjj|kr&tdƒ‚d}nd}tƒ}|j|ƒ}|dkp\|p\|dko\|jdks |dkrvt|jj ƒƒ}nd}|j ƒtƒ}t |||ƒ|j ƒ|}|rÊt |dƒ�}|j|jƒƒWdQRXn|j|jƒƒ|j ƒdS)zƒSave 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!rrr(rrr Ú_saveÚlistÚkeysÚflushÚreorderFontTablesr%r#r4Úgetvalue)r'r(Z reorderTablesZ createStreamr+Zwriter_reordersTablesÚ tableOrderZtmp2r,r,r-ÚsaveŒs.     z TTFont.savecCs„|jrd|kr|dt|jƒƒ}d|kr4|jdƒt|ƒ}t|||j|j|jƒ}g}x|D]}|j ||||ƒq\W|j ƒ|j ƒS)zAInternal function, to be shared by save() and TTCollection.save()ÚheadÚ GlyphOrder) rr7r8ÚremoveÚlenr rrr Ú _writeTabler%ZreordersTables)r'r(Ú tableCacheÚtagsÚ numTablesÚwriterÚdoneÚtagr,r,r-r6µs   z TTFont._saveÚ cKs(tj||d�}|j|f|Ž|jƒdS)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Ú_saveXMLr%)r'Ú fileOrPathrJÚkwargsrFr,r,r-ÚsaveXMLÊs zTTFont.saveXMLÚrawc CsÞ|dk rtddƒ||_| |_|sdt|jƒƒ}d|kr@dg|}|rdx|D]} | |krJ|j| ƒqJWt|ƒ} |r¸ddlm} dj | j dƒdd…ƒ} |j dt t |jƒƒd d…| d �n |j dt t |jƒƒd d…d �|jƒ|pæ|}|sö|jƒntjj|jƒ\} }| d |}x²t| ƒD]¦}||} |�rŽ|t| ƒ}tj||jd �}|j d| d�|jƒ|jƒ|jt| ƒtjj|ƒd�|jƒn|}|j|| |d�|�r|jdƒ|jƒ|jƒ�qW|jdƒ|jƒdS)Nrzconfigure logging insteadr?r)ÚversionÚ.éÚttFontr )rÚ ttLibVersion)rz.%s)rJ)rU)Úsrc)Ú splitGlyphséÿÿÿÿrX)rÚdisassembleInstructionsÚbitmapGlyphDataFormatr7r8r@rAÚ fontToolsrQÚjoinÚsplitÚbegintagÚreprrrÚnewlineÚosÚpathÚsplitextÚfilenameÚrangeÚtagToIdentifierrrKrJÚ simpletagÚtagToXMLÚbasenameÚ _tableToXMLÚendtagr%)r'rFZ writeVersionrrZ skipTablesZ splitTablesrWrYrZrHrErQrbÚextZfileNameTemplateÚiZ tablePathZ tableWriterr,r,r-rL×sX              zTTFont._saveXMLc Csâ|dk rtddƒ||kr,||}d|}nd|}tj|ƒ||krJdSt|ƒ}tƒ}t|dƒrjd|d<ddlm} |j| krˆd |d <|j |f|Ž|j ƒ|d kr¸|j |||d �n |j ||ƒ|j |ƒ|j ƒ|j ƒdS) Nrzconfigure logging insteadzDumping '%s' table...zNo '%s' table found.ÚERRORzdecompilation errorr )Ú DefaultTableTrPÚglyf)rW) rÚlogÚinforhÚdictr!Útables.DefaultTableroÚ __class__r^r`ÚtoXMLrk) r'rFrHrrWÚtableÚreportZxmlTagÚattrsror,r,r-rjs0        zTTFont._tableToXMLcCsN|dk rtddƒd|kr*d|kr*|jƒddlm}|j||ƒ}|jƒdS)zSImport a TTX file (an XML-based text format), so as to recreate a font object. Nrzconfigure logging insteadÚmaxpÚpostr)Ú xmlReader)rÚ getGlyphOrderÚfontTools.miscr|Ú XMLReaderr)r'rMrr|rr,r,r-Ú importXML/s   zTTFont.importXMLcCs ||jkS)zZReturn true if the table identified by 'tag' has been decompiled and loaded into memory.)r)r'rHr,r,r-ÚisLoadedBszTTFont.isLoadedcCs6|j|ƒrdS|jr"||jkr"dS|dkr.dSdSdS)NTr?F)r�r)r'rHr,r,r-Úhas_keyGs zTTFont.has_keycCsbt|jjƒƒ}|jr>x(t|jjƒƒD]}||kr$|j|ƒq$Wd|krP|jdƒt|ƒ}dg|S)Nr?)r7rr8rÚappendr@Ú sortedTagList)r'r8Úkeyr,r,r-r8Ss z TTFont.keyscCstt|jƒƒƒS)N)rAr7r8)r'r,r,r-Ú__len___szTTFont.__len__cCs^t|ƒ}|jj|ƒ}|dkrZ|dkr8t|ƒ}||j|<n"|jdk rN|j|ƒ}n td|ƒ‚|S)Nr?z'%s' table not found)rrrr?rÚ _readTableÚKeyError)r'rHrwr,r,r-Ú __getitem__bs     zTTFont.__getitem__c Csþtjd|ƒ|j|}|jdk r<|jj||fƒ}|dk r<|St|ƒ}||ƒ}||j|<tjd|ƒy|j||ƒWnntk rà|j sŠ‚tj d|ƒddl m }t ƒ}tj|d�||ƒ}|jƒ|_||j|<|j||ƒYnX|jdk rú||j||f<|S)NzReading '%s' table from diskzDecompiling '%s' tablez@An exception occurred during the decompilation of the '%s' tabler )ro)r()rqÚdebugrr&rÚ getTableClassrZ decompileÚ ExceptionrÚ exceptionrtror r2Ú print_excr;rn)r'rHÚdatarwÚ tableClassror(r,r,r-r‡os6          zTTFont._readTablecCs||jt|ƒ<dS)N)rr)r'rHrwr,r,r-Ú __setitem__�szTTFont.__setitem__cCsB||krtd|ƒ‚||jkr&|j|=|jr>||jkr>|j|=dS)Nz'%s' table not found)rˆrr)r'rHr,r,r-Ú __delitem__�s   zTTFont.__delitem__c Cs"y||Stk r|SXdS)N)rˆ)r'rHÚdefaultr,r,r-r˜sz TTFont.getcCs||_t|dƒr|`dS)NÚ_reverseGlyphOrderDict)Ú glyphOrderr!r”)r'r•r,r,r-Ú setGlyphOrderžs zTTFont.setGlyphOrderc Csty|jStk rYnXd|kr8|d}|jƒ|_n6d|krf|djƒ}|dkr^|jƒqn||_n|jƒ|jS)NzCFF r{)r•ÚAttributeErrorr}Ú_getGlyphNamesFromCmap)r'Úcffr•r,r,r-r}£s   zTTFont.getGlyphOrderc Cs|jdƒr|jd}|jd=nd}t|djƒ}dg|}d|d<xtd|ƒD]}d|||<qNW||_d|kr~|djƒ}ni}i}xjt|ƒD]^}||}||kr�|jt||ƒƒ}|j |dƒd} ||<| dkræd|| df}|||<q�Wd|k�r|jd=||_|�r||jd<dS)NÚcmaprzz.notdefrr z glyph%.5dz%s.alt%d) r�rÚintÚ numGlyphsrer•Z buildReversedÚ_makeGlyphNameÚminr) r'Z cmapLoadingrœr•rmZ reversecmapZuseCountZtempNameÚ glyphNameZnumUsesr,r,r-r˜»s6      zTTFont._getGlyphNamesFromCmapcCs<ddlm}||jkr |j|S|dkr0d|Sd|SdS)Nr)Úagliÿÿzuni%04Xzu%X)r[r ZUV2AGL)Ú codepointr r,r,r-r�ÿs    zTTFont._makeGlyphNamecCst|jƒƒ}|S)z1Get a list of glyph names, sorted alphabetically.)Úsortedr})r'Z glyphNamesr,r,r-Ú getGlyphNames s zTTFont.getGlyphNamescCsddlm}|j|jƒƒS)zNGet a list of glyph names, sorted alphabetically, but not case sensitive. r)Ú textTools)r~r¤Z caselessSortr})r'r¤r,r,r-ÚgetGlyphNames2s zTTFont.getGlyphNames2c Cs*y |jƒ|Stk r$d|SXdS)Nz glyph%.5d)r}Ú IndexError)r'ÚglyphIDr,r,r-Ú getGlyphNames zTTFont.getGlyphNamecs$|jƒ‰tˆƒ‰‡‡fdd„|DƒS)Ncs$g|]}|ˆkrˆ|nd|‘qS)z glyph%.5dr,)Ú.0Úgid)Úcntr•r,r-ú sz+TTFont.getGlyphNameMany..)r}rA)r'Úlstr,)r«r•r-ÚgetGlyphNameManys zTTFont.getGlyphNameManycCshy |jƒ|Stk rb|dd…dkr^yt|dd…ƒSttfk r\t|ƒ‚YnXYnXdS)NéÚglyph)ÚgetReverseGlyphMaprˆr›Ú NameErrorÚ ValueError)r'rŸr,r,r-Ú getGlyphID!s zTTFont.getGlyphIDc sH|jƒ‰y‡fdd„|DƒStk rB|j‰‡fdd„|DƒSXdS)Ncsg|] }ˆ|‘qSr,r,)r©rŸ)Údr,r-r¬.sz)TTFont.getGlyphIDMany..csg|] }ˆ|ƒ‘qSr,r,)r©rŸ)r´r,r-r¬1s)r±rˆr´)r'r­r,)rµr´r-ÚgetGlyphIDMany+s zTTFont.getGlyphIDManycCs|st|dƒ r|jƒ|jS)Nr”)r!Ú_buildReverseGlyphOrderDictr”)r'Zrebuildr,r,r-r±3szTTFont.getReverseGlyphMapcCs0i|_}x t|jƒƒD]\}}|||<qW|S)N)r”Ú enumerater})r'rµr§rŸr,r,r-r·8s  z"TTFont._buildReverseGlyphOrderDictc CsÖ||kr dSt|ƒ}x:|jD]0}||kr||krB|j||||ƒq|j|ƒqW|j|ƒ|j|ƒ}|dk r¢|jt|ƒ|fƒ}|dk r¢tjd|ƒ|j ||ƒdStjd|ƒ|||<|dk rÒ|||t|ƒ|f<dS)zWInternal helper function for self.save(). Keeps track of inter-table dependencies. Nzreusing '%s' tablezWriting '%s' table to disk) r‹Z dependenciesrBrƒÚ getTableDatarrrqrŠZsetEntry) r'rHrFrGrCr�Z masterTableZ tabledataÚentryr,r,r-rB>s(      zTTFont._writeTablecCs`t|ƒ}|j|ƒr.tjd|ƒ|j|j|ƒS|jrT||jkrTtjd|ƒ|j|St|ƒ‚dS)zGReturns raw table data, whether compiled or directly read from disk. zCompiling '%s' tablezReading '%s' table from diskN)rr�rqrŠrÚcompilerrˆ)r'rHr,r,r-r¹Xs    zTTFont.getTableDatacs d}|rt‡fdd„d Dƒƒsrsz%TTFont.getGlyphSet..úCFF ÚCFF2rpc3s|]}|ˆkVqdS)Nr,)r©r¼)r'r,r-r½ssrzFont contains no outlines)r¾r¿)r¾r¿) ÚanyÚ _TTGlyphSetr7r™ÚvaluesZ CharStringsÚ _TTGlyphCFFÚ _TTGlyphGlyfr)r'Z preferCFFÚglyphsZ table_tagr,)r'r-Ú getGlyphSetes zTTFont.getGlyphSetéé éérScCs|dj|d�S)aFReturn 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)r'rËr,r,r-rÌ€s zTTFont.getBestCmaprX)T)N)rI)TNNNFFTrP)NF)N)N)F)N)T©rÇrÈ©rrÉ©rrÊ©rÇr ©rrÇ©rrS©rr ©rr©rÍrÎrÏrÐrÑrÒrÓrÔ)rÕ)*Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚNotImplementedr.r/r3r%r=r6rOrLrjr€r�r‚Ú __contains__r8r†r‰r‡r‘r’rr–r}r˜Ú staticmethodr�r£r¥r¨r®r´r¶r±r·rBr¹rÆrÌr,r,r,r-r sX h )   8      D     r c@sFeZdZdZdd„Zdd„Zdd„ZeZdd „Zd d „Z dd d„Z d S)rÁzfGeneric dict-like GlyphSet class that pulls metrics from hmtx and glyph shape from TrueType or CFF. cCs0||_|d|_d|kr |dnd|_||_dS)zìConstruct 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``. ÚhmtxZvmtxN)Ú_glyphsÚ_hmtxÚ_vmtxÚ _glyphType)r'rTrÅZ glyphTyper,r,r-r.’s z_TTGlyphSet.__init__cCst|jjƒƒS)N)r7rÞr8)r'r,r,r-r8Ÿsz_TTGlyphSet.keyscCs ||jkS)N)rÞ)r'rŸr,r,r-r‚¢sz_TTGlyphSet.has_keycCs4|j|}|jr|j|nd}|j||j|||ƒS)N)rßràrárÞ)r'rŸÚhorizontalMetricsÚverticalMetricsr,r,r-r‰§s z_TTGlyphSet.__getitem__cCs t|jƒS)N)rArÞ)r'r,r,r-r†­sz_TTGlyphSet.__len__Nc Cs"y||Stk r|SXdS)N)rˆ)r'rŸr“r,r,r-r°sz_TTGlyphSet.get)N) rÖr×rØrÙr.r8r‚rÛr‰r†rr,r,r,r-rÁŒs rÁc@s*eZdZdZd dd„Zdd„Zdd„ZdS) Ú_TTGlyphaQWrapper 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. NcCs:||_||_|\|_|_|r*|\|_|_n d\|_|_dS)zñConstruct 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. N)NN)Ú _glyphsetÚ_glyphÚwidthÚlsbÚheightZtsb)r'Zglyphsetr°rârãr,r,r-r.Ás  z_TTGlyph.__init__cCs|jj|ƒdS)zXDraw the glyph onto ``pen``. See fontTools.pens.basePen for details how that works. N)ræÚdraw)r'Úpenr,r,r-rêÑsz _TTGlyph.drawcCs tƒ‚dS)N)ÚNotImplementedError)r'rër,r,r-Ú drawPoints×sz_TTGlyph.drawPoints)N)rÖr×rØrÙr.rêrír,r,r,r-rä¶s  räc@s eZdZdS)rÃN)rÖr×rØr,r,r,r-rÃÛsrÃc@seZdZdd„Zdd„ZdS)rÄcCs:|jj}|j}t|dƒr$|j|jnd}|j|||ƒdS)zTDraw the glyph onto Pen. See fontTools.pens.basePen for details how that works. ÚxMinrN)rårÞrær!rèrîrê)r'rëÚ glyfTabler°Úoffsetr,r,r-rêàsz_TTGlyphGlyf.drawcCs:|jj}|j}t|dƒr$|j|jnd}|j|||ƒdS)zZDraw the glyph onto PointPen. See fontTools.pens.pointPen for details how that works. rîrN)rårÞrær!rèrîrí)r'rërïr°rðr,r,r-ríész_TTGlyphGlyf.drawPointsN)rÖr×rØrêrír,r,r,r-rÄÞs rÄc@s*eZdZdZd dd„Zdd„Zdd„ZdS) r?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. NcCsdS)Nr,)r'rHr,r,r-r.ùszGlyphOrder.__init__cCsT|jƒ}|jdƒ|jƒx4tt|ƒƒD]$}||}|jd||d�|jƒq(WdS)NzAThe 'id' attribute is only for humans; it is ignored when parsed.ÚGlyphID)Úidr)r}Úcommentr`rerArg)r'rFrTr•rmrŸr,r,r-rvüs zGlyphOrder.toXMLcCs8t|dƒsg|_|dkr(|jj|dƒ|j|jƒdS)Nr•rñr)r!r•rƒr–)r'rryÚcontentrTr,r,r-ÚfromXMLs  zGlyphOrder.fromXML)N)rÖr×rØrÙr.rvrõr,r,r,r-r?ós  r?cCspddlm}t|ƒ}ytd|ƒWn<tk r`}z t|ƒj|ƒdkrLdS|‚WYdd}~Xn Xt||ƒSdS)zUFetch the packer/unpacker module for a table. Return None when no module is found. r )rzfontTools.ttLib.tables.rN)r"rrfÚ __import__Ú ImportErrorÚstrÚfindÚgetattr)rHrÚpyTagÚerrr,r,r-ÚgetTableModules rýcCs$|dkrdt|ƒ}||ft|<dS)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_)rfÚ_customTableRegistry)rHÚ moduleNameÚ classNamer,r,r-ÚregisterCustomTableClass)s  rcCs t|=dS)z8Unregister the custom packer/unpacker class for a table.N)rÿ)rHr,r,r-ÚunregisterCustomTableClass7srcCs4|tkr dSddl}t|\}}|j|ƒ}t||ƒS)zyReturn the custom table class for tag, if one has been registered with 'registerCustomTableClass()'. Else return None. Nr)rÿÚ importlibÚ import_modulerú)rHrrrÚmoduler,r,r-ÚgetCustomTableClass<s   rcCsNt|ƒ}|dk r|St|ƒ}|dkr4ddlm}|St|ƒ}t|d|ƒ}|S)z,Fetch the packer/unpacker class for a table.Nr )rorþ)rrýrtrorfrú)rHr�rrorûr,r,r-r‹Hs r‹cCs.|j}|dd…dkst‚|dd…}t|ƒS)z'Fetch the table tag for a class object.NrÉrþ)rÖÚAssertionErrorÚidentifierToTag)Úklassrr,r,r-Ú getClassTagVs r cCst|ƒ}||ƒS)z!Return a new instance of a table.)r‹)rHr�r,r,r-ÚnewTable^sr cCsHddl}|jd|ƒrd|S|jd|ƒr0|dStt|ƒƒdd…SdS)z%Helper function for tagToIdentifier()rNz[a-z0-9]Ú_z[A-Z]rS)ÚreÚmatchÚhexr)Úcrr,r,r-Ú _escapechards   rcCs�ddl}t|ƒ}|dkr|St|ƒdks0tdƒ‚x(t|ƒdkrX|d dkrX|dd …}q2Wd}x|D]}|t|ƒ}qdW|jd |ƒrŒd |}|S) a4Convert 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' rNr?rÊztag should be 4 characters longr ú r"z[0-9]r rXrX)rrrArrr)rHrÚidentrr,r,r-rfos   rfcCsÖ|dkr |St|ƒdr0|ddkr0|dd…}t|ƒd sBt‚d}xrtdt|ƒdƒD]^}||dkrz|||d}qX||ddkr˜|||}qX|tt|||d…dƒƒ}qXW|d t|ƒd }t|ƒS) z!the opposite of tagToIdentifier()r?rSrr r Nr"érÊr)rArreÚchrr›r)rrHrmr,r,r-r ‹s  "r cCsHddl}t|ƒ}|dkrdS|dkr(|S|jd|ƒr<|jƒSt|ƒSdS)z±Similarly 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. rNzOS/2ÚOS_2r?z[A-Za-z_][A-Za-z_0-9]* *$)rrrÚstriprf)rHrr,r,r-rh s rhcCs@|dkrtdƒSt|ƒdkr$t|ƒSt|ddt|ƒƒSdS)zThe opposite of tagToXML()rzOS/2érrÊN)rrAr )rHr,r,r-ÚxmlToTag±s  rr>ZhhearzzOS/2rÝZLTSHZVDMXZhdmxršZfpgmÚprepzcvt ZlocarpÚkernrr{ZgaspZPCLTzCFF cCszt|ƒ}|dkr>d|kr,|jdƒ|jdƒd|kr:t}nt}g}x(|D] }||krH|j|ƒ|j|ƒqHW|j|ƒ|S)z¼Return 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. NZDSIGzCFF )r¢r@rƒÚ OTFTableOrderÚ TTFTableOrderÚextend)ZtagListr<Z orderedTablesrHr,r,r-r„Äs     r„FcCst|jdƒ|jdƒt||d�}t|t|jƒ|j|j|jƒ}t|j ƒƒ}xt ||ƒD]}||||<qTW|j ƒdS)z]Rewrite a font file, ordering the tables as recommended by the OpenType specification 1.4. r)r)N) r$rr rArrrr r7r8r„r%)ZinFileZoutFiler<r)rrFrrHr,r,r-r:Üs    r:cCs,d}x|r|d?}|d}qWt|ddƒS)zYReturn the highest exponent of two, so that (2 ** exponent) <= x. Return 0 if x is 0. rr )Úmax)ÚxÚexponentr,r,r-Ú maxPowerOfTwoês  r#rcCs4t|ƒ}d||}|}td|||ƒ}|||fS)z3Calculate searchRange, entrySelector, rangeShift. rSr)r#r )ÚnZitemSizer"Z searchRangeZ entrySelectorZ rangeShiftr,r,r-ÚgetSearchRangeõs  r%)N)N)NF)r)0r~rZfontTools.misc.textToolsrrrZfontTools.misc.loggingToolsrZfontTools.ttLibrZfontTools.ttLib.sfntrr Úior r raÚloggingr2Ú getLoggerrÖrqÚobjectr rÁrärÃrÄr?rýrÿrrrr‹r r rrfr rhrrrr„r:r#r%r,r,r,r-ÚsT    *%