a
    w=ic_                     @   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_tableCachelazy)
fontshasattropenr   rangeZnumFontsr   appendgetclose)
selffileshareTableskwargsr   ZcloseStream
tableCacheheaderifont r   m/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/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 )zSave 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.miscr1   Z	XMLWriterZ	fontToolsr3   joinsplitZbegintagnewliner   Z_saveXMLZendtagr   )	r   Z
fileOrPathr2   r5   r   r1   writerr3   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)r0   T)__name__
__module____qualname____doc__r   r   r#   r   r/   r:   r>   r?   r@   rA   rC   r   r   r   r   r   
   s   

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