B
    0\
                 @   sD   d dl mZ d dlZddlmZmZ dZdd ZG dd	 d	eZ	dS )
    )print_functionN   )Image_binaryi   c             C   s2   x,|D ]$}|dk r|d7 }|  t| qW d S )Nr   i   )writer   Zo16be)fpvaluesv r
   +lib/python3.7/site-packages/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   Zixr
   r
   r   __getitem__-   s    zFontFile.__getitem__c             C   s  | j r
dS d } }}d}xp| D ]h}|r |\}}}}	t||d |d  }||d |d   }|tkr~|d7 }|d |d  }t||}q W |}
|| }|
dkr|dkrdS || _td|
|f| _ dgd | _d }}xtdD ]}| | }|r|\}}}}	|d |d  }|| }}|| }|tkrFd||  }}|| }}|}|d | |d | |d | |d | f}| j |		|| |||f| j|< qW d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   compile0   sF    



,zFontFile.compilec          	   C   s   |    | jtj|d d d ttj|d d d}|d |d| j 	d |d	 xNt
d
D ]B}| j| }|st|dgd  qvt||d |d  |d   qvW W d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   )
Z
__future__r   r.   r   r   r   r   r   objectr   r
   r
   r
   r   <module>   s
   