matplotlib.afm

Adobe字体度量文件的python接口。

尽管存在许多其他python实现,而且可能比这更完整,但决定不使用它们,因为它们是:

  1. 版权所有或使用了不兼容BSD的许可证
  2. 依赖关系太多,需要一个独立的lib
  3. 做的比需要的多,重新写比想办法得到所需的要容易得多。

它非常易于使用,并且没有外部依赖关系:

>>> import matplotlib as mpl
>>> from pathlib import Path
>>> afm_path = Path(mpl.get_data_path(), 'fonts', 'afm', 'ptmr8a.afm')
>>>
>>> from matplotlib.afm import AFM
>>> with afm_path.open('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]

与Adobe字体度量文件格式规范一样,所有尺寸均以所用字体的比例因子(点大小)的1/1000为单位给出。

class matplotlib.afm.AFM(fh)[源代码]

基类:object

在文件对象中分析AFM文件 fh .

property family_name

字体系列名称,例如“Times”。

get_angle()[源代码]

将fontangle返回为float。

get_bbox_char(c, isord=False)[源代码]
get_capheight()[源代码]

将盖高度恢复为浮动。

get_familyname()[源代码]

返回字体系列名称,例如“Times”。

get_fontname()[源代码]

返回字体名,例如“Times Roman”。

get_fullname()[源代码]

返回字体全名,例如“Times Roman”。

get_height_char(c, isord=False)[源代码]

获取字符的边界框(墨迹)高度 c (空间为0)。

get_horizontal_stem_width()[源代码]

将标准水平杆宽度作为浮动返回,或 None 如果AFM文件中未指定。

get_kern_dist(c1, c2)[源代码]

返回字符的紧排对距离(可能为0) c1c2 .

get_kern_dist_from_name(name1, name2)[源代码]

返回字符的紧排对距离(可能为0) NAME1NAME2 .

get_name_char(c, isord=False)[源代码]

获取字符的名称,即“;”是“分号”。

get_str_bbox(s)[源代码]

返回字符串边界框。

get_str_bbox_and_descent(s)[源代码]

返回字符串边界框和最大下降。

get_underline_thickness()[源代码]

将下划线厚度返回为float。

get_vertical_stem_width()[源代码]

将标准垂直杆宽度作为浮动返回,或 None 如果AFM文件中未指定。

get_weight()[源代码]

返回字体粗细,例如“粗体”或“罗马体”。

get_width_char(c, isord=False)[源代码]

从字符度量wx字段中获取字符的宽度。

get_width_from_char_name(name)[源代码]

从type1字符名称中获取字符宽度。

get_xheight()[源代码]

将xheight作为float返回。

string_width_height(s)[源代码]

返回字符串宽度(包括紧排)和字符串高度作为( wh 元组。

class matplotlib.afm.CharMetrics(width, name, bbox)

基类:tuple

表示单个字符的字符度量。

笔记

这些字段目前只描述AFM标准中定义的字符度量信息的子集。

创建charmetrics的新实例(宽度、名称、bbox)

property bbox

作为元组的字符(b)的bbox( llxllyurxury

property name

字符名(n)。

property width

字符宽度(wx)。

class matplotlib.afm.CompositePart(name, dx, dy)

基类:tuple

表示关于复合字符的复合元素的信息。

创建compositepart的新实例(name、dx、dy)

property dx

X—零件从原点的位移。

property dy

Y—零件从原点的位移。

property name

部件名称,例如“急性”。