
    Ph)/                         d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
mZmZ ddlmZ d dlZd dlZd dlZd dlZ ej&                  e      ZdZ ej.                  e      Z G d	 d
ej                        Zd Zd Zy)    )ttLib)standardGlyphOrder)sstruct)bytechrbyteordtobytestostrsafeEvalreadHex   )DefaultTableNa  
	>
	formatType:			16.16F
	italicAngle:		16.16F		# italic angle in degrees
	underlinePosition:	h
	underlineThickness:	h
	isFixedPitch:		L
	minMemType42:		L			# minimum memory if TrueType font is downloaded
	maxMemType42:		L			# maximum memory if TrueType font is downloaded
	minMemType1:		L			# minimum memory if Type1 font is downloaded
	maxMemType1:		L			# maximum memory if Type1 font is downloaded
c                   X    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zy)table__p_o_s_ta:  PostScript table

    The ``post`` table contains information needed to use the font on
    PostScript printers, including the PostScript names of glyphs and
    data that was stored in the ``FontInfo`` dictionary for Type 1 fonts.

    See also https://learn.microsoft.com/en-us/typography/opentype/spec/post
    c                    t        j                  t        |d t         |        |t        d  }| j                  dk(  r| j                  ||       y | j                  dk(  r| j                  ||       y | j                  dk(  r| j                  ||       y | j                  dk(  r| j                  ||       y t        j                  d| j                  z        Ng      ?g       @g      @g      @z$'post' table format %f not supported)r   unpack
postFormatpostFormatSize
formatTypedecode_format_1_0decode_format_2_0decode_format_3_0decode_format_4_0r   
TTLibErrorselfdatattFonts      jC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\fontTools/ttLib/tables/_p_o_s_t.py	decompileztable__p_o_s_t.decompile'   s    z4#8$?NO$??c!""40__#""40__#""40__#""40 ""6H     c                 V   t        j                  t        |       }| j                  dk(  r	 |S | j                  dk(  r|| j	                  |      z   }|S | j                  dk(  r	 |S | j                  dk(  r|| j                  |      z   }|S t        j                  d| j                  z        r   )r   packr   r   encode_format_2_0encode_format_4_0r   r   )r   r   r   s      r   compileztable__p_o_s_t.compile8   s    ||J-??c!  __#$0088D  __#  __#$0088D  ""6H r!   c                 d    t        | d      st        j                  d      | j                  }| `|S )zThis function will get called by a ttLib.TTFont instance.
        Do not call this function yourself, use TTFont().getGlyphOrder()
        or its relatives instead!
        
glyphOrderzillegal use of getGlyphOrder())hasattrr   r   r(   )r   r(   s     r   getGlyphOrderztable__p_o_s_t.getGlyphOrderI   s4    
 t\*""#CDD__
Or!   c                 :    t         d |d   j                   | _        y )Nmaxp)r   	numGlyphsr(   r   s      r   r   z table__p_o_s_t.decode_format_1_0T   s    ,-Gvf~/G/GHr!   c                 z   t        j                  d|d d       \  }t        |      }||d   j                  kD  r|d   j                  }|dd  }t	        j                  d      }|j                  |d d|z          t        j                  dk7  r|j                          |d|z  d  }t        |      }t        ||dz
        x| _        }dgt        |d   j                        z  x| _        }t        |      D ]$  }||   }	|	dkD  r
	 ||	dz
     }
n	t        |	   }
|
||<   & | j!                  |       y # t        $ r d}
Y &w xY w)	N>H   r,   Hbigi     )structr   intr-   array	frombytessys	byteorderbyteswapmaxunpackPStrings
extraNamesr(   range
IndexErrorr   build_psNameMapping)r   r   r   r-   indicesmaxIndexr>   r(   glyphIDindexnames              r   r   z table__p_o_s_t.decode_format_2_0W   sQ   }}T484	N	vf~///
 v00IABx++c"$Y/0==E!A	MO$w<'5dHsN'KK*(*tc&.2J2J.K'KK*Y'GG$Es{%eck2D
 *%0"&Jw ( 	  ( " Ds   D,,D:9D:c                    i }i }t        |d   j                        D ]  }| j                  |   x}}|dk(  rd|z  }||v ry||   }t        |j	                               t        | j                        z  }|dz   t        |      z   |v r|dz  }|dz   t        |      z   |v r|dz   ||<   |dz   t        |      z   }|| j                  |<   d||<   ||k7  s|||<    || _        y )Nr,   r3   z	glyph%.5d.r   )r?   r-   r(   setkeysstrmapping)	r   r   rL   allNamesi	glyphNamepsNamennamess	            r   rA   z"table__p_o_s_t.build_psNameMappingv   s    vf~//0A!%!33IB'!O	H$Y'HMMO,s4??/CC 3Q/E9FA !3Q/E9&'!e#%Oc!f4	!*DOOA"#HYF"%+	"% 1( r!   c                     d | _         y )N)r(   r   s      r   r   z table__p_o_s_t.decode_format_3_0   s     r!   c                    ddl m} |d   j                  }t        j                  d      }|j	                  |       t
        j                  dk7  r|j                          dgt        |      z  x| _	        }t        t        t        |      |            D ]`  }||   dk(  rd| j                  |<   ||   |j                  v r |j                  ||      | j                  |<   Ld||   z  | j                  |<   b | j                  |       y )	Nr   aglr,   r1   r2   r3     zuni%04X)	fontToolsrV   r-   r7   r8   r9   r:   r;   r6   r(   r?   minlenUV2AGLrA   )r   r   r   rV   r-   rB   r(   rN   s           r   r   z table__p_o_s_t.decode_format_4_0   s    !6N,,	++c"$==E! )+tc)n'<<*s3w<34AqzV#%'"szz)%(ZZ
%;"%.%;" 5 	  (r!   c                    |d   j                   }|j                         }t        |      |k(  sJ t        j                  d      }i }| j                  D cg c]  }|t
        vs| c}x}| _        t        t        |            D ]
  }||||   <    t        |      D ]  }	||	   }
|
| j                  v r| j                  |
   }n|
}||v r	d||   z   }nK|t
        v rt        j                  |      }n-dt        |      z   }t        |      ||<   |j                  |       |j                  |        t        j                  dk7  r|j                          t        j                  d|      |j                         z   t!        |      z   S c c}w )Nr,   r1   r4   r2   r/   )r-   r*   rZ   r7   r>   r   r?   rL   rE   appendr9   r:   r;   r5   r#   r   packPStrings)r   r   r-   r(   rB   	extraDictrQ   r>   rN   rD   rO   rP   rE   s                r   r$   z table__p_o_s_t.encode_format_2_0   s{   6N,,	))+
:)+++++c"	(
&!!3E*EA(
 	

T_ s:'A'(Ijm$ (Y'G"7+IDLL(i0""i//--*008c*o-$'
O	&!!!&)NN5! ( ==E!KKi(7??+<<|J?WW	
-(
s   F#Fc                    ddl m} |d   j                  }|j                         }t	        |      |k(  sJ t        j
                  d      }|D ]  }|j                  d      d   }||j                  v r|j                  |j                  |          Dt	        |      dk(  r'|d d dk(  r|j                  t        |dd  d	             y|j                  d
        t        j                  dk7  r|j                          |j                         S )Nr   rU   r,   r1   #      uni   rW   r2   )rX   rV   r-   r*   rZ   r7   splitAGL2UVr]   r6   r9   r:   r;   r   )r   r   rV   r-   r(   rB   rD   s          r   r%   z table__p_o_s_t.encode_format_4_0   s    !6N,,	))+
:)+++++c"!GmmC(+G#**$szz'23W"wr{e';s712;34v& " ==E!  r!   c                 D   t        j                  t              \  }}}|D ]1  }t        | |      }|j	                  ||       |j                          3 t        | d      r|j                  d       |j                          |j                  d       |j                          t        | j                  j                               }|D ])  \  }}	|j	                  d||	       |j                          + |j                  d       |j                          t        | d      r|j                  d       |j                          |j                  d       |j                          | j                  D ]%  }|j	                  d|	       |j                          ' |j                  d       |j                          t        | d
      r^|j                  d       |j                          |j                  | j                         |j                  d       |j                          y y )N)valuerL   psNamesaL  This file uses unique glyph names based on the information
found in the 'post' table. Since these names might not be unique,
we have to invent artificial names in case of clashes. In order to
be able to retain the original information, we need a name to
ps name mapping for those cases where they differ. That's what
you see below.
rP   )rF   rP   r>   zKfollowing are the name that are not taken from the standard Mac glyph order)rF   r   hexdata)r   	getformatr   getattr	simpletagnewliner)   begintagcommentsortedrL   itemsendtagr>   dumphexr   )
r   writerr   formatstringrR   fixesrF   ri   rs   rP   s
             r   toXMLztable__p_o_s_t.toXML   s   %,%6%6z%B"eUDD$'ET/NN  4#OOI&NNNN# NN4<<--/0E %f  V D  !& MM)$NN4&OOL)NNNN] NN   5  ( MM,'NN4 OOI&NNNN499%MM)$NN !r!   c                    |dvrt        | |t        |d                y |dk(  rAi | _        |D ]4  }t        |t              s|\  }}}|dk(  s |d   | j                  |d   <   6 y |dk(  rJg | _        |D ]=  }t        |t              s|\  }}}|dk(  s | j
                  j                  |d          ? y t        |      | _        y )N)rj   r>   rk   ri   rj   rP   rF   r>   )	setattrr
   rL   
isinstancetupler>   r]   r   r   )r   rF   attrscontentr   elements         r   fromXMLztable__p_o_s_t.fromXML  s    ;;D$w 89YDL"!'51'.$eW8#27/DLLv/ # \! DO"!'51'.$eW8#OO**5=9 #  (DIr!   N)__name__
__module____qualname____doc__r    r&   r*   r   r   rA   r   r   r$   r%   ry   r    r!   r   r   r      sF    ""	I)>2
)(
@!&)V)r!   r   c                 \   g }d}t        |       }t        |      D ]T  }||k  rd}nt        | |         }|dz  }|||z   dz
  k  rd}nt        | |||z    d      }|j	                  |       ||z  }V ||k  rt
        j                  d||z
         |S ||k  rt
        j                  d       |S )Nr   r   r3   latin1encodingz'%d extra bytes in post.stringData arrayz(not enough data in post.stringData array)rZ   r?   r   r	   r]   logwarning)r   rQ   stringsrE   dataLen_lengthrF   s           r   r=   r=     s     GE$iG1XeFT%[)F
efnq((Deefn5IDt  w=wO
 N 
5>?Nr!   c                 b    d}| D ]'  }|t        t        |            z   t        |d      z   }) |S )Nr!   r   r   )r   rZ   r   )r   r   ss      r   r^   r^   <  s4    Dgc!fo%H(EE Kr!   )rX   r   "fontTools.ttLib.standardGlyphOrderr   fontTools.miscr   fontTools.misc.textToolsr   r   r   r	   r
   r   r3   r   r9   r5   r7   logging	getLoggerr   r   r   calcsizer   r   r=   r^   r   r!   r   <module>r      so     A " X X  
   g!
 "!!*-})\.. })@>r!   