o
    ø'Ëhe  ã                   @   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   úJ/var/www/html/scripts/venv/lib/python3.10/site-packages/PIL/PcfFontFile.pyÚ<lambda>,   s    r   c                 C   ó   | d d? d@ S )Né   r   éþÿÿÿr   r   r   r   r   r   -   ó    c                 C   r   )Né   r   éüÿÿÿr   r   r   r   r   r   .   r   c                 C   r   )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|< q'|| _	|  
¡ | _|  ¡ }|  |¡}	|  ¡ }
t|
ƒD ]-\}}|d urŽ|| \}}}}}}}}|df||| || |fdd||f|	| f| j|< qad 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Ú	enumerateÚglyph)Úselfr1   r(   ÚmagicÚmsgÚcountÚiÚtypeÚmetricsÚbitmapsÚencodingÚchÚixÚxsizeÚysizeÚleftÚrightÚwidthÚascentÚdescentÚ
attributes©Ú	__class__r   r   r.   <   sF   
0


÷

ü€ôzPcfFontFile.__init__c                 C   sX   | j | \}}}| j}| |¡ t| d¡ƒ}|d@ r!tt}}ntt}}||||fS )Nr   )r/   r1   Úseekr)   r*   Úb16Úb32Úl16)r9   ÚtagÚformatÚsizeÚoffsetr1   Úi16Úi32r   r   r   Ú
_getformatj   s   

zPcfFontFile._getformatc              	   C   sÊ   i }|   t¡\}}}}|| d¡ƒ}g }t|ƒD ]}| || d¡ƒt| d¡ƒ|| d¡ƒf¡ q|d@ rA| d|d@  tj¡ | || d¡ƒ¡}	|D ]\}
}}t	|	|
ƒ}
|r^t	|	|ƒ}|||
< qM|S )Nr   r   r   )
rX   ÚPCF_PROPERTIESr*   r0   Úappendr   rN   ÚioÚSEEK_CURr$   )r9   Ú
propertiesr1   rS   rV   rW   ÚnpropsÚpr=   ÚdataÚkr"   Úvr   r   r   r2   y   s   0


zPcfFontFile._load_propertiesc              
   C   s^  g }|   t¡\}}}}|j}|d@ dkrct|| d¡ƒƒD ]C}t| d¡ƒd }t| d¡ƒd }	t| d¡ƒd }
t| d¡ƒd }t| d¡ƒd }|	| }|| }|||||	|
||dfƒ q|S t|| d¡ƒƒD ]@}|| d¡ƒ}|| d¡ƒ}	|| d¡ƒ}
|| d¡ƒ}|| d¡ƒ}|| d¡ƒ}|	| }|| }|||||	|
|||fƒ ql|S )Ni ÿ  r   r
   r   r   r   r   )rX   ÚPCF_METRICSrZ   r0   r*   r   )r9   r?   r1   rS   rV   rW   rZ   r=   rF   rG   rH   rI   rJ   rD   rE   rK   r   r   r   r4   ”   s2   õzPcfFontFile._load_metricsc                 C   s,  g }|   t¡\}}}}|| d¡ƒ}|t|ƒkrd}t|ƒ‚g }	t|ƒD ]}
|	 || d¡ƒ¡ q$g }tdƒD ]}
| || d¡ƒ¡ q7|d@ }|d@ }|| }|	 |¡ | |¡}t| }d}|rdd}t|ƒD ]+}
||
 d d… \}}|	|
|
d … \}}| t 	d||f|||… d|||ƒ¡¡ qh|S )	Nr   zWrong number of bitmapsr   r   z1;RÚ1r
   Úraw)
rX   ÚPCF_BITMAPSr*   ÚlenÚOSErrorr0   rZ   ÚBYTES_PER_ROWr   Ú	frombytes)r9   r?   r@   r1   rS   rV   rW   Únbitmapsr;   Úoffsetsr=   Úbitmap_sizesÚbitorderÚpadindexÚ
bitmapsizer`   ÚpadÚmoderD   rE   ÚbÚer   r   r   r5   ¹   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 ]"}
z|	tt|
gƒ | j	¡ƒ }|dkrm|||
< W qU t
yw   Y qUw |S )Nr
   r   r   c                    s   g | ]	}ˆˆ   d ¡ƒ‘qS )r
   )r*   )Ú.0Ú_©r1   rV   r   r   Ú
<listcomp>ó   s    z.PcfFontFile._load_encoding.<locals>.<listcomp>iÿÿ  )rX   ÚPCF_BDF_ENCODINGSr*   Úminr0   rg   ÚordÚ	bytearrayÚdecoder(   ÚUnicodeDecodeError)r9   rS   rW   Ú	first_colÚlast_colÚ	first_rowÚlast_rowÚ	nencodingrA   Úencoding_offsetsr=   Úencoding_offsetr   rw   r   r6   æ   s&   ÿ€þzPcfFontFile._load_encoding)r'   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r&   r.   rX   r2   r4   r5   r6   Ú__classcell__r   r   rL   r   r%   7   s    .%-r%   )r[   Ú r   r   Ú_binaryr   r   rO   r   rQ   r   rP   r	   r)   r+   rY   ÚPCF_ACCELERATORSrc   rf   ÚPCF_INK_METRICSry   ÚPCF_SWIDTHSÚPCF_GLYPH_NAMESÚPCF_BDF_ACCELERATORSri   r$   r%   r   r   r   r   Ú<module>   s0   ü