diff --git a/gfx/ots/include/opentype-sanitiser.h b/gfx/ots/include/opentype-sanitiser.h index f3c3d4e49502..2625783a53fd 100644 --- a/gfx/ots/include/opentype-sanitiser.h +++ b/gfx/ots/include/opentype-sanitiser.h @@ -5,6 +5,26 @@ #ifndef OPENTYPE_SANITISER_H_ #define OPENTYPE_SANITISER_H_ +#if defined(_WIN32) || defined(__CYGWIN__) + #define OTS_DLL_IMPORT __declspec(dllimport) + #define OTS_DLL_EXPORT __declspec(dllexport) +#else + #if __GNUC__ >= 4 + #define OTS_DLL_IMPORT __attribute__((visibility ("default"))) + #define OTS_DLL_EXPORT __attribute__((visibility ("default"))) + #endif +#endif + +#ifdef OTS_DLL + #ifdef OTS_DLL_EXPORTS + #define OTS_API OTS_DLL_EXPORT + #else + #define OTS_API OTS_DLL_IMPORT + #endif +#else + #define OTS_API +#endif + #if defined(_WIN32) #include typedef signed char int8_t; @@ -175,7 +195,7 @@ enum TableAction { TABLE_ACTION_DROP // Drop the table }; -class OTSContext { +class OTS_API OTSContext { public: OTSContext() {} virtual ~OTSContext() {} diff --git a/gfx/ots/src/glat.cc b/gfx/ots/src/glat.cc index d9034e1e11a8..b42453008d5a 100644 --- a/gfx/ots/src/glat.cc +++ b/gfx/ots/src/glat.cc @@ -5,7 +5,7 @@ #include "glat.h" #include "gloc.h" -#include "lz4.h" +#include "mozilla/Compression.h" #include #include @@ -215,14 +215,15 @@ bool OpenTypeGLAT_v3::Parse(const uint8_t* data, size_t length, decompressed_size / (1024.0 * 1024.0)); } std::unique_ptr decompressed(new uint8_t[decompressed_size]()); - int ret = LZ4_decompress_safe_partial( + size_t outputSize = 0; + bool ret = mozilla::Compression::LZ4::decompressPartial( reinterpret_cast(data + table.offset()), - reinterpret_cast(decompressed.get()), table.remaining(), // input buffer size (input size + padding) + reinterpret_cast(decompressed.get()), decompressed_size, // target output size - decompressed_size); // output buffer size - if (ret < 0 || unsigned(ret) != decompressed_size) { - return DropGraphite("Decompression failed with error code %d", ret); + &outputSize); // return output size + if (!ret || outputSize != decompressed_size) { + return DropGraphite("Decompression failed"); } return this->Parse(decompressed.get(), decompressed_size, true); } diff --git a/gfx/ots/src/ots.cc b/gfx/ots/src/ots.cc index ed22b8cc59fe..1ee4498363e1 100644 --- a/gfx/ots/src/ots.cc +++ b/gfx/ots/src/ots.cc @@ -14,7 +14,7 @@ #include #include -#include +#include "../RLBoxWOFF2Host.h" // The OpenType Font File // http://www.microsoft.com/typography/otspec/otff.htm @@ -518,43 +518,9 @@ bool ProcessWOFF(ots::FontFile *header, return ProcessGeneric(header, font, woff_tag, output, data, length, tables, file); } -bool ProcessWOFF2(ots::FontFile *header, - ots::OTSStream *output, - const uint8_t *data, - size_t length, - uint32_t index) { - size_t decompressed_size = woff2::ComputeWOFF2FinalSize(data, length); - - if (decompressed_size < length) { - return OTS_FAILURE_MSG_HDR("Size of decompressed WOFF 2.0 is less than compressed size"); - } - - if (decompressed_size == 0) { - return OTS_FAILURE_MSG_HDR("Size of decompressed WOFF 2.0 is set to 0"); - } - // decompressed font must be <= OTS_MAX_DECOMPRESSED_FILE_SIZE - if (decompressed_size > OTS_MAX_DECOMPRESSED_FILE_SIZE) { - return OTS_FAILURE_MSG_HDR("Size of decompressed WOFF 2.0 font exceeds %gMB", - OTS_MAX_DECOMPRESSED_FILE_SIZE / (1024.0 * 1024.0)); - } - - if (decompressed_size > output->size()) { - return OTS_FAILURE_MSG_HDR("Size of decompressed WOFF 2.0 font exceeds output size (%gMB)", output->size() / (1024.0 * 1024.0)); - } - - std::string buf(decompressed_size, 0); - woff2::WOFF2StringOut out(&buf); - if (!woff2::ConvertWOFF2ToTTF(data, length, &out)) { - return OTS_FAILURE_MSG_HDR("Failed to convert WOFF 2.0 font to SFNT"); - } - const uint8_t *decompressed = reinterpret_cast(buf.data()); - - if (data[4] == 't' && data[5] == 't' && data[6] == 'c' && data[7] == 'f') { - return ProcessTTC(header, output, decompressed, out.Size(), index); - } else { - ots::Font font(header); - return ProcessTTF(header, &font, output, decompressed, out.Size()); - } +bool ProcessWOFF2(ots::FontFile* header, ots::OTSStream* output, + const uint8_t* data, size_t length, uint32_t index) { + return RLBoxProcessWOFF2(header, output, data, length, index, ProcessTTC, ProcessTTF); } ots::TableAction GetTableAction(const ots::FontFile *header, uint32_t tag) { diff --git a/gfx/ots/src/silf.cc b/gfx/ots/src/silf.cc index fa3634c17a14..e1d521a98ca3 100644 --- a/gfx/ots/src/silf.cc +++ b/gfx/ots/src/silf.cc @@ -5,7 +5,7 @@ #include "silf.h" #include "name.h" -#include "lz4.h" +#include "mozilla/Compression.h" #include #include @@ -50,14 +50,15 @@ bool OpenTypeSILF::Parse(const uint8_t* data, size_t length, decompressed_size / (1024.0 * 1024.0)); } std::unique_ptr decompressed(new uint8_t[decompressed_size]()); - int ret = LZ4_decompress_safe_partial( + size_t outputSize = 0; + bool ret = mozilla::Compression::LZ4::decompressPartial( reinterpret_cast(data + table.offset()), - reinterpret_cast(decompressed.get()), table.remaining(), // input buffer size (input size + padding) + reinterpret_cast(decompressed.get()), decompressed_size, // target output size - decompressed_size); // output buffer size - if (ret < 0 || unsigned(ret) != decompressed_size) { - return DropGraphite("Decompression failed with error code %d", ret); + &outputSize); // return output size + if (!ret || outputSize != decompressed_size) { + return DropGraphite("Decompression failed"); } return this->Parse(decompressed.get(), decompressed_size, true); }