add (mac) test for ttcindex in SkFontStream
git-svn-id: http://skia.googlecode.com/svn/trunk@8073 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp
index 5c43128..87c6680 100644
--- a/tests/FontHostTest.cpp
+++ b/tests/FontHostTest.cpp
@@ -7,10 +7,13 @@
#include "Test.h"
#include "SkPaint.h"
+#include "SkFontStream.h"
+#include "SkStream.h"
#include "SkTypeface.h"
#include "SkEndian.h"
//#define DUMP_TABLES
+//#define DUMP_TTC_TABLES
#define kFontTableTag_head SkSetFourByteTag('h', 'e', 'a', 'd')
#define kFontTableTag_hhea SkSetFourByteTag('h', 'h', 'e', 'a')
@@ -40,6 +43,52 @@
}
}
+static void test_fontstream(skiatest::Reporter* reporter,
+ SkStream* stream, int ttcIndex) {
+ int n = SkFontStream::GetTableTags(stream, ttcIndex, NULL);
+ SkAutoTArray<SkFontTableTag> array(n);
+
+ int n2 = SkFontStream::GetTableTags(stream, ttcIndex, array.get());
+ REPORTER_ASSERT(reporter, n == n2);
+
+ for (int i = 0; i < n; ++i) {
+#ifdef DUMP_TTC_TABLES
+ SkString str;
+ SkFontTableTag t = array[i];
+ str.appendUnichar((t >> 24) & 0xFF);
+ str.appendUnichar((t >> 16) & 0xFF);
+ str.appendUnichar((t >> 8) & 0xFF);
+ str.appendUnichar((t >> 0) & 0xFF);
+ SkDebugf("[%d:%d] '%s'\n", ttcIndex, i, str.c_str());
+#endif
+ size_t size = SkFontStream::GetTableSize(stream, ttcIndex, array[i]);
+ for (size_t j = 0; j < SK_ARRAY_COUNT(gKnownTableSizes); ++j) {
+ if (gKnownTableSizes[j].fTag == array[i]) {
+ REPORTER_ASSERT(reporter, gKnownTableSizes[j].fSize == size);
+ }
+ }
+ }
+}
+
+static void test_fontstream(skiatest::Reporter* reporter, SkStream* stream) {
+ int count = SkFontStream::CountTTCEntries(stream);
+#ifdef DUMP_TTC_TABLES
+ SkDebugf("CountTTCEntries %d\n", count);
+#endif
+ for (int i = 0; i < count; ++i) {
+ test_fontstream(reporter, stream, i);
+ }
+}
+
+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);
+ if (stream.isValid()) {
+ test_fontstream(reporter, &stream);
+ }
+}
+
static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) {
if (false) { // avoid bit rot, suppress warning
SkFontID fontID = face->uniqueID();
@@ -177,6 +226,7 @@
static void TestFontHost(skiatest::Reporter* reporter) {
test_tables(reporter);
+ test_fontstream(reporter);
test_advances(reporter);
}