Index: src/ots.cc |
=================================================================== |
--- src/ots.cc (revision 99) |
+++ src/ots.cc (working copy) |
@@ -14,12 +14,15 @@ |
#include <map> |
#include <vector> |
+#include "woff2.h" |
+ |
// The OpenType Font File |
// http://www.microsoft.com/typography/otspec/cmap.htm |
namespace { |
bool g_debug_output = true; |
+bool g_enable_woff2 = false; |
struct OpenTypeTable { |
uint32_t tag; |
@@ -402,6 +405,21 @@ |
return ProcessGeneric(header, woff_tag, output, data, length, tables, file); |
} |
+bool ProcessWOFF2(ots::OpenTypeFile *header, |
+ ots::OTSStream *output, const uint8_t *data, size_t length) { |
+ size_t decompressed_size = ots::ComputeWOFF2FinalSize(data, length); |
+ if (decompressed_size == 0) { |
+ return OTS_FAILURE(); |
+ } |
+ |
+ std::vector<uint8_t> decompressed_buffer(decompressed_size); |
Yusuke Sato
2013/04/17 18:38:46
* Do we have to zero-fill the buffer?
* Please def
Kunihiko Sakamoto
2013/04/23 06:36:26
Done.
Yusuke Sato
2013/05/07 06:11:27
std::vector<uint8_t> decompressed_buffer(decompres
Kunihiko Sakamoto
2013/05/07 10:17:23
Oh, got it.
We should zero clear this buffer, beca
|
+ if (!ots::ConvertWOFF2ToTTF(&decompressed_buffer[0], decompressed_size, |
+ data, length)) { |
+ return OTS_FAILURE(); |
+ } |
+ return ProcessTTF(header, output, &decompressed_buffer[0], decompressed_size); |
+} |
+ |
bool ProcessGeneric(ots::OpenTypeFile *header, uint32_t signature, |
ots::OTSStream *output, |
const uint8_t *data, size_t length, |
@@ -683,6 +701,10 @@ |
g_debug_output = false; |
} |
+void EnableWOFF2() { |
+ g_enable_woff2 = true; |
+} |
+ |
bool Process(OTSStream *output, const uint8_t *data, size_t length) { |
OpenTypeFile header; |
if (length < 4) { |
@@ -692,6 +714,10 @@ |
bool result; |
if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] == 'F') { |
result = ProcessWOFF(&header, output, data, length); |
+ } else if (g_enable_woff2 && |
+ data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && |
+ data[3] == '2') { |
+ result = ProcessWOFF2(&header, output, data, length); |
} else { |
result = ProcessTTF(&header, output, data, length); |
} |