o
    Ȑie                     @   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   ^/var/www/html/eduruby.in/lip-sync/lip-sync-env/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   ir   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	enumerateZglyph)selfr1   r(   magicmsgcountitypemetricsbitmapsencodingchZ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)r8   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   )
rV   PCF_PROPERTIESr*   r0   appendr   rL   ioSEEK_CURr$   )r8   
propertiesr1   rQ   rT   rU   Z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   )rV   PCF_METRICSrX   r0   r*   r   )r8   r>   r1   rQ   rT   rU   rX   r<   rD   rE   rF   rG   rH   rB   rC   rI   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)
rV   PCF_BITMAPSr*   lenOSErrorr0   rX   BYTES_PER_ROWr   	frombytes)r8   r>   r?   r1   rQ   rT   rU   Znbitmapsr:   offsetsr<   Zbitmap_sizesZbitorderZpadindexZ
bitmapsizer]   padmoderB   rC   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   rT   r   r   
<listcomp>   s    z.PcfFontFile._load_encoding.<locals>.<listcomp>i  )rV   PCF_BDF_ENCODINGSr*   minr0   rd   ord	bytearraydecoder(   UnicodeDecodeError)r8   rQ   rU   Z	first_colZlast_col	first_rowlast_rowZ	nencodingr@   Zencoding_offsetsr<   Zencoding_offsetr   ro   r   r6      s&   zPcfFontFile._load_encoding)r'   )__name__
__module____qualname____doc__r&   r.   rV   r2   r4   r5   r6   __classcell__r   r   rJ   r   r%   7   s    .%-r%   )rY    r   r   _binaryr   r   rM   r   rO   r   rN   r	   r)   r+   rW   ZPCF_ACCELERATORSr`   rc   ZPCF_INK_METRICSrq   ZPCF_SWIDTHSZPCF_GLYPH_NAMESZPCF_BDF_ACCELERATORSrf   r$   r%   r   r   r   r   <module>   s0   