OLD | NEW |
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 SkAutoTUnref<SkFont> font(SkFont::Testing_CreateFromPaint(paint)); | 26 sk_sp<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 Loading... |
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 SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(faces[i], SkTyp
eface::kNormal)); | 81 paint.setTypeface(SkTypeface::MakeFromName(faces[i], SkTypeface::kNormal
)); |
82 paint.setTypeface(face); | |
83 | 82 |
84 for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) { | 83 for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) { |
85 paint.setHinting(settings[j].hinting); | 84 paint.setHinting(settings[j].hinting); |
86 paint.setLinearText((settings[j].flags & SkPaint::kLinearText_Flag)
!= 0); | 85 paint.setLinearText((settings[j].flags & SkPaint::kLinearText_Flag)
!= 0); |
87 paint.setSubpixelText((settings[j].flags & SkPaint::kSubpixelText_Fl
ag) != 0); | 86 paint.setSubpixelText((settings[j].flags & SkPaint::kSubpixelText_Fl
ag) != 0); |
88 | 87 |
89 for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) { | 88 for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) { |
90 paint.setTextScaleX(gScaleRec[k].fScaleX); | 89 paint.setTextScaleX(gScaleRec[k].fScaleX); |
91 paint.setTextSkewX(gScaleRec[k].fSkewX); | 90 paint.setTextSkewX(gScaleRec[k].fSkewX); |
92 | 91 |
93 test_cachedfont(reporter, paint); | 92 test_cachedfont(reporter, paint); |
94 | 93 |
95 SkRect bounds; | 94 SkRect bounds; |
96 | 95 |
97 // For no hinting and light hinting this should take the | 96 // For no hinting and light hinting this should take the |
98 // optimized generateAdvance path. | 97 // optimized generateAdvance path. |
99 SkScalar width1 = paint.measureText(txt, strlen(txt)); | 98 SkScalar width1 = paint.measureText(txt, strlen(txt)); |
100 | 99 |
101 // Requesting the bounds forces a generateMetrics call. | 100 // Requesting the bounds forces a generateMetrics call. |
102 SkScalar width2 = paint.measureText(txt, strlen(txt), &bounds); | 101 SkScalar width2 = paint.measureText(txt, strlen(txt), &bounds); |
103 | 102 |
104 REPORTER_ASSERT(reporter, width1 == width2); | 103 REPORTER_ASSERT(reporter, width1 == width2); |
105 | 104 |
106 SkAutoTUnref<SkFont> font(SkFont::Testing_CreateFromPaint(paint)
); | 105 sk_sp<SkFont> font(SkFont::Testing_CreateFromPaint(paint)); |
107 SkScalar font_width1 = font->measureText(txt, strlen(txt), kUTF8
_SkTextEncoding); | 106 SkScalar font_width1 = font->measureText(txt, strlen(txt), kUTF8
_SkTextEncoding); |
108 // measureText not yet implemented... | 107 // measureText not yet implemented... |
109 REPORTER_ASSERT(reporter, font_width1 == -1); | 108 REPORTER_ASSERT(reporter, font_width1 == -1); |
110 // REPORTER_ASSERT(reporter, width1 == font_width1); | 109 // REPORTER_ASSERT(reporter, width1 == font_width1); |
111 } | 110 } |
112 } | 111 } |
113 } | 112 } |
114 } | 113 } |
115 | 114 |
116 DEF_TEST(FontObj, reporter) { | 115 DEF_TEST(FontObj, reporter) { |
117 test_cachedfont(reporter); | 116 test_cachedfont(reporter); |
118 } | 117 } |
119 | 118 |
120 // need tests for SkStrSearch | 119 // need tests for SkStrSearch |
OLD | NEW |