Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

FontVariation

繼承: Font < Resource < RefCounted < Object

字形的變體,提供額外的設定。

說明

Provides OpenType variations, simulated bold / slant, and additional font settings like OpenType features and extra spacing.

To use simulated bold font variant:

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

To set the coordinate of multiple variation axes:

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

float

baseline_offset

0.0

Dictionary

opentype_features

{}

PackedColorArray

palette_custom_colors

PackedColorArray()

int

palette_index

0

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(spacing: SpacingType, value: int)


屬性說明

Font base_font 🔗

  • void set_base_font(value: Font)

  • Font get_base_font()

用於建立變體的基礎字形。如果未設定,則使用預設的 Theme 字形。


float baseline_offset = 0.0 🔗

  • void set_baseline_offset(value: float)

  • float get_baseline_offset()

Extra baseline offset (as a fraction of font height).


Dictionary opentype_features = {} 🔗

一組 OpenType 功能標籤。更多資訊:OpenType 功能標籤


PackedColorArray palette_custom_colors = PackedColorArray() 🔗

An array of colors to override predefined palette. Use Color(0, 0, 0, 0), to keep predefined palette color at specific position.

Note: The returned array is copied and any changes to it will not update the original property value. See PackedColorArray for more details.


int palette_index = 0 🔗

  • void set_palette_index(value: int)

  • int get_palette_index()

A palette index.


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(value: float)

  • float get_variation_embolden()

如果不等於零,則加粗字形輪廓。負值會減小輪廓厚度。

注意:加粗字形可能有自相交的輪廓,這將阻止 MSDF 字形和 TextMesh 正常工作。


int variation_face_index = 0 🔗

  • void set_variation_face_index(value: int)

  • int get_variation_face_index()

在 TrueType / OpenType 集合檔中的活動字形索引。


Dictionary variation_opentype = {} 🔗

Font OpenType variation coordinates. More info: OpenType variation tags.

Note: This Dictionary uses OpenType tags as keys. Variation axes can be identified both by tags (int, e.g. 0x77678674) and names (String, e.g. wght). Some axes might be accessible by multiple names. For example, wght refers to the same axis as weight. Tags on the other hand are unique. To convert between names and tags, use TextServer.name_to_tag() and TextServer.tag_to_name().

Note: To get available variation axes of a font, use 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(spacing: SpacingType, value: int) 🔗

Sets the spacing for spacing to value in pixels (not relative to the font size).