reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Test.h" |
| 9 | |
| 10 | #include "SkCommandLineFlags.h" |
| 11 | #include "SkFontMgr.h" |
| 12 | #include "SkTypeface.h" |
| 13 | |
reed@google.com | d44d988 | 2013-09-18 20:32:25 +0000 | [diff] [blame^] | 14 | /* |
| 15 | * If the font backend is going to "alias" some font names to other fonts |
| 16 | * (e.g. sans -> Arial) then we want to at least get the same typeface back |
| 17 | * if we request the alias name multiple times. |
| 18 | */ |
| 19 | static void test_badnames(skiatest::Reporter* reporter) { |
| 20 | const char* inName = "sans"; |
| 21 | SkAutoTUnref<SkTypeface> first(SkTypeface::CreateFromName(inName, SkTypeface::kNormal)); |
| 22 | |
| 23 | SkString name; |
| 24 | for (int i = 0; i < 10; ++i) { |
| 25 | SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(inName, SkTypeface::kNormal)); |
| 26 | #if 0 |
| 27 | face->getFamilyName(&name); |
| 28 | printf("request %s, received %s, first id %x received %x\n", |
| 29 | inName, name.c_str(), first->uniqueID(), face->uniqueID()); |
| 30 | #endif |
| 31 | REPORTER_ASSERT(reporter, first->uniqueID() == face->uniqueID()); |
| 32 | } |
| 33 | } |
| 34 | |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 35 | static void test_fontiter(skiatest::Reporter* reporter, bool verbose) { |
| 36 | SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| 37 | int count = fm->countFamilies(); |
| 38 | |
| 39 | for (int i = 0; i < count; ++i) { |
| 40 | SkString fname; |
| 41 | fm->getFamilyName(i, &fname); |
| 42 | REPORTER_ASSERT(reporter, fname.size() > 0); |
| 43 | |
bungeman@google.com | 7103344 | 2013-05-01 14:21:20 +0000 | [diff] [blame] | 44 | SkAutoTUnref<SkFontStyleSet> fnset(fm->matchFamily(fname.c_str())); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 45 | SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); |
bungeman@google.com | 7103344 | 2013-05-01 14:21:20 +0000 | [diff] [blame] | 46 | REPORTER_ASSERT(reporter, fnset->count() == set->count()); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 47 | |
| 48 | if (verbose) { |
| 49 | SkDebugf("[%2d] %s\n", i, fname.c_str()); |
| 50 | } |
| 51 | |
| 52 | for (int j = 0; j < set->count(); ++j) { |
| 53 | SkString sname; |
| 54 | SkFontStyle fs; |
| 55 | set->getStyle(j, &fs, &sname); |
reed@google.com | eb02957 | 2013-04-25 14:59:32 +0000 | [diff] [blame] | 56 | // REPORTER_ASSERT(reporter, sname.size() > 0); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 57 | |
| 58 | SkAutoTUnref<SkTypeface> face(set->createTypeface(j)); |
reed@google.com | c1ccda3 | 2013-04-19 14:28:54 +0000 | [diff] [blame] | 59 | // REPORTER_ASSERT(reporter, face.get()); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 60 | |
| 61 | if (verbose) { |
| 62 | SkDebugf("\t[%d] %s [%3d %d %d]\n", j, sname.c_str(), |
| 63 | fs.weight(), fs.width(), fs.isItalic()); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
reed@google.com | 66c9f99 | 2013-04-11 19:04:34 +0000 | [diff] [blame] | 69 | DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 70 | |
| 71 | static void TestFontMgr(skiatest::Reporter* reporter) { |
| 72 | test_fontiter(reporter, FLAGS_verboseFontMgr); |
reed@google.com | d44d988 | 2013-09-18 20:32:25 +0000 | [diff] [blame^] | 73 | test_badnames(reporter); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | #include "TestClassDef.h" |
| 77 | DEFINE_TESTCLASS("FontMgr", FontMgrClass, TestFontMgr) |