@@ -576,12 +576,14 @@ static int DrawLayoutLine(const Paragrap
const uint shadow_offset = ScaleGUITrad(1);
TextColour colour = TC_BLACK;
bool draw_shadow = false;
for (int run_index = 0; run_index < line.CountRuns(); run_index++) {
const ParagraphLayouter::VisualRun &run = line.GetVisualRun(run_index);
const auto &glyphs = run.GetGlyphs();
const auto &positions = run.GetPositions();
const Font *f = run.GetFont();
FontCache *fc = f->fc;
colour = f->colour;
SetColourRemap(colour);
@@ -589,20 +591,20 @@ static int DrawLayoutLine(const Paragrap
int dpi_left = dpi->left;
int dpi_right = dpi->left + dpi->width - 1;
draw_shadow = fc->GetDrawGlyphShadow() && (colour & TC_NO_SHADE) == 0 && colour != TC_BLACK;
for (int i = 0; i < run.GetGlyphCount(); i++) {
GlyphID glyph = run.GetGlyphs()[i];
GlyphID glyph = glyphs[i];
/* Not a valid glyph (empty) */
if (glyph == 0xFFFF) 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 = (int)positions[i * 2] + left - offset_x;
int end_x = (int)positions[i * 2 + 2] + left - offset_x - 1;
int top = (int)positions[i * 2 + 1] + y;
/* Truncated away. */
if (truncation && (begin_x < min_x || end_x > max_x)) continue;
const Sprite *sprite = fc->GetGlyph(glyph);
/* Check clipping (the "+ 1" is for the shadow). */
@@ -251,17 +251,19 @@ Point Layouter::GetCharPosition(std::str
/* Valid character. */
/* Scan all runs until we've found our code point index. */
for (int run_index = 0; run_index < line->CountRuns(); run_index++) {
const ParagraphLayouter::VisualRun &run = line->GetVisualRun(run_index);
const auto &charmap = run.GetGlyphToCharMap();
/* Matching glyph? Return position. */
if ((size_t)run.GetGlyphToCharMap()[i] == index) {
Point p = { (int)run.GetPositions()[i * 2], (int)run.GetPositions()[i * 2 + 1] };
if ((size_t)charmap[i] == index) {
Point p = { (int)positions[i * 2], (int)positions[i * 2 + 1] };
return p;
}
NOT_REACHED();
@@ -278,23 +280,26 @@ ptrdiff_t Layouter::GetCharAtPosition(in
if (line_index >= this->size()) return -1;
const auto &line = this->at(line_index);
/* Not a valid glyph (empty). */
if (run.GetGlyphs()[i] == 0xFFFF) continue;
if (glyphs[i] == 0xFFFF) continue;
int begin_x = (int)run.GetPositions()[i * 2];
int end_x = (int)run.GetPositions()[i * 2 + 2];
int begin_x = (int)positions[i * 2];
int end_x = (int)positions[i * 2 + 2];
if (IsInsideMM(x, begin_x, end_x)) {
/* Found our glyph, now convert to UTF-8 string index. */
size_t index = run.GetGlyphToCharMap()[i];
size_t index = charmap[i];
size_t cur_idx = 0;
for (auto str = this->string.begin(); str != this->string.end();) {
if (cur_idx == index) return str - this->string.begin();
char32_t c = Utf8Consume(str);
Status change: