From 4ccc40a15c5c250fbd5ddbefcfff5b651b102825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 20 Feb 2014 22:31:44 +0100 Subject: [PATCH] app_server: Fixed BFont::GetEscapements() Both versions effectively ignored the provided escapement_delta. Also when layouting glyphs, the space/non-space delta were applied off-by-one. It should affect the advance for the current glyph, not the offset. --- src/servers/app/ServerFont.cpp | 22 ++++++++++++------- .../app/drawing/Painter/AGGTextRenderer.cpp | 3 ++- src/servers/app/font/GlyphLayoutEngine.h | 22 +++++++++++-------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/servers/app/ServerFont.cpp b/src/servers/app/ServerFont.cpp index 5655b02d44..3e25553b9a 100644 --- a/src/servers/app/ServerFont.cpp +++ b/src/servers/app/ServerFont.cpp @@ -446,7 +446,8 @@ class HasGlyphsConsumer { fHasArray[index] = false; } bool ConsumeGlyph(int32 index, uint32 charCode, const GlyphCache* glyph, - FontCacheEntry* entry, double x, double y) + FontCacheEntry* entry, double x, double y, double advanceX, + double advanceY) { fHasArray[index] = glyph->glyph_index != 0; return true; @@ -491,7 +492,8 @@ class EdgesConsumer { fEdges[index].right = 0.0; } bool ConsumeGlyph(int32 index, uint32 charCode, const GlyphCache* glyph, - FontCacheEntry* entry, double x, double y) + FontCacheEntry* entry, double x, double y, double advanceX, + double advanceY) { fEdges[index].left = glyph->inset_left / fSize; fEdges[index].right = glyph->inset_right / fSize; @@ -560,9 +562,10 @@ public: } bool ConsumeGlyph(int32 index, uint32 charCode, const GlyphCache* glyph, - FontCacheEntry* entry, double x, double y) + FontCacheEntry* entry, double x, double y, double advanceX, + double advanceY) { - return _Set(index, glyph->advance_x, glyph->advance_y); + return _Set(index, advanceX, advanceY); } private: @@ -631,12 +634,13 @@ public: } bool ConsumeGlyph(int32 index, uint32 charCode, const GlyphCache* glyph, - FontCacheEntry* entry, double x, double y) + FontCacheEntry* entry, double x, double y, double advanceX, + double advanceY) { if (index >= fNumChars) return false; - fWidths[index] = glyph->advance_x / fSize; + fWidths[index] = advanceX / fSize; return true; } @@ -685,7 +689,8 @@ class BoundingBoxConsumer { void Finish(double x, double y) {} void ConsumeEmptyGlyph(int32 index, uint32 charCode, double x, double y) {} bool ConsumeGlyph(int32 index, uint32 charCode, const GlyphCache* glyph, - FontCacheEntry* entry, double x, double y) + FontCacheEntry* entry, double x, double y, double advanceX, + double advanceY) { if (glyph->data_type != glyph_data_outline) { const agg::rect_i& r = glyph->bounds; @@ -812,7 +817,8 @@ class StringWidthConsumer { void Finish(double x, double y) { width = x; } void ConsumeEmptyGlyph(int32 index, uint32 charCode, double x, double y) {} bool ConsumeGlyph(int32 index, uint32 charCode, const GlyphCache* glyph, - FontCacheEntry* entry, double x, double y) + FontCacheEntry* entry, double x, double y, double advanceX, + double advanceY) { return true; } float width; diff --git a/src/servers/app/drawing/Painter/AGGTextRenderer.cpp b/src/servers/app/drawing/Painter/AGGTextRenderer.cpp index 64876d571e..ad4598a8f8 100644 --- a/src/servers/app/drawing/Painter/AGGTextRenderer.cpp +++ b/src/servers/app/drawing/Painter/AGGTextRenderer.cpp @@ -184,7 +184,8 @@ public: } bool ConsumeGlyph(int32 index, uint32 charCode, const GlyphCache* glyph, - FontCacheEntry* entry, double x, double y) + FontCacheEntry* entry, double x, double y, double advanceX, + double advanceY) { // "glyphBounds" is the bounds of the glyph transformed // by the x y location of the glyph along the base line, diff --git a/src/servers/app/font/GlyphLayoutEngine.h b/src/servers/app/font/GlyphLayoutEngine.h index d03619c49e..481cfb121c 100644 --- a/src/servers/app/font/GlyphLayoutEngine.h +++ b/src/servers/app/font/GlyphLayoutEngine.h @@ -232,9 +232,6 @@ GlyphLayoutEngine::LayoutGlyphs(GlyphConsumer& consumer, x += advanceX; y += advanceY; - - if (delta != NULL && index > 0) - x += IsWhiteSpace(charCode) ? delta->space : delta->nonspace; } const GlyphCache* glyph = entry->CachedGlyph(charCode); @@ -258,15 +255,22 @@ GlyphLayoutEngine::LayoutGlyphs(GlyphConsumer& consumer, advanceX = 0; advanceY = 0; } else { - if (!consumer.ConsumeGlyph(index++, charCode, glyph, entry, x, y)) { - advanceX = 0; - advanceY = 0; - break; - } - // get next increment for pen position advanceX = glyph->advance_x; advanceY = glyph->advance_y; + + // adjust for custom spacing + if (delta != NULL) { + advanceX += IsWhiteSpace(charCode) + ? delta->space : delta->nonspace; + } + + if (!consumer.ConsumeGlyph(index++, charCode, glyph, entry, x, y, + advanceX, advanceY)) { + advanceX = 0.0; + advanceY = 0.0; + break; + } } // lastCharCode = charCode;