2023-06-20 04:33:09 +00:00
|
|
|
#ifndef STAR_FONT_HPP
|
|
|
|
#define STAR_FONT_HPP
|
|
|
|
|
|
|
|
#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:
|
|
|
|
static FontPtr loadTrueTypeFont(String const& fileName, unsigned pixelSize = 12);
|
|
|
|
static FontPtr loadTrueTypeFont(ByteArrayConstPtr const& bytes, unsigned pixelSize = 12);
|
|
|
|
|
|
|
|
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);
|
2023-08-04 13:47:52 +00:00
|
|
|
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).
|
2023-07-03 09:46:56 +00:00
|
|
|
std::pair<Image, Vec2I> render(String::Char c);
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
FontImplPtr m_fontImpl;
|
|
|
|
ByteArrayConstPtr m_fontBuffer;
|
|
|
|
unsigned m_pixelSize;
|
2023-08-04 13:47:52 +00:00
|
|
|
uint8_t m_alphaThreshold;
|
2023-07-03 04:21:51 +00:00
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
HashMap<pair<String::Char, unsigned>, unsigned> m_widthCache;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|