Font: compute baseline_offset
This commit is contained in:
parent
de5b4e7413
commit
5c52ed0c4d
21
src/Font.cc
21
src/Font.cc
@ -95,10 +95,13 @@ static VALUE Font_new(VALUE klass, VALUE fname, VALUE size)
|
|||||||
FT_Set_Pixel_Sizes(font->face, 0, NUM2INT(size));
|
FT_Set_Pixel_Sizes(font->face, 0, NUM2INT(size));
|
||||||
|
|
||||||
static const char preload_glyphs[] = "HMgjqxy_|^";
|
static const char preload_glyphs[] = "HMgjqxy_|^";
|
||||||
|
int max_top = -9999;
|
||||||
|
int min_bottom = 9999;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < sizeof(preload_glyphs) - 1u; i++)
|
for (unsigned int i = 0; i < sizeof(preload_glyphs) - 1u; i++)
|
||||||
{
|
{
|
||||||
if (get_glyph(font, preload_glyphs[i]) == NULL)
|
GlyphRef g = get_glyph(font, preload_glyphs[i]);
|
||||||
|
if (g == NULL)
|
||||||
{
|
{
|
||||||
delete font;
|
delete font;
|
||||||
rb_raise(rb_eRuntimeError,
|
rb_raise(rb_eRuntimeError,
|
||||||
@ -106,18 +109,20 @@ static VALUE Font_new(VALUE klass, VALUE fname, VALUE size)
|
|||||||
preload_glyphs[i],
|
preload_glyphs[i],
|
||||||
fname_cstr);
|
fname_cstr);
|
||||||
}
|
}
|
||||||
|
if (font->face->glyph->bitmap_top > max_top)
|
||||||
|
max_top = font->face->glyph->bitmap_top;
|
||||||
|
int bitmap_bottom = font->face->glyph->bitmap_top - font->face->glyph->bitmap.rows;
|
||||||
|
if (bitmap_bottom < min_bottom)
|
||||||
|
min_bottom = bitmap_bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
int line_height = round_up_26_6(font->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);
|
int baseline_offset = (line_height - (max_top - min_bottom)) / 2;
|
||||||
#endif
|
|
||||||
#if 0
|
|
||||||
m_baseline_offset = 1 - m_face->glyph->bitmap_top + m_face->glyph->bitmap.rows;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
VALUE rv = Data_Wrap_Struct(klass, NULL, Font_free, font);
|
VALUE rv = Data_Wrap_Struct(klass, NULL, Font_free, font);
|
||||||
rb_iv_set(rv, "@advance", INT2FIX(get_glyph(font, 'x')->get_advance()));
|
rb_iv_set(rv, "@advance", INT2FIX(get_glyph(font, 'x')->get_advance()));
|
||||||
rb_iv_set(rv, "@line_height", INT2FIX(round_up_26_6(font->face->size->metrics.height)));
|
rb_iv_set(rv, "@line_height", INT2FIX(line_height));
|
||||||
|
rb_iv_set(rv, "@baseline_offset", INT2FIX(baseline_offset));
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user