Reviewed by Mark Rowe.
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Mar 2009 00:41:32 +0000 (00:41 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Mar 2009 00:41:32 +0000 (00:41 +0000)
        - fix <rdar://problem/6724514> A bit of OpenTypeUtilities cleanup

        * platform/graphics/chromium/FontCustomPlatformData.cpp:
        (WebCore::EOTStream::EOTStream): Changed to use EOTHeader.
        (WebCore::createFontCustomPlatformData): Ditto.
        * platform/graphics/opentype/OpenTypeUtilities.cpp:
        (WebCore::EOTHeader::EOTHeader): Added. Initializes the buffer size to
        the size of an EOTPrefix.
        (WebCore::EOTHeader::updateEOTSize): Added. Updates the size field in
        the prefix.
        (WebCore::EOTHeader::appendBigEndianString): Changed the static
        appendBigEndianStringToEOTHeader() into this member function.
        (WebCore::EOTHeader::appendPaddingShort): Added.
        (WebCore::getEOTHeader): Changed to use EOTHeader.
        * platform/graphics/opentype/OpenTypeUtilities.h:
        (WebCore::EOTHeader::size):
        (WebCore::EOTHeader::data):
        (WebCore::EOTHeader::prefix):
        * platform/graphics/win/FontCustomPlatformData.cpp:
        (WebCore::EOTStream::EOTStream): Changed to use EOTHeader.
        (WebCore::createFontCustomPlatformData): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@42060 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/graphics/chromium/FontCustomPlatformData.cpp
WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp
WebCore/platform/graphics/opentype/OpenTypeUtilities.h
WebCore/platform/graphics/win/FontCustomPlatformData.cpp

index 3dd59df..f3912b2 100644 (file)
@@ -1,3 +1,29 @@
+2009-03-27  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Mark Rowe.
+
+        - fix <rdar://problem/6724514> A bit of OpenTypeUtilities cleanup
+
+        * platform/graphics/chromium/FontCustomPlatformData.cpp:
+        (WebCore::EOTStream::EOTStream): Changed to use EOTHeader.
+        (WebCore::createFontCustomPlatformData): Ditto.
+        * platform/graphics/opentype/OpenTypeUtilities.cpp:
+        (WebCore::EOTHeader::EOTHeader): Added. Initializes the buffer size to
+        the size of an EOTPrefix.
+        (WebCore::EOTHeader::updateEOTSize): Added. Updates the size field in
+        the prefix.
+        (WebCore::EOTHeader::appendBigEndianString): Changed the static
+        appendBigEndianStringToEOTHeader() into this member function.
+        (WebCore::EOTHeader::appendPaddingShort): Added.
+        (WebCore::getEOTHeader): Changed to use EOTHeader.
+        * platform/graphics/opentype/OpenTypeUtilities.h:
+        (WebCore::EOTHeader::size):
+        (WebCore::EOTHeader::data):
+        (WebCore::EOTHeader::prefix):
+        * platform/graphics/win/FontCustomPlatformData.cpp:
+        (WebCore::EOTStream::EOTStream): Changed to use EOTHeader.
+        (WebCore::createFontCustomPlatformData): Ditto.
+
 2009-03-27  Darin Adler  <darin@apple.com>
 
         Reviewed by Sam Weinig.
index 1e923ac..e99c12a 100644 (file)
@@ -116,7 +116,7 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, b
 // Streams the concatenation of a header and font data.
 class EOTStream {
 public:
-    EOTStream(const Vector<uint8_t, 512>& eotHeader, const SharedBuffer* fontData, size_t overlayDst, size_t overlaySrc, size_t overlayLength)
+    EOTStream(const EOTHeader& eotHeader, const SharedBuffer* fontData, size_t overlayDst, size_t overlaySrc, size_t overlayLength)
         : m_eotHeader(eotHeader)
         , m_fontData(fontData)
         , m_overlayDst(overlayDst)
@@ -130,7 +130,7 @@ public:
     size_t read(void* buffer, size_t count);
 
 private:
-    const Vector<uint8_t, 512>& m_eotHeader;
+    const EOTHeader& m_eotHeader;
     const SharedBuffer* m_fontData;
     size_t m_overlayDst;
     size_t m_overlaySrc;
@@ -200,7 +200,7 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
 
     // TTLoadEmbeddedFont works only with Embedded OpenType (.eot) data,
     // so we need to create an EOT header and prepend it to the font data.
-    Vector<uint8_t, 512> eotHeader;
+    EOTHeader eotHeader;
     size_t overlayDst;
     size_t overlaySrc;
     size_t overlayLength;
index 16c3c00..895887f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Apple Inc.  All rights reserved.
+ * Copyright (C) 2008, 2009 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -161,11 +161,21 @@ struct nameTable {
 
 #pragma pack()
 
-static void appendBigEndianStringToEOTHeader(Vector<uint8_t, 512>& eotHeader, const BigEndianUShort* string, unsigned short length)
+EOTHeader::EOTHeader()
 {
-    size_t size = eotHeader.size();
-    eotHeader.resize(size + length + 2 * sizeof(unsigned short));
-    UChar* dst = reinterpret_cast<UChar*>(eotHeader.data() + size);
+    m_buffer.resize(sizeof(EOTPrefix));
+}
+
+void EOTHeader::updateEOTSize(size_t fontDataSize)
+{
+    prefix()->eotSize = m_buffer.size() + fontDataSize;
+}
+
+void EOTHeader::appendBigEndianString(const BigEndianUShort* string, unsigned short length)
+{
+    size_t oldSize = m_buffer.size();
+    m_buffer.resize(oldSize + length + 2 * sizeof(unsigned short));
+    UChar* dst = reinterpret_cast<UChar*>(m_buffer.data() + oldSize);
     unsigned i = 0;
     dst[i++] = length;
     unsigned numCharacters = length / 2;
@@ -174,7 +184,13 @@ static void appendBigEndianStringToEOTHeader(Vector<uint8_t, 512>& eotHeader, co
     dst[i] = 0;
 }
 
-bool getEOTHeader(SharedBuffer* fontData, Vector<uint8_t, 512>& eotHeader, size_t& overlayDst, size_t& overlaySrc, size_t& overlayLength)
+void EOTHeader::appendPaddingShort()
+{
+    unsigned short padding = 0;
+    m_buffer.append(reinterpret_cast<uint8_t*>(&padding), sizeof(padding));
+}
+
+bool getEOTHeader(SharedBuffer* fontData, EOTHeader& eotHeader, size_t& overlayDst, size_t& overlaySrc, size_t& overlayLength)
 {
     overlayDst = 0;
     overlaySrc = 0;
@@ -183,8 +199,7 @@ bool getEOTHeader(SharedBuffer* fontData, Vector<uint8_t, 512>& eotHeader, size_
     size_t dataLength = fontData->size();
     const char* data = fontData->data();
 
-    eotHeader.resize(sizeof(EOTPrefix));
-    EOTPrefix* prefix = reinterpret_cast<EOTPrefix*>(eotHeader.data());
+    EOTPrefix* prefix = eotHeader.prefix();
 
     prefix->fontDataSize = dataLength;
     prefix->version = 0x00020001;
@@ -306,9 +321,9 @@ bool getEOTHeader(SharedBuffer* fontData, Vector<uint8_t, 512>& eotHeader, size_
     prefix->reserved[3] = 0;
     prefix->padding1 = 0;
 
-    appendBigEndianStringToEOTHeader(eotHeader, familyName, familyNameLength);
-    appendBigEndianStringToEOTHeader(eotHeader, subfamilyName, subfamilyNameLength);
-    appendBigEndianStringToEOTHeader(eotHeader, versionString, versionStringLength);
+    eotHeader.appendBigEndianString(familyName, familyNameLength);
+    eotHeader.appendBigEndianString(subfamilyName, subfamilyNameLength);
+    eotHeader.appendBigEndianString(versionString, versionStringLength);
 
     // If possible, ensure that the family name is a prefix of the full name.
     if (fullNameLength >= familyNameLength && memcmp(familyName, fullName, familyNameLength)) {
@@ -316,13 +331,10 @@ bool getEOTHeader(SharedBuffer* fontData, Vector<uint8_t, 512>& eotHeader, size_
         overlayDst = reinterpret_cast<const char*>(familyName) - data;
         overlayLength = familyNameLength;
     }
+    eotHeader.appendBigEndianString(fullName, fullNameLength);
 
-    appendBigEndianStringToEOTHeader(eotHeader, fullName, fullNameLength);
-
-    unsigned short padding = 0;
-    eotHeader.append(reinterpret_cast<uint8_t*>(&padding), sizeof(padding));
-
-    prefix->eotSize = eotHeader.size() + fontData->size();
+    eotHeader.appendPaddingShort();
+    eotHeader.updateEOTSize(fontData->size());
 
     return true;
 }
index a67ffc7..13dad6f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Apple Inc.  All rights reserved.
+ * Copyright (C) 2008, 2009 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 namespace WebCore {
 
+struct BigEndianUShort;
+struct EOTPrefix;
 class SharedBuffer;
 
-bool getEOTHeader(SharedBuffer* fontData, Vector<uint8_t, 512>& eotHeader, size_t& overlayDst, size_t& overlaySrc, size_t& overlayLength);
+struct EOTHeader {
+    EOTHeader();
+
+    size_t size() const { return m_buffer.size(); }
+    const uint8_t* data() const { return m_buffer.data(); }
+
+    EOTPrefix* prefix() { return reinterpret_cast<EOTPrefix*>(m_buffer.data()); }
+    void updateEOTSize(size_t);
+    void appendBigEndianString(const BigEndianUShort*, unsigned short length);
+    void appendPaddingShort();
+
+private:
+    Vector<uint8_t, 512> m_buffer;
+};
+
+bool getEOTHeader(SharedBuffer* fontData, EOTHeader& eotHeader, size_t& overlayDst, size_t& overlaySrc, size_t& overlayLength);
 HANDLE renameAndActivateFont(SharedBuffer*, const String&);
 
 } // namespace WebCore
index 1ac3359..24db173 100644 (file)
@@ -116,7 +116,7 @@ size_t getBytesWithOffset(void *info, void* buffer, size_t offset, size_t count)
 // Streams the concatenation of a header and font data.
 class EOTStream {
 public:
-    EOTStream(const Vector<uint8_t, 512>& eotHeader, const SharedBuffer* fontData, size_t overlayDst, size_t overlaySrc, size_t overlayLength)
+    EOTStream(const EOTHeader& eotHeader, const SharedBuffer* fontData, size_t overlayDst, size_t overlaySrc, size_t overlayLength)
         : m_eotHeader(eotHeader)
         , m_fontData(fontData)
         , m_overlayDst(overlayDst)
@@ -130,7 +130,7 @@ public:
     size_t read(void* buffer, size_t count);
 
 private:
-    const Vector<uint8_t, 512>& m_eotHeader;
+    const EOTHeader& m_eotHeader;
     const SharedBuffer* m_fontData;
     size_t m_overlayDst;
     size_t m_overlaySrc;
@@ -206,7 +206,7 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
 
     // TTLoadEmbeddedFont works only with Embedded OpenType (.eot) data, so we need to create an EOT header
     // and prepend it to the font data.
-    Vector<uint8_t, 512> eotHeader;
+    EOTHeader eotHeader;
     size_t overlayDst;
     size_t overlaySrc;
     size_t overlayLength;