diff options
author | bungeman <bungeman@google.com> | 2015-05-20 09:21:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-20 09:21:04 -0700 |
commit | 41868fe5625fc3bd70daa3f461c881b5db6a9265 (patch) | |
tree | 6f6d670bbf415a70c152b0a6332a0428fb0d77b4 /tests | |
parent | d223eb36a0be2bb5a278a483d6289a16b28eaf1a (diff) |
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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/FontConfigParser.cpp | 53 | ||||
-rw-r--r-- | tests/SerializationTest.cpp | 51 |
2 files changed, 90 insertions, 14 deletions
diff --git a/tests/FontConfigParser.cpp b/tests/FontConfigParser.cpp index e58d35c625..218aa9a09a 100644 --- a/tests/FontConfigParser.cpp +++ b/tests/FontConfigParser.cpp @@ -10,6 +10,9 @@ #include "SkFontConfigParser_android.h" #include "Test.h" +#include <cmath> +#include <cstdio> + DECLARE_bool(verboseFontMgr); int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) { @@ -91,7 +94,55 @@ void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* label) { SkDebugf("\n\n"); } +template <int N, typename T> static double test_parse_fixed_r(skiatest::Reporter* reporter, + double low, double high, double inc) +{ + double SK_FixedMax_double = nextafter(1 << (sizeof(T) * CHAR_BIT - N - 1), 0.0); + double SK_FixedEpsilon_double = (1.0 / (1 << N)); + double maxError = 0; + char buffer[64]; + for (double f = low; f < high; f += inc) { + SkString s; + // 'sprintf' formatting as expected depends on the current locale being "C". + // We currently expect tests and tools to run in the "C" locale. + sprintf(buffer, "%.20f", f); + T fix; + bool b = parse_fixed<N>(buffer, &fix); + if (b) { + double f2 = fix * SK_FixedEpsilon_double; + double error = fabs(f - f2); + REPORTER_ASSERT(reporter, error <= SK_FixedEpsilon_double); + maxError = SkTMax(maxError, error); + } else { + REPORTER_ASSERT(reporter, f < -SK_FixedMax_double || SK_FixedMax_double < f); + } + } + + //SkDebugf("maxError: %.20f\n", maxError); + return maxError; +} + +static void test_parse_fixed(skiatest::Reporter* reporter) { + test_parse_fixed_r<27, int32_t>(reporter, -8.1, -7.9, 0.000001); + test_parse_fixed_r<27, int32_t>(reporter, -0.1, 0.1, 0.000001); + test_parse_fixed_r<27, int32_t>(reporter, 7.9, 8.1, 0.000001); + test_parse_fixed_r<16, int32_t>(reporter, -0.125, 0.125, 1.0 / (1 << 19)); + test_parse_fixed_r<16, int32_t>(reporter, -32768.125, -32766.875, 1.0 / (1 << 17)); + test_parse_fixed_r<16, int32_t>(reporter, 32766.875, 32768.125, 1.0 / (1 << 17)); + test_parse_fixed_r<16, int32_t>(reporter, -1.1, 1.1, 0.0001); + + SkFixed fix; + REPORTER_ASSERT(reporter, !parse_fixed<27>("-17.1", &fix)); + REPORTER_ASSERT(reporter, !parse_fixed<16>("32768", &fix)); + REPORTER_ASSERT(reporter, !parse_fixed<16>("", &fix)); + REPORTER_ASSERT(reporter, !parse_fixed<16>(".", &fix)); + REPORTER_ASSERT(reporter, !parse_fixed<16>("123.", &fix)); + REPORTER_ASSERT(reporter, !parse_fixed<16>("a", &fix)); + REPORTER_ASSERT(reporter, !parse_fixed<16>(".123a", &fix)); +} + DEF_TEST(FontConfigParserAndroid, reporter) { + test_parse_fixed(reporter); bool resourcesMissing = false; @@ -137,7 +188,7 @@ DEF_TEST(FontConfigParserAndroid, reporter) { NULL); if (v22FontFamilies.count() > 0) { - REPORTER_ASSERT(reporter, v22FontFamilies.count() == 53); + REPORTER_ASSERT(reporter, v22FontFamilies.count() == 54); REPORTER_ASSERT(reporter, CountFallbacks(v22FontFamilies) == 42); DumpLoadedFonts(v22FontFamilies, "version 22"); 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); } |