OwlCyberSecurity - MANAGER
Edit File: afm.cpython-38.pyc
U ��]�D � @ s" d Z ddlmZ ddlZddlZddlmZ ddlmZ e� e �Zdd� Zd d � Z dd� Zd d� Zdd� Zdd� Zdd� Zdd� Zedd�Zde_ dej_ dej_ dej_ dd� Zdd � Zed!d"�Zd#e_ d$ej_ d%ej_ d&ej_ d'd(� Zd)d*� Zed+d,d-�d.d/� �Zd0d1� Z G d2d3� d3e!�Z"dS )4a� This is a python interface to Adobe Font Metrics Files. Although a number of other python implementations exist, and may be more complete than this, it was decided not to go with them because they were either: 1) copyrighted or used a non-BSD compatible license 2) had too many dependencies and a free standing lib was needed 3) Did more than needed and it was easier to write afresh rather than figure out how to get just what was needed. It is pretty easy to use, and requires only built-in python libs: >>> from matplotlib import rcParams >>> import os.path >>> afm_fname = os.path.join(rcParams['datapath'], ... 'fonts', 'afm', 'ptmr8a.afm') >>> >>> from matplotlib.afm import AFM >>> with open(afm_fname, 'rb') as fh: ... afm = AFM(fh) >>> afm.string_width_height('What the heck?') (6220.0, 694) >>> afm.get_fontname() 'Times-Roman' >>> afm.get_kern_dist('A', 'f') 0 >>> afm.get_kern_dist('A', 'y') -92.0 >>> afm.get_bbox_char('!') [130, -9, 238, 676] As in the Adobe Font Metrics File Format Specification, all dimensions are given in units of 1/1000 of the scale factor (point size) of the font being used. � )� namedtupleN� )� uni2type1)� deprecatedc C s t t| ��S �N)�int�float��x� r �0/usr/lib/python3/dist-packages/matplotlib/afm.py�_to_int4 s r c C s$ t | t�r| �d�} t| �dd��S )Nzlatin-1�,�.)� isinstance�bytes�decoder �replacer r r r � _to_float= s r c C s | � d�S )N�utf8)r r r r r �_to_strH s r c C s | � dd�} dd� | �� D �S )N� ,� c S s g | ]}t |��qS r )r ��.0�valr r r � <listcomp>N s z$_to_list_of_ints.<locals>.<listcomp>)r �split��sr r r �_to_list_of_intsL s r c C s dd� | � � D �S )Nc S s g | ]}t |��qS r )r r r r r r R s z&_to_list_of_floats.<locals>.<listcomp>)r r r r r �_to_list_of_floatsQ s r! c C s | � � �� dkrdS dS d S )N)s false� 0s noFT)�lower�stripr r r r �_to_boolU s r% c C s: | � � }zt| �}W 5 | �|d� X |�d�s6td��dS )zP Check if the file looks like AFM; if it doesn't, raise `RuntimeError`. r � StartFontMetricszNot an AFM fileN)�tell�seek�next� startswith�RuntimeError)�fh�pos�liner r r � _sanity_check\ s r/ c C s t ttttt ttt t tdd� tt t t t t t t tttd�}i }| D ]�}|�� }|�d�rXq@|�dd�}|d }t|�dkr�|d }nd }z|| }W n& t k r� t �d | � Y q@Y nX z||�||<