Index: tests/TypefaceTest.cpp |
diff --git a/tests/TypefaceTest.cpp b/tests/TypefaceTest.cpp |
index 4c65fa3f9d8e08d018a3c980a669ef56c6727951..26e512aef73345a6237567c83803de34b38aadec 100644 |
--- a/tests/TypefaceTest.cpp |
+++ b/tests/TypefaceTest.cpp |
@@ -5,11 +5,77 @@ |
* found in the LICENSE file. |
*/ |
+#include "SkData.h" |
+#include "SkOTTable_OS_2.h" |
+#include "SkSFNTHeader.h" |
+#include "SkStream.h" |
#include "SkRefCnt.h" |
#include "SkTypeface.h" |
#include "SkTypefaceCache.h" |
+#include "Resources.h" |
#include "Test.h" |
+#include <memory> |
+static void TypefaceStyle_test(skiatest::Reporter* reporter, uint16_t weight, uint16_t width, |
+ SkData* data) |
+{ |
+ SkSFNTHeader* sfntHeader = static_cast<SkSFNTHeader*>(data->writable_data()); |
bungeman-skia
2016/07/25 13:23:08
This is what is actually failing on Mac (on the se
|
+ SkSFNTHeader::TableDirectoryEntry* tableEntry = SkTAfter<SkSFNTHeader::TableDirectoryEntry>(sfntHeader); |
+ SkSFNTHeader::TableDirectoryEntry* os2TableEntry = nullptr; |
+ int numTables = SkEndian_SwapBE16(sfntHeader->numTables); |
+ for (int tableEntryIndex = 0; tableEntryIndex < numTables; ++tableEntryIndex) { |
+ if (SkOTTableOS2::TAG == tableEntry[tableEntryIndex].tag) { |
+ os2TableEntry = tableEntry + tableEntryIndex; |
+ break; |
+ } |
+ } |
+ SkASSERT(os2TableEntry); |
+ |
+ size_t os2TableOffset = SkEndian_SwapBE32(os2TableEntry->offset); |
+ SkOTTableOS2_V0* os2Table = SkTAddOffset<SkOTTableOS2_V0>(sfntHeader, os2TableOffset); |
+ os2Table->usWeightClass.value = SkEndian_SwapBE16(weight); |
+ os2Table->usWidthClass.value = static_cast<SkOTTableOS2_V0::WidthClass::Value>(SkEndian_SwapBE16(width)); |
+ |
+ sk_sp<SkTypeface> newTypeface(SkTypeface::MakeFromStream(new SkMemoryStream(data))); |
+ SkASSERT(newTypeface); |
+ |
+ SkFontStyle newStyle = newTypeface->fontStyle(); |
+ //printf("%d, %f\n", weight, (newStyle.weight() - (float)0x7FFF) / (float)0x7FFF); |
+ //printf("%d, %f\n", width, (newStyle.width() - (float)0x7F) / (float)0x7F); |
+ //printf("(%d, %d)\n", weight, newStyle.weight()); |
+ //printf("%d, %d\n", width, newStyle.width()); |
+ |
+ // Some back-ends (CG, GDI, DW) support OS/2 version A which uses 0 - 10 (but all differently). |
+ REPORTER_ASSERT(reporter, |
+ newStyle.weight() == weight || |
+ (weight <= 10 && newStyle.weight() == 100 * weight) || |
+ (weight == 4 && newStyle.weight() == 350) || // GDI weirdness |
+ (weight == 5 && newStyle.weight() == 400) || // GDI weirdness |
+ (weight == 0 && newStyle.weight() == 1) || // DW weirdness |
+ (weight == 1000 && newStyle.weight() == 999) // DW weirdness |
+ ); |
+ |
+ // Some back-ends (GDI) don't support width, ensure these always report 'medium'. |
+ REPORTER_ASSERT(reporter, newStyle.width() == width || newStyle.width() == 5); |
+} |
+DEF_TEST(TypefaceStyle, reporter) { |
+ sk_sp<SkTypeface> typeface(MakeResourceAsTypeface("/fonts/Em.ttf")); |
+ if (!typeface) { |
+ REPORT_FAILURE(reporter, "/fonts/Em.ttf", SkString("Cannot load resource")); |
+ return; |
+ } |
+ std::unique_ptr<SkStreamAsset> stream(typeface->openStream(nullptr)); |
+ SkASSERT(stream); |
+ sk_sp<SkData> data(SkData::MakeFromStream(stream.get(), stream->getLength())); |
+ |
+ for (int weight = 0; weight <= 1000; ++weight) { |
+ TypefaceStyle_test(reporter, weight, 4, data.get()); |
+ } |
+ for (int width = SkFontStyle::kUltraCondensed_Width; width <= SkFontStyle::kUltaExpanded_Width; ++width) { |
+ TypefaceStyle_test(reporter, 400, width, data.get()); |
+ } |
+} |
+ |
DEF_TEST(Typeface, reporter) { |
sk_sp<SkTypeface> t1(SkTypeface::MakeFromName(nullptr, SkFontStyle())); |