How to use c++ to construct a Dynamic Font that can be used in modules ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cjmxp

How to use c++ to construct a Dynamic Font that can be used in modules ?

:bust_in_silhouette: Reply From: Zylann

To construct a DynamicFont, you need to create an instance of it, set its size, and assign a DynamicFontData to it (which is obtained by importing a .ttf file for example).

In GDScript, it’s something like:

var font = DynamicFont.new()
font.size = 12 # set some parameters
font.font_data = load("res://some_font.ttf")

In C++, it would be:

Ref<DynamicFont> font(memnew(DynamicFont));
font->set_size(12);
Ref<DynamicFontData> data = ResourceLoader::load("res://some_font.ttf");
font->set_font_data(data);