a
    ù!fe  ã                   @   s¶   d dl Z ddlmZ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	ZdZd
ZdZdZdZdZdZdZdZdd„ dd„ dd„ dd„ gZdd„ ZG dd„ dejƒZdS )é    Né   )ÚFontFileÚImage)Úi8)Úi16be)Úi16le)Úi32be)Úi32leifcpé   é   é   é   é    é@   é€   é   c                 C   s   | d d? S )Né   é   © ©Úbitsr   r   úP/var/www/html/python-backend/venv/lib/python3.9/site-packages/PIL/PcfFontFile.pyÚ<lambda>,   ó    r   c                 C   s   | d d? d@ S )Né   r   éþÿÿÿr   r   r   r   r   r   -   r   c                 C   s   | d d? d@ S )Né   r   éüÿÿÿr   r   r   r   r   r   .   r   c                 C   s   | d d? d@ S )Né?   r   iøÿÿÿr   r   r   r   r   r   /   r   c                 C   s   | ||   d|¡… S )Nó    )Úindex)ÚsÚor   r   r   Úsz3   s    r#   c                       sN   e Zd ZdZdZd‡ fdd„	Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
‡  ZS )ÚPcfFontFilez(Font file plugin for the X11 PCF format.Únameú	iso8859-1c              	      s"  || _ t| d¡ƒ}|tkr(d}t|ƒ‚tƒ  ¡  t| d¡ƒ}i | _t|ƒD ]@}t| d¡ƒ}t| d¡ƒt| d¡ƒt| d¡ƒf| j|< qN|| _	|  
¡ | _|  ¡ }|  |¡}	|  ¡ }
t|
ƒD ]Z\}}|d urÂ|| \}}}}}}}}|df||| || |fdd||f|	| f| j|< qÂd S )Nr   znot a PCF filer   )Úcharset_encodingÚl32ÚreadÚ	PCF_MAGICÚSyntaxErrorÚsuperÚ__init__ÚtocÚrangeÚfpÚ_load_propertiesÚinfoÚ_load_metricsÚ_load_bitmapsÚ_load_encodingÚ	enumerateZglyph)Úselfr0   r'   ÚmagicÚmsgÚcountÚiÚtypeÚmetricsÚbitmapsÚencodingÚchZixÚxsizeÚysizeÚleftÚrightÚwidthÚascentÚdescentÚ
attributes©Ú	__class__r   r   r-   <   sB    
0


÷
üzPcfFontFile.__init__c                 C   sX   | j | \}}}| j}| |¡ t| d¡ƒ}|d@ rBtt }}n
tt }}||||fS )Nr   )r.   r0   Úseekr(   r)   Úb16Úb32Úl16)r7   ÚtagÚformatÚsizeÚoffsetr0   Úi16Úi32r   r   r   Ú
_getformatj   s    

zPcfFontFile._getformatc              	   C   sÊ   i }|   t¡\}}}}|| d¡ƒ}g }t|ƒD ]2}| || d¡ƒt| d¡ƒ|| d¡ƒf¡ q0|d@ r‚| d|d@  tj¡ | || d¡ƒ¡}	|D ]*\}
}}t	|	|
ƒ}
|r¼t	|	|ƒ}|||
< qš|S )Nr   r   r   )
rU   ÚPCF_PROPERTIESr)   r/   Úappendr   rK   ÚioÚSEEK_CURr#   )r7   Ú
propertiesr0   rP   rS   rT   ZnpropsÚpr;   ÚdataÚkr!   Úvr   r   r   r1   y   s    0


zPcfFontFile._load_propertiesc              
   C   s\  g }|   t¡\}}}}|j}|d@ dkrÄt|| d¡ƒƒD ]†}t| d¡ƒd }t| d¡ƒd }	t| d¡ƒd }
t| d¡ƒd }t| d¡ƒd }|	| }|| }|||||	|
||dfƒ q:n”t|| d¡ƒƒD ]€}|| d¡ƒ}|| d¡ƒ}	|| d¡ƒ}
|| d¡ƒ}|| d¡ƒ}|| d¡ƒ}|	| }|| }|||||	|
|||fƒ qÖ|S )Ni ÿ  r   r
   r   r   r   r   )rU   ÚPCF_METRICSrW   r/   r)   r   )r7   r=   r0   rP   rS   rT   rW   r;   rC   rD   rE   rF   rG   rA   rB   rH   r   r   r   r3   ”   s0    zPcfFontFile._load_metricsc                 C   s,  g }|   t¡\}}}}|| d¡ƒ}|t|ƒkr<d}t|ƒ‚g }	t|ƒD ]}
|	 || d¡ƒ¡ qHg }tdƒD ]}
| || d¡ƒ¡ qn|d@ }|d@ }|| }|	 |¡ | |¡}t| }d}|rÈd}t|ƒD ]V}
||
 d d… \}}|	|
|
d … \}}| t 	d||f|||… d|||ƒ¡¡ qÐ|S )	Nr   zWrong number of bitmapsr   r   z1;RÚ1r
   Úraw)
rU   ÚPCF_BITMAPSr)   ÚlenÚOSErrorr/   rW   ÚBYTES_PER_ROWr   Ú	frombytes)r7   r=   r>   r0   rP   rS   rT   Znbitmapsr9   Úoffsetsr;   Zbitmap_sizesZbitorderZpadindexZ
bitmapsizer\   ÚpadÚmoderA   rB   ÚbÚer   r   r   r4   ¹   s8    

"ÿzPcfFontFile._load_bitmapsc              	      sö   |   t¡\‰ }‰}ˆˆ  d¡ƒˆˆ  d¡ƒ }}ˆˆ  d¡ƒˆˆ  d¡ƒ }}ˆˆ  d¡ƒ || d || d  }d gtd|ƒ }‡ ‡fdd„t|ƒD ƒ}	t|t|ƒƒD ]F}
z.|	tt|
gƒ | j	¡ƒ }|dkrÚ|||
< W qª t
yî   Y qª0 qª|S )Nr
   r   r   c                    s   g | ]}ˆˆ   d ¡ƒ‘qS )r
   )r)   )Ú.0Ú_©r0   rS   r   r   Ú
<listcomp>ó   r   z.PcfFontFile._load_encoding.<locals>.<listcomp>iÿÿ  )rU   ÚPCF_BDF_ENCODINGSr)   Úminr/   rc   ÚordÚ	bytearrayÚdecoder'   ÚUnicodeDecodeError)r7   rP   rT   Z	first_colZlast_colÚ	first_rowÚlast_rowZ	nencodingr?   Zencoding_offsetsr;   Zencoding_offsetr   rn   r   r5   æ   s"    ÿzPcfFontFile._load_encoding)r&   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   r-   rU   r1   r3   r4   r5   Ú__classcell__r   r   rI   r   r$   7   s   .%-r$   )rX   Ú r   r   Ú_binaryr   r   rL   r   rN   r   rM   r	   r(   r*   rV   ZPCF_ACCELERATORSr_   rb   ZPCF_INK_METRICSrp   ZPCF_SWIDTHSZPCF_GLYPH_NAMESZPCF_BDF_ACCELERATORSre   r#   r$   r   r   r   r   Ú<module>   s.   ü