2014-08-05 13:36:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Resources.h"
|
2018-06-20 20:43:02 +00:00
|
|
|
#include "SkCanvas.h"
|
2015-02-10 15:51:12 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
2016-04-07 15:49:31 +00:00
|
|
|
#include "SkFixed.h"
|
2017-11-13 16:14:36 +00:00
|
|
|
#include "SkFontMgr_android.h"
|
2015-06-23 20:25:46 +00:00
|
|
|
#include "SkFontMgr_android_parser.h"
|
2017-12-08 18:35:47 +00:00
|
|
|
#include "SkOSFile.h"
|
2017-11-13 16:14:36 +00:00
|
|
|
#include "SkTypeface.h"
|
2014-08-05 13:36:11 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
2015-05-20 16:21:04 +00:00
|
|
|
#include <cmath>
|
|
|
|
#include <cstdio>
|
|
|
|
|
2015-02-10 15:51:12 +00:00
|
|
|
DECLARE_bool(verboseFontMgr);
|
|
|
|
|
2014-08-13 14:53:48 +00:00
|
|
|
int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) {
|
|
|
|
int countOfFallbackFonts = 0;
|
|
|
|
for (int i = 0; i < fontFamilies.count(); i++) {
|
|
|
|
if (fontFamilies[i]->fIsFallbackFont) {
|
|
|
|
countOfFallbackFonts++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return countOfFallbackFonts;
|
|
|
|
}
|
|
|
|
|
2015-02-11 15:18:51 +00:00
|
|
|
//https://tools.ietf.org/html/rfc5234#appendix-B.1
|
|
|
|
static bool isALPHA(int c) {
|
|
|
|
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
|
|
|
|
}
|
|
|
|
|
|
|
|
//https://tools.ietf.org/html/rfc5234#appendix-B.1
|
|
|
|
static bool isDIGIT(int c) {
|
|
|
|
return ('0' <= c && c <= '9');
|
|
|
|
}
|
|
|
|
|
2018-11-15 22:14:41 +00:00
|
|
|
static void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* firstExpectedFile,
|
|
|
|
skiatest::Reporter* reporter) {
|
2014-08-05 13:36:11 +00:00
|
|
|
REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5);
|
|
|
|
REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fNames[0].c_str(), "sans-serif"));
|
|
|
|
REPORTER_ASSERT(reporter,
|
2014-11-04 18:54:31 +00:00
|
|
|
!strcmp(fontFamilies[0]->fFonts[0].fFileName.c_str(), firstExpectedFile));
|
2014-08-05 13:36:11 +00:00
|
|
|
REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont);
|
2015-02-11 15:18:51 +00:00
|
|
|
|
|
|
|
// Check that the languages are all sane.
|
2017-08-10 17:49:41 +00:00
|
|
|
for (const auto& fontFamily : fontFamilies) {
|
|
|
|
for (const auto& lang : fontFamily->fLanguages) {
|
|
|
|
const SkString& langString = lang.getTag();
|
|
|
|
for (size_t i = 0; i < langString.size(); ++i) {
|
|
|
|
int c = langString[i];
|
|
|
|
REPORTER_ASSERT(reporter, isALPHA(c) || isDIGIT(c) || '-' == c);
|
|
|
|
}
|
2015-02-11 15:18:51 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-13 16:55:16 +00:00
|
|
|
|
|
|
|
// All file names in the test configuration files start with a capital letter.
|
|
|
|
// This is not a general requirement, but it is true of all the test configuration data.
|
|
|
|
// Verifying ensures the filenames have been read sanely and have not been 'sliced'.
|
|
|
|
for (int i = 0; i < fontFamilies.count(); ++i) {
|
|
|
|
FontFamily& family = *fontFamilies[i];
|
|
|
|
for (int j = 0; j < family.fFonts.count(); ++j) {
|
|
|
|
FontFileInfo& file = family.fFonts[j];
|
|
|
|
REPORTER_ASSERT(reporter, !file.fFileName.isEmpty() &&
|
|
|
|
file.fFileName[0] >= 'A' &&
|
|
|
|
file.fFileName[0] <= 'Z');
|
|
|
|
}
|
|
|
|
}
|
2014-08-05 13:36:11 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 22:14:41 +00:00
|
|
|
static void DumpFiles(const FontFamily& fontFamily) {
|
|
|
|
for (int j = 0; j < fontFamily.fFonts.count(); ++j) {
|
|
|
|
const FontFileInfo& ffi = fontFamily.fFonts[j];
|
|
|
|
SkDebugf(" file (%d) %s#%d", ffi.fWeight, ffi.fFileName.c_str(), ffi.fIndex);
|
|
|
|
for (const auto& coordinate : ffi.fVariationDesignPosition) {
|
|
|
|
SkDebugf(" @'%c%c%c%c'=%f",
|
|
|
|
(coordinate.axis >> 24) & 0xFF,
|
|
|
|
(coordinate.axis >> 16) & 0xFF,
|
|
|
|
(coordinate.axis >> 8) & 0xFF,
|
|
|
|
(coordinate.axis ) & 0xFF,
|
|
|
|
coordinate.value);
|
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* label) {
|
2015-02-10 15:51:12 +00:00
|
|
|
if (!FLAGS_verboseFontMgr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-14 02:30:11 +00:00
|
|
|
SkDebugf("\n--- Dumping %s\n", label);
|
2014-08-05 13:36:11 +00:00
|
|
|
for (int i = 0; i < fontFamilies.count(); ++i) {
|
|
|
|
SkDebugf("Family %d:\n", i);
|
2014-08-05 20:35:00 +00:00
|
|
|
switch(fontFamilies[i]->fVariant) {
|
2015-01-31 03:58:19 +00:00
|
|
|
case kElegant_FontVariant: SkDebugf(" elegant\n"); break;
|
|
|
|
case kCompact_FontVariant: SkDebugf(" compact\n"); break;
|
2014-08-05 20:35:00 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2015-02-10 15:51:12 +00:00
|
|
|
SkDebugf(" basePath %s\n", fontFamilies[i]->fBasePath.c_str());
|
2017-08-10 17:49:41 +00:00
|
|
|
if (!fontFamilies[i]->fLanguages.empty()) {
|
|
|
|
SkDebugf(" language");
|
|
|
|
for (const auto& lang : fontFamilies[i]->fLanguages) {
|
|
|
|
SkDebugf(" %s", lang.getTag().c_str());
|
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
2014-08-05 20:35:00 +00:00
|
|
|
}
|
2014-08-05 13:36:11 +00:00
|
|
|
for (int j = 0; j < fontFamilies[i]->fNames.count(); ++j) {
|
|
|
|
SkDebugf(" name %s\n", fontFamilies[i]->fNames[j].c_str());
|
|
|
|
}
|
2018-11-15 22:14:41 +00:00
|
|
|
DumpFiles(*fontFamilies[i]);
|
|
|
|
fontFamilies[i]->fallbackFamilies.foreach(
|
|
|
|
[](SkString, std::unique_ptr<FontFamily>* fallbackFamily) {
|
|
|
|
SkDebugf(" Fallback for: %s\n", (*fallbackFamily)->fFallbackFor.c_str());
|
|
|
|
DumpFiles(*(*fallbackFamily).get());
|
2016-02-25 19:20:01 +00:00
|
|
|
}
|
2018-11-15 22:14:41 +00:00
|
|
|
);
|
2014-08-05 13:36:11 +00:00
|
|
|
}
|
2015-02-11 15:18:51 +00:00
|
|
|
SkDebugf("\n\n");
|
2014-08-05 13:36:11 +00:00
|
|
|
}
|
|
|
|
|
2015-05-20 16:21:04 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2015-06-23 20:25:46 +00:00
|
|
|
DEF_TEST(FontMgrAndroidParser, reporter) {
|
2015-05-20 16:21:04 +00:00
|
|
|
test_parse_fixed(reporter);
|
2014-08-05 13:36:11 +00:00
|
|
|
|
2014-08-07 17:20:51 +00:00
|
|
|
bool resourcesMissing = false;
|
|
|
|
|
2014-08-05 13:36:11 +00:00
|
|
|
SkTDArray<FontFamily*> preV17FontFamilies;
|
2015-06-23 20:25:46 +00:00
|
|
|
SkFontMgr_Android_Parser::GetCustomFontFamilies(preV17FontFamilies,
|
2015-02-06 15:59:19 +00:00
|
|
|
SkString("/custom/font/path/"),
|
2014-08-05 13:36:11 +00:00
|
|
|
GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(),
|
|
|
|
GetResourcePath("android_fonts/pre_v17/fallback_fonts.xml").c_str());
|
|
|
|
|
2014-08-07 17:20:51 +00:00
|
|
|
if (preV17FontFamilies.count() > 0) {
|
|
|
|
REPORTER_ASSERT(reporter, preV17FontFamilies.count() == 14);
|
2014-08-13 14:53:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, CountFallbacks(preV17FontFamilies) == 10);
|
2014-08-05 13:36:11 +00:00
|
|
|
|
2015-02-14 02:30:11 +00:00
|
|
|
DumpLoadedFonts(preV17FontFamilies, "pre version 17");
|
2014-11-04 18:54:31 +00:00
|
|
|
ValidateLoadedFonts(preV17FontFamilies, "Roboto-Regular.ttf", reporter);
|
2014-08-07 17:20:51 +00:00
|
|
|
} else {
|
|
|
|
resourcesMissing = true;
|
|
|
|
}
|
2015-07-15 18:29:25 +00:00
|
|
|
preV17FontFamilies.deleteAll();
|
2014-08-05 13:36:11 +00:00
|
|
|
|
2014-08-05 20:35:00 +00:00
|
|
|
|
2014-08-05 13:36:11 +00:00
|
|
|
SkTDArray<FontFamily*> v17FontFamilies;
|
2015-06-23 20:25:46 +00:00
|
|
|
SkFontMgr_Android_Parser::GetCustomFontFamilies(v17FontFamilies,
|
2015-02-06 15:59:19 +00:00
|
|
|
SkString("/custom/font/path/"),
|
2014-08-05 13:36:11 +00:00
|
|
|
GetResourcePath("android_fonts/v17/system_fonts.xml").c_str(),
|
2015-02-11 15:18:51 +00:00
|
|
|
GetResourcePath("android_fonts/v17/fallback_fonts.xml").c_str(),
|
|
|
|
GetResourcePath("android_fonts/v17").c_str());
|
2014-08-05 13:36:11 +00:00
|
|
|
|
2014-08-07 17:20:51 +00:00
|
|
|
if (v17FontFamilies.count() > 0) {
|
2015-02-11 15:18:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, v17FontFamilies.count() == 56);
|
|
|
|
REPORTER_ASSERT(reporter, CountFallbacks(v17FontFamilies) == 46);
|
2014-08-05 13:36:11 +00:00
|
|
|
|
2015-02-14 02:30:11 +00:00
|
|
|
DumpLoadedFonts(v17FontFamilies, "version 17");
|
2014-11-04 18:54:31 +00:00
|
|
|
ValidateLoadedFonts(v17FontFamilies, "Roboto-Regular.ttf", reporter);
|
2014-08-07 17:20:51 +00:00
|
|
|
} else {
|
|
|
|
resourcesMissing = true;
|
|
|
|
}
|
2015-07-15 18:29:25 +00:00
|
|
|
v17FontFamilies.deleteAll();
|
2014-08-05 13:36:11 +00:00
|
|
|
|
2014-08-05 20:35:00 +00:00
|
|
|
|
2014-08-05 13:36:11 +00:00
|
|
|
SkTDArray<FontFamily*> v22FontFamilies;
|
2015-06-23 20:25:46 +00:00
|
|
|
SkFontMgr_Android_Parser::GetCustomFontFamilies(v22FontFamilies,
|
2015-02-06 15:59:19 +00:00
|
|
|
SkString("/custom/font/path/"),
|
2014-08-05 13:36:11 +00:00
|
|
|
GetResourcePath("android_fonts/v22/fonts.xml").c_str(),
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr);
|
2014-08-05 13:36:11 +00:00
|
|
|
|
2014-08-07 17:20:51 +00:00
|
|
|
if (v22FontFamilies.count() > 0) {
|
2015-05-20 16:21:04 +00:00
|
|
|
REPORTER_ASSERT(reporter, v22FontFamilies.count() == 54);
|
2014-08-13 14:53:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, CountFallbacks(v22FontFamilies) == 42);
|
2014-08-05 13:36:11 +00:00
|
|
|
|
2015-02-14 02:30:11 +00:00
|
|
|
DumpLoadedFonts(v22FontFamilies, "version 22");
|
2014-11-04 18:54:31 +00:00
|
|
|
ValidateLoadedFonts(v22FontFamilies, "Roboto-Thin.ttf", reporter);
|
2014-08-07 17:20:51 +00:00
|
|
|
} else {
|
|
|
|
resourcesMissing = true;
|
|
|
|
}
|
2015-07-15 18:29:25 +00:00
|
|
|
v22FontFamilies.deleteAll();
|
2014-08-07 17:20:51 +00:00
|
|
|
|
|
|
|
if (resourcesMissing) {
|
|
|
|
SkDebugf("---- Resource files missing for FontConfigParser test\n");
|
|
|
|
}
|
2014-08-05 13:36:11 +00:00
|
|
|
}
|
2017-11-13 16:14:36 +00:00
|
|
|
|
|
|
|
DEF_TEST(FontMgrAndroidLegacyMakeTypeface, reporter) {
|
2017-12-08 18:35:47 +00:00
|
|
|
constexpr char fontsXmlFilename[] = "fonts/fonts.xml";
|
2017-11-13 16:14:36 +00:00
|
|
|
SkString basePath = GetResourcePath("fonts/");
|
2017-12-08 18:35:47 +00:00
|
|
|
SkString fontsXml = GetResourcePath(fontsXmlFilename);
|
|
|
|
|
|
|
|
if (!sk_exists(fontsXml.c_str())) {
|
|
|
|
ERRORF(reporter, "file missing: %s\n", fontsXmlFilename);
|
|
|
|
return;
|
|
|
|
}
|
2017-11-13 16:14:36 +00:00
|
|
|
|
|
|
|
SkFontMgr_Android_CustomFonts custom;
|
|
|
|
custom.fSystemFontUse = SkFontMgr_Android_CustomFonts::kOnlyCustom;
|
|
|
|
custom.fBasePath = basePath.c_str();
|
|
|
|
custom.fFontsXml = fontsXml.c_str();
|
|
|
|
custom.fFallbackFontsXml = nullptr;
|
|
|
|
custom.fIsolated = false;
|
|
|
|
|
|
|
|
sk_sp<SkFontMgr> fm(SkFontMgr_New_Android(&custom));
|
|
|
|
sk_sp<SkTypeface> t(fm->legacyMakeTypeface("non-existent-font", SkFontStyle()));
|
|
|
|
REPORTER_ASSERT(reporter, nullptr == t);
|
|
|
|
}
|
2018-06-20 20:43:02 +00:00
|
|
|
|
|
|
|
static bool bitmap_compare(const SkBitmap& ref, const SkBitmap& test) {
|
|
|
|
for (int y = 0; y < test.height(); ++y) {
|
|
|
|
for (int x = 0; x < test.width(); ++x) {
|
|
|
|
SkColor testColor = test.getColor(x, y);
|
|
|
|
SkColor refColor = ref.getColor(x, y);
|
|
|
|
if (refColor != testColor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(FontMgrAndroidSystemVariableTypeface, reporter) {
|
|
|
|
constexpr char fontsXmlFilename[] = "fonts/fonts.xml";
|
|
|
|
SkString basePath = GetResourcePath("fonts/");
|
|
|
|
SkString fontsXml = GetResourcePath(fontsXmlFilename);
|
|
|
|
|
|
|
|
if (!sk_exists(fontsXml.c_str())) {
|
|
|
|
ERRORF(reporter, "file missing: %s\n", fontsXmlFilename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkFontMgr_Android_CustomFonts custom;
|
|
|
|
custom.fSystemFontUse = SkFontMgr_Android_CustomFonts::kOnlyCustom;
|
|
|
|
custom.fBasePath = basePath.c_str();
|
|
|
|
custom.fFontsXml = fontsXml.c_str();
|
|
|
|
custom.fFallbackFontsXml = nullptr;
|
|
|
|
custom.fIsolated = false;
|
|
|
|
|
|
|
|
sk_sp<SkFontMgr> fontMgr(SkFontMgr_New_Android(&custom));
|
|
|
|
// "sans-serif" in "fonts/fonts.xml" is "fonts/Distortable.ttf"
|
|
|
|
sk_sp<SkTypeface> typeface(fontMgr->legacyMakeTypeface("sans-serif", SkFontStyle()));
|
|
|
|
|
|
|
|
SkBitmap bitmapStream;
|
|
|
|
bitmapStream.allocN32Pixels(64, 64);
|
|
|
|
SkCanvas canvasStream(bitmapStream);
|
|
|
|
canvasStream.drawColor(SK_ColorWHITE);
|
|
|
|
|
|
|
|
SkBitmap bitmapClone;
|
|
|
|
bitmapClone.allocN32Pixels(64, 64);
|
|
|
|
SkCanvas canvasClone(bitmapClone);
|
|
|
|
canvasStream.drawColor(SK_ColorWHITE);
|
|
|
|
|
|
|
|
SkPaint paintStream;
|
|
|
|
paintStream.setColor(SK_ColorGRAY);
|
|
|
|
paintStream.setTextSize(SkIntToScalar(20));
|
|
|
|
paintStream.setAntiAlias(true);
|
|
|
|
paintStream.setLCDRenderText(true);
|
|
|
|
|
|
|
|
SkPaint paintClone;
|
|
|
|
paintClone.setColor(SK_ColorGRAY);
|
|
|
|
paintClone.setTextSize(SkIntToScalar(20));
|
|
|
|
paintClone.setAntiAlias(true);
|
|
|
|
paintClone.setLCDRenderText(true);
|
|
|
|
|
|
|
|
std::unique_ptr<SkStreamAsset> distortableStream(
|
|
|
|
GetResourceAsStream("fonts/Distortable.ttf"));
|
|
|
|
if (!distortableStream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* text = "abc";
|
|
|
|
const size_t textLen = strlen(text);
|
|
|
|
SkPoint point = SkPoint::Make(20.0f, 20.0f);
|
|
|
|
SkFourByteTag tag = SkSetFourByteTag('w', 'g', 'h', 't');
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
SkScalar styleValue =
|
|
|
|
SkDoubleToScalar(0.5 + i * ((2.0 - 0.5) / 10));
|
|
|
|
SkFontArguments::VariationPosition::Coordinate
|
|
|
|
coordinates[] = {{tag, styleValue}};
|
|
|
|
SkFontArguments::VariationPosition
|
|
|
|
position = {coordinates, SK_ARRAY_COUNT(coordinates)};
|
|
|
|
|
|
|
|
paintStream.setTypeface(sk_sp<SkTypeface>(
|
|
|
|
fontMgr->makeFromStream(distortableStream->duplicate(),
|
|
|
|
SkFontArguments().setVariationDesignPosition(position))));
|
|
|
|
|
|
|
|
paintClone.setTypeface(sk_sp<SkTypeface>(
|
|
|
|
typeface->makeClone(SkFontArguments().setVariationDesignPosition(position))));
|
|
|
|
|
|
|
|
canvasStream.drawColor(SK_ColorWHITE);
|
|
|
|
canvasStream.drawText(text, textLen, point.fX, point.fY, paintStream);
|
|
|
|
|
|
|
|
canvasClone.drawColor(SK_ColorWHITE);
|
|
|
|
canvasClone.drawText(text, textLen, point.fX, point.fY, paintClone);
|
|
|
|
|
|
|
|
bool success = bitmap_compare(bitmapStream, bitmapClone);
|
|
|
|
REPORTER_ASSERT(reporter, success);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 22:14:41 +00:00
|
|
|
DEF_TEST(FontMgrAndroidSystemFallbackFor, reporter) {
|
|
|
|
constexpr char fontsXmlFilename[] = "fonts/fonts.xml";
|
|
|
|
SkString basePath = GetResourcePath("fonts/");
|
|
|
|
SkString fontsXml = GetResourcePath(fontsXmlFilename);
|
|
|
|
|
|
|
|
if (!sk_exists(fontsXml.c_str())) {
|
|
|
|
ERRORF(reporter, "file missing: %s\n", fontsXmlFilename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkFontMgr_Android_CustomFonts custom;
|
|
|
|
custom.fSystemFontUse = SkFontMgr_Android_CustomFonts::kOnlyCustom;
|
|
|
|
custom.fBasePath = basePath.c_str();
|
|
|
|
custom.fFontsXml = fontsXml.c_str();
|
|
|
|
custom.fFallbackFontsXml = nullptr;
|
|
|
|
custom.fIsolated = false;
|
|
|
|
|
|
|
|
sk_sp<SkFontMgr> fontMgr(SkFontMgr_New_Android(&custom));
|
|
|
|
// "sans-serif" in "fonts/fonts.xml" is "fonts/Distortable.ttf", which doesn't have a '!'
|
|
|
|
// but "TestTTC" has a bold font which does have '!' and is marked as fallback for "sans-serif"
|
|
|
|
// and should take precedence over the same font marked as normal weight next to it.
|
|
|
|
sk_sp<SkTypeface> typeface(fontMgr->matchFamilyStyleCharacter(
|
|
|
|
"sans-serif", SkFontStyle(), nullptr, 0, '!'));
|
2018-06-20 20:43:02 +00:00
|
|
|
|
2018-11-15 22:14:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, typeface->fontStyle() == SkFontStyle::Bold());
|
|
|
|
}
|