Title: [158519] trunk/Source/WebCore
Revision
158519
Author
par...@webkit.org
Date
2013-11-02 20:24:47 -0700 (Sat, 02 Nov 2013)

Log Message

Cleanup OpenTypeUtilities
https://bugs.webkit.org/show_bug.cgi?id=123686

Reviewed by Darin Adler.

Merge the WinCE specific code into the general Windows code to
make the compilation of WinCE port on WinNT easier.

* platform/graphics/opentype/OpenTypeUtilities.cpp:
(WebCore::renameFont):
(WebCore::renameAndActivateFont):
* platform/graphics/opentype/OpenTypeUtilities.h:
* platform/graphics/win/FontCustomPlatformData.cpp:
(WebCore::createFontCustomPlatformData):
* platform/graphics/win/FontCustomPlatformDataCairo.cpp:
(WebCore::createFontCustomPlatformData):
* platform/graphics/wince/FontCustomPlatformData.cpp:
(WebCore::createFontCustomPlatformData):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (158518 => 158519)


--- trunk/Source/WebCore/ChangeLog	2013-11-03 03:19:32 UTC (rev 158518)
+++ trunk/Source/WebCore/ChangeLog	2013-11-03 03:24:47 UTC (rev 158519)
@@ -1,3 +1,24 @@
+2013-11-02  Patrick Gansterer  <par...@webkit.org>
+
+        Cleanup OpenTypeUtilities
+        https://bugs.webkit.org/show_bug.cgi?id=123686
+
+        Reviewed by Darin Adler.
+
+        Merge the WinCE specific code into the general Windows code to
+        make the compilation of WinCE port on WinNT easier.
+
+        * platform/graphics/opentype/OpenTypeUtilities.cpp:
+        (WebCore::renameFont):
+        (WebCore::renameAndActivateFont):
+        * platform/graphics/opentype/OpenTypeUtilities.h:
+        * platform/graphics/win/FontCustomPlatformData.cpp:
+        (WebCore::createFontCustomPlatformData):
+        * platform/graphics/win/FontCustomPlatformDataCairo.cpp:
+        (WebCore::createFontCustomPlatformData):
+        * platform/graphics/wince/FontCustomPlatformData.cpp:
+        (WebCore::createFontCustomPlatformData):
+
 2013-11-02  Andreas Kling  <akl...@apple.com>
 
         CSSFontFaceSrcValue constructors should return PassRef.

Modified: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp (158518 => 158519)


--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp	2013-11-03 03:19:32 UTC (rev 158518)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp	2013-11-03 03:24:47 UTC (rev 158519)
@@ -340,30 +340,37 @@
     return true;
 }
 
-// code shared by renameFont and renameAndActivateFont
 // adds fontName to the font table in fontData, and writes the new font table to rewrittenFontTable
 // returns the size of the name table (which is used by renameAndActivateFont), or 0 on early abort
-static size_t renameFontInternal(SharedBuffer* fontData, const String& fontName, Vector<char> &rewrittenFontData)
+bool renameFont(const SharedBuffer& fontData, const String& fontName, Vector<char>& rewrittenFontData)
 {
-    size_t originalDataSize = fontData->size();
-    const sfntHeader* sfnt = reinterpret_cast<const sfntHeader*>(fontData->data());
+    size_t originalDataSize = fontData.size();
+    const sfntHeader* sfnt = reinterpret_cast<const sfntHeader*>(fontData.data());
 
+    // Abort if the data is too small to be a font header with a "tables" entry.
+    if (originalDataSize < offsetof(sfntHeader, tables))
+        return false;
+
+    // Abort if the data is too small to hold all the tables specified in the header.
+    if (originalDataSize < offsetof(sfntHeader, tables) + sfnt->numTables * sizeof(TableDirectoryEntry))
+        return false;
+
     unsigned t;
     for (t = 0; t < sfnt->numTables; ++t) {
         if (sfnt->tables[t].tag == 'name')
             break;
     }
     if (t == sfnt->numTables)
-        return 0;
+        return false;
 
     const int nameRecordCount = 5;
 
     // Rounded up to a multiple of 4 to simplify the checksum calculation.
     size_t nameTableSize = ((offsetof(nameTable, nameRecords) + nameRecordCount * sizeof(nameRecord) + fontName.length() * sizeof(UChar)) & ~3) + 4;
 
-    rewrittenFontData.resize(fontData->size() + nameTableSize);
+    rewrittenFontData.resize(fontData.size() + nameTableSize);
     char* data = ""
-    memcpy(data, fontData->data(), originalDataSize);
+    memcpy(data, fontData.data(), originalDataSize);
 
     // Make the table directory entry point to the new 'name' table.
     sfntHeader* rewrittenSfnt = reinterpret_cast<sfntHeader*>(data);
@@ -398,42 +405,19 @@
     for (unsigned i = 0; i * sizeof(BigEndianULong) < nameTableSize; ++i)
         rewrittenSfnt->tables[t].checkSum = rewrittenSfnt->tables[t].checkSum + reinterpret_cast<BigEndianULong*>(name)[i];
 
-    return nameTableSize;
-}
-
-#if OS(WINCE)
-// AddFontMemResourceEx does not exist on WinCE, so we must handle the font data manually
-// This function just renames the font and overwrites the old font data with the new
-bool renameFont(SharedBuffer* fontData, const String& fontName)
-{
-    // abort if the data is too small to be a font header with a "tables" entry
-    if (fontData->size() < offsetof(sfntHeader, tables))
-        return false;
-
-    // abort if the data is too small to hold all the tables specified in the header
-    const sfntHeader* header = reinterpret_cast<const sfntHeader*>(fontData->data());
-    if (fontData->size() < offsetof(sfntHeader, tables) + header->numTables * sizeof(TableDirectoryEntry))
-        return false;
-
-    Vector<char> rewrittenFontData;
-    if (!renameFontInternal(fontData, fontName, rewrittenFontData))
-        return false;
-
-    fontData->clear();
-    fontData->append(rewrittenFontData.data(), rewrittenFontData.size());
     return true;
 }
-#else
+
+#if !OS(WINCE)
 // Rename the font and install the new font data into the system
-HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName)
+HANDLE renameAndActivateFont(const SharedBuffer& fontData, const String& fontName)
 {
     Vector<char> rewrittenFontData;
-    size_t nameTableSize = renameFontInternal(fontData, fontName, rewrittenFontData);
-    if (!nameTableSize)
+    if (!renameFont(fontData, fontName, rewrittenFontData))
         return 0;
 
     DWORD numFonts = 0;
-    HANDLE fontHandle = AddFontMemResourceEx(rewrittenFontData.data(), fontData->size() + nameTableSize, 0, &numFonts);
+    HANDLE fontHandle = AddFontMemResourceEx(rewrittenFontData.data(), rewrittenFontData.size(), 0, &numFonts);
 
     if (fontHandle && numFonts < 1) {
         RemoveFontMemResourceEx(fontHandle);

Modified: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeUtilities.h (158518 => 158519)


--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeUtilities.h	2013-11-03 03:19:32 UTC (rev 158518)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeUtilities.h	2013-11-03 03:24:47 UTC (rev 158519)
@@ -57,7 +57,8 @@
 };
 
 bool getEOTHeader(SharedBuffer* fontData, EOTHeader& eotHeader, size_t& overlayDst, size_t& overlaySrc, size_t& overlayLength);
-HANDLE renameAndActivateFont(SharedBuffer*, const String&);
+bool renameFont(const SharedBuffer&, const String&, Vector<char>&);
+HANDLE renameAndActivateFont(const SharedBuffer&, const String&);
 
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp (158518 => 158519)


--- trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp	2013-11-03 03:19:32 UTC (rev 158518)
+++ trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp	2013-11-03 03:24:47 UTC (rev 158519)
@@ -97,7 +97,7 @@
 
     String fontName = createUniqueFontName();
     HANDLE fontReference;
-    fontReference = renameAndActivateFont(buffer, fontName);
+    fontReference = renameAndActivateFont(*buffer, fontName);
     if (!fontReference)
         return nullptr;
     return std::make_unique<FontCustomPlatformData>(fontReference, fontName);

Modified: trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp (158518 => 158519)


--- trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp	2013-11-03 03:19:32 UTC (rev 158518)
+++ trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp	2013-11-03 03:24:47 UTC (rev 158519)
@@ -85,7 +85,7 @@
     ASSERT_ARG(buffer, buffer);
 
     String fontName = createUniqueFontName();
-    HANDLE fontReference = renameAndActivateFont(buffer, fontName);
+    HANDLE fontReference = renameAndActivateFont(*buffer, fontName);
 
     if (!fontReference)
         return nullptr;

Modified: trunk/Source/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp (158518 => 158519)


--- trunk/Source/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp	2013-11-03 03:19:32 UTC (rev 158518)
+++ trunk/Source/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp	2013-11-03 03:24:47 UTC (rev 158519)
@@ -24,6 +24,7 @@
 
 #include "CachedFont.h"
 #include "FontPlatformData.h"
+#include "OpenTypeUtilities.h"
 #include "SharedBuffer.h"
 #include <wtf/RandomNumber.h>
 #include <wtf/text/Base64.h>
@@ -32,8 +33,6 @@
 
 static CustomFontCache* g_customFontCache = 0;
 
-bool renameFont(SharedBuffer* fontData, const String& fontName);
-
 void setCustomFontCache(CustomFontCache* cache)
 {
     g_customFontCache = cache;
@@ -72,13 +71,19 @@
 
 std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(const SharedBuffer* buffer)
 {
-    if (g_customFontCache) {
-        String fontName = createUniqueFontName();
-        RefPtr<SharedBuffer> localBuffer = SharedBuffer::create(buffer->data(), buffer->size());
-        if (renameFont(localBuffer.get(), fontName) && g_customFontCache->registerFont(fontName, localBuffer.get()))
-            return std::make_unique<FontCustomPlatformData>(fontName);
-    }
-    return nullptr;
+    ASSERT_ARG(buffer, buffer);
+
+    String fontName = createUniqueFontName();
+
+    Vector<char> rewrittenFontData;
+    if (!renameFont(*buffer, fontName, rewrittenFontData))
+        return nullptr;
+
+    RefPtr<SharedBuffer> localBuffer = SharedBuffer::adoptVector(rewrittenFontData);
+    if (!g_customFontCache || !g_customFontCache->registerFont(fontName, localBuffer.get()))
+        return nullptr;
+
+    return std::make_unique<FontCustomPlatformData>(fontName);
 }
 
 bool FontCustomPlatformData::supportsFormat(const String& format)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to