From 0d2150483270880b467a766aa447e60bd5c04810 Mon Sep 17 00:00:00 2001 From: cirdan Date: Fri, 3 Mar 2017 18:07:53 +0100 Subject: [PATCH] Add GlyphPos for a visual run glyph and its position Add a new struct ParagraphLayouter::GlyphPos to hold a glyph id and its position in a visual run and a method ParagraphLayouter::VisualRun::GetGlyphPos to retrieve the GlyphPos for a given glyph index in a visual run, and use them from DrawLayoutLine. --- src/gfx.cpp | 15 +++++++-------- src/gfx_layout.h | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/gfx.cpp b/src/gfx.cpp index 25db95f16..5ccace8bf 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -433,23 +433,22 @@ static int DrawLayoutLine (const ParagraphLayouter::Line *line, draw_shadow = colour != TC_BLACK && (colour & TC_NO_SHADE) == 0 && fc->GetDrawGlyphShadow(); for (int i = 0; i < run->GetGlyphCount(); i++) { - GlyphID glyph = run->GetGlyphs()[i]; - + ParagraphLayouter::GlyphPos gp; /* Not a valid glyph (empty) */ - if (glyph == 0xFFFF) continue; + if (!run->GetGlyphPos (&gp, i)) continue; - int begin_x = (int)run->GetPositions()[i * 2] + left - offset_x; - int end_x = (int)run->GetPositions()[i * 2 + 2] + left - offset_x - 1; - int top = (int)run->GetPositions()[i * 2 + 1] + y; + int begin_x = gp.x0 + left - offset_x; + int end_x = gp.x1 + left - offset_x - 1; + int top = gp.y + y; /* Truncated away. */ if (truncation && (begin_x < min_x || end_x > max_x)) continue; - const Sprite *sprite = fc->GetGlyph(glyph); + const Sprite *sprite = fc->GetGlyph (gp.glyph); /* Check clipping (the "+ 1" is for the shadow). */ if (begin_x + sprite->x_offs > dpi_right || begin_x + sprite->x_offs + sprite->width /* - 1 + 1 */ < dpi_left) continue; - if (draw_shadow && (glyph & SPRITE_GLYPH) == 0) { + if (draw_shadow && (gp.glyph & SPRITE_GLYPH) == 0) { SetColourRemap(TC_BLACK); GfxMainBlitter (dpi, sprite, begin_x + 1, top + 1, BM_COLOUR_REMAP); SetColourRemap(colour); diff --git a/src/gfx_layout.h b/src/gfx_layout.h index b5cbfe4af..7a7850785 100644 --- a/src/gfx_layout.h +++ b/src/gfx_layout.h @@ -27,6 +27,12 @@ struct FontBase { /** Namespace for paragraph layout-related types. */ namespace ParagraphLayouter { + /** A glyph and the position where it goes. */ + struct GlyphPos { + int x0, x1, y; + GlyphID glyph; + }; + /** Visual run contains data about the bit of text with the same font. */ class VisualRun { public: @@ -35,6 +41,25 @@ namespace ParagraphLayouter { virtual int GetGlyphCount() const = 0; virtual const GlyphID *GetGlyphs() const = 0; virtual const float *GetPositions() const = 0; + + /** + * Get the glyph and position for a glyph. + * @param gp Struct to receive the data. + * @param i Index of the glyph whose data to get. + * @return Whether the glyph is valid (non-empty). + */ + bool GetGlyphPos (GlyphPos *gp, int i) const + { + GlyphID glyph = this->GetGlyphs()[i]; + if (glyph == 0xFFFF) return false; + + gp->glyph = glyph; + const float *pos = this->GetPositions(); + gp->x0 = pos[i * 2]; + gp->x1 = pos[i * 2 + 2]; + gp->y = pos[i * 2 + 1]; + return true; + } }; /** A single line worth of VisualRuns. */ -- 2.11.4.GIT