summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/graphics/WOFFFileFormat.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/platform/graphics/WOFFFileFormat.cpp')
-rw-r--r--Source/WebCore/platform/graphics/WOFFFileFormat.cpp76
1 files changed, 56 insertions, 20 deletions
diff --git a/Source/WebCore/platform/graphics/WOFFFileFormat.cpp b/Source/WebCore/platform/graphics/WOFFFileFormat.cpp
index 61a58b904..c2323cf04 100644
--- a/Source/WebCore/platform/graphics/WOFFFileFormat.cpp
+++ b/Source/WebCore/platform/graphics/WOFFFileFormat.cpp
@@ -37,25 +37,25 @@
namespace WebCore {
-static bool readUInt32(SharedBuffer* buffer, size_t& offset, uint32_t& value)
+static bool readUInt32(SharedBuffer& buffer, size_t& offset, uint32_t& value)
{
- ASSERT_ARG(offset, offset <= buffer->size());
- if (buffer->size() - offset < sizeof(value))
+ ASSERT_ARG(offset, offset <= buffer.size());
+ if (buffer.size() - offset < sizeof(value))
return false;
- value = ntohl(*reinterpret_cast_ptr<const uint32_t*>(buffer->data() + offset));
+ value = ntohl(*reinterpret_cast_ptr<const uint32_t*>(buffer.data() + offset));
offset += sizeof(value);
return true;
}
-static bool readUInt16(SharedBuffer* buffer, size_t& offset, uint16_t& value)
+static bool readUInt16(SharedBuffer& buffer, size_t& offset, uint16_t& value)
{
- ASSERT_ARG(offset, offset <= buffer->size());
- if (buffer->size() - offset < sizeof(value))
+ ASSERT_ARG(offset, offset <= buffer.size());
+ if (buffer.size() - offset < sizeof(value))
return false;
- value = ntohs(*reinterpret_cast_ptr<const uint16_t*>(buffer->data() + offset));
+ value = ntohs(*reinterpret_cast_ptr<const uint16_t*>(buffer.data() + offset));
offset += sizeof(value);
return true;
@@ -75,7 +75,7 @@ static bool writeUInt16(Vector<char>& vector, uint16_t value)
static const uint32_t woffSignature = 0x774f4646; /* 'wOFF' */
-bool isWOFF(SharedBuffer* buffer)
+bool isWOFF(SharedBuffer& buffer)
{
size_t offset = 0;
uint32_t signature;
@@ -90,7 +90,43 @@ bool isWOFF(SharedBuffer* buffer)
#endif
}
-bool convertWOFFToSfnt(SharedBuffer* woff, Vector<char>& sfnt)
+#if USE(WOFF2)
+class WOFF2VectorOut : public woff2::WOFF2Out {
+public:
+ WOFF2VectorOut(Vector<char>& vector)
+ : m_vector(vector)
+ { }
+
+ bool Write(const void* data, size_t n) override
+ {
+ if (!m_vector.tryReserveCapacity(m_vector.size() + n))
+ return false;
+ m_vector.append(static_cast<const char*>(data), n);
+ return true;
+ }
+
+ bool Write(const void* data, size_t offset, size_t n) override
+ {
+ if (!m_vector.tryReserveCapacity(offset + n))
+ return false;
+ if (offset + n > m_vector.size())
+ m_vector.resize(offset + n);
+ m_vector.remove(offset, n);
+ m_vector.insert(offset, static_cast<const char*>(data), n);
+ return true;
+ }
+
+ size_t Size() override
+ {
+ return m_vector.size();
+ }
+
+private:
+ Vector<char>& m_vector;
+};
+#endif
+
+bool convertWOFFToSfnt(SharedBuffer& woff, Vector<char>& sfnt)
{
ASSERT_ARG(sfnt, sfnt.isEmpty());
@@ -105,15 +141,15 @@ bool convertWOFFToSfnt(SharedBuffer* woff, Vector<char>& sfnt)
#if USE(WOFF2)
if (signature == woff2::kWoff2Signature) {
- const uint8_t* woffData = reinterpret_cast_ptr<const uint8_t*>(woff->data());
- const size_t woffSize = woff->size();
+ const uint8_t* woffData = reinterpret_cast_ptr<const uint8_t*>(woff.data());
+ const size_t woffSize = woff.size();
const size_t sfntSize = woff2::ComputeWOFF2FinalSize(woffData, woffSize);
if (!sfnt.tryReserveCapacity(sfntSize))
return false;
- sfnt.resize(sfntSize);
- return woff2::ConvertWOFF2ToTTF(reinterpret_cast<uint8_t*>(sfnt.data()), sfnt.size(), woffData, woffSize);
+ WOFF2VectorOut out(sfnt);
+ return woff2::ConvertWOFF2ToTTF(woffData, woffSize, &out);
}
#endif
@@ -127,7 +163,7 @@ bool convertWOFFToSfnt(SharedBuffer* woff, Vector<char>& sfnt)
return false;
uint32_t length;
- if (!readUInt32(woff, offset, length) || length != woff->size())
+ if (!readUInt32(woff, offset, length) || length != woff.size())
return false;
uint16_t numTables;
@@ -145,7 +181,7 @@ bool convertWOFFToSfnt(SharedBuffer* woff, Vector<char>& sfnt)
if (!readUInt32(woff, offset, totalSfntSize))
return false;
- if (woff->size() - offset < sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t))
+ if (woff.size() - offset < sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t))
return false;
offset += sizeof(uint16_t); // majorVersion
@@ -157,7 +193,7 @@ bool convertWOFFToSfnt(SharedBuffer* woff, Vector<char>& sfnt)
offset += sizeof(uint32_t); // privLength
// Check if the WOFF can supply as many tables as it claims it has.
- if (woff->size() - offset < numTables * 5 * sizeof(uint32_t))
+ if (woff.size() - offset < numTables * 5 * sizeof(uint32_t))
return false;
// Write the sfnt offset subtable.
@@ -201,7 +237,7 @@ bool convertWOFFToSfnt(SharedBuffer* woff, Vector<char>& sfnt)
if (!readUInt32(woff, offset, tableCompLength))
return false;
- if (tableOffset > woff->size() || tableCompLength > woff->size() - tableOffset)
+ if (tableOffset > woff.size() || tableCompLength > woff.size() - tableOffset)
return false;
uint32_t tableOrigLength;
@@ -225,7 +261,7 @@ bool convertWOFFToSfnt(SharedBuffer* woff, Vector<char>& sfnt)
if (tableCompLength == tableOrigLength) {
// The table is not compressed.
- if (!sfnt.tryAppend(woff->data() + tableOffset, tableCompLength))
+ if (!sfnt.tryAppend(woff.data() + tableOffset, tableCompLength))
return false;
} else {
uLongf destLen = tableOrigLength;
@@ -233,7 +269,7 @@ bool convertWOFFToSfnt(SharedBuffer* woff, Vector<char>& sfnt)
return false;
Bytef* dest = reinterpret_cast<Bytef*>(sfnt.end());
sfnt.grow(sfnt.size() + tableOrigLength);
- if (uncompress(dest, &destLen, reinterpret_cast<const Bytef*>(woff->data() + tableOffset), tableCompLength) != Z_OK)
+ if (uncompress(dest, &destLen, reinterpret_cast<const Bytef*>(woff.data() + tableOffset), tableCompLength) != Z_OK)
return false;
if (destLen != tableOrigLength)
return false;