add (mac) test for ttcindex in SkFontStream
git-svn-id: http://skia.googlecode.com/svn/trunk@8073 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
fe7533eebe
commit
ed268bfed3
@ -120,13 +120,13 @@ struct SfntHeader {
|
||||
}
|
||||
|
||||
stream->rewind();
|
||||
if (stream->skip(offsetToDir) != offsetToDir) {
|
||||
if (!skip(stream, offsetToDir)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t size = fCount * sizeof(SkSFNTDirEntry);
|
||||
fDir = reinterpret_cast<SkSFNTDirEntry*>(sk_malloc_throw(size));
|
||||
return stream->read(fDir, size) == size;
|
||||
return read(stream, fDir, size);
|
||||
}
|
||||
|
||||
int fCount;
|
||||
@ -139,7 +139,7 @@ int SkFontStream::CountTTCEntries(SkStream* stream) {
|
||||
stream->rewind();
|
||||
|
||||
SkSharedTTHeader shared;
|
||||
if (stream->read(&shared, sizeof(shared)) != sizeof(shared)) {
|
||||
if (!read(stream, &shared, sizeof(shared))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ int SkFontStream::CountTTCEntries(SkStream* stream) {
|
||||
if (SkSetFourByteTag('t', 't', 'c', 'f') == tag) {
|
||||
return SkEndian_SwapBE32(shared.fCollection.fNumOffsets);
|
||||
} else {
|
||||
return 0;
|
||||
return 1; // normal 'sfnt' has 1 dir entry
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,10 +196,10 @@ size_t SkFontStream::GetTableData(SkStream* stream, int ttcIndex,
|
||||
// skip the stream to the part of the table we want to copy from
|
||||
stream->rewind();
|
||||
size_t bytesToSkip = realOffset + offset;
|
||||
if (stream->skip(bytesToSkip) != bytesToSkip) {
|
||||
if (skip(stream, bytesToSkip)) {
|
||||
return 0;
|
||||
}
|
||||
if (stream->read(data, length) != length) {
|
||||
if (!read(stream, data, length)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,9 @@ class SkStream;
|
||||
class SkFontStream {
|
||||
public:
|
||||
/**
|
||||
* Return the number of shared 'fonts' inside a TTC sfnt, or return 0
|
||||
* if the stream is a normal sfnt (not a TTC).
|
||||
* Return the number of shared directories inside a TTC sfnt, or return 1
|
||||
* if the stream is a normal sfnt (ttf). If there is an error or
|
||||
* no directory is found, return 0.
|
||||
*
|
||||
* Note: the stream is rewound initially, but is returned at an arbitrary
|
||||
* read offset.
|
||||
@ -39,6 +40,10 @@ public:
|
||||
*/
|
||||
static size_t GetTableData(SkStream*, int ttcIndex, SkFontTableTag tag,
|
||||
size_t offset, size_t length, void* data);
|
||||
|
||||
static size_t GetTableSize(SkStream* stream, int ttcIndex, SkFontTableTag tag) {
|
||||
return GetTableData(stream, ttcIndex, tag, 0, ~0U, NULL);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -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_unitsPerEm(skiatest::Reporter* reporter, SkTypeface* face) {
|
||||
}
|
||||
}
|
||||
|
||||
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 test_advances(skiatest::Reporter* reporter) {
|
||||
|
||||
static void TestFontHost(skiatest::Reporter* reporter) {
|
||||
test_tables(reporter);
|
||||
test_fontstream(reporter);
|
||||
test_advances(reporter);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user