Font variations.

Multiple Master and TrueType fonts support variation axes.
This implements back-end support for axes on platforms which
support it.

Committed: https://skia.googlesource.com/skia/+/05773ed30920c0214d1433c07cf6360a05476c97

Committed: https://skia.googlesource.com/skia/+/3489ee0f4fa34f124f9de090d12bdc2107d52aa9

Review URL: https://codereview.chromium.org/1027373002
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index f7e2983..31dbbe8 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -8,6 +8,8 @@
 #include "Resources.h"
 #include "SkBitmapSource.h"
 #include "SkCanvas.h"
+#include "SkFixed.h"
+#include "SkFontDescriptor.h"
 #include "SkMallocPixelRef.h"
 #include "SkOSFile.h"
 #include "SkPictureRecorder.h"
@@ -315,21 +317,14 @@
     }
     REPORTER_ASSERT(reporter, 0 == pixelErrors);
 }
-
-static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) {
-    // Load typeface form file to test CreateFromFile with index.
-    SkString filename = GetResourcePath("/fonts/test.ttc");
-    SkTypeface* typeface = SkTypeface::CreateFromFile(filename.c_str(), 1);
-    if (!typeface) {
-        SkDebugf("Could not run fontstream test because test.ttc not found.");
-        return;
-    }
-
-    // Create a paint with the typeface we loaded.
+static void serialize_and_compare_typeface(SkTypeface* typeface, const char* text,
+                                           skiatest::Reporter* reporter)
+{
+    // Create a paint with the typeface.
     SkPaint paint;
     paint.setColor(SK_ColorGRAY);
     paint.setTextSize(SkIntToScalar(30));
-    SkSafeUnref(paint.setTypeface(typeface));
+    paint.setTypeface(typeface);
 
     // Paint some text.
     SkPictureRecorder recorder;
@@ -338,7 +333,7 @@
                                                SkIntToScalar(canvasRect.height()), 
                                                NULL, 0);
     canvas->drawColor(SK_ColorWHITE);
-    canvas->drawText("A!", 2, 24, 32, paint);
+    canvas->drawText(text, 2, 24, 32, paint);
     SkAutoTUnref<SkPicture> picture(recorder.endRecording());
 
     // Serlialize picture and create its clone from stream.
@@ -353,6 +348,36 @@
     compare_bitmaps(reporter, origBitmap, destBitmap);
 }
 
+static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) {
+    {
+        // Load typeface from file to test CreateFromFile with index.
+        SkString filename = GetResourcePath("/fonts/test.ttc");
+        SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFile(filename.c_str(), 1));
+        if (!typeface) {
+            SkDebugf("Could not run fontstream test because test.ttc not found.");
+        } else {
+            serialize_and_compare_typeface(typeface, "A!", reporter);
+        }
+    }
+
+    {
+        // Load typeface as stream to create with axis settings.
+        SkAutoTDelete<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Distortable.ttf"));
+        if (!distortable) {
+            SkDebugf("Could not run fontstream test because Distortable.ttf not found.");
+        } else {
+            SkFixed axis = SK_FixedSqrt2;
+            SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFontData(
+                new SkFontData(distortable.detach(), 0, &axis, 1)));
+            if (!typeface) {
+                SkDebugf("Could not run fontstream test because Distortable.ttf not created.");
+            } else {
+                serialize_and_compare_typeface(typeface, "abc", reporter);
+            }
+        }
+    }
+}
+
 static void setup_bitmap_for_canvas(SkBitmap* bitmap) {
     bitmap->allocN32Pixels(kBitmapSize, kBitmapSize);
 }