Bug 1397361 - Apply skew transform to glyphs to undo inverse transform in font code. r?jrmuizel draft
authorAlexis Beingessner <a.beingessner@gmail.com>
Wed, 06 Sep 2017 13:08:09 -0400
changeset 660184 db4de2901a7a053e2561bb9dfbee9f6eb4aaa20b
parent 659873 c959327c6b75cd4930a6ea087583c38b805e7524
child 730148 52334b105b6d1e9e8ab4cf90cfba799a9532543f
push id78306
push userbmo:a.beingessner@gmail.com
push dateWed, 06 Sep 2017 17:10:52 +0000
reviewersjrmuizel
bugs1397361
milestone57.0a1
Bug 1397361 - Apply skew transform to glyphs to undo inverse transform in font code. r?jrmuizel MozReview-Commit-ID: GBpDmWp1Hnm
layout/generic/TextDrawTarget.h
--- a/layout/generic/TextDrawTarget.h
+++ b/layout/generic/TextDrawTarget.h
@@ -114,16 +114,29 @@ public:
       fragment = &mText.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) { mShadows.AppendElement(aShadow); }
 
   void
   AppendSelection(const LayoutDeviceRect& aRect, const Color& aColor)
   {
     SelectionFragment frag;