a
    ¥Q•h{  ã                   @   sV   d dl mZ d dlmZmZ d dlmZ d dlZd dlZe 	e
¡ZG dd„ deƒZdS )é    )ÚTTFont)ÚreadTTCHeaderÚwriteTTCHeader)ÚBytesIONc                   @   sn   e Zd ZdZddd„Zdd„ Zdd	„ Zd
d„ Zddd„Zddd„Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )ÚTTCollectionaç  Object representing a TrueType Collection / OpenType Collection.
    The main API is self.fonts being a list of TTFont instances.

    If shareTables is True, then different fonts in the collection
    might point to the same table object if the data for the table was
    the same in the font file.  Note, however, that this might result
    in suprises and incorrect behavior if the different fonts involved
    have different GlyphOrder.  Use only if you know what you are doing.
    NFc           
      K   s    g  }| _ |d u rd S d|vs&J |ƒ‚d}t|dƒsBt|dƒ}d}|rJi nd }t|ƒ}t|jƒD ]$}t|f||dœ|¤Ž}	| |	¡ q`| d¡sœ|rœ| 	¡  d S )NÚ
fontNumberFÚreadÚrbT)r   Ú_tableCacheÚlazy)
ÚfontsÚhasattrÚopenr   ÚrangeÚnumFontsr   ÚappendÚgetÚclose)
ÚselfÚfileÚshareTablesÚkwargsr   ÚcloseStreamÚ
tableCacheÚheaderÚiÚfont© r   úU/var/www/sistema_ama/venv/lib/python3.9/site-packages/fontTools/ttLib/ttCollection.pyÚ__init__   s    


zTTCollection.__init__c                 C   s   | S ©Nr   ©r   r   r   r   Ú	__enter__0   s    zTTCollection.__enter__c                 C   s   |   ¡  d S r    )r   )r   ÚtypeÚvalueÚ	tracebackr   r   r   Ú__exit__3   s    zTTCollection.__exit__c                 C   s   | j D ]}| ¡  qd S r    )r   r   )r   r   r   r   r   r   6   s    
zTTCollection.closeTc                 C   sÂ   t |dƒsd}t|dƒ}n
|}tƒ }|r,i nd}t|t| jƒƒ}g }| jD ],}| | ¡ ¡ |j||d� | 	dd¡ qJ| 	|¡ | 
tjdt| jƒ g|¢R Ž ¡ |r¶| 
| ¡ ¡ | ¡  dS )z•Save the font to disk. Similarly to the constructor,
        the 'file' argument can be either a pathname or a writable
        file object.
        ÚwriteNÚwb)r   r   é   z>%dL)r   r   r   r   Úlenr   r   ÚtellÚ_saveÚseekr'   ÚstructÚpackÚgetvaluer   )r   r   r   Úfinalr   Zoffsets_offsetZoffsetsr   r   r   r   Úsave:   s"    


"zTTCollection.saveÚ
c           	      K   s´   ddl m} |j||d�}|rRddlm} d | d¡d d… ¡}|jd|d� n
| d¡ | ¡  | ¡  | j	D ]"}|j
|fd	d
i|¤Ž | ¡  qr| d¡ | ¡  | ¡  d S )Nr   )Ú	xmlWriter)Ú
newlinestr)ÚversionÚ.r)   ZttCollection)ÚttLibVersionÚwriteVersionF)ÚfontTools.miscr4   Ú	XMLWriterÚ	fontToolsr6   ÚjoinÚsplitÚbegintagÚnewliner   Ú_saveXMLÚendtagr   )	r   Ú
fileOrPathr5   r9   r   r4   Úwriterr6   r   r   r   r   ÚsaveXMLX   s    



zTTCollection.saveXMLc                 C   s
   | j | S r    ©r   ©r   Úitemr   r   r   Ú__getitem__p   s    zTTCollection.__getitem__c                 C   s   || j |< d S r    rF   )r   rH   r$   r   r   r   Ú__setitem__s   s    zTTCollection.__setitem__c                 C   s
   | j | S r    rF   rG   r   r   r   Ú__delitem__v   s    zTTCollection.__delitem__c                 C   s
   t | jƒS r    )r*   r   r!   r   r   r   Ú__len__y   s    zTTCollection.__len__c                 C   s
   t | jƒS r    )Úiterr   r!   r   r   r   Ú__iter__|   s    zTTCollection.__iter__)NF)T)r3   T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   r&   r   r2   rE   rI   rJ   rK   rL   rN   r   r   r   r   r   
   s   



r   )ÚfontTools.ttLib.ttFontr   ÚfontTools.ttLib.sfntr   r   Úior   r.   ÚloggingÚ	getLoggerrO   ÚlogÚobjectr   r   r   r   r   Ú<module>   s   
