Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: tests/FontObjTest.cpp

Issue 1974783002: Revert of Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "SkFont.h" 8 #include "SkFont.h"
9 #include "SkPaint.h" 9 #include "SkPaint.h"
10 #include "SkTypeface.h" 10 #include "SkTypeface.h"
11 #include "Test.h" 11 #include "Test.h"
12 12
13 static bool is_use_nonlinear_metrics(const SkPaint& paint) { 13 static bool is_use_nonlinear_metrics(const SkPaint& paint) {
14 return !paint.isSubpixelText() && !paint.isLinearText(); 14 return !paint.isSubpixelText() && !paint.isLinearText();
15 } 15 }
16 16
17 static bool is_enable_auto_hints(const SkPaint& paint) { 17 static bool is_enable_auto_hints(const SkPaint& paint) {
18 return paint.isAutohinted(); 18 return paint.isAutohinted();
19 } 19 }
20 20
21 static bool is_enable_bytecode_hints(const SkPaint& paint) { 21 static bool is_enable_bytecode_hints(const SkPaint& paint) {
22 return paint.getHinting() >= SkPaint::kFull_Hinting; 22 return paint.getHinting() >= SkPaint::kFull_Hinting;
23 } 23 }
24 24
25 static void test_cachedfont(skiatest::Reporter* reporter, const SkPaint& paint) { 25 static void test_cachedfont(skiatest::Reporter* reporter, const SkPaint& paint) {
26 sk_sp<SkFont> font(SkFont::Testing_CreateFromPaint(paint)); 26 SkAutoTUnref<SkFont> font(SkFont::Testing_CreateFromPaint(paint));
27 27
28 // Currently SkFont resolves null into the default, so only test if paint's is not null 28 // Currently SkFont resolves null into the default, so only test if paint's is not null
29 if (paint.getTypeface()) { 29 if (paint.getTypeface()) {
30 REPORTER_ASSERT(reporter, font->getTypeface() == paint.getTypeface()); 30 REPORTER_ASSERT(reporter, font->getTypeface() == paint.getTypeface());
31 } 31 }
32 REPORTER_ASSERT(reporter, font->getSize() == paint.getTextSize()); 32 REPORTER_ASSERT(reporter, font->getSize() == paint.getTextSize());
33 REPORTER_ASSERT(reporter, font->getScaleX() == paint.getTextScaleX()); 33 REPORTER_ASSERT(reporter, font->getScaleX() == paint.getTextScaleX());
34 REPORTER_ASSERT(reporter, font->getSkewX() == paint.getTextSkewX()); 34 REPORTER_ASSERT(reporter, font->getSkewX() == paint.getTextSkewX());
35 35
36 REPORTER_ASSERT(reporter, font->isVertical() == paint.isVerticalText()); 36 REPORTER_ASSERT(reporter, font->isVertical() == paint.isVerticalText());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 { SK_Scalar1/2, 0 }, 71 { SK_Scalar1/2, 0 },
72 // these two exercise obliquing (skew) 72 // these two exercise obliquing (skew)
73 { SK_Scalar1, -SK_Scalar1/4 }, 73 { SK_Scalar1, -SK_Scalar1/4 },
74 { SK_Scalar1/2, -SK_Scalar1/4 }, 74 { SK_Scalar1/2, -SK_Scalar1/4 },
75 }; 75 };
76 76
77 SkPaint paint; 77 SkPaint paint;
78 char txt[] = "long.text.with.lots.of.dots."; 78 char txt[] = "long.text.with.lots.of.dots.";
79 79
80 for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) { 80 for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) {
81 paint.setTypeface(SkTypeface::MakeFromName(faces[i], SkTypeface::kNormal )); 81 SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(faces[i], SkTyp eface::kNormal));
82 paint.setTypeface(face);
82 83
83 for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) { 84 for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) {
84 paint.setHinting(settings[j].hinting); 85 paint.setHinting(settings[j].hinting);
85 paint.setLinearText((settings[j].flags & SkPaint::kLinearText_Flag) != 0); 86 paint.setLinearText((settings[j].flags & SkPaint::kLinearText_Flag) != 0);
86 paint.setSubpixelText((settings[j].flags & SkPaint::kSubpixelText_Fl ag) != 0); 87 paint.setSubpixelText((settings[j].flags & SkPaint::kSubpixelText_Fl ag) != 0);
87 88
88 for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) { 89 for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) {
89 paint.setTextScaleX(gScaleRec[k].fScaleX); 90 paint.setTextScaleX(gScaleRec[k].fScaleX);
90 paint.setTextSkewX(gScaleRec[k].fSkewX); 91 paint.setTextSkewX(gScaleRec[k].fSkewX);
91 92
92 test_cachedfont(reporter, paint); 93 test_cachedfont(reporter, paint);
93 94
94 SkRect bounds; 95 SkRect bounds;
95 96
96 // For no hinting and light hinting this should take the 97 // For no hinting and light hinting this should take the
97 // optimized generateAdvance path. 98 // optimized generateAdvance path.
98 SkScalar width1 = paint.measureText(txt, strlen(txt)); 99 SkScalar width1 = paint.measureText(txt, strlen(txt));
99 100
100 // Requesting the bounds forces a generateMetrics call. 101 // Requesting the bounds forces a generateMetrics call.
101 SkScalar width2 = paint.measureText(txt, strlen(txt), &bounds); 102 SkScalar width2 = paint.measureText(txt, strlen(txt), &bounds);
102 103
103 REPORTER_ASSERT(reporter, width1 == width2); 104 REPORTER_ASSERT(reporter, width1 == width2);
104 105
105 sk_sp<SkFont> font(SkFont::Testing_CreateFromPaint(paint)); 106 SkAutoTUnref<SkFont> font(SkFont::Testing_CreateFromPaint(paint) );
106 SkScalar font_width1 = font->measureText(txt, strlen(txt), kUTF8 _SkTextEncoding); 107 SkScalar font_width1 = font->measureText(txt, strlen(txt), kUTF8 _SkTextEncoding);
107 // measureText not yet implemented... 108 // measureText not yet implemented...
108 REPORTER_ASSERT(reporter, font_width1 == -1); 109 REPORTER_ASSERT(reporter, font_width1 == -1);
109 // REPORTER_ASSERT(reporter, width1 == font_width1); 110 // REPORTER_ASSERT(reporter, width1 == font_width1);
110 } 111 }
111 } 112 }
112 } 113 }
113 } 114 }
114 115
115 DEF_TEST(FontObj, reporter) { 116 DEF_TEST(FontObj, reporter) {
116 test_cachedfont(reporter); 117 test_cachedfont(reporter);
117 } 118 }
118 119
119 // need tests for SkStrSearch 120 // need tests for SkStrSearch
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698