Re: Use woff2 decoder in blink (issue 322433005)

16 views
Skip to first unread message

ba...@chromium.org

unread,
Sep 26, 2014, 12:00:35 AM9/26/14
to ksak...@chromium.org, dgla...@chromium.org, blink-...@chromium.org, jam...@chromium.org, dsch...@chromium.org, jbr...@chromium.org, dan...@chromium.org, caba...@adobe.com, sche...@chromium.org, p...@chromium.org, rob....@samsung.com
Reviewers: Kunihiko Sakamoto, dglazkov,

Message:
I'd like to revisit this CL. This blocks ksakamoto@'s ots roll for
https://codereview.chromium.org/512923003/

Description:
Use woff2 decoder in blink

To remove woff2 logic from ots.

BUG=371267

Please review this at https://codereview.chromium.org/322433005/

SVN Base: https://chromium.googlesource.com/chromium/blink.git@master

Affected files (+46, -12 lines):
M Source/platform/BUILD.gn
M Source/platform/DEPS
M Source/platform/blink_platform.gyp
M Source/platform/fonts/opentype/OpenTypeSanitizer.cpp


Index: Source/platform/BUILD.gn
diff --git a/Source/platform/BUILD.gn b/Source/platform/BUILD.gn
index
54ae27437530ca22db1eb8d54897e4420a2a04f3..c0dc7e26a442ae16bff02db7439761ed7fd8c84c
100644
--- a/Source/platform/BUILD.gn
+++ b/Source/platform/BUILD.gn
@@ -195,6 +195,7 @@ component("platform") {
"//gpu/command_buffer/client:gles2_c_lib",
"//skia",
"//third_party:jpeg",
+ "//third_party/brotli",
"//third_party/iccjpeg",
"//third_party/libpng",
"//third_party/libwebp",
Index: Source/platform/DEPS
diff --git a/Source/platform/DEPS b/Source/platform/DEPS
index
c1e622ae52a248af7adc9b42e0f16abf1b10637a..907dc3227ee83004034b2184808bbe0cffcc22cb
100644
--- a/Source/platform/DEPS
+++ b/Source/platform/DEPS
@@ -3,6 +3,7 @@ include_rules = [
"+platform",
"+public/platform",
"+skia/ext",
+ "+third_party/brotli",
"+third_party/khronos",
"+third_party/skia",
"+url",
Index: Source/platform/blink_platform.gyp
diff --git a/Source/platform/blink_platform.gyp
b/Source/platform/blink_platform.gyp
index
9f09481cc6a2af1ccd6bbbf9365f321c809a1244..7be9fc2bcb8109437075f16579cb3b70c03aeaf2
100644
--- a/Source/platform/blink_platform.gyp
+++ b/Source/platform/blink_platform.gyp
@@ -185,6 +185,7 @@
'blink_prerequisites',
'<(DEPTH)/gpu/gpu.gyp:gles2_c_lib',
'<(DEPTH)/skia/skia.gyp:skia',
+ '<(DEPTH)/third_party/brotli/brotli.gyp:woff2_dec',
'<(DEPTH)/third_party/icu/icu.gyp:icui18n',
'<(DEPTH)/third_party/icu/icu.gyp:icuuc',
'<(DEPTH)/third_party/libpng/libpng.gyp:libpng',
@@ -200,6 +201,7 @@
'export_dependent_settings': [
'<(DEPTH)/gpu/gpu.gyp:gles2_c_lib',
'<(DEPTH)/skia/skia.gyp:skia',
+ '<(DEPTH)/third_party/brotli/brotli.gyp:woff2_dec',
'<(DEPTH)/third_party/libpng/libpng.gyp:libpng',
'<(DEPTH)/third_party/libwebp/libwebp.gyp:libwebp',
'<(DEPTH)/third_party/ots/ots.gyp:ots',
Index: Source/platform/fonts/opentype/OpenTypeSanitizer.cpp
diff --git a/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp
b/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp
index
1a6724407b97f2f220026e263fbfe6f40b7e2bf8..45d7c9fe373a36e39e1be42cb0ea0868a8fdbb21
100644
--- a/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp
+++ b/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp
@@ -35,22 +35,26 @@
#include "platform/SharedBuffer.h"
#include "opentype-sanitiser.h"
#include "ots-memory-stream.h"
+#include "third_party/brotli/src/woff2/woff2_dec.h"
+#include "wtf/Vector.h"

namespace blink {

-PassRefPtr<SharedBuffer> OpenTypeSanitizer::sanitize()
-{
- if (!m_buffer)
- return nullptr;
+// This is the largest web font size which we'll try to transcode.
+static const size_t maxWebFontSize = 30 * 1024 * 1024; // 30 MB

- // This is the largest web font size which we'll try to transcode.
- static const size_t maxWebFontSize = 30 * 1024 * 1024; // 30 MB
- if (m_buffer->size() > maxWebFontSize)
- return nullptr;
+static bool isWoff2(SharedBuffer* buffer)
+{
+ static const size_t signatureSize = 4;
+ if (buffer->size() < signatureSize)
+ return false;

- if (RuntimeEnabledFeatures::woff2Enabled())
- ots::EnableWOFF2();
+ const char* signature = buffer->data();
+ return signature[0] == 'w' && signature[1] == 'O' && signature[2]
== 'F' && signature[3] == '2';
+}

+static PassRefPtr<SharedBuffer> transcode(const uint8_t* targetData,
size_t targetDataSize)
+{
// A transcoded font is usually smaller than an original font.
// However, it can be slightly bigger than the original one due to
// name table replacement and/or padding for glyf table.
@@ -58,14 +62,40 @@ PassRefPtr<SharedBuffer> OpenTypeSanitizer::sanitize()
// With WOFF fonts, however, we'll be decompressing, so the result can
be
// much larger than the original.

- ots::ExpandingMemoryStream output(m_buffer->size(), maxWebFontSize);
- if (!ots::Process(&output, reinterpret_cast<const
uint8_t*>(m_buffer->data()), m_buffer->size()))
+ ots::ExpandingMemoryStream output(targetDataSize, maxWebFontSize);
+ if (!ots::Process(&output, targetData, targetDataSize))
return nullptr;

const size_t transcodeLen = output.Tell();
return SharedBuffer::create(static_cast<unsigned char*>(output.get()),
transcodeLen);
}

+PassRefPtr<SharedBuffer> OpenTypeSanitizer::sanitize()
+{
+ if (!m_buffer)
+ return nullptr;
+
+ if (m_buffer->size() > maxWebFontSize)
+ return nullptr;
+
+ if (RuntimeEnabledFeatures::woff2Enabled())
+ ots::EnableWOFF2();
+
+ const uint8_t* originalData = reinterpret_cast<const
uint8_t*>(m_buffer->data());
+ size_t originalDataSize = m_buffer->size();
+ if (RuntimeEnabledFeatures::woff2Enabled() && isWoff2(m_buffer)) {
+ size_t woff2Size = woff2::ComputeWOFF2FinalSize(originalData,
originalDataSize);
+ if (woff2Size > maxWebFontSize)
+ return nullptr;
+
+ Vector<uint8_t> woff2Output(woff2Size);
+ if (!woff2::ConvertWOFF2ToTTF(woff2Output.data(), woff2Size,
originalData, originalDataSize))
+ return nullptr;
+ return transcode(woff2Output.data(), woff2Size);
+ }
+ return transcode(originalData, originalDataSize);
+}
+
bool OpenTypeSanitizer::supportsFormat(const String& format)
{
return equalIgnoringCase(format, "woff")


ba...@chromium.org

unread,
Sep 26, 2014, 12:02:45 AM9/26/14
to ksak...@chromium.org, dgla...@chromium.org, jam...@chromium.org, blink-...@chromium.org, jam...@chromium.org, dsch...@chromium.org, jbr...@chromium.org, dan...@chromium.org, caba...@adobe.com, sche...@chromium.org, p...@chromium.org, rob....@samsung.com
jamesr@, could you take a look (or suggest reviewers)?

https://codereview.chromium.org/322433005/
Reply all
Reply to author
Forward
0 new messages