1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 09:22:42 +01:00

Change: Make truncation ellipsis translatable. (#14417)

This commit is contained in:
Peter Nelson
2025-07-09 22:55:43 +01:00
committed by GitHub
parent 259830777c
commit f6e78a480d
4 changed files with 36 additions and 26 deletions

View File

@@ -523,10 +523,9 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
int max_x = right; // The maximum x position to draw normal glyphs on.
truncation &= max_w < w; // Whether we need to do truncation.
int dot_width = 0; // Cache for the width of the dot.
const Sprite *dot_sprite = nullptr; // Cache for the sprite of the dot.
bool dot_has_shadow = false; // Whether the dot's font requires shadows.
int truncation_width = 0; // Width of the ellipsis string.
std::optional<Layouter> truncation_layout; ///< Layout for truncation ellipsis.
if (truncation) {
/*
* Assumption may be made that all fonts of a run are of the same size.
@@ -534,20 +533,17 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
* another size would be chosen it won't have truncated too little for
* the truncation dots.
*/
FontCache *fc = line.GetVisualRun(0).GetFont()->fc;
dot_has_shadow = fc->GetDrawGlyphShadow();
GlyphID dot_glyph = fc->MapCharToGlyph('.');
dot_width = fc->GetGlyphWidth(dot_glyph);
dot_sprite = fc->GetGlyph(dot_glyph);
truncation_layout.emplace(GetEllipsis(), INT32_MAX, line.GetVisualRun(0).GetFont()->fc->GetSize());
truncation_width = truncation_layout->GetBounds().width;
/* Is there enough space even for an ellipsis? */
if (max_w < dot_width * 3) return (_current_text_dir == TD_RTL) ? left : right;
if (max_w < truncation_width) return (_current_text_dir == TD_RTL) ? left : right;
if (_current_text_dir == TD_RTL) {
min_x += 3 * dot_width;
min_x += truncation_width;
offset_x = w - max_w;
} else {
max_x -= 3 * dot_width;
max_x -= truncation_width;
}
w = max_w;
@@ -583,9 +579,11 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
const uint shadow_offset = ScaleGUITrad(1);
/* Draw shadow, then foreground */
for (bool do_shadow : { true, false }) {
bool colour_has_shadow = false;
auto draw_line = [&](const ParagraphLayouter::Line &line, bool do_shadow, int left, int min_x, int max_x, bool truncation) {
const DrawPixelInfo *dpi = _cur_dpi;
int dpi_left = dpi->left;
int dpi_right = dpi->left + dpi->width - 1;
for (int run_index = 0; run_index < line.CountRuns(); run_index++) {
const ParagraphLayouter::VisualRun &run = line.GetVisualRun(run_index);
const auto &glyphs = run.GetGlyphs();
@@ -595,22 +593,18 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
FontCache *fc = f->fc;
TextColour colour = f->colour;
if (colour == TC_INVALID || HasFlag(default_colour, TC_FORCED)) colour = default_colour;
colour_has_shadow = (colour & TC_NO_SHADE) == 0 && colour != TC_BLACK;
bool colour_has_shadow = (colour & TC_NO_SHADE) == 0 && colour != TC_BLACK;
SetColourRemap(do_shadow ? TC_BLACK : colour); // the last run also sets the colour for the truncation dots
if (do_shadow && (!fc->GetDrawGlyphShadow() || !colour_has_shadow)) continue;
DrawPixelInfo *dpi = _cur_dpi;
int dpi_left = dpi->left;
int dpi_right = dpi->left + dpi->width - 1;
for (int i = 0; i < run.GetGlyphCount(); i++) {
GlyphID glyph = glyphs[i];
/* Not a valid glyph (empty) */
if (glyph == 0xFFFF) continue;
int begin_x = positions[i].left + left - offset_x;
int end_x = positions[i].right + left - offset_x;
int begin_x = positions[i].left + left;
int end_x = positions[i].right + left;
int top = positions[i].top + y;
/* Truncated away. */
@@ -625,12 +619,15 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
GfxMainBlitter(sprite, begin_x + (do_shadow ? shadow_offset : 0), top + (do_shadow ? shadow_offset : 0), BlitterMode::ColourRemap);
}
}
};
if (truncation && (!do_shadow || (dot_has_shadow && colour_has_shadow))) {
int x = (_current_text_dir == TD_RTL) ? left : (right - 3 * dot_width);
for (int i = 0; i < 3; i++, x += dot_width) {
GfxMainBlitter(dot_sprite, x + (do_shadow ? shadow_offset : 0), y + (do_shadow ? shadow_offset : 0), BlitterMode::ColourRemap);
}
/* Draw shadow, then foreground */
for (bool do_shadow : {true, false}) {
draw_line(line, do_shadow, left - offset_x, min_x, max_x, truncation);
if (truncation) {
int x = (_current_text_dir == TD_RTL) ? left : (right - truncation_width);
draw_line(*truncation_layout->front(), do_shadow, x, INT32_MIN, INT32_MAX, false);
}
}