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

Unified Diff: tests/FontHostTest.cpp

Issue 22859070: Implement charToGlyph on remaining ports. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
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);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698