diff --git a/src/gfx_layout_fallback.cpp b/src/gfx_layout_fallback.cpp --- a/src/gfx_layout_fallback.cpp +++ b/src/gfx_layout_fallback.cpp @@ -40,7 +40,7 @@ public: /** Visual run contains data about the bit of text with the same font. */ class FallbackVisualRun : public ParagraphLayouter::VisualRun { std::vector glyphs; ///< The glyphs we're drawing. - std::vector positions; ///< The positions of the glyphs. + std::vector positions; ///< The positions of the glyphs. std::vector glyph_to_char; ///< The char index of the glyphs. Font *font; ///< The font used to layout these. @@ -50,7 +50,7 @@ public: const Font *GetFont() const override { return this->font; } int GetGlyphCount() const override { return static_cast(this->glyphs.size()); } const std::vector &GetGlyphs() const override { return this->glyphs; } - const std::vector &GetPositions() const override { return this->positions; } + const std::vector &GetPositions() const override { return this->positions; } int GetLeading() const override { return this->GetFont()->fc->GetHeight(); } const std::vector &GetGlyphToCharMap() const override { return this->glyph_to_char; } }; @@ -118,21 +118,23 @@ FallbackParagraphLayout::FallbackVisualR this->glyph_to_char.reserve(char_count); /* Positions contains the location of the begin of each of the glyphs, and the end of the last one. */ - this->positions.resize(char_count * 2 + 2); - this->positions[0] = x; + this->positions.reserve(char_count + 1); + int advance = x; for (int i = 0; i < char_count; i++) { const GlyphID &glyph_id = this->glyphs.emplace_back(font->fc->MapCharToGlyph(chars[i])); if (isbuiltin) { - this->positions[2 * i + 1] = font->fc->GetAscender(); // Apply sprite font's ascender. + this->positions.emplace_back(advance, font->fc->GetAscender()); // Apply sprite font's ascender. } else if (chars[i] >= SCC_SPRITE_START && chars[i] <= SCC_SPRITE_END) { - this->positions[2 * i + 1] = (font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(font->fc->GetSize()))) / 2; // Align sprite font to centre + this->positions.emplace_back(advance, (font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(font->fc->GetSize()))) / 2); // Align sprite font to centre } else { - this->positions[2 * i + 1] = 0; // No ascender adjustment. + this->positions.emplace_back(advance, 0); // No ascender adjustment. } - this->positions[2 * i + 2] = this->positions[2 * i] + font->fc->GetGlyphWidth(glyph_id); + advance += font->fc->GetGlyphWidth(glyph_id); this->glyph_to_char.push_back(char_offset + i); } + /* End-of-run position. */ + this->positions.emplace_back(advance, 0); } /** @@ -163,7 +165,7 @@ int FallbackParagraphLayout::FallbackLin * the last run gives us the end of the line and thus the width. */ const auto &run = this->GetVisualRun(this->CountRuns() - 1); - return (int)run.GetPositions()[run.GetGlyphCount() * 2]; + return run.GetPositions().back().x; } /**