Dawn/archive/FontMeasure.hpp

95 lines
2.5 KiB
C++

// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "assert/assert.hpp"
namespace Dawn {
struct FontLineMeasure {
/** What (real character) index the line starts at */
int32_t start;
/** How many (real) characters the line is in length */
int32_t length;
};
struct FontMeasure {
public:
/** How many raw chars are in the string */
int32_t length;
/** How many real characters (non whitespace) are in the string */
int32_t realLength;
/** The real character info for each line */
std::vector<struct FontLineMeasure> lines;
/** Dimensions of the string */
float_t width, height;
/** Height of a single line */
float_t lineHeight;
/**
* Internal method that adds a line to the text buffer process.
*
* @param start Start character index for the next line.
* @param len Length of the next line.
*/
void addLine(int32_t start, int32_t length);
/**
* Returns the width of this measured string.
*
* @return Width of the pre measured string.
*/
float_t getWidth();
/**
* Returns the height of the measured string.
*
* @return Height of the pre measured string.
*/
float_t getHeight();
/**
* Returns the count of quads on the given line.
*
* @param line Which line to get the count of quads for.
* @return Count of quads on that line.
*/
int32_t getQuadsOnLine(size_t line);
/**
* Returns the index, of which quad is the first quad on the given line.
*
* @param line Line to get the quad index of.
* @return The quad index of that line.
*/
int32_t getQuadIndexOnLine(size_t line);
/**
* Returns the height of the count of lines provided.
*
* @param lineCount Count of lines to get the height of.
* @return Height of the given count of lines.
*/
float_t getHeightOfLineCount(size_t lineCount);
/**
* Returns the count of lines in this string.
*
* @return Count of lines.
*/
size_t getLineCount();
/**
* Returns the count of quads in this string.
*
* @return Total count of quads.
*/
int32_t getQuadCount();
};
}