Font: add operator[](), get_baseline_offset()
This commit is contained in:
parent
da73f62845
commit
21aa8543ac
@ -29,15 +29,17 @@ namespace jes
|
|||||||
|
|
||||||
FT_Set_Pixel_Sizes(m_face, 0, size);
|
FT_Set_Pixel_Sizes(m_face, 0, size);
|
||||||
|
|
||||||
m_line_height = round_up_26_6(m_face->size->metrics.height);
|
|
||||||
|
|
||||||
GlyphRef x_glyph = load_glyph('x');
|
GlyphRef x_glyph = load_glyph('x');
|
||||||
if (x_glyph.is_null())
|
if (x_glyph.is_null())
|
||||||
{
|
{
|
||||||
std::cerr << "Could not load 'x' glyph from font" << fname << std::endl;
|
std::cerr << "Could not load 'x' glyph from font" << fname << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
m_glyphs['x'] = x_glyph;
|
||||||
|
|
||||||
m_advance = x_glyph->get_advance();
|
m_advance = x_glyph->get_advance();
|
||||||
|
m_line_height = round_up_26_6(m_face->size->metrics.height);
|
||||||
|
m_baseline_offset = round_up_26_6((m_face->size->metrics.height - (m_face->size->metrics.ascender - m_face->size->metrics.descender)) / 2 - m_face->size->metrics.descender);
|
||||||
|
|
||||||
m_loaded = true;
|
m_loaded = true;
|
||||||
return true;
|
return true;
|
||||||
|
@ -44,12 +44,23 @@ namespace jes
|
|||||||
bool load(FT_Library ft, const char * fname, size_t size);
|
bool load(FT_Library ft, const char * fname, size_t size);
|
||||||
int get_line_height() { return m_line_height; }
|
int get_line_height() { return m_line_height; }
|
||||||
int get_advance() { return m_advance; }
|
int get_advance() { return m_advance; }
|
||||||
|
int get_baseline_offset() { return m_baseline_offset; }
|
||||||
|
GlyphRef operator[](FT_ULong char_code)
|
||||||
|
{
|
||||||
|
auto it = m_glyphs.find(char_code);
|
||||||
|
if (it != m_glyphs.end())
|
||||||
|
return it->second;
|
||||||
|
GlyphRef g = load_glyph(char_code);
|
||||||
|
m_glyphs[char_code] = g;
|
||||||
|
return g;
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
GlyphRef load_glyph(FT_ULong char_code);
|
GlyphRef load_glyph(FT_ULong char_code);
|
||||||
|
|
||||||
FT_Face m_face;
|
FT_Face m_face;
|
||||||
int m_line_height;
|
int m_line_height;
|
||||||
int m_advance;
|
int m_advance;
|
||||||
|
int m_baseline_offset;
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
std::unordered_map<FT_ULong, GlyphRef> m_glyphs;
|
std::unordered_map<FT_ULong, GlyphRef> m_glyphs;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user