/**
 * 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);

/**
 * Convert a Font's Size into a Font Scale. The scale is based on the font's 
 * default size for the given texture size (Refer to FONT_SIZE_DEFAULT).
 * 
 * @param fontSize Font size to convert.
 * @return The times scale that the font size is to the textured default.
 */
float fontGetScale(float fontSize);

/**
 * 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 (pixels) to clamp the text to, -1 for no max width.
 * @param fontSize Font Size of the text.
 */
void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
  float maxWidth, float fontSize
);

/**
 * 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);