KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache
System : Linux server112.speedpacket.com 3.10.0-962.3.2.lve1.5.36.el7.x86_64 #1 SMP Mon May 18 02:16:06 EDT 2020 x86_64
User : equistyl ( 1341)
PHP Version : 8.1.30
Disable Function : NONE
Directory :  /lib64/python2.7/site-packages/matplotlib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib64/python2.7/site-packages/matplotlib/afm.pyc
�
r`]c@sfdZddlmZddlZddlZddlZddlmZd�Ze	Z
ejddkrxd�Zne
Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zdefd��YZedkrbdZx_eje�D]KZeejj ee���(Z!ee!�Z"e"j#d�\Z$Z%WdQXqWndS(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 = open('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����(tprint_functionN(t	uni2type1cCstt|��S(N(tinttfloat(tx((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt_to_int5siicCs
|jd�S(Ntutf8(tdecode(R((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt_to_str:scCs5|jdd�}g|j�D]}t|�^qS(Nt,t (treplacetsplitR(tstval((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt_to_list_of_ints@scCs#g|j�D]}t|�^q
S(N(Rt	_to_float(R
R((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt_to_list_of_floatsEscCs$|j�j�dkrtStSdS(Ntfalset0tno(RRR(tlowertstriptFalsetTrue(R
((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt_to_boolIscCsR|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((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt
_sanity_checkPscCs�itd6td6td6td6td6td6td6td6td	6td
6td6td6td
6td6td6td6td6td6td6td6td6td6td6}i}x�|j�}|s�Pn|j�}|jd�r�q�n|jdd�}|d}t	|�dkr"|d}nd}y|||�||<WnWt
k
rotd||dtj
�q�n+tk
r�td |dtj
�q�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
CharacterstCommentR
iiits"Value error parsing header in AFM:tfiles/Found an unknown keyword in AFM header (was %s)s	Bad parseN(RRRRRRtrstripRRtlent
ValueErrortprinttsyststderrtKeyErrorR(R theaderConverterstdR"tlsttkeyR((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt
_parse_headerfsd






c	CsVi}i}x7|j�}|s%Pn|j�}|jd�rJ||fS|jd�d }t|�dkr�td|��nt|dj�d�}t|dj�d�}|dj�d}|jd�}t	|d	d�}t
t|�}|d
krd}n|dkr3|||f||<n||f||<qtd
��dS(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: %siiitasciiitEuroi�i����s	Bad parseN(RR=RRR>RRRRRtmapR(	R tascii_dtname_dR"tvalstnumtwxtnametbbox((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt_parse_char_metrics�s0
	cCs$|j�}|jd�s.td|��ni}x�|j�}|sMPn|j�}t|�dkrqq7n|jd�r�|j�|S|j�}t|�dks�|ddkr�td|��nt|d�t|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(RRRR=R>RRR(R R"RERPtc1tc2R((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt_parse_kern_pairs�s(
"2c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
EndCompositesRJiii����isBad composites parseN(	RR=R>RRRRtappendR(R RER"RPtccRStnumPartstpccPartsR
tpcctdxtdy((s4/usr/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(R[RdRR=R>R(R toptionalRER"RGtl((s4/usr/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(R#RHRURi(R tdheadtdcmetrics_asciitdcmetrics_namet	doptional((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt	parse_afm@s
	
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(Rnt_headert_kernt_metricst_metrics_by_namet
_composite(tselfR RjRkRlt
dkernpairst
dcomposite((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt__init__Rs				cCs/|st|�}n|j|\}}}|S(N(tordRr(RutctisordRRRSRT((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt
get_bbox_char^scCst|�sdSd}d}d}d}x�|D]�}|dkrGq/n|jt|�\}}}	|	\}
}}}
y|j||f}Wntk
r�d}nX|||7}||
}||kr�|}n|}||kr�|}n|}q/W|||fS(sn
        Return the string width (including kerning) and string height
        as a (*w*, *h*) tuple.
        ige��As
(iiN(R>tNoneRrRyRqRC(RuR
ttotalwtnamelasttminytmaxyRzRRRSRTRhtbtwthtkptthismaxtthismin((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pytstring_width_heightds0



		
cCs�t|�sdSd}d}d}d}d}t|t�sO|jd�}nx"|D]}|dkrnqVntjt|�d�}y|j|\}	}
Wn*t	k
r�d}|j|\}	}
nX|
\}}}
}||kr�|}ny|j
||f}Wnt	k
r!d}nX||	|7}||}||krO|}n|}||krj|}n|}qVW||||||fS(s0
        Return the string bounding box
        ige��ARKs
tquestion(iiiiN(R>R}t
isinstancetunicodeRRtgetRyRsRCRq(RuR
R~RR�R�tleftRzRSRRRTRhR�R�R�R�R�R�((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pytget_str_bbox_and_descent�sD

	


		
cCs|j|�d S(s0
        Return the string bounding box
        i(R�(RuR
((s4/usr/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'
        (RyRr(RuRzR{RRRSRT((s4/usr/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
        (RyRr(RuRzR{RRRSRT((s4/usr/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
        (Rs(RuRSRRRT((s4/usr/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����(RyRr(RuRzR{RRRSRT((s4/usr/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(RuRYRZtname1tname2((s4/usr/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(Rq(RuR�R�((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyR��scCs|jdS(s'Return the font name, eg, 'Times-Roman'R$(Rp(Ru((s4/usr/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(RpR�R}(RuRS((s4/usr/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))+$R;N(RpR�R}R�tretsub(RuRStextras((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pytget_familyname�scCs|jdS(s-Return the font weight, eg, 'Bold' or 'Roman'R'(Rp(Ru((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt
get_weightscCs|jdS(sReturn the fontangle as floatR((Rp(Ru((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt	get_anglescCs|jdS(sReturn the cap height as floatR0(Rp(Ru((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt
get_capheightscCs|jdS(sReturn the xheight as floatR2(Rp(Ru((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pytget_xheightscCs|jdS(s'Return the underline thickness as floatR,(Rp(Ru((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pytget_underline_thicknessscCs|jjdd�S(su
        Return the standard horizontal stem width as float, or *None* if
        not specified in AFM file.
        R5N(RpR�R}(Ru((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pytget_horizontal_stem_widthscCs|jjdd�S(ss
        Return the standard vertical stem width as float, or *None* if
        not specified in AFM file.
        R6N(RpR�R}(Ru((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pytget_vertical_stem_width#s(t__name__t
__module__RxRR|R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�(((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyRoPs*		%	-		
	
		
									t__main__s!/usr/local/share/fonts/afms/adobesJohn Hunter is the Man!(&t__doc__t
__future__RRAtosR�t_mathtext_dataRRRRtversion_infoRtstrRRRR#RHRUR[RdRiRntobjectRoR�tpathnametlistdirtfnametopentpathtjoinR tafmR�R�R�(((s4/usr/lib64/python2.7/site-packages/matplotlib/afm.pyt<module>#s6						K	(	#	%		�

Anon7 - 2021