|
1 diff --git a/gfx/ots/include/opentype-sanitiser.h b/gfx/ots/include/opentype-sanitiser.h |
|
2 --- a/gfx/ots/include/opentype-sanitiser.h |
|
3 +++ b/gfx/ots/include/opentype-sanitiser.h |
|
4 @@ -236,14 +236,16 @@ typedef TableAction (*TableActionFunc)(u |
|
5 // Set a callback function that will be called when OTS needs to decide what to |
|
6 // do for a font table. |
|
7 void OTS_API SetTableActionCallback(TableActionFunc func, void *user_data); |
|
8 |
|
9 // Force to disable debug output even when the library is compiled with |
|
10 // -DOTS_DEBUG. |
|
11 void DisableDebugOutput(); |
|
12 |
|
13 +#ifdef MOZ_OTS_WOFF2 |
|
14 // Enable WOFF2 support(experimental). |
|
15 void EnableWOFF2(); |
|
16 +#endif |
|
17 |
|
18 } // namespace ots |
|
19 |
|
20 #endif // OPENTYPE_SANITISER_H_ |
|
21 diff --git a/gfx/ots/src/ots.cc b/gfx/ots/src/ots.cc |
|
22 --- a/gfx/ots/src/ots.cc |
|
23 +++ b/gfx/ots/src/ots.cc |
|
24 @@ -9,25 +9,29 @@ |
|
25 |
|
26 #include <algorithm> |
|
27 #include <cstdlib> |
|
28 #include <cstring> |
|
29 #include <limits> |
|
30 #include <map> |
|
31 #include <vector> |
|
32 |
|
33 +#ifdef MOZ_OTS_WOFF2 |
|
34 #include "woff2.h" |
|
35 +#endif |
|
36 |
|
37 // The OpenType Font File |
|
38 // http://www.microsoft.com/typography/otspec/cmap.htm |
|
39 |
|
40 namespace { |
|
41 |
|
42 bool g_debug_output = true; |
|
43 +#ifdef MOZ_OTS_WOFF2 |
|
44 bool g_enable_woff2 = false; |
|
45 +#endif |
|
46 |
|
47 ots::MessageFunc g_message_func = NULL; |
|
48 void *g_message_user_data = NULL; |
|
49 |
|
50 ots::TableActionFunc g_table_action_func = NULL; |
|
51 void *g_table_action_user_data = NULL; |
|
52 |
|
53 // Generate a message with or without a table tag, when 'header' is the OpenTypeFile pointer |
|
54 @@ -395,16 +399,17 @@ bool ProcessWOFF(ots::OpenTypeFile *head |
|
55 } |
|
56 if (block_end != ots::Round4(length)) { |
|
57 return OTS_FAILURE_MSG_HDR("file length mismatch (trailing junk?)"); |
|
58 } |
|
59 |
|
60 return ProcessGeneric(header, woff_tag, output, data, length, tables, file); |
|
61 } |
|
62 |
|
63 +#ifdef MOZ_OTS_WOFF2 |
|
64 bool ProcessWOFF2(ots::OpenTypeFile *header, |
|
65 ots::OTSStream *output, const uint8_t *data, size_t length) { |
|
66 size_t decompressed_size = ots::ComputeWOFF2FinalSize(data, length); |
|
67 if (decompressed_size == 0) { |
|
68 return OTS_FAILURE(); |
|
69 } |
|
70 // decompressed font must be <= 30MB |
|
71 if (decompressed_size > 30 * 1024 * 1024) { |
|
72 @@ -413,16 +418,17 @@ bool ProcessWOFF2(ots::OpenTypeFile *hea |
|
73 |
|
74 std::vector<uint8_t> decompressed_buffer(decompressed_size); |
|
75 if (!ots::ConvertWOFF2ToTTF(&decompressed_buffer[0], decompressed_size, |
|
76 data, length)) { |
|
77 return OTS_FAILURE(); |
|
78 } |
|
79 return ProcessTTF(header, output, &decompressed_buffer[0], decompressed_size); |
|
80 } |
|
81 +#endif |
|
82 |
|
83 ots::TableAction GetTableAction(uint32_t tag) { |
|
84 ots::TableAction action = ots::TABLE_ACTION_DEFAULT; |
|
85 |
|
86 if (g_table_action_func != NULL) { |
|
87 action = g_table_action_func(htonl(tag), g_table_action_user_data); |
|
88 } |
|
89 |
|
90 @@ -795,19 +801,21 @@ bool IsValidVersionTag(uint32_t tag) { |
|
91 tag == Tag("true") || |
|
92 tag == Tag("typ1"); |
|
93 } |
|
94 |
|
95 void DisableDebugOutput() { |
|
96 g_debug_output = false; |
|
97 } |
|
98 |
|
99 +#ifdef MOZ_OTS_WOFF2 |
|
100 void EnableWOFF2() { |
|
101 g_enable_woff2 = true; |
|
102 } |
|
103 +#endif |
|
104 |
|
105 void SetMessageCallback(MessageFunc func, void *user_data) { |
|
106 g_message_func = func; |
|
107 g_message_user_data = user_data; |
|
108 } |
|
109 |
|
110 void SetTableActionCallback(TableActionFunc func, void *user_data) { |
|
111 g_table_action_func = func; |
|
112 @@ -822,20 +830,22 @@ bool Process(OTSStream *output, const ui |
|
113 |
|
114 if (length < 4) { |
|
115 return OTS_FAILURE_MSG_(&header, "file less than 4 bytes"); |
|
116 } |
|
117 |
|
118 bool result; |
|
119 if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] == 'F') { |
|
120 result = ProcessWOFF(&header, output, data, length); |
|
121 +#ifdef MOZ_OTS_WOFF2 |
|
122 } else if (g_enable_woff2 && |
|
123 data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && |
|
124 data[3] == '2') { |
|
125 result = ProcessWOFF2(&header, output, data, length); |
|
126 +#endif |
|
127 } else { |
|
128 result = ProcessTTF(&header, output, data, length); |
|
129 } |
|
130 |
|
131 for (unsigned i = 0; ; ++i) { |
|
132 if (table_parsers[i].parse == NULL) break; |
|
133 table_parsers[i].free(&header); |
|
134 } |