Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Unified Diff: Source/platform/fonts/opentype/OpenTypeSanitizer.cpp

Issue 983973004: Provide user friendly messages for OTS parsing of fonts (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase patch Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/fonts/opentype/OpenTypeSanitizer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/fonts/opentype/OpenTypeSanitizer.cpp
diff --git a/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp b/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp
index c5e71ae45976e36add0d0c78f017cdfcaa0c23f9..58684434fe2a1178ef29aca53734b60f366748d7 100644
--- a/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp
+++ b/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp
@@ -58,13 +58,17 @@ static void recordDecodeSpeedHistogram(SharedBuffer* buffer, double decodeTime,
PassRefPtr<SharedBuffer> OpenTypeSanitizer::sanitize()
{
- if (!m_buffer)
+ if (!m_buffer) {
+ setErrorString("Empty 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
- if (m_buffer->size() > maxWebFontSize)
+ if (m_buffer->size() > maxWebFontSize) {
+ setErrorString("Web font size more than 30MB");
return nullptr;
+ }
// A transcoded font is usually smaller than an original font.
// However, it can be slightly bigger than the original one due to
@@ -77,8 +81,10 @@ PassRefPtr<SharedBuffer> OpenTypeSanitizer::sanitize()
double start = currentTime();
BlinkOTSContext otsContext;
- if (!otsContext.Process(&output, reinterpret_cast<const uint8_t*>(m_buffer->data()), m_buffer->size()))
+ if (!otsContext.Process(&output, reinterpret_cast<const uint8_t*>(m_buffer->data()), m_buffer->size())) {
+ setErrorString(otsContext.getErrorString());
return nullptr;
+ }
const size_t transcodeLen = output.Tell();
recordDecodeSpeedHistogram(m_buffer, currentTime() - start, transcodeLen);
@@ -90,4 +96,54 @@ bool OpenTypeSanitizer::supportsFormat(const String& format)
return equalIgnoringCase(format, "woff") || equalIgnoringCase(format, "woff2");
}
+void BlinkOTSContext::Message(int level, const char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+
+#if COMPILER(MSVC)
+ int result = _vscprintf(format, args);
+#else
+ char ch;
+ int result = vsnprintf(&ch, 1, format, args);
+#endif
+ va_end(args);
+
+ if (result <= 0) {
+ m_errorString = String("OTS Error");
+ } else {
+ Vector<char, 256> buffer;
+ unsigned len = result;
+ buffer.grow(len + 1);
+
+ va_start(args, format);
+ vsnprintf(buffer.data(), buffer.size(), format, args);
+ va_end(args);
+ m_errorString = StringImpl::create(reinterpret_cast<const LChar*>(buffer.data()), len);
+ }
+}
+
+ots::TableAction BlinkOTSContext::GetTableAction(uint32_t tag)
+{
+#define TABLE_TAG(c1, c2, c3, c4) ((uint32_t)((((uint8_t)(c1)) << 24) | (((uint8_t)(c2)) << 16) | (((uint8_t)(c3)) << 8) | ((uint8_t)(c4))))
+
+ const uint32_t cbdtTag = TABLE_TAG('C', 'B', 'D', 'T');
+ const uint32_t cblcTag = TABLE_TAG('C', 'B', 'L', 'C');
+ const uint32_t colrTag = TABLE_TAG('C', 'O', 'L', 'R');
+ const uint32_t cpalTag = TABLE_TAG('C', 'P', 'A', 'L');
+
+ switch (tag) {
+ // Google Color Emoji Tables
+ case cbdtTag:
+ case cblcTag:
+ // Windows Color Emoji Tables
+ case colrTag:
+ case cpalTag:
+ return ots::TABLE_ACTION_PASSTHRU;
+ default:
+ return ots::TABLE_ACTION_DEFAULT;
+ }
+#undef TABLE_TAG
+}
+
} // namespace blink
« no previous file with comments | « Source/platform/fonts/opentype/OpenTypeSanitizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698