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.h

Issue 983973004: Provide user friendly messages for OTS parsing of fonts (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Code update for test expectation 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.h
diff --git a/Source/platform/fonts/opentype/OpenTypeSanitizer.h b/Source/platform/fonts/opentype/OpenTypeSanitizer.h
index 460dd0262ee3a89e3ce70e8ffb96b7c2b3698e91..8799d51e37d4af96bcd91144b7f17d449b951aff 100644
--- a/Source/platform/fonts/opentype/OpenTypeSanitizer.h
+++ b/Source/platform/fonts/opentype/OpenTypeSanitizer.h
@@ -33,6 +33,7 @@
#include "opentype-sanitiser.h"
#include "wtf/Forward.h"
+#include "wtf/text/WTFString.h"
namespace blink {
@@ -42,20 +43,60 @@ class OpenTypeSanitizer {
public:
explicit OpenTypeSanitizer(SharedBuffer* buffer)
: m_buffer(buffer)
+ , m_otsErrorString("")
{
}
PassRefPtr<SharedBuffer> sanitize();
static bool supportsFormat(const String&);
+ String getErrorString() const { return static_cast<String>(m_otsErrorString); }
+
+ void setErrorString(const String& errorString) { m_otsErrorString = errorString; }
+
+ bool isParsingError() const { return m_parsingError; }
+ void setParsingError(bool parsingError) { m_parsingError = parsingError; }
private:
SharedBuffer* const m_buffer;
+ String m_otsErrorString;
+ bool m_parsingError;
};
class BlinkOTSContext: public ots::OTSContext {
public:
- // TODO: Implement "Message" to support user friendly messages
+ BlinkOTSContext()
+ : m_errorString("")
+ {
+ }
+
+ virtual void Message(int level, const char *format, ...)
jungshik at Google 2015/05/12 20:22:48 Just wondering if there's a reason to have this in
h.joshi 2015/05/14 04:52:15 Moved methods to CPP file, normally all methods we
+ {
+ 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);
+ }
+ }
+
virtual ots::TableAction 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))))
@@ -78,6 +119,10 @@ public:
}
#undef TABLE_TAG
}
+
+ String getErrorString() const { return static_cast<String>(m_errorString); }
+private:
+ String m_errorString;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698