Bug 1404370 - TextDrawTarget: add fallbacks for remaining cases, remove some hacks. r=jrmuizel
authorAlexis Beingessner <a.beingessner@gmail.com>
Fri, 29 Sep 2017 12:05:34 -0400
changeset 426663 0cf0a269491e2e2fecc607a4bce42991407befec
parent 426662 e7ac83f1710ac5e4c151d9ca6b79ed9a4971e909
child 426664 698b17a7805c785fda0ac4e782630bdd8a327748
push id97
push userfmarier@mozilla.com
push dateSat, 14 Oct 2017 01:12:59 +0000
reviewersjrmuizel
bugs1404370
milestone58.0a1
Bug 1404370 - TextDrawTarget: add fallbacks for remaining cases, remove some hacks. r=jrmuizel This adds fallbacks for: * synthetic bold * synthetic italics * text-writing-modes This also removes an old hack to make synthetic italics less broken. This also prevents special opacity handling for color fonts so that webrender gets that information. MozReview-Commit-ID: DKiTUBR6hzy
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxTextRun.cpp
layout/generic/TextDrawTarget.h
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -2079,16 +2079,22 @@ gfxFont::Draw(const gfxTextRun *aTextRun
     fontParams.isVerticalFont =
         aOrientation == gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT;
 
     bool sideways = false;
     gfxContextMatrixAutoSaveRestore matrixRestore;
 
     gfxPoint origPt = *aPt;
     if (aRunParams.isVerticalRun && !fontParams.isVerticalFont) {
+
+        if (textDrawer) {
+            textDrawer->FoundUnsupportedFeature();
+            return;
+        }
+
         sideways = true;
         matrixRestore.SetContext(aRunParams.context);
         gfxPoint p(aPt->x * aRunParams.devPerApp,
                    aPt->y * aRunParams.devPerApp);
         const Metrics& metrics = GetMetrics(eHorizontal);
         // Get a matrix we can use to draw the (horizontally-shaped) textrun
         // with 90-degree CW rotation.
         const gfxFloat
@@ -2134,16 +2140,21 @@ gfxFont::Draw(const gfxTextRun *aTextRun
     // (these values are only needed if IsSyntheticBold() is true)
     if (IsSyntheticBold()) {
         double xscale = CalcXScale(aRunParams.context->GetDrawTarget());
         fontParams.synBoldOnePixelOffset = aRunParams.direction * xscale;
         if (xscale != 0.0) {
             // use as many strikes as needed for the the increased advance
             fontParams.extraStrikes =
                 std::max(1, NS_lroundf(GetSyntheticBoldOffset() / xscale));
+
+            if (textDrawer) {
+                textDrawer->FoundUnsupportedFeature();
+                return;
+            }
         }
     } else {
         fontParams.synBoldOnePixelOffset = 0;
         fontParams.extraStrikes = 0;
     }
 
     bool oldSubpixelAA = aRunParams.dt->GetPermitSubpixelAA();
     if (!AllowSubpixelAA()) {
@@ -2162,16 +2173,20 @@ gfxFont::Draw(const gfxTextRun *aTextRun
 
     // The cairo DrawTarget backend uses the cairo_scaled_font directly
     // and so has the font skew matrix applied already.
     if (mScaledFont &&
         aRunParams.dt->GetBackendType() != BackendType::CAIRO) {
         cairo_matrix_t matrix;
         cairo_scaled_font_get_font_matrix(mScaledFont, &matrix);
         if (matrix.xy != 0) {
+            if (textDrawer) {
+                textDrawer->FoundUnsupportedFeature();
+            }
+
             // If this matrix applies a skew, which can happen when drawing
             // oblique fonts, we will set the DrawTarget matrix to apply the
             // skew. We'll need to move the glyphs by the inverse of the skew to
             // get the glyphs positioned correctly in the new device space
             // though, since the font matrix should only be applied to drawing
             // the glyphs, and not to their position.
             mat = Matrix(matrix.xx, matrix.yx,
                          matrix.xy, matrix.yy,
--- a/gfx/thebes/gfxTextRun.cpp
+++ b/gfx/thebes/gfxTextRun.cpp
@@ -637,17 +637,19 @@ gfxTextRun::Draw(Range aRange, gfxPoint 
     // synthetic bolding draws glyphs twice ==> colors with opacity won't draw
     // correctly unless first drawn without alpha
     BufferAlphaColor syntheticBoldBuffer(aParams.context);
     Color currentColor;
     bool needToRestore = false;
 
     if (aParams.drawMode & DrawMode::GLYPH_FILL &&
         HasNonOpaqueNonTransparentColor(aParams.context, currentColor) &&
-        HasSyntheticBoldOrColor(this, aRange)) {
+        HasSyntheticBoldOrColor(this, aRange) &&
+        !aParams.context->GetTextDrawer()) {
+
         needToRestore = true;
         // Measure text; use the bounding box to determine the area we need
         // to buffer.
         gfxTextRun::Metrics metrics = MeasureText(
             aRange, gfxFont::LOOSE_INK_EXTENTS,
             aParams.context->GetDrawTarget(), aParams.provider);
         if (IsRightToLeft()) {
             metrics.mBoundingBox.MoveBy(gfxPoint(aPt.x - metrics.mAdvanceWidth,
--- a/layout/generic/TextDrawTarget.h
+++ b/layout/generic/TextDrawTarget.h
@@ -155,29 +155,16 @@ public:
       fragment = &mCurrentPart->text.LastElement();
     }
 
     nsTArray<Glyph>& glyphs = fragment->glyphs;
 
     size_t oldLength = glyphs.Length();
     glyphs.SetLength(oldLength + aBuffer.mNumGlyphs);
     PodCopy(glyphs.Elements() + oldLength, aBuffer.mGlyphs, aBuffer.mNumGlyphs);
-
-    // If there's a skew for synthetic italics we need to apply it, as the font
-    // code applies the inverse transformation to glyph positions in anticipation.
-    Matrix trans = GetTransform();
-    if (trans._21 != 0) {
-      Matrix skew = Matrix(1, trans._12,
-                           trans._21, 1,
-                           0, 0);
-      for (size_t i = oldLength; i < oldLength + aBuffer.mNumGlyphs; ++i) {
-        auto position = &glyphs[i].mPosition;
-        *position = skew.TransformPoint(*position);
-      }
-    }
   }
 
   void
   AppendShadow(const wr::TextShadow& aShadow) {
     mCurrentPart->shadows.AppendElement(aShadow);
   }
 
   void