Index: tests/SerializationTest.cpp |
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp |
index f7e298305f86fc5741b7d07422485785c95dbbe1..31dbbe8ad93c00af466b4c3f8a632c44121d5284 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 @@ static void compare_bitmaps(skiatest::Reporter* reporter, |
} |
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 @@ static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) { |
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 @@ static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) { |
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); |
} |