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"
|
2015-02-10 15:51:12 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
2014-08-05 13:36:11 +00:00
|
|
|
#include "SkFontConfigParser_android.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2014-11-04 18:54:31 +00:00
|
|
|
void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* firstExpectedFile,
|
2014-08-05 13:36:11 +00:00
|
|
|
skiatest::Reporter* reporter) {
|
|
|
|
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.
|
|
|
|
for (int i = 0; i < fontFamilies.count(); ++i) {
|
|
|
|
const SkString& lang = fontFamilies[i]->fLanguage.getTag();
|
|
|
|
for (size_t j = 0; j < lang.size(); ++j) {
|
|
|
|
int c = lang[j];
|
|
|
|
REPORTER_ASSERT(reporter, isALPHA(c) || isDIGIT(c) || '-' == c);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2015-02-14 02:30:11 +00:00
|
|
|
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());
|
2014-08-05 20:35:00 +00:00
|
|
|
if (!fontFamilies[i]->fLanguage.getTag().isEmpty()) {
|
2015-01-31 03:58:19 +00:00
|
|
|
SkDebugf(" language %s\n", fontFamilies[i]->fLanguage.getTag().c_str());
|
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());
|
|
|
|
}
|
2014-08-11 18:28:00 +00:00
|
|
|
for (int j = 0; j < fontFamilies[i]->fFonts.count(); ++j) {
|
|
|
|
const FontFileInfo& ffi = fontFamilies[i]->fFonts[j];
|
2015-01-31 03:58:19 +00:00
|
|
|
SkDebugf(" file (%d) %s#%d\n", ffi.fWeight, ffi.fFileName.c_str(), ffi.fIndex);
|
2014-08-05 20:35:00 +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
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(FontConfigParserAndroid, reporter) {
|
|
|
|
|
2014-08-07 17:20:51 +00:00
|
|
|
bool resourcesMissing = false;
|
|
|
|
|
2014-08-05 13:36:11 +00:00
|
|
|
SkTDArray<FontFamily*> preV17FontFamilies;
|
2015-02-06 15:59:19 +00:00
|
|
|
SkFontConfigParser::GetCustomFontFamilies(preV17FontFamilies,
|
|
|
|
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;
|
|
|
|
}
|
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-02-06 15:59:19 +00:00
|
|
|
SkFontConfigParser::GetCustomFontFamilies(v17FontFamilies,
|
|
|
|
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;
|
|
|
|
}
|
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-02-06 15:59:19 +00:00
|
|
|
SkFontConfigParser::GetCustomFontFamilies(v22FontFamilies,
|
|
|
|
SkString("/custom/font/path/"),
|
2014-08-05 13:36:11 +00:00
|
|
|
GetResourcePath("android_fonts/v22/fonts.xml").c_str(),
|
|
|
|
NULL);
|
|
|
|
|
2014-08-07 17:20:51 +00:00
|
|
|
if (v22FontFamilies.count() > 0) {
|
|
|
|
REPORTER_ASSERT(reporter, v22FontFamilies.count() == 53);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resourcesMissing) {
|
|
|
|
SkDebugf("---- Resource files missing for FontConfigParser test\n");
|
|
|
|
}
|
2014-08-05 13:36:11 +00:00
|
|
|
}
|
|
|
|
|