o
    j!                     @   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   `/var/www/html/Deteccion_Ine/venv/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   )Z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decoderZ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   r/   r   r,   r4   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subboxBitmapr2   subboxesr:   r9   Glat_format_3_subbox_entryappendr$   r&   octabox)r   r/   onumsubbZ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:   r9   r,   rI   r.   setr   compress)r   r0   r/   encoderZ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<   r8   r7   )r   entriesr   rP   r=   r9   )r   rN   r   r/   r4   r   r   r   rQ      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 )NrB    )r*   rJ   r   rP   rD   rE   rF   r2   r:   rH   rG   rQ   r&   )r   rN   rK   r/   rL   rM   r   r   r   rR      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   )Z
getGlyphID)xr0   r   r   <lambda>   s    z&table_G__l_a_t.toXML.<locals>.<lambda>)keyglyph)namerJ   rF   z{:.3f}%      Y@   z{:0X}bitmap	octaboxes	attribute)indexvalue)re   )rJ   )Z	simpletagr#   r   newlinesortedr,   itemsZbegintaghasattrrJ   r   Z	getformatrD   formatgetattrrF   rH   rG   Zendtag)r   writerr0   rV   arK   formatstringnamesfixesrA   kr3   vr   r]   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[   r`   r,   ra   rf   rg   rh   re   Trd   r   g     o@rb   g      ?)r"   r   r#   intr   rl   r,   r   
isinstancetupler*   r
   rF   rG   rk   setattrrI   rJ   )r   ra   rN   contentr0   gnamer,   elementr   Z
subcontentrt   ru   rK   sor   r   r   fromXML   sH   



*

*ztable_G__l_a_t.fromXML)N)r   r   r   __doc__r   r5   r$   r+   rW   rQ   rR   rv   r   r   r   r   r   r   @   s    
&r   )ZfontTools.miscr   ZfontTools.misc.fixedToolsr   ZfontTools.misc.textToolsr   	functoolsr   rZ   r   r   r=   r!   r(   r%   r&   rD   rH   r
   dictr   r   r   r   r   r   <module>   s     	