a
    ZXh                     @   sH   d Z ddlmZ ddlmZ ddlmZmZmZ G dd deejZ	dS )	a]   TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT)
tool to store its hinting source data.

TSI1 contains the text of the glyph programs in the form of low-level assembly
code, as well as the 'extra' programs 'fpgm', 'ppgm' (i.e. 'prep'), and 'cvt'.

See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables
   )DefaultTable    )LogMixin)strjointobytestostrc                   @   s>   e Zd ZdddddZdZdd Zd	d
 Zdd Zdd ZdS )table_T_S_I__1ZppgmcvtreservedZfpgm)i  i  i  i  ZTSI0c                 C   sz  t |}|| j }t|j|jfdD ]N\}}i }t|D ]"\}\}	}
}|rZ| j|	 }n
||	}||kr~| j	d|  q:|
dk rn|
dkr|t |d k}|r|r|}q|jd d }n||d  d }||ksJ d||kr| j	d|  |}|| }
ndd	l
m} |d
||
f ||||
  }t ||
ksFJ t|dd}|r:|||< q:|rn|| _q$|| _q$d S )N)FTz$textOffset > totalLength; %r skipped   r   r      zentries not sorted by offsetz*nextTextOffset > totalLength; %r truncated)ttLibz&%r textLength (%d) must not be > 32768utf-8encoding)len
indextablezipindicesextra_indices	enumerateextrasZgetGlyphNamelogwarningZ	fontToolsr   Z
TTLibErrorr   extraProgramsglyphPrograms)selfdatattFontZtotalLengthr   r   ZisExtraZprogramsiZglyphID
textLengthZ
textOffsetnameZisLastZnextTextOffsetr   text r#   d/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/site-packages/fontTools/ttLib/tables/T_S_I__1.py	decompile   sR    





ztable_T_S_I__1.decompilec                 C   sZ  t | dsi | _i | _d}|| j }| }g }tt|D ]r}t|d rT|d }|| }|| jv rzt| j| dd}nd}t|}	|	dkrd}	|||	t|f || }q<g }
t	| j
 }tt|D ]z}t|d r|d }|| \}}|| jv rt| j| dd}nd}t|}	|	dkr,d}	|
||	t|f || }q|||
 |S )Nr       r      r   r   r   )hasattrr   r   r   ZgetGlyphOrderranger   r   appendsortedr   itemsset)r   r   r   r   Z
glyphNamesr   r   r!   r"   r    r   codescoder#   r#   r$   compileU   sJ    





ztable_T_S_I__1.compilec                 C   s   t | j }|  |D ]^}| j| }|s.q|jd|d |  ||dd |  |d |  |  qt | j }|D ]^}| j| }|sq|jd|d |  ||dd |  |d |  |  qd S )NglyphProgram)r!   
extraProgram)	r+   r   keysnewlineZbegintagZwrite_noindentreplaceZendtagr   )r   writerr   namesr!   r"   Zextra_namesr#   r#   r$   toXML   s2    




ztable_T_S_I__1.toXMLc                 C   sp   t | dsi | _i | _t|ddd}d|dd }|dkrV|| j|d < n|dkrl|| j|d < d S )	Nr   r2   r3   r   r1   r!   r4   )r(   r   r   r   r7   splitjoin)r   r!   attrscontentr   linesr"   r#   r#   r$   fromXML   s    
ztable_T_S_I__1.fromXMLN)	__name__
__module____qualname__r   r   r%   r0   r:   rA   r#   r#   r#   r$   r      s   A-r   N)
__doc__ r   ZfontTools.misc.loggingToolsr   ZfontTools.misc.textToolsr   r   r   r   r#   r#   r#   r$   <module>   s   	