HEX
Server: LiteSpeed
System: Linux standart9.isimtescil.net 3.10.0-962.3.2.lve1.5.26.7.el7.x86_64 #1 SMP Wed Oct 2 07:53:12 EDT 2019 x86_64
User: karalev (5310)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //proc/self/root/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyc
�
�)�Uc@s+dZddlZddlZddlZddlmZd�ZeZe	Z
d�Zd�Zd�Z
d�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zddd��YZedkr'dZxVeje�D]BZeejjee��Zee�Zejd�\Z Z!q�WndS(s�
This is a python interface to Adobe Font Metrics Files.  Although a
number of other python implementations exist (and may be more complete
than mine) I decided not to go with them because either they were
either

  1) copyrighted or used a non-BSD compatible license

  2) had too many dependencies and I wanted a free standing lib

  3) Did more than I needed and it was easier to write my own than
     figure out how to just get what I needed from theirs

It is pretty easy to use, and requires only built-in python libs::

    >>> from afm import AFM
    >>> fh = file('ptmr8a.afm')
    >>> afm = AFM(fh)
    >>> afm.string_width_height('What the heck?')
    (6220.0, 683)
    >>> 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]
    >>> afm.get_bbox_font()
    [-168, -218, 1000, 898]


AUTHOR:
  John D. Hunter <jdh2358@gmail.com>
i����N(t	uni2type1cCstt|��S(N(tinttfloat(tx((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt_to_int0scCs5|jdd�}g|j�D]}t|�^qS(Nt,t (treplacetsplitR(tstval((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt_to_list_of_ints6scCs#g|j�D]}t|�^q
S(N(Rt	_to_float(R	R
((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt_to_list_of_floats:scCs$|j�j�dkrtStSdS(Ntfalset0tno(RRR(tlowertstriptFalsetTrue(R	((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt_to_bool<scCsR|j�}z|j�}Wd|j|d�X|jd�sNtd��ndS(s[
    Check if the file at least looks like AFM.
    If not, raise :exc:`RuntimeError`.
    NitStartFontMetricssNot an AFM file(ttelltreadlinetseekt
startswithtRuntimeError(tfhtpostline((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt
_sanity_checkAscCs�itd6td6td6td6td6td6td6td6td	6td
6td6td6td
6td6td6td6td6td6td6td6td6td6td6}i}x�|j�}|s�Pn|j�}|jd�r�q�n|jdd�}|d}t	|�dkr"|d}nd}y|||�||<WnQt
k
rotjdI|I|IJq�n%t
k
r�tjd|IJq�nX|dkr�|Sq�td ��d!S("s;
    Reads the font metrics header (up to the char metrics) and returns
    a dictionary mapping *key* to *val*.  *val* will be converted to the
    appropriate python type as necessary; eg:

        * 'False'->False
        * '0'->0
        * '-168 -218 1000 898'-> [-168, -218, 1000, 898]

    Dictionary keys are

      StartFontMetrics, FontName, FullName, FamilyName, Weight,
      ItalicAngle, IsFixedPitch, FontBBox, UnderlinePosition,
      UnderlineThickness, Version, Notice, EncodingScheme, CapHeight,
      XHeight, Ascender, Descender, StartCharMetrics

    RtFontNametFullNamet
FamilyNametWeighttItalicAngletIsFixedPitchtFontBBoxtUnderlinePositiontUnderlineThicknesstVersiontNoticetEncodingSchemet	CapHeightt	CapheighttXHeighttAscendert	DescendertStdHWtStdVWtStartCharMetricstCharacterSett
CharacterstCommentRiiits"Value error parsing header in AFM:s/Found an unknown keyword in AFM header (was %s)s	Bad parseN(Rt_to_strRRRRtrstripRRtlent
ValueErrortsyststderrtKeyErrorR(RtheaderConverterstdRtlsttkeyR
((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt
_parse_headerVs`




c	CsGi}i}x(|j�}|s%Pn|j�}|jd�rJ||fS|jd�d }t|�dkr�td|��nt|dj�d�}t|dj�d�}|dj�d}t|dd�}t	t
|�}|d	krd
}n|dkr$|||f||<n||f||<qtd��d
S(sz
    Return a character metric dictionary.  Keys are the ASCII num of
    the character, values are a (*wx*, *name*, *bbox*) tuple, where
    *wx* is the character width, *name* is the postscript language
    name, and *bbox* is a (*llx*, *lly*, *urx*, *ury*) tuple.

    This function is incomplete per the standard, but thus far parses
    all the sample afm files tried.
    tEndCharMetricst;isBad char metrics line: %siiiitEuroi�i����s	Bad parseN(RR9RRR:RRRR
tmapR(	Rtascii_dtname_dRtvalstnumtwxtnametbbox((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt_parse_char_metrics�s.
	cCs|j�}|jd�s.td|��ni}x�|j�}|sMPn|j�}t|�dkrqq7n|jd�r�|j�|S|j�}t|�dks�|ddkr�td|��n|d|d	t|d
�}}}||||f<q7td��dS(
s�
    Return a kern pairs dictionary; keys are (*char1*, *char2*) tuples and
    values are the kern pair value.  For example, a kern pairs line like
    ``KPX A y -50``

    will be represented as::

      d[ ('A', 'y') ] = -50

    tStartKernPairss Bad start of kern pairs data: %sitEndKernPairsitKPXsBad kern pairs line: %siiisBad kern pairs parseN(RRRR9R:RR(RRR@RJtc1tc2R
((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt_parse_kern_pairs�s(
"&cCsi}x|j�}|sPn|j�}t|�dkrCq	n|jd�rV|S|jd�}|dj�}|dt|d�}}g}xc|dd!D]T}|j�}	|	dt|	d�t|	d�}}
}|j||
|f�q�W|||<q	td��d	S(
sx
    Return a composites dictionary.  Keys are the names of the
    composites.  Values are a num parts list of composite information,
    with each element being a (*name*, *dx*, *dy*) tuple.  Thus a
    composites line reading:

      CC Aacute 2 ; PCC A 0 0 ; PCC acute 160 170 ;

    will be represented as::

      d['Aacute'] = [ ('A', 0, 0), ('acute', 160, 170) ]

    it
EndCompositesREiii����isBad composites parseN(	RR9R:RRRRtappendR(RR@RRJtccRMtnumPartstpccPartsR	tpcctdxtdy((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt_parse_composites�s(,
cCs�itd6td6}iid6id6}xp|j�}|sAPn|j�}t|�dkreq+n|j�d}||kr+|||�||<q+q+|d|df}|S(s

    Parse the optional fields for kern pair data and composites

    return value is a (*kernDict*, *compositeDict*) which are the
    return values from :func:`_parse_kern_pairs`, and
    :func:`_parse_composites` if the data exists, or empty dicts
    otherwise
    t
StartKernDatatStartCompositesi(RUR^RR9R:R(RtoptionalR@RRBtl((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt_parse_optional�s 	
cCsOt|�t|�}t|�\}}t|�}||||d|dfS(s�
    Parse the Adobe Font Metics file in file handle *fh*. Return value
    is a (*dhead*, *dcmetrics*, *dkernpairs*, *dcomposite*) tuple where
    *dhead* is a :func:`_parse_header` dict, *dcmetrics* is a
    :func:`_parse_composites` dict, *dkernpairs* is a
    :func:`_parse_kern_pairs` dict (possibly {}), and *dcomposite* is a
    :func:`_parse_composites` dict (possibly {})
    ii(RRCRORc(Rtdheadtdcmetrics_asciitdcmetrics_namet	doptional((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt	parse_afms
	
tAFMcBs�eZd�Zed�Zd�Zd�Zd�Zed�Zed�Z	d�Z
ed�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(cCsLt|�\}}}}}||_||_||_||_||_dS(s8
        Parse the AFM file in file object *fh*
        N(Rht_headert_kernt_metricst_metrics_by_namet
_composite(tselfRRdReRft
dkernpairst
dcomposite((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt__init__+s				cCs/|st|�}n|j|\}}}|S(N(tordRl(RotctisordRLRMRN((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt
get_bbox_char8scCst|�sdSd}d}d}d}x�|D]�}|dkrGq/n|jt|�\}}}	|	\}
}}}
y|j||f}Wntk
r�d}nX|||7}||
}||kr�|}n|}||kr/|}q/q/W|||fS(sn
        Return the string width (including kerning) and string height
        as a (*w*, *h*) tuple.
        ige��As
(iiN(R:tNoneRlRsRkR>(RoR	ttotalwtnamelasttminytmaxyRtRLRMRNRbtbtwthtkptthismaxtthismin((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytstring_width_height=s.



	
cCs�t|�sdSd}d}d}d}d}t|t�sL|j�}nx|D]}|dkrkqSntjt|�d�}y|j|\}	}
Wn*t	k
r�d}|j|\}	}
nX|
\}}}
}||kr�|}ny|j
||f}Wnt	k
rd}nX||	|7}||}||krL|}n|}||krS|}qSqSW||||||fS(s0
        Return the string bounding box
        ige��As
tquestion(iiiiN(R:Rwt
isinstancetunicodetdecodeRtgetRsRmR>Rk(RoR	RxRyRzR{tleftRtRMRLRNRbR|R}R~RR�R�((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytget_str_bbox_and_descent[sB

	


	
cCs|j|�d S(s0
        Return the string bounding box
        i(R�(RoR	((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytget_str_bbox�scCs/|st|�}n|j|\}}}|S(sG
        Get the name of the character, ie, ';' is 'semicolon'
        (RsRl(RoRtRuRLRMRN((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt
get_name_char�scCs/|st|�}n|j|\}}}|S(s[
        Get the width of the character from the character metric WX
        field
        (RsRl(RoRtRuRLRMRN((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytget_width_char�scCs|j|\}}|S(sL
        Get the width of the character from a type1 character name
        (Rm(RoRMRLRN((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytget_width_from_char_name�scCs3|st|�}n|j|\}}}|dS(su
        Get the height of character *c* from the bounding box.  This
        is the ink height (space is 0)
        i����(RsRl(RoRtRuRLRMRN((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytget_height_char�scCs/|j|�|j|�}}|j||�S(s_
        Return the kerning pair distance (possibly 0) for chars *c1*
        and *c2*
        (R�tget_kern_dist_from_name(RoRSRTtname1tname2((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt
get_kern_dist�scCs$y|j||fSWndSXdS(se
        Return the kerning pair distance (possibly 0) for chars
        *name1* and *name2*
        iN(Rk(RoR�R�((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyR��scCs|jdS(s'Return the font name, eg, 'Times-Roman'R (Rj(Ro((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytget_fontname�scCs2|jjd�}|dkr.|jd}n|S(s,Return the font full name, eg, 'Times-Roman'R!R N(RjR�Rw(RoRM((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytget_fullname�scCsG|jjd�}|dk	r"|S|j�}d}tj|d|�S(s(Return the font family name, eg, 'Times'R"sY(?i)([ -](regular|plain|italic|oblique|bold|semibold|light|ultralight|extra|condensed))+$R7N(RjR�RwR�tretsub(RoRMtextras((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytget_familyname�scCs|jdS(s-Return the font weight, eg, 'Bold' or 'Roman'R#(Rj(Ro((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt
get_weight�scCs|jdS(sReturn the fontangle as floatR$(Rj(Ro((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt	get_angle�scCs|jdS(sReturn the cap height as floatR,(Rj(Ro((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt
get_capheight�scCs|jdS(sReturn the xheight as floatR.(Rj(Ro((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytget_xheight�scCs|jdS(s'Return the underline thickness as floatR((Rj(Ro((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytget_underline_thickness�scCs|jjdd�S(su
        Return the standard horizontal stem width as float, or *None* if
        not specified in AFM file.
        R1N(RjR�Rw(Ro((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytget_horizontal_stem_width�scCs|jjdd�S(ss
        Return the standard vertical stem width as float, or *None* if
        not specified in AFM file.
        R2N(RjR�Rw(Ro((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pytget_vertical_stem_width�s(t__name__t
__module__RrRRvR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�(((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyRi)s*	
		&															t__main__s!/usr/local/share/fonts/afms/adobesJohn Hunter is the Man!(("t__doc__R<tosR�t_mathtext_dataRRRRtstrR8RR
RRRCRORUR^RcRhRiR�tpathnametlistdirtfnametfiletpathtjoinRtafmR�R}R~(((sA/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/afm.pyt<module>#s,$
						D	"	 	"		�