� ��g���~�ddlmZddlmZddlmZddlmZmZm Z ddl m Z ddl m Z ddlmZmZmZmZddlmZmZdd lmZmZmZdd lZdd lZdd lZeje��ZGd �d e ��Z!Gd �de ��Z"d�Z#iZ$d#d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+d�Z,d�Z-d�Z.d�Z/gd�Z0gd�Z1d#d�Z2d$d�Z3d �Z4d%d"�Z5d S)&�)�Config)� xmlWriter)�AbstractConfig)�Tag�byteord�tostr)�deprecateArgument)� TTLibError)�_TTGlyph�_TTGlyphSetCFF�_TTGlyphSetGlyf�_TTGlyphSetVARC)� SFNTReader� SFNTWriter)�BytesIO�StringIO�UnsupportedOperationNc�V�eZdZdZdddddddeddddddifd�Zd �Zd �Zd �Zd1d �Z d2d �Z d3d�Z d4d�Z d5d�Z d2d�Zd�Zd�ZeZd�Zd2d�Zd�Zd�Zd�Zd�Zd�Zd2d�Zd�Zd�Zd �Zed!���Zd"�Zd#�Z d$�Z!d%�Z"d&�Z#d'�Z$d6d(�Z%d)�Z&d2d*�Z'd+�Z( d7d,�Z)d-�Z* d8d/�Z+d0�Z,dS)9�TTFonta_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. NzrTF�����c��dD]F}t���|��}|�t|d��t|||���G| |_||_| |_i|_d|_t|t��r|� ��nt|��|_ | |_|s||_||_d|_dSd}t%|d��sud}|�`ddlm}|dkr=|�|��r|�|d��}n�t/|d��}n�|�||��}nqt/|d��}n`d }t%|d ��r|���}n9t%|d ��r) |�d��n#t4$rd }YnwxYw|jsm|r|�d��t7|�����}t%|d ��r |j|_|r|���|}n|st?d ���||_ tC||| ���|_|jj|_|jj|_|jj|_dS)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�openrr rrrr!�closer � _tableCacher)�self�file�res_name_or_indexr/r0�checkChecksumsrr'�allowVIDr.r(r"r&rr8r-r!�valr� closeStreamr�tmps �f/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/fontTools/ttLib/ttFont.py�__init__zTTFont.__init__js���$)� %� %�D��(�(�,�,�t�$�$�C���!�$�(C�D�D�D� �D�$�� $� $� $� $��� �(���.����� ��� �!+�C��!@�!@�Q�3�8�8�:�:�:�f�S�k�k���%:��"�� �*�D� � �D�K�"�D�O� �F����t�V�$�$� %��K� �,�&�&�&�&�&�&�$��)�)��1�1�$�7�7�0�'�:�:�4��C�C���#�D�$�/�/���#�6�6�t�=N�O�O�D�D��D�$�'�'��� �K��t�Z�(�(� %��=�=�?�?�����v�&�&� %�%��I�I�a�L�L�L�L��+�%�%�%�$�H�H�H�%�����y� K�� �� � �!� � � ��$�)�)�+�+�&�&�C��t�V�$�$� %��9���� �� � � � � ��D�D�� K��I�J�J� J�&��� ��~�*�M�M�M�� ��;�2����k�(�� ��+�0����s� F� F.�-F.c��|S�N��r9s rA� __enter__zTTFont.__enter__�s��� �c�.�|���dSrD)r7)r9�type�value� tracebacks rA�__exit__zTTFont.__exit__�s�� � � � � � � � rHc�J�|j�|j���dSdS)z+If we still have a reader object, close it.N)r*r7rFs rAr7z TTFont.close�s,�� �;� "� �K� � � � � � � � #� "rHc���t|d��s.|jr$|jjj|krt d���d}nd}t ��}|�|��}|��|s�|dur|j�v|dur't|j� ����}nd}|� ��t ��}t|||��|� ��|}|rPt|d��5}|�|�����ddd��n #1swxYwYn'|�|�����|� ��dS)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)r2r&r*r:r!r r�_save�list�keys�flush�reorderFontTablesr7r6rP�getvalue)r9r:� reorderTables� createStreamr@�writer_reordersTables� tableOrder�tmp2s rA�savez TTFont.save�s����t�W�%�%� !��y� Y�T�[�-�2�d�:�:� �!W�X�X�X��L�L�!�L��i�i�� $� � �3���� � !�$� "���&�&�4�;�+>���%�%�!�$�+�"2�"2�"4�"4�5�5� � �"� � �I�I�K�K�K��9�9�D� �c�4�� 4� 4� 4� �I�I�K�K�K��C� � '��d�D�!�!� +�T�� � �3�<�<�>�>�*�*�*� +� +� +� +� +� +� +� +� +� +� +���� +� +� +� +�� �J�J�s�|�|�~�~� &� &� &� � � � � � � � s�;(D/�/D3�6D3c��|jr d|vr|dt|�����}d|vr|�d��t |��}t |||j|j|j��}g}|D]}|� ||||���|� ��|� ��S)zAInternal function, to be shared by save() and TTCollection.save()�head� GlyphOrder) r(rSrT�remove�lenrr/r0r1� _writeTabler7�reordersTables)r9r:� tableCache�tags� numTables�writer�done�tags rArRz TTFont._save�s��� � � �F�d�N�N� �� � ��D�I�I�K�K� � �� �4� � � �K�K� � %� %� %���I�I� �� �)�T�-�t�{�D�O� � ����� <� <�C� � � �S�&�$� � ;� ;� ;� ;�� � �����$�$�&�&�&rH� c �v�tj||���}|j|fi|��|���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�_saveXMLr7)r9� fileOrPathrn�kwargsrhs rA�saveXMLzTTFont.saveXMLsD���$�Z�J�G�G�G���� �f�'�'��'�'�'�� � �����rH�rawc ���|�tdd��||_| |_|sKt|�����}d|vrdg|z}|r|D]} | |vr|�| ���t |��} |rvddlm} d� | � d��dd���} |� dtt|j����d d �| � ��n>|� dtt|j����d d �� ��|���|p|}|s|���n't j�|j��\} }t)| ��D�].}||} |r�| dzt+| ��z|z}t-j||j� ��}|� d| ���|���|���|�t5| ��t j�|�����|���n|}|�|| |���|r=|�d��|���|�����0|�d��|���dS)Nrrr`r)�version�.��ttFontrr)r/� ttLibVersion)r/rm)rz)�src�� splitGlyphs)r �disassembleInstructions�bitmapGlyphDataFormatrSrTrarb� fontToolsrv�join�split�begintag�reprrr/�newline�os�path�splitext�filename�range�tagToIdentifierrrorn� simpletag�tagToXML�basename� _tableToXML�endtagr7)r9rh� writeVersionrr)� skipTables� splitTablesr}r~rrjrgrvr��ext�i� tablePath� tableWriters rArpzTTFont._saveXML$s�� � � �g�'B� C� C� C�'>��$�%:��"�� +��$�)�)�+�+�&�&�F��6�)�)�&��&�0��� +�%�+�+�C��f�}�}�� � �c�*�*�*����K�K� � � W� )� )� )� )� )� )��h�h�w�}�}�S�1�1�"�1�"�5�6�6�G� �O�O�� ��t�'7�!8�!8�9�9�!�B�$�?�$� � � � � � �O�O�H�$�u�T�=M�7N�7N�2O�2O�PQ�RT�PT�2U�O� V� V� V�������"�0�[� �� :� �N�N� � � � ���(�(���9�9�I�D�#��y�!�!� $� $�A���)�C�� %� �3�J���)=�)=�=��C� �'�1��&�*;���� ��$�$�X�G�$�D�D�D��#�#�%�%�%��#�#�%�%�%�� � ��#���B�G�4D�4D�Y�4O�4O� �P�P�P���� � � � �$� � � � �[�#�;� � G� G� G�� $��"�"�8�,�,�,��#�#�%�%�%��!�!�#�#�#��� � �h�����������rHc�P�|�tdd��||vr||}d|z}nd|z}t�|��||vrdSt|��}t ��}t |d��rd|d<ddlm} |j| krd |d <|j |fi|��|� ��|d kr|� |||� ��n|� ||��|� |��|� ��|� ��dS) NrrzDumping '%s' table...zNo '%s' table found.�ERRORzdecompilation errorr�� DefaultTableTrt�glyfr|) r �log�infor��dictr2�tables.DefaultTabler�� __class__r�r��toXMLr�) r9rhrjrr}�table�report�xmlTag�attrsr�s rAr�zTTFont._tableToXMLjsR�� � � �g�'B� C� C� C� �$�;�;���I�E�,�s�2�F�F�+�c�1�F� ������� �d�?�?� �F��#�������� �5�'� "� "� 3�2�E�'�N�5�5�5�5�5�5� �?�l� *� *��E�%�L�����(�(�%�(�(�(������� �&�=�=� �K�K���+�K� >� >� >� >� �K�K��� %� %� %�� � �f�����������������rHc���|�tdd��d|vrd|vr|���ddlm}|�||��}|���dS)z_Import a TTX file (an XML-based text format), so as to recreate a font object. Nrr�maxp�postr)� xmlReader)r � getGlyphOrder�fontTools.miscr�� XMLReaderr)r9rqrr�r*s rA� importXMLzTTFont.importXML�sx�� � � �g�'B� C� C� C� �T�>�>�f��n�n� � � � � � �,�,�,�,�,�,��$�$�Z��6�6��� � � � � � � rHc��||jvS)zbReturn true if the table identified by ``tag`` has been decompiled and loaded into memory.�r)�r9rjs rA�isLoadedzTTFont.isLoaded�s���d�k�!�!rHc�h�|�|��rdS|jr ||jvrdS|dkrdSdS)z�Test 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.Tr`F)r�r*r�s rA�has_keyzTTFont.has_key�sM�� �=�=�� � � ��4� �[� �S�D�K�/�/��4� �L� � ��4��5rHc�<�t|j�����}|jrBt|j�����D]}||vr|�|���d|vr|�d��t |��}dg|zS)zSReturns the list of tables in the font, along with the ``GlyphOrder`` pseudo-table.r`)rSr)rTr*�appendra� sortedTagList)r9rT�keys rArTz TTFont.keys�s����D�K�$�$�&�&�'�'�� �;� %��D�K�,�,�.�.�/�/� %� %���d�?�?��K�K��$�$�$�� �4� � � �K�K� � %� %� %��T�"�"���~��$�$rHc��|���D]=}||}|� |jdu}|r&t|d��r|�|����>d|_dS)zEDecompile all the tables, even if a TTFont was opened in 'lazy' mode.NF�ensureDecompiled)�recurse)rTr&r2r�)r9r�rjr�s rAr�zTTFont.ensureDecompiled�sp���9�9�;�;� 8� 8�C���I�E����)�5�0��� 8�7�5�*<�=�=� 8��&�&�w�&�7�7�7���� � � rHc�^�tt|�������SrD)rbrSrTrFs rA�__len__zTTFont.__len__�s ���4�� � � � �$�$�%�%�%rHc���t|��}|j�|��}|�O|dkrt|��}||j|<n/|j�|�|��}nt d|z���|S)Nr`�'%s' table not found)rr)r$r`r*� _readTable�KeyError�r9rjr�s rA� __getitem__zTTFont.__getitem__�s~���#�h�h��� ����$�$�� �=��l�"�"�"�3����#(�� �C� � ���(�����,�,����5��;�<�<�<�� rHc��t�d|��|j|}|j� |j�||f��}|�|St |��}||��}||j|<t�d|�� |�||��n�#t$r�|j s�t� d|��ddl m }t��}tj|���||��}|���|_||j|<|�||��YnwxYw|j� ||j||f<|S)N�Reading '%s' table from diskzDecompiling '%s' tablez@An exception occurred during the decompilation of the '%s' tablerr�)r:)r��debugr*r8r$� getTableClassr)� decompile� Exceptionr.� exceptionr�r�rrL� print_excrWr�)r9rj�datar�� tableClassr�r:s rAr�zTTFont._readTable�s��� � � �0�#�6�6�6��{�3��� � � '��$�(�(�#�t��5�5�E�� �� �"�3�'�'� �� �3���� �� �C�� � � �*�C�0�0�0� (� �O�O�D�$� '� '� '� '��� (� (� (��-� �� �M�M�R�TW� � � � :� 9� 9� 9� 9� 9��:�:�D� � �T� *� *� *� *� �L��%�%�E��-�-�/�/�E�K�$�D�K�� � �O�O�D�$� '� '� '� '� '� (���� � � '�,1�D� �c�4�[� )�� s�B'�'BE�Ec�4�||jt|��<dSrD)r)rr�s rA� __setitem__zTTFont.__setitem__�s�� %�� �C��H�H���rHc��||vrtd|z���||jvr|j|=|jr||jvr |j|=dSdSdS)Nr�)r�r)r*r�s rA� __delitem__zTTFont.__delitem__�sl�� �d�?�?��1�C�7�8�8� 8� �$�+� � �� �C� � �;� !�3�$�+�-�-�� �C� � � � !� !�-�-rHc�8� ||S#t$r|cYSwxYw)zGReturns the table if it exists or (optionally) a default if it doesn't.)r�)r9rj�defaults rAr$z TTFont.gets5�� ���9� ��� � � ��N�N�N� ���s � � �c��||_t|d��r|`|�d��r|d�|��dSdS)zmSet the glyph order Args: glyphOrder ([str]): List of glyph names in order. �_reverseGlyphOrderDictr�N)� glyphOrderr2r�r�� setGlyphOrder)r9r�s rAr�zTTFont.setGlyphOrders`�� %��� �4�1� 2� 2� ,��+� �=�=�� � � 3� ��L� &� &�z� 2� 2� 2� 2� 2� 3� 3rHc��� |jS#t$rYnwxYwd|vr"|d}|���|_n�d|vr�|d���}|�|���nit |��|djkr/t �d��|���n||_n|���|jS)zDReturns a list of glyph names ordered by their position in the font.�CFF r�Nr�zMNot enough names found in the 'post' table, generating them from cmap instead)r��AttributeErrorr��_getGlyphNamesFromCmaprb� numGlyphsr��warning)r9�cffr�s rAr�zTTFont.getGlyphOrders��� ��?� "��� � � � �D� ���� �T�>�>��v�,�C�!�/�/�1�1�D�O�O� �t�^�^��f��3�3�5�5�J��!� �+�+�-�-�-�-��Z���4��<�#9�9�9� � � �c�����+�+�-�-�-�-�",���� � '� '� )� )� )���s � � �c�B�|�d��r|jd}|jd=nd}t|dj��}d�t |��D��}d|d<||_d|vr|d���}ni}i}t |��D]\}||}||vrN|�||��}|�|d��dzx} ||<| dkr d|| dz fz}|||<�]d|vr|jd=||_|r||jd<dSdSdS)N�cmapr�c��g|]}d|z��S�� glyph%.5drE)�.0r�s rA� <listcomp>z1TTFont._getGlyphNamesFromCmap.<locals>.<listcomp>Ts��@�@�@�!�k�A�o�@�@�@rHz.notdefrrz%s.alt%d) r�r)�intr�r�r��buildReversedMin�_makeGlyphNamer$) r9� cmapLoadingr�r�� reversecmap�useCountr��tempName� glyphName�numUsess rAr�zTTFont._getGlyphNamesFromCmap7s}�� �=�=�� � � ��+�f�-�K�� �F�#�#��K���V� �.�/�/� �@�@�u�Y�/?�/?�@�@�@� �!� �1� �%��� �T�>�>��v�,�7�7�9�9�K�K��K����y�!�!� *� *�A�!�!�}�H��;�&�&�!�/�/� �H�0E�F�F� �08� � �Y��0J�0J�Q�0N�N��(�9�-��Q�;�;� *�i��1��-E� E�I� )� �1� �� �T�>�>�� �F�#�(�D�O�� 2�'2�� �F�#�#�#� �>�  2� 2rHc�Z�ddlm}||jvr |j|S|dkrd|zSd|zS)Nr)�agli��zuni%04Xzu%X)r�r��UV2AGL)� codepointr�s rAr�zTTFont._makeGlyphNameysO��!�!�!�!�!�!� �� � "� "��:�i�(� (� �&� � ��y�(� (��9�$� $rHc�H�t|�����}|S)z1Get a list of glyph names, sorted alphabetically.)�sortedr�)r9� glyphNamess rA� getGlyphNameszTTFont.getGlyphNames�s!���D�.�.�0�0�1�1� ��rHc�\�ddlm}|�|�����S)zZGet a list of glyph names, sorted alphabetically, but not case sensitive. r)� textTools)r�r�� caselessSortr�)r9r�s rA�getGlyphNames2zTTFont.getGlyphNames2�s6�� -�,�,�,�,�,��%�%�d�&8�&8�&:�&:�;�;�;rHc�b� |���|S#t$rd|zcYSwxYw)z�Returns 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)r9�glyphIDs rA� getGlyphNamezTTFont.getGlyphName�sJ��  )��%�%�'�'��0� 0��� )� )� )���(� (� (� (� )���s ��.�.c�j���|����t������fd�|D��S)z8Converts a list of glyph IDs into a list of glyph names.c�6��g|]}|�kr�|nd|z��Sr�rE)r��gid�cntr�s ��rAr�z+TTFont.getGlyphNameMany.<locals>.<listcomp>�s.���S�S�S��3��9�9� �3���+��2C�S�S�SrH)r�rb)r9�lstrr�s @@rA�getGlyphNameManyzTTFont.getGlyphNameMany�s=�����'�'�)�)� ��*�o�o��S�S�S�S�S�s�S�S�S�SrHc��� |���|S#t$rN|dd�dkr> t|dd���cYS#ttf$rt|���wxYw�wxYw)z0Returns the ID of the glyph with the given name.N��glyph)�getReverseGlyphMapr�r�� NameError� ValueError)r9r�s rA� getGlyphIDzTTFont.getGlyphID�s��� ��*�*�,�,�Y�7� 7��� � � ���!��}��'�'�.��y����}�-�-�-�-�-��!�:�.�.�.�.�"�9�-�-�-�.���� �  ���s ��A4�A� A4�!A/�/A4c����|���� �fd�|D��S#t$r|j��fd�|D��cYSwxYw)z8Converts a list of glyph names into a list of glyph IDs.c� ��g|] }�|�� SrErE)r�r��ds �rAr�z)TTFont.getGlyphIDMany.<locals>.<listcomp>�s���6�6�6�Y�A�i�L�6�6�6rHc�&��g|] }�|����SrErE)r�r�r s �rAr�z)TTFont.getGlyphIDMany.<locals>.<listcomp>�s#���?�?�?�i�J�J�y�)�)�?�?�?rH)rr�r )r9rrr s @@rA�getGlyphIDManyzTTFont.getGlyphIDMany�s{���� � #� #� %� %�� @�6�6�6�6�#�6�6�6� 6��� @� @� @���J�?�?�?�?�3�?�?�?� ?� ?� ?� @���s� &�A�Ac�\�|st|d��s|���|jS)z.Returns a mapping of glyph names to glyph IDs.r�)r2�_buildReverseGlyphOrderDictr�)r9�rebuilds rArzTTFont.getReverseGlyphMap�s7�� � /�'�$�(@�A�A� /� � ,� ,� .� .� .��*�*rHc�p�ix|_}t|�����D] \}}|||<� |SrD)r�� enumerater�)r9rr�r�s rArz"TTFont._buildReverseGlyphOrderDict�sG��*,�,��#�a�"+�D�,>�,>�,@�,@�"A�"A� #� #� �G�Y�"�A�i�L�L��rHc�6�||vrdSt|��}|jD]8}||vr2||vr|�||||���#|�|���9|�|��|�|��}|�Y|�t |��|f��}|�3t�d|��|� ||��dSt�d|��|||<|�|||t |��|f<dSdS)zcInternal helper function for self.save(). Keeps track of inter-table dependencies. Nzreusing '%s' tablezWriting '%s' table to disk) r�� dependenciesrcr�� getTableDatar$rr�r��setEntry) r9rjrhrirer�� masterTable� tabledata�entrys rArczTTFont._writeTable�s=�� �$�;�;� �F�"�3�'�'� �%�2� -� -�K��$�&�&��$�&�&��$�$�[�&�$� �K�K�K�K��K�K� �,�,�,�� � � �C�����%�%�c�*�*� � � !��N�N�C��H�H�i�#8�9�9�E�� �� � �.��4�4�4�����U�+�+�+��� � � �.��4�4�4���s� � � !�06�s� �J��C���)�,� -� -� -� "� !rHc�N�t|��}|�|��r;t�d|��|j|�|��S|jr1||jvr(t�d|��|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�)rr�r�r�r)�compiler*r�r�s rArzTTFont.getTableData�s����#�h�h�� �=�=�� � � � �I�I�,�c� 2� 2� 2��;�s�#�+�+�D�1�1� 1� �[� �S�D�K�/�/� �I�I�4�c� :� :� :��;�s�#� #��3�-�-� rHc��|rd|vrd}|r|s|�|��}d}d|vsd|vr|sd|vrt||��}n&d|vrt|||���}ntd���d|vrt |||��}|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. �fvarNr��CFF2r�)� recalcBoundszFont contains no outlines�VARC)�normalizeLocationr r r r)r9� preferCFF�location� normalizedr"�glyphSets rA� getGlyphSetzTTFont.getGlyphSet�s���4 � ��d�*�*��H� � 8�J� 8��-�-�h�7�7�H��� �d�N�N�f��n�n�9�n��d�@R�@R�%�d�H�5�5�H�H� �t�^�^�&�t�X�L�Q�Q�Q�H�H��8�9�9� 9� �T�>�>�&�t�X�x�@�@�H��rHc���ddlm}d|vrtd���|d���}|||��}d|vr|d�||��}|S)a�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 zNot a variable font�avar)�fontTools.varLib.modelsr$r �getAxes�renormalizeLocation)r9r&r$�axess rAr$zTTFont.normalizeLocations~�� >�=�=�=�=�=� �� � ��2�3�3� 3��F�|�#�#�%�%��$�$�X�t�4�4�� �T�>�>��F�|�7�7��$�G�G�H��rH�)�� )r�)r�)r1r)rr1)rrx)rr)rrc�:�|d�|���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)r9r6s rAr7zTTFont.getBestCmap,s ��F�F�|�'�'��'�H�H�HrHc�*�ddlm}|||��dS)Nr�� reorderGlyphsr9)r9�new_glyph_orderr:s rAr:zTTFont.reorderGlyphsQs,��0�0�0�0�0�0�� �d�O�,�,�,�,�,rH)TrD)rk)TNNNFFTrt�NF)F)TNFT)r0)-�__name__� __module__� __qualname__�__doc__�NotImplementedrBrGrMr7r]rRrsrpr�r�r�r�� __contains__rTr�r�r�r�r�r�r$r�r�r�� staticmethodr�r�r�r�rr rrrrcrr)r$r7r:rErHrArrs!������Q�Q�j��&������#��� ��� �!V1�V1�V1�V1�p������ � � � /�/�/�/�b'�'�'�'�2 � � � � ������ $�#�D�D�D�D�L����:����&"�"�"� � � ��L� %� %� %�����&�&�&� � � ����@&�&�&�!�!�!����� 3� 3� 3�!�!�!�F@2�@2�@2�D�%�%��\�%���� <�<�<� )� )� )�T�T�T� � � �@�@�@�+�+�+�+� ��� <�<�<�<�4 � � �$MQ�'�'�'�'�R���.  �#I�#I�#I�#I�J-�-�-�-�-rHrc�&�eZdZdZdd�Zd�Zd�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. Nc��dSrDrEr�s rArBzGlyphOrder.__init__\s�� �rHc�&�|���}|�d��|���tt |����D]6}||}|�d||���|����7dS)NzAThe 'id' attribute is only for humans; it is ignored when parsed.�GlyphID)�idr!)r��commentr�r�rbr�)r9rhryr�r�r�s rAr�zGlyphOrder.toXML_s����)�)�+�+� ���� R� � � � �������s�:���'�'� � �A�"�1� �I� � � �Y�1�9� � =� =� =� �N�N� � � � � � rHc��t|d��sg|_|dkr |j�|d��|�|j��dS)Nr�rGr!)r2r�r�r�)r9r!r��contentrys rA�fromXMLzGlyphOrder.fromXMLjs\���t�\�*�*� !� �D�O� �9� � � �O� "� "�5��=� 1� 1� 1����T�_�-�-�-�-�-rHrD)r=r>r?r@rBr�rLrErHrAr`r`WsP�������� � � � � � � �.�.�.�.�.rHr`c���ddlm}t|��} td|z��t ||��S#t $r3}t |���|��dkrYd}~dS|�d}~wwxYw)z[Fetch the packer/unpacker module for a table. Return None when no module is found. rr�zfontTools.ttLib.tables.rN)r3r)r�� __import__�getattr� ImportError�str�find)rjr)�pyTag�errs rA�getTableModulerUrs��������� �C� � �E� &��,�u�4�5�5�5��v�u�%�%�%�� ���� �s�8�8�=�=�� � �1� $� $��4�4�4�4�4��I��������s�9� A6�&A1�/A1�1A6c�F�|�dt|��z}||ft|<dS)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` N�table_)r��_customTableRegistry)rj� moduleName� classNames rA�registerCustomTableClassr[�s2������s�3�3�3� �!+�Y� 7�����rHc��t|=dS)z8Unregister the custom packer/unpacker class for a table.N)rX�rjs rA�unregisterCustomTableClassr^�s���S�!�!�!rHc��|tvrdSddl}t|\}}|�|��}t||��S)zReturn the custom table class for tag, if one has been registered with 'registerCustomTableClass()'. Else return None. Nr)rX� importlib� import_modulerO)rjr`rYrZ�modules rA�getCustomTableClassrc�sS�� �&�&�&��t�����0��5��J� � � $� $�Z� 0� 0�F� �6�9� %� %�%rHc��t|��}|�|St|��}|�ddlm}|St |��}t |d|z��}|S)z,Fetch the packer/unpacker class for a table.Nrr�rW)rcrUr�r�r�rO)rjr�rbr�rSs rAr�r��sl��$�S�)�)�J����� �C� � �F� �~�5�5�5�5�5�5��� �C� � �E����E�!1�2�2�J� �rHc�b�|j}|dd�dksJ�|dd�}t|��S)z'Fetch the table tag for a class object.Nr3rW)r=�identifierToTag)�klassr!s rA� getClassTagrh�s=�� �>�D� ����8�x� � � � � ����8�D� �4� � � rHc�6�t|��}||��S)z!Return a new instance of a table.)r�)rjr�s rA�newTablerj�s���s�#�#�J� �:�c�?�?�rHc��ddl}|�d|��rd|zS|�d|��r|dzStt|����dd�S)z%Helper function for tagToIdentifier()rNz[a-z0-9]�_z[A-Z]rx)�re�match�hexr)�crms rA� _escapecharrq�sd�� �I�I�I� �x�x� �A���#��Q�w�� ���'�1� � �#��3�w���7�1�:�:���q�r�r�"�"rHc�n�ddl}t|��}|dkr|St|��dks Jd���t|��dkr5|ddkr)|dd�}t|��dkr |ddk�)d }|D]}|t|��z}�|�d |��rd |z}|S) 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' rNr`r4ztag should be 4 characters longrr� r3z[0-9]rl)rmrrbrqrn)rjrm�identrps rAr�r��s���&�I�I�I� �c�(�(�C� �l���� � �s�8�8�q�=�=�=�;�=�=�=� �c�(�(�Q�,�,�3�r�7�c�>�>��#�2�#�h�� �c�(�(�Q�,�,�3�r�7�c�>�>� �E� �'�'��� �A���&��� �x�x�������e� �� �LrHc ���|dkr|St|��dzr|ddkr |dd�}t|��dzrJ�d}tdt|��d��D]c}||dkr|||dzz}�||dzdkr |||z}�8|tt|||dz�d����z}�d|d t|��z d zz}t |��S) z!the opposite of tagToIdentifier()r`rxrrlrNr3�r4rs)rbr��chrr�r)rtrjr�s rArfrf�s �� � ���� � �5�z�z�A�~��%��(�c�/�/��a�b�b� ���E� � �Q���� � �C� �1�c�%�j�j�!� $� $�7�7�� ��8�s�?�?���a�!�e� �$�C�C� �1�q�5�\�S� � ���a��.�C�C���C��a�!�a�%�i� 0�"�5�5�6�6�6�C�C� ��S��X�X���$� $�C� �s�8�8�OrHc��ddl}t|��}|dkrdS|dkr|S|�d|��r|���St |��S)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. rN�OS/2�OS_2r`z[A-Za-z_][A-Za-z_0-9]* *$)rmrrn�stripr�)rjrms rAr�r�si�� �I�I�I� �c�(�(�C� �f�}�}��v� � � � �� � �x�x�+�S�1�1�$��y�y�{�{���s�#�#�#rHc��|dkrtd��St|��dkrt|��St|ddt|��z zz��S)zThe opposite of tagToXML()rzry�rsr4)rrbrfr]s rA�xmlToTagr~"sV�� �f�}�}��6�{�{�� �3�x�x�1�}�}��s�#�#�#��3���C��H�H� �-�-�.�.�.rH)r_�hhear�ry�hmtx�LTSH�VDMX�hdmxr��fpgm�prepzcvt �locar��kernr!r��gasp�PCLT)r_rr�ryr!r�r�r�c�>�t|��}|�Ad|vr*|�d��|�d��d|vrt}nt}g}|D]0}||vr*|�|��|�|���1|�|��|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. N�DSIGr�)r�rar�� OTFTableOrder� TTFTableOrder�extend)�tagListr[� orderedTablesrjs rAr�r�Fs��� �W�o�o�G��� �W� � � �N�N�6� "� "� "� �N�N�6� "� "� "� �W� � �&�J�J�&�J��M�� � �� �'�>�>� � � �� %� %� %� �N�N�3� � � ������!�!�!� �rHFc��|�d��|�d��t||���}t|t|j��|j|j|j��}t|� ����}t||��D] }||||<�|� ��dS)zcRewrite a font file, ordering the tables as recommended by the OpenType specification 1.4. r)r<N) r rrrbr)r/r0r1rSrTr�r7)�inFile�outFiler[r<r*rhr)rjs rArVrV^s��� �K�K��N�N�N� �L�L��O�O�O� ��~� >� >� >�F� �� �F�M������ ��� ��F��&�+�+�-�-� � �F��V�Z�0�0�"�"���S�k��s� � � �L�L�N�N�N�N�NrHc�H�d}|r |dz }|dz}|� t|dz d��S)z_Return the highest exponent of two, so that (2 ** exponent) <= x. Return 0 if x is 0. rr)�max)�x�exponents rA� maxPowerOfTwor�rsC���H� � � ��F���a�<�� � � �x�!�|�Q� � �rHrvc�j�t|��}d|z|z}|}td||z|z ��}|||fS)z1Calculate searchRange, entrySelector, rangeShift.rxr)r�r�)�n�itemSizer�� searchRange� entrySelector� rangeShifts rA�getSearchRanger�}sI���Q���H��h�;�(�*�K��M��Q��H� �{�2�3�3�J� � �z� 1�1rHrDr<)rv)6�fontTools.configrr�r�fontTools.misc.configToolsr�fontTools.misc.textToolsrrr�fontTools.misc.loggingToolsr �fontTools.ttLibr �fontTools.ttLib.ttGlyphSetr r r r�fontTools.ttLib.sfntrr�iorrrr��loggingrL� getLoggerr=r��objectrr`rUrXr[r^rcr�rhrjrqr�rfr�r~r�r�r�rVr�r�rErHrA�<module>r�s���#�#�#�#�#�#�$�$�$�$�$�$�5�5�5�5�5�5�8�8�8�8�8�8�8�8�8�8�9�9�9�9�9�9�&�&�&�&�&�&������������� 8�7�7�7�7�7�7�7�6�6�6�6�6�6�6�6�6�6� � � � ����������g���!�!��~ -�~ -�~ -�~ -�~ -�V�~ -�~ -�~ -�B.�.�.�.�.��.�.�.�6&�&�&�2�� 8� 8� 8� 8�"�"�"� &� &� &� � � �!�!�!���� #� #� #� � � �F���*$�$�$�$/�/�/���� �,Q�P�P� �����0����( � � �2�2�2�2�2�2rH
Memory