a
    i=icÛ  ã                   @   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   ú`/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/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$tdƒ‚tƒ  ¡  t| d¡ƒ}i | _t|ƒD ]@}t| d¡ƒ}t| d¡ƒt| d¡ƒt| d¡ƒf| j|< qJ|| _	|  
¡ | _|  ¡ }|  |¡}|  ¡ }	t|	ƒD ]^\}
}|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Ú	enumerateÚglyph)Úselfr0   r'   ÚmagicÚcountÚiÚtypeÚmetricsÚbitmapsÚencodingÚchZixÚxÚyÚlÚrÚwÚaÚdÚfr7   ©Ú	__class__r   r   r-   <   s(    
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)r8   ÚtagÚformatÚsizeÚoffsetr0   Úi16Úi32r   r   r   Ú
_getformat]   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#   )r8   Ú
propertiesr0   rP   rS   rT   ZnpropsÚpr;   ÚdataÚkr!   Úvr   r   r   r1   m   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   )r8   r=   r0   rP   rS   rT   rW   r;   ÚleftÚrightÚwidthZascentZdescentZxsizeZysizeÚ
attributesr   r   r   r3   ‰   s0    zPcfFontFile._load_metricsc                 C   s.  g }|   t¡\}}}}|| d¡ƒ}|t|ƒkr8tdƒ‚g }t|ƒD ]}	| || d¡ƒ¡ qDg }
tdƒD ]}	|
 || d¡ƒ¡ qj|d@ }|d@ }|
| }| |¡ | |¡}t| }d}|rÄd}t|ƒ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)r8   r=   r>   r0   rP   rS   rT   ZnbitmapsÚoffsetsr;   Zbitmap_sizesZbitorderZpadindexZ
bitmapsizer\   ÚpadÚmoderA   rB   rC   rD   rE   rF   rG   rH   ÚbÚer   r   r   r4   ±   s2    

,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/   rg   ÚordÚ	bytearrayÚdecoder'   ÚUnicodeDecodeError)r8   rP   rT   Ú	first_colZlast_colÚ	first_rowÚlast_rowZ	nencodingr?   Zencoding_offsetsr;   Zencoding_offsetr   rr   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_   rf   ZPCF_INK_METRICSrt   ZPCF_SWIDTHSZPCF_GLYPH_NAMESZPCF_BDF_ACCELERATORSri   r#   r$   r   r   r   r   Ú<module>   s.   ü