ots-rlbox.patch (2799B)
1 diff --git a/src/ots.cc b/src/ots.cc 2 --- a/src/ots.cc 3 +++ b/src/ots.cc 4 @@ -9,17 +9,17 @@ 5 6 #include <algorithm> 7 #include <cstdlib> 8 #include <cstring> 9 #include <limits> 10 #include <map> 11 #include <vector> 12 13 -#include <woff2/decode.h> 14 +#include "../RLBoxWOFF2Host.h" 15 16 // The OpenType Font File 17 // http://www.microsoft.com/typography/otspec/otff.htm 18 19 #include "avar.h" 20 #include "cff.h" 21 #include "cmap.h" 22 #include "colr.h" 23 @@ -513,54 +513,19 @@ bool ProcessWOFF(ots::FontFile *header, 24 } 25 if (block_end != ots::Round4(length)) { 26 return OTS_FAILURE_MSG_HDR("File length mismatch (trailing junk?)"); 27 } 28 29 return ProcessGeneric(header, font, woff_tag, output, data, length, tables, file); 30 } 31 32 -bool ProcessWOFF2(ots::FontFile *header, 33 - ots::OTSStream *output, 34 - const uint8_t *data, 35 - size_t length, 36 - uint32_t index) { 37 - size_t decompressed_size = woff2::ComputeWOFF2FinalSize(data, length); 38 - 39 - if (decompressed_size < length) { 40 - return OTS_FAILURE_MSG_HDR("Size of decompressed WOFF 2.0 is less than compressed size"); 41 - } 42 - 43 - if (decompressed_size == 0) { 44 - return OTS_FAILURE_MSG_HDR("Size of decompressed WOFF 2.0 is set to 0"); 45 - } 46 - // decompressed font must be <= OTS_MAX_DECOMPRESSED_FILE_SIZE 47 - if (decompressed_size > OTS_MAX_DECOMPRESSED_FILE_SIZE) { 48 - return OTS_FAILURE_MSG_HDR("Size of decompressed WOFF 2.0 font exceeds %gMB", 49 - OTS_MAX_DECOMPRESSED_FILE_SIZE / (1024.0 * 1024.0)); 50 - } 51 - 52 - if (decompressed_size > output->size()) { 53 - return OTS_FAILURE_MSG_HDR("Size of decompressed WOFF 2.0 font exceeds output size (%gMB)", output->size() / (1024.0 * 1024.0)); 54 - } 55 - 56 - std::string buf(decompressed_size, 0); 57 - woff2::WOFF2StringOut out(&buf); 58 - out.SetMaxSize(decompressed_size); 59 - if (!woff2::ConvertWOFF2ToTTF(data, length, &out)) { 60 - return OTS_FAILURE_MSG_HDR("Failed to convert WOFF 2.0 font to SFNT"); 61 - } 62 - const uint8_t *decompressed = reinterpret_cast<const uint8_t*>(buf.data()); 63 - 64 - if (data[4] == 't' && data[5] == 't' && data[6] == 'c' && data[7] == 'f') { 65 - return ProcessTTC(header, output, decompressed, out.Size(), index); 66 - } else { 67 - ots::Font font(header); 68 - return ProcessTTF(header, &font, output, decompressed, out.Size()); 69 - } 70 +bool ProcessWOFF2(ots::FontFile* header, ots::OTSStream* output, 71 + const uint8_t* data, size_t length, uint32_t index) { 72 + return RLBoxProcessWOFF2(header, output, data, length, index, ProcessTTC, ProcessTTF); 73 } 74 75 ots::TableAction GetTableAction(const ots::FontFile *header, uint32_t tag) { 76 ots::TableAction action = header->context->GetTableAction(tag); 77 78 if (action == ots::TABLE_ACTION_DEFAULT) { 79 action = ots::TABLE_ACTION_DROP;