o
    _h!                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ ddlm	Z	 ddlm
Z
 d dlZd	Zd
ZdZdZdZdZG dd dZG dd deZG dd de	j	ZdS )    )sstruct)floatToFixedToStr)safeEval)partial   )DefaultTable)grUtilsNz/
    >        # big endian
    version: 16.16F
zR
    >
    version: 16.16F
    compression:L    # compression scheme or reserved 
zz
    >
    attNum:     B    # Attribute number of first attribute
    num:        B    # Number of attributes in this run
zz
    >
    attNum:     H    # Attribute number of first attribute
    num:        H    # Number of attributes in this run
ao  
    >
    subboxBitmap:   H    # Which subboxes exist on 4x4 grid
    diagNegMin:     B    # Defines minimum negatively-sloped diagonal (si)
    diagNegMax:     B    # Defines maximum negatively-sloped diagonal (sa)
    diagPosMin:     B    # Defines minimum positively-sloped diagonal (di)
    diagPosMax:     B    # Defines maximum positively-sloped diagonal (da)
a  
    >
    left:           B    # xi
    right:          B    # xa
    bottom:         B    # yi
    top:            B    # ya
    diagNegMin:     B    # Defines minimum negatively-sloped diagonal (si)
    diagNegMax:     B    # Defines maximum negatively-sloped diagonal (sa)
    diagPosMin:     B    # Defines minimum positively-sloped diagonal (di)
    diagPosMax:     B    # Defines maximum positively-sloped diagonal (da)
c                   @      e Zd ZdS )_ObjectN__name__
__module____qualname__ r   r   S/var/www/html/myenv/lib/python3.10/site-packages/fontTools/ttLib/tables/G__l_a_t.pyr
   8       r
   c                   @   r	   )_DictNr   r   r   r   r   r   <   r   r   c                   @   sZ   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )table_G__l_a_tzsGraphite Glyph Attributes table

    See also https://graphite.sil.org/graphite_techAbout#graphite-font-tables
    Nc                 C   s   t j | | d| _d S Nr   )r   __init__scheme)selftagr   r   r   r   F   s   
ztable_G__l_a_t.__init__c                 C   s   t t||  tt| jdd| _| jdkrt| jtd}n,| jdkr+t| jt	d}n| jdkrJt
|\}| _t t||  | jd@ dk| _| j}|d }i | _d	}t||dd  D ]\}}|||| | j||< |d7 }q\d S )
N   )precisionBitsffffff?fmt333333@      @r   Glocr   )r   unpack2Glat_format_0floatr   versionr   decompileAttributes12Glat_format_1_entryGlat_format_23_entryr   
decompressr   Glat_format_3compressionhasOctaboxesdecompileAttributes3
attributeszipgetGlyphName)r   datattFontdecodergloccountser   r   r   	decompileJ   s$   



ztable_G__l_a_t.decompilec                 C   s   t  }t|dkrFt||t \}}t|j|j|j }t|d|j kr@t	d|j |}|
t|| |d|j d  }t|dks	|S )N      >%dh)r   lenr   r!   r
   rangeattNumnumstructunpack_fromupdater.   )r   r0   r   r-   r6   keysvalsr   r   r   r%   ^   s   z$table_G__l_a_t.decompileAttributes12c                 C   s   | j r5tt|t \}}t|jd}g |_t	|D ]}t
|dkr4tt|t \}}|j| q| |t}| j rA||_|S )N1   )r+   r   r!   Glat_format_3_octabox_metricsr
   binsubboxBitmapr4   subboxesr<   r;   Glat_format_3_subbox_entryappendr%   r'   octabox)r   r0   onumsubbsubboxattrsr   r   r   r,   i   s   z#table_G__l_a_t.decompileAttributes3c                 C   s   t t| }| jdkrt| jtd}n(| jdkr t| jtd}n| jdkr;| jd> | jr.dnd | _	t t
| }| j}g }tt| jD ]}|t| ||| j|| 7 }qD|t| |d | | jdkrtt| j|}|S )	Nr   r   r   r      r   r   r    )r   packr"   r$   r   compileAttributes12r&   r   r+   r*   r)   compileAttributes3r<   r;   r-   rK   r/   setr   compress)r   r1   r0   encoderglocsnr   r   r   compiley   s$   



ztable_G__l_a_t.compilec                 C   sX   d}t |D ]"}|t||d |d dtjdt|d  g|d R   7 }q|S )N    r   r   )r=   r>   r:   r9   )r   entriesr   rS   r?   r;   )r   rQ   r   r0   r6   r   r   r   rT      s   z"table_G__l_a_t.compileAttributes12c                 C   sb   | j r'|j}tt|}t|jd}t|D ]}|tt	|j
| 7 }qnd}|| |t S )NrD    )r+   rL   r   rS   rF   rG   rH   r4   r<   rJ   rI   rT   r'   )r   rQ   rM   r0   rN   rO   r   r   r   rU      s   z!table_G__l_a_t.compileAttributes3c                    s  |j d| j| jd |  t| j  fdddD ]\}}|jd|d |  t|dr|j	}t
t\}}}i }	|D ]}
|
d	krEq>d
t||
d d |	|
< q>d|j|	d< |jdi |	 |  t
t\}}}|jD ]#}i }	|D ]}
d
t||
d d |	|
< qy|j di |	 |  qs|d |  t| D ]\}
}|j d|
|d |  q|d |  qd S )Nr$   )r$   compressionSchemec                    s     | d S r   )
getGlyphID)xr1   r   r   <lambda>   s    z&table_G__l_a_t.toXML.<locals>.<lambda>)keyglyph)namerL   rH   z{:.3f}%      Y@   z{:0X}bitmap	octaboxes	attribute)indexvalue)rj   )rL   )	simpletagr$   r   newlinesortedr-   itemsbegintaghasattrrL   r   	getformatrF   formatgetattrrH   rJ   rI   endtag)r   writerr1   rZ   arM   formatstringnamesfixesrC   kr5   vr   rb   r   toXML   sJ   








ztable_G__l_a_t.toXMLc                 C   s  |dkrt t|d | _tt|d | _|dkrd S t| ds$i | _|d }t }|D ]}t|t	s5q-|\}}}	|dkrStt|d }
tt|d }|||
< q-|d	krd
| _
t }t|d d|_g |_|d= | D ]\}
}t||
tt |d d d d d  qo|	D ]3}t|t	sq|\}}}	t }| D ]\}
}t||
tt |d d d d d  q|j| q||_q-|| j|< d S )Nr$   r_   re   r-   rf   rk   rl   rm   rj   Tri   r   g     o@rg   g      ?)r#   r   r$   intr   rs   r-   r   
isinstancetupler+   r
   rH   rI   rq   setattrrK   rL   )r   rf   rQ   contentr1   gnamer-   elementr   
subcontentr}   r~   rM   sor   r   r   fromXML   sH   



*

*ztable_G__l_a_t.fromXML)N)r   r   r   __doc__r   r7   r%   r,   r[   rT   rU   r   r   r   r   r   r   r   @   s    
&r   )fontTools.miscr   fontTools.misc.fixedToolsr   fontTools.misc.textToolsr   	functoolsr   r^   r   r   r?   r"   r)   r&   r'   rF   rJ   r
   dictr   r   r   r   r   r   <module>   s     	