Attached Files |
debug [^] (3,833 bytes) 2012-07-25 17:23
broken.patch [^] (6,535 bytes) 2012-07-25 19:27 [Show Content] [Hide Content]diff --git a/crawl-ref/source/fontwrapper-ft.cc b/crawl-ref/source/fontwrapper-ft.cc
index 5ff5c19..2966c1f 100644
--- a/crawl-ref/source/fontwrapper-ft.cc
+++ b/crawl-ref/source/fontwrapper-ft.cc
@@ -41,7 +41,6 @@ FTFontWrapper::FTFontWrapper() :
m_glyphs_lru(0),
m_glyphs_mru(0),
m_glyphs_top(0), // reinitialised to 1 in load_font
- m_max_advance(0, 0),
m_min_offset(0),
charsz(1,1)
{
@@ -98,14 +97,13 @@ bool FTFontWrapper::load_font(const char *font_name, unsigned int font_size,
// Get maximum advance and other global metrics
FT_Size_Metrics metrics = face->size->metrics;
- m_max_advance = coord_def(0,0);
- m_max_advance.x = metrics.max_advance >> 6;
- m_max_advance.y = (metrics.ascender-metrics.descender)>>6;
- ascender = (metrics.ascender>>6);
- int max_width = (face->bbox.xMax >> 6) - (face->bbox.xMin >> 6);
- int max_height = m_max_advance.y;
- m_min_offset = 0;
- m_glyphs = new GlyphInfo[MAX_GLYPHS];
+ int max_width = (face->bbox.xMax - face->bbox.xMin) >> 6;
+ int max_height = (face->bbox.yMax - face->bbox.yMin) >> 6;
+ max_advance = metrics.max_advance >> 6;
+ line_height = metrics.height >> 6;
+ bbox_ymax = face->bbox.yMax >> 6;
+ m_min_offset = 0;
+ m_glyphs = new GlyphInfo[MAX_GLYPHS];
if (outl)
max_width += 2, max_height += 2;
@@ -150,8 +148,8 @@ bool FTFontWrapper::load_font(const char *font_name, unsigned int font_size,
m_glyphs[0].uchar = MISSING_CHAR;
m_glyphs[0].prev = 0;
m_glyphs[0].next = 0;
- for (int x = 0; x < max_width; x++)
- for (int y = 0; y < max_height; y++)
+ for (int x = 0; x < charsz.x; x++)
+ for (int y = 0; y < charsz.y; y++)
{
unsigned int idx = x + y * charsz.x;
idx *= 4;
@@ -194,8 +192,8 @@ void FTFontWrapper::load_glyph(unsigned int c, ucs_t uchar)
int advance = face->glyph->advance.x >> 6;
int bmp_width = bmp->width;
- int bmp_top = ascender - face->glyph->bitmap_top;
- int bmp_bottom = ascender + bmp->rows - face->glyph->bitmap_top;
+ int bmp_top = bbox_ymax - face->glyph->bitmap_top;
+ int bmp_bottom = bbox_ymax + bmp->rows - face->glyph->bitmap_top;
if (outl)
{
bmp_width += 2;
@@ -214,7 +212,7 @@ void FTFontWrapper::load_glyph(unsigned int c, ucs_t uchar)
{
m_glyphs[c].renderable = true;
- int vert_offset = ascender - face->glyph->bitmap_top;
+ int vert_offset = bbox_ymax - face->glyph->bitmap_top;
ASSERT(bmp->pixel_mode == FT_PIXEL_MODE_GRAY);
ASSERT(bmp->num_grays == 256);
@@ -374,7 +372,7 @@ void FTFontWrapper::render_textblock(unsigned int x_pos, unsigned int y_pos,
m_buf->clear();
n_subst = 0;
- float texcoord_dy = (float)m_max_advance.y / (float)m_tex.height();
+ float texcoord_dy = (float)charsz.y / (float)m_tex.height();
for (unsigned int y = 0; y < height; y++)
{
@@ -387,7 +385,7 @@ void FTFontWrapper::render_textblock(unsigned int x_pos, unsigned int y_pos,
if (col_bg != 0)
{
GLWPrim rect(adv.x, adv.y,
- adv.x + m_max_advance.x, adv.y + m_max_advance.y);
+ adv.x + max_advance, adv.y + line_height);
// Leave tex coords at their default 0.0f
VColour col(term_colours[col_bg].r,
term_colours[col_bg].g,
@@ -408,7 +406,7 @@ void FTFontWrapper::render_textblock(unsigned int x_pos, unsigned int y_pos,
float tex_y2 = tex_y + texcoord_dy;
GLWPrim rect(adv.x, adv.y, adv.x + this_width,
- adv.y + m_max_advance.y);
+ adv.y + charsz.y);
VColour col(term_colours[col_fg].r,
term_colours[col_fg].g,
term_colours[col_fg].b);
@@ -431,7 +429,7 @@ void FTFontWrapper::render_textblock(unsigned int x_pos, unsigned int y_pos,
}
adv.x = 0;
- adv.y += m_max_advance.y;
+ adv.y += line_height;
}
draw_m_buf(x_pos, y_pos, drop_shadow);
@@ -746,7 +744,7 @@ void FTFontWrapper::store(FontBuffer &buf, float &x, float &y,
if (c == '\n')
{
x = orig_x;
- y += m_max_advance.y;
+ y += line_height;
}
else
store(buf, x, y, c, col);
@@ -795,12 +793,12 @@ void FTFontWrapper::store(FontBuffer &buf, float &x, float &y,
float pos_sx = x + m_glyphs[c].offset;
float pos_sy = y;
float pos_ex = pos_sx + this_width;
- float pos_ey = y + m_max_advance.y;
+ float pos_ey = y + charsz.y;
float tex_sx = (float)(c % GLYPHS_PER_ROWCOL) / (float)GLYPHS_PER_ROWCOL;
float tex_sy = (float)(c / GLYPHS_PER_ROWCOL) / (float)GLYPHS_PER_ROWCOL;
float tex_ex = tex_sx + (float)this_width / (float)(GLYPHS_PER_ROWCOL*charsz.x);//(float)m_tex.width();
- float tex_ey = tex_sy + (float)m_max_advance.y / (float)(GLYPHS_PER_ROWCOL*charsz.y);//(float)m_tex.height();
+ float tex_ey = tex_sy + (float)charsz.y / (float)(GLYPHS_PER_ROWCOL*charsz.y);//(float)m_tex.height();
GLWPrim rect(pos_sx, pos_sy, pos_ex, pos_ey);
rect.set_tex(tex_sx, tex_sy, tex_ex, tex_ey);
@@ -812,12 +810,12 @@ void FTFontWrapper::store(FontBuffer &buf, float &x, float &y,
unsigned int FTFontWrapper::char_width() const
{
- return m_max_advance.x;
+ return max_advance;
}
unsigned int FTFontWrapper::char_height() const
{
- return m_max_advance.y;
+ return line_height;
}
const GenericTexture *FTFontWrapper::font_tex() const
diff --git a/crawl-ref/source/fontwrapper-ft.h b/crawl-ref/source/fontwrapper-ft.h
index 2352c02..72cc59f 100644
--- a/crawl-ref/source/fontwrapper-ft.h
+++ b/crawl-ref/source/fontwrapper-ft.h
@@ -111,14 +111,17 @@ protected:
// count of glyph loads in the current text block
int n_subst;
- // cached value of the maximum advance from m_advance
- coord_def m_max_advance;
-
// minimum offset (likely negative)
int m_min_offset;
- // size of ascender
- int ascender;
+ // maximum horizontal advance (NOT maximum glyph width!)
+ int max_advance;
+
+ // default line height
+ int line_height;
+
+ // maximum character y coord
+ int bbox_ymax;
// other font metrics
coord_def charsz;
0001-fixed-font-rendering-for-non-default-fonts.patch [^] (7,370 bytes) 2012-07-28 01:59 [Show Content] [Hide Content]From e0ba98f9c56185d8bc650df4df9d49b4bb428e4b Mon Sep 17 00:00:00 2001
From: frogbotherer <therealchriswest@hotmail.com>
Date: Sat, 28 Jul 2012 00:56:31 +0100
Subject: [PATCH] fixed font rendering for non-default fonts
---
crawl-ref/source/fontwrapper-ft.cc | 55 ++++++++++++++++--------------------
crawl-ref/source/fontwrapper-ft.h | 9 ++++--
2 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/crawl-ref/source/fontwrapper-ft.cc b/crawl-ref/source/fontwrapper-ft.cc
index 620dbdc..fdd40c6 100644
--- a/crawl-ref/source/fontwrapper-ft.cc
+++ b/crawl-ref/source/fontwrapper-ft.cc
@@ -41,7 +41,9 @@ FTFontWrapper::FTFontWrapper() :
m_glyphs_top(0), // reinitialised to 1 in load_font
m_max_advance(0, 0),
m_min_offset(0),
- charsz(1,1)
+ charsz(1,1),
+ m_max_width(0),
+ m_max_height(0)
{
m_buf = GLShapeBuffer::create(true, true);
}
@@ -101,19 +103,19 @@ bool FTFontWrapper::load_font(const char *font_name, unsigned int font_size,
m_max_advance = coord_def(0,0);
m_max_advance.x = metrics.max_advance >> 6;
m_max_advance.y = (metrics.ascender-metrics.descender)>>6;
- ascender = (metrics.ascender>>6);
- int max_width = (face->bbox.xMax >> 6) - (face->bbox.xMin >> 6);
- int max_height = m_max_advance.y;
+ m_ascender = (metrics.ascender>>6);
+ m_max_width = (face->bbox.xMax >> 6) - (face->bbox.xMin >> 6);
+ m_max_height = (face->bbox.yMax>>6)-(face->bbox.yMin>>6);//m_max_advance.y;
m_min_offset = 0;
m_glyphs = new GlyphInfo[MAX_GLYPHS];
if (outl)
- max_width += 2, max_height += 2;
+ m_max_width += 2, m_max_height += 2;
// Grow character size to power of 2
- while (charsz.x < max_width)
+ while (charsz.x < m_max_width)
charsz.x *= 2;
- while (charsz.y < max_height)
+ while (charsz.y < m_max_height)
charsz.y *= 2;
// Fill out texture to be (16*charsz.x) X (16*charsz.y) X (32-bit)
@@ -142,14 +144,15 @@ bool FTFontWrapper::load_font(const char *font_name, unsigned int font_size,
m_glyphs_mru = 0;
m_glyphs[0].offset = 0;
m_glyphs[0].advance = 0;
+ m_glyphs[0].ascender = 0;
m_glyphs[0].renderable = false;
m_glyphs[0].uchar = MISSING_CHAR;
m_glyphs[0].prev = 0;
m_glyphs[0].next = 0;
- for (int x = 0; x < max_width; x++)
- for (int y = 0; y < max_height; y++)
+ for (int x = 0; x < m_max_width; x++)
+ for (int y = 0; y < m_max_height; y++)
{
- unsigned int idx = x + y * charsz.x;
+ unsigned int idx = x + y * m_max_width;
idx *= 4;
pixels[idx] = 255;
pixels[idx + 1] = 255;
@@ -174,6 +177,7 @@ void FTFontWrapper::load_glyph(unsigned int c, ucs_t uchar)
FT_Error error;
m_glyphs[c].offset = 0;
m_glyphs[c].advance = 0;
+ m_glyphs[c].ascender = m_ascender;
m_glyphs[c].renderable = false;
FT_Int glyph_index = FT_Get_Char_Index(face, uchar);
@@ -191,34 +195,25 @@ void FTFontWrapper::load_glyph(unsigned int c, ucs_t uchar)
int advance = face->glyph->advance.x >> 6;
int bmp_width = bmp->width;
- int bmp_top = ascender - face->glyph->bitmap_top;
- int bmp_bottom = ascender + bmp->rows - face->glyph->bitmap_top;
if (outl)
- {
bmp_width += 2;
- bmp_top -= 1;
- bmp_bottom += 1;
- }
m_glyphs[c].offset = face->glyph->bitmap_left;
m_glyphs[c].advance = advance;
+ m_glyphs[c].ascender = face->glyph->bitmap_top;
m_glyphs[c].width = bmp_width;
// Some glyphs (e.g. ' ') don't get a buffer.
- if (!bmp->buffer)
- m_glyphs[c].renderable = false;
- else
+ if (bmp->buffer)
{
m_glyphs[c].renderable = true;
- int vert_offset = ascender - face->glyph->bitmap_top;
-
ASSERT(bmp->pixel_mode == FT_PIXEL_MODE_GRAY);
ASSERT(bmp->num_grays == 256);
// Horizontal offset stored in m_glyphs and handled when drawing
const unsigned int offset_x = 0;
- const unsigned int offset_y = vert_offset;
+ const unsigned int offset_y = 0;
memset(pixels, 0, sizeof(unsigned char) * 4 * charsz.x * charsz.y);
if (outl)
{
@@ -354,8 +349,7 @@ void FTFontWrapper::render_textblock(unsigned int x_pos, unsigned int y_pos,
m_buf->clear();
n_subst = 0;
- float texcoord_dy = (float)m_max_advance.y / (float)m_tex.height();
-
+ float texcoord_dy = (float)m_max_height / (float)m_tex.height();
for (unsigned int y = 0; y < height; y++)
{
for (unsigned int x = 0; x < width; x++)
@@ -387,8 +381,9 @@ void FTFontWrapper::render_textblock(unsigned int x_pos, unsigned int y_pos,
float tex_x2 = tex_x + (float)this_width / (float)m_tex.width();
float tex_y2 = tex_y + texcoord_dy;
- GLWPrim rect(adv.x, adv.y, adv.x + this_width,
- adv.y + m_max_advance.y);
+ GLWPrim rect(adv.x, adv.y - m_glyphs[c].ascender + m_ascender,
+ adv.x + this_width, adv.y + m_max_height - m_glyphs[c].ascender + m_ascender);
+
VColour col(term_colours[col_fg].r,
term_colours[col_fg].g,
term_colours[col_fg].b);
@@ -761,14 +756,14 @@ void FTFontWrapper::store(FontBuffer &buf, float &x, float &y,
int this_width = m_glyphs[c].width;
float pos_sx = x + m_glyphs[c].offset;
- float pos_sy = y;
+ float pos_sy = y - m_glyphs[c].ascender + m_ascender;
float pos_ex = pos_sx + this_width;
- float pos_ey = y + m_max_advance.y;
+ float pos_ey = y + m_max_height - m_glyphs[c].ascender + m_ascender;
float tex_sx = (float)(c % GLYPHS_PER_ROWCOL) / (float)GLYPHS_PER_ROWCOL;
float tex_sy = (float)(c / GLYPHS_PER_ROWCOL) / (float)GLYPHS_PER_ROWCOL;
- float tex_ex = tex_sx + (float)this_width / (float)(GLYPHS_PER_ROWCOL*charsz.x);//(float)m_tex.width();
- float tex_ey = tex_sy + (float)m_max_advance.y / (float)(GLYPHS_PER_ROWCOL*charsz.y);//(float)m_tex.height();
+ float tex_ex = tex_sx + (float)this_width / (float)(GLYPHS_PER_ROWCOL*charsz.x);
+ float tex_ey = tex_sy + (float)m_max_height / (float)(GLYPHS_PER_ROWCOL*charsz.y);
GLWPrim rect(pos_sx, pos_sy, pos_ex, pos_ey);
rect.set_tex(tex_sx, tex_sy, tex_ex, tex_ey);
diff --git a/crawl-ref/source/fontwrapper-ft.h b/crawl-ref/source/fontwrapper-ft.h
index 10f4c3a..f04dd5f 100644
--- a/crawl-ref/source/fontwrapper-ft.h
+++ b/crawl-ref/source/fontwrapper-ft.h
@@ -96,6 +96,9 @@ protected:
int8_t advance;
// per-glyph width
int8_t width;
+ // per-glyph ascender
+ int8_t ascender;
+
// does glyph have any pixels?
bool renderable;
@@ -122,13 +125,15 @@ protected:
// minimum offset (likely negative)
int m_min_offset;
- // size of ascender
- int ascender;
+ // size of ascender according to font
+ int m_ascender;
// other font metrics
coord_def charsz;
unsigned int m_ft_width;
unsigned int m_ft_height;
+ int m_max_width;
+ int m_max_height;
GenericTexture m_tex;
GLShapeBuffer *m_buf;
--
1.7.9.5
|