1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-09-20 05:34:47 +00:00

Look ma, we calculated the correct baseline without using floating-point math!

This commit is contained in:
Samuel Gomes 2024-05-12 02:17:58 +05:30
parent fdb3bd2c8c
commit bce4a7fcbd

View file

@ -818,15 +818,9 @@ int32_t FontLoad(const uint8_t *content_original, int32_t content_bytes, int32_t
fontManager.fonts[h]->defaultHeight = default_pixel_height; // save default pixel height fontManager.fonts[h]->defaultHeight = default_pixel_height; // save default pixel height
// Calculate the baseline using font metrics only if it is scalable // Calculate the baseline using font metrics only if it is scalable
if (FT_IS_SCALABLE(fontManager.fonts[h]->face)) { if (FT_IS_SCALABLE(fontManager.fonts[h]->face))
if (FT_IS_FIXED_WIDTH(fontManager.fonts[h]->face)) { fontManager.fonts[h]->baseline = FT_MulDiv(FT_MulFix(fontManager.fonts[h]->face->ascender, fontManager.fonts[h]->face->size->metrics.y_scale),
fontManager.fonts[h]->baseline = default_pixel_height, fontManager.fonts[h]->face->size->metrics.height);
(FT_Pos)qbr((double)fontManager.fonts[h]->face->ascender / (double)fontManager.fonts[h]->face->units_per_EM * (double)default_pixel_height);
} else {
fontManager.fonts[h]->baseline = (FT_Pos)qbr(((double)fontManager.fonts[h]->face->size->metrics.ascender / 64.0) /
((double)fontManager.fonts[h]->face->size->metrics.height / 64.0) * (double)default_pixel_height);
}
}
// Check if automatic fixed width font detection was requested // Check if automatic fixed width font detection was requested
if ((options & FONT_LOAD_AUTOMONO) && FT_IS_FIXED_WIDTH(fontManager.fonts[h]->face)) if ((options & FONT_LOAD_AUTOMONO) && FT_IS_FIXED_WIDTH(fontManager.fonts[h]->face))
@ -846,14 +840,14 @@ int32_t FontLoad(const uint8_t *content_original, int32_t content_bytes, int32_t
if (fontManager.fonts[h]->face->glyph) { if (fontManager.fonts[h]->face->glyph) {
fontManager.fonts[h]->monospaceWidth = fontManager.fonts[h]->monospaceWidth =
std::max(fontManager.fonts[h]->face->glyph->advance.x / 64, (FT_Pos)fontManager.fonts[h]->face->glyph->bitmap.width); // save the max width std::max<FT_Pos>(fontManager.fonts[h]->face->glyph->advance.x >> 6, fontManager.fonts[h]->face->glyph->bitmap.width); // save the max width
FONT_DEBUG_PRINT("Monospace font (width = %li) requested", fontManager.fonts[h]->monospaceWidth); FONT_DEBUG_PRINT("Monospace font (width = %li) requested", fontManager.fonts[h]->monospaceWidth);
}
// Set the baseline to bitmap_top if the font is not scalable // Set the baseline to bitmap_top if the font is not scalable
if (!FT_IS_SCALABLE(fontManager.fonts[h]->face)) if (!FT_IS_SCALABLE(fontManager.fonts[h]->face))
fontManager.fonts[h]->baseline = fontManager.fonts[h]->face->glyph->bitmap_top; // for bitmap fonts bitmap_top is the same for all glyph bitmaps fontManager.fonts[h]->baseline = fontManager.fonts[h]->face->glyph->bitmap_top; // for bitmap fonts bitmap_top is the same for all glyph bitmaps
}
// Clear the monospace flag is we failed to get the monospace width // Clear the monospace flag is we failed to get the monospace width
if (!fontManager.fonts[h]->monospaceWidth) if (!fontManager.fonts[h]->monospaceWidth)