U
    &^
                     @   s6   d dl Z ddlmZmZ dZdd ZG dd dZdS )	    N   )Image_binaryi   c                 C   s.   |D ]$}|dk r|d7 }|  t| qd S )Nr   i   )writer   Zo16be)fpvaluesv r	   0/tmp/pip-install-a1j0c_p1/Pillow/PIL/FontFile.pyputi16   s    r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 ZdS )
FontFileNc                 C   s   i | _ d gd | _d S )N   )infoglyph)selfr	   r	   r
   __init__)   s    zFontFile.__init__c                 C   s
   | j | S )N)r   )r   ixr	   r	   r
   __getitem__.   s    zFontFile.__getitem__c                 C   s  | j r
dS d } }}d}| D ]h}|r|\}}}}	t||d |d  }||d |d   }|tkr||d7 }|d |d  }t||}q|}
|| }|
dkr|dkrdS || _td|
|f| _ dgd | _d }}tdD ]}| | }|r|\}}}}	|d |d  }|| }}|| }|tkr@d||  }}|| }}|}|d | |d | |d | |d | f}| j |		|| |||f| j|< qdS )	zCreate metrics and bitmapNr   r          1r   )
bitmapmaxWIDTHysizer   newmetricsrangeZpasteZcrop)r   hwZmaxwidthlinesr   ddstsrcZimZxsizer   xyiZxxZx0Zy0sr	   r	   r
   compile1   sF    


,zFontFile.compilec              	   C   s   |    | jtj|d d d ttj|d d d|}|d |d| j 	d |d	 t
d
D ]B}| j| }|st|dgd  qtt||d |d  |d   qtW 5 Q R X dS )z	Save fontr   z.pbmZPNGz.pilwbs   PILfont
z
;;;;;;%d;
asciis   DATA
r   
   r   r   N)r)   r   saveospathsplitextopenr   r   encoder   r   r   )r   filenamer   idmr	   r	   r
   r-   `   s    


zFontFile.save)__name__
__module____qualname__r   r   r   r)   r-   r	   r	   r	   r
   r   %   s
   /r   )r.   r   r   r   r   r   r   r	   r	   r	   r
   <module>   s   