Can I get access font glyph/character paths?

Godot Version

4.2.1

Question

There have been a lot of nice additions to text and font support lately in Godot, like access to installed system fonts and a lot of technical font data useful for text layout.

However, I haven’t found any way to get access to the actual character paths (as in the vector outline of the glyphs). It seems like at least internally this is available to Godot as it can be used to render text and generate TextMeshes. Is there any way for me to get access to this font glyph path data via GDScript? Or some other more way?

You can access the glyph contours with TextServer.font_get_glyph_contours()

Example:

func _ready() -> void:
	var font = get_tree().root.get_theme_default_font()
	var font_rid = font.get_rids()[0]
	var text_server = TextServerManager.get_primary_interface()
	var glyph_index = text_server.font_get_glyph_index(font_rid, 16, "1".unicode_at(0), 0)
	var contours = text_server.font_get_glyph_contours(font_rid, 16, glyph_index)
	print(contours)

Here’s how TextMesh interpret that information to generate the mesh godot/scene/resources/primitive_meshes.cpp at 0bcc0e92b3f0ac57d4c4650722f347593a258572 · godotengine/godot · GitHub

1 Like

Great, thanks! Looks like exactly the thing I was looking for. I guess the terminology threw me off as I was looking for paths and not contours.

And thanks for the link to the TextMesh generation as well, I tried looking for that as well, but couldn’t find it in the code as I didn’t realize it was in this big primitive_meshes.cpp file.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.