blob: 00ff79b89788cbfaa30ed8a4f759cab74a3ebe2a [file] [log] [blame]
reed@google.com83165a52013-04-11 18:31:25 +00001/*
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.comd44d9882013-09-18 20:32:25 +000014/*
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 */
19static 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.com83165a52013-04-11 18:31:25 +000035static 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.com71033442013-05-01 14:21:20 +000044 SkAutoTUnref<SkFontStyleSet> fnset(fm->matchFamily(fname.c_str()));
reed@google.com83165a52013-04-11 18:31:25 +000045 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i));
bungeman@google.com71033442013-05-01 14:21:20 +000046 REPORTER_ASSERT(reporter, fnset->count() == set->count());
reed@google.com83165a52013-04-11 18:31:25 +000047
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.comeb029572013-04-25 14:59:32 +000056// REPORTER_ASSERT(reporter, sname.size() > 0);
reed@google.com83165a52013-04-11 18:31:25 +000057
58 SkAutoTUnref<SkTypeface> face(set->createTypeface(j));
reed@google.comc1ccda32013-04-19 14:28:54 +000059// REPORTER_ASSERT(reporter, face.get());
reed@google.com83165a52013-04-11 18:31:25 +000060
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.com66c9f992013-04-11 19:04:34 +000069DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests.");
reed@google.com83165a52013-04-11 18:31:25 +000070
71static void TestFontMgr(skiatest::Reporter* reporter) {
72 test_fontiter(reporter, FLAGS_verboseFontMgr);
reed@google.comd44d9882013-09-18 20:32:25 +000073 test_badnames(reporter);
reed@google.com83165a52013-04-11 18:31:25 +000074}
75
76#include "TestClassDef.h"
77DEFINE_TESTCLASS("FontMgr", FontMgrClass, TestFontMgr)