michael@0: diff --git a/gfx/ots/include/opentype-sanitiser.h b/gfx/ots/include/opentype-sanitiser.h michael@0: --- a/gfx/ots/include/opentype-sanitiser.h michael@0: +++ b/gfx/ots/include/opentype-sanitiser.h michael@0: @@ -236,14 +236,16 @@ typedef TableAction (*TableActionFunc)(u michael@0: // Set a callback function that will be called when OTS needs to decide what to michael@0: // do for a font table. michael@0: void OTS_API SetTableActionCallback(TableActionFunc func, void *user_data); michael@0: michael@0: // Force to disable debug output even when the library is compiled with michael@0: // -DOTS_DEBUG. michael@0: void DisableDebugOutput(); michael@0: michael@0: +#ifdef MOZ_OTS_WOFF2 michael@0: // Enable WOFF2 support(experimental). michael@0: void EnableWOFF2(); michael@0: +#endif michael@0: michael@0: } // namespace ots michael@0: michael@0: #endif // OPENTYPE_SANITISER_H_ michael@0: diff --git a/gfx/ots/src/ots.cc b/gfx/ots/src/ots.cc michael@0: --- a/gfx/ots/src/ots.cc michael@0: +++ b/gfx/ots/src/ots.cc michael@0: @@ -9,25 +9,29 @@ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: +#ifdef MOZ_OTS_WOFF2 michael@0: #include "woff2.h" michael@0: +#endif michael@0: michael@0: // The OpenType Font File michael@0: // http://www.microsoft.com/typography/otspec/cmap.htm michael@0: michael@0: namespace { michael@0: michael@0: bool g_debug_output = true; michael@0: +#ifdef MOZ_OTS_WOFF2 michael@0: bool g_enable_woff2 = false; michael@0: +#endif michael@0: michael@0: ots::MessageFunc g_message_func = NULL; michael@0: void *g_message_user_data = NULL; michael@0: michael@0: ots::TableActionFunc g_table_action_func = NULL; michael@0: void *g_table_action_user_data = NULL; michael@0: michael@0: // Generate a message with or without a table tag, when 'header' is the OpenTypeFile pointer michael@0: @@ -395,16 +399,17 @@ bool ProcessWOFF(ots::OpenTypeFile *head michael@0: } michael@0: if (block_end != ots::Round4(length)) { michael@0: return OTS_FAILURE_MSG_HDR("file length mismatch (trailing junk?)"); michael@0: } michael@0: michael@0: return ProcessGeneric(header, woff_tag, output, data, length, tables, file); michael@0: } michael@0: michael@0: +#ifdef MOZ_OTS_WOFF2 michael@0: bool ProcessWOFF2(ots::OpenTypeFile *header, michael@0: ots::OTSStream *output, const uint8_t *data, size_t length) { michael@0: size_t decompressed_size = ots::ComputeWOFF2FinalSize(data, length); michael@0: if (decompressed_size == 0) { michael@0: return OTS_FAILURE(); michael@0: } michael@0: // decompressed font must be <= 30MB michael@0: if (decompressed_size > 30 * 1024 * 1024) { michael@0: @@ -413,16 +418,17 @@ bool ProcessWOFF2(ots::OpenTypeFile *hea michael@0: michael@0: std::vector decompressed_buffer(decompressed_size); michael@0: if (!ots::ConvertWOFF2ToTTF(&decompressed_buffer[0], decompressed_size, michael@0: data, length)) { michael@0: return OTS_FAILURE(); michael@0: } michael@0: return ProcessTTF(header, output, &decompressed_buffer[0], decompressed_size); michael@0: } michael@0: +#endif michael@0: michael@0: ots::TableAction GetTableAction(uint32_t tag) { michael@0: ots::TableAction action = ots::TABLE_ACTION_DEFAULT; michael@0: michael@0: if (g_table_action_func != NULL) { michael@0: action = g_table_action_func(htonl(tag), g_table_action_user_data); michael@0: } michael@0: michael@0: @@ -795,19 +801,21 @@ bool IsValidVersionTag(uint32_t tag) { michael@0: tag == Tag("true") || michael@0: tag == Tag("typ1"); michael@0: } michael@0: michael@0: void DisableDebugOutput() { michael@0: g_debug_output = false; michael@0: } michael@0: michael@0: +#ifdef MOZ_OTS_WOFF2 michael@0: void EnableWOFF2() { michael@0: g_enable_woff2 = true; michael@0: } michael@0: +#endif michael@0: michael@0: void SetMessageCallback(MessageFunc func, void *user_data) { michael@0: g_message_func = func; michael@0: g_message_user_data = user_data; michael@0: } michael@0: michael@0: void SetTableActionCallback(TableActionFunc func, void *user_data) { michael@0: g_table_action_func = func; michael@0: @@ -822,20 +830,22 @@ bool Process(OTSStream *output, const ui michael@0: michael@0: if (length < 4) { michael@0: return OTS_FAILURE_MSG_(&header, "file less than 4 bytes"); michael@0: } michael@0: michael@0: bool result; michael@0: if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] == 'F') { michael@0: result = ProcessWOFF(&header, output, data, length); michael@0: +#ifdef MOZ_OTS_WOFF2 michael@0: } else if (g_enable_woff2 && michael@0: data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && michael@0: data[3] == '2') { michael@0: result = ProcessWOFF2(&header, output, data, length); michael@0: +#endif michael@0: } else { michael@0: result = ProcessTTF(&header, output, data, length); michael@0: } michael@0: michael@0: for (unsigned i = 0; ; ++i) { michael@0: if (table_parsers[i].parse == NULL) break; michael@0: table_parsers[i].free(&header); michael@0: }