Changeset - r28802:79312686cdf9
[Not reviewed]
master
0 1 0
frosch - 2 months ago 2024-02-22 22:22:35
frosch@openttd.org
Fix #12127, 555a379: Truncation ellipses rendered shadows even for black font without shadows (#12132)
1 file changed with 8 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -519,21 +519,23 @@ static int DrawLayoutLine(const Paragrap
 
	int min_x = left;  // The minimum x position to draw normal glyphs on.
 
	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.
 

	
 
	if (truncation) {
 
		/*
 
		 * Assumption may be made that all fonts of a run are of the same size.
 
		 * In any case, we'll use these dots for the abbreviation, so even if
 
		 * 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);
 

	
 
		if (_current_text_dir == TD_RTL) {
 
			min_x += 3 * dot_width;
 
@@ -574,23 +576,24 @@ static int DrawLayoutLine(const Paragrap
 
	}
 

	
 
	const uint shadow_offset = ScaleGUITrad(1);
 

	
 
	/* Draw shadow, then foreground */
 
	for (bool do_shadow : { true, false }) {
 
		TextColour colour = TC_BLACK;
 
		bool colour_has_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;
 
			if (do_shadow && (!fc->GetDrawGlyphShadow() || (colour & TC_NO_SHADE) != 0 || colour == TC_BLACK)) continue;
 
			SetColourRemap(do_shadow ? TC_BLACK : colour);
 
			TextColour colour = f->colour;
 
			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++) {
 
@@ -613,13 +616,13 @@ static int DrawLayoutLine(const Paragrap
 
				if (do_shadow && (glyph & SPRITE_GLYPH) != 0) continue;
 

	
 
				GfxMainBlitter(sprite, begin_x + (do_shadow ? shadow_offset : 0), top + (do_shadow ? shadow_offset : 0), BM_COLOUR_REMAP);
 
			}
 
		}
 

	
 
		if (truncation) {
 
		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), BM_COLOUR_REMAP);
 
			}
 
		}
 
	}
0 comments (0 inline, 0 general)