|
@@ -489,13 +489,13 @@ void FreeTypeFontCache::SetFontSize(Font
|
|
|
|
|
|
TT_Header *head = (TT_Header *)FT_Get_Sfnt_Table(this->face, ft_sfnt_head);
|
|
|
if (head != nullptr) {
|
|
|
/* 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(min(head->Lowest_Rec_PPEM, 20) + diff, scaled_height, MAX_FONT_SIZE);
|
|
|
pixels = Clamp(std::min<uint>(head->Lowest_Rec_PPEM, 20u) + diff, scaled_height, MAX_FONT_SIZE);
|
|
|
}
|
|
|
} else {
|
|
|
pixels = ScaleFontTrad(pixels);
|
|
|
}
|
|
|
this->used_size = pixels;
|
|
|
|
|
@@ -653,14 +653,14 @@ const Sprite *FreeTypeFontCache::Interna
|
|
|
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 = max(1U, (uint)slot->bitmap.width + (this->fs == FS_NORMAL));
|
|
|
uint height = max(1U, (uint)slot->bitmap.rows + (this->fs == FS_NORMAL));
|
|
|
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));
|
|
|
|
|
|
/* Limit glyph size to prevent overflows later on. */
|
|
|
if (width > 256 || height > 256) 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;
|
|
@@ -794,13 +794,13 @@ void Win32FontCache::SetFontSize(FontSiz
|
|
|
LPOUTLINETEXTMETRIC otm = (LPOUTLINETEXTMETRIC)AllocaM(BYTE, size);
|
|
|
GetOutlineTextMetrics(this->dc, size, otm);
|
|
|
|
|
|
/* 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(min(otm->otmusMinimumPPEM, 20) + diff, scaled_height, MAX_FONT_SIZE);
|
|
|
pixels = Clamp(std::min(otm->otmusMinimumPPEM, 20u) + diff, scaled_height, MAX_FONT_SIZE);
|
|
|
|
|
|
SelectObject(dc, old);
|
|
|
DeleteObject(temp);
|
|
|
}
|
|
|
} else {
|
|
|
pixels = ScaleFontTrad(pixels);
|
|
@@ -848,13 +848,13 @@ void Win32FontCache::ClearFontCache()
|
|
|
/* virtual */ const Sprite *Win32FontCache::InternalGetGlyph(GlyphID key, bool aa)
|
|
|
{
|
|
|
GLYPHMETRICS gm;
|
|
|
MAT2 mat = { {0, 1}, {0, 0}, {0, 0}, {0, 1} };
|
|
|
|
|
|
/* Make a guess for the needed memory size. */
|
|
|
DWORD size = this->glyph_size.cy * Align(aa ? this->glyph_size.cx : max(this->glyph_size.cx / 8l, 1l), 4); // Bitmap data is DWORD-aligned rows.
|
|
|
DWORD size = this->glyph_size.cy * Align(aa ? this->glyph_size.cx : std::max(this->glyph_size.cx / 8l, 1l), 4); // Bitmap data is DWORD-aligned rows.
|
|
|
byte *bmp = AllocaM(byte, size);
|
|
|
size = GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
|
|
|
|
|
|
if (size == GDI_ERROR) {
|
|
|
/* No dice with the guess. First query size of needed glyph memory, then allocate the
|
|
|
* memory and query again. This dance is necessary as some glyphs will only render with
|
|
@@ -865,14 +865,14 @@ void Win32FontCache::ClearFontCache()
|
|
|
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 = max(1U, (uint)gm.gmBlackBoxX + (this->fs == FS_NORMAL));
|
|
|
uint height = max(1U, (uint)gm.gmBlackBoxY + (this->fs == FS_NORMAL));
|
|
|
uint width = std::max(1U, (uint)gm.gmBlackBoxX + (this->fs == FS_NORMAL));
|
|
|
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");
|
|
|
|
|
|
/* GDI has rendered the glyph, now we allocate a sprite and copy the image into it. */
|
|
|
SpriteLoader::Sprite sprite;
|
|
@@ -886,13 +886,13 @@ void Win32FontCache::ClearFontCache()
|
|
|
if (size > 0) {
|
|
|
/* All pixel data returned by GDI is in the form of DWORD-aligned rows.
|
|
|
* For a non anti-aliased glyph, the returned bitmap has one bit per pixel.
|
|
|
* For anti-aliased rendering, GDI uses the strange value range of 0 to 64,
|
|
|
* inclusively. To map this to 0 to 255, we shift left by two and then
|
|
|
* subtract one. */
|
|
|
uint pitch = Align(aa ? gm.gmBlackBoxX : max(gm.gmBlackBoxX / 8u, 1u), 4);
|
|
|
uint pitch = Align(aa ? gm.gmBlackBoxX : std::max(gm.gmBlackBoxX / 8u, 1u), 4);
|
|
|
|
|
|
/* 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))) {
|