Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

FontVariation

继承: Font < Resource < RefCounted < Object

字体的变体,提供额外的设置。

描述

提供 OpenType 变体,模拟的粗体/斜体,以及 OpenType 特性和额外间距等额外的字体设置。

要使用模拟的粗体变体:

var fv = FontVariation.new()
fv.set_base_font(load("res://BarlowCondensed-Regular.ttf"))
fv.set_variation_embolden(1.2)
$Label.add_theme_font_override("font", fv)
$Label.add_theme_font_size_override("font_size", 64)

要设置多个变体轴的坐标:

var fv = FontVariation.new();
var ts = TextServerManager.get_primary_interface()
fv.base_font = load("res://BarlowCondensed-Regular.ttf")
fv.variation_opentype = { ts.name_to_tag("wght"): 900, ts.name_to_tag("custom_hght"): 900 }

属性

Font

base_font

Dictionary

opentype_features

{}

int

spacing_bottom

0

int

spacing_glyph

0

int

spacing_space

0

int

spacing_top

0

float

variation_embolden

0.0

int

variation_face_index

0

Dictionary

variation_opentype

{}

Transform2D

variation_transform

Transform2D(1, 0, 0, 1, 0, 0)

方法

void

set_spacing ( SpacingType spacing, int value )


属性说明

Font base_font

  • void set_base_font ( Font value )

  • Font get_base_font ( )

用于创建变体的基础字体。如果未设置,则使用默认的 Theme 字体。


Dictionary opentype_features = {}

一组 OpenType 功能标签。更多信息:OpenType 功能标签


int spacing_bottom = 0

行底部的额外间距,单位为像素。


int spacing_glyph = 0

图形字形之间的额外间距。


int spacing_space = 0

空格字形的额外宽度。


int spacing_top = 0

行顶部的额外间距,单位为像素。


float variation_embolden = 0.0

  • void set_variation_embolden ( float value )

  • float get_variation_embolden ( )

如果不等于零,则加粗字体轮廓。负值会减小轮廓厚度。

注意:加粗字体可能有自相交的轮廓,这将阻止 MSDF 字体和 TextMesh 正常工作。


int variation_face_index = 0

  • void set_variation_face_index ( int value )

  • int get_variation_face_index ( )

在 TrueType / OpenType 集合文件中的活动字体索引。


Dictionary variation_opentype = {}

字体 OpenType 变体坐标。详见:OpenType 变体标签

注意:这个 Dictionary 使用 OpenType 标签作为键。变体轴既可以用标签来标识(int,例如 0x77678674),也可以用名称来标识(String,例如 wght)。有些轴可以通过多个名称来访问。例如,wghtweight 引用的是同一个轴。而标签则是唯一的。要在名称和标签之间转换,请使用 TextServer.name_to_tagTextServer.tag_to_name

注意:要获取字体的可用变体轴,请使用 Font.get_supported_variation_list


Transform2D variation_transform = Transform2D(1, 0, 0, 1, 0, 0)

应用于字体轮廓的 2D 变换,可用于倾斜、翻转和旋转字形。

例如,要通过倾斜来模拟斜体字体,请应用以下变换 Transform2D(1.0, slant, 0.0, 1.0, 0.0, 0.0)


方法说明

void set_spacing ( SpacingType spacing, int value )

spacing 的间距(见 SpacingType)设置为 value,单位为像素(与字体大小无关)。