o
    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s!t|d}d}|r%i nd }t|}t|jD ]}t|f||d|}	||	 q0|dsP|rR|	  d S d S 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   p/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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 q%|	| |
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   tell_saveseekr'   structpackgetvaluer   )r   r   r   finalr   offsets_offsetoffsetsr   r   r   r   save:   s"   


"zTTCollection.save
c           	      K   s   ddl m} |j||d}|r)ddlm} d|dd d }|jd|d n|d |  |  | j	D ]}|j
|fd	d
i| |  q9|d |  |  d S )Nr   )	xmlWriter)
newlinestr)version.r)   ttCollection)ttLibVersionwriteVersionF)fontTools.miscr6   	XMLWriter	fontToolsr8   joinsplitbegintagnewliner   _saveXMLendtagr   )	r   
fileOrPathr7   r<   r   r6   writerr8   r   r   r   r   saveXMLX   s   



zTTCollection.saveXMLc                 C   
   | j | S r    r   r   itemr   r   r   __getitem__p      
zTTCollection.__getitem__c                 C   s   || j |< d S r    rJ   )r   rL   r$   r   r   r   __setitem__s   s   zTTCollection.__setitem__c                 C   rI   r    rJ   rK   r   r   r   __delitem__v   rN   zTTCollection.__delitem__c                 C   
   t | jS r    )r*   r   r!   r   r   r   __len__y   rN   zTTCollection.__len__c                 C   rQ   r    )iterr   r!   r   r   r   __iter__|   rN   zTTCollection.__iter__)NF)T)r5   T)__name__
__module____qualname____doc__r   r"   r&   r   r4   rH   rM   rO   rP   rR   rT   r   r   r   r   r   
   s    

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