osb/source/core/StarFont.hpp

50 lines
1.1 KiB
C++
Raw Normal View History

#pragma once
2023-06-20 04:33:09 +00:00
#include "StarString.hpp"
#include "StarImage.hpp"
#include "StarByteArray.hpp"
#include "StarMap.hpp"
namespace Star {
STAR_EXCEPTION(FontException, StarException);
STAR_STRUCT(FontImpl);
STAR_CLASS(Font);
class Font {
public:
2024-03-25 01:49:18 +00:00
static FontPtr loadFont(String const& fileName, unsigned pixelSize = 12);
static FontPtr loadFont(ByteArrayConstPtr const& bytes, unsigned pixelSize = 12);
2023-06-20 04:33:09 +00:00
Font();
Font(Font const&) = delete;
Font const& operator=(Font const&) = delete;
// Create a new font from the same data
FontPtr clone() const;
void setPixelSize(unsigned pixelSize);
void setAlphaThreshold(uint8_t alphaThreshold = 0);
2023-06-20 04:33:09 +00:00
unsigned height() const;
unsigned width(String::Char c);
// May return empty image on unrenderable character (Normally, this will
// render a box, but if there is an internal freetype error this may return
// an empty image).
std::pair<Image, Vec2I> render(String::Char c);
bool exists(String::Char c);
2023-06-20 04:33:09 +00:00
private:
FontImplPtr m_fontImpl;
ByteArrayConstPtr m_fontBuffer;
unsigned m_pixelSize;
uint8_t m_alphaThreshold;
2023-06-20 04:33:09 +00:00
HashMap<pair<String::Char, unsigned>, unsigned> m_widthCache;
};
}