Files
old-parkingkoncept/parkingkonceptvenv/lib/python3.7/site-packages/matplotlib/__pycache__/afm.cpython-37.pyc

281 lines
16 KiB
Plaintext
Raw Normal View History

2019-11-17 12:44:16 +01:00
B
U<>]<5D>D<00>@s"dZddlmZddlZddlZddlmZddlmZe<03> e
<EFBFBD>Z dd<08>Z d d
<EFBFBD>Z d d <0C>Zd d<0E>Zdd<10>Zdd<12>Zdd<14>Zdd<16>Zedd<18>Zde_dej_dej_dej_dd<1E>Zdd <20>Zed!d"<22>Zd#e_d$ej_d%ej_d&ej_d'd(<28>Zd)d*<2A>Zed+d,d-<2D>d.d/<2F><00>Zd0d1<64>Z Gd2d3<64>d3e!<21>Z"dS)4a<34>
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.
<EFBFBD>)<01>
namedtupleN<EFBFBD>)<01> uni2type1)<01>
deprecatedcCs tt|<00><01>S)N)<02>int<6E>float)<01>x<>r <00>6/tmp/pip-install-i8dhxrtk/matplotlib/matplotlib/afm.py<70>_to_int4sr cCs$t|t<01>r|<00>d<01>}t|<00>dd<03><02>S)Nzlatin-1<>,<2C>.)<05>
isinstance<EFBFBD>bytes<65>decoder<00>replace)rr r r
<00> _to_float=s

rcCs
|<00>d<01>S)N<>utf8)r)rr r r
<00>_to_strHsrcCs|<00>dd<02>}dd<04>|<00><01>D<00>S)N<>,<2C> cSsg|] }t|<01><01>qSr )r )<02>.0<EFBFBD>valr r r
<00>
<listcomp>Nsz$_to_list_of_ints.<locals>.<listcomp>)r<00>split)<01>sr r r
<00>_to_list_of_intsLs rcCsdd<02>|<00><00>D<00>S)NcSsg|] }t|<01><01>qSr )r)rrr r r
rRsz&_to_list_of_floats.<locals>.<listcomp>)r)rr r r
<00>_to_list_of_floatsQsrcCs|<00><00><00><01>dkrdSdSdS)N)sfalse<73>0snoFT)<02>lower<65>strip)rr r r
<00>_to_boolUsr!c
Cs:|<00><00>}z t|<00>}Wd|<00>|d<02>X|<02>d<03>s6td<04><01>dS)zP
Check if the file looks like AFM; if it doesn't, raise `RuntimeError`.
NrsStartFontMetricszNot an AFM file)<05>tell<6C>next<78>seek<65>
startswith<EFBFBD> RuntimeError)<03>fh<66>pos<6F>liner r r
<00> _sanity_check\s  
r*cCs tttttttttttdd<02>tttttttttttd<03>}i}x<>|D]<5D>}|<03><05>}|<03>d<04>rZqB|<03>dd<06>}|d}t|<04>dkr<>|d}nd }y ||}Wn$t k
r<EFBFBD>t
<EFBFBD> d
|<00>wBYnXy||<06>||<Wn$t k
r<EFBFBD>t
<EFBFBD> d ||<06>wBYnX|d krB|SqBWt d <0A><01>dS)a=
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; e.g.:
* '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
cSs|S)Nr )rr r r
<00><lambda><3E><00>z_parse_header.<locals>.<lambda>)sStartFontMetricssFontNamesFullNames
FamilyNamesWeights ItalicAngles IsFixedPitchsFontBBoxsUnderlinePositionsUnderlineThicknesssVersionsNoticesEncodingSchemes CapHeights CapheightsXHeightsAscenders DescendersStdHWsStdVWsStartCharMetricss CharacterSets
CharacterssCommentrrr<00>r,z/Found an unknown keyword in AFM header (was %r)z)Value error parsing header in AFM: %s, %ssStartCharMetricsz Bad parseN)rrr!rr <00>rstripr%r<00>len<65>KeyError<6F>_log<6F>error<6F>
ValueErrorr&)r'Zheader_converters<72>dr)<00>lst<73>keyr<00> converterr r r
<00> _parse_headeros\

  
 r8<00> CharMetricszwidth, name, bboxz<78>
Represents the character metrics of a single character.
Notes
-----
The fields do currently only describe a subset of character metrics
information defined in the AFM standard.
zThe character width (WX).zThe character name (N).zK
The bbox of the character (B) as a tuple (*llx*, *lly*, *urx*, *ury*).c Cs<>ddddh}i}i}x<>|D]<5D>}t|<04><01><00>}|<04>d<05>r<||fStdd<07>|<04>d<08>D<00><01>}|<01>|<05>sjtd |<00><01>t|d<00>}t|d<00>}|d}t |d<00>} t
t t | <09><02>} t ||| <09>}
|d
kr<>d }|d kr<>|
||<|
||<qWtd <0A><01>dS)a<>
Parse the given filehandle for character metrics information and return
the information as dicts.
It is assumed that the file cursor is on the line behind
'StartCharMetrics'.
Returns
-------
ascii_d : dict
A mapping "ASCII num of the character" to `.CharMetrics`.
name_d : dict
A mapping "character name" to `.CharMetrics`.
Notes
-----
This function is incomplete per the standard, but thus far parses
all the sample afm files tried.
<20>CZWX<57>N<>BZEndCharMetricscss"|]}|r|<01><00><00>dd<01>VqdS)<03> rN)r r)rrr r r
<00> <genexpr><3E>sz&_parse_char_metrics.<locals>.<genexpr><3E>;zBad char metrics line: %sZEuro<72><6F><00><><EFBFBD><EFBFBD><EFBFBD>z Bad parseN)rr.r%<00>dictr<00>issubsetr&r rr<00>list<73>maprr9) r'Z required_keysZascii_dZname_dr)<00>vals<6C>num<75>wx<77>name<6D>bboxZmetricsr r r
<00>_parse_char_metrics<63>s, 
 

      rKcCs<>t|<00>}|<01>d<01>std|<00><01>i}x<>|D]<5D>}|<01><03>}|s:q(|<01>d<03>rPt|<00>|S|<01><04>}t|<03>dksp|ddkr|td|<00><01>t|d<00>t|d <00>t|d
<00>}}}||||f<q(Wtd <0B><01>d S) z<>
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
sStartKernPairsz Bad start of kern pairs data: %ss EndKernPairs<72>rsKPXzBad kern pairs line: %srr-<00>zBad kern pairs parseN)r#r%r&r.rr/rr)r'r)r4rF<00>c1<63>c2rr r r
<00>_parse_kern_pairs<72>s" 
 

 (rP<00> CompositePartz name, dx, dyzK
Represents the information on a composite element of a composite char.zName of the part, e.g. 'acute'.z+x-displacement of the part from the origin.z+y-displacement of the part from the origin.c Cs<>i}x<>|D]<5D>}|<02><00>}|sq
|<02>d<01>r*|S|<02>d<02>}|d<00><02>}|dt|d<00>}}g}xF|dd<06>D]6}|<08><02>} t| dt| d<00>t| d<00><01>}
|<07>|
<EFBFBD>qhW|||<q
Wtd<08><01>d S)
a<EFBFBD>
Parse the given filehandle for composites information return them as a
dict.
It is assumed that the file cursor is on the line behind 'StartComposites'.
Returns
-------
composites : dict
A dict mapping composite character names to a parts list. The parts
list is a list of `.CompositePart` entries describing the parts of
the composite.
Example
-------
A composite definition line::
CC Aacute 2 ; PCC A 0 0 ; PCC acute 160 170 ;
will be represented as::
composites['Aacute'] = [CompositePart(name='A', dx=0, dy=0),
CompositePart(name='acute', dx=160, dy=170)]
s EndComposites<65>;rrr-rArMzBad composites parseN)r.r%rr rQr<00>appendr&) r'<00>
compositesr)rF<00>ccrIZnumPartsZpccPartsrZpcc<63>partr r r
<00>_parse_composites%s"


   rWcCsdttd<01>}iid<01>}x>|D]6}|<03><02>}|s,q|<03><03>d}||kr|||<00>||<qW|d|dfS)aJ
Parse the optional fields for kern pair data and composites.
Returns
-------
kern_data : dict
A dict containing kerning information. May be empty.
See `._parse_kern_pairs`.
composites : dict
A dict containing composite information. May be empty.
See `._parse_composites`.
)s StartKernDatasStartCompositesrs StartKernDatasStartComposites)rPrWr.r)r'<00>optionalr4r)r6r r r
<00>_parse_optionalSs
 rYz3.0z the AFM class)<01> alternativecCst|<00>S)N)<01>
_parse_afm)r'r r r
<00> parse_afmssr\cCs6t|<00>t|<00>}t|<00>\}}t|<00>\}}|||||fS)a<>
Parse the Adobe Font Metrics file in file handle *fh*.
Returns
-------
header : dict
A header dict. See :func:`_parse_header`.
cmetrics_by_ascii : dict
From :func:`_parse_char_metrics`.
cmetrics_by_name : dict
From :func:`_parse_char_metrics`.
kernpairs : dict
From :func:`_parse_kern_pairs`.
composites : dict
From :func:`_parse_composites`
)r*r8rKrY)r'<00>headerZcmetrics_by_asciiZcmetrics_by_nameZ kernpairsrTr r r
r[xs
  r[c@s<>eZdZdd<02>Zd/dd<05>Zdd<07>Zdd <09>Zd
d <0B>Zd0d d <0A>Zd1dd<0F>Z dd<11>Z
d2dd<13>Z dd<15>Z dd<17>Z dd<19>Zdd<1B>Zdd<1D>Zedd<1F><00>Zd d!<21>Zd"d#<23>Zd$d%<25>Zd&d'<27>Zd(d)<29>Zd*d+<2B>Zd,d-<2D>Zd.S)3<>AFMcCs t|<01>\|_|_|_|_|_dS)z'Parse the AFM file in file object *fh*.N)r[<00>_header<65>_metrics<63>_metrics_by_name<6D>_kernZ
_composite)<02>selfr'r r r
<00>__init__<5F>sz AFM.__init__FcCs|s t|<01>}|j|jS)N)<03>ordr`rJ)rc<00>c<>isordr r r
<00> get_bbox_char<61>szAFM.get_bbox_charcCs<>t|<01>s dSd}d}d}d}xl|D]d}|dkr0q"|jt|<06>\}}} |||j<03>||fd<02>7}| \}
} } } t|| <0B>}t|| | <00>}|}q"W|||fS)zn
Return the string width (including kerning) and string height
as a (*w*, *h*) tuple.
)rrrNge<><65>A<EFBFBD>
)r/r`rerb<00>get<65>min<69>max)rcr<00> total_width<74>namelast<73>miny<6E>maxyrfrHrIrJ<00>l<>b<>w<>hr r r
<00>string_width_height<68>s 
 
zAFM.string_width_heightc Cs<>t|<01>s dSd}d}d}d}d}t|t<02>s2t|<01>}x<>|D]<5D>}|dkrFq8t<04>t|<07>d<06>}y|j|\} }
} Wn(tk
r<EFBFBD>d}|j|\} }
} YnX|| |j <09>||fd<02>7}| \} } }}t
|| <0C>}t
|| <0A>}t || |<00>}|}q8W|||||| fS)z7Return the string bounding box and the maximal descent.)rrrrrrNge<><65>AriZquestion) r/r<00>strrrrjrerar0rbrkrl)rcrrmrnrorp<00>leftrfrIrH<00>_rJrqrrrsrtr r r
<00>get_str_bbox_and_descent<6E>s2

 

zAFM.get_str_bbox_and_descentcCs|<00>|<01>dd<02>S)zReturn the string bounding box.NrL)ry)rcrr r r
<00> get_str_bbox<6F>szAFM.get_str_bboxcCs|s t|<01>}|j|jS)z8Get the name of the character, i.e., ';' is 'semicolon'.)rer`rI)rcrfrgr r r
<00> get_name_char<61>szAFM.get_name_charcCs|s t|<01>}|j|jS)zT
Get the width of the character from the character metric WX field.
)rer`<00>width)rcrfrgr r r
<00>get_width_char<61>szAFM.get_width_charcCs |j|jS)z;Get the width of the character from a type1 character name.)rar|)rcrIr r r
<00>get_width_from_char_name<6D>szAFM.get_width_from_char_namecCs|s t|<01>}|j|jdS)z@Get the bounding box (ink) height of character *c* (space is 0).rA)rer`rJ)rcrfrgr r r
<00>get_height_char<61>szAFM.get_height_charcCs"|<00>|<01>|<00>|<02>}}|<00>||<04>S)zX
Return the kerning pair distance (possibly 0) for chars *c1* and *c2*.
)r{<00>get_kern_dist_from_name)rcrNrO<00>name1<65>name2r r r
<00> get_kern_dist<73>szAFM.get_kern_distcCs|j<00>||fd<01>S)zf
Return the kerning pair distance (possibly 0) for chars
*name1* and *name2*.
r)rbrj)rcr<>r<>r r r
r<><00>szAFM.get_kern_dist_from_namecCs
|jdS)z*Return the font name, e.g., 'Times-Roman'.sFontName)r_)rcr r r
<00> get_fontnameszAFM.get_fontnamecCs"|j<00>d<01>}|dkr|jd}|S)z/Return the font full name, e.g., 'Times-Roman'.sFullNameNsFontName)r_rj)rcrIr r r
<00> get_fullnames 
zAFM.get_fullnamecCs2|j<00>d<01>}|dk r|S|<00><02>}d}t<03>|d|<01>S)z+Return the font family name, e.g., 'Times'.s
FamilyNameNzY(?i)([ -](regular|plain|italic|oblique|bold|semibold|light|ultralight|extra|condensed))+$<24>)r_rjr<><00>re<72>sub)rcrI<00>extrasr r r
<00>get_familyname s  zAFM.get_familynamecCs|<00><00>S)z$The font family name, e.g., 'Times'.)r<>)rcr r r
<00> family_nameszAFM.family_namecCs
|jdS)z0Return the font weight, e.g., 'Bold' or 'Roman'.sWeight)r_)rcr r r
<00>
get_weightszAFM.get_weightcCs
|jdS)zReturn the fontangle as float.s ItalicAngle)r_)rcr r r
<00> get_angle!sz AFM.get_anglecCs
|jdS)zReturn the cap height as float.s CapHeight)r_)rcr r r
<00> get_capheight%szAFM.get_capheightcCs
|jdS)zReturn the xheight as float.sXHeight)r_)rcr r r
<00> get_xheight)szAFM.get_xheightcCs
|jdS)z(Return the underline thickness as float.sUnderlineThickness)r_)rcr r r
<00>get_underline_thickness-szAFM.get_underline_thicknesscCs|j<00>dd<02>S)zu
Return the standard horizontal stem width as float, or *None* if
not specified in AFM file.
sStdHWN)r_rj)rcr r r
<00>get_horizontal_stem_width1szAFM.get_horizontal_stem_widthcCs|j<00>dd<02>S)zs
Return the standard vertical stem width as float, or *None* if
not specified in AFM file.
sStdVWN)r_rj)rcr r r
<00>get_vertical_stem_width8szAFM.get_vertical_stem_widthN)F)F)F)F)<1A>__name__<5F>
__module__<EFBFBD> __qualname__rdrhruryrzr{r}r~rr<>r<>r<>r<>r<><00>propertyr<79>r<>r<>r<>r<>r<>r<>r<>r r r r
r^<00>s,



 r^)#<23>__doc__<5F> collectionsr<00>loggingr<67>Z_mathtext_datarZmatplotlib.cbookr<00> getLoggerr<72>r1r rrrrr!r*r8r9r|rIrJrKrPrQZdxZdyrWrYr\r[<00>objectr^r r r r
<00><module>&s>   
  K
4
.