FontMgrTest.cpp revision c1ccda3af8c462dc99d5893806baac3bd85fa5d3
183165a5f71319b04beb561afb7c968493027bcbdreed@google.com/* 283165a5f71319b04beb561afb7c968493027bcbdreed@google.com * Copyright 2013 Google Inc. 383165a5f71319b04beb561afb7c968493027bcbdreed@google.com * 483165a5f71319b04beb561afb7c968493027bcbdreed@google.com * Use of this source code is governed by a BSD-style license that can be 583165a5f71319b04beb561afb7c968493027bcbdreed@google.com * found in the LICENSE file. 683165a5f71319b04beb561afb7c968493027bcbdreed@google.com */ 783165a5f71319b04beb561afb7c968493027bcbdreed@google.com 883165a5f71319b04beb561afb7c968493027bcbdreed@google.com#include "Test.h" 983165a5f71319b04beb561afb7c968493027bcbdreed@google.com 1083165a5f71319b04beb561afb7c968493027bcbdreed@google.com#include "SkCommandLineFlags.h" 1183165a5f71319b04beb561afb7c968493027bcbdreed@google.com#include "SkFontMgr.h" 1283165a5f71319b04beb561afb7c968493027bcbdreed@google.com#include "SkTypeface.h" 1383165a5f71319b04beb561afb7c968493027bcbdreed@google.com 1483165a5f71319b04beb561afb7c968493027bcbdreed@google.comstatic void test_fontiter(skiatest::Reporter* reporter, bool verbose) { 1583165a5f71319b04beb561afb7c968493027bcbdreed@google.com SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 1683165a5f71319b04beb561afb7c968493027bcbdreed@google.com int count = fm->countFamilies(); 1783165a5f71319b04beb561afb7c968493027bcbdreed@google.com 1883165a5f71319b04beb561afb7c968493027bcbdreed@google.com for (int i = 0; i < count; ++i) { 1983165a5f71319b04beb561afb7c968493027bcbdreed@google.com SkString fname; 2083165a5f71319b04beb561afb7c968493027bcbdreed@google.com fm->getFamilyName(i, &fname); 2183165a5f71319b04beb561afb7c968493027bcbdreed@google.com REPORTER_ASSERT(reporter, fname.size() > 0); 2283165a5f71319b04beb561afb7c968493027bcbdreed@google.com 2383165a5f71319b04beb561afb7c968493027bcbdreed@google.com SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); 2483165a5f71319b04beb561afb7c968493027bcbdreed@google.com 2583165a5f71319b04beb561afb7c968493027bcbdreed@google.com if (verbose) { 2683165a5f71319b04beb561afb7c968493027bcbdreed@google.com SkDebugf("[%2d] %s\n", i, fname.c_str()); 2783165a5f71319b04beb561afb7c968493027bcbdreed@google.com } 2883165a5f71319b04beb561afb7c968493027bcbdreed@google.com 2983165a5f71319b04beb561afb7c968493027bcbdreed@google.com for (int j = 0; j < set->count(); ++j) { 3083165a5f71319b04beb561afb7c968493027bcbdreed@google.com SkString sname; 3183165a5f71319b04beb561afb7c968493027bcbdreed@google.com SkFontStyle fs; 3283165a5f71319b04beb561afb7c968493027bcbdreed@google.com set->getStyle(j, &fs, &sname); 3383165a5f71319b04beb561afb7c968493027bcbdreed@google.com REPORTER_ASSERT(reporter, sname.size() > 0); 3483165a5f71319b04beb561afb7c968493027bcbdreed@google.com 3583165a5f71319b04beb561afb7c968493027bcbdreed@google.com SkAutoTUnref<SkTypeface> face(set->createTypeface(j)); 36c1ccda3af8c462dc99d5893806baac3bd85fa5d3reed@google.com// REPORTER_ASSERT(reporter, face.get()); 3783165a5f71319b04beb561afb7c968493027bcbdreed@google.com 3883165a5f71319b04beb561afb7c968493027bcbdreed@google.com if (verbose) { 3983165a5f71319b04beb561afb7c968493027bcbdreed@google.com SkDebugf("\t[%d] %s [%3d %d %d]\n", j, sname.c_str(), 4083165a5f71319b04beb561afb7c968493027bcbdreed@google.com fs.weight(), fs.width(), fs.isItalic()); 4183165a5f71319b04beb561afb7c968493027bcbdreed@google.com } 4283165a5f71319b04beb561afb7c968493027bcbdreed@google.com } 4383165a5f71319b04beb561afb7c968493027bcbdreed@google.com } 4483165a5f71319b04beb561afb7c968493027bcbdreed@google.com} 4583165a5f71319b04beb561afb7c968493027bcbdreed@google.com 4666c9f9995ec581f578aa7de4f0defe7dd728fa7ereed@google.comDEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); 4783165a5f71319b04beb561afb7c968493027bcbdreed@google.com 4883165a5f71319b04beb561afb7c968493027bcbdreed@google.comstatic void TestFontMgr(skiatest::Reporter* reporter) { 4983165a5f71319b04beb561afb7c968493027bcbdreed@google.com test_fontiter(reporter, FLAGS_verboseFontMgr); 5083165a5f71319b04beb561afb7c968493027bcbdreed@google.com} 5183165a5f71319b04beb561afb7c968493027bcbdreed@google.com 5283165a5f71319b04beb561afb7c968493027bcbdreed@google.com#include "TestClassDef.h" 5383165a5f71319b04beb561afb7c968493027bcbdreed@google.comDEFINE_TESTCLASS("FontMgr", FontMgrClass, TestFontMgr) 54