| Index: tests/FontHostTest.cpp
|
| ===================================================================
|
| --- tests/FontHostTest.cpp (revision 10894)
|
| +++ tests/FontHostTest.cpp (working copy)
|
| @@ -8,6 +8,7 @@
|
| #include "Test.h"
|
| #include "SkPaint.h"
|
| #include "SkFontStream.h"
|
| +#include "SkOSFile.h"
|
| #include "SkStream.h"
|
| #include "SkTypeface.h"
|
| #include "SkEndian.h"
|
| @@ -72,6 +73,30 @@
|
| }
|
| }
|
|
|
| +// Test that SkPaint::textToGlyphs agrees with SkTypeface::charsToGlyphs.
|
| +static void test_charsToGlyphs(skiatest::Reporter* reporter, SkTypeface* face) {
|
| + const char text[5] = "ABCD";
|
| + const size_t textLength = SK_ARRAY_COUNT(text)-1;
|
| +
|
| + uint16_t paintGlyphIds[textLength];
|
| + SkPaint paint;
|
| + paint.setTypeface(face);
|
| + paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
|
| + paint.textToGlyphs(text, textLength, paintGlyphIds);
|
| +
|
| + uint16_t faceGlyphIds[textLength];
|
| + face->charsToGlyphs(text, SkTypeface::kUTF8_Encoding, faceGlyphIds, textLength);
|
| +
|
| + for (size_t i = 0; i < textLength; ++i) {
|
| + SkString name;
|
| + face->getFamilyName(&name);
|
| + SkString a;
|
| + a.appendf("paintGlyphIds[%d] = %d, faceGlyphIds[%d] = %d, name = %s",
|
| + (int)i, (int)paintGlyphIds[i], (int)i, (int)faceGlyphIds[i], name.c_str());
|
| + REPORTER_ASSERT_MESSAGE(reporter, paintGlyphIds[i] == faceGlyphIds[i], a.c_str());
|
| + }
|
| +}
|
| +
|
| static void test_fontstream(skiatest::Reporter* reporter,
|
| SkStream* stream, int ttcIndex) {
|
| int n = SkFontStream::GetTableTags(stream, ttcIndex, NULL);
|
| @@ -110,11 +135,19 @@
|
| }
|
|
|
| static void test_fontstream(skiatest::Reporter* reporter) {
|
| - // TODO: replace when we get a tools/resources/fonts/test.ttc
|
| - const char* name = "/AmericanTypewriter.ttc";
|
| - SkFILEStream stream(name);
|
| + // This test cannot run if there is no resource path.
|
| + SkString resourcePath = skiatest::Test::GetResourcePath();
|
| + if (resourcePath.isEmpty()) {
|
| + SkDebugf("Could not run fontstream test because resourcePath not specified.");
|
| + return;
|
| + }
|
| + SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "test.ttc");
|
| +
|
| + SkFILEStream stream(filename.c_str());
|
| if (stream.isValid()) {
|
| test_fontstream(reporter, &stream);
|
| + } else {
|
| + SkDebugf("Could not run fontstream test because test.ttc not found.");
|
| }
|
| }
|
|
|
| @@ -169,8 +202,7 @@
|
| };
|
|
|
| for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) {
|
| - SkTypeface* face = SkTypeface::CreateFromName(gNames[i],
|
| - SkTypeface::kNormal);
|
| + SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(gNames[i], SkTypeface::kNormal));
|
| if (face) {
|
| #ifdef DUMP_TABLES
|
| SkDebugf("%s\n", gNames[i]);
|
| @@ -178,7 +210,7 @@
|
| test_tables(reporter, face);
|
| test_unitsPerEm(reporter, face);
|
| test_countGlyphs(reporter, face);
|
| - face->unref();
|
| + test_charsToGlyphs(reporter, face);
|
| }
|
| }
|
| }
|
|
|