a
    èÝEb_  ã                   @   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   Z_tableCacheZlazy)
ÚfontsÚhasattrÚopenr   ÚrangeZnumFontsr   ÚappendÚgetÚclose)
ÚselfÚfileÚshareTablesÚkwargsr
   ZcloseStreamÚ
tableCacheÚheaderÚiÚfont© r   ú\/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/fontTools/ttLib/ttCollection.pyÚ__init__   s    


zTTCollection.__init__c                 C   s   | S ©Nr   ©r   r   r   r   Ú	__enter__1   s    zTTCollection.__enter__c                 C   s   |   ¡  d S r   )r   )r   ÚtypeÚvalueÚ	tracebackr   r   r   Ú__exit__4   s    zTTCollection.__exit__c                 C   s   | j D ]}| ¡  qd S r   )r
   r   )r   r   r   r   r   r   7   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   ÚtellZ_saveÚseekr#   ÚstructÚpackÚgetvaluer   )r   r   r   Úfinalr   Zoffsets_offsetÚ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)ZttLibVersionÚwriteVersionF)ZfontTools.miscr0   Z	XMLWriterZ	fontToolsr2   ÚjoinÚsplitZbegintagÚnewliner
   Z_saveXMLZendtagr   )	r   Z
fileOrPathr1   r4   r   r0   Úwriterr2   r   r   r   r   ÚsaveXMLY   s    



zTTCollection.saveXMLc                 C   s
   | j | S r   ©r
   ©r   Úitemr   r   r   Ú__getitem__q   s    zTTCollection.__getitem__c                 C   s   || j |< d S r   r:   )r   r<   r    r   r   r   Ú__setitem__t   s    zTTCollection.__setitem__c                 C   s
   | j | S r   r:   r;   r   r   r   Ú__delitem__w   s    zTTCollection.__delitem__c                 C   s
   t | jƒS r   )r&   r
   r   r   r   r   Ú__len__z   s    zTTCollection.__len__c                 C   s
   t | jƒS r   )Úiterr
   r   r   r   r   Ú__iter__}   s    zTTCollection.__iter__)NF)T)r/   T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r"   r   r.   r9   r=   r>   r?   r@   rB   r   r   r   r   r   
   s   

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