B
    Jd                 @   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'.
   )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   s  t |}|| j }xnt|j|jfdD ]V\}}i }x2t|D ]$\}\}	}
}|rb| j|	 }n
||	}||kr| j	d|  qB|
dk rn|
dkr|t |d k}|r|r|}q|jd d }n||d  d }||kst
d||kr| j	d|  |}|| }
ndd	lm} |d
||
f ||||
  }t ||
ksPt
t|dd}|rB|||< qBW |rz|| _q(|| _q(W d S )N)FTz$textOffset > totalLength; %r skippedi   r   r      zentries not sorted by offsetz*nextTextOffset > totalLength; %r truncated)ttLibz&%r textLength (%d) must not be > 32768zutf-8)encoding)len
indextablezipindicesextra_indices	enumerateextrasZgetGlyphNamelogwarningAssertionErrorZ	fontToolsr   Z
TTLibErrorr   extraProgramsglyphPrograms)selfdatattFontZtotalLengthr   r   ZisExtraZprogramsiZglyphID
textLengthZ
textOffsetnameZisLastZnextTextOffsetr   text r!   Q/var/www/html/venv/lib/python3.7/site-packages/fontTools/ttLib/tables/T_S_I__1.py	decompile   sL    





ztable_T_S_I__1.decompilec             C   sb  t | dsi | _i | _d}|| j }| }g }xtt|D ]r}t|d rV|d }|| }|| jkr|t| j| dd}nd}t|}	|	dkrd}	|||	t|f || }q>W g }
t	| j
 }xtt|D ]z}t|d r|d }|| \}}|| jkrt| j| dd}nd}t|}	|	dkr2d}	|
||	t|f || }qW |||
 |S )Nr       r      zutf-8)r   i   )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"   compileO   sF    



ztable_T_S_I__1.compilec             C   s   t | j }|  xf|D ]^}| j| }|s0q|jd|d |  ||dd |  |d |  |  qW t | j }xf|D ]^}| j| }|sq|jd|d |  ||dd |  |d |  |  qW d S )NglyphProgram)r   
extraProgram)	r)   r   keysnewlineZbegintagZwrite_noindentreplaceZendtagr   )r   writerr   namesr   r    Zextra_namesr!   r!   r"   toXMLx   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   r0   r1   r   r/   r   r2   )r&   r   r   r   r5   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#   r.   r8   r?   r!   r!   r!   r"   r      s   =)r   N)
__doc__ r   ZfontTools.misc.loggingToolsr   ZfontTools.misc.textToolsr   r   r   r   r!   r!   r!   r"   <module>   s   