remove GetTable* APIs from SkFontHost, and rely on SkTypeface::onGetTable*
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 21 Mar 2013 20:34:27 +0000 (20:34 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 21 Mar 2013 20:34:27 +0000 (20:34 +0000)
default impls call SkFontStream, and rely on SkTypeface::onOpenStream
Review URL: https://codereview.chromium.org/13001002

git-svn-id: http://skia.googlecode.com/svn/trunk@8310 2bbb7eff-a529-9590-31e7-b0007b416f81

gyp/ports.gyp
include/core/SkFontHost.h
src/core/SkTypeface.cpp
src/ports/SkFontHost_fontconfig.cpp
src/ports/SkFontHost_mac.cpp
src/ports/SkFontHost_tables.cpp [deleted file]
src/ports/SkHarfBuzzFont.cpp

index 83c6c5173cf6a896654bf8afc49adbf4267f2285..49b278de21e2d4aed94aee0ec7f4dac781c7eb58 100644 (file)
@@ -30,7 +30,6 @@
         '../src/ports/SkPurgeableMemoryBlock_none.cpp',
         '../src/ports/SkThread_win.cpp',
 
-        '../src/ports/SkFontHost_tables.cpp',
         '../src/ports/SkMemory_malloc.cpp',
         '../src/ports/SkOSFile_stdio.cpp',
         '../src/ports/SkTime_Unix.cpp',
@@ -58,9 +57,6 @@
             '../src/ports/SkFontConfigInterface_direct.cpp',
             '../src/ports/SkThread_pthread.cpp',
           ],
-          'sources!': [
-            '../src/ports/SkFontHost_tables.cpp',
-          ],
         }],
         [ 'skia_os == "nacl"', {
           'dependencies': [
index 30852f22f64ee9da6694f70232f0f3856d1c29f8..3939cc4d35949a2a521ca8ba92d9dcd6957fe1d2 100644 (file)
@@ -225,43 +225,6 @@ private:
             const uint32_t* glyphIDs,
             uint32_t glyphIDsCount);
 
-    /** Return the number of tables in the font
-     */
-    static int CountTables(SkFontID);
-
-    /** Copy into tags[] (allocated by the caller) the list of table tags in
-        the font, and return the number. This will be the same as CountTables()
-        or 0 if an error occured.
-     */
-    static int GetTableTags(SkFontID, SkFontTableTag[]);
-
-    /** Given a table tag, return the size of its contents, or 0 if not present
-     */
-    static size_t GetTableSize(SkFontID, SkFontTableTag);
-
-    /** Copy the contents of a table into data (allocated by the caller). Note
-        that the contents of the table will be in their native endian order
-        (which for most truetype tables is big endian). If the table tag is
-        not found, or there is an error copying the data, then 0 is returned.
-        If this happens, it is possible that some or all of the memory pointed
-        to by data may have been written to, even though an error has occured.
-
-        @param fontID the font to copy the table from
-        @param tag  The table tag whose contents are to be copied
-        @param offset The offset in bytes into the table's contents where the
-                copy should start from.
-        @param length The number of bytes, starting at offset, of table data
-                to copy.
-        @param data storage address where the table contents are copied to
-        @return the number of bytes actually copied into data. If offset+length
-                exceeds the table's size, then only the bytes up to the table's
-                size are actually copied, and this is the value returned. If
-                offset > the table's size, or tag is not a valid table,
-                then 0 is returned.
-     */
-    static size_t GetTableData(SkFontID fontID, SkFontTableTag tag,
-                               size_t offset, size_t length, void* data);
-
     ///////////////////////////////////////////////////////////////////////////
 
     friend class SkTypeface;
index 4a3dd4fe11b3ca223dce7ed692527609072da6bb..5632bbc6d74e8ccf22ca00a5c47ccd93ca2337ae 100644 (file)
@@ -106,20 +106,20 @@ SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics(
 ///////////////////////////////////////////////////////////////////////////////
 
 int SkTypeface::countTables() const {
-    return SkFontHost::CountTables(fUniqueID);
+    return this->onGetTableTags(NULL);
 }
 
 int SkTypeface::getTableTags(SkFontTableTag tags[]) const {
-    return SkFontHost::GetTableTags(fUniqueID, tags);
+    return this->onGetTableTags(tags);
 }
 
 size_t SkTypeface::getTableSize(SkFontTableTag tag) const {
-    return SkFontHost::GetTableSize(fUniqueID, tag);
+    return this->onGetTableData(tag, 0, ~0U, NULL);
 }
 
 size_t SkTypeface::getTableData(SkFontTableTag tag, size_t offset, size_t length,
                                 void* data) const {
-    return SkFontHost::GetTableData(fUniqueID, tag, offset, length, data);
+    return this->onGetTableData(tag, offset, length, data);
 }
 
 SkStream* SkTypeface::openStream(int* ttcIndex) const {
@@ -164,10 +164,25 @@ SkStream* SkTypeface::onOpenStream(int* ttcIndex) const {
     return SkFontHost::OpenStream(fUniqueID);
 }
 
-int SkTypeface::onGetTableTags(SkFontTableTag tags[]) const { return 0; }
-size_t SkTypeface::onGetTableData(SkFontTableTag, size_t offset,
-                                  size_t length, void* data) const { return 0; }
 void SkTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const {
     desc->setStyle(this->style());
 }
 
+#include "SkFontStream.h"
+#include "SkStream.h"
+
+int SkTypeface::onGetTableTags(SkFontTableTag tags[]) const {
+    int ttcIndex;
+    SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex));
+    return stream.get() ? SkFontStream::GetTableTags(stream, ttcIndex, tags) : 0;
+}
+
+size_t SkTypeface::onGetTableData(SkFontTableTag tag, size_t offset,
+                                  size_t length, void* data) const {
+    int ttcIndex;
+    SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex));
+    return stream.get()
+        ? SkFontStream::GetTableData(stream, ttcIndex, tag, offset, length, data)
+        : 0;
+}
+
index ea0971018a3eaee439ef6b6d9b4733c8ebc25b30..8cdca1e5842f043b049d531d5393cc27c81797c5 100644 (file)
@@ -175,31 +175,6 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
 
 ///////////////////////////////////////////////////////////////////////////////
 
-// DEPRECATED
-int SkFontHost::CountTables(SkFontID fontID) {
-    SkTypeface* face = SkTypefaceCache::FindByID(fontID);
-    return face ? face->onGetTableTags(NULL) : 0;
-}
-
-// DEPRECATED
-int SkFontHost::GetTableTags(SkFontID fontID, SkFontTableTag tags[]) {
-    SkTypeface* face = SkTypefaceCache::FindByID(fontID);
-    return face ? face->onGetTableTags(tags) : 0;
-}
-
-// DEPRECATED
-size_t SkFontHost::GetTableSize(SkFontID fontID, SkFontTableTag tag) {
-    SkTypeface* face = SkTypefaceCache::FindByID(fontID);
-    return face ? face->onGetTableData(tag, 0, ~0U, NULL) : 0;
-}
-
-// DEPRECATED
-size_t SkFontHost::GetTableData(SkFontID fontID, SkFontTableTag tag,
-                                size_t offset, size_t length, void* dst) {
-    SkTypeface* face = SkTypefaceCache::FindByID(fontID);
-    return face ? face->onGetTableData(tag, offset, length, dst) : 0;
-}
-
 // DEPRECATED
 SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID curr, SkFontID orig) {
     // We don't handle font fallback.
@@ -304,3 +279,4 @@ void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const {
     desc->setStyle(this->style());
     desc->setFamilyName(this->getFamilyName());
 }
+
index 9bc757cb9c64f3f541a26c5e79fda89b19a84b5f..8f93c0e5d3e45e5700a09b53bd7ac8ddd664542e 100755 (executable)
@@ -1728,31 +1728,6 @@ SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFo
     return SkSafeRef(face);
 }
 
-// DEPRECATED
-int SkFontHost::CountTables(SkFontID fontID) {
-    SkTypeface* face = SkTypefaceCache::FindByID(fontID);
-    return face ? face->onGetTableTags(NULL) : 0;
-}
-
-// DEPRECATED
-int SkFontHost::GetTableTags(SkFontID fontID, SkFontTableTag tags[]) {
-    SkTypeface* face = SkTypefaceCache::FindByID(fontID);
-    return face ? face->onGetTableTags(tags) : 0;
-}
-
-// DEPRECATED
-size_t SkFontHost::GetTableSize(SkFontID fontID, SkFontTableTag tag) {
-    SkTypeface* face = SkTypefaceCache::FindByID(fontID);
-    return face ? face->onGetTableData(tag, 0, ~0U, NULL) : 0;
-}
-
-// DEPRECATED
-size_t SkFontHost::GetTableData(SkFontID fontID, SkFontTableTag tag,
-                                size_t offset, size_t length, void* dst) {
-    SkTypeface* face = SkTypefaceCache::FindByID(fontID);
-    return face ? face->onGetTableData(tag, offset, length, dst) : 0;
-}
-
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
 
diff --git a/src/ports/SkFontHost_tables.cpp b/src/ports/SkFontHost_tables.cpp
deleted file mode 100644 (file)
index 9ddf6c0..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkEndian.h"
-#include "SkFontHost.h"
-#include "SkFontStream.h"
-#include "SkStream.h"
-
-int SkFontHost::CountTables(SkFontID fontID) {
-    SkStream* stream = SkFontHost::OpenStream(fontID);
-    if (NULL == stream) {
-        return 0;
-    }
-
-    SkAutoUnref au(stream);
-    int ttcIndex = 0;
-    return SkFontStream::GetTableTags(stream, ttcIndex, NULL);
-}
-
-int SkFontHost::GetTableTags(SkFontID fontID, SkFontTableTag tags[]) {
-    SkStream* stream = SkFontHost::OpenStream(fontID);
-    if (NULL == stream) {
-        return 0;
-    }
-
-    SkAutoUnref au(stream);
-    int ttcIndex = 0;
-    return SkFontStream::GetTableTags(stream, ttcIndex, tags);
-}
-
-size_t SkFontHost::GetTableSize(SkFontID fontID, SkFontTableTag tag) {
-    SkStream* stream = SkFontHost::OpenStream(fontID);
-    if (NULL == stream) {
-        return 0;
-    }
-
-    SkAutoUnref au(stream);
-    int ttcIndex = 0;
-    return SkFontStream::GetTableData(stream, ttcIndex, tag, 0, ~0U, NULL);
-}
-
-size_t SkFontHost::GetTableData(SkFontID fontID, SkFontTableTag tag,
-                                size_t offset, size_t length, void* data) {
-    SkStream* stream = SkFontHost::OpenStream(fontID);
-    if (NULL == stream) {
-        return 0;
-    }
-
-    SkAutoUnref au(stream);
-    int ttcIndex = 0;
-    return SkFontStream::GetTableData(stream, ttcIndex, tag, offset, length, data);
-}
index b5cd0f7f9e858a31f533946ab6e6802fb0a5ca76..4e6f48da0dee33613fce4108b3ef76eaad9fff2f 100644 (file)
@@ -166,9 +166,9 @@ const HB_FontClass& SkHarfBuzzFont::GetFontClass() {
 HB_Error SkHarfBuzzFont::GetFontTableFunc(void* voidface, const HB_Tag tag,
                                           HB_Byte* buffer, HB_UInt* len) {
     SkHarfBuzzFont* font = reinterpret_cast<SkHarfBuzzFont*>(voidface);
-    uint32_t uniqueID = SkTypeface::UniqueID(font->getTypeface());
+    SkTypeface* typeface = font->getTypeface();
 
-    const size_t tableSize = SkFontHost::GetTableSize(uniqueID, tag);
+    const size_t tableSize = typeface->getTableSize(tag);
     if (!tableSize) {
         return HB_Err_Invalid_Argument;
     }
@@ -182,6 +182,7 @@ HB_Error SkHarfBuzzFont::GetFontTableFunc(void* voidface, const HB_Tag tag,
         // is this right, or should we just copy less than the full table?
         return HB_Err_Invalid_Argument;
     }
-    SkFontHost::GetTableData(uniqueID, tag, 0, tableSize, buffer);
+    typeface->getTableData(tag, 0, tableSize, buffer);
     return HB_Err_Ok;
 }
+