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
 
@@ -237,9 +237,10 @@ const Sprite *FreeTypeFontCache::Interna
 
	/* 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");
 
@@ -259,8 +260,8 @@ const Sprite *FreeTypeFontCache::Interna
 
		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;
 
				}
 
			}
 
		}
src/gfx.cpp
Show inline comments
 
@@ -564,6 +564,8 @@ static int DrawLayoutLine(const Paragrap
 
			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++) {
 
@@ -599,7 +601,7 @@ static int DrawLayoutLine(const Paragrap
 

	
 
			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);
 
@@ -611,7 +613,7 @@ static int DrawLayoutLine(const Paragrap
 
		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
 
@@ -276,9 +276,10 @@ const Sprite *CoreTextFontCache::Interna
 
	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");
 
@@ -314,8 +315,8 @@ const Sprite *CoreTextFontCache::Interna
 
			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;
 
					}
 
				}
 
			}
src/os/windows/font_win32.cpp
Show inline comments
 
@@ -476,9 +476,10 @@ void Win32FontCache::ClearFontCache()
 
		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");
 
@@ -506,8 +507,8 @@ void Win32FontCache::ClearFontCache()
 
			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;
 
					}
 
				}
 
			}
0 comments (0 inline, 0 general)