| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Resources.h" | 8 #include "Resources.h" |
| 9 #include "SkCommandLineFlags.h" |
| 9 #include "SkFontConfigParser_android.h" | 10 #include "SkFontConfigParser_android.h" |
| 10 #include "Test.h" | 11 #include "Test.h" |
| 11 | 12 |
| 13 DECLARE_bool(verboseFontMgr); |
| 14 |
| 12 int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) { | 15 int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) { |
| 13 int countOfFallbackFonts = 0; | 16 int countOfFallbackFonts = 0; |
| 14 for (int i = 0; i < fontFamilies.count(); i++) { | 17 for (int i = 0; i < fontFamilies.count(); i++) { |
| 15 if (fontFamilies[i]->fIsFallbackFont) { | 18 if (fontFamilies[i]->fIsFallbackFont) { |
| 16 countOfFallbackFonts++; | 19 countOfFallbackFonts++; |
| 17 } | 20 } |
| 18 } | 21 } |
| 19 return countOfFallbackFonts; | 22 return countOfFallbackFonts; |
| 20 } | 23 } |
| 21 | 24 |
| 22 void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* firstE
xpectedFile, | 25 void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* firstE
xpectedFile, |
| 23 skiatest::Reporter* reporter) { | 26 skiatest::Reporter* reporter) { |
| 24 REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5); | 27 REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5); |
| 25 REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fNames[0].c_str(), "sans-
serif")); | 28 REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fNames[0].c_str(), "sans-
serif")); |
| 26 REPORTER_ASSERT(reporter, | 29 REPORTER_ASSERT(reporter, |
| 27 !strcmp(fontFamilies[0]->fFonts[0].fFileName.c_str(), firstE
xpectedFile)); | 30 !strcmp(fontFamilies[0]->fFonts[0].fFileName.c_str(), firstE
xpectedFile)); |
| 28 REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont); | 31 REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont); |
| 29 } | 32 } |
| 30 | 33 |
| 31 void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) { | 34 void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) { |
| 32 #if SK_DEBUG_FONTS | 35 if (!FLAGS_verboseFontMgr) { |
| 36 return; |
| 37 } |
| 38 |
| 33 for (int i = 0; i < fontFamilies.count(); ++i) { | 39 for (int i = 0; i < fontFamilies.count(); ++i) { |
| 34 SkDebugf("Family %d:\n", i); | 40 SkDebugf("Family %d:\n", i); |
| 35 switch(fontFamilies[i]->fVariant) { | 41 switch(fontFamilies[i]->fVariant) { |
| 36 case kElegant_FontVariant: SkDebugf(" elegant\n"); break; | 42 case kElegant_FontVariant: SkDebugf(" elegant\n"); break; |
| 37 case kCompact_FontVariant: SkDebugf(" compact\n"); break; | 43 case kCompact_FontVariant: SkDebugf(" compact\n"); break; |
| 38 default: break; | 44 default: break; |
| 39 } | 45 } |
| 40 if (fontFamilies[i]->fBasePath) { | 46 SkDebugf(" basePath %s\n", fontFamilies[i]->fBasePath.c_str()); |
| 41 SkDebugf(" basePath %s\n", fontFamilies[i]->fBasePath); | |
| 42 } | |
| 43 if (!fontFamilies[i]->fLanguage.getTag().isEmpty()) { | 47 if (!fontFamilies[i]->fLanguage.getTag().isEmpty()) { |
| 44 SkDebugf(" language %s\n", fontFamilies[i]->fLanguage.getTag().c_st
r()); | 48 SkDebugf(" language %s\n", fontFamilies[i]->fLanguage.getTag().c_st
r()); |
| 45 } | 49 } |
| 46 for (int j = 0; j < fontFamilies[i]->fNames.count(); ++j) { | 50 for (int j = 0; j < fontFamilies[i]->fNames.count(); ++j) { |
| 47 SkDebugf(" name %s\n", fontFamilies[i]->fNames[j].c_str()); | 51 SkDebugf(" name %s\n", fontFamilies[i]->fNames[j].c_str()); |
| 48 } | 52 } |
| 49 for (int j = 0; j < fontFamilies[i]->fFonts.count(); ++j) { | 53 for (int j = 0; j < fontFamilies[i]->fFonts.count(); ++j) { |
| 50 const FontFileInfo& ffi = fontFamilies[i]->fFonts[j]; | 54 const FontFileInfo& ffi = fontFamilies[i]->fFonts[j]; |
| 51 SkDebugf(" file (%d) %s#%d\n", ffi.fWeight, ffi.fFileName.c_str(),
ffi.fIndex); | 55 SkDebugf(" file (%d) %s#%d\n", ffi.fWeight, ffi.fFileName.c_str(),
ffi.fIndex); |
| 52 } | 56 } |
| 53 } | 57 } |
| 54 #endif // SK_DEBUG_FONTS | |
| 55 } | 58 } |
| 56 | 59 |
| 57 DEF_TEST(FontConfigParserAndroid, reporter) { | 60 DEF_TEST(FontConfigParserAndroid, reporter) { |
| 58 | 61 |
| 59 bool resourcesMissing = false; | 62 bool resourcesMissing = false; |
| 60 | 63 |
| 61 SkTDArray<FontFamily*> preV17FontFamilies; | 64 SkTDArray<FontFamily*> preV17FontFamilies; |
| 62 SkFontConfigParser::GetCustomFontFamilies(preV17FontFamilies, | 65 SkFontConfigParser::GetCustomFontFamilies(preV17FontFamilies, |
| 63 SkString("/custom/font/path/"), | 66 SkString("/custom/font/path/"), |
| 64 GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(), | 67 GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 ValidateLoadedFonts(v22FontFamilies, "Roboto-Thin.ttf", reporter); | 109 ValidateLoadedFonts(v22FontFamilies, "Roboto-Thin.ttf", reporter); |
| 107 } else { | 110 } else { |
| 108 resourcesMissing = true; | 111 resourcesMissing = true; |
| 109 } | 112 } |
| 110 | 113 |
| 111 if (resourcesMissing) { | 114 if (resourcesMissing) { |
| 112 SkDebugf("---- Resource files missing for FontConfigParser test\n"); | 115 SkDebugf("---- Resource files missing for FontConfigParser test\n"); |
| 113 } | 116 } |
| 114 } | 117 } |
| 115 | 118 |
| OLD | NEW |