Bug 376129 - Scale the missing-glyph hex digits more usefully for large font sizes. r=gfx-reviewers,lsalzman

This makes the digits scale up to better fill the box, as it looks a bit odd to have
the box grow with the font size but the digits remain tiny in the middle of it.

One thing that may look a little odd with this version is that 6-digit hexboxes tend
to get smaller digits than 4-digit ones with large font sizes. But I think that's
OK; it allows the 4-digit chars to be more readable, and 6-digit (non-BMP) ones are
generally much rarer.

(And the whole thing is basically cosmetic anyhow; this isn't about rendering web
content as intended, but trying to provide a bit of useful information when the
content is somehow broken or not renderable.)

Differential Revision: https://phabricator.services.mozilla.com/D173463
This commit is contained in:
Jonathan Kew 2023-03-24 09:07:04 +00:00
parent 6996eb2bcc
commit c96601cb34
3 changed files with 15 additions and 11 deletions

View File

@ -2199,10 +2199,9 @@ bool gfxFont::DrawMissingGlyph(const TextRunDrawParams& aRunParams,
aRunParams.context->SetMatrix(mat);
}
gfxFontMissingGlyphs::DrawMissingGlyph(aDetails->mGlyphID, glyphRect,
*aRunParams.dt,
PatternFromState(aRunParams.context),
1.0 / aRunParams.devPerApp, matPtr);
gfxFontMissingGlyphs::DrawMissingGlyph(
aDetails->mGlyphID, glyphRect, *aRunParams.dt,
PatternFromState(aRunParams.context), matPtr);
}
return true;
}

View File

@ -378,7 +378,6 @@ void gfxFontMissingGlyphs::Shutdown() { Purge(); }
void gfxFontMissingGlyphs::DrawMissingGlyph(uint32_t aChar, const Rect& aRect,
DrawTarget& aDrawTarget,
const Pattern& aPattern,
uint32_t aAppUnitsPerDevPixel,
const Matrix* aMat) {
Rect rect(aRect);
// If there is an orientation transform, reorient the bounding rect.
@ -426,10 +425,19 @@ void gfxFontMissingGlyphs::DrawMissingGlyph(uint32_t aChar, const Rect& aRect,
Point center = rect.Center();
Float halfGap = HEX_CHAR_GAP / 2.f;
Float top = -(MINIFONT_HEIGHT + halfGap);
// Figure out a scaling factor that will fit the glyphs in the target rect
// both horizontally and vertically.
Float width = HEX_CHAR_GAP + MINIFONT_WIDTH + HEX_CHAR_GAP + MINIFONT_WIDTH +
((aChar < 0x10000) ? 0 : HEX_CHAR_GAP + MINIFONT_WIDTH) +
HEX_CHAR_GAP;
Float height = HEX_CHAR_GAP + MINIFONT_HEIGHT + HEX_CHAR_GAP +
MINIFONT_HEIGHT + HEX_CHAR_GAP;
Float scaling = std::min(rect.Height() / height, rect.Width() / width);
// We always want integer scaling, otherwise the "bitmap" glyphs will look
// even uglier than usual when zoomed
int32_t devPixelsPerCSSPx =
std::max<int32_t>(1, AppUnitsPerCSSPixel() / aAppUnitsPerDevPixel);
// even uglier than usual when scaled to the target.
int32_t devPixelsPerCSSPx = std::max<int32_t>(1, std::floor(scaling));
Matrix tempMat;
if (aMat) {

View File

@ -37,13 +37,10 @@ class gfxFontMissingGlyphs final {
* @param aRect the glyph-box for the glyph that is missing
* @param aDrawTarget the DrawTarget to draw to
* @param aPattern the pattern currently being used to paint
* @param aAppUnitsPerDevPixel the appUnits to devPixel ratio we're using,
* (so we can scale glyphs to a sensible size)
* @param aMat optional local-space orientation matrix
*/
static void DrawMissingGlyph(uint32_t aChar, const Rect& aRect,
DrawTarget& aDrawTarget, const Pattern& aPattern,
uint32_t aAppUnitsPerDevPixel,
const Matrix* aMat = nullptr);
/**
* @return the desired minimum width for a glyph-box that will allow