Changeset - r26578:600ca52b97e6
[Not reviewed]
master
0 4 0
Peter Nelson - 21 months ago 2022-09-30 20:36:00
peter1138@openttd.org
Change: Scale position of font shadow.
4 files changed with 22 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/fontcache/freetypefontcache.cpp
Show inline comments
 
@@ -234,15 +234,16 @@ const Sprite *FreeTypeFontCache::Interna
 
	FT_Load_Glyph(this->face, key, aa ? FT_LOAD_TARGET_NORMAL : FT_LOAD_TARGET_MONO);
 
	FT_Render_Glyph(this->face->glyph, aa ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO);
 

	
 
	/* Despite requesting a normal glyph, FreeType may have returned a bitmap */
 
	aa = (slot->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY);
 

	
 
	/* Add 1 pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel */
 
	uint width  = std::max(1U, (uint)slot->bitmap.width + (this->fs == FS_NORMAL));
 
	uint height = std::max(1U, (uint)slot->bitmap.rows  + (this->fs == FS_NORMAL));
 
	/* Add 1 scaled pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel */
 
	uint shadow = (this->fs == FS_NORMAL) ? ScaleGUITrad(1) : 0;
 
	uint width  = std::max(1U, (uint)slot->bitmap.width + shadow);
 
	uint height = std::max(1U, (uint)slot->bitmap.rows  + shadow);
 

	
 
	/* Limit glyph size to prevent overflows later on. */
 
	if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) usererror("Font glyph is too large");
 

	
 
	/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
 
	SpriteLoader::Sprite sprite;
 
@@ -256,14 +257,14 @@ const Sprite *FreeTypeFontCache::Interna
 

	
 
	/* Draw shadow for medium size */
 
	if (this->fs == FS_NORMAL && !aa) {
 
		for (uint y = 0; y < (uint)slot->bitmap.rows; y++) {
 
			for (uint x = 0; x < (uint)slot->bitmap.width; x++) {
 
				if (HasBit(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
 
					sprite.data[1 + x + (1 + y) * sprite.width].m = SHADOW_COLOUR;
 
					sprite.data[1 + x + (1 + y) * sprite.width].a = 0xFF;
 
					sprite.data[shadow + x + (shadow + y) * sprite.width].m = SHADOW_COLOUR;
 
					sprite.data[shadow + x + (shadow + y) * sprite.width].a = 0xFF;
 
				}
 
			}
 
		}
 
	}
 

	
 
	for (uint y = 0; y < (uint)slot->bitmap.rows; y++) {
src/gfx.cpp
Show inline comments
 
@@ -561,12 +561,14 @@ static int DrawLayoutLine(const Paragrap
 
			break;
 

	
 
		default:
 
			NOT_REACHED();
 
	}
 

	
 
	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 Font *f = (const Font*)run.GetFont();
 

	
 
@@ -596,25 +598,25 @@ static int DrawLayoutLine(const Paragrap
 
			const Sprite *sprite = fc->GetGlyph(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) {
 
				SetColourRemap(TC_BLACK);
 
				GfxMainBlitter(sprite, begin_x + 1, top + 1, BM_COLOUR_REMAP);
 
				GfxMainBlitter(sprite, begin_x + shadow_offset, top + shadow_offset, BM_COLOUR_REMAP);
 
				SetColourRemap(colour);
 
			}
 
			GfxMainBlitter(sprite, begin_x, top, BM_COLOUR_REMAP);
 
		}
 
	}
 

	
 
	if (truncation) {
 
		int x = (_current_text_dir == TD_RTL) ? left : (right - 3 * dot_width);
 
		for (int i = 0; i < 3; i++, x += dot_width) {
 
			if (draw_shadow) {
 
				SetColourRemap(TC_BLACK);
 
				GfxMainBlitter(dot_sprite, x + 1, y + 1, BM_COLOUR_REMAP);
 
				GfxMainBlitter(dot_sprite, x + shadow_offset, y + shadow_offset, BM_COLOUR_REMAP);
 
				SetColourRemap(colour);
 
			}
 
			GfxMainBlitter(dot_sprite, x, y, BM_COLOUR_REMAP);
 
		}
 
	}
 

	
src/os/macosx/font_osx.cpp
Show inline comments
 
@@ -273,15 +273,16 @@ const Sprite *CoreTextFontCache::Interna
 
	}
 
	if (CGRectIsNull(bounds)) usererror("Unable to render font glyph");
 

	
 
	uint bb_width = (uint)std::ceil(bounds.size.width) + 1; // Sometimes the glyph bounds are too tight and cut of the last pixel after rounding.
 
	uint bb_height = (uint)std::ceil(bounds.size.height);
 

	
 
	/* Add 1 pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel. */
 
	uint width = std::max(1U, bb_width + (this->fs == FS_NORMAL ? 1 : 0));
 
	uint height = std::max(1U, bb_height + (this->fs == FS_NORMAL ? 1 : 0));
 
	/* Add 1 scaled pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel. */
 
	uint shadow = (this->fs == FS_NORMAL) ? ScaleGUITrad(1) : 0;
 
	uint width = std::max(1U, bb_width + shadow);
 
	uint height = std::max(1U, bb_height + shadow);
 

	
 
	/* Limit glyph size to prevent overflows later on. */
 
	if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) usererror("Font glyph is too large");
 

	
 
	SpriteLoader::Sprite sprite;
 
	sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
 
@@ -311,14 +312,14 @@ const Sprite *CoreTextFontCache::Interna
 

	
 
		/* Draw shadow for medium size. */
 
		if (this->fs == FS_NORMAL && !use_aa) {
 
			for (uint y = 0; y < bb_height; y++) {
 
				for (uint x = 0; x < bb_width; x++) {
 
					if (bmp[y * pitch + x] > 0) {
 
						sprite.data[1 + x + (1 + y) * sprite.width].m = SHADOW_COLOUR;
 
						sprite.data[1 + x + (1 + y) * sprite.width].a = use_aa ? bmp[x + y * pitch] : 0xFF;
 
						sprite.data[shadow + x + (shadow + y) * sprite.width].m = SHADOW_COLOUR;
 
						sprite.data[shadow + x + (shadow + y) * sprite.width].a = use_aa ? bmp[x + y * pitch] : 0xFF;
 
					}
 
				}
 
			}
 
		}
 

	
 
		/* Extract pixel data. */
src/os/windows/font_win32.cpp
Show inline comments
 
@@ -473,15 +473,16 @@ void Win32FontCache::ClearFontCache()
 
		size = GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, 0, nullptr, &mat);
 
		if (size == GDI_ERROR) usererror("Unable to render font glyph");
 
		bmp = AllocaM(byte, size);
 
		GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
 
	}
 

	
 
	/* Add 1 pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel. */
 
	uint width = std::max(1U, (uint)gm.gmBlackBoxX + (this->fs == FS_NORMAL));
 
	uint height = std::max(1U, (uint)gm.gmBlackBoxY + (this->fs == FS_NORMAL));
 
	/* Add 1 scaled pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel. */
 
	uint shadow = (this->fs == FS_NORMAL) ? ScaleGUITrad(1) : 0;
 
	uint width = std::max(1U, (uint)gm.gmBlackBoxX + shadow);
 
	uint height = std::max(1U, (uint)gm.gmBlackBoxY + shadow);
 

	
 
	/* Limit glyph size to prevent overflows later on. */
 
	if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) usererror("Font glyph is too large");
 

	
 
	/* GDI has rendered the glyph, now we allocate a sprite and copy the image into it. */
 
	SpriteLoader::Sprite sprite;
 
@@ -503,14 +504,14 @@ void Win32FontCache::ClearFontCache()
 

	
 
		/* Draw shadow for medium size. */
 
		if (this->fs == FS_NORMAL && !aa) {
 
			for (uint y = 0; y < gm.gmBlackBoxY; y++) {
 
				for (uint x = 0; x < gm.gmBlackBoxX; x++) {
 
					if (aa ? (bmp[x + y * pitch] > 0) : HasBit(bmp[(x / 8) + y * pitch], 7 - (x % 8))) {
 
						sprite.data[1 + x + (1 + y) * sprite.width].m = SHADOW_COLOUR;
 
						sprite.data[1 + x + (1 + y) * sprite.width].a = aa ? (bmp[x + y * pitch] << 2) - 1 : 0xFF;
 
						sprite.data[shadow + x + (shadow + y) * sprite.width].m = SHADOW_COLOUR;
 
						sprite.data[shadow + x + (shadow + y) * sprite.width].a = aa ? (bmp[x + y * pitch] << 2) - 1 : 0xFF;
 
					}
 
				}
 
			}
 
		}
 

	
 
		for (uint y = 0; y < gm.gmBlackBoxY; y++) {
0 comments (0 inline, 0 general)