gfx/ots/ots-woff2.patch

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/ots/ots-woff2.patch	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,134 @@
     1.4 +diff --git a/gfx/ots/include/opentype-sanitiser.h b/gfx/ots/include/opentype-sanitiser.h
     1.5 +--- a/gfx/ots/include/opentype-sanitiser.h
     1.6 ++++ b/gfx/ots/include/opentype-sanitiser.h
     1.7 +@@ -236,14 +236,16 @@ typedef TableAction (*TableActionFunc)(u
     1.8 + // Set a callback function that will be called when OTS needs to decide what to
     1.9 + // do for a font table.
    1.10 + void OTS_API SetTableActionCallback(TableActionFunc func, void *user_data);
    1.11 + 
    1.12 + // Force to disable debug output even when the library is compiled with
    1.13 + // -DOTS_DEBUG.
    1.14 + void DisableDebugOutput();
    1.15 + 
    1.16 ++#ifdef MOZ_OTS_WOFF2
    1.17 + // Enable WOFF2 support(experimental).
    1.18 + void EnableWOFF2();
    1.19 ++#endif
    1.20 + 
    1.21 + }  // namespace ots
    1.22 + 
    1.23 + #endif  // OPENTYPE_SANITISER_H_
    1.24 +diff --git a/gfx/ots/src/ots.cc b/gfx/ots/src/ots.cc
    1.25 +--- a/gfx/ots/src/ots.cc
    1.26 ++++ b/gfx/ots/src/ots.cc
    1.27 +@@ -9,25 +9,29 @@
    1.28 + 
    1.29 + #include <algorithm>
    1.30 + #include <cstdlib>
    1.31 + #include <cstring>
    1.32 + #include <limits>
    1.33 + #include <map>
    1.34 + #include <vector>
    1.35 + 
    1.36 ++#ifdef MOZ_OTS_WOFF2
    1.37 + #include "woff2.h"
    1.38 ++#endif
    1.39 + 
    1.40 + // The OpenType Font File
    1.41 + // http://www.microsoft.com/typography/otspec/cmap.htm
    1.42 + 
    1.43 + namespace {
    1.44 + 
    1.45 + bool g_debug_output = true;
    1.46 ++#ifdef MOZ_OTS_WOFF2
    1.47 + bool g_enable_woff2 = false;
    1.48 ++#endif
    1.49 + 
    1.50 + ots::MessageFunc  g_message_func = NULL;
    1.51 + void             *g_message_user_data = NULL;
    1.52 + 
    1.53 + ots::TableActionFunc  g_table_action_func = NULL;
    1.54 + void                 *g_table_action_user_data = NULL;
    1.55 + 
    1.56 + // Generate a message with or without a table tag, when 'header' is the OpenTypeFile pointer
    1.57 +@@ -395,16 +399,17 @@ bool ProcessWOFF(ots::OpenTypeFile *head
    1.58 +   }
    1.59 +   if (block_end != ots::Round4(length)) {
    1.60 +     return OTS_FAILURE_MSG_HDR("file length mismatch (trailing junk?)");
    1.61 +   }
    1.62 + 
    1.63 +   return ProcessGeneric(header, woff_tag, output, data, length, tables, file);
    1.64 + }
    1.65 + 
    1.66 ++#ifdef MOZ_OTS_WOFF2
    1.67 + bool ProcessWOFF2(ots::OpenTypeFile *header,
    1.68 +                   ots::OTSStream *output, const uint8_t *data, size_t length) {
    1.69 +   size_t decompressed_size = ots::ComputeWOFF2FinalSize(data, length);
    1.70 +   if (decompressed_size == 0) {
    1.71 +     return OTS_FAILURE();
    1.72 +   }
    1.73 +   // decompressed font must be <= 30MB
    1.74 +   if (decompressed_size > 30 * 1024 * 1024) {
    1.75 +@@ -413,16 +418,17 @@ bool ProcessWOFF2(ots::OpenTypeFile *hea
    1.76 + 
    1.77 +   std::vector<uint8_t> decompressed_buffer(decompressed_size);
    1.78 +   if (!ots::ConvertWOFF2ToTTF(&decompressed_buffer[0], decompressed_size,
    1.79 +                               data, length)) {
    1.80 +     return OTS_FAILURE();
    1.81 +   }
    1.82 +   return ProcessTTF(header, output, &decompressed_buffer[0], decompressed_size);
    1.83 + }
    1.84 ++#endif
    1.85 + 
    1.86 + ots::TableAction GetTableAction(uint32_t tag) {
    1.87 +   ots::TableAction action = ots::TABLE_ACTION_DEFAULT;
    1.88 + 
    1.89 +   if (g_table_action_func != NULL) {
    1.90 +     action = g_table_action_func(htonl(tag), g_table_action_user_data);
    1.91 +   }
    1.92 + 
    1.93 +@@ -795,19 +801,21 @@ bool IsValidVersionTag(uint32_t tag) {
    1.94 +          tag == Tag("true") ||
    1.95 +          tag == Tag("typ1");
    1.96 + }
    1.97 + 
    1.98 + void DisableDebugOutput() {
    1.99 +   g_debug_output = false;
   1.100 + }
   1.101 + 
   1.102 ++#ifdef MOZ_OTS_WOFF2
   1.103 + void EnableWOFF2() {
   1.104 +   g_enable_woff2 = true;
   1.105 + }
   1.106 ++#endif
   1.107 + 
   1.108 + void SetMessageCallback(MessageFunc func, void *user_data) {
   1.109 +   g_message_func = func;
   1.110 +   g_message_user_data = user_data;
   1.111 + }
   1.112 + 
   1.113 + void SetTableActionCallback(TableActionFunc func, void *user_data) {
   1.114 +   g_table_action_func = func;
   1.115 +@@ -822,20 +830,22 @@ bool Process(OTSStream *output, const ui
   1.116 + 
   1.117 +   if (length < 4) {
   1.118 +     return OTS_FAILURE_MSG_(&header, "file less than 4 bytes");
   1.119 +   }
   1.120 + 
   1.121 +   bool result;
   1.122 +   if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] == 'F') {
   1.123 +     result = ProcessWOFF(&header, output, data, length);
   1.124 ++#ifdef MOZ_OTS_WOFF2
   1.125 +   } else if (g_enable_woff2 &&
   1.126 +              data[0] == 'w' && data[1] == 'O' && data[2] == 'F' &&
   1.127 +              data[3] == '2') {
   1.128 +     result = ProcessWOFF2(&header, output, data, length);
   1.129 ++#endif
   1.130 +   } else {
   1.131 +     result = ProcessTTF(&header, output, data, length);
   1.132 +   }
   1.133 + 
   1.134 +   for (unsigned i = 0; ; ++i) {
   1.135 +     if (table_parsers[i].parse == NULL) break;
   1.136 +     table_parsers[i].free(&header);
   1.137 +   }

mercurial