зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1400917 - render missing glyphs with WebRender. r=gankro
This commit is contained in:
Родитель
1455a9946c
Коммит
d7042b0a8f
|
@ -1995,9 +1995,18 @@ gfxFont::DrawMissingGlyph(const TextRunDrawParams& aRunParams,
|
|||
float advance = aDetails->mAdvance;
|
||||
if (aRunParams.drawMode != DrawMode::GLYPH_PATH && advance > 0) {
|
||||
auto* textDrawer = aRunParams.context->GetTextDrawer();
|
||||
const Matrix* matPtr = nullptr;
|
||||
Matrix mat;
|
||||
if (textDrawer) {
|
||||
textDrawer->FoundUnsupportedFeature();
|
||||
return false;
|
||||
// Generate an orientation matrix for the current writing mode
|
||||
wr::FontInstanceFlags flags = textDrawer->GetWRGlyphFlags();
|
||||
if (flags.bits & wr::FontInstanceFlags::TRANSPOSE) {
|
||||
std::swap(mat._11, mat._12);
|
||||
std::swap(mat._21, mat._22);
|
||||
}
|
||||
mat.PostScale(flags.bits & wr::FontInstanceFlags::FLIP_X ? -1.0f : 1.0f,
|
||||
flags.bits & wr::FontInstanceFlags::FLIP_Y ? -1.0f : 1.0f);
|
||||
matPtr = &mat;
|
||||
}
|
||||
|
||||
Point pt(Float(ToDeviceUnits(aPt.x, aRunParams.devPerApp)),
|
||||
|
@ -2005,7 +2014,8 @@ gfxFont::DrawMissingGlyph(const TextRunDrawParams& aRunParams,
|
|||
Float advanceDevUnits =
|
||||
Float(ToDeviceUnits(advance, aRunParams.devPerApp));
|
||||
Float height = GetMetrics(eHorizontal).maxAscent;
|
||||
Rect glyphRect = aFontParams.isVerticalFont ?
|
||||
// Horizontally center if drawing vertically upright with no sideways transform.
|
||||
Rect glyphRect = aFontParams.isVerticalFont && !mat.HasNonAxisAlignedTransform() ?
|
||||
Rect(pt.x - height / 2, pt.y,
|
||||
height, advanceDevUnits) :
|
||||
Rect(pt.x, pt.y - height,
|
||||
|
@ -2028,7 +2038,7 @@ gfxFont::DrawMissingGlyph(const TextRunDrawParams& aRunParams,
|
|||
gfxFontMissingGlyphs::DrawMissingGlyph(
|
||||
aDetails->mGlyphID, glyphRect, *aRunParams.dt,
|
||||
PatternFromState(aRunParams.context),
|
||||
1.0 / aRunParams.devPerApp);
|
||||
1.0 / aRunParams.devPerApp, matPtr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -158,13 +158,39 @@ static const Float BOX_BORDER_OPACITY = 0.5;
|
|||
#ifndef MOZ_GFX_OPTIMIZE_MOBILE
|
||||
static void
|
||||
DrawHexChar(uint32_t aDigit, const Point& aPt, DrawTarget& aDrawTarget,
|
||||
const Pattern &aPattern)
|
||||
const Pattern &aPattern, const Matrix* aMat)
|
||||
{
|
||||
uint32_t glyphBits = glyphMicroFont[aDigit];
|
||||
|
||||
if (aMat) {
|
||||
// If using an orientation matrix instead of a DT transform, step
|
||||
// with the matrix basis vectors, filling individual rectangles of
|
||||
// the size indicated by the matrix.
|
||||
Point stepX(aMat->_11, aMat->_12);
|
||||
Point stepY(aMat->_21, aMat->_22);
|
||||
Point corner = stepX + stepY;
|
||||
// Get the rectangle at the origin that will be stepped into place.
|
||||
Rect startRect(std::min(corner.x, 0.0f), std::min(corner.y, 0.0f),
|
||||
fabs(corner.x), fabs(corner.y));
|
||||
startRect.MoveBy(aMat->TransformPoint(aPt));
|
||||
for (int y = 0; y < MINIFONT_HEIGHT; ++y) {
|
||||
Rect curRect = startRect;
|
||||
for (int x = 0; x < MINIFONT_WIDTH; ++x) {
|
||||
if (glyphBits & 1) {
|
||||
aDrawTarget.FillRect(curRect, aPattern);
|
||||
}
|
||||
glyphBits >>= 1;
|
||||
curRect.MoveBy(stepX);
|
||||
}
|
||||
startRect.MoveBy(stepY);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// To avoid the potential for seams showing between rects when we're under
|
||||
// a transform we concat all the rects into a PathBuilder and fill the
|
||||
// resulting Path (rather than using DrawTarget::FillRect).
|
||||
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
|
||||
uint32_t glyphBits = glyphMicroFont[aDigit];
|
||||
for (int y = 0; y < MINIFONT_HEIGHT; ++y) {
|
||||
for (int x = 0; x < MINIFONT_WIDTH; ++x) {
|
||||
if (glyphBits & 1) {
|
||||
|
@ -189,8 +215,17 @@ gfxFontMissingGlyphs::DrawMissingGlyph(uint32_t aChar,
|
|||
const Rect& aRect,
|
||||
DrawTarget& aDrawTarget,
|
||||
const Pattern& aPattern,
|
||||
uint32_t aAppUnitsPerDevPixel)
|
||||
uint32_t aAppUnitsPerDevPixel,
|
||||
const Matrix* aMat)
|
||||
{
|
||||
Rect rect(aRect);
|
||||
// If there is an orientation transform, reorient the bounding rect.
|
||||
if (aMat) {
|
||||
rect.MoveBy(-aRect.BottomLeft());
|
||||
rect = aMat->TransformBounds(rect);
|
||||
rect.MoveBy(aRect.BottomLeft());
|
||||
}
|
||||
|
||||
// If we're currently drawing with some kind of pattern, we just draw the
|
||||
// missing-glyph data in black.
|
||||
ColorPattern color = aPattern.GetType() == PatternType::COLOR ?
|
||||
|
@ -201,11 +236,11 @@ gfxFontMissingGlyphs::DrawMissingGlyph(uint32_t aChar,
|
|||
// from the left edge of the glyph box and the stroke's right edge
|
||||
// is inset one pixel from the right edge of the glyph box.
|
||||
Float halfBorderWidth = BOX_BORDER_WIDTH / 2.0;
|
||||
Float borderLeft = aRect.X() + BOX_HORIZONTAL_INSET + halfBorderWidth;
|
||||
Float borderRight = aRect.XMost() - BOX_HORIZONTAL_INSET - halfBorderWidth;
|
||||
Rect borderStrokeRect(borderLeft, aRect.Y() + halfBorderWidth,
|
||||
Float borderLeft = rect.X() + BOX_HORIZONTAL_INSET + halfBorderWidth;
|
||||
Float borderRight = rect.XMost() - BOX_HORIZONTAL_INSET - halfBorderWidth;
|
||||
Rect borderStrokeRect(borderLeft, rect.Y() + halfBorderWidth,
|
||||
borderRight - borderLeft,
|
||||
aRect.Height() - 2.0 * halfBorderWidth);
|
||||
rect.Height() - 2.0 * halfBorderWidth);
|
||||
if (!borderStrokeRect.IsEmpty()) {
|
||||
ColorPattern adjustedColor = color;
|
||||
color.mColor.a *= BOX_BORDER_OPACITY;
|
||||
|
@ -218,7 +253,7 @@ gfxFontMissingGlyphs::DrawMissingGlyph(uint32_t aChar,
|
|||
}
|
||||
|
||||
#ifndef MOZ_GFX_OPTIMIZE_MOBILE
|
||||
Point center = aRect.Center();
|
||||
Point center = rect.Center();
|
||||
Float halfGap = HEX_CHAR_GAP / 2.f;
|
||||
Float top = -(MINIFONT_HEIGHT + halfGap);
|
||||
// We always want integer scaling, otherwise the "bitmap" glyphs will look
|
||||
|
@ -226,46 +261,65 @@ gfxFontMissingGlyphs::DrawMissingGlyph(uint32_t aChar,
|
|||
int32_t devPixelsPerCSSPx =
|
||||
std::max<int32_t>(1, nsDeviceContext::AppUnitsPerCSSPixel() /
|
||||
aAppUnitsPerDevPixel);
|
||||
AutoRestoreTransform autoRestoreTransform(&aDrawTarget);
|
||||
aDrawTarget.SetTransform(
|
||||
aDrawTarget.GetTransform().PreTranslate(center).
|
||||
PreScale(devPixelsPerCSSPx,
|
||||
devPixelsPerCSSPx));
|
||||
|
||||
Matrix tempMat;
|
||||
if (aMat) {
|
||||
// If there is an orientation transform, since draw target transforms may
|
||||
// not be supported, scale and translate it so that it can be directly used
|
||||
// for rendering the mini font without changing the draw target transform.
|
||||
tempMat = Matrix(*aMat).PostScale(devPixelsPerCSSPx, devPixelsPerCSSPx)
|
||||
.PostTranslate(center);
|
||||
aMat = &tempMat;
|
||||
} else {
|
||||
// Otherwise, scale and translate the draw target transform assuming it
|
||||
// supports that.
|
||||
tempMat = aDrawTarget.GetTransform();
|
||||
aDrawTarget.SetTransform(
|
||||
Matrix(tempMat).PreTranslate(center)
|
||||
.PreScale(devPixelsPerCSSPx, devPixelsPerCSSPx));
|
||||
}
|
||||
|
||||
if (aChar < 0x10000) {
|
||||
if (aRect.Width() >= 2 * (MINIFONT_WIDTH + HEX_CHAR_GAP) &&
|
||||
aRect.Height() >= 2 * MINIFONT_HEIGHT + HEX_CHAR_GAP) {
|
||||
if (rect.Width() >= 2 * (MINIFONT_WIDTH + HEX_CHAR_GAP) &&
|
||||
rect.Height() >= 2 * MINIFONT_HEIGHT + HEX_CHAR_GAP) {
|
||||
// Draw 4 digits for BMP
|
||||
Float left = -(MINIFONT_WIDTH + halfGap);
|
||||
DrawHexChar((aChar >> 12) & 0xF,
|
||||
Point(left, top), aDrawTarget, color);
|
||||
Point(left, top), aDrawTarget, color, aMat);
|
||||
DrawHexChar((aChar >> 8) & 0xF,
|
||||
Point(halfGap, top), aDrawTarget, color);
|
||||
Point(halfGap, top), aDrawTarget, color, aMat);
|
||||
DrawHexChar((aChar >> 4) & 0xF,
|
||||
Point(left, halfGap), aDrawTarget, color);
|
||||
Point(left, halfGap), aDrawTarget, color, aMat);
|
||||
DrawHexChar(aChar & 0xF,
|
||||
Point(halfGap, halfGap), aDrawTarget, color);
|
||||
Point(halfGap, halfGap), aDrawTarget, color, aMat);
|
||||
}
|
||||
} else {
|
||||
if (aRect.Width() >= 3 * (MINIFONT_WIDTH + HEX_CHAR_GAP) &&
|
||||
aRect.Height() >= 2 * MINIFONT_HEIGHT + HEX_CHAR_GAP) {
|
||||
if (rect.Width() >= 3 * (MINIFONT_WIDTH + HEX_CHAR_GAP) &&
|
||||
rect.Height() >= 2 * MINIFONT_HEIGHT + HEX_CHAR_GAP) {
|
||||
// Draw 6 digits for non-BMP
|
||||
Float first = -(MINIFONT_WIDTH * 1.5 + HEX_CHAR_GAP);
|
||||
Float second = -(MINIFONT_WIDTH / 2.0);
|
||||
Float third = (MINIFONT_WIDTH / 2.0 + HEX_CHAR_GAP);
|
||||
DrawHexChar((aChar >> 20) & 0xF,
|
||||
Point(first, top), aDrawTarget, color);
|
||||
Point(first, top), aDrawTarget, color, aMat);
|
||||
DrawHexChar((aChar >> 16) & 0xF,
|
||||
Point(second, top), aDrawTarget, color);
|
||||
Point(second, top), aDrawTarget, color, aMat);
|
||||
DrawHexChar((aChar >> 12) & 0xF,
|
||||
Point(third, top), aDrawTarget, color);
|
||||
Point(third, top), aDrawTarget, color, aMat);
|
||||
DrawHexChar((aChar >> 8) & 0xF,
|
||||
Point(first, halfGap), aDrawTarget, color);
|
||||
Point(first, halfGap), aDrawTarget, color, aMat);
|
||||
DrawHexChar((aChar >> 4) & 0xF,
|
||||
Point(second, halfGap), aDrawTarget, color);
|
||||
Point(second, halfGap), aDrawTarget, color, aMat);
|
||||
DrawHexChar(aChar & 0xF,
|
||||
Point(third, halfGap), aDrawTarget, color);
|
||||
Point(third, halfGap), aDrawTarget, color, aMat);
|
||||
}
|
||||
}
|
||||
|
||||
if (!aMat) {
|
||||
// The draw target transform was changed, so it must be restored to
|
||||
// the original value.
|
||||
aDrawTarget.SetTransform(tempMat);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -38,12 +38,14 @@ public:
|
|||
* @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);
|
||||
uint32_t aAppUnitsPerDevPixel,
|
||||
const Matrix* aMat = nullptr);
|
||||
/**
|
||||
* @return the desired minimum width for a glyph-box that will allow
|
||||
* the hexboxes to be drawn reasonably.
|
||||
|
|
|
@ -399,14 +399,48 @@ public:
|
|||
void FillRect(const Rect &aRect,
|
||||
const Pattern &aPattern,
|
||||
const DrawOptions &aOptions = DrawOptions()) override {
|
||||
MOZ_CRASH("TextDrawTarget: Method shouldn't be called");
|
||||
MOZ_RELEASE_ASSERT(aPattern.GetType() == PatternType::COLOR);
|
||||
|
||||
auto rect = mSc.ToRelativeLayoutRect(LayoutDeviceRect::FromUnknownRect(aRect));
|
||||
auto color = wr::ToColorF(static_cast<const ColorPattern&>(aPattern).mColor);
|
||||
mBuilder.PushRect(rect, mClipRect, mBackfaceVisible, color);
|
||||
}
|
||||
|
||||
void StrokeRect(const Rect &aRect,
|
||||
const Pattern &aPattern,
|
||||
const StrokeOptions &aStrokeOptions,
|
||||
const DrawOptions &aOptions) override {
|
||||
MOZ_CRASH("TextDrawTarget: Method shouldn't be called");
|
||||
MOZ_RELEASE_ASSERT(aPattern.GetType() == PatternType::COLOR &&
|
||||
aStrokeOptions.mDashLength == 0);
|
||||
|
||||
wr::Line line;
|
||||
line.wavyLineThickness = 0; // dummy value, unused
|
||||
line.color = wr::ToColorF(static_cast<const ColorPattern&>(aPattern).mColor);
|
||||
line.style = wr::LineStyle::Solid;
|
||||
|
||||
// Top horizontal line
|
||||
LayoutDevicePoint top(aRect.x, aRect.y - aStrokeOptions.mLineWidth / 2);
|
||||
LayoutDeviceSize horiSize(aRect.width, aStrokeOptions.mLineWidth);
|
||||
line.bounds = mSc.ToRelativeLayoutRect(LayoutDeviceRect(top, horiSize));
|
||||
line.orientation = wr::LineOrientation::Horizontal;
|
||||
mBuilder.PushLine(mClipRect, mBackfaceVisible, line);
|
||||
|
||||
// Bottom horizontal line
|
||||
LayoutDevicePoint bottom(aRect.x, aRect.YMost() - aStrokeOptions.mLineWidth / 2);
|
||||
line.bounds = mSc.ToRelativeLayoutRect(LayoutDeviceRect(bottom, horiSize));
|
||||
mBuilder.PushLine(mClipRect, mBackfaceVisible, line);
|
||||
|
||||
// Left vertical line
|
||||
LayoutDevicePoint left(aRect.x + aStrokeOptions.mLineWidth / 2, aRect.y + aStrokeOptions.mLineWidth / 2);
|
||||
LayoutDeviceSize vertSize(aStrokeOptions.mLineWidth, aRect.height - aStrokeOptions.mLineWidth);
|
||||
line.bounds = mSc.ToRelativeLayoutRect(LayoutDeviceRect(left, vertSize));
|
||||
line.orientation = wr::LineOrientation::Vertical;
|
||||
mBuilder.PushLine(mClipRect, mBackfaceVisible, line);
|
||||
|
||||
// Right vertical line
|
||||
LayoutDevicePoint right(aRect.XMost() - aStrokeOptions.mLineWidth / 2, aRect.y + aStrokeOptions.mLineWidth / 2);
|
||||
line.bounds = mSc.ToRelativeLayoutRect(LayoutDeviceRect(right, vertSize));
|
||||
mBuilder.PushLine(mClipRect, mBackfaceVisible, line);
|
||||
}
|
||||
|
||||
void StrokeLine(const Point &aStart,
|
||||
|
|
Загрузка…
Ссылка в новой задаче