Font

Inherits: Resource < Reference < Object

Inherited By: BitmapFont, DynamicFont

国际化的字体和文本绘制支持。

描述

字体包含一个与 Unicode 兼容的字符集,并且提供使用不同宽度(width)、升部(ascent)、降部(descent) 和字偶距(kerning)进行绘制的能力。关于从 TTF 文件(或其他字体格式)创建字体,请参见编辑器对字体的支持。

注意:DynamicFont 中不包含字符串中所使用的某个字符时,将使用码位 0xfffd 去替换该字符,如果这个替换字符在 DynamicFont 中也不可用,该字符将被隐藏,不在字符串中显示任何替换字符。

注意:BitmapFont 中不包含字符串中所使用的某个字符,该字符将被隐藏,不在字符串中显示任何替换字符。

注意:Windows 上不支持 0xffff 之后的 Unicode 字符(如大多数表情符号)。它们将显示为未知字符。这个问题将在 Godot 4.0 中得到解决。

方法

void

draw ( RID canvas_item, Vector2 position, String string, Color modulate=Color( 1, 1, 1, 1 ), int clip_w=-1, Color outline_modulate=Color( 1, 1, 1, 1 ) ) const

float

draw_char ( RID canvas_item, Vector2 position, int char, int next=-1, Color modulate=Color( 1, 1, 1, 1 ), bool outline=false ) const

float

get_ascent ( ) const

Vector2

get_char_size ( int char, int next=0 ) const

float

get_descent ( ) const

float

get_height ( ) const

Vector2

get_string_size ( String string ) const

Vector2

get_wordwrap_string_size ( String string, float width ) const

bool

has_outline ( ) const

bool

is_distance_field_hint ( ) const

void

update_changes ( )

方法说明

  • void draw ( RID canvas_item, Vector2 position, String string, Color modulate=Color( 1, 1, 1, 1 ), int clip_w=-1, Color outline_modulate=Color( 1, 1, 1, 1 ) ) const

在给定位置使用字体将string绘制到画布项目中,并使用modulate颜色,并可以选择裁剪宽度。 position指定基线,而不是顶部。要从顶部绘制,必须在 Y 轴上添加升部

另请参阅 CanvasItem.draw_string


使用字体在画布项目的指定位置绘制字符 char,使用的颜色是 modulate,并且会根据宽度做裁剪,如果传入了 next 还会利用到字偶距。position 指定的是基线,而不是顶部。要从顶部绘制,必须在 Y 轴上加上字体的升部大小。该函数返回的是字符所使用的宽度,因此用来逐字符绘制字符串非常方便。


  • float get_ascent ( ) const

返回字体的上升幅度(超出基线的像素数)。


返回指定字符的大小,如果提供了下一个字符,还会将字偶距考虑在内。注意,返回的高度是字体高度(见 get_height),与该字形的高度没有关系。


  • float get_descent ( ) const

返回字体的减少量(低于基线的像素数)。


  • float get_height ( ) const

返回总体字体的高度(增加和减少),单位是像素。


返回指定字符串的大小,并考虑到字偶距和前进量。注意,返回的高度是字体高度(见 get_height),与该字符串没有关系。


返回字符串在启用固定宽度 width 的自动换行后的大小。


  • bool has_outline ( ) const

如果字体有轮廓,则返回 true


  • bool is_distance_field_hint ( ) const

  • void update_changes ( )

在编辑一个字体后(改变大小、升部、字框等)。调用这个函数,将变化传播给可能使用它的控件。