Dawn/src/display/gui/font.h

70 lines
1.9 KiB
C

/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "../texture.h"
#include "../primitive.h"
#include "../primitives/quad.h"
#include "../../util/mem.h"
/**
* Initializes Font from raw TTF data.
* @param font Font to initialize
* @param data Data to intialize for.
*/
void fontInit(font_t *font, char *data);
/**
* Clean up a previously loaded font
* @param font Loaded font.
*/
void fontDispose(font_t *Font);
/**
* Buffers the vertices of a font text onto a primitive. Requires some info
* about how the font is meant to render from the text info section.
*
* @param font Font to render.
* @param primitive Primitive to render into.
* @param info The precalculated text info.
*/
void fontTextBuffer(font_t *font, primitive_t *primitive, fonttextinfo_t *info);
/**
* Initializes an uninitialized primitive for rendering.
*
* @param font Font to render.
* @param primitive Primitive to render into.
* @param info Text Info to use while rendering.
*/
void fontTextInit(font_t *font, primitive_t *primitive, fonttextinfo_t *info);
/**
* Clamps text to a max width, inserting newlines where possible.
*
* @param font Font to use
* @param info Font text info to clamp into.
* @param text Text to clamp.
* @param maxWidth Max width (in pixels) to clamp the text to.
*/
void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
float maxWidth
);
/**
* Returns the number of real characters on the lines specified. Useful when
* attempting to clamp to a set of lines.
*
* @param info Info to get the character counts from.
* @param start Starting line index.
* @param count Count of lines, this method will clamp to info's line length.
* @returns The count of characters in those lines summed.
*/
int32_t fontGetLineCharCount(fonttextinfo_t *info, int32_t start,int32_t count);