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.
Checking the stable version of the documentation...
FontFile¶
继承: Font < Resource < RefCounted < Object
存放字体源数据和预渲染字形的缓存,从动态字体或位图字体导入。
描述¶
FontFile 包含了一组字形,代表从字体文件中导入的 Unicode 字符,还包含了光栅化字形的缓存,以及一组备用的回退 Font。
要访问字体的 OpenType 变体,创建模拟的粗体/斜体版本,或者绘制文本行,请使用 FontVariation。
要进行更复杂的文本处理,请将 FontVariation 与 TextLine 或 TextParagraph 结合使用。
支持的字体格式:
动态字体导入器:TrueType(.ttf)、TrueType 合集(.ttc)、OpenType(.otf)、OpenType 合集(.otc)、WOFF(.woff)、WOFF2(.woff2)、Type 1(.pfb,.pfm)。
位图字体导入器:AngelCode BMFont(.fnt,.font),支持文本和二进制(版本 3)格式变体。
等宽图像字体导入器:所有支持的图像格式。
注意:字符(character)是一种表示某个项目(字母、数字等)的抽象符号。
注意:字形(glphy)是一种位图或形状,用于根据上下文绘制一个或多个字符。字形索引绑定的是某个字体数据源。
注意:如果所有字体数据源都不包含字符串中某个字符的字形,那么该字符就会被替换为一个中间是对应十六进制码的方框。
var f = load("res://BarlowCondensed-Bold.ttf")
$Label.add_theme_font_override("font", f)
$Label.add_theme_font_size_override("font_size", 64)
var f = ResourceLoader.Load<FontFile>("res://BarlowCondensed-Bold.ttf");
GetNode("Label").AddThemeFontOverride("font", f);
GetNode("Label").AddThemeFontSizeOverride("font_size", 64);
教程¶
属性¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
BitField[FontStyle] |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法¶
void |
|
void |
clear_glyphs(cache_index: int, size: Vector2i) |
void |
clear_kerning_map(cache_index: int, size: int) |
void |
clear_size_cache(cache_index: int) |
void |
clear_textures(cache_index: int, size: Vector2i) |
get_cache_ascent(cache_index: int, size: int) const |
|
get_cache_count() const |
|
get_cache_descent(cache_index: int, size: int) const |
|
get_cache_scale(cache_index: int, size: int) const |
|
get_cache_underline_position(cache_index: int, size: int) const |
|
get_cache_underline_thickness(cache_index: int, size: int) const |
|
get_char_from_glyph_index(size: int, glyph_index: int) const |
|
get_embolden(cache_index: int) const |
|
get_extra_baseline_offset(cache_index: int) const |
|
get_extra_spacing(cache_index: int, spacing: SpacingType) const |
|
get_face_index(cache_index: int) const |
|
get_glyph_advance(cache_index: int, size: int, glyph: int) const |
|
get_glyph_index(size: int, char: int, variation_selector: int) const |
|
get_glyph_list(cache_index: int, size: Vector2i) const |
|
get_glyph_offset(cache_index: int, size: Vector2i, glyph: int) const |
|
get_glyph_size(cache_index: int, size: Vector2i, glyph: int) const |
|
get_glyph_texture_idx(cache_index: int, size: Vector2i, glyph: int) const |
|
get_glyph_uv_rect(cache_index: int, size: Vector2i, glyph: int) const |
|
get_kerning(cache_index: int, size: int, glyph_pair: Vector2i) const |
|
get_kerning_list(cache_index: int, size: int) const |
|
get_language_support_override(language: String) const |
|
get_language_support_overrides() const |
|
get_script_support_override(script: String) const |
|
get_script_support_overrides() const |
|
get_size_cache_list(cache_index: int) const |
|
get_texture_count(cache_index: int, size: Vector2i) const |
|
get_texture_image(cache_index: int, size: Vector2i, texture_index: int) const |
|
get_texture_offsets(cache_index: int, size: Vector2i, texture_index: int) const |
|
get_transform(cache_index: int) const |
|
get_variation_coordinates(cache_index: int) const |
|
load_bitmap_font(path: String) |
|
load_dynamic_font(path: String) |
|
void |
remove_cache(cache_index: int) |
void |
remove_glyph(cache_index: int, size: Vector2i, glyph: int) |
void |
remove_kerning(cache_index: int, size: int, glyph_pair: Vector2i) |
void |
remove_language_support_override(language: String) |
void |
remove_script_support_override(script: String) |
void |
remove_size_cache(cache_index: int, size: Vector2i) |
void |
remove_texture(cache_index: int, size: Vector2i, texture_index: int) |
void |
render_glyph(cache_index: int, size: Vector2i, index: int) |
void |
render_range(cache_index: int, size: Vector2i, start: int, end: int) |
void |
set_cache_ascent(cache_index: int, size: int, ascent: float) |
void |
set_cache_descent(cache_index: int, size: int, descent: float) |
void |
set_cache_scale(cache_index: int, size: int, scale: float) |
void |
set_cache_underline_position(cache_index: int, size: int, underline_position: float) |
void |
set_cache_underline_thickness(cache_index: int, size: int, underline_thickness: float) |
void |
set_embolden(cache_index: int, strength: float) |
void |
set_extra_baseline_offset(cache_index: int, baseline_offset: float) |
void |
set_extra_spacing(cache_index: int, spacing: SpacingType, value: int) |
void |
set_face_index(cache_index: int, face_index: int) |
void |
set_glyph_advance(cache_index: int, size: int, glyph: int, advance: Vector2) |
void |
set_glyph_offset(cache_index: int, size: Vector2i, glyph: int, offset: Vector2) |
void |
set_glyph_size(cache_index: int, size: Vector2i, glyph: int, gl_size: Vector2) |
void |
set_glyph_texture_idx(cache_index: int, size: Vector2i, glyph: int, texture_idx: int) |
void |
set_glyph_uv_rect(cache_index: int, size: Vector2i, glyph: int, uv_rect: Rect2) |
void |
set_kerning(cache_index: int, size: int, glyph_pair: Vector2i, kerning: Vector2) |
void |
set_language_support_override(language: String, supported: bool) |
void |
set_script_support_override(script: String, supported: bool) |
void |
set_texture_image(cache_index: int, size: Vector2i, texture_index: int, image: Image) |
void |
set_texture_offsets(cache_index: int, size: Vector2i, texture_index: int, offset: PackedInt32Array) |
void |
set_transform(cache_index: int, transform: Transform2D) |
void |
set_variation_coordinates(cache_index: int, variation_coordinates: Dictionary) |
属性说明¶
bool allow_system_fallback = true
🔗
如果设置为 true
,则可以自动将系统字体作为回退使用。
FontAntialiasing antialiasing = 1
🔗
void set_antialiasing(value: FontAntialiasing)
FontAntialiasing get_antialiasing()
字体抗锯齿模式。
PackedByteArray data = PackedByteArray()
🔗
void set_data(value: PackedByteArray)
PackedByteArray get_data()
动态字体源文件的内容。
Note: The returned array is copied and any changes to it will not update the original property value. See PackedByteArray for more details.
bool disable_embedded_bitmaps = true
🔗
如果为 true
,则会禁用内嵌字体位图的加载(仅包含位图的字体以及彩色字体会禁用该属性)。
字体大小,仅用于位图字体。
FixedSizeScaleMode fixed_size_scale_mode = 0
🔗
void set_fixed_size_scale_mode(value: FixedSizeScaleMode)
FixedSizeScaleMode get_fixed_size_scale_mode()
缩放模式,只有 fixed_size 大于零的位图字体会使用。
字体家族名称。