Changeset - r24786:883ea1a9d161
[Not reviewed]
master
0 3 0
Michael Lutz - 4 years ago 2021-02-13 21:44:45
michi@icosahedron.de
Codechange: Replace magic numbers by constants.
3 files changed with 7 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/fontcache.cpp
Show inline comments
 
@@ -440,7 +440,7 @@ void FreeTypeFontCache::SetFontSize(Font
 
			/* Font height is minimum height plus the difference between the default
 
			 * height for this font size and the small size. */
 
			int diff = scaled_height - ScaleFontTrad(_default_font_height[FS_SMALL]);
 
			pixels = Clamp(std::min<uint>(head->Lowest_Rec_PPEM, 20u) + diff, scaled_height, MAX_FONT_SIZE);
 
			pixels = Clamp(std::min<uint>(head->Lowest_Rec_PPEM, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height, MAX_FONT_SIZE);
 
		}
 
	} else {
 
		pixels = ScaleFontTrad(pixels);
 
@@ -608,7 +608,7 @@ const Sprite *FreeTypeFontCache::Interna
 
	uint height = std::max(1U, (uint)slot->bitmap.rows  + (this->fs == FS_NORMAL));
 

	
 
	/* Limit glyph size to prevent overflows later on. */
 
	if (width > 256 || height > 256) usererror("Font glyph is too large");
 
	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;
src/fontcache_internal.h
Show inline comments
 
@@ -22,6 +22,9 @@ static const byte SHADOW_COLOUR = 2;
 
/** Font cache for fonts that are based on a TrueType font. */
 
class TrueTypeFontCache : public FontCache {
 
protected:
 
	static constexpr int MAX_GLYPH_DIM = 256;          ///< Maximum glyph dimensions.
 
	static constexpr uint MAX_FONT_MIN_REC_SIZE = 20u; ///< Upper limit for the recommended font size in case a font file contains nonsensical values.
 

	
 
	int req_size;  ///< Requested font size.
 
	int used_size; ///< Used font size.
 

	
src/os/windows/font_win32.cpp
Show inline comments
 
@@ -414,7 +414,7 @@ void Win32FontCache::SetFontSize(FontSiz
 
			/* Font height is minimum height plus the difference between the default
 
			 * height for this font size and the small size. */
 
			int diff = scaled_height - ScaleFontTrad(this->GetDefaultFontHeight(FS_SMALL));
 
			pixels = Clamp(std::min(otm->otmusMinimumPPEM, 20u) + diff, scaled_height, MAX_FONT_SIZE);
 
			pixels = Clamp(std::min(otm->otmusMinimumPPEM, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height, MAX_FONT_SIZE);
 

	
 
			SelectObject(dc, old);
 
			DeleteObject(temp);
 
@@ -489,7 +489,7 @@ void Win32FontCache::ClearFontCache()
 
	uint height = std::max(1U, (uint)gm.gmBlackBoxY + (this->fs == FS_NORMAL));
 

	
 
	/* Limit glyph size to prevent overflows later on. */
 
	if (width > 256 || height > 256) usererror("Font glyph is too large");
 
	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;
0 comments (0 inline, 0 general)