|
8 | 8 | #include "Resources.h" |
9 | 9 | #include "SkAutoMalloc.h" |
10 | 10 | #include "SkEndian.h" |
| 11 | +#include "SkFont.h" |
11 | 12 | #include "SkFontStream.h" |
12 | 13 | #include "SkOSFile.h" |
13 | 14 | #include "SkPaint.h" |
@@ -87,17 +88,17 @@ struct CharsToGlyphs_TestData { |
87 | 88 | }; |
88 | 89 |
|
89 | 90 | // Test that SkPaint::textToGlyphs agrees with SkTypeface::charsToGlyphs. |
90 | | -static void test_charsToGlyphs(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) { |
| 91 | +static void test_charsToGlyphs(skiatest::Reporter* reporter, sk_sp<SkTypeface> face) { |
91 | 92 | uint16_t paintGlyphIds[256]; |
92 | 93 | uint16_t faceGlyphIds[256]; |
93 | 94 |
|
94 | 95 | for (size_t testIndex = 0; testIndex < SK_ARRAY_COUNT(charsToGlyphs_TestData); ++testIndex) { |
95 | 96 | CharsToGlyphs_TestData& test = charsToGlyphs_TestData[testIndex]; |
| 97 | + SkTextEncoding encoding = static_cast<SkTextEncoding>(test.typefaceEncoding); |
96 | 98 |
|
97 | | - SkPaint paint; |
98 | | - paint.setTypeface(face); |
99 | | - paint.setTextEncoding(static_cast<SkTextEncoding>(test.typefaceEncoding)); |
100 | | - paint.textToGlyphs(test.chars, test.charsByteLength, paintGlyphIds); |
| 99 | + SkFont font(face); |
| 100 | + font.textToGlyphs(test.chars, test.charsByteLength, encoding, |
| 101 | + paintGlyphIds, SK_ARRAY_COUNT(paintGlyphIds)); |
101 | 102 |
|
102 | 103 | face->charsToGlyphs(test.chars, test.typefaceEncoding, faceGlyphIds, test.charCount); |
103 | 104 |
|
@@ -154,20 +155,17 @@ static void test_fontstream(skiatest::Reporter* reporter) { |
154 | 155 | } |
155 | 156 | } |
156 | 157 |
|
| 158 | +// Exercise this rare cmap format (platform 3, encoding 0) |
157 | 159 | static void test_symbolfont(skiatest::Reporter* reporter) { |
158 | | - SkUnichar c = 0xf021; |
159 | | - uint16_t g; |
160 | | - SkPaint paint; |
161 | | - paint.setTypeface(MakeResourceAsTypeface("fonts/SpiderSymbol.ttf")); |
162 | | - paint.setTextEncoding(kUTF32_SkTextEncoding); |
163 | | - paint.textToGlyphs(&c, 4, &g); |
164 | | - |
165 | | - if (!paint.getTypeface()) { |
| 160 | + auto tf = MakeResourceAsTypeface("fonts/SpiderSymbol.ttf"); |
| 161 | + if (tf) { |
| 162 | + SkUnichar c = 0xf021; |
| 163 | + uint16_t g = SkFont(tf).unicharToGlyph(c); |
| 164 | + REPORTER_ASSERT(reporter, g == 3); |
| 165 | + } else { |
| 166 | + // not all platforms support data fonts, so we just note that failure |
166 | 167 | SkDebugf("Skipping FontHostTest::test_symbolfont\n"); |
167 | | - return; |
168 | 168 | } |
169 | | - |
170 | | - REPORTER_ASSERT(reporter, g == 3); |
171 | 169 | } |
172 | 170 |
|
173 | 171 | static void test_tables(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) { |
@@ -274,29 +272,29 @@ static void test_advances(skiatest::Reporter* reporter) { |
274 | 272 | { SK_Scalar1/2, -SK_Scalar1/4 }, |
275 | 273 | }; |
276 | 274 |
|
277 | | - SkPaint paint; |
| 275 | + SkFont font; |
278 | 276 | char txt[] = "long.text.with.lots.of.dots."; |
279 | 277 |
|
280 | 278 | for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) { |
281 | | - paint.setTypeface(SkTypeface::MakeFromName(faces[i], SkFontStyle())); |
| 279 | + font.setTypeface(SkTypeface::MakeFromName(faces[i], SkFontStyle())); |
282 | 280 |
|
283 | 281 | for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) { |
284 | | - paint.setHinting(settings[j].hinting); |
285 | | - paint.setLinearText((settings[j].flags & SkPaint::kLinearText_Flag) != 0); |
286 | | - paint.setSubpixelText((settings[j].flags & SkPaint::kSubpixelText_Flag) != 0); |
| 282 | + font.setHinting(settings[j].hinting); |
| 283 | + font.setLinearMetrics((settings[j].flags & SkPaint::kLinearText_Flag) != 0); |
| 284 | + font.setSubpixel((settings[j].flags & SkPaint::kSubpixelText_Flag) != 0); |
287 | 285 |
|
288 | 286 | for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) { |
289 | | - paint.setTextScaleX(gScaleRec[k].fScaleX); |
290 | | - paint.setTextSkewX(gScaleRec[k].fSkewX); |
| 287 | + font.setScaleX(gScaleRec[k].fScaleX); |
| 288 | + font.setSkewX(gScaleRec[k].fSkewX); |
291 | 289 |
|
292 | 290 | SkRect bounds; |
293 | 291 |
|
294 | 292 | // For no hinting and light hinting this should take the |
295 | 293 | // optimized generateAdvance path. |
296 | | - SkScalar width1 = paint.measureText(txt, strlen(txt)); |
| 294 | + SkScalar width1 = font.measureText(txt, strlen(txt), kUTF8_SkTextEncoding); |
297 | 295 |
|
298 | 296 | // Requesting the bounds forces a generateMetrics call. |
299 | | - SkScalar width2 = paint.measureText(txt, strlen(txt), &bounds); |
| 297 | + SkScalar width2 = font.measureText(txt, strlen(txt), kUTF8_SkTextEncoding, &bounds); |
300 | 298 |
|
301 | 299 | // SkDebugf("Font: %s, generateAdvance: %f, generateMetrics: %f\n", |
302 | 300 | // faces[i], SkScalarToFloat(width1), SkScalarToFloat(width2)); |
|
0 commit comments