mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
bug 808299 - scale missing-glyph hexbox digits depending on device resolution and zoom. r=roc
This commit is contained in:
parent
17f8d8db67
commit
a19d1387a1
@ -2399,7 +2399,8 @@ struct NS_STACK_CLASS CanvasBidiProcessor : public nsBidiPresUtils::BidiProcesso
|
||||
gfxRect glyphRect(xpos, baselineOrigin.y - height,
|
||||
advance, height);
|
||||
gfxFontMissingGlyphs::DrawMissingGlyph(thebes, glyphRect,
|
||||
detailedGlyphs[0].mGlyphID);
|
||||
detailedGlyphs[0].mGlyphID,
|
||||
nsDeviceContext::AppUnitsPerCSSPixel());
|
||||
|
||||
mCtx->mTarget->SetTransform(matrix);
|
||||
}
|
||||
|
@ -1901,7 +1901,8 @@ gfxFont::Draw(gfxTextRun *aTextRun, uint32_t aStart, uint32_t aEnd,
|
||||
gfxRect glyphRect(pt.x, pt.y - height, advanceDevUnits, height);
|
||||
gfxFontMissingGlyphs::DrawMissingGlyph(aContext,
|
||||
glyphRect,
|
||||
details->mGlyphID);
|
||||
details->mGlyphID,
|
||||
appUnitsPerDevUnit);
|
||||
}
|
||||
} else {
|
||||
double glyphX = x + details->mXOffset;
|
||||
@ -2104,7 +2105,8 @@ gfxFont::Draw(gfxTextRun *aTextRun, uint32_t aStart, uint32_t aEnd,
|
||||
gfxRect glyphRect(pt.x, pt.y - height, advanceDevUnits, height);
|
||||
gfxFontMissingGlyphs::DrawMissingGlyph(aContext,
|
||||
glyphRect,
|
||||
details->mGlyphID);
|
||||
details->mGlyphID,
|
||||
appUnitsPerDevUnit);
|
||||
}
|
||||
} else {
|
||||
double glyphX = x + details->mXOffset;
|
||||
@ -4565,8 +4567,10 @@ gfxShapedText::SetMissingGlyph(uint32_t aIndex, uint32_t aChar, gfxFont *aFont)
|
||||
// Setting advance width to zero will prevent drawing the hexbox
|
||||
details->mAdvance = 0;
|
||||
} else {
|
||||
gfxFloat width = std::max(aFont->GetMetrics().aveCharWidth,
|
||||
gfxFontMissingGlyphs::GetDesiredMinWidth(aChar));
|
||||
gfxFloat width =
|
||||
std::max(aFont->GetMetrics().aveCharWidth,
|
||||
gfxFontMissingGlyphs::GetDesiredMinWidth(aChar,
|
||||
mAppUnitsPerDevUnit));
|
||||
details->mAdvance = uint32_t(width * mAppUnitsPerDevUnit);
|
||||
}
|
||||
details->mXOffset = 0;
|
||||
|
@ -4,6 +4,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "gfxFontMissingGlyphs.h"
|
||||
#include "nsDeviceContext.h"
|
||||
|
||||
#define CHAR_BITS(b00, b01, b02, b10, b11, b12, b20, b21, b22, b30, b31, b32, b40, b41, b42) \
|
||||
((b00 << 0) | (b01 << 1) | (b02 << 2) | (b10 << 3) | (b11 << 4) | (b12 << 5) | \
|
||||
@ -164,8 +165,10 @@ DrawHexChar(gfxContext *aContext, const gfxPoint& aPt, uint32_t aDigit)
|
||||
#endif // MOZ_GFX_OPTIMIZE_MOBILE
|
||||
|
||||
void
|
||||
gfxFontMissingGlyphs::DrawMissingGlyph(gfxContext *aContext, const gfxRect& aRect,
|
||||
uint32_t aChar)
|
||||
gfxFontMissingGlyphs::DrawMissingGlyph(gfxContext *aContext,
|
||||
const gfxRect& aRect,
|
||||
uint32_t aChar,
|
||||
uint32_t aAppUnitsPerDevPixel)
|
||||
{
|
||||
aContext->Save();
|
||||
|
||||
@ -183,7 +186,8 @@ gfxFontMissingGlyphs::DrawMissingGlyph(gfxContext *aContext, const gfxRect& aRec
|
||||
gfxFloat borderLeft = aRect.X() + BOX_HORIZONTAL_INSET + halfBorderWidth;
|
||||
gfxFloat borderRight = aRect.XMost() - BOX_HORIZONTAL_INSET - halfBorderWidth;
|
||||
gfxRect borderStrokeRect(borderLeft, aRect.Y() + halfBorderWidth,
|
||||
borderRight - borderLeft, aRect.Height() - 2*halfBorderWidth);
|
||||
borderRight - borderLeft,
|
||||
aRect.Height() - 2.0 * halfBorderWidth);
|
||||
if (!borderStrokeRect.IsEmpty()) {
|
||||
aContext->SetLineWidth(BOX_BORDER_WIDTH);
|
||||
aContext->SetDash(gfxContext::gfxLineSolid);
|
||||
@ -207,41 +211,47 @@ gfxFontMissingGlyphs::DrawMissingGlyph(gfxContext *aContext, const gfxRect& aRec
|
||||
aRect.Y() + aRect.Height() / 2);
|
||||
gfxFloat halfGap = HEX_CHAR_GAP / 2.0;
|
||||
gfxFloat top = -(MINIFONT_HEIGHT + halfGap);
|
||||
aContext->SetDeviceColor(currentColor);
|
||||
aContext->Translate(center);
|
||||
// We always want integer scaling, otherwise the "bitmap" glyphs will look
|
||||
// even uglier than usual when zoomed
|
||||
int32_t scale =
|
||||
std::max<int32_t>(1, nsDeviceContext::AppUnitsPerCSSPixel() /
|
||||
aAppUnitsPerDevPixel);
|
||||
aContext->Scale(gfxFloat(scale), gfxFloat(scale));
|
||||
if (aChar < 0x10000) {
|
||||
if (aRect.Width() >= 2*MINIFONT_WIDTH + HEX_CHAR_GAP &&
|
||||
if (aRect.Width() >= 2 * (MINIFONT_WIDTH + HEX_CHAR_GAP) &&
|
||||
aRect.Height() >= 2 * MINIFONT_HEIGHT + HEX_CHAR_GAP) {
|
||||
// Draw 4 digits for BMP
|
||||
aContext->SetDeviceColor(currentColor);
|
||||
gfxFloat left = -(MINIFONT_WIDTH + halfGap);
|
||||
DrawHexChar(aContext,
|
||||
center + gfxPoint(left, top), (aChar >> 12) & 0xF);
|
||||
gfxPoint(left, top), (aChar >> 12) & 0xF);
|
||||
DrawHexChar(aContext,
|
||||
center + gfxPoint(halfGap, top), (aChar >> 8) & 0xF);
|
||||
gfxPoint(halfGap, top), (aChar >> 8) & 0xF);
|
||||
DrawHexChar(aContext,
|
||||
center + gfxPoint(left, halfGap), (aChar >> 4) & 0xF);
|
||||
gfxPoint(left, halfGap), (aChar >> 4) & 0xF);
|
||||
DrawHexChar(aContext,
|
||||
center + gfxPoint(halfGap, halfGap), aChar & 0xF);
|
||||
gfxPoint(halfGap, halfGap), aChar & 0xF);
|
||||
}
|
||||
} else {
|
||||
if (aRect.Width() >= 3*MINIFONT_WIDTH + 2*HEX_CHAR_GAP &&
|
||||
if (aRect.Width() >= 3 * (MINIFONT_WIDTH + HEX_CHAR_GAP) &&
|
||||
aRect.Height() >= 2 * MINIFONT_HEIGHT + HEX_CHAR_GAP) {
|
||||
// Draw 6 digits for non-BMP
|
||||
aContext->SetDeviceColor(currentColor);
|
||||
gfxFloat first = -(MINIFONT_WIDTH * 1.5 + HEX_CHAR_GAP);
|
||||
gfxFloat second = -(MINIFONT_WIDTH / 2.0);
|
||||
gfxFloat third = (MINIFONT_WIDTH / 2.0 + HEX_CHAR_GAP);
|
||||
DrawHexChar(aContext,
|
||||
center + gfxPoint(first, top), (aChar >> 20) & 0xF);
|
||||
gfxPoint(first, top), (aChar >> 20) & 0xF);
|
||||
DrawHexChar(aContext,
|
||||
center + gfxPoint(second, top), (aChar >> 16) & 0xF);
|
||||
gfxPoint(second, top), (aChar >> 16) & 0xF);
|
||||
DrawHexChar(aContext,
|
||||
center + gfxPoint(third, top), (aChar >> 12) & 0xF);
|
||||
gfxPoint(third, top), (aChar >> 12) & 0xF);
|
||||
DrawHexChar(aContext,
|
||||
center + gfxPoint(first, halfGap), (aChar >> 8) & 0xF);
|
||||
gfxPoint(first, halfGap), (aChar >> 8) & 0xF);
|
||||
DrawHexChar(aContext,
|
||||
center + gfxPoint(second, halfGap), (aChar >> 4) & 0xF);
|
||||
gfxPoint(second, halfGap), (aChar >> 4) & 0xF);
|
||||
DrawHexChar(aContext,
|
||||
center + gfxPoint(third, halfGap), aChar & 0xF);
|
||||
gfxPoint(third, halfGap), aChar & 0xF);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -250,14 +260,19 @@ gfxFontMissingGlyphs::DrawMissingGlyph(gfxContext *aContext, const gfxRect& aRec
|
||||
}
|
||||
|
||||
gfxFloat
|
||||
gfxFontMissingGlyphs::GetDesiredMinWidth(uint32_t aChar)
|
||||
gfxFontMissingGlyphs::GetDesiredMinWidth(uint32_t aChar,
|
||||
uint32_t aAppUnitsPerDevPixel)
|
||||
{
|
||||
/**
|
||||
* The minimum desired width for a missing-glyph glyph box. I've laid it out
|
||||
* like this so you can see what goes where.
|
||||
*/
|
||||
return BOX_HORIZONTAL_INSET + BOX_BORDER_WIDTH + HEX_CHAR_GAP +
|
||||
gfxFloat width = BOX_HORIZONTAL_INSET + BOX_BORDER_WIDTH + HEX_CHAR_GAP +
|
||||
MINIFONT_WIDTH + HEX_CHAR_GAP + MINIFONT_WIDTH +
|
||||
((aChar < 0x10000) ? 0 : HEX_CHAR_GAP + MINIFONT_WIDTH) +
|
||||
HEX_CHAR_GAP + BOX_BORDER_WIDTH + BOX_HORIZONTAL_INSET;
|
||||
// Note that this will give us floating-point division, so the width will
|
||||
// -not- be snapped to integer multiples of its basic pixel value
|
||||
width *= gfxFloat(nsDeviceContext::AppUnitsPerCSSPixel()) / aAppUnitsPerDevPixel;
|
||||
return width;
|
||||
}
|
||||
|
@ -21,14 +21,19 @@ public:
|
||||
* @param aContext the context to draw to
|
||||
* @param aRect the glyph-box for the glyph that is missing
|
||||
* @param aChar the UTF16 codepoint for the character
|
||||
* @param aAppUnitsPerDevPixel the appUnits to devPixel ratio we're using,
|
||||
* (so we can scale glyphs to a sensible size)
|
||||
*/
|
||||
static void DrawMissingGlyph(gfxContext *aContext, const gfxRect& aRect,
|
||||
uint32_t aChar);
|
||||
static void DrawMissingGlyph(gfxContext *aContext,
|
||||
const gfxRect& aRect,
|
||||
uint32_t aChar,
|
||||
uint32_t aAppUnitsPerDevPixel);
|
||||
/**
|
||||
* @return the desired minimum width for a glyph-box that will allow
|
||||
* the hexboxes to be drawn reasonably.
|
||||
*/
|
||||
static gfxFloat GetDesiredMinWidth(uint32_t aChar);
|
||||
static gfxFloat GetDesiredMinWidth(uint32_t aChar,
|
||||
uint32_t aAppUnitsPerDevUnit);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user