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" | 13 #include "SkFont.h" |
14 #include "SkPaint.h" | 14 #include "SkPaint.h" |
15 | 15 |
16 #include <initializer_list> | 16 #include <initializer_list> |
17 #include <limits> | 17 #include <limits> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 static void test_font(skiatest::Reporter* reporter) { | 20 static void test_font(skiatest::Reporter* reporter) { |
21 uint32_t flags = 0; | 21 uint32_t flags = 0; |
22 SkAutoTUnref<SkFont> font(SkFont::Create(nullptr, 24, SkFont::kA8_MaskType,
flags)); | 22 sk_sp<SkFont> font(SkFont::Make(nullptr, 24, SkFont::kA8_MaskType, flags)); |
23 | 23 |
24 REPORTER_ASSERT(reporter, font->getTypeface()); | 24 REPORTER_ASSERT(reporter, font->getTypeface()); |
25 REPORTER_ASSERT(reporter, 24 == font->getSize()); | 25 REPORTER_ASSERT(reporter, 24 == font->getSize()); |
26 REPORTER_ASSERT(reporter, 1 == font->getScaleX()); | 26 REPORTER_ASSERT(reporter, 1 == font->getScaleX()); |
27 REPORTER_ASSERT(reporter, 0 == font->getSkewX()); | 27 REPORTER_ASSERT(reporter, 0 == font->getSkewX()); |
28 REPORTER_ASSERT(reporter, SkFont::kA8_MaskType == font->getMaskType()); | 28 REPORTER_ASSERT(reporter, SkFont::kA8_MaskType == font->getMaskType()); |
29 | 29 |
30 uint16_t glyphs[5]; | 30 uint16_t glyphs[5]; |
31 sk_bzero(glyphs, sizeof(glyphs)); | 31 sk_bzero(glyphs, sizeof(glyphs)); |
32 | 32 |
33 int count = font->textToGlyphs("Hello", 5, kUTF8_SkTextEncoding, glyphs, SK_
ARRAY_COUNT(glyphs)); | 33 int count = font->textToGlyphs("Hello", 5, kUTF8_SkTextEncoding, glyphs, SK_
ARRAY_COUNT(glyphs)); |
34 | 34 |
35 REPORTER_ASSERT(reporter, 5 == count); | 35 REPORTER_ASSERT(reporter, 5 == count); |
36 for (int i = 0; i < count; ++i) { | 36 for (int i = 0; i < count; ++i) { |
37 REPORTER_ASSERT(reporter, 0 != glyphs[i]); | 37 REPORTER_ASSERT(reporter, 0 != glyphs[i]); |
38 } | 38 } |
39 REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e' | 39 REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e' |
40 REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l' | 40 REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l' |
41 | 41 |
42 SkAutoTUnref<SkFont> newFont(font->cloneWithSize(36)); | 42 sk_sp<SkFont> newFont(font->makeWithSize(36)); |
43 REPORTER_ASSERT(reporter, newFont.get()); | 43 REPORTER_ASSERT(reporter, newFont.get()); |
44 REPORTER_ASSERT(reporter, font->getTypeface() == newFont->getTypeface()); | 44 REPORTER_ASSERT(reporter, font->getTypeface() == newFont->getTypeface()); |
45 REPORTER_ASSERT(reporter, 36 == newFont->getSize()); // double check we ha
ven't changed | 45 REPORTER_ASSERT(reporter, 36 == newFont->getSize()); // double check we ha
ven't changed |
46 REPORTER_ASSERT(reporter, 24 == font->getSize()); // double check we haven
't changed | 46 REPORTER_ASSERT(reporter, 24 == font->getSize()); // double check we haven
't changed |
47 | 47 |
48 SkPaint paint; | 48 SkPaint paint; |
49 paint.setTextSize(18); | 49 paint.setTextSize(18); |
50 font.reset(SkFont::Testing_CreateFromPaint(paint)); | 50 font = SkFont::Testing_CreateFromPaint(paint); |
51 REPORTER_ASSERT(reporter, font.get()); | 51 REPORTER_ASSERT(reporter, font.get()); |
52 REPORTER_ASSERT(reporter, font->getSize() == paint.getTextSize()); | 52 REPORTER_ASSERT(reporter, font->getSize() == paint.getTextSize()); |
53 REPORTER_ASSERT(reporter, SkFont::kBW_MaskType == font->getMaskType()); | 53 REPORTER_ASSERT(reporter, SkFont::kBW_MaskType == font->getMaskType()); |
54 } | 54 } |
55 | 55 |
56 /* | 56 /* |
57 * If the font backend is going to "alias" some font names to other fonts | 57 * If the font backend is going to "alias" some font names to other fonts |
58 * (e.g. sans -> Arial) then we want to at least get the same typeface back | 58 * (e.g. sans -> Arial) then we want to at least get the same typeface back |
59 * if we request the alias name multiple times. | 59 * if we request the alias name multiple times. |
60 */ | 60 */ |
61 static void test_alias_names(skiatest::Reporter* reporter) { | 61 static void test_alias_names(skiatest::Reporter* reporter) { |
62 const char* inNames[] = { | 62 const char* inNames[] = { |
63 "sans", "sans-serif", "serif", "monospace", "times", "helvetica" | 63 "sans", "sans-serif", "serif", "monospace", "times", "helvetica" |
64 }; | 64 }; |
65 | 65 |
66 for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) { | 66 for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) { |
67 SkAutoTUnref<SkTypeface> first(SkTypeface::CreateFromName(inNames[i], | 67 sk_sp<SkTypeface> first(SkTypeface::MakeFromName(inNames[i], SkTypeface:
:kNormal)); |
68 SkTypeface::kNormal)); | |
69 if (nullptr == first.get()) { | 68 if (nullptr == first.get()) { |
70 continue; | 69 continue; |
71 } | 70 } |
72 for (int j = 0; j < 10; ++j) { | 71 for (int j = 0; j < 10; ++j) { |
73 SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(inNames[i], | 72 sk_sp<SkTypeface> face(SkTypeface::MakeFromName(inNames[i], SkTypefa
ce::kNormal)); |
74 SkTypeface::kNormal)); | |
75 #if 0 | 73 #if 0 |
76 SkString name; | 74 SkString name; |
77 face->getFamilyName(&name); | 75 face->getFamilyName(&name); |
78 printf("request %s, received %s, first id %x received %x\n", | 76 printf("request %s, received %s, first id %x received %x\n", |
79 inNames[i], name.c_str(), first->uniqueID(), face->uniqueID()
); | 77 inNames[i], name.c_str(), first->uniqueID(), face->uniqueID()
); |
80 #endif | 78 #endif |
81 REPORTER_ASSERT(reporter, first->uniqueID() == face->uniqueID()); | 79 REPORTER_ASSERT(reporter, first->uniqueID() == face->uniqueID()); |
82 } | 80 } |
83 } | 81 } |
84 } | 82 } |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 } | 703 } |
706 | 704 |
707 DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); | 705 DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); |
708 | 706 |
709 DEF_TEST(FontMgr, reporter) { | 707 DEF_TEST(FontMgr, reporter) { |
710 test_matchStyleCSS3(reporter); | 708 test_matchStyleCSS3(reporter); |
711 test_fontiter(reporter, FLAGS_verboseFontMgr); | 709 test_fontiter(reporter, FLAGS_verboseFontMgr); |
712 test_alias_names(reporter); | 710 test_alias_names(reporter); |
713 test_font(reporter); | 711 test_font(reporter); |
714 } | 712 } |
OLD | NEW |