U
    »mœd•¾ ã                ‡  @   sæ  d Z ddlmZ ddlmZ ddlmZmZ ddlmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlZddlZddlZejd Ze e¡ZdZdZ G dd„ de!ƒZ"G dd„ dej#ƒZ$G dd„ de%ƒZ&G dd„ de%ƒZ'dd„ Z(G dd„ de%ƒZ)G dd„ de)ƒZ*G dd„ de)ƒZ+G dd „ d e)ƒZ,G d!d"„ d"e)ƒZ-G d#d$„ d$e-ƒZ.G d%d&„ d&e-ƒZ/G d'd(„ d(e%ƒZ0G d)d*„ d*e0ƒZ1G d+d,„ d,e1ƒZ2G d-d.„ d.e0ƒZ3G d/d0„ d0e0ƒZ4G d1d2„ d2e%ƒZ5G d3d4„ d4e%ƒZ6G d5d6„ d6e%ƒZ7d7d8„ Z8d9d:„ Z9d;d<„ Z:d=d>„ Z;d?d@„ Z<dAdB„ Z=dCdD„ Z>dEdF„ Z?dGdH„ Z@dIdJ„ ZAdKdL„ ZBdMdN„ ZCdOdP„ ZDdQdR„ ZEG dSdT„ dTe%ƒZFG dUdV„ dVeFƒZGG dWdX„ dXeFƒZHdYdZ„ ZId[d\„ ZJG d]d^„ d^eFƒZKG d_d`„ d`eFƒZLG dadb„ dbeFƒZMG dcdd„ ddeMƒZNG dedf„ dfeMƒZOG dgdh„ dheMƒZPG didj„ djeFƒZQG dkdl„ dle%ƒZRdmdn„ ZSdodp„ ZTdqdr„ ZUdsdt„ ZVdudv„ ZWdwdx„ ZXdydz„ ZYG d{d|„ d|e%ƒZZG d}d~„ d~eFƒZ[dd€„ Z\d�d‚„ Z]dƒd„„ Z^d…d†„ Z_G d‡dˆ„ dˆeMƒZ`G d‰dŠ„ dŠeFƒZaG d‹dŒ„ dŒeFƒZbd�dŽ„ Zcd�d�„ Zdd‘d’„ ZeG d“d”„ d”e%ƒZfG d•d–„ d–e%ƒZgG d—d˜„ d˜eFƒZhd™dšd›dœdehƒ fd�džddŸd deHƒ fd¡d¢d deHƒ fd£d¤d¥d¦d§d¨d©dªd«d¬d­d®d¯d°ddd°ddgdfd±d²d³d¯ddddgdfd´dµd¶d·d¸d¹dºd»d¼d½d¾d¿deQƒ fdÀdÁdÂd¿de[ƒ fdÃdÄdÅdeNƒ fdÆd4d¿deaƒ fdÇdÈd¿de`ƒ fdÉd6d¿dePƒ fdÊdËd¿debƒ fg$Zid™d­d®d¯d°ddd°ddgdfdÆd4d¿deaƒ fdÇdÈd¿de`ƒ fdÉd6d¿dePƒ fdÊdËd¿debƒ fgZjdÌZkdÍZldÎelekdÏddfdÐdÑdÒdÓdÔdÕdÖd×dØdÙdÚdÛdÜdÝdÞdßdàdádâdãdäd¿deOƒ fgZmdÎelekdÏddfdÐdÑdÒdÓdÔdÕdÖd×dØdÙdÚdÞdßdãdäd¿deOƒ fgZndådæ„ Zoeoemƒ eoeiƒ G dçdè„ dèejpƒZqG dédê„ dêejpƒZrG dëdì„ dìe%ƒZsdídî„ ZtG dïdð„ dðesƒZuG dñdò„ dòesƒZvG dódô„ dôesƒZwG dõdö„ döe%ƒZxG d÷dø„ døexƒZyG dùdú„ dúexƒZzG dûdü„ düexƒZ{G dýdþ„ dþe%ƒZ|dÿ�d �d�d�d�d�d�d�d�d�d	�d
�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d �d!�d"�d#�d$�d%�d&�d'�d(�d)�d*�d+�d,�d-�d.�d/�d0�d1�d2�d3�d4�d5�d6�d7�d8�d9�d:�d;�d<�d=�d>�d?�d@�dA�dB�dC�dD�dE�dF�dG�dH�dI�dJ�dK�dL�dM�dN�dO�dP�dQ�dR�dS�dT�dU�dV�dW�dX�dY�dZ�d[�d\�d]�d^�d_�d`�da�db�dc�dd�de�df�dg�dh�di�dj�dk�dl�dm�dn�do�dp�dq�dr�ds�dt�du�dv�dw�dx�dy�dz�d{�d|�d}�d~�d�d€�d��d‚�dƒ�d„�d…�d†�d‡�dˆ�d‰�dŠ�d‹�dŒ�d��dŽ�d��d��d‘�d’�d“�d”�d•�d–�d—�d˜�d™�dš�d›�dœ�d��dž�dŸ�d �d¡�d¢�d£�d¤�d¥�d¦�d§�d¨�d©�dª�d«�d¬�d­�d®�d¯�d°�d±�d²�d³�d´�dµ�d¶�d·�d¸�d¹�dº�d»�d¼�d½�d¾�d¿�dÀ�dÁ�dÂ�dÃ�dÄ�dÅ�dÆ�dÇ�dÈ�dÉ�dÊ�dË�dÌ�dÍ�dÎ�dÏ�dÐ�dÑ�dÒ�dÓ�dÔ�dÕ�dÖ�d×�dØ�dÙ�dÚ�dÛ�dÜ�dÝ�dÞ�dß�dà�dá�dâ�dã�dä�då�dæ�dç�dè�dé�dê�dë�dì�dí�dî�dï�dð�dñ�dò�dó�dô�dõ�dö�d÷�dø�dù�dú�dû�dü�dý�dþ�dÿ�d �d�d�d�d�d�d�d�d�d	�d
�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d �d!�d"�d#�d$�d%�d&�d'�d(�d)�d*�d+�d,�d-�d.�d/�d0�d1�d2�d3�d4�d5�d6�d7�d8�d9�d:�d;�d<�d=�d>�d?�d@�dA�dB�dC�dD�dE�dF�dG�dH�dI�dJ�dK�dL�dM�dN�dO�dP�dQ�dR�dS�dT�dU�dV�dW�dX�dY�dZ�d[�d\�d]�d^�d_�d`�da�db�dc�dd�de�df�dg�dh�di�dj�dk�dl�dm�dn�do�dp�dq�dr�ds�dt�du�dv�dw�dx�dy�dz�d{�d|�d}�d~�d�d€�d��d‚�dƒ�d„�d…�g‡Z}�d†Z~ee}ƒe~k�sìt€‚i Z�e‚e~ƒD ]Zƒeƒe�e}eƒ < �qødÿ�d �d�d�d�d�d�d�d�d�d	�d
�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d �d!�d"�d#�d$�d%�d&�d'�d(�d)�d*�d+�d,�d-�d.�d/�d0�d1�d2�d3�d4�d5�d6�d7�d8�d9�d:�d;�d<�d=�d>�d?�d@�dA�dB�dC�dD�dE�dF�dG�dH�dI�dJ�dK�dL�dM�dN�dO�dP�dQ�dR�dS�dT�dU�dV�dW�dX�dY�dZ�d[�d\�d]�d^�d_�d`�da�db�dc�dd�de�df�dg�dh�di�dj�dk�dl�dm�dn�do�dp�dq�dr�ds�dt�du�dv�dw�dx�dy�dz�d{�d|�d}�d~�d�d€�d��d‚�dƒ�d„�d…�d†�d‡�dˆ�d‰�dŠ�d‹�dŒ�d��dŽ�d��d��d‘�d’�d“�d”�d•�d–�d—�d˜�d™�dš�d›�dœ�d��dž�dŸ�d �d¡�d¢�d£�d¤�d¥�d¦�d§�d¨�d©�dª�d«�d¬�d­�d®�d¯�d°�d±�d²�d³�d´�dµ�d¶�d·�d¸�d¹�dº�d»�d¼�d½�d¾�d¿�dÀ�dÁ�dÂ�dÃ�dÄ�dÅ�dÆ�dÇ�dÈ�dÉ�dÊ�dË�dÌ�dÍ�dÎ�dÏ�dÐ�dÑ�dÒ�dÓ�dÔ�dÕ�dÖ�d×�dØ�dÙ�dÚ�dÛ�dÜ�dÝ�dÞ�dß�dà�dá�dâ�dãgåZ„�d‡Z…ee„ƒe…k�sºt€‚dÿ�d �dä�då�dæ�dç�dè�dé�dê�dë�dì�dí�d�d�d�db�dî�dï�dð�dñ�dò�dó�dô�dõ�dö�d÷�d�d�dø�dù�dú�dû�dü�dý�dþ�dÿ�d �d�d�d�d�d�d�d�d�d	�dl�dm�d
�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d �d!�d"�d#�d$�d%�d&�d'�d(�d)�d*�d+�d,�d-�d.�d/�d0�d1�d2�d3�d4�d5�d6�d7�d8�d9�d:�d;�d<�d=�d��dš�d¢�d>�d?�d@�dA�dB�dC�dD�dE�d•�d£�d¨�dF�dG�dH�dI�dJ�dK�dL�dM�dN�dO�dP�dQ�dR�dS�dT�dU�dV�dW�dX�dY�dZ�d[�d\�d]�d^�d_�d`�da�db�dc�dd�de�df�dg�dh�di�dj�dk�dl�dm�dn�do�dp�dq�dr�ds�dt�du�dv�dw�dx�dyg¦Z†�dˆZ‡ee†ƒe‡k�slt€‚dÿ�d �dæ�dç�dê�dë�dì�dí�d�d�d�db�dî�dï�dð�dñ�dò�dó�dô�dõ�dö�d÷�d�d�dø�dù�dú�dü�dý�dþ�dÿ�d �d�d�d�d�d�d�d�d�d	�dl�dm�d
�d�d�d�d�d+�d,�d-�d0�d9�d:�d��dš�d¢�d?�d@�dA�dB�dC�dD�dE�d•�d£�d¨�dF�dG�dH�dI�dJ�dK�dL�dM�dN�dO�dP�dQ�dR�dS�dT�dU�dV�dW�dX�dYgWZˆ�d‰Z‰eeˆƒe‰k�sât€‚dS (Š  a+  cffLib: read/write Adobe CFF fonts

OpenType fonts with PostScript outlines contain a completely independent
font file, Adobe's *Compact Font Format*. So dealing with OpenType fonts
requires also dealing with CFF. This module allows you to read and write
fonts written in the CFF format.

In 2016, OpenType 1.8 introduced the `CFF2 <https://docs.microsoft.com/en-us/typography/opentype/spec/cff2>`_
format which, along with other changes, extended the CFF format to deal with
the demands of variable fonts. This module parses both original CFF and CFF2.

é    )Ússtruct)ÚpsCharStrings)Ú	unionRectÚintRect)ÚbytechrÚbyteordÚ	bytesjoinÚtobytesÚtostrÚsafeEval)ÚTTFont)ÚOTTableWriter)ÚOTTableReader)ÚotTables)ÚBytesIONé   z%
	major:   B
	minor:   B
	hdrSize: B
i  c                   @   s   e Zd ZdS )ÚStopHintCountEventN)Ú__name__Ú
__module__Ú__qualname__© r   r   úR/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/fontTools/cffLib/__init__.pyr   0   s   r   c                   @   sJ   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )Ú_DesubroutinizingT2Decompiler)Úop_hintmaskZop_cntrmaskZ
op_rmovetoZ
op_hmovetoZ
op_vmovetoNc                 C   s   t j | |||¡ d S ©N)r   ÚSimpleT2DecompilerÚ__init__)ÚselfÚ
localSubrsÚglobalSubrsÚprivater   r   r   r   =   s       ÿz&_DesubroutinizingT2Decompiler.__init__c                 C   sh  d| _ | jD ]}t| || jƒ qt|dƒrj| j rf| jrfztj | |¡ W n t	k
rd   | jd= Y nX d S g |_
tj | |¡ |jd d … }t|j
ƒD ]t\}}|dksªt‚||d  dksÊt||d  ƒ‚t||d  ƒtksât‚|d dkrú|d d… }|||d |…< q–| jj�sZd|k�r8|d | d¡d … }n"t|ƒ�rP|d dk�rZ| d¡ ||_|`
d S )	NTÚ_desubroutinizedéÿÿÿÿé   r   )ZcallsubrZ	callgsubrÚreturnÚendchar)Úneed_hintcountÚstop_hintcount_opsÚsetattrÚstop_hint_countÚhasattrÚcallingStackr   r   Úexecuter   Ú_patchesÚprogramÚreversedÚAssertionErrorÚtypeÚintr    Úin_cff2ÚindexÚlenÚappendr!   )r   Ú
charStringÚop_nameZdesubroutinizedÚidxZ	expansionr   r   r   r,   B   s>    


ý

ÿ
z%_DesubroutinizingT2Decompiler.executec                 C   s4   | j | jd | j  }tj | |¡ |  ||¡ d S ©Nr"   )r   ÚoperandStackZ	localBiasr   r   Úop_callsubrÚprocessSubr©r   r4   Úsubrr   r   r   r<   m   s    z)_DesubroutinizingT2Decompiler.op_callsubrc                 C   s4   | j | jd | j  }tj | |¡ |  ||¡ d S r:   )r   r;   Z
globalBiasr   r   Úop_callgsubrr=   r>   r   r   r   r@   r   s    z*_DesubroutinizingT2Decompiler.op_callgsubrc                 G   s<   d| _ | jD ]}t| |d ƒ q| jd }t|dƒr8tƒ ‚d S )NFr"   r!   )r&   r'   r(   r+   r*   r   )r   Úargsr8   Úcsr   r   r   r)   w   s    


z-_DesubroutinizingT2Decompiler.stop_hint_countc                 C   s    t j | |¡ | jr|  ¡  d S r   )r   r   r   r&   r)   ©r   r4   r   r   r   r      s    z)_DesubroutinizingT2Decompiler.op_hintmaskc                 C   s*   | j d }t|dƒs&|j ||jf¡ d S )Nr"   r!   )r+   r*   r-   r6   r!   )r   r4   r?   rB   r   r   r   r=   „   s    

z)_DesubroutinizingT2Decompiler.processSubr)N)r   r   r   r'   r   r,   r<   r@   r)   r   r=   r   r   r   r   r   4   s   
+r   c                   @   sf   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zddd„Z	dd„ Z
ddd„Zdd„ Zdd„ ZdS )Ú
CFFFontSetan  A CFF font "file" can contain more than one font, although this is
    extremely rare (and not allowed within OpenType fonts).

    This class is the entry point for parsing a CFF table. To actually
    manipulate the data inside the CFF font, you will want to access the
    ``CFFFontSet``'s :class:`TopDict` object. To do this, a ``CFFFontSet``
    object can either be treated as a dictionary (with appropriate
    ``keys()`` and ``values()`` methods) mapping font names to :class:`TopDict`
    objects, or as a list.

    .. code:: python

            from fontTools import ttLib
            tt = ttLib.TTFont("Tests/cffLib/data/LinLibertine_RBI.otf")
            tt["CFF "].cff
            # <fontTools.cffLib.CFFFontSet object at 0x101e24c90>
            tt["CFF "].cff[0] # Here's your actual font data
            # <fontTools.cffLib.TopDict object at 0x1020f1fd0>

    Nc                 C   s8  || _ t t| d¡| ¡ |dk	rL|r*dnd}| j|krhtd|| jf ƒ‚n| jdks^tdƒ‚| jdk}|sÆt d| d¡¡d	 | _	| 
| j¡ td
d„ t||d�D ƒƒ| _t||d�| _t|ƒ| _nLt d| d¡¡d	 | _| 
| j¡ dg| _|j}t||| j|d�| _d| _t||d�| _| j| j_| j| j_dS )a‹  Parse a binary CFF file into an internal representation. ``file``
        should be a file handle object. ``otFont`` is the top-level
        :py:class:`fontTools.ttLib.ttFont.TTFont` object containing this CFF file.

        If ``isCFF2`` is passed and set to ``True`` or ``False``, then the
        library makes an assertion that the CFF header is of the appropriate
        version.
        é   Nr#   r   ú2Invalid CFF 'major' version: expected %d, found %d©r   r#   úUnknown CFF formatÚBr   c                 s   s   | ]}t |ƒV  qd S r   ©r
   ©Ú.0Úsr   r   r   Ú	<genexpr>¼   s     z'CFFFontSet.decompile.<locals>.<genexpr>©ÚisCFF2ú>HÚCFF2Font)ÚotFontr   ÚunpackÚcffHeaderFormatÚreadÚmajorÚ
ValueErrorr0   ÚstructÚoffSizeÚseekÚhdrSizeÚlistÚIndexÚ	fontNamesÚTopDictIndexÚtopDictIndexÚIndexedStringsÚstringsÚtopDictSizeÚgetGlyphOrderÚGlobalSubrsIndexÚGlobalSubrs)r   ÚfilerS   rP   Úexpected_majorÚcff2GetGlyphOrderr   r   r   Ú	decompile    s@    

ÿÿ
   ÿ
zCFFFontSet.decompilec                 C   s
   t | jƒS r   )r5   r_   ©r   r   r   r   Ú__len__Í   s    zCFFFontSet.__len__c                 C   s
   t | jƒS r   )r]   r_   rl   r   r   r   ÚkeysÐ   s    zCFFFontSet.keysc                 C   s   | j S r   )ra   rl   r   r   r   ÚvaluesÓ   s    zCFFFontSet.valuesc                 C   sd   t |dƒr| ¡ }nFt|tƒrR|}z| j |¡}W qZ tk
rN   t|ƒ‚Y qZX nt|ƒ‚| j	| S )z{Return TopDict instance identified by name (str) or index (int
        or any object that implements `__index__`).
        Ú	__index__)
r*   rp   Ú
isinstanceÚstrr_   r4   rX   ÚKeyErrorÚ	TypeErrorra   )r   ZnameOrIndexr4   Únamer   r   r   Ú__getitem__Ö   s    


zCFFFontSet.__getitem__c                 C   sÜ  || _ |dk	r8|rdnd}| j|krTtd|| jf ƒ‚n| jdksJtdƒ‚| jdk}|jrr|sr| jD ]}| ¡  qd|s~tƒ }nd}t|ƒ}| jj	|| |d�}|rØd| _
| t t| ¡¡ | ¡ | _| t d	| j¡¡ n2d
| _
d
| _| t t| ¡¡ | t d| j¡¡ |�sDtƒ }	| jD ]}
|	 |
¡ �q| |	j	|| |d�¡ | |¡ |�sb| | 	¡ ¡ | | jj	|| |d�¡ | jD ],}t|dƒ�rœ|jdk�r€| ¡ }||_�q€| |¡}|D ]}| |¡ �q¼| |¡ dS )a˜  Write the object back into binary representation onto the given file.
        ``file`` should be a file handle object. ``otFont`` is the top-level
        :py:class:`fontTools.ttLib.ttFont.TTFont` object containing this CFF file.

        If ``isCFF2`` is passed and set to ``True`` or ``False``, then the
        library makes an assertion that the CFF header is of the appropriate
        version.
        Nr#   r   rF   rG   rH   rO   é   rQ   é   rI   Úcharset)rS   rW   rX   r0   ZrecalcBBoxesra   ÚrecalcFontBBoxrb   Ú	CFFWriterÚgetCompilerr\   Úaddr   ÚpackrU   ÚgetDataLengthrd   rY   rZ   r^   r_   r6   rg   r*   ry   re   ÚgetChildrenÚtoFile)r   rh   rS   rP   ri   ÚtopDictrc   ÚwriterZtopCompilerr_   ru   ry   ÚchildrenÚchildr   r   r   Úcompileæ   sZ    	
ÿÿ









zCFFFontSet.compilec                 C   s¶   |j d| jd� | ¡  |j d| jd� | ¡  | jD ]B}|jdt|ƒd� | ¡  | | }| |¡ | d¡ | ¡  q6| ¡  | d¡ | ¡  | j	 |¡ | d¡ | ¡  dS )z÷Write the object into XML representation onto the given
        :class:`fontTools.misc.xmlWriter.XMLWriter`.

        .. code:: python

                writer = xmlWriter.XMLWriter(sys.stdout)
                tt["CFF "].cff.toXML(writer)

        rW   ©ÚvalueÚminorÚCFFFont©ru   rg   N)
Ú	simpletagrW   Únewliner‰   r_   Úbegintagr
   ÚtoXMLÚendtagrg   )r   Ú	xmlWriterÚfontNameÚfontr   r   r   r�   &  s"    





zCFFFontSet.toXMLc                 C   s8  || _ t| dƒsd| _t| dƒs&d| _|dk�r–| jdkr¬t| dƒsJd| _t| dƒsZd| _t| d	ƒsltƒ | _t| d
ƒs„g | _t	ƒ | _
|d }| j |¡ t| jd�}d|_nb| jdk�rt| dƒsÈd| _t| d	ƒsÚtƒ | _t| d
ƒsìdg| _| j j}t| j|d�}t	d|ƒ| _
| j
 |¡ |D ].}t|tƒ�r2�q|\}}}| |||¡ �qt|dƒ�r4|jd jdk�r4|j}	|	D ]}
t|
dƒ�rv|j|
j_�qvnž|d	k�rtj}t| d	ƒ�sºtƒ | _|D ]@}t|tƒ�rÒ�q¾|\}}}|ƒ }| |||¡ | j |¡ �q¾n2|dk�rt|d ƒ| _n|dk�r4t|d ƒ| _dS )z?Reads data from the XML element into the ``CFFFontSet`` object.rW   r   r‰   r   rŠ   rZ   rx   r\   rg   r_   ru   )rg   Nr#   rw   rR   )rg   rj   ÚVarStoreÚPrivaterˆ   )rS   r*   rW   r‰   rZ   r\   rf   rg   r_   r`   ra   r6   ÚTopDictry   re   rq   rr   ÚfromXMLÚFDArrayÚvstorer”   r•   r   ÚT2CharStringr2   )r   ru   ÚattrsÚcontentrS   r’   r‚   rj   ÚelementÚfdArrayÚfontDictZsubrCharStringClassr?   r   r   r   r—   C  sv    










 ÿ




zCFFFontSet.fromXMLc                 C   s8  d| _ | jj}td|ƒ}| jj|_|| _|d }t|dƒrB|j}nd}tt	ƒ}||_
||_tD ]:}|d }||kr^||jkr„|j|= t||ƒr^t||ƒ q^t|dƒ�sVtƒ  }	|_d|	_|j|	_|	|j_|j}
|
jrÞ|	|
j_n|	|
_tƒ }| d¡ |	 |¡ ||_ttƒ}tD ]B}|d }||k�r||jk�r:|j|= t||ƒ�rt||ƒ �qn®|j}	ttƒ}|	D ]š}| d¡ |j ¡ D ]0}||j
k�r€|j|= t||ƒ�r€t||ƒ �q€|j}tD ]B}|d }||k�r¼||jk�ræ|j|= t||ƒ�r¼t||ƒ �q¼�qhtƒ }| j||dd� | d¡ | j ||dd� dS )	z÷Converts this object from CFF format to CFF2 format. This conversion
        is done 'in-place'. The conversion cannot be reversed.

        This assumes a decompiled CFF table. (i.e. that the object has been
        filled via :meth:`decompile`.)r#   Nr   r•   r   r˜   TrO   )!rW   rS   re   r`   ra   Úitemsr*   r•   Ú
buildOrderÚtopDictOperators2Úorderrj   ÚtopDictOperatorsÚrawDictÚdelattrÚFDArrayIndexr˜   rc   rg   rž   ÚCharStringsÚcharStringsAreIndexedÚcharStringsIndexÚFontDictÚsetCFF2r6   ÚprivateDictOperators2ÚprivateDictOperatorsrn   r   r†   r[   rk   )r   rS   rj   ZtopDictDatar‚   ZprivateDictZopOrderÚentryÚkeyrž   ÚcharStringsrŸ   ZprivateOpOrderrh   r   r   r   ÚconvertCFFToCFF2‡  sz    











zCFFFontSet.convertCFFToCFF2c                 C   sâ   | j D ]Ì}| | }|j}|jD ]N}| |¡\}}| ¡  t|jdg ƒ}t||j|jƒ}| 	|¡ |j
|_|`
qt|dƒr¬|jD ]*}	|	j}
t|
dƒr–|
`d|
jkr~|
jd= q~q|j}
t|
dƒrÀ|
`d|
jkr|
jd= q| j ¡  d S )NÚSubrsr˜   )r_   r¨   ry   ÚgetItemAndSelectorrk   Úgetattrr    r   r   r,   r!   r.   r*   r˜   r•   r³   r¥   rg   Úclear)r   r’   r“   rB   ÚgÚcÚ_ZsubrsZ
decompilerÚfdÚpdr   r   r   Údesubroutinize×  s8    

  ÿ







zCFFFontSet.desubroutinize)N)N)N)r   r   r   Ú__doc__rk   rm   rn   ro   rv   r†   r�   r—   r²   r¼   r   r   r   r   rD   Š   s   
-
@
DPrD   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r{   zXHelper class for serializing CFF data to binary. Used by
    :meth:`CFFFontSet.compile`.c                 C   s   g | _ || _d S r   )ÚdatarP   ©r   rP   r   r   r   r   û  s    zCFFWriter.__init__c                 C   s   | j  |¡ d S r   )r¾   r6   )r   Útabler   r   r   r}   ÿ  s    zCFFWriter.addc           	      C   sR  d }d}t   td|¡ |d }d}|g}| jD ]f}t|dƒrd|| ¡  }t|tƒrp|jrp| ¡ | _n|t	|ƒ }t|dƒr†| 
||¡ |}| |¡ q.||kr q¦|}qt   td¡ | ¡ }| jrÖt d| j¡| jd< n"t|d ƒ| _t d	| j¡| jd< dg}| jD ]:}t|d
ƒ�r | |¡ n
| |¡ | | ¡ | ¡ �q||k�sNt‚d S )Nr   z CFFWriter.toFile() iteration: %dr   r   ÚsetPosz#CFFWriter.toFile() writing to file.rQ   r"   rI   r�   )ÚlogÚDEBUGr¾   r*   r   rq   ÚTopDictIndexCompilerrP   rd   r5   rÁ   r6   ÚtellrY   r~   ÚcalcOffSizerZ   r�   Úwriter0   )	r   rh   ZlastPosListÚcountÚposZposListÚitemÚendPosÚbeginr   r   r   r�     s@    




zCFFWriter.toFileN)r   r   r   r½   r   r}   r�   r   r   r   r   r{   ÷  s   r{   c                 C   s2   | dk rd}n | dk rd}n| dk r*d}nd}|S )Né   r   i   r#   i   rE   rx   r   )ZlargestOffsetrZ   r   r   r   rÆ   )  s    rÆ   c                   @   s:   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚIndexCompilerz…Base class for writing CFF `INDEX data <https://docs.microsoft.com/en-us/typography/opentype/spec/cff2#5-index-data>`_
    to binary.Nc                 C   sB   |d kr$t |dƒr$|j}|d k	s$t‚|| _|  ||¡| _|| _d S ©NrP   )r*   rP   r0   ÚgetItemsr    Úparent)r   r    rc   rÑ   rP   r   r   r   r   9  s    zIndexCompiler.__init__c                 C   s   |S r   r   ©r   r    rc   r   r   r   rÐ   A  s    zIndexCompiler.getItemsc                 C   sT   | j rLd}|g}| j D ]2}t|dƒr2|| ¡  }n|t|ƒ }| |¡ qng }|S )Nr   r   )r    r*   r   r5   r6   )r   rÉ   ÚoffsetsrÊ   r   r   r   Ú
getOffsetsD  s    

zIndexCompiler.getOffsetsc                 C   sV   | j rd}nd}| jrN|  ¡ d }t|ƒ}|d t| jƒd |  | d }n|}|S )Nrx   r#   r"   r   )rP   r    rÔ   rÆ   r5   )r   Z	countSizeZ
lastOffsetrZ   Ú
dataLengthr   r   r   r   S  s$    ÿþýüÿ	zIndexCompiler.getDataLengthc           	      C   sÌ   |   ¡ }| jr t|t| jƒƒ nt|t| jƒƒ | jrÈt|d ƒ}t||ƒ | }tj	}|D ]2}|d|ƒ|d … }t|ƒ| ks„t
‚| |¡ q\| jD ]0}t|dƒr°| |¡ q–t|dd�}| |¡ q–d S )Nr"   ú>lr�   Úlatin1©Úencoding)rÔ   rP   ÚwriteCard32r5   r    ÚwriteCard16rÆ   Ú
writeCard8rY   r~   r0   rÇ   r*   r�   r	   )	r   rh   rÓ   rZ   r~   ÚoffsetÚ	binOffsetrÊ   r¾   r   r   r   r�   i  s$    


zIndexCompiler.toFile)N)	r   r   r   r½   r   rÐ   rÔ   r   r�   r   r   r   r   rÎ   5  s   
rÎ   c                   @   s   e Zd Zdd„ ZdS )ÚIndexedStringsCompilerc                 C   s   |j S r   ©rc   rÒ   r   r   r   rÐ   ‚  s    zIndexedStringsCompiler.getItemsN)r   r   r   rÐ   r   r   r   r   rß   �  s   rß   c                       sH   e Zd ZdZdd„ Zdd„ Z‡ fdd„Z‡ fdd	„Z‡ fd
d„Z‡  Z	S )rÄ   z/Helper class for writing the TopDict to binary.c                 C   s$   g }|D ]}|  | || ¡¡ q|S r   ©r6   r|   ©r   r    rc   ÚoutrÊ   r   r   r   rÐ   ‰  s    zTopDictIndexCompiler.getItemsc                 C   s$   g }| j D ]}| | |¡¡ q
|S r   ©r    Úextendr€   )r   rc   r„   r‚   r   r   r   r€   �  s    
z TopDictIndexCompiler.getChildrenc                    s.   | j rd| jd  ¡ g}|S tt| ƒ ¡ S d S ©Nr   )rP   r    r   ÚsuperrÄ   rÔ   )r   rÓ   ©Ú	__class__r   r   rÔ   •  s    zTopDictIndexCompiler.getOffsetsc                    s*   | j r| jd  ¡ }|S tt| ƒ ¡ S d S ræ   )rP   r    r   rç   rÄ   )r   rÕ   rè   r   r   r   œ  s    z"TopDictIndexCompiler.getDataLengthc                    s,   | j r| jd  |¡ ntt| ƒ |¡ d S ræ   )rP   r    r�   rç   rÄ   ©r   rh   rè   r   r   r�   £  s    zTopDictIndexCompiler.toFile)
r   r   r   r½   rÐ   r€   rÔ   r   r�   Ú__classcell__r   r   rè   r   rÄ   †  s   rÄ   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚFDArrayIndexCompilerz®Helper class for writing the
    `Font DICT INDEX <https://docs.microsoft.com/en-us/typography/opentype/spec/cff2#10-font-dict-index-font-dicts-and-fdselect>`_
    to binary.c                 C   s$   g }|D ]}|  | || ¡¡ q|S r   rá   râ   r   r   r   rÐ   ¯  s    zFDArrayIndexCompiler.getItemsc                 C   s$   g }| j D ]}| | |¡¡ q
|S r   rä   )r   rc   r„   rŸ   r   r   r   r€   µ  s    
z FDArrayIndexCompiler.getChildrenc                 C   sº   |   ¡ }| jr t|t| jƒƒ nt|t| jƒƒ t|d ƒ}t||ƒ | }tj	}|D ]2}|d|ƒ|d … }t|ƒ| ks~t
‚| |¡ qV| jD ]$}t|dƒrª| |¡ q�| |¡ q�d S )Nr"   rÖ   r�   )rÔ   rP   rÚ   r5   r    rÛ   rÆ   rÜ   rY   r~   r0   rÇ   r*   r�   )r   rh   rÓ   rZ   r~   rÝ   rÞ   rÊ   r   r   r   r�   »  s     


zFDArrayIndexCompiler.toFilec                 C   s   || j jd< d S )Nr˜   ©rÑ   r¥   ©r   rÉ   rË   r   r   r   rÁ   Ï  s    zFDArrayIndexCompiler.setPosN)r   r   r   r½   rÐ   r€   r�   rÁ   r   r   r   r   rì   ª  s
   rì   c                   @   s   e Zd ZdZdd„ ZdS )ÚGlobalSubrsCompilerz§Helper class for writing the `global subroutine INDEX <https://docs.microsoft.com/en-us/typography/opentype/spec/cff2#9-local-and-global-subr-indexes>`_
    to binary.c                 C   s*   g }|D ]}|  | j¡ | |j¡ q|S r   ©r†   rP   r6   Úbytecode©r   r    rc   rã   rB   r   r   r   rÐ   ×  s
    zGlobalSubrsCompiler.getItemsN)r   r   r   r½   rÐ   r   r   r   r   rï   Ó  s   rï   c                   @   s   e Zd ZdZdd„ ZdS )ÚSubrsCompilerz¦Helper class for writing the `local subroutine INDEX <https://docs.microsoft.com/en-us/typography/opentype/spec/cff2#9-local-and-global-subr-indexes>`_
    to binary.c                 C   s   || j j }|| j jd< d S ©Nr³   )rÑ   rÉ   r¥   )r   rÉ   rË   rÝ   r   r   r   rÁ   ã  s    zSubrsCompiler.setPosN)r   r   r   r½   rÁ   r   r   r   r   ró   ß  s   ró   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚCharStringsCompilerz¡Helper class for writing the `CharStrings INDEX <https://docs.microsoft.com/en-us/typography/opentype/spec/cff2#9-local-and-global-subr-indexes>`_
    to binary.c                 C   s*   g }|D ]}|  | j¡ | |j¡ q|S r   rð   rò   r   r   r   rÐ   ì  s
    zCharStringsCompiler.getItemsc                 C   s   || j jd< d S ©Nr¨   rí   rî   r   r   r   rÁ   ó  s    zCharStringsCompiler.setPosN)r   r   r   r½   rÐ   rÁ   r   r   r   r   rõ   è  s   rõ   c                   @   sX   e Zd ZdZeZddd„Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zddd„Zdd„ ZdS )r^   z§This class represents what the CFF spec calls an INDEX (an array of
    variable-sized objects). `Index` items can be addressed and set using
    Python list indexing.Nc                 C   s8  |d k|d kkst ‚g | _| jj}|d kr.d S || _t td|| ¡ ¡ || _|r\t	|ƒ}nt
|ƒ}|dkrpd S d g| | _t|ƒ}t td||¡ |dks¨t d| ƒ‚g  | _}dd|  }t|d ƒD ]2}| |¡}	||	 }	t d|	¡\}
| t|
ƒ¡ qÊ| ¡ d | _| | j|d	  ¡ t td
|| ¡ ¡ d S )Núloading %s at %sr   z    index count: %s offSize: %srx   zoffSize too large: %só    r   ú>Lr"   ú    end of %s at %s)r0   r    ré   r   Ú_isCFF2rÂ   rÃ   rÅ   rh   Ú
readCard32Ú
readCard16Ú	readCard8rÓ   ÚrangerV   rY   rT   r6   r2   Ú
offsetBaser[   )r   rh   rP   ru   rÈ   rZ   rÓ   Úpadr4   ÚchunkrÝ   r   r   r   r   þ  s6    


zIndex.__init__c                 C   s
   t | jƒS r   )r5   r    rl   r   r   r   rm     s    zIndex.__len__c                 C   s†   | j | }|d k	r|S | j| | j }| j|d  | j|  }| j}| |¡ | |¡}t|ƒ|ksht‚|  ||||¡}|| j |< |S ©Nr   )	r    rÓ   r   rh   r[   rV   r5   r0   ÚproduceItem)r   r4   rÊ   rÝ   Úsizerh   r¾   r   r   r   rv     s    



zIndex.__getitem__c                 C   s   || j |< d S r   ©r    )r   r4   rÊ   r   r   r   Ú__setitem__-  s    zIndex.__setitem__c                 C   s   |S r   r   )r   r4   r¾   rh   rÝ   r   r   r   r  0  s    zIndex.produceItemc                 C   s   | j  |¡ dS )zAdd an item to an INDEX.N)r    r6   )r   rÊ   r   r   r   r6   3  s    zIndex.appendc                 C   s   | j | |||d�S ©NrO   ©ÚcompilerClass©r   rc   rÑ   rP   r   r   r   r|   7  s    zIndex.getCompilerc                 C   s   | j dd…= dS )zEmpty the INDEX.Nr  rl   r   r   r   r¶   :  s    zIndex.clear)NN)N)r   r   r   r½   rÎ   r
  r   rm   rv   r  r  r6   r|   r¶   r   r   r   r   r^   ÷  s   

r^   c                       sR   e Zd ZdZeZejZejZ	d‡ fdd„	Z
dd„ Zdd„ Zd	d
„ Zdd„ Z‡  ZS )rf   ay  This index contains all the global subroutines in the font. A global
    subroutine is a set of ``CharString`` data which is accessible to any
    glyph in the font, and are used to store repeated instructions - for
    example, components may be encoded as global subroutines, but so could
    hinting instructions.

    Remember that when interpreting a ``callgsubr`` instruction (or indeed
    a ``callsubr`` instruction) that you will need to add the "subroutine
    number bias" to number given:

    .. code:: python

            tt = ttLib.TTFont("Almendra-Bold.otf")
            u = tt["CFF "].cff[0].CharStrings["udieresis"]
            u.decompile()

            u.toXML(XMLWriter(sys.stdout))
            # <some stuff>
            # -64 callgsubr <-- Subroutine which implements the dieresis mark
            # <other stuff>

            tt["CFF "].cff[0].GlobalSubrs[-64] # <-- WRONG
            # <T2CharString (bytecode) at 103451d10>

            tt["CFF "].cff[0].GlobalSubrs[-64 + 107] # <-- RIGHT
            # <T2CharString (source) at 103451390>

    ("The bias applied depends on the number of subrs (gsubrs). If the number of
    subrs (gsubrs) is less than 1240, the bias is 107. Otherwise if it is less
    than 33900, it is 1131; otherwise it is 32768.",
    `Subroutine Operators <https://docs.microsoft.com/en-us/typography/opentype/otspec180/cff2charstr#section4.4>`)
    Nc                    s8   t t| ƒj||d� || _|| _|r*|| _|r4|| _d S r  )rç   rf   r   r   r    ÚfdSelectrž   )r   rh   r   r    r  rž   rP   rè   r   r   r   e  s    	zGlobalSubrsIndex.__init__c                 C   sn   | j d k	r| j }nJt| dƒrX| jd k	rXt| dƒrF| jd k	rF| j| }nd}| j| j}nd }| j||| jd�S )Nrž   r  r   ©r    r   )r    r*   rž   r  r•   Ú	subrClassr   )r   r4   r¾   rh   rÝ   r    ÚfdIndexr   r   r   r  v  s    
zGlobalSubrsIndex.produceItemc                 C   s|   |  d¡ | ¡  tt| ƒƒD ]X}| | }| ¡ rD|jd|dd� n|jd|d� | ¡  | |¡ | d¡ | ¡  qdS )a  Write the subroutines index into XML representation onto the given
        :class:`fontTools.misc.xmlWriter.XMLWriter`.

        .. code:: python

                writer = xmlWriter.XMLWriter(sys.stdout)
                tt["CFF "].cff[0].GlobalSubrs.toXML(writer)

        zDThe 'index' attribute is only for humans; it is ignored when parsed.Ú
CharStringr   )r4   Úraw©r4   N)Úcommentr�   rÿ   r5   ÚneedsDecompilationrŽ   r�   r�   )r   r‘   Úir?   r   r   r   r�   ƒ  s    
ÿ

zGlobalSubrsIndex.toXMLc                 C   s0   |dkrd S |   ¡ }| |||¡ |  |¡ d S )Nr  )r  r—   r6   )r   ru   r›   rœ   r?   r   r   r   r—   œ  s
    zGlobalSubrsIndex.fromXMLc                 C   s$   d }t | dƒr| j| }| | |fS )Nr  )r*   r  )r   r4   Úselr   r   r   r´   £  s    

z#GlobalSubrsIndex.getItemAndSelector)NNNNNN)r   r   r   r½   rï   r
  r   rš   r  ÚcharStringClassr   r  r�   r—   r´   rë   r   r   rè   r   rf   ?  s   !      ùrf   c                   @   s   e Zd ZdZeZdS )Ú
SubrsIndexz¹This index contains a glyph's local subroutines. A local subroutine is a
    private set of ``CharString`` data which is accessible only to the glyph to
    which the index is attached.N)r   r   r   r½   ró   r
  r   r   r   r   r  ª  s   r  c                       s6   e Zd ZdZeZd
‡ fdd„	Zdd„ Zdd	„ Z‡  Z	S )r`   a‡  This index represents the array of ``TopDict`` structures in the font
    (again, usually only one entry is present). Hence the following calls are
    equivalent:

    .. code:: python

            tt["CFF "].cff[0]
            # <fontTools.cffLib.TopDict object at 0x102ed6e50>
            tt["CFF "].cff.topDictIndex[0]
            # <fontTools.cffLib.TopDict object at 0x102ed6e50>

    Nr   c                    s¶   |d k|d kkst ‚|| _|d k	rž|rž|| _g | _| jj}t td|| ¡ ¡ || _	d}d g| | _d|g| _
| ¡ | _| | j| ¡ t td|| ¡ ¡ ntt| ƒj||d� d S )Nr÷   r   r   rú   rO   )r0   rj   rû   r    ré   r   rÂ   rÃ   rÅ   rh   rÓ   r   r[   rç   r`   r   )r   rh   rj   ZtopSizerP   ru   rÈ   rè   r   r   r   Â  s    

zTopDictIndex.__init__c                 C   s*   t | j||| j| j| jd�}| |¡ |S r  )r–   rc   rg   rj   rû   rk   )r   r4   r¾   rh   rÝ   Útopr   r   r   r  Õ  s    ú
zTopDictIndex.produceItemc                 C   sL   t t| ƒƒD ]:}|jd|d� | ¡  | |  |¡ | d¡ | ¡  qd S ©Nr«   r  ©rÿ   r5   rŽ   r�   r�   r�   ©r   r‘   r  r   r   r   r�   á  s    
zTopDictIndex.toXML)NNr   N)
r   r   r   r½   rÄ   r
  r   r  r�   rë   r   r   rè   r   r`   ²  s
   r`   c                   @   s(   e Zd ZeZdd„ Zdd„ Zdd„ ZdS )r§   c                 C   sL   t t| ƒƒD ]:}|jd|d� | ¡  | |  |¡ | d¡ | ¡  qd S r  r  r  r   r   r   r�   î  s    
zFDArrayIndex.toXMLc                 C   s*   t | j||| j| j| jd�}| |¡ |S ©N)rP   r™   )r«   rc   rg   rû   r™   rk   )r   r4   r¾   rh   rÝ   rŸ   r   r   r   r  ö  s    ú
zFDArrayIndex.produceItemc                 C   sN   |dkrd S t ƒ }|D ](}t|tƒr&q|\}}}| |||¡ q|  |¡ d S )Nr«   )r«   rq   rr   r—   r6   )r   ru   r›   rœ   rŸ   r�   r   r   r   r—     s    

zFDArrayIndex.fromXMLN)r   r   r   rì   r
  r�   r  r—   r   r   r   r   r§   ê  s   r§   c                   @   sF   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dS )ÚVarStoreDataNc                 C   s   || _ d | _|| _tƒ | _d S r   )rh   r¾   Ú
otVarStorer   r“   )r   rh   r  r   r   r   r     s    zVarStoreData.__init__c                 C   sL   | j rHt| j ƒ}| j  |¡| _i }t| j|ƒ}t ¡ | _| j || j	¡ | S r   )
rh   rý   rV   r¾   r   Úotr”   r  rk   r“   )r   ÚlengthZglobalStateÚreaderr   r   r   rk     s    

zVarStoreData.decompilec                 C   s$   t ƒ }| j || j¡ | ¡ | _d S r   )r   r  r†   r“   Z
getAllDatar¾   )r   rƒ   r   r   r   r†      s    zVarStoreData.compilec                 C   s   | j  || j¡ d S r   )r  r�   r“   )r   r‘   ru   r   r   r   ÚwriteXML'  s    zVarStoreData.writeXMLc                 C   sB   t  ¡ | _|D ].}t|tƒr|\}}}| j |||| j¡ qqd S r   )r   r”   r  rq   Útupler—   r“   )r   ru   r›   rœ   rÑ   r�   r   r   r   ÚxmlRead*  s    


zVarStoreData.xmlReadc                 C   s
   t | jƒS r   ©r5   r¾   rl   r   r   r   rm   4  s    zVarStoreData.__len__c                 C   s"   |d krd}| j j| }|j}|S ræ   )r  ZVarDataZVarRegionCount)r   ZvsIndexZvarDataÚ
numRegionsr   r   r   ÚgetNumRegions7  s
    zVarStoreData.getNumRegions)NN)
r   r   r   r   rk   r†   r#  r%  rm   r(  r   r   r   r   r    s   

r  c                   @   s6   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚFDSelectNc                 C   sœ  |�rŒt |ƒ| _| jdkr@ddlm} |d| |¡ƒ ¡ | _�q˜| jdkrÖd g| }t|ƒ}d }d }t|ƒD ]8}	t|ƒ}
|d k	r˜t||
ƒD ]}|||< qŠ|
}t |ƒ}ql|d k	rÎt|ƒ}
t||
ƒD ]}|||< qÀ|| _n´| jdk�rxd g| }t|ƒ}d }d }t|ƒD ]>}	t|ƒ}
|d k	�r4t||
ƒD ]}|||< �q$|
}t|ƒ}�q|d k	�rpt|ƒ}
t||
ƒD ]}|||< �q`|| _nd�s˜t	d| ƒ‚n|| _g | _d S )Nr   )ÚarrayrI   rE   rx   Fzunsupported FDSelect format: %s)
rþ   Úformatr*  rV   ÚtolistÚgidArrayrý   rÿ   rü   r0   )r   rh   Ú	numGlyphsr+  r*  r-  ÚnRangesrº   Úprevr  ÚfirstÚglyphIDr   r   r   r   @  sT    









zFDSelect.__init__c                 C   s
   t | jƒS r   )r5   r-  rl   r   r   r   rm   r  s    zFDSelect.__len__c                 C   s
   | j | S r   ©r-  rC   r   r   r   rv   u  s    zFDSelect.__getitem__c                 C   s   || j |< d S r   r3  )r   r4   ÚfdSelectValuer   r   r   r  x  s    zFDSelect.__setitem__c                 C   s   | j  |¡ d S r   )r-  r6   )r   r4  r   r   r   r6   {  s    zFDSelect.append)NNN)r   r   r   r   rm   rv   r  r6   r   r   r   r   r)  ?  s
   
2r)  c                   @   sf   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZeZdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )r¨   a  The ``CharStrings`` in the font represent the instructions for drawing
    each glyph. This object presents a dictionary interface to the font's
    CharStrings, indexed by glyph name:

    .. code:: python

            tt["CFF "].cff[0].CharStrings["a"]
            # <T2CharString (bytecode) at 103451e90>

    See :class:`fontTools.misc.psCharStrings.T1CharString` and
    :class:`fontTools.misc.psCharStrings.T2CharString` for how to decompile,
    compile and interpret the glyph drawing instructions in the returned objects.

    Nc	                 C   sŒ   || _ || _|d k	rZt||||||d�| _i  | _}	tt|ƒƒD ]}
|
|	||
 < q@d| _n.i | _d| _|| _|d k	rz|| _	|d k	rˆ|| _
d S )NrO   r   r   )r   ÚvarStorer  rª   r±   rÿ   r5   r©   r    r  rž   )r   rh   ry   r   r    r  rž   rP   r5  r±   r  r   r   r   r   �  s,         ÿ
zCharStrings.__init__c                 C   s   t | j ¡ ƒS r   )r]   r±   rn   rl   r   r   r   rn   °  s    zCharStrings.keysc                 C   s   | j r| jS t| j ¡ ƒS d S r   )r©   rª   r]   r±   ro   rl   r   r   r   ro   ³  s    zCharStrings.valuesc                 C   s
   || j kS r   )r±   )r   ru   r   r   r   Úhas_key¹  s    zCharStrings.has_keyc                 C   s
   t | jƒS r   )r5   r±   rl   r   r   r   rm   ¾  s    zCharStrings.__len__c                 C   s   | j | }| jr| j| }|S r   )r±   r©   rª   )r   ru   r7   r   r   r   rv   Á  s    

zCharStrings.__getitem__c                 C   s*   | j r| j| }|| j|< n
|| j|< d S r   )r©   r±   rª   )r   ru   r7   r4   r   r   r   r  Ç  s    
zCharStrings.__setitem__c                 C   sZ   | j r| j| }| j |¡S t| dƒrDt| dƒr>| j| j}qHd}nd }| j| |fS d S )Nrž   r  r   )r©   r±   rª   r´   r*   ÚfdSelectIndex)r   ru   r4   r  r   r   r   r´   Î  s    


zCharStrings.getItemAndSelectorc                 C   sœ   t |  ¡ ƒ}|D ]†}|  |¡\}}| ¡ r2dg}ng }|d krV| dd|fg| ¡ n| dd|fd|fg| ¡ | ¡  | |¡ | d¡ | ¡  qd S )N)r  r   r  ru   r7  )Úsortedrn   r´   r  rŽ   r�   r�   r�   )r   r‘   Únamesru   ZcharStrr7  r  r   r   r   r�   Ü  s     þ

zCharStrings.toXMLc           
   	   C   sº   |D ]°}t |tƒrq|\}}}|dkr(qd}t| dƒrnzt|d ƒ}W n tk
r^   d}Y nX | j| j}n| j}|d }tj	}||| j
d�}	|	 |||¡ |dkr¬||	_|	| |< qd S )Nr  r"   rž   r7  r   ru   r  )rq   rr   r*   r   rs   rž   r•   r    r   rš   r   r—   r7  )
r   ru   r›   rœ   r�   ZfdIDr    Ú	glyphNamer  r7   r   r   r   r—   ð  s*    



zCharStrings.fromXML)NN)r   r   r   r½   r   rn   ro   r6  Ú__contains__rm   rv   r  r´   r�   r—   r   r   r   r   r¨     s     ÷
!r¨   c                 C   s   t |  d¡ƒS r  )r   rV   )rh   r   r   r   rþ   
  s    rþ   c                 C   s   t  d|  d¡¡\}|S )NrQ   r#   ©rY   rT   rV   ©rh   rˆ   r   r   r   rý     s    rý   c                 C   s   t  d|  d¡¡\}|S )Nrù   rx   r<  r=  r   r   r   rü     s    rü   c                 C   s   |   t|ƒ¡ d S r   )rÇ   r   r=  r   r   r   rÜ     s    rÜ   c                 C   s   |   t d|¡¡ d S ©NrQ   ©rÇ   rY   r~   r=  r   r   r   rÛ     s    rÛ   c                 C   s   |   t d|¡¡ d S ©Nrù   r?  r=  r   r   r   rÚ      s    rÚ   c                 C   s   t | ƒS r   )r   r‡   r   r   r   Ú	packCard8$  s    rA  c                 C   s   t  d| ¡S r>  ©rY   r~   r‡   r   r   r   Ú
packCard16(  s    rC  c                 C   s   t  d| ¡S r@  rB  r‡   r   r   r   Ú
packCard32,  s    rD  c                 C   s(   i }| D ]\}}}}}||f||< q|S r   r   ©rÀ   ÚdÚopru   ÚargÚdefaultÚconvr   r   r   ÚbuildOperatorDict0  s    rK  c                 C   sT   i }| D ]F\}}}}}t |tƒr:t|d ƒt|d ƒ }nt|ƒ}||f||< q|S ©Nr   r   )rq   r$  r   rE  r   r   r   ÚbuildOpcodeDict7  s    
rM  c                 C   s&   g }| D ]\}}}}}|  |¡ q|S r   )r6   )rÀ   ÚlrG  ru   rH  rI  rJ  r   r   r   r¡   B  s    r¡   c                 C   s,   i }| D ]\}}}}}|d k	r|||< q|S r   r   rE  r   r   r   ÚbuildDefaultsI  s
    
rO  c                 C   s$   i }| D ]\}}}}}|||< q|S r   r   rE  r   r   r   ÚbuildConvertersQ  s    
rP  c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚSimpleConverterc              	   C   sF   t |dƒs|  ||¡S |j}| ¡ }z|  ||¡W ¢S | |¡ X d S )Nrh   )r*   Ú_readrh   rÅ   r[   )r   rÑ   rˆ   rh   rÉ   r   r   r   rV   Y  s    
zSimpleConverter.readc                 C   s   |S r   r   ©r   rÑ   rˆ   r   r   r   rR  c  s    zSimpleConverter._readc                 C   s   |S r   r   rS  r   r   r   rÇ   f  s    zSimpleConverter.writec                 C   s   |j ||d� | ¡  d S )Nr‡   )rŒ   r�   ©r   r‘   ru   rˆ   r   r   r   ÚxmlWritei  s    zSimpleConverter.xmlWritec                 C   s   |d S ©Nrˆ   r   ©r   ru   r›   rœ   rÑ   r   r   r   r%  m  s    zSimpleConverter.xmlReadN)r   r   r   rV   rR  rÇ   rU  r%  r   r   r   r   rQ  X  s
   
rQ  c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚASCIIConverterc                 C   s   t |dd�S ©NÚasciirØ   rJ   rS  r   r   r   rR  r  s    zASCIIConverter._readc                 C   s   t |dd�S rY  ©r	   rS  r   r   r   rÇ   u  s    zASCIIConverter.writec                 C   s"   |j |t|dd�d� | ¡  d S )NrZ  rØ   r‡   ©rŒ   r
   r�   rT  r   r   r   rU  x  s    zASCIIConverter.xmlWritec                 C   s   t |d dd�S )Nrˆ   rZ  rØ   r[  rW  r   r   r   r%  |  s    zASCIIConverter.xmlReadN©r   r   r   rR  rÇ   rU  r%  r   r   r   r   rX  q  s   rX  c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚLatin1Converterc                 C   s   t |dd�S ©Nr×   rØ   rJ   rS  r   r   r   rR  �  s    zLatin1Converter._readc                 C   s   t |dd�S r_  r[  rS  r   r   r   rÇ   „  s    zLatin1Converter.writec                 C   s<   t |dd�}|dkr"t dd|¡}|j||d� | ¡  d S )Nr×   rØ   )ÚNoticeÚ	Copyrightz	[\r\n]\s+ú r‡   )r
   ÚreÚsubrŒ   r�   rT  r   r   r   rU  ‡  s
    zLatin1Converter.xmlWritec                 C   s   t |d dd�S )Nrˆ   r×   rØ   r[  rW  r   r   r   r%  Ž  s    zLatin1Converter.xmlReadNr]  r   r   r   r   r^  €  s   r^  c                 C   s&   zt | ƒ}W n   t| ƒ}Y nX |S r   )r2   Úfloat)rM   rˆ   r   r   r   ÚparseNum’  s
    rf  c                 C   s`   g }| D ]>}t |tƒrq|\}}}|d  ¡ }dd„ |D ƒ}| |¡ qt|ƒdkr\|d }|S )Nrˆ   c                 S   s   g | ]}t |ƒ‘qS r   )Úeval©rL   Úvalr   r   r   Ú
<listcomp>¡  s     z"parseBlendList.<locals>.<listcomp>r   r   )rq   rr   Úsplitr6   r5   )rM   Ú	valueListr�   ru   r›   rœ   Ú	blendListr   r   r   ÚparseBlendListš  s    

rn  c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚNumberConverterc                 C   s„   t |tƒrj| |¡ | ¡  | ¡  d dd„ |D ƒ¡}|jt|d� | ¡  | ¡  | 	|¡ | ¡  n|j||d� | ¡  d S )Nrb  c                 S   s   g | ]}t |ƒ‘qS r   ©rr   rh  r   r   r   rj  ®  s     z,NumberConverter.xmlWrite.<locals>.<listcomp>r‡   ©
rq   r]   rŽ   r�   ÚindentÚjoinrŒ   ÚkBlendDictOpNameÚdedentr�   )r   r‘   ru   rˆ   Ú
blendValuer   r   r   rU  ©  s    



zNumberConverter.xmlWritec                 C   s.   |  dd ¡}|d krt|ƒ}nt|d ƒ}|S rV  )Úgetrn  rf  )r   ru   r›   rœ   rÑ   ÚvalueStringrˆ   r   r   r   r%  ¸  s
    
zNumberConverter.xmlReadN©r   r   r   rU  r%  r   r   r   r   ro  ¨  s   ro  c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚArrayConverterc                 C   sª   |r|t |d tƒr|| |¡ | ¡  | ¡  |D ].}d dd„ |D ƒ¡}|jt|d� | ¡  q0| ¡  | 	|¡ | ¡  n*d dd„ |D ƒ¡}|j||d� | ¡  d S )Nr   rb  c                 S   s   g | ]}t |ƒ‘qS r   rp  rh  r   r   r   rj  È  s     z+ArrayConverter.xmlWrite.<locals>.<listcomp>r‡   c                 S   s   g | ]}t |ƒ‘qS r   rp  rh  r   r   r   rj  Ï  s     rq  )r   r‘   ru   rˆ   rl  rv  r   r   r   rU  Â  s    



zArrayConverter.xmlWritec                 C   s8   |  dd ¡}|d krt|ƒ}n| ¡ }dd„ |D ƒ}|S )Nrˆ   c                 S   s   g | ]}t |ƒ‘qS r   )rf  )rL   rˆ   r   r   r   rj  Ù  s     z*ArrayConverter.xmlRead.<locals>.<listcomp>)rw  rn  rk  )r   ru   r›   rœ   rÑ   rx  rl  ro   r   r   r   r%  Ó  s    
zArrayConverter.xmlReadNry  r   r   r   r   rz  Á  s   rz  c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚTableConverterc                 C   s2   |  |¡ | ¡  | |¡ | |¡ | ¡  d S r   )rŽ   r�   r�   r�   rT  r   r   r   rU  Þ  s
    


zTableConverter.xmlWritec                 C   s<   |   ¡ ƒ }|D ](}t|tƒrq|\}}}| |||¡ q|S r   )ÚgetClassrq   rr   r—   )r   ru   r›   rœ   rÑ   Úobr�   r   r   r   r%  å  s    


zTableConverter.xmlReadNry  r   r   r   r   r{  Ý  s   r{  c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚPrivateDictConverterc                 C   s   t S r   )ÚPrivateDictrl   r   r   r   r|  ð  s    zPrivateDictConverter.getClassc           
      C   s~   |\}}|j }|j}z
|j}W n tk
r6   d }Y nX t|j||||d�}| |¡ | |¡}	t|	ƒ|kspt	‚| 
|	¡ |S r  )rh   rû   r™   ÚAttributeErrorr  rc   r[   rV   r5   r0   rk   )
r   rÑ   rˆ   r  rÝ   rh   rP   r™   Zprivr¾   r   r   r   rR  ó  s    




zPrivateDictConverter._readc                 C   s   dS )N)r   r   r   rS  r   r   r   rÇ     s    zPrivateDictConverter.writeN©r   r   r   r|  rR  rÇ   r   r   r   r   r~  ï  s   r~  c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚSubrsConverterc                 C   s   t S r   )r  rl   r   r   r   r|    s    zSubrsConverter.getClassc                 C   s(   |j }|j}| |j| ¡ t||d�S r  )rh   rû   r[   rÝ   r  )r   rÑ   rˆ   rh   rP   r   r   r   rR  
  s    zSubrsConverter._readc                 C   s   dS ræ   r   rS  r   r   r   rÇ     s    zSubrsConverter.writeNr�  r   r   r   r   r‚    s   r‚  c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚCharStringsConverterc              
   C   s„   |j }|j}|j}t|dd ƒ}|j}t|dƒrP|j}t|dƒrF|j}	nd }	d }
nd\}	}|j}
| 	|¡ t
||||
|	|||d�}|S )Nr”   r˜   r)  )NN)rP   r5  )rh   rû   ry   rµ   rg   r*   r˜   r)  r•   r[   r¨   )r   rÑ   rˆ   rh   rP   ry   r5  r   rž   r  r    r±   r   r   r   rR    s2    


ø
zCharStringsConverter._readc                 C   s   dS ræ   r   rS  r   r   r   rÇ   2  s    zCharStringsConverter.writec           	      C   sp   t |dƒr,|j}t |dƒr"|j}nd }d }n|jd d   }}}td d |j|||t|dd ƒd�}| |||¡ |S )Nr˜   r)  r”   )r5  )r*   r˜   r)  r•   r¨   rg   rµ   r—   )	r   ru   r›   rœ   rÑ   rž   r  r    r±   r   r   r   r%  5  s$    


ù	zCharStringsConverter.xmlReadN©r   r   r   rR  rÇ   r%  r   r   r   r   rƒ    s   rƒ  c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚCharsetConverterc                 C   s”  t |dƒ}|dk�r|j}|j}| |¡ t td|¡ t|ƒ}|dkrZt|||j|ƒ}n(|dksj|dkr~t	|||j||ƒ}nt
‚t|ƒ|ks’t‚t td| ¡ ¡ i }g }	|D ]`}
|
|krþ||
 }|
d t|ƒ |krâ|d7 }qÄ|d ||
< |
d t|ƒ }
d||
< |	 |
¡ q°|	}nT|�s*d|jk�r>|dk�s8t‚d }n.|dk�rNt}n|dk�r^t}n|dk�rlt}|�r�t|ƒ|jk�r�|d |j… }|S )	NÚROSr#   zloading charset at %sr   r   z    charset end at %sú#r¨   )r*   r.  rh   r[   rÂ   rÃ   rþ   ÚparseCharset0rc   ÚparseCharsetÚNotImplementedErrorr5   r0   rÅ   rr   r6   r¥   ÚcffISOAdobeStringsÚcffIExpertStringsÚcffExpertSubsetStrings)r   rÑ   rˆ   ÚisCIDr.  rh   r+  ry   ZallNamesZ
newCharsetr:  Únr   r   r   rR  R  sL    






zCharsetConverter._readc                 C   s   dS ræ   r   rS  r   r   r   rÇ   €  s    zCharsetConverter.writec                 C   s   |  d¡ | ¡  d S )Nz8charset is dumped separately as the 'GlyphOrder' element)r  r�   rT  r   r   r   rU  ƒ  s    
zCharsetConverter.xmlWritec                 C   s   d S r   r   rW  r   r   r   r%  Š  s    zCharsetConverter.xmlReadNr]  r   r   r   r   r…  Q  s   .r…  c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚCharsetCompilerc                 C   s\   |d dkst ‚t|jdƒ}t|||ƒ}t|||ƒ}t|ƒt|ƒk rL|| _n|| _|| _d S )Nr   ú.notdefr†  )r0   r*   ÚdictObjÚpackCharset0ÚpackCharsetr5   r¾   rÑ   )r   rc   ry   rÑ   rŽ  Údata0r¾   r   r   r   r   �  s    zCharsetCompiler.__init__c                 C   s   || j jd< d S )Nry   rí   rî   r   r   r   rÁ   š  s    zCharsetCompiler.setPosc                 C   s
   t | jƒS r   r&  rl   r   r   r   r   �  s    zCharsetCompiler.getDataLengthc                 C   s   |  | j¡ d S r   ©rÇ   r¾   rê   r   r   r   r�      s    zCharsetCompiler.toFileN©r   r   r   r   rÁ   r   r�   r   r   r   r   r�  Ž  s   r�  c                 C   s|   d }t tdfttdfttdfg}t| ƒ}|D ]J\}}}|d k	rB qx||krLq,|}t|ƒD ]}| | || krXd } q,qXq,|S )Nr   r   r#   )ÚcffISOAdobeStringCountr‹  ÚcffExpertStringCountrŒ  ÚcffExpertSubsetStringCountr�  r5   rÿ   )ry   ZpredefinedCharSetValZpredefinedCharSetsZlcsZcntZpcsÚcsvr  r   r   r   ÚgetStdCharSet¤  s"    ýrœ  c                 C   s   t | dd … ƒS )NrE   )r2   ©ru   rc   r   r   r   ÚgetCIDfromNameº  s    rž  c                 C   s
   |  | ¡S r   )ÚgetSIDr�  r   r   r   ÚgetSIDfromName¾  s    r   c                 C   sJ   d}t |ƒg}|rt}nt}| dd … D ]}| t|||ƒƒ¡ q(t|ƒS rL  )rA  rž  r   r6   rC  r   )ry   rŽ  rc   Úfmtr¾   Ú	getNameIDru   r   r   r   r“  Â  s    
r“  c                 C   sì   d}g }d }d}|rt }nt}| dd … D ]R}|||ƒ}	|d krF|	}n2|d |	krx|| }
|
dkrfd}| ||
f¡ |	}|	}q*|r¤|| }
|
dkr–d}| ||
f¡ t|ƒg}|dkr¼t}nt}|D ]\}}
| t|ƒ||
ƒ ¡ qÄt|ƒS )Nr   r   éÿ   r#   )rž  r   r6   rA  rC  r   )ry   rŽ  rc   r¡  Úrangesr1  Úendr¢  ru   ÚSIDÚnLeftr¾   Ú	nLeftFuncr   r   r   r”  Ï  s<    

r”  c                 C   sj   dg}|r>t | d ƒD ]$}t|ƒ}| dt|ƒ d¡ ¡ qn(t | d ƒD ]}t|ƒ}| || ¡ qJ|S ©Nr‘  r   Zcidrw   )rÿ   rý   r6   rr   Úzfill)r.  rh   rc   rŽ  ry   r  ÚCIDr¦  r   r   r   rˆ  ô  s    rˆ  c                 C   s¢   dg}d}|dkrt }nt}|| k ržt|ƒ}||ƒ}	|rjt|||	 d ƒD ]}
| dt|
ƒ d¡ ¡ qJn&t|||	 d ƒD ]}| || ¡ q|||	 d }q|S r©  )rþ   rý   rÿ   r6   rr   rª  )r.  rh   rc   rŽ  r¡  ry   rÈ   r¨  r1  r§  r«  r¦  r   r   r   r‰    s    r‰  c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚEncodingCompilerc                 C   sZ   t |tƒrt‚t|jj||jƒ}t|jj||jƒ}t|ƒt|ƒk rJ|| _	n|| _	|| _
d S r   )rq   rr   r0   ÚpackEncoding0r’  ry   rc   ÚpackEncoding1r5   r¾   rÑ   )r   rc   rÙ   rÑ   r•  Zdata1r   r   r   r     s    zEncodingCompiler.__init__c                 C   s   || j jd< d S )NÚEncodingrí   rî   r   r   r   rÁ      s    zEncodingCompiler.setPosc                 C   s
   t | jƒS r   r&  rl   r   r   r   r   #  s    zEncodingCompiler.getDataLengthc                 C   s   |  | j¡ d S r   r–  rê   r   r   r   r�   &  s    zEncodingCompiler.toFileNr—  r   r   r   r   r¬    s   
r¬  c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚEncodingConverterc                 C   s¤   |dkrdS |dkrdS |dks$t ‚|j}| |¡ t td|¡ t|ƒ}|d@ }|r^tdƒ‚|d@ }|dkr‚t|j|||j	ƒ}n|dkrœt
|j|||j	ƒ}|S d S )	Nr   ÚStandardEncodingr   ÚExpertEncodingzloading Encoding at %sé€   z*Encoding supplements are not yet supportedé   )r0   rh   r[   rÂ   rÃ   rþ   rŠ  ÚparseEncoding0ry   rc   ÚparseEncoding1)r   rÑ   rˆ   rh   r¡  ÚhaveSupplementrÙ   r   r   r   rR  +  s8    
   ÿ   ÿzEncodingConverter._readc                 C   s   |dkrdS |dkrdS dS )Nr±  r   r²  r   r   rS  r   r   r   rÇ   D  s
    zEncodingConverter.writec                 C   sˆ   |dkr"|j ||d� | ¡  d S | |¡ | ¡  tt|ƒƒD ]0}|| }|dkr@|j dt|ƒ|d� | ¡  q@| |¡ | ¡  d S )N)r±  r²  r‹   r‘  Úmap)Úcoderu   )rŒ   r�   rŽ   rÿ   r5   Úhexr�   )r   r‘   ru   rˆ   r¹  r:  r   r   r   rU  K  s    


zEncodingConverter.xmlWritec           	      C   sZ   d|kr|d S dgd }|D ]6}t |tƒr.q|\}}}t|d ƒ}|d }|||< q|S )Nru   r‘  rÍ   r¹  )rq   rr   r   )	r   ru   r›   rœ   rÑ   rÙ   r�   r¹  r:  r   r   r   r%  Z  s    



zEncodingConverter.xmlReadNr]  r   r   r   r   r°  *  s   r°  c                 C   sF   t |ƒ}dgd }td|d ƒD ] }t |ƒ}|dkr | | ||< q |S )Nr‘  rÍ   r   r   ©rþ   rÿ   )ry   rh   r·  rc   ZnCodesrÙ   r2  r¹  r   r   r   rµ  h  s    
rµ  c           
      C   sl   t |ƒ}dgd }d}t|ƒD ]H}t |ƒ}t |ƒ}	t|||	 d ƒD ]}| | ||< |d }qD|d }q|S )Nr‘  rÍ   r   r»  )
ry   rh   r·  rc   r/  rÙ   r2  r  r¹  r§  r   r   r   r¶  r  s    


r¶  c           	      C   s¶   d}i }t t|ƒƒD ]}|| }|dkr|||< qg }| dd … D ]}| |¡}| |¡ qB|rv|d d krv| ¡  q\t|ƒtt|ƒƒg}|D ]}|d kržd}| t|ƒ¡ qŽt|ƒS )Nr   r‘  r   r"   ©rÿ   r5   rw  r6   ÚpoprA  r   )	ry   rÙ   rc   r¡  Úmr¹  ru   Úcodesr¾   r   r   r   r­  €  s$    


r­  c                 C   s  d}i }t t|ƒƒD ]}|| }|dkr|||< qg }d }d}	| dd … D ]H}| |d¡}|d krh|}n&|	d |krŽ|	| }
| ||
f¡ |}|}	qJ|	| }
| ||
f¡ |rÈ|d d dkrÈ| ¡  qªt|ƒtt|ƒƒg}|D ]*\}}
|dkrôd}| t|ƒt|
ƒ ¡ qàt|ƒS )Nr   r‘  r   r"   r¼  )ry   rÙ   rc   r¡  r¾  r¹  ru   r¤  r1  r¥  r§  r¾   r   r   r   r®  —  s8    

r®  c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚFDArrayConverterc                 C   s`   z
|j }W n tk
r"   d }Y nX |j}|j}| |¡ t||d�}||_|j|_|j|_|S r  )	r”   r€  rh   rû   r[   r§   r™   rc   rg   )r   rÑ   rˆ   r™   rh   rP   rž   r   r   r   rR  º  s    


zFDArrayConverter._readc                 C   s   dS ræ   r   rS  r   r   r   rÇ   È  s    zFDArrayConverter.writec                 C   s8   t ƒ }|D ](}t|tƒrq
|\}}}| |||¡ q
|S r   )r§   rq   rr   r—   )r   ru   r›   rœ   rÑ   rž   r�   r   r   r   r%  Ë  s    

zFDArrayConverter.xmlReadNr„  r   r   r   r   rÀ  ¹  s   rÀ  c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚFDSelectConverterc                 C   s    |j }| |¡ t||jƒ}|S r   )rh   r[   r)  r.  )r   rÑ   rˆ   rh   r  r   r   r   rR  Ö  s    
zFDSelectConverter._readc                 C   s   dS ræ   r   rS  r   r   r   rÇ   Ü  s    zFDSelectConverter.writec                 C   s    |  |d|jfg¡ | ¡  d S ©Nr+  )rŒ   r+  r�   rT  r   r   r   rU  á  s    zFDSelectConverter.xmlWritec           	      C   s$   t |d ƒ}d }d }t|||ƒ}|S rÂ  )r   r)  )	r   ru   r›   rœ   rÑ   r¡  rh   r.  r  r   r   r   r%  å  s
    zFDSelectConverter.xmlReadNr]  r   r   r   r   rÁ  Õ  s   rÁ  c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚVarStoreConverterc                 C   s$   |j }| |¡ t|ƒ}| ¡  |S r   )rh   r[   r  rk   )r   rÑ   rˆ   rh   r5  r   r   r   rR  î  s
    
zVarStoreConverter._readc                 C   s   dS ræ   r   rS  r   r   r   rÇ   õ  s    zVarStoreConverter.writec                 C   s   |  ||¡ d S r   )r#  rT  r   r   r   rU  ø  s    zVarStoreConverter.xmlWritec                 C   s   t ƒ }| ||||¡ |S r   )r  r%  )r   ru   r›   rœ   rÑ   r5  r   r   r   r%  û  s    zVarStoreConverter.xmlReadNr]  r   r   r   r   rÃ  í  s   rÃ  c                 C   s.   d}t |ƒg}| D ]}| t |ƒ¡ qt|ƒS ræ   )rA  r6   r   )ÚfdSelectArrayr¡  r¾   r4   r   r   r   ÚpackFDSelect0  s
    
rÅ  c           
      C   s¬   d}g }t | ƒ}d}t|ƒD ]&}| | }||kr| ||g¡ |}q|d }t|ƒg}| tt |ƒƒ¡ |D ](}	| t|	d ƒ¡ | t|	d ƒ¡ ql| t|ƒ¡ t|ƒS )NrE   r"   r   r   )r5   rÿ   r6   rA  rC  r   ©
rÄ  r¡  ZfdRangesZlenArrayZlastFDIndexr  r  ZsentinelGIDr¾   ZfdRanger   r   r   ÚpackFDSelect3	  s"    
rÇ  c           
      C   s¬   d}g }t | ƒ}d}t|ƒD ]&}| | }||kr| ||g¡ |}q|d }t|ƒg}| tt |ƒƒ¡ |D ](}	| t|	d ƒ¡ | t|	d ƒ¡ ql| t|ƒ¡ t|ƒS )Nrx   r"   r   r   )r5   rÿ   r6   rA  rD  rC  r   rÆ  r   r   r   ÚpackFDSelect4  s"    
rÈ  c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚFDSelectCompilerc                 C   sŒ   |j }|j}|dkr t|ƒ| _nb|dkr4t|ƒ| _nN|dkrHt|ƒ| _n:t|ƒ}t|ƒ}t|ƒt|ƒk rv|| _d|_ n|| _d|_ || _d S )Nr   rE   rx   )r+  r-  rÅ  r¾   rÇ  rÈ  r5   rÑ   )r   r  rÑ   r¡  rÄ  r•  Zdata3r   r   r   r   4  s     zFDSelectCompiler.__init__c                 C   s   || j jd< d S )Nr)  rí   rî   r   r   r   rÁ   J  s    zFDSelectCompiler.setPosc                 C   s
   t | jƒS r   r&  rl   r   r   r   r   M  s    zFDSelectCompiler.getDataLengthc                 C   s   |  | j¡ d S r   r–  rê   r   r   r   r�   P  s    zFDSelectCompiler.toFileNr—  r   r   r   r   rÉ  3  s   rÉ  c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚVarStoreCompilerc                 C   s6   || _ |js| ¡  tt|jƒƒ|jg}t|ƒ| _d S r   )rÑ   r¾   r†   rC  r5   r   )r   ÚvarStoreDatarÑ   r¾   r   r   r   r   U  s
    zVarStoreCompiler.__init__c                 C   s   || j jd< d S )Nr”   rí   rî   r   r   r   rÁ   \  s    zVarStoreCompiler.setPosc                 C   s
   t | jƒS r   r&  rl   r   r   r   r   _  s    zVarStoreCompiler.getDataLengthc                 C   s   |  | j¡ d S r   r–  rê   r   r   r   r�   b  s    zVarStoreCompiler.toFileNr—  r   r   r   r   rÊ  T  s   rÊ  c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚROSConverterc                 C   s<   |\}}}|  |dt|ƒfdt|ƒfd|fg¡ | ¡  d S ©NZRegistryZOrderZ
Supplementr\  )r   r‘   ru   rˆ   Úregistryr£   Z
supplementr   r   r   rU  g  s    


ýþzROSConverter.xmlWritec                 C   s   |d |d t |d ƒfS rÍ  )r   rW  r   r   r   r%  s  s    zROSConverter.xmlReadNry  r   r   r   r   rÌ  f  s   rÌ  )é   ZmaxstackÚnumberNN)é   é   r†  )r¦  r¦  rÐ  ))rÑ  é   ZSyntheticBaserÐ  NN)r   Úversionr¦  NNr`  r¦  )rÑ  r   ra  )r#   ZFullNamer¦  NN))rÑ  é&   ÚFontNamer¦  NN)rE   Z
FamilyNamer¦  NN)rx   ÚWeightr¦  NN))rÑ  r   ZisFixedPitchrÐ  r   N))rÑ  r#   ZItalicAnglerÐ  r   N))rÑ  rE   ZUnderlinePositionrÐ  iœÿÿÿN))rÑ  rx   ZUnderlineThicknessrÐ  é2   N))rÑ  rw   Z	PaintTyperÐ  r   N))rÑ  é   ZCharstringTyperÐ  r#   N)rÑ  é   Ú
FontMatrixr*  gü©ñÒMbP?)é   ZUniqueIDrÐ  NNrw   ÚFontBBox))rÑ  é   ZStrokeWidthrÐ  r   N)é   ZXUIDr*  NN))rÑ  é   Ú
PostScriptr¦  NN))rÑ  é   ZBaseFontNamer¦  NN))rÑ  é   ZBaseFontBlendÚdeltaNN))rÑ  é   ÚCIDFontVersionrÐ  r   N))rÑ  é    ÚCIDFontRevisionrÐ  r   N))rÑ  é!   ÚCIDFontTyperÐ  r   N))rÑ  é"   ÚCIDCountrÐ  i"  Né   ry   rÐ  ))rÑ  é#   ZUIDBaserÐ  NNé   r¯  é   r•   )rÐ  rÐ  )rÑ  é%   )rÑ  é$   r˜   é   é   r”   Úblendrã  )râ  ÚvsindexrÐ  NNrm  )rÙ  Z
BlueValuesrä  NN)rÚ  Z
OtherBluesrä  NN)rÞ  ZFamilyBluesrä  NN)é	   ZFamilyOtherBluesrä  NN))rÑ  r÷  Z	BlueScalerÐ  g}?5^ºI¤?N))rÑ  é
   Z	BlueShiftrÐ  rÚ  N))rÑ  é   ZBlueFuzzrÐ  r   N)rø  ZStdHWrÐ  NN)rù  ZStdVWrÐ  NN))rÑ  rÑ  Z	StemSnapHrä  NN))rÑ  rÜ  Z	StemSnapVrä  NN))rÑ  rß  Z	ForceBoldrÐ  r   N))rÑ  rí  ZForceBoldThresholdrÐ  NN))rÑ  rï  ZlenIVrÐ  NN))rÑ  ró  ZLanguageGrouprÐ  r   N))rÑ  rð  ZExpansionFactorrÐ  g¸…ëQ¸®?N))rÑ  é   ZinitialRandomSeedrÐ  r   N)rÓ  ÚdefaultWidthXrÐ  r   N)rà  ÚnominalWidthXrÐ  r   Nrú  r³   c                 C   sŠ   t t| ƒƒD ]x}| | \}}}}}|d k	r,q|dkr<tƒ }n6|dkrLtƒ }n&|dkr\tƒ }n|dkrjd }ndsrt‚|||||f| |< qd S )N)rä  r*  rÐ  r¦  rm  F)rÿ   r5   rz  ro  rX  r0   )rÀ   r  rG  ru   rH  rI  rJ  r   r   r   ÚaddConvertersê  s    rý  c                   @   s   e Zd ZeeƒZdS )ÚTopDictDecompilerN)r   r   r   rK  r¤   Ú	operatorsr   r   r   r   rþ   	  s   rþ  c                   @   s   e Zd ZeeƒZdS )ÚPrivateDictDecompilerN)r   r   r   rK  r®   rÿ  r   r   r   r   r   	  s   r   c                   @   sb   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚDictCompilerr   Nc           	      C   s®   |rt |tƒst‚|d kr6t|dƒr6|j}|d k	s6t‚|| _|| _|| _|| _i }|jD ]J}t	||d ƒ}|d krrqX|j
| }| ||¡}||j |¡kršqX|||< qX|| _d S rÏ   )rq   rb   r0   r*   rP   r’  rc   rÑ   r£   rµ   Ú
convertersrÇ   Údefaultsrw  r¥   )	r   r’  rc   rÑ   rP   r¥   ru   rˆ   rJ  r   r   r   r   	  s(    


zDictCompiler.__init__c                 C   s   d S r   r   rî   r   r   r   rÁ   !	  s    zDictCompiler.setPosc                 C   s   t |  d¡ƒS )Nr   )r5   r†   rl   r   r   r   r   $	  s    zDictCompiler.getDataLengthc                 C   sâ   t   td| jj|¡ | j}g }| jjD ]®}| |¡}|d kr>q&| j| \}}t	|t
ƒr®t|ƒ}t|ƒ|ksrtdƒ‚t|ƒD ]0}	||	 }
||	 }t| d|
 ƒ}| ||ƒ¡ qznt| d| ƒ}| ||ƒ¡ | |¡ q&t|ƒ}|S )Nz-- compiling %s for %szvalue doesn't match arg typeZarg_)rÂ   rÃ   ré   r   r¥   r’  r£   rw  Úopcodesrq   r$  r5   r0   rÿ   rµ   r6   r   )r   Úreasonr¥   r¾   ru   rˆ   rG  ZargTyperN  r  rH  ÚvZ
arghandlerr   r   r   r†   '	  s*    

zDictCompiler.compilec                 C   s   |   d¡}| |¡ d S )Nr�   )r†   rÇ   )r   rh   r¾   r   r   r   r�   ?	  s    
zDictCompiler.toFilec                 C   sJ   t |tƒr>dd„ |D ƒ}| tdƒ¡ | ttƒ¡ t|ƒ}nt|ƒ}|S )Nc                 S   s   g | ]}t |ƒ‘qS r   ©ÚencodeNumberrh  r   r   r   rj  E	  s     z+DictCompiler.arg_number.<locals>.<listcomp>r   )rq   r]   r6   r  r   ÚblendOpr   )r   Únumr¾   Zdatumr   r   r   Ú
arg_numberC	  s    

zDictCompiler.arg_numberc                 C   s   t  | j |¡¡S r   )r   ÚencodeIntCFFrc   rŸ  )r   rM   r   r   r   Úarg_SIDM	  s    zDictCompiler.arg_SIDc                 C   s&   g }|D ]}|  |  |¡¡ qt|ƒS r   )r6   r  r   )r   rˆ   r¾   r
  r   r   r   Ú	arg_arrayP	  s    zDictCompiler.arg_arrayc                 C   sn   |sdS |d }t |tƒr&|  |¡}n@g }d}|D ]}| || ¡ |}q2g }|D ]}| t|ƒ¡ qRt|ƒS )Nó    r   )rq   r]   Úarg_delta_blendr6   r  r   )r   rˆ   Zval0r¾   rã   Úlastr  r
  r   r   r   Ú	arg_deltaV	  s    
zDictCompiler.arg_deltac                 C   s,  t |d ƒ}t |ƒ}|| d }|| jkrˆt| jd | ƒ}g }tt |ƒ|ƒ}|dkrXq†|d|… }|  |¡}	| |	¡ ||d… }q@n dg| }
dg| }d}d}||k ræ|| d }|| |
|< |}|| dd… ||< |d7 }q¤|
}|D ]}| |¡ qîdd„ |D ƒ}| t|ƒ¡ | tt	ƒ¡ |S )aM  A delta list with blend lists has to be *all* blend lists.

        The value is a list is arranged as follows::

                [
                        [V0, d0..dn]
                        [V1, d0..dn]
                        ...
                        [Vm, d0..dn]
                ]

        ``V`` is the absolute coordinate value from the default font, and ``d0-dn``
        are the delta values from the *n* regions. Each ``V`` is an absolute
        coordinate from the default font.

        We want to return a list::

                [
                        [v0, v1..vm]
                        [d0..dn]
                        ...
                        [d0..dn]
                        numBlends
                        blendOp
                ]

        where each ``v`` is relative to the previous default font value.
        r   r   Nc                 S   s   g | ]}t |ƒ‘qS r   r  rh  r   r   r   rj  ¨	  s     z0DictCompiler.arg_delta_blend.<locals>.<listcomp>)
r5   ÚmaxBlendStackr2   Úminr  rå   r6   r  r   r	  )r   rˆ   Z
numMastersZ	numBlendsZnumStackZnumBlendValuesrã   ZnumValZvalListZout1Z	firstListZ	deltaListr  ZprevValÚdefaultValueZrelValueListrm  r   r   r   r  g	  s<    





zDictCompiler.arg_delta_blend)N)r   r   r   r  r   rÁ   r   r†   r�   r  r  r  r  r  r   r   r   r   r  	  s   

r  c                 C   s"   t | tƒrt | ¡S t | ¡S d S r   )rq   re  r   ZencodeFloatr  )r
  r   r   r   r  ®	  s    

r  c                   @   s   e Zd ZeeƒZdd„ ZdS )ÚTopDictCompilerc                 C   sú  | j }g }| jjd kr¬t| jdƒrr| jjrrt| jdƒr<d }nt| jjƒ}|d krh| t|| jj| ƒ¡ n
|| jd< t| jdƒrÔ| jj	rÔ| jj	}t
|tƒsÔ| t||| ƒ¡ n(t| jdƒrÔ| jj}t|| ƒ}| |¡ t| jdƒ�r4| jj}t|ƒdk�r | jj}	| jjD ]}
| |	|
 j¡ �qt|| ƒ}| |¡ t| jdƒ�r†g }| jj}	| jjD ]}
| |	|
 ¡ �qVt||| |d�}| |¡ t| jd	ƒ�r¾| jj || ¡}| |¡ | | |¡¡ t| jd
ƒ�rö| jj || ¡}| |¡ | | |¡¡ |S )Nry   r†  r¯  r”   r)  r   r¨   rO   r˜   r•   )rP   r’  rj   r*   ry   rœ  r6   r�  r¥   r¯  rq   rr   r¬  r”   rÊ  r)  r5   r¨   r7  rÉ  rõ   r˜   r|   rå   r€   r•   )r   rc   rP   r„   ZcharsetCoderÙ   rË  ZvarStoreCompr  r±   ru   ZfdSelectCompr    ZcharStringsCompZfdArrayIndexCompÚprivCompr   r   r   r€   ¹	  sX    ÿ








zTopDictCompiler.getChildrenN)r   r   r   rM  r¤   r  r€   r   r   r   r   r  µ	  s   r  c                       s.   e Zd ZeeƒZd‡ fdd„	Zdd„ Z‡  ZS )ÚFontDictCompilerNc           	         sº   t t| ƒj||||d� g }| j}tt|jƒt|jƒ ƒD ]^}||jkrT| 	|¡ q:|j
 |¡}|d k	r~|j| }| ||¡}t||d ƒ|kr:| 	|¡ q:|r¶t dd t|ƒ¡ ¡ d S )NrO   z:Some CFF FDArray/FontDict keys were ignored upon compile: rb  )rç   r  r   r’  r8  Úsetr  r£   r¥   r6   r  rw  rV   rµ   rÂ   Úwarningrs  )	r   r’  rc   rÑ   rP   ÚignoredNamesru   rI  rJ  rè   r   r   r   ö	  s$    

ÿÿzFontDictCompiler.__init__c                 C   s>   g }t | jdƒr:| jj || ¡}| |¡ | | |¡¡ |S ©Nr•   )r*   r’  r•   r|   r6   rå   r€   )r   rc   r„   r  r   r   r   r€   
  s    
zFontDictCompiler.getChildren)N)	r   r   r   rM  r¤   r  r   r€   rë   r   r   rè   r   r  ó	  s   !r  c                   @   s(   e Zd ZeZeeƒZdd„ Zdd„ Z	dS )ÚPrivateDictCompilerc                 C   s"   || }||f| j jd< || _d S r  )rÑ   r¥   rÉ   )r   rÉ   rË   r  r   r   r   rÁ   %
  s    zPrivateDictCompiler.setPosc                 C   s*   g }t | jdƒr&| | jj || ¡¡ |S rô   )r*   r’  r6   r³   r|   )r   rc   r„   r   r   r   r€   *
  s    zPrivateDictCompiler.getChildrenN)
r   r   r   ÚmaxStackLimitr  rM  r®   r  rÁ   r€   r   r   r   r   r   
  s   r  c                   @   sH   e Zd Zddd„Zdd„ Zdd„ Zddd	„Zd
d„ Zdd„ Zdd„ Z	dS )ÚBaseDictNc                 C   sd   |d k|d kkst ‚i | _g | _|| _|d kr2d S || _|| _|d k	r`t td| jj	|¡ || _
d S )Nr÷   )r0   r¥   Ú	skipNamesrc   rû   rh   rÂ   rÃ   ré   r   rÝ   )r   rc   rh   rÝ   rP   r   r   r   r   2
  s    zBaseDict.__init__c                 C   sF   t   td| jjt|ƒ¡ |  | j| ¡}| |¡ | ¡ | _	|  
¡  d S )Nz    length %s is %d)rÂ   rÃ   ré   r   r5   ÚdecompilerClassrc   rk   ZgetDictr¥   ÚpostDecompile)r   r¾   Údecr   r   r   rk   ?
  s
    

zBaseDict.decompilec                 C   s   d S r   r   rl   r   r   r   r"  F
  s    zBaseDict.postDecompilec                 C   s   | j | |||d�S r  r	  r  r   r   r   r|   I
  s    zBaseDict.getCompilerc                 C   sˆ   |d d… |dd …   kr$dkr0n nt |ƒ‚| j |d ¡}|d krR| j |¡}|d krbt |ƒ‚| j| }| | |¡}t| ||ƒ |S )Nr#   éþÿÿÿÚ__)r€  r¥   rw  r  r  rV   r(   )r   ru   rˆ   rJ  r   r   r   Ú__getattr__L
  s    (
zBaseDict.__getattr__c                 C   sŠ   | j D ]F}|| jkrqt| |d ƒ}|d kr4|dkr4q| j| }| |||¡ qt| jƒt| j ƒ }|r†| dd t	|ƒ¡ ¡ | 
¡  d S )Nry   zsome keys were ignored: %srb  )r£   r   rµ   r  rU  r  r¥   r  rs  r8  r�   )r   r‘   ru   rˆ   rJ  r  r   r   r   r�   ]
  s    



ÿzBaseDict.toXMLc                 C   s*   | j | }| |||| ¡}t| ||ƒ d S r   )r  r%  r(   )r   ru   r›   rœ   rJ  rˆ   r   r   r   r—   v
  s    
zBaseDict.fromXML)NNNN)N)
r   r   r   r   rk   r"  r|   r&  r�   r—   r   r   r   r   r  1
  s   

r  c                       sj   e Zd ZdZeeƒZeeƒZe	Z
eeƒZeZd‡ fdd„	Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z‡  ZS )r–   ad  The ``TopDict`` represents the top-level dictionary holding font
    information. CFF2 tables contain a restricted set of top-level entries
    as described `here <https://docs.microsoft.com/en-us/typography/opentype/spec/cff2#7-top-dict-data>`_,
    but CFF tables may contain a wider range of information. This information
    can be accessed through attributes or through the dictionary returned
    through the ``rawDict`` property:

    .. code:: python

            font = tt["CFF "].cff[0]
            font.FamilyName
            # 'Linux Libertine O'
            font.rawDict["FamilyName"]
            # 'Linux Libertine O'

    More information is available in the CFF file's private dictionary, accessed
    via the ``Private`` property:

    .. code:: python

            tt["CFF "].cff[0].Private.BlueValues
            # [-15, 0, 515, 515, 666, 666]

    Nc                    s^   t t| ƒj||||d� || _|| _|rFttƒ| _|ƒ | _t	tƒ| _
nttƒ| _t	tƒ| _
d S r  )rç   r–   r   rj   rg   rO  r¢   r  ry   r¡   r£   r¤   )r   rc   rh   rÝ   rg   rj   rP   rè   r   r   r   œ
  s    	

zTopDict.__init__c                 C   s   | j S )z.Returns a list of glyph names in the CFF font.)ry   rl   r   r   r   re   °
  s    zTopDict.getGlyphOrderc                 C   sH   | j  d¡}|d krd S | j |¡ | jr8t| jƒ| _nt| jƒ| _d S rö   )r¥   rw  rh   r[   rû   rü   r.  rý   )r   rÝ   r   r   r   r"  ´
  s    zTopDict.postDecompilec                 C   sV   t | dƒr|  ¡  t | dƒr$dg| _t | dƒr8t | dƒsFddddg| _t | |¡ d S )Nr¨   r†  r¯  ræ  rè  rê  rì  )r*   ÚdecompileAllCharStringsr   r  r�   )r   r‘   r   r   r   r�   ¿
  s    

üzTopDict.toXMLc                 C   sD   t | j ¡ ƒD ]0\}}z| ¡  W q   t d|¡ ‚ Y qX qd S )NzError in charstring %s)Ú	enumerater¨   ro   rk   rÂ   Úerror)r   r  r7   r   r   r   r'  Ï
  s    zTopDict.decompileAllCharStringsc                 C   sp   d }| j  ¡ D ]0}| | j ¡}|d k	r|d k	r:t||ƒ}q|}q|d kr^| jd d d … | _ntt|ƒƒ| _d S )NrÝ  )r¨   ro   Z
calcBoundsr   r  rÝ  r]   r   )r   ZfontBBoxr7   Zboundsr   r   r   rz   Ø
  s    zTopDict.recalcFontBBox)NNNNNN)r   r   r   r½   rO  r¤   r  rP  r  r  r
  r¡   r£   rþ  r!  r   re   r"  r�   r'  rz   rë   r   r   rè   r   r–   |
  s$         ù	r–   c                       sL   e Zd Zi ZeeƒZeZddddgZ	dgZ
eZd
‡ fdd„	Zdd	„ Z‡  ZS )r«   rÖ  rÛ  r×  r•   Nc                    s,   t t| ƒj||||d� || _|  |¡ d S r  )rç   r«   r   r™   r¬   )r   rc   rh   rÝ   rg   rP   r™   rè   r   r   r     s    	zFontDict.__init__c                 C   s&   |r| j | _d| _n| j| _d| _d S )NTF)Ú	orderCFF2r£   rû   ÚorderCFFr¿   r   r   r   r¬     s
    zFontDict.setCFF2)NNNNNN)r   r   r   r  rP  r¤   r  r  r
  r+  r*  rþ  r!  r   r¬   rë   r   r   rè   r   r«   è
  s         ùr«   c                       sT   e Zd ZeeƒZeeƒZeeƒZ	e
ZeZd‡ fdd„	Zedd„ ƒZd	dd„Z‡  ZS )
r  Nc                    s\   t t| ƒj||||d� || _|rDttƒ| _ttƒ| _d  | _	| _
nttƒ| _ttƒ| _d S r  )rç   r  r   r™   rO  r­   r  r¡   r£   rü  rû  r®   )r   rc   rh   rÝ   rP   r™   rè   r   r   r   )  s    


zPrivateDict.__init__c                 C   s   | j S r   )rû   rl   r   r   r   r3   6  s    zPrivateDict.in_cff2c                 C   s.   |d krt | dƒr| j}nd}| j |¡}|S )Nrö  r   )r*   rö  r™   r(  )r   Úvir'  r   r   r   r(  :  s    
zPrivateDict.getNumRegions)NNNNN)N)r   r   r   rO  r®   r  rP  r  r¡   r£   r   r!  r  r
  r   Úpropertyr3   r(  rë   r   r   rè   r   r  "  s   
r  c                   @   sJ   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )rb   zSID -> string mapping.Nc                 C   s.   |d krg }ndd„ t |dd�D ƒ}|| _d S )Nc                 S   s   g | ]}t |d d�‘qS )r×   rØ   rJ   rK   r   r   r   rj  M  s     z+IndexedStrings.__init__.<locals>.<listcomp>FrO   )r^   rc   )r   rh   rc   r   r   r   r   I  s    zIndexedStrings.__init__c                 C   s   t | d | dd�S )NFrO   )rß   rl   r   r   r   r|   P  s    zIndexedStrings.getCompilerc                 C   s
   t | jƒS r   )r5   rc   rl   r   r   r   rm   S  s    zIndexedStrings.__len__c                 C   s"   |t k rt| S | j|t   S d S r   )ÚcffStandardStringCountÚcffStandardStringsrc   )r   r¦  r   r   r   rv   V  s    zIndexedStrings.__getitem__c                 C   sn   t | dƒs|  ¡  t|dd�}|tkr0t| }n:|| jkrF| j| }n$t| jƒt }| j |¡ || j|< |S )NÚstringMappingr×   rØ   )	r*   ÚbuildStringMappingr
   ÚcffStandardStringMappingr0  r5   rc   r.  r6   )r   rM   r¦  r   r   r   rŸ  \  s    



zIndexedStrings.getSIDc                 C   s   | j S r   rà   rl   r   r   r   Ú
getStringsj  s    zIndexedStrings.getStringsc                 C   s2   i | _ tt| jƒƒD ]}|t | j | j| < qd S r   )r0  rÿ   r5   rc   r.  rC   r   r   r   r1  m  s    z!IndexedStrings.buildStringMapping)N)r   r   r   r½   r   r|   rm   rv   rŸ  r3  r1  r   r   r   r   rb   E  s   
rb   r‘  ÚspaceZexclamZquotedblZ
numbersignÚdollarÚpercentZ	ampersandZ
quoterightZ	parenleftZ
parenrightZasteriskÚplusÚcommaZhyphenZperiodÚslashÚzeroÚoneÚtwoÚthreeÚfourÚfiveÚsixÚsevenÚeightÚnineÚcolonÚ	semicolonÚlessÚequalZgreaterÚquestionÚatÚArI   ÚCÚDÚEÚFÚGÚHÚIÚJÚKÚLÚMÚNÚOÚPÚQÚRÚSÚTÚUÚVÚWÚXÚYÚZZbracketleftZ	backslashZbracketrightZasciicircumZ
underscoreZ	quoteleftÚaÚbr¸   rF  ÚeÚfr·   Úhr  ÚjÚkrN  r¾  r�  ÚoÚpÚqÚrrM   ÚtÚur  ÚwÚxÚyÚzZ	braceleftÚbarZ
bracerightZ
asciitildeZ
exclamdownÚcentZsterlingÚfractionÚyenZflorinÚsectionÚcurrencyZquotesingleZquotedblleftZguillemotleftZguilsinglleftZguilsinglrightÚfiÚflZendashÚdaggerZ	daggerdblZperiodcenteredZ	paragraphZbulletZquotesinglbaseZquotedblbaseZquotedblrightZguillemotrightÚellipsisZperthousandZquestiondownZgraveÚacuteZ
circumflexÚtildeZmacronZbreveZ	dotaccentZdieresisÚringZcedillaZhungarumlautZogonekZcaronZemdashZAEZordfeminineZLslashÚOslashZOEZordmasculineZaeZdotlessiZlslashÚoslashZoeZ
germandblsZonesuperiorZ
logicalnotÚmuZ	trademarkZEthZonehalfZ	plusminusZThornZ
onequarterÚdivideZ	brokenbarZdegreeÚthornZthreequartersZtwosuperiorÚ
registeredÚminusÚethÚmultiplyZthreesuperiorÚ	copyrightÚAacuteZAcircumflexZ	AdieresisÚAgraveÚAringÚAtildeZCcedillaÚEacuteZEcircumflexZ	EdieresisÚEgraveÚIacuteZIcircumflexZ	IdieresisÚIgraveÚNtildeÚOacuteZOcircumflexZ	OdieresisÚOgraveÚOtildeÚScaronÚUacuteZUcircumflexZ	UdieresisÚUgraveÚYacuteZ	YdieresisZZcaronÚaacuteZacircumflexZ	adieresisÚagraveÚaringÚatildeZccedillaÚeacuteZecircumflexZ	edieresisÚegraveÚiacuteZicircumflexZ	idieresisÚigraveÚntildeÚoacuteZocircumflexZ	odieresisÚograveÚotildeÚscaronÚuacuteZucircumflexZ	udieresisÚugraveÚyacuteZ	ydieresisZzcaronZexclamsmallZHungarumlautsmallZdollaroldstyleZdollarsuperiorZampersandsmallZ
AcutesmallZparenleftsuperiorZparenrightsuperiorZtwodotenleaderZonedotenleaderZzerooldstyleZoneoldstyleZtwooldstyleZthreeoldstyleZfouroldstyleZfiveoldstyleZsixoldstyleZsevenoldstyleZeightoldstyleZnineoldstyleZcommasuperiorZthreequartersemdashZperiodsuperiorZquestionsmallZ	asuperiorZ	bsuperiorZcentsuperiorZ	dsuperiorZ	esuperiorZ	isuperiorZ	lsuperiorZ	msuperiorZ	nsuperiorZ	osuperiorZ	rsuperiorZ	ssuperiorZ	tsuperiorÚffÚffiÚfflZparenleftinferiorZparenrightinferiorZCircumflexsmallZhyphensuperiorZ
GravesmallZAsmallZBsmallZCsmallZDsmallZEsmallZFsmallZGsmallZHsmallZIsmallZJsmallZKsmallZLsmallZMsmallZNsmallZOsmallZPsmallZQsmallZRsmallZSsmallZTsmallZUsmallZVsmallZWsmallZXsmallZYsmallZZsmallZcolonmonetaryZ	onefittedZrupiahZ
TildesmallZexclamdownsmallZcentoldstyleZLslashsmallZScaronsmallZZcaronsmallZDieresissmallZ
BrevesmallZ
CaronsmallZDotaccentsmallZMacronsmallZ
figuredashZhypheninferiorZOgoneksmallZ	RingsmallZCedillasmallZquestiondownsmallZ	oneeighthZthreeeighthsZfiveeighthsZseveneighthsZonethirdZ	twothirdsZzerosuperiorZfoursuperiorZfivesuperiorZsixsuperiorZsevensuperiorZeightsuperiorZninesuperiorZzeroinferiorZoneinferiorZtwoinferiorZthreeinferiorZfourinferiorZfiveinferiorZsixinferiorZseveninferiorZeightinferiorZnineinferiorZcentinferiorZdollarinferiorZperiodinferiorZcommainferiorZAgravesmallZAacutesmallZAcircumflexsmallZAtildesmallZAdieresissmallZ
AringsmallZAEsmallZCcedillasmallZEgravesmallZEacutesmallZEcircumflexsmallZEdieresissmallZIgravesmallZIacutesmallZIcircumflexsmallZIdieresissmallZEthsmallZNtildesmallZOgravesmallZOacutesmallZOcircumflexsmallZOtildesmallZOdieresissmallZOEsmallZOslashsmallZUgravesmallZUacutesmallZUcircumflexsmallZUdieresissmallZYacutesmallZ
ThornsmallZYdieresissmallz001.000z001.001z001.002z001.003ZBlackZBoldZBookZLightZMediumZRegularZRomanZSemiboldi‡  éå   é¦   éW   )Šr½   ZfontTools.miscr   r   ZfontTools.misc.arrayToolsr   r   ZfontTools.misc.textToolsr   r   r   r	   r
   r   ZfontTools.ttLibr   ZfontTools.ttLib.tables.otBaser   r   ZfontTools.ttLib.tablesr   r   Úior   rY   Úloggingrc  rÃ   Ú	getLoggerr   rÂ   rU   r  Ú	Exceptionr   r   r   ÚobjectrD   r{   rÆ   rÎ   rß   rÄ   rì   rï   ró   rõ   r^   rf   r  r`   r§   r  r)  r¨   rþ   rý   rü   rÜ   rÛ   rÚ   rA  rC  rD  rK  rM  r¡   rO  rP  rQ  rX  r^  rf  rn  ro  rz  r{  r~  r‚  rƒ  r…  r�  rœ  rž  r   r“  r”  rˆ  r‰  r¬  r°  rµ  r¶  r­  r®  rÀ  rÁ  rÃ  rÅ  rÇ  rÈ  rÉ  rÊ  rÌ  r¤   r¢   rt  r	  r®   r­   rý  ZDictDecompilerrþ  r   r  r  r  r  r  r  r–   r«   r  rb   r/  r.  r5   r0   r2  rÿ   Z_ir‹  r˜  rŒ  r™  r�  rš  r   r   r   r   Ú<module>   s”   

V  o2L$)	Hk8$1@ ==%>
"!Û*ùûã"ûé '>-Kl:#2€ € € ù   € › i€ Ú *©Z