Skip to content

Commit f9e824b

Browse files
reed-at-googleSkia Commit-Bot
authored andcommitted
use SkFont for textToGlyphs
Bug: skia: Change-Id: Ifbbd3d99789c142ebd5b1ef2a149799a25c310a0 Reviewed-on: https://skia-review.googlesource.com/c/177343 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Mike Reed <reed@google.com>
1 parent c723b76 commit f9e824b

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

tests/FontHostTest.cpp

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Resources.h"
99
#include "SkAutoMalloc.h"
1010
#include "SkEndian.h"
11+
#include "SkFont.h"
1112
#include "SkFontStream.h"
1213
#include "SkOSFile.h"
1314
#include "SkPaint.h"
@@ -87,17 +88,17 @@ struct CharsToGlyphs_TestData {
8788
};
8889

8990
// 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) {
9192
uint16_t paintGlyphIds[256];
9293
uint16_t faceGlyphIds[256];
9394

9495
for (size_t testIndex = 0; testIndex < SK_ARRAY_COUNT(charsToGlyphs_TestData); ++testIndex) {
9596
CharsToGlyphs_TestData& test = charsToGlyphs_TestData[testIndex];
97+
SkTextEncoding encoding = static_cast<SkTextEncoding>(test.typefaceEncoding);
9698

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));
101102

102103
face->charsToGlyphs(test.chars, test.typefaceEncoding, faceGlyphIds, test.charCount);
103104

@@ -154,20 +155,17 @@ static void test_fontstream(skiatest::Reporter* reporter) {
154155
}
155156
}
156157

158+
// Exercise this rare cmap format (platform 3, encoding 0)
157159
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
166167
SkDebugf("Skipping FontHostTest::test_symbolfont\n");
167-
return;
168168
}
169-
170-
REPORTER_ASSERT(reporter, g == 3);
171169
}
172170

173171
static void test_tables(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) {
@@ -274,29 +272,29 @@ static void test_advances(skiatest::Reporter* reporter) {
274272
{ SK_Scalar1/2, -SK_Scalar1/4 },
275273
};
276274

277-
SkPaint paint;
275+
SkFont font;
278276
char txt[] = "long.text.with.lots.of.dots.";
279277

280278
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()));
282280

283281
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);
287285

288286
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);
291289

292290
SkRect bounds;
293291

294292
// For no hinting and light hinting this should take the
295293
// optimized generateAdvance path.
296-
SkScalar width1 = paint.measureText(txt, strlen(txt));
294+
SkScalar width1 = font.measureText(txt, strlen(txt), kUTF8_SkTextEncoding);
297295

298296
// 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);
300298

301299
// SkDebugf("Font: %s, generateAdvance: %f, generateMetrics: %f\n",
302300
// faces[i], SkScalarToFloat(width1), SkScalarToFloat(width2));

0 commit comments

Comments
 (0)