font
font
¶
Text rendering via SDL_ttf 3.x.
Rasterizes each string to a surface with TTF_RenderText_Blended, uploads it as a transient texture, and draws it as a quad. UTF-8 in, no rune-pointer juggling.
newFont ¶
proc newFont(filename: string; size: cint): Font
Open a TrueType font at the given pixel size. Raises IOError when the
file cannot be opened.
Parameters
-
filename(string) -
size(cint)
Returns
Font
newImageFont ¶
proc newImageFont(nim2d: Nim2d; data: ImageData; glyphs: string; spacing: int32 = 1): Font
A bitmap font from a glyph sheet. The glyphs sit in a row separated by
columns of the sheet's top-left pixel color, and glyphs lists the
characters in that order. It is sampled crisply (nearest) and tinted by the
current color, like the TTF path. Good for pixel-art text.
Parameters
-
nim2d(Nim2d) -
data(ImageData) -
glyphs(string) -
spacing(int32)
Returns
Font
newImageFont ¶
proc newImageFont(nim2d: Nim2d; filename, glyphs: string; spacing: int32 = 1): Font
A bitmap font loaded from an image file. See the other overload.
Parameters
-
nim2d(Nim2d) -
filename(string) -
glyphs(string) -
spacing(int32)
Returns
Font
getAscent ¶
proc getAscent(font: Font): int
How far the font reaches above the baseline, in pixels. A bitmap font
reports its glyph height, since it draws from the top.
Parameters
-
font(Font)
Returns
int
getDescent ¶
proc getDescent(font: Font): int
How far the font reaches below the baseline, as a negative pixel count.
A bitmap font reports 0.
Parameters
-
font(Font)
Returns
int
getHeight ¶
proc getHeight(font: Font): int
getSize ¶
proc getSize(font: Font; text: string): tuple[w, h: int32]
The width and height in pixels that text would take when printed.
Parameters
-
font(Font) -
text(string)
Returns
tuple[w, h: int32]
print ¶
proc print(nim2d: Nim2d; text: string; x, y: float; angle: float = 0; sx: float = 1; sy: float = 1)
Draw text in the current color using the current font. Call inside draw.
Parameters
-
nim2d(Nim2d) -
text(string) -
x(float) -
y(float) -
angle(float) -
sx(float) -
sy(float)