
    g!                         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      Z G d de      Z G d de	j                        Zy)    )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y)_ObjectN__name__
__module____qualname__     \/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/fontTools/ttLib/tables/G__l_a_t.pyr   r   8       r   r   c                       e Zd Zy)_DictNr   r   r   r   r   r   <   r   r   r   c                   H    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zy)table_G__l_a_tzsGraphite Glyph Attributes table

    See also https://graphite.sil.org/graphite_techAbout#graphite-font-tables
    Nc                 R    t         j                   j                  | |       d| _        y Nr   )r   __init__scheme)selftags     r   r   ztable_G__l_a_t.__init__F   s    !!**45r   c                    t        j                  t        ||        t        t	        | j
                  d            | _        | j
                  dk  rt        | j                  t              }n| j
                  dk  rt        | j                  t              }nj| j
                  dk\  r[t        j                  |      \  }| _        t        j                  t        ||        | j                  dz  dk(  | _        | j                   }|d   }i | _        d	}t%        ||dd        D ]1  \  }} |||       | j"                  |j'                  |      <   |dz  }3 y )
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es           r   	decompileztable_G__l_a_t.decompileJ   s    tT2.t||2NO<<3d88>QRG\\S d88>RSG\\S ")"4"4T":T4;OOM46!%!1!1A!5! ;D//Gf~d12h' 	DAq:A$q):LDOOF//67QJE	r   c                    t               }t        |      dkD  rt        j                  ||t	                     \  }}t        |j                  |j                  |j                  z         }t        |      d|j                  z  k\  rPt        j                  d|j                  z  |      }|j                  t        ||             |d|j                  z  d  }t        |      dkD  r|S )N      >%dh)r   lenr   r'   r   rangeattNumnumstructunpack_fromupdater4   )r   r6   r#   r3   r<   keysvalss          r   r+   z$table_G__l_a_t.decompileAttributes12^   s    W
$i!mooc4;GAt188aee#34D4yAI%))6AEE>DA!!#dD/2AIK( $i!m r   c                    | j                   rt        j                  t        |t	                     \  }}t        |j                        j                  d      }g |_        t        |      D ]R  }t        |      dk\  st        j                  t        |t	                     \  }}|j                  j                  |       T | j                  |t              }| j                   r|_        |S )N1   )r1   r   r'   Glat_format_3_octabox_metricsr   binsubboxBitmapr:   subboxesrC   rB   Glat_format_3_subbox_entryappendr+   r-   octabox)r   r6   onumsubbsubboxattrss          r   r2   z#table_G__l_a_t.decompileAttributes3i   s    oo&CT79UGAt(..s3FAJ6] .t9>#*??2D')$LFD JJ%%f-. **41EFEMr   c                     t        j                  t        |       }| j                  dk  rt	        | j
                  t              }n| j                  dk  rt	        | j
                  t              }nZ| j                  dk\  rK| j                  dz  | j                  rdndz   | _	        t        j                  t        |       }| j                  }g }t        t        | j                              D ]C  }|j                  t        |             | | j                  |j!                  |               z  }E |j                  t        |             |d   j#                  |       | j                  dk\  r t%        j&                  | j                  |      }|S )	Nr!   r"   r$   r%      r   r   r&   )r   packr(   r*   r   compileAttributes12r,   r   r1   r0   r/   compileAttributes3rC   rB   r3   rS   r5   setr	   compress)r   r7   r6   encoderglocsns         r   compileztable_G__l_a_t.compiley   s:   ||M40<<3d66<OPG\\S d66<OPG\\S  $r 14;L;LaRSTD<<t4D--Gs4??+, 	EALLT#GDOOF,?,?,BCDDD	E 	SYv5!<<3##DKK6Dr   c           
          d}t        j                  |      D ]M  }|t        j                  ||d   |d   d      t	        j                  dt        |d         z  g|d    z   z  }O |S )Nr   r   r   )rD   rE   rA   r@   )r	   entriesr   r\   rF   rB   )r   rY   r#   r6   r<   s        r   r]   z"table_G__l_a_t.compileAttributes12   sx    ' 	AGLL1ad&CDv{{#ad)#H'(tH  D	 r   c                 Z   | j                   r|j                  }t        j                  t        |      }t        |j                        j                  d      }t        |      D ],  }|t        j                  t        |j                  |         z  }. nd}|| j                  |t              z   S )NrL    )r1   rT   r   r\   rN   rO   rP   r:   rC   rR   rQ   r]   r-   )r   rY   rU   r6   rV   rW   s         r   r^   z!table_G__l_a_t.compileAttributes3   s    A<< =qAD(..s3F6] P%?AOOP Dd..u6JKKKr   c           	      z   |j                  d| j                  | j                         |j                          t	        | j
                  j                         fd      D ]  \  }}|j                  d|       |j                          t        |d      r:|j                  }t        j                  t              \  }}}i }	|D ],  }
|
dk(  r	d	j                  t        ||
      d
z  dz        |	|
<   . dj                  |j                        |	d<    |j                  di |	 |j                          t        j                  t               \  }}}|j"                  D ]Q  }i }	|D ]&  }
d	j                  t        ||
      d
z  dz        |	|
<   (  |j                   di |	 |j                          S |j%                  d       |j                          t	        |j                               D ])  \  }
}|j                  d|
|       |j                          + |j%                  d       |j                           y )Nr*   )r*   compressionSchemec                 ,    j                  | d         S r   )
getGlyphID)xr7   s    r   <lambda>z&table_G__l_a_t.toXML.<locals>.<lambda>   s    63D3DQqT3J r   )keyglyph)namerT   rP   z{:.3f}%      Y@   z{:0X}bitmap	octaboxes	attribute)indexvalue)ru   )rT   )	simpletagr*   r   newlinesortedr3   itemsbegintaghasattrrT   r   	getformatrN   formatgetattrrP   rR   rQ   endtag)r   writerr7   rc   arU   formatstringnamesfixesrJ   kr;   vs     `          r   toXMLztable_G__l_a_t.toXML   s   DLLDKKXOO!!#)J
 !	DAq OOG!O,NNq)$II-4->->1.*eU  LAN* '..wq!}u/Ds/JKDGL ")!?X4t4 -4->->..*eU  %AD" P"+"2"271a=53H33N"OQP$F$$7$7NN$% k* qwwy) !1  AQ ? ! MM'"NNC!	r   c                    |dk(  r8t        t        |d               | _        t        t        |d               | _        |dk7  ry t        | d      si | _        |d   }t               }|D ]X  }t        |t              s|\  }}}	|dk(  r4t        t        |d               }
t        t        |d               }|||
<   T|d	k(  sZd
| _
        t               }t        |d   d      |_        g |_        |d= |j                         D ]0  \  }
}t        ||
t        t        |d d       dz  dz  dz                2 |	D ]  }t        |t              s|\  }}}	t               }|j                         D ]0  \  }
}t        ||
t        t        |d d       dz  dz  dz                2 |j                  j!                  |        ||_        [ || j                  |<   y )Nr*   rj   rp   r3   rq   rv   rw   rx   ru   Trt   r   g     o@rr   g      ?)r)   r   r*   intr   r~   r3   r   
isinstancetupler1   r   rP   rQ   r|   setattrrS   rT   )r   rq   rY   contentr7   gnamer3   elementr   
subcontentr   r   rU   sos                 r   fromXMLztable_G__l_a_t.fromXML   s   9 %	*:!;<DLhu-@'ABCDK7?t\* DOfW
 	'Ggu-%,"C
k!w01w01 !
1#$(!I!$U8_b!9
(O!KKM LDAqAq#eAcrFme&;e&Cc&I"JKL) *G%gu5 /6,S% B % Q1As53B=5+@5+H3+N'OPQJJ%%b)* &'
"1	'2 ",r   )N)r   r   r   __doc__r   r=   r+   r2   rd   r]   r^   r   r   r   r   r   r   r   @   s6    
(	 ,	L$L#,r   r   )fontTools.miscr   fontTools.misc.fixedToolsr   fontTools.misc.textToolsr   	functoolsr   rh   r   r	   rF   r(   r/   r,   r-   rN   rR   r   dictr   r   r   r   r   <module>r      st    " 7 -    
 
 ! 
 	 		D 	k,\.. k,r   