зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1057488 - Part 3: Update OTS to 97d043dd8977751835ca8d33d773ae8416e456d5. r=jfkthame
--HG-- extra : rebase_source : a040d22b1758ae60b7bbafecbe35d0dc9891365a
This commit is contained in:
Родитель
1d9bae5809
Коммит
3ca9ad3ae3
|
@ -2,7 +2,7 @@ This is the Sanitiser for OpenType project, from http://code.google.com/p/ots/.
|
|||
|
||||
Our reference repository is https://github.com/khaledhosny/ots/.
|
||||
|
||||
Current revision: 2a1859a6629bdb6f2915b1d3041621dbd396a4f7
|
||||
Current revision: 97d043dd8977751835ca8d33d773ae8416e456d5
|
||||
|
||||
Upstream files included: LICENSE, src/, include/
|
||||
|
||||
|
|
|
@ -199,15 +199,11 @@ class OTSStream {
|
|||
unsigned chksum_buffer_offset_;
|
||||
};
|
||||
|
||||
// Signature of the function to be provided by the client in order to report errors.
|
||||
// The return type is a boolean so that it can be used within an expression,
|
||||
// but the actual value is ignored. (Suggested convention is to always return 'false'.)
|
||||
#ifdef __GCC__
|
||||
#define MSGFUNC_FMT_ATTR __attribute__((format(printf, 2, 3)))
|
||||
#else
|
||||
#define MSGFUNC_FMT_ATTR
|
||||
#endif
|
||||
typedef bool (*MessageFunc)(void *user_data, const char *format, ...) MSGFUNC_FMT_ATTR;
|
||||
|
||||
enum TableAction {
|
||||
TABLE_ACTION_DEFAULT, // Use OTS's default action for that table
|
||||
|
@ -216,21 +212,9 @@ enum TableAction {
|
|||
TABLE_ACTION_DROP // Drop the table
|
||||
};
|
||||
|
||||
// Signature of the function to be provided by the client to decide what action
|
||||
// to do for a given table.
|
||||
// tag: table tag as an integer in big-endian byte order, independent of platform endianness
|
||||
// user_data: user defined data that are passed to SetTableActionCallback()
|
||||
typedef TableAction (*TableActionFunc)(uint32_t tag, void *user_data);
|
||||
|
||||
class OTS_API OTSContext {
|
||||
public:
|
||||
OTSContext()
|
||||
: message_func(0),
|
||||
message_user_data(0),
|
||||
table_action_func(0),
|
||||
table_action_user_data(0)
|
||||
{}
|
||||
|
||||
OTSContext() {}
|
||||
~OTSContext() {}
|
||||
|
||||
// Process a given OpenType file and write out a sanitised version
|
||||
|
@ -242,24 +226,14 @@ class OTS_API OTSContext {
|
|||
// context: optional context that holds various OTS settings like user callbacks
|
||||
bool Process(OTSStream *output, const uint8_t *input, size_t length);
|
||||
|
||||
// Set a callback function that will be called when OTS is reporting an error.
|
||||
void SetMessageCallback(MessageFunc func, void *user_data) {
|
||||
message_func = func;
|
||||
message_user_data = user_data;
|
||||
}
|
||||
// This function will be called when OTS is reporting an error.
|
||||
virtual void Message(const char *format, ...) MSGFUNC_FMT_ATTR {}
|
||||
|
||||
// Set a callback function that will be called when OTS needs to decide what to
|
||||
// do for a font table.
|
||||
void SetTableActionCallback(TableActionFunc func, void *user_data) {
|
||||
table_action_func = func;
|
||||
table_action_user_data = user_data;
|
||||
}
|
||||
|
||||
private:
|
||||
MessageFunc message_func;
|
||||
void *message_user_data;
|
||||
TableActionFunc table_action_func;
|
||||
void *table_action_user_data;
|
||||
// This function will be called when OTS needs to decide what to do for a
|
||||
// font table.
|
||||
// tag: table tag as an integer in big-endian byte order, independent of
|
||||
// platform endianness
|
||||
virtual TableAction GetTableAction(uint32_t tag) { return ots::TABLE_ACTION_DEFAULT; }
|
||||
};
|
||||
|
||||
// Force to disable debug output even when the library is compiled with
|
||||
|
|
|
@ -37,22 +37,22 @@ diff --git a/gfx/ots/include/opentype-sanitiser.h b/gfx/ots/include/opentype-san
|
|||
typedef unsigned short uint16_t;
|
||||
typedef int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
@@ -197,17 +217,17 @@ enum TableAction {
|
||||
};
|
||||
@@ -187,17 +187,17 @@ class OTSStream {
|
||||
|
||||
// Signature of the function to be provided by the client to decide what action
|
||||
// to do for a given table.
|
||||
// tag: table tag as an integer in big-endian byte order, independent of platform endianness
|
||||
// user_data: user defined data that are passed to SetTableActionCallback()
|
||||
typedef TableAction (*TableActionFunc)(uint32_t tag, void *user_data);
|
||||
enum TableAction {
|
||||
TABLE_ACTION_DEFAULT, // Use OTS's default action for that table
|
||||
TABLE_ACTION_SANITIZE, // Sanitize the table, potentially droping it
|
||||
TABLE_ACTION_PASSTHRU, // Serialize the table unchanged
|
||||
TABLE_ACTION_DROP // Drop the table
|
||||
};
|
||||
|
||||
-class OTSContext {
|
||||
+class OTS_API OTSContext {
|
||||
public:
|
||||
OTSContext()
|
||||
: message_func(0),
|
||||
message_user_data(0),
|
||||
table_action_func(0),
|
||||
table_action_user_data(0)
|
||||
{}
|
||||
OTSContext() {}
|
||||
~OTSContext() {}
|
||||
|
||||
// Process a given OpenType file and write out a sanitised version
|
||||
// output: a pointer to an object implementing the OTSStream interface. The
|
||||
// sanitisied output will be written to this. In the even of a failure,
|
||||
// partial output may have been written.
|
||||
|
|
|
@ -90,7 +90,7 @@ bool ots_name_parse(OpenTypeFile* file, const uint8_t* data, size_t length) {
|
|||
// are invalid name records, but it's not clear that is necessary.
|
||||
for (unsigned i = 0; i < count; ++i) {
|
||||
NameRecord rec;
|
||||
uint16_t name_length, name_offset;
|
||||
uint16_t name_length, name_offset = 0;
|
||||
if (!table.ReadU16(&rec.platform_id) ||
|
||||
!table.ReadU16(&rec.encoding_id) ||
|
||||
!table.ReadU16(&rec.language_id) ||
|
||||
|
|
|
@ -420,9 +420,7 @@ bool ProcessWOFF2(ots::OpenTypeFile *header,
|
|||
ots::TableAction GetTableAction(ots::OpenTypeFile *header, uint32_t tag) {
|
||||
ots::TableAction action = ots::TABLE_ACTION_DEFAULT;
|
||||
|
||||
if (header->table_action_func != NULL) {
|
||||
action = header->table_action_func(htonl(tag), header->table_action_user_data);
|
||||
}
|
||||
action = header->context->GetTableAction(htonl(tag));
|
||||
|
||||
if (action == ots::TABLE_ACTION_DEFAULT) {
|
||||
action = ots::TABLE_ACTION_DROP;
|
||||
|
@ -807,10 +805,7 @@ bool OTSContext::Process(OTSStream *output,
|
|||
size_t length) {
|
||||
OpenTypeFile header;
|
||||
|
||||
header.message_func = message_func;
|
||||
header.message_user_data = message_user_data;
|
||||
header.table_action_func = table_action_func;
|
||||
header.table_action_user_data = table_action_user_data;
|
||||
header.context = this;
|
||||
|
||||
if (length < 4) {
|
||||
return OTS_FAILURE_MSG_(&header, "file less than 4 bytes");
|
||||
|
|
|
@ -52,15 +52,11 @@ void Warning(const char *f, int l, const char *format, ...)
|
|||
|
||||
// Generate a simple message
|
||||
#define OTS_FAILURE_MSG_(otf_,...) \
|
||||
((otf_)->message_func && \
|
||||
(*(otf_)->message_func)((otf_)->message_user_data, __VA_ARGS__) && \
|
||||
false)
|
||||
((otf_)->context->Message(__VA_ARGS__), false)
|
||||
|
||||
// Generate a message with an associated table tag
|
||||
#define OTS_FAILURE_MSG_TAG_(otf_,msg_,tag_) \
|
||||
((otf_)->message_func && \
|
||||
(*(otf_)->message_func)((otf_)->message_user_data, "%4.4s: %s", tag_, msg_) && \
|
||||
false)
|
||||
((otf_)->context->Message("%4.4s: %s", tag_, msg_), false)
|
||||
|
||||
// Convenience macro for use in files that only handle a single table tag,
|
||||
// defined as TABLE_NAME at the top of the file; the 'file' variable is
|
||||
|
@ -250,11 +246,7 @@ struct OpenTypeFile {
|
|||
uint16_t entry_selector;
|
||||
uint16_t range_shift;
|
||||
|
||||
MessageFunc message_func;
|
||||
void *message_user_data;
|
||||
|
||||
TableActionFunc table_action_func;
|
||||
void *table_action_user_data;
|
||||
OTSContext *context;
|
||||
|
||||
#define F(name, capname) OpenType##capname *name;
|
||||
FOR_EACH_TABLE_TYPE
|
||||
|
|
|
@ -870,7 +870,7 @@ bool ConvertWOFF2ToTTF(uint8_t* result, size_t result_length,
|
|||
ots::Buffer file(data, length);
|
||||
|
||||
uint32_t signature;
|
||||
uint32_t flavor;
|
||||
uint32_t flavor = 0;
|
||||
if (!file.ReadU32(&signature) || signature != kWoff2Signature ||
|
||||
!file.ReadU32(&flavor)) {
|
||||
return OTS_FAILURE();
|
||||
|
|
|
@ -172,47 +172,45 @@ gfxProxyFontEntry::CreateFontInstance(const gfxFontStyle *aFontStyle, bool aNeed
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
static ots::TableAction
|
||||
OTSTableAction(uint32_t aTag, void *aUserData)
|
||||
{
|
||||
// preserve Graphite, color glyph and SVG tables
|
||||
if (aTag == TRUETYPE_TAG('S', 'i', 'l', 'f') ||
|
||||
aTag == TRUETYPE_TAG('S', 'i', 'l', 'l') ||
|
||||
aTag == TRUETYPE_TAG('G', 'l', 'o', 'c') ||
|
||||
aTag == TRUETYPE_TAG('G', 'l', 'a', 't') ||
|
||||
aTag == TRUETYPE_TAG('F', 'e', 'a', 't') ||
|
||||
aTag == TRUETYPE_TAG('S', 'V', 'G', ' ') ||
|
||||
aTag == TRUETYPE_TAG('C', 'O', 'L', 'R') ||
|
||||
aTag == TRUETYPE_TAG('C', 'P', 'A', 'L')) {
|
||||
return ots::TABLE_ACTION_PASSTHRU;
|
||||
}
|
||||
return ots::TABLE_ACTION_DEFAULT;
|
||||
}
|
||||
class gfxOTSContext : public ots::OTSContext {
|
||||
public:
|
||||
gfxOTSContext(gfxMixedFontFamily *aFamily, gfxProxyFontEntry *aProxy)
|
||||
: mFamily(aFamily), mProxy(aProxy) {}
|
||||
|
||||
struct OTSCallbackUserData {
|
||||
virtual ots::TableAction GetTableAction(uint32_t aTag) MOZ_OVERRIDE {
|
||||
// preserve Graphite, color glyph and SVG tables
|
||||
if (aTag == TRUETYPE_TAG('S', 'i', 'l', 'f') ||
|
||||
aTag == TRUETYPE_TAG('S', 'i', 'l', 'l') ||
|
||||
aTag == TRUETYPE_TAG('G', 'l', 'o', 'c') ||
|
||||
aTag == TRUETYPE_TAG('G', 'l', 'a', 't') ||
|
||||
aTag == TRUETYPE_TAG('F', 'e', 'a', 't') ||
|
||||
aTag == TRUETYPE_TAG('S', 'V', 'G', ' ') ||
|
||||
aTag == TRUETYPE_TAG('C', 'O', 'L', 'R') ||
|
||||
aTag == TRUETYPE_TAG('C', 'P', 'A', 'L')) {
|
||||
return ots::TABLE_ACTION_PASSTHRU;
|
||||
}
|
||||
return ots::TABLE_ACTION_DEFAULT;
|
||||
}
|
||||
|
||||
virtual void Message(const char *format, ...) MSGFUNC_FMT_ATTR MOZ_OVERRIDE {
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
|
||||
// buf should be more than adequate for any message OTS generates,
|
||||
// so we don't worry about checking the result of vsnprintf()
|
||||
char buf[512];
|
||||
(void)vsnprintf(buf, sizeof(buf), format, va);
|
||||
|
||||
va_end(va);
|
||||
|
||||
mProxy->mFontSet->LogMessage(mFamily, mProxy, buf);
|
||||
}
|
||||
|
||||
private:
|
||||
gfxMixedFontFamily *mFamily;
|
||||
gfxProxyFontEntry *mProxy;
|
||||
};
|
||||
|
||||
/* static */ bool
|
||||
gfxProxyFontEntry::OTSMessage(void *aUserData, const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
|
||||
// buf should be more than adequate for any message OTS generates,
|
||||
// so we don't worry about checking the result of vsnprintf()
|
||||
char buf[512];
|
||||
(void)vsnprintf(buf, sizeof(buf), format, va);
|
||||
|
||||
va_end(va);
|
||||
|
||||
OTSCallbackUserData *d = static_cast<OTSCallbackUserData*>(aUserData);
|
||||
d->mProxy->mFontSet->LogMessage(d->mFamily, d->mProxy, buf);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Call the OTS library to sanitize an sfnt before attempting to use it.
|
||||
// Returns a newly-allocated block, or nullptr in case of fatal errors.
|
||||
const uint8_t*
|
||||
|
@ -226,13 +224,7 @@ gfxProxyFontEntry::SanitizeOpenTypeData(gfxMixedFontFamily *aFamily,
|
|||
ExpandingMemoryStream output(aIsCompressed ? aLength * 2 : aLength,
|
||||
1024 * 1024 * 256);
|
||||
|
||||
OTSCallbackUserData userData;
|
||||
userData.mFamily = aFamily;
|
||||
userData.mProxy = this;
|
||||
|
||||
ots::OTSContext otsContext;
|
||||
otsContext.SetTableActionCallback(&OTSTableAction, nullptr);
|
||||
otsContext.SetMessageCallback(&OTSMessage, &userData);
|
||||
gfxOTSContext otsContext(aFamily, this);
|
||||
|
||||
if (otsContext.Process(&output, aData, aLength)) {
|
||||
aSaneLength = output.Tell();
|
||||
|
|
|
@ -156,9 +156,11 @@ public:
|
|||
};
|
||||
|
||||
class gfxProxyFontEntry;
|
||||
class gfxOTSContext;
|
||||
|
||||
class gfxUserFontSet {
|
||||
friend class gfxProxyFontEntry;
|
||||
friend class gfxOTSContext;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -517,6 +519,7 @@ class gfxProxyFontEntry : public gfxFontEntry {
|
|||
friend class gfxUserFontSet;
|
||||
friend class nsUserFontSet;
|
||||
friend class nsFontFaceLoader;
|
||||
friend class gfxOTSContext;
|
||||
|
||||
public:
|
||||
enum LoadStatus {
|
||||
|
@ -576,8 +579,6 @@ protected:
|
|||
FallibleTArray<uint8_t>* aMetadata,
|
||||
uint32_t aMetaOrigLen);
|
||||
|
||||
static bool OTSMessage(void *aUserData, const char *format, ...);
|
||||
|
||||
// note that code depends on the ordering of these values!
|
||||
enum LoadingState {
|
||||
NOT_LOADING = 0, // not started to load any font resources yet
|
||||
|
|
Загрузка…
Ссылка в новой задаче