Skip to content
Steven Arnow edited this page Oct 30, 2013 · 5 revisions

DARNIT_FONT

A handle to a font. When it's loaded, it gets a fixed size.

DARNIT_TEXT_SURFACE

A text surface is used to draw text to the screen. A text surface can be appended with text and be reset, but you can't erase induvidual characters.

DARNIT_FONT_ORIENTATION

Sets what direction to add glyphs in. Default is left-to-right as primary, and top-to-bottom for secondary.

typedef enum {
	DARNIT_FONT_LEFT_TO_RIGHT,
	DARNIT_FONT_RIGHT_TO_LEFT,
	DARNIT_FONT_TOP_TO_BOTTOM
} DARNIT_FONT_ORIENTATION;

d_font_load

DARNIT_FONT *d_font_load(const char *fname, unsigned int size, unsigned int sheet_w, int sheet_h);

Loads a font with the given size.

Arguments

  • fname - File name of the font file
  • size - Font height in pixels
  • sheet_w - Width of the texture to use for caching font glyphs. 256 or 512 is a good number to use
  • sheet_h - Height of the texture to use for caching font glyphs. 256 or 512 is a good number to use

Return value

Returns NULL on failure, everything else is a valid DARNIT_FONT

d_font_glyph_w

unsigned int d_font_glyph_w(DARNIT_FONT *font, const char *s);

Returns the width of a character in pixels.

Arguments

  • font - The font you want the character width for
  • s - A text string containing a UTF-8 character. UTF-8 is compatible with the lower 7-bits of ASCII

Return value

Returns the width of the character in pixels

d_font_string_w

unsigned int d_font_string_w(DARNIT_FONT *font, const char *string);

Returns the width of a string in pixels. The string must be NULL-terminated.

Arguments

  • font - The font to use when calculating the string width
  • string - The string containing the character to add up the width of

Return value

Returns the width of the string in pixels, not taking into account for line breaks.

d_font_word_w

unsigned int d_font_word_w(DARNIT_FONT *font, const char *string, unsigned int *bytes);

Returns the width in pixels of the first word in the string provided by string. bytes is filled in with how many bytes the word contained.

Arguments

  • font - The font to use for these calculations
  • string - The string to count the word length for
  • bytes - Gets set to the number of bytes making up the string. This pointer can be NULL

Return value

Returns the width of the word in pixels

d_font_string_geometrics

unsigned int d_font_string_geometrics(DARNIT_FONT *font, const char *string, int linelen, int *string_w);

Calculates how tall and how wide a given string will be when rendered, taking line breaks and word wrapping into account. This function assumes text goes from right to left, and lines grow downwards.

Arguments

  • font - The font to use when calculating the geometrics of the string
  • string - The string to calculate geometrics for
  • linelen - How long a line can be in pixels
  • string_w - This gets set to the width of the text block (longest line width.) Initial value is ignored.

Return value

Returns the height of the text block in pixels.

d_font_string_geometrics_o

unsigned int d_font_string_geometrics_o(DARNIT_FONT *font, const char *string, int linelen, int *string_w);

Calculates how tall and how wide a given string will be when rendered, taking line breaks and word wrapping into account. Ths function assumes text goes from right to left, and lines grows downwards. The initial value of string_w is used as an offset, of how much the first line should be indentated.

Arguments

  • font - The font to use when calculating the geometrics of the string
  • string - The string to calculate geometrics for
  • linelen - How long a line can be in pixels
  • string_w - This gets set to the width of the text block (longest line width.) Initial value is used for first line indentation amount

Return value

Returns the height of the text block in pixels.

d_font_glyph_h

unsigned int d_font_glyph_h(DARNIT_FONT *font);

Returns the height of the text this font generates excluding line spacing.

Arguments

  • font - The font to use

Return value

Returns the maximum height of a character rendered using this font. Excluding line spacing.

d_font_glyph_hs

unsigned int d_font_glyph_hs(DARNIT_FONT *font);

Returns the height of the text this font generates including line spacing.

Arguments

  • font - The font to use

Return value

Returns the the maximum height of a character rendered using this font. Includes line spacing.

d_text_surface_new

DARNIT_TEXT_SURFACE *d_text_surface_new(DARNIT_FONT *font, unsigned int glyphs, unsigned int linelen, int x, int y);

Creates a new text surface using font font. It is cleared and uses left-to-right orientation with new lines growing downwards as default. It does not support colored text, but it can be tinted with d_render_tint.

Arguments

  • font - The font to use with this surface
  • glyphs - The maximum number of glyphs that can be displayed. Line breaks and spaces does not count
  • linelen - How many pixels wide (or tall if characters append downwards) a line can be
  • x - At what x-coordinate to render the text at. Can be offset with d_render_offset
  • y - At what y-coordinate to render the text at. Can be offset with d_render_offset

Return value

Returns NULL on failure. Everything is a valid DARNIT_TEXT_SURFACE.

d_text_surface_color_new

DARNIT_TEXT_SURFACE *d_text_surface_new(DARNIT_FONT *font, unsigned int glyphs, unsigned int linelen, int x, int y);

Creates a new text surface using font font. It is cleared and uses left-to-right orientation with new lines growing downwards as default. It does support colored text (white being default,) but it can also be tinted with d_render_tint.

Arguments

  • font - The font to use with this surface
  • glyphs - The maximum number of glyphs that can be displayed. Line breaks and spaces does not count
  • linelen - How many pixels wide (or tall if characters append downwards) a line can be
  • x - At what x-coordinate to render the text at. Can be offset with d_render_offset
  • y - At what y-coordinate to render the text at. Can be offset with d_render_offset

Return value

Returns NULL on failure. Everything is a valid DARNIT_TEXT_SURFACE.

d_text_surface_free

DARNIT_TEXT_SURFACE *d_text_surface_free(DARNIT_TEXT_SURFACE *surface);

Frees all the resources used by a text surface.

Arguments

  • surface - The text surface to free the resources of

Return value

Returns NULL for compact pointer clearing.

d_text_surface_reset

void d_text_surface_reset(DARNIT_TEXT_SURFACE *surface);

Resets a text surface to its initial state. This clears all text written to it, resets the character pointer to the start and resets the character color to white.

Arguments

  • surface - The text surface to reset

Return value None.

d_text_surface_orientation

void d_text_surface_orientation(DARNIT_TEXT_SURFACE *surface, DARNIT_FONT_ORIENTATION prim, DARNIT_FONT_ORIENTATION sec);

Sets the orientation of a text surface (in what direction characters and lines are added.)

Arguments

  • surface - The text surface to set orientation for
  • prim - The direction characters are added in
  • sec - The direction lines are added in

Return value None.

d_text_surface_char_append

int d_text_surface_char_append(DARNIT_TEXT_SURFACE *surface, const char *c);

Appends a character to the text surface.

Arguments

  • surface - The text surface to append a character to
  • c - The character to append

Return value

  • Returns the number of bytes long the first character in the string c was

d_text_surface_string_append

void d_text_surface_string_append(DARNIT_TEXT_SURFACE *surface, const char *string);

Appends a string to the surface surface.

Arguments

  • surface - The surface to append a string to
  • string - The string to append to the surface. The string must be NULL-terminated

Return value None.

d_text_surface_color_next

void d_text_surface_color_next(DARNIT_TEXT_SURFACE *surface, unsigned char r, unsigned char g, unsigned char b);

Sets the color of the next character that is appended. This function does nothing if the text surface doesn't support colors.

Arguments

  • surface - The surface to set the next character color for
  • r - The red color channel for the color to use (range is 0..255)
  • g - The green color channel for the color to use (range is 0..255)
  • b - The blue color channel for the color to use (range is 0..255)

Return value None.

d_text_surface_draw

void d_text_surface_draw(DARNIT_TEXT_SURFACE *surface);

Draws the text surface surface.

Arguments

  • surface - The surface to draw

Return value None.

d_text_surface_offset_next_add

void d_text_surface_offset_next_add(DARNIT_TEXT_SURFACE *surface, int pixels);

Moves the cursor for next character an additional pixels.

Arguments

  • surface - The text surface to move the next character cursor for
  • pixels - The amount of pixels to move it

Return value None.

d_text_surface_offset_next_set

void d_text_surface_offset_next_set(DARNIT_TEXT_SURFACE *surface, int x_pos);

Sets the cursor for the next character to x_pos pixels into the line.

Arguments

  • surface - The text surface to move the next character cursor in
  • x_pos - An absolute X-coordinate on the text line to put the next character on

Return value None.

d_text_surface_offset_y

void d_text_surface_offset_y(DARNIT_TEXT_SURFACE *surface, int y_off);

Offsets any characters added on the Y-axis with y_off pixels. Default is zero, and is set to zero by d_text_surface_reset.

Arguments

  • surface - The text surface to offset next character in
  • x_pos - A relative Y-coordinate to offset the next characters with.

Return value None.

d_text_surface_pos

unsigned int d_text_surface_pos(DARNIT_TEXT_SURFACE *text)

Returns an X-coordinate relative to where the line starts, where the next character will be placed.

Arguments

  • text - The text surface to get the next character coordinate from

Return value

Coordinate for the next character. This value is always positive regardless of the text surface orientation.

Clone this wiki locally