diff options
-rw-r--r-- | include/core/SkTypeface.h | 8 | ||||
-rw-r--r-- | src/core/SkTypeface.cpp | 18 | ||||
-rw-r--r-- | tests/FontHostTest.cpp | 17 |
3 files changed, 42 insertions, 1 deletions
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index 9693219aa7..73794dbcdc 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -176,7 +176,13 @@ public: */ size_t getTableData(SkFontTableTag tag, size_t offset, size_t length, void* data) const; - + + /** + * Return the units-per-em value for this typeface, or zero if there is an + * error. + */ + int getUnitsPerEm() const; + protected: /** uniqueID must be unique (please!) and non-zero */ diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index 66e7904cd2..3a40e0130b 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -117,3 +117,21 @@ size_t SkTypeface::getTableData(SkFontTableTag tag, size_t offset, size_t length return SkFontHost::GetTableData(fUniqueID, tag, offset, length, data); } +int SkTypeface::getUnitsPerEm() const { + int upem = 0; + +#ifdef SK_BUILD_FOR_ANDROID + upem = SkFontHost::GetUnitsPerEm(fUniqueID); +#else + SkAdvancedTypefaceMetrics* metrics; + metrics = SkFontHost::GetAdvancedTypefaceMetrics(fUniqueID, + SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo, + NULL, 0); + if (metrics) { + upem = metrics->fEmSize; + metrics->unref(); + } +#endif + return upem; +} + diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp index 260956fe57..fcdeaba1a5 100644 --- a/tests/FontHostTest.cpp +++ b/tests/FontHostTest.cpp @@ -8,6 +8,7 @@ #include "Test.h" #include "SkPaint.h" #include "SkTypeface.h" +#include "SkEndian.h" //#define DUMP_TABLES @@ -24,6 +25,21 @@ static const struct TagSize { { kFontTableTag_maxp, 32 }, }; +static void test_unitsPerEm(skiatest::Reporter* reporter, SkTypeface* face) { + int upem = face->getUnitsPerEm(); + REPORTER_ASSERT(reporter, upem > 0); + + size_t size = face->getTableSize(kFontTableTag_head); + if (size) { + SkAutoMalloc storage(size); + char* ptr = (char*)storage.get(); + face->getTableData(kFontTableTag_head, 0, size, ptr); + // unitsPerEm is at offset 18 into the 'head' table. + int upem2 = SkEndian_SwapBE16(*(uint16_t*)&ptr[18]); + REPORTER_ASSERT(reporter, upem2 == upem); + } +} + static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) { SkFontID fontID = face->uniqueID(); if (false) { // avoid bit rot, suppress warning @@ -82,6 +98,7 @@ static void test_tables(skiatest::Reporter* reporter) { SkDebugf("%s\n", gNames[i]); #endif test_tables(reporter, face); + test_unitsPerEm(reporter, face); face->unref(); } } |