diff options
author | 2015-05-13 10:57:09 -0700 | |
---|---|---|
committer | 2015-05-13 10:57:10 -0700 | |
commit | 05773ed30920c0214d1433c07cf6360a05476c97 (patch) | |
tree | 5da7ade81a22ca07b2018f42b111bc861bf1edcd /tests/SerializationTest.cpp | |
parent | c5f1c5414fc8f73cbefadcc1b24ec794056fa203 (diff) |
Font variations.
Multiple Master and TrueType fonts support variation axes.
This implements back-end support for axes on platforms which
support it.
Review URL: https://codereview.chromium.org/1027373002
Diffstat (limited to 'tests/SerializationTest.cpp')
-rw-r--r-- | tests/SerializationTest.cpp | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp index f7e298305f..31dbbe8ad9 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); } |