OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkCommandLineFlags.h" | 8 #include "SkCommandLineFlags.h" |
9 #include "SkFontMgr.h" | 9 #include "SkFontMgr.h" |
10 #include "SkTypeface.h" | 10 #include "SkTypeface.h" |
11 #include "Test.h" | 11 #include "Test.h" |
12 | 12 |
| 13 #include "SkFont.h" |
| 14 #include "SkPaint.h" |
| 15 static void test_font(skiatest::Reporter* reporter) { |
| 16 uint32_t flags = 0; |
| 17 SkAutoTUnref<SkFont> font(SkFont::Create(NULL, 24, SkFont::kA8_MaskType, fla
gs)); |
| 18 |
| 19 REPORTER_ASSERT(reporter, NULL != font->getTypeface()); |
| 20 REPORTER_ASSERT(reporter, 24 == font->getSize()); |
| 21 REPORTER_ASSERT(reporter, 1 == font->getScaleX()); |
| 22 REPORTER_ASSERT(reporter, 0 == font->getSkewX()); |
| 23 REPORTER_ASSERT(reporter, SkFont::kA8_MaskType == font->getMaskType()); |
| 24 |
| 25 uint16_t glyphs[5]; |
| 26 sk_bzero(glyphs, sizeof(glyphs)); |
| 27 |
| 28 int count = font->textToGlyphs("Hello", 5, kUTF8_SkTextEncoding, glyphs, SK_
ARRAY_COUNT(glyphs)); |
| 29 |
| 30 REPORTER_ASSERT(reporter, 5 == count); |
| 31 for (int i = 0; i < count; ++i) { |
| 32 REPORTER_ASSERT(reporter, 0 != glyphs[i]); |
| 33 } |
| 34 REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e' |
| 35 REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l' |
| 36 |
| 37 SkAutoTUnref<SkFont> newFont(font->cloneWithSize(36)); |
| 38 REPORTER_ASSERT(reporter, newFont.get()); |
| 39 REPORTER_ASSERT(reporter, font->getTypeface() == newFont->getTypeface()); |
| 40 REPORTER_ASSERT(reporter, 36 == newFont->getSize()); // double check we ha
ven't changed |
| 41 REPORTER_ASSERT(reporter, 24 == font->getSize()); // double check we haven
't changed |
| 42 |
| 43 SkPaint paint; |
| 44 paint.setTextSize(18); |
| 45 font.reset(SkFont::Testing_CreateFromPaint(paint)); |
| 46 REPORTER_ASSERT(reporter, font.get()); |
| 47 REPORTER_ASSERT(reporter, font->getSize() == paint.getTextSize()); |
| 48 REPORTER_ASSERT(reporter, SkFont::kBW_MaskType == font->getMaskType()); |
| 49 } |
| 50 |
13 /* | 51 /* |
14 * If the font backend is going to "alias" some font names to other fonts | 52 * If the font backend is going to "alias" some font names to other fonts |
15 * (e.g. sans -> Arial) then we want to at least get the same typeface back | 53 * (e.g. sans -> Arial) then we want to at least get the same typeface back |
16 * if we request the alias name multiple times. | 54 * if we request the alias name multiple times. |
17 */ | 55 */ |
18 static void test_alias_names(skiatest::Reporter* reporter) { | 56 static void test_alias_names(skiatest::Reporter* reporter) { |
19 const char* inNames[] = { | 57 const char* inNames[] = { |
20 "sans", "sans-serif", "serif", "monospace", "times", "helvetica" | 58 "sans", "sans-serif", "serif", "monospace", "times", "helvetica" |
21 }; | 59 }; |
22 | 60 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 109 } |
72 } | 110 } |
73 } | 111 } |
74 } | 112 } |
75 | 113 |
76 DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); | 114 DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); |
77 | 115 |
78 DEF_TEST(FontMgr, reporter) { | 116 DEF_TEST(FontMgr, reporter) { |
79 test_fontiter(reporter, FLAGS_verboseFontMgr); | 117 test_fontiter(reporter, FLAGS_verboseFontMgr); |
80 test_alias_names(reporter); | 118 test_alias_names(reporter); |
| 119 test_font(reporter); |
81 } | 120 } |
OLD | NEW |