Frostbite2D/Fostbite2D/include/fostbite2D/render/font.h

88 lines
2.0 KiB
C
Raw Normal View History

2026-02-17 13:28:38 +08:00
#pragma once
#include <fostbite2D/core/color.h>
#include <fostbite2D/core/types.h>
#include <fostbite2D/core/math_types.h>
#include <string>
namespace frostbite2D {
// ============================================================================
// 字形信息
// ============================================================================
struct Glyph {
float u0, v0; // 纹理坐标左下角
float u1, v1; // 纹理坐标右上角
float width; // 字形宽度(像素)
float height; // 字形高度(像素)
float bearingX; // 水平偏移
float bearingY; // 垂直偏移
float advance; // 前进距离
};
// ============================================================================
// 字体图集接口
// ============================================================================
class FontAtlas {
public:
virtual ~FontAtlas() = default;
/**
* @brief
* @param codepoint Unicode码点
* @return
*/
virtual const Glyph *getGlyph(char32_t codepoint) const = 0;
/**
* @brief
* @return
*/
virtual class Texture *getTexture() const = 0;
/**
* @brief
* @return
*/
virtual int getFontSize() const = 0;
/**
* @brief
* @return
*/
virtual float getAscent() const = 0;
/**
* @brief
* @return
*/
virtual float getDescent() const = 0;
/**
* @brief
* @return
*/
virtual float getLineGap() const = 0;
/**
* @brief
* @return
*/
virtual float getLineHeight() const = 0;
/**
* @brief
* @param text
* @return
*/
virtual Vec2 measureText(const std::string &text) = 0;
/**
* @brief SDF
* @return SDF返回true
*/
virtual bool isSDF() const = 0;
};
} // namespace frostbite2D