[COLRv1] Take P2 into account again in gradient skewing

The change in [1] is likely responsible for a regression in which we're
not taking into account P2 for gradient skewing anymore.

Fix that, and add a test case to the gradient set of test cases.
Source for test glyph, see here:
https://github.com/googlefonts/color-fonts/pull/90/files

[1] https://source.chromium.org/chromium/_/skia/skia.git/+/2da029b28f9784b0a534e9d97d7c38f2ce151178

Cq-Include-Trybots: luci.skia.skia.primary:Test-Android-Clang-GalaxyS20-GPU-MaliG77-arm64-Release-All-Android_NativeFonts,Test-Debian10-Clang-GCE-CPU-AVX2-x86_64-Debug-All-NativeFonts
Bug: skia:12822, chromium:1287162
Change-Id: I8b790e2a5c6c04487118306b4b38b1d77349431d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/494676
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Dominik Röttsches <drott@google.com>
diff --git a/gm/colrv1.cpp b/gm/colrv1.cpp
index 51fa770..0270cd8 100644
--- a/gm/colrv1.cpp
+++ b/gm/colrv1.cpp
@@ -92,7 +92,7 @@
                 SkASSERT(false);
                 break;
             case kColorFontsRepoGradients:
-                fEmojiFont.fGlyphs = {2, 5, 6, 7, 8};
+                fEmojiFont.fGlyphs = {2, 5, 6, 7, 8, 55};
                 break;
             case kColorFontsRepoScaling:
                 fEmojiFont.fGlyphs = {9, 10, 11, 12, 13, 14};
diff --git a/resources/fonts/more_samples-glyf_colr_1.ttf b/resources/fonts/more_samples-glyf_colr_1.ttf
index 55d4415..8f9ffde 100644
--- a/resources/fonts/more_samples-glyf_colr_1.ttf
+++ b/resources/fonts/more_samples-glyf_colr_1.ttf
Binary files differ
diff --git a/src/ports/SkFontHost_FreeType_common.cpp b/src/ports/SkFontHost_FreeType_common.cpp
index a9868d1..db5dd28 100644
--- a/src/ports/SkFontHost_FreeType_common.cpp
+++ b/src/ports/SkFontHost_FreeType_common.cpp
@@ -594,11 +594,12 @@
 
             // Follow implementation note in nanoemoji:
             // https://github.com/googlefonts/nanoemoji/blob/0ac6e7bb4d8202db692574d8530a9b643f1b3b3c/src/nanoemoji/svg.py#L188
-            // to compute a new gradient end point as the orthogonal projection of the vector from p0 to p1 onto a line
-            // perpendicular to line p0p2 and passing through p0.
+            // to compute a new gradient end point P3 as the orthogonal
+            // projection of the vector from p0 to p1 onto a line perpendicular
+            // to line p0p2 and passing through p0.
             SkVector perpendicular_to_p2_p0 = (p2 - p0);
             perpendicular_to_p2_p0 = SkPoint::Make(perpendicular_to_p2_p0.y(), -perpendicular_to_p2_p0.x());
-            line_positions[1] = p0 + SkVectorProjection((p1 - p0), perpendicular_to_p2_p0);
+            SkVector p3 = p0 + SkVectorProjection((p1 - p0), perpendicular_to_p2_p0);
 
             std::vector<SkScalar> stops;
             std::vector<SkColor> colors;
@@ -613,15 +614,15 @@
                 break;
             }
 
-            // Project/scale points according to stop extrema along p0p1 line,
-            // then scale stops to to [0, 1] range so that repeat modes work.
-            // The Skia linear gradient shader performs the repeat modes over
-            // the 0 to 1 range, that's why we need to scale the stops to within
-            // that range.
-            SkVector p0p1 = p1 - p0;
-            SkVector new_p0_offset = p0p1;
+            // Project/scale points according to stop extrema along p0p3 line,
+            // p3 being the result of the projection above, then scale stops to
+            // to [0, 1] range so that repeat modes work.  The Skia linear
+            // gradient shader performs the repeat modes over the 0 to 1 range,
+            // that's why we need to scale the stops to within that range.
+            SkVector p0p3 = p3 - p0;
+            SkVector new_p0_offset = p0p3;
             new_p0_offset.scale(stops.front());
-            SkVector new_p1_offset = p0p1;
+            SkVector new_p1_offset = p0p3;
             new_p1_offset.scale(stops.back());
 
             line_positions[0] = p0 + new_p0_offset;