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"
|
|
|
|
#include "SkFontConfigParser_android.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) {
|
|
|
|
#if SK_DEBUG_FONTS
|
|
|
|
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) {
|
|
|
|
case SkPaintOptionsAndroid::kElegant_Variant: SkDebugf(" elegant"); break;
|
|
|
|
case SkPaintOptionsAndroid::kCompact_Variant: SkDebugf(" compact"); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
if (!fontFamilies[i]->fLanguage.getTag().isEmpty()) {
|
|
|
|
SkDebugf(" language: %s", fontFamilies[i]->fLanguage.getTag().c_str());
|
|
|
|
}
|
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];
|
2014-08-05 20:35:00 +00:00
|
|
|
SkDebugf(" file (%d %s %d) %s\n",
|
|
|
|
ffi.fWeight,
|
|
|
|
ffi.fPaintOptions.getLanguage().getTag().isEmpty() ? "" :
|
|
|
|
ffi.fPaintOptions.getLanguage().getTag().c_str(),
|
|
|
|
ffi.fPaintOptions.getFontVariant(),
|
|
|
|
ffi.fFileName.c_str());
|
|
|
|
}
|
2014-08-05 13:36:11 +00:00
|
|
|
}
|
|
|
|
#endif // SK_DEBUG_FONTS
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
SkFontConfigParser::GetTestFontFamilies(preV17FontFamilies,
|
|
|
|
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
|
|
|
|
2014-08-07 17:20:51 +00:00
|
|
|
DumpLoadedFonts(preV17FontFamilies);
|
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;
|
|
|
|
SkFontConfigParser::GetTestFontFamilies(v17FontFamilies,
|
|
|
|
GetResourcePath("android_fonts/v17/system_fonts.xml").c_str(),
|
|
|
|
GetResourcePath("android_fonts/v17/fallback_fonts.xml").c_str());
|
|
|
|
|
2014-08-07 17:20:51 +00:00
|
|
|
if (v17FontFamilies.count() > 0) {
|
|
|
|
REPORTER_ASSERT(reporter, v17FontFamilies.count() == 41);
|
2014-08-13 14:53:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, CountFallbacks(v17FontFamilies) == 31);
|
2014-08-05 13:36:11 +00:00
|
|
|
|
2014-08-07 17:20:51 +00:00
|
|
|
DumpLoadedFonts(v17FontFamilies);
|
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;
|
|
|
|
SkFontConfigParser::GetTestFontFamilies(v22FontFamilies,
|
|
|
|
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
|
|
|
|
2014-08-07 17:20:51 +00:00
|
|
|
DumpLoadedFonts(v22FontFamilies);
|
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
|
|
|
}
|
|
|
|
|