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

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: Comment fixes Created 5 years, 7 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
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..d210f1fb5aedf645e2d320bf6b6d288917e46258 100644
--- a/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp
+++ b/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp
@@ -77,9 +77,14 @@ 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())) {
+ setParsingError(true);
+ setErrorString(otsContext.getErrorString());
return nullptr;
+ }
+ setParsingError(false);
+ setErrorString(otsContext.getErrorString());
const size_t transcodeLen = output.Tell();
recordDecodeSpeedHistogram(m_buffer, currentTime() - start, transcodeLen);
return SharedBuffer::create(static_cast<unsigned char*>(output.get()), transcodeLen);
@@ -90,4 +95,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

Powered by Google App Engine
This is Rietveld 408576698