40 int advanceX, advanceY;
45 return image ==
nullptr;
48 void* rendererData =
nullptr;
56 return (size << 2) | int(fr);
59 bool operator<(
const FontKey& f)
const {
60 return hash() < f.hash();
66 void* rendererData =
nullptr;
70 using FontEntry = std::pair<FontKey, FontData&>;
81 return mCharData[
FontKey{size, fr}];
84 Character renderGlyph(
const FontEntry& fs,
long glyph);
87 AFont(AFontManager* fm,
const AString& path);
89 AFont(AFontManager* fm,
const AUrl& url);
91 FontEntry getFontEntry(
const FontKey& key) {
92 return {key, mCharData[key]};
95 glm::vec2 getKerning(
wchar_t left,
wchar_t right);
97 AFont(
const AFont&) =
delete;
99 Character& getCharacter(
const FontEntry& charset,
long glyph);
101 float length(
const FontEntry& charset,
const AString& text);
103 template<
class Iterator>
104 float length(
const FontEntry& charset, Iterator begin, Iterator end) {
105 int size = charset.first.size;
108 for (Iterator i = begin; i != end; i++) {
110 advance += getSpaceWidth(size);
114 Character& ch = getCharacter(charset, *i);
116 advance += ch.advanceX;
117 advance = glm::floor(advance);
119 advance += getSpaceWidth(size);
126 trimStringToWidth(
const FontEntry& charset, AString::iterator begin, AString::iterator end,
float maxWidth) {
128 for (
auto i = begin; i != end; i++) {
130 return AString(begin, i);
132 float charWidth = length(charset, i, std::next(i));
133 if (width + charWidth > maxWidth) {
134 return AString(begin, i);
138 return AString(begin, end);
145 AString getFontFamilyName()
const;
148 AFontFamily::Weight getFontWeight()
const;
150 int getAscenderHeight(
unsigned size)
const;
152 int getDescenderHeight(
unsigned size)
const;
154 int getSpaceWidth(
unsigned size) {
155 return size * 10 / 23;
159 bool isItalic()
const;