Text & Fonts

Font loading, drawing, measurement, UTF-8 + codepoint utilities, string helpers.

Text reference

Font loading, drawing, measurement, glyph lookup, UTF-8 + codepoint utilities, string helpers. Everything raylib's rtext.c ships.

Font loading

Font.load(filePath: String) -> Font

Category: Loading · raylib: LoadFont

Load TTF/OTF/FNT. Check Font.is_valid(f); unload with Font.unload(f).

val font = Font.load("tests/assets/fonts/roboto.ttf")

raylib cheatsheet · Iron source · Test usage

Font.load_ex(filePath: String, fontSize: Int32, codepoints: [Int32]) -> Font

Category: Loading · raylib: LoadFontEx

Load font with specific pixel size + subset of codepoints (smaller atlas). Empty codepoints loads 95 printable ASCII.

val font = Font.load_ex("roboto.ttf", Int32(32), [])

raylib cheatsheet · Iron source · Test usage

Font.from_image(image: Image, keyColor: Color, firstChar: Int32) -> Font

Category: Loading · raylib: LoadFontFromImage

Build font from an atlas image — keyColor pixels separate glyphs.

val font = Font.from_image(atlas, MAGENTA, Int32(32))

raylib cheatsheet · Iron source · Test usage

Font.from_memory(file_type, data: [UInt8], data_size, font_size, codepoints: [Int32]) -> Font

Category: Loading · raylib: LoadFontFromMemory

Load font from in-memory byte buffer (e.g. embedded resource).

In-memory font bytes

Use this when the font bytes already live in memory, such as embedded assets or data loaded with Files.load_data.

val font = Font.from_memory(".ttf", bytes, Int32(bytes.length), Int32(32), [])

raylib cheatsheet · Iron source · Test usage

Font export + atlas

Font.export_as_code(font, filePath: String) -> Bool / Font.gen_image_atlas(glyphs, fontSize, padding, packMethod) / Font.unload_data(glyphs)

Category: Export · raylib: ExportFontAsCode / GenImageFontAtlas / UnloadFontData

Dump font as C source; pack glyphs into a new atlas image; free glyph table.

Font.export_as_code(font, "embedded_font.h")

raylib cheatsheet · Iron source · Test usage

Text draw

Draw.text(text, posX, posY, fontSize: Int32, color: Color)

Category: Draw · raylib: DrawText

Default-font text draw. For loaded fonts use font.draw_ex.

Draw.text("Hello", Int32(200), Int32(280), Int32(24), WHITE)

raylib cheatsheet · Iron source · Test usage

Font.draw_ex(font, text, position, fontSize, spacing, tint)

Category: Draw · raylib: DrawTextEx

Draw with specific loaded font at float position + spacing.

Font.draw_ex(font, "hi", pos, Float32(32.0), Float32(2.0), WHITE)

raylib cheatsheet · Iron source · Test usage

Font.draw_pro(font, text, position, origin, rotation, fontSize, spacing, tint)

Category: Draw · raylib: DrawTextPro

Draw with rotation around an origin point.

Font.draw_pro(font, "ROTATE", pos, origin, Float32(45.0), Float32(32.0), Float32(0.0), RED)

raylib cheatsheet · Iron source · Test usage

Font.draw_codepoint(font, codepoint, position, fontSize, tint) / draw_codepoints(font, codepoints: [Int32], ...)

Category: Draw · raylib: DrawTextCodepoint / Codepoints

Single codepoint or explicit array (skip UTF-8 decoding).

Font.draw_codepoint(font, Int32(0x1F600), pos, Float32(64.0), WHITE)

raylib cheatsheet · Iron source · Test usage

Text measure

Text.measure(text: String, fontSize: Int32) -> Int32 / Font.measure_ex(font, text, fontSize, spacing) -> Vector2 / Text.set_line_spacing(spacing: Int32)

Category: Measure · raylib: MeasureText / MeasureTextEx / SetTextLineSpacing

Default-font width; loaded-font Vector2; line-height override.

val w = Text.measure("PLAY", Int32(48))

raylib cheatsheet · Iron source · Test usage

Glyph lookup

Font.get_glyph_index / get_glyph_info / get_glyph_atlas_rec

Category: Glyph · raylib: GetGlyphIndex / GetGlyphInfo / GetGlyphAtlasRec

Per-codepoint metadata: slot in atlas, full GlyphInfo struct, source rectangle in the atlas texture.

val info = Font.get_glyph_info(font, Int32(0x41))

raylib cheatsheet · Iron source · Test usage

UTF-8 + codepoints

Text.load_codepoints(text: String) -> [Int32] / Text.load_utf8(codepoints: [Int32]) -> String

Category: UTF-8 · raylib: LoadCodepoints / LoadUTF8

Decode UTF-8 string into codepoint array; encode codepoints back to UTF-8.

val cps = Text.load_codepoints("héllo")

raylib cheatsheet · Iron source · Test usage

Text.codepoint_count(text: String) -> Int32 / codepoint_to_utf8(codepoint: Int32) -> String

Category: UTF-8 · raylib: GetCodepointCount / CodepointToUTF8

Count logical characters (grapheme count ≈ codepoint count); single-codepoint → UTF-8 string.

val n = Text.codepoint_count("こんにちは")

raylib cheatsheet · Iron source · Test usage

Text.codepoint_at / codepoint_next / codepoint_previous(text, offset) -> (Int32, Int32)

Category: UTF-8 · raylib: GetCodepoint / Next / Previous

Cursor-style UTF-8 iteration. Returns (codepoint, byteCount-consumed).

val (cp, n) = Text.codepoint_next(text, Int32(0))

raylib cheatsheet · Iron source · Test usage

String helpers

Text.format_i / format_f / format_s

Category: Strings · raylib: TextFormat

printf-style formatters for Int32, Float32, String. fmt uses %i / %f / %s.

val s = Text.format_i("score: %i", Int32(score))

raylib cheatsheet · Iron source · Test usage

Text.subtext / replace / insert / find_index

Category: Strings · raylib: TextSubtext / Replace / Insert / FindIndex

Substring extraction / replace / insertion / index search.

val part = Text.subtext(text, Int32(0), Int32(5))

raylib cheatsheet · Iron source · Test usage

Text.join(parts: [String], delimiter: String) / split(text, delimiter) -> [String]

Category: Strings · raylib: TextJoin / Split

Collection ↔ string conversions.

val parts = Text.split("a,b,c", ",")

raylib cheatsheet · Iron source · Test usage

Text.to_upper / to_lower / to_pascal / to_snake / to_camel

Category: Strings · raylib: TextToUpper / Lower / Pascal / Snake / Camel

Case conversions (identifier-friendly for code generators).

val id = Text.to_snake("HelloWorld")  -- "hello_world"

raylib cheatsheet · Iron source · Test usage

Text.to_integer(text) -> Int32 / to_float(text) -> Float32

Category: Strings · raylib: TextToInteger / TextToFloat

String → numeric. Returns 0 on parse failure.

val n = Text.to_integer("42")

raylib cheatsheet · Iron source · Test usage

See also