matplotlib.ft2font#

class matplotlib.ft2font.FT2Font(self: matplotlib.ft2font.FT2Font, filename: object, hinting_factor: int = 8, *, _fallback_list: list[matplotlib.ft2font.FT2Font] | None = None, _kerning_factor: int = 0)#

基类:pybind11_object

创建一个新的 FT2Font 对象。

参数:
文件名str 或 file-like

字体数据的来源,格式为 FreeType 可以读取的格式(ttf 或 ttc)

hinting_factorint, 可选

必须为正数。用于在x方向上缩放提示。

_fallback_listFT2Font 列表,可选

用于查找缺失字形的 FT2Font 对象列表。

警告

此API既私有又临时:请勿直接使用它

_kerning_factorint, 可选

用于调整字距的程度。

警告

此API是私有的:请勿直接使用

property ascender#

上升部分为26.6单位。

property bbox#

面部全局边界框 (xmin, ymin, xmax, ymax)。

clear(self: matplotlib.ft2font.FT2Font) None#

清除所有字形,为新的 set_text 调用重置。

property descender#

在26.6单位中的下降。

draw_glyph_to_bitmap(self: matplotlib.ft2font.FT2Font, image: matplotlib.ft2font.FT2Image, x: float, y: float, glyph: matplotlib.ft2font.Glyph, *, antialiased: bool = True) None#

在位图的像素位置 x, y 处绘制一个单独的字形。

请注意,在此调用之前,您有责任手动创建具有正确尺寸的图像。

如果你想自动布局,请结合使用 set_textdraw_glyphs_to_bitmap。这个函数是为那些想要在精确位置渲染单个字形(例如,由 load_char 返回的字形)的人设计的。

draw_glyphs_to_bitmap(self: matplotlib.ft2font.FT2Font, *, antialiased: bool = True) None#

将通过 set_text 加载的图元绘制到位图中。

位图大小将自动设置以包含字形。

property face_flags#

面部标志;参见 ft2font 常量。

property family_name#

面对家庭姓氏。

property fname#

!! 由 numpydoc 处理 !!

get_bitmap_offset(self: matplotlib.ft2font.FT2Font) tuple#

如果墨水悬挂在左边或下方 (0, 0),获取位图的 (x, y) 偏移量,单位为 26.6 子像素。由于 Matplotlib 仅支持从左到右的文本,y 始终为 0。

get_char_index(self: matplotlib.ft2font.FT2Font, codepoint: int) int#

返回对应于字符 代码点 的字形索引。

get_charmap(self: matplotlib.ft2font.FT2Font) dict#

返回一个字典,该字典将所选字符映射(默认是Unicode)的字符代码映射到其对应的字形索引。

get_descent(self: matplotlib.ft2font.FT2Font) int#

获取由 set_text 设置的当前字符串在26.6个子像素中的下降值。字符串的旋转已被考虑在内。要获取以像素为单位的下降值,请将此值除以64。

get_glyph_name(self: matplotlib.ft2font.FT2Font, index: int) str#

获取给定字形 index 在字体中的 ASCII 名称。

由于 Matplotlib 的内部设计,对于不包含字形名称(根据 FT_FACE_FLAG_GLYPH_NAMES)的字体,这将返回一个虚构的名称,该名称*不会*通过 get_name_index 进行往返。

get_image(self: matplotlib.ft2font.FT2Font) numpy.ndarray#

返回此字体对象的基础图像缓冲区。

get_kerning(self: matplotlib.ft2font.FT2Font, left: int, right: int, mode: int) int#

获取 字形索引之间的字距。

mode 是一个字距调整模式常量:

  • KERNING_DEFAULT - 返回缩放和网格拟合的字距调整距离

  • KERNING_UNFITTED - 返回缩放但未网格拟合的字距调整距离

  • KERNING_UNSCALED - 以原始字体单位返回字距向量

get_name_index(self: matplotlib.ft2font.FT2Font, name: str) int#

返回给定字形 名称 的字形索引。字形索引 0 表示 '未定义字符代码'。

get_num_glyphs(self: matplotlib.ft2font.FT2Font) int#

返回加载的字形数量。

get_path(self: matplotlib.ft2font.FT2Font) tuple#

从当前加载的字形中获取路径数据,作为顶点和代码的元组。

get_ps_font_info(self: matplotlib.ft2font.FT2Font) tuple#

返回PS字体信息结构中的信息。

get_sfnt(self: matplotlib.ft2font.FT2Font) dict#

加载整个 SFNT 名称表,作为一个字典,其键是 (平台ID, ISO编码方案, 语言代码, 描述) 元组。

get_sfnt_table(self: matplotlib.ft2font.FT2Font, name: str) dict | None#

返回以下SFNT表之一:head、maxp、OS/2、hhea、vhea、post或pclt。

get_width_height(self: matplotlib.ft2font.FT2Font) tuple#

获取当前由 set_text 设置的字符串在 26.6 子像素中的宽度和高度。字符串的旋转已被考虑在内。要获取以像素为单位的宽度和高度,请将这些值除以 64。

property height#

高度为26.6单位;用于计算默认行间距(基线到基线的距离)。

load_char(self: matplotlib.ft2font.FT2Font, charcode: int, flags: int = 32) matplotlib.ft2font.Glyph#

在当前字体文件中加载带有 charcode 的字符并设置字形。flags 可以是 LOAD_XXX 常量的按位或;默认值是 LOAD_FORCE_AUTOHINT。返回值是一个 Glyph 对象,具有属性。

  • 宽度: 字形宽度

  • 高度: 字形高度

  • bbox: 字形 bbox (xmin, ymin, xmax, ymax)

  • horiBearingX: 水平布局中的左侧边距

  • horiBearingY: 水平布局中的顶部边距

  • horiAdvance: 水平布局的推进宽度

  • vertBearingX: 垂直布局中的左侧间距

  • vertBearingY: 垂直布局中的顶部侧向轴承

  • vertAdvance: 垂直布局的推进高度

load_glyph(self: matplotlib.ft2font.FT2Font, glyph_index: int, flags: int = 32) matplotlib.ft2font.Glyph#

在当前字体文件中使用 glyphindex 加载字符并设置字形。flags 可以是 LOAD_XXX 常量的按位或;默认值为 LOAD_FORCE_AUTOHINT。返回值是一个 Glyph 对象,具有属性

  • 宽度: 字形宽度

  • 高度: 字形高度

  • bbox: 字形 bbox (xmin, ymin, xmax, ymax)

  • horiBearingX: 水平布局中的左侧边距

  • horiBearingY: 水平布局中的顶部边距

  • horiAdvance: 水平布局的推进宽度

  • vertBearingX: 垂直布局中的左侧间距

  • vertBearingY: 垂直布局中的顶部侧向轴承

  • vertAdvance: 垂直布局的推进高度

property max_advance_height#

所有字形的最大垂直光标前进量。

property max_advance_width#

所有字形的最大水平光标前进距离。

property num_charmaps#

!! 由 numpydoc 处理 !!

property num_faces#

文件中的面数。

property num_fixed_sizes#

面中的位图数量。

property num_glyphs#

字体中的字形数量。

property postscript_name#

字体的 PostScript 名称。

property scalable#

是否为可缩放字体;此属性之后的属性仅针对可缩放字体定义。

select_charmap(self: matplotlib.ft2font.FT2Font, i: int) None#

通过其 FT_Encoding 编号选择一个字符映射。

set_charmap(self: matplotlib.ft2font.FT2Font, i: int) None#

将第 i 个字符映射设为当前。

set_size(self: matplotlib.ft2font.FT2Font, ptsize: float, dpi: float) None#

设置文本的点大小和dpi。

set_text(self: matplotlib.ft2font.FT2Font, string: str, angle: float = 0.0, flags: int = 32) numpy.ndarray[numpy.float64]#

设置文本 字符串角度标志 可以是 LOAD_XXX 常量的按位或;默认值是 LOAD_FORCE_AUTOHINT。你必须在调用 draw_glyphs_to_bitmap 之前调用此函数。返回一个 26.6 子像素的 x,y 位置序列;除以 64 得到像素值。

property style_flags#

样式标志;参见 ft2font 常量。

property style_name#

样式名称。

property underline_position#

下划线栏的垂直位置。

property underline_thickness#

下划线栏的厚度。

property units_per_EM#

EM 覆盖的字体单位数量。

class matplotlib.ft2font.FT2Image(self: matplotlib.ft2font.FT2Image, width: float, height: float)#

基类:pybind11_object

draw_rect_filled(self: matplotlib.ft2font.FT2Image, x0: float, y0: float, x1: float, y1: float) None#

在图像上绘制一个填充矩形。

class matplotlib.ft2font.Glyph(self: matplotlib.ft2font.Glyph)#

基类:pybind11_object

property bbox#

!! 由 numpydoc 处理 !!

property height#

!! 由 numpydoc 处理 !!

property horiAdvance#

!! 由 numpydoc 处理 !!

property horiBearingX#

!! 由 numpydoc 处理 !!

property horiBearingY#

!! 由 numpydoc 处理 !!

property linearHoriAdvance#

!! 由 numpydoc 处理 !!

property vertAdvance#

!! 由 numpydoc 处理 !!

property vertBearingX#

!! 由 numpydoc 处理 !!

property vertBearingY#

!! 由 numpydoc 处理 !!

property width#

!! 由 numpydoc 处理 !!