#include <woff2/decode.h>
#include <stdlib.h>
#include <algorithm>
#include <complex>
#include <cstring>
#include <limits>
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <utility>
#include <brotli/decode.h>
#include "./buffer.h"
#include "./port.h"
#include "./round.h"
#include "./store_bytes.h"
#include "./table_tags.h"
#include "./variable_length.h"
#include "./woff2_common.h"
namespace woff2 {
namespace {
const int kGlyfOnCurve = …;
const int kGlyfXShort = …;
const int kGlyfYShort = …;
const int kGlyfRepeat = …;
const int kGlyfThisXIsSame = …;
const int kGlyfThisYIsSame = …;
const int kOverlapSimple = …;
const int FLAG_ARG_1_AND_2_ARE_WORDS = …;
const int FLAG_WE_HAVE_A_SCALE = …;
const int FLAG_MORE_COMPONENTS = …;
const int FLAG_WE_HAVE_AN_X_AND_Y_SCALE = …;
const int FLAG_WE_HAVE_A_TWO_BY_TWO = …;
const int FLAG_WE_HAVE_INSTRUCTIONS = …;
const int FLAG_OVERLAP_SIMPLE_BITMAP = …;
const size_t kCheckSumAdjustmentOffset = …;
const size_t kEndPtsOfContoursOffset = …;
const size_t kCompositeGlyphBegin = …;
const size_t kDefaultGlyphBuf = …;
const float kMaxPlausibleCompressionRatio = …;
struct TtcFont { … };
struct WOFF2Header { … };
struct WOFF2FontInfo { … };
struct RebuildMetadata { … };
int WithSign(int flag, int baseval) { … }
bool _SafeIntAddition(int a, int b, int* result) { … }
bool TripletDecode(const uint8_t* flags_in, const uint8_t* in, size_t in_size,
unsigned int n_points, Point* result, size_t* in_bytes_consumed) { … }
bool StorePoints(unsigned int n_points, const Point* points,
unsigned int n_contours, unsigned int instruction_length,
bool has_overlap_bit, uint8_t* dst, size_t dst_size,
size_t* glyph_size) { … }
void ComputeBbox(unsigned int n_points, const Point* points, uint8_t* dst) { … }
bool SizeOfComposite(Buffer composite_stream, size_t* size,
bool* have_instructions) { … }
bool Pad4(WOFF2Out* out) { … }
bool StoreLoca(const std::vector<uint32_t>& loca_values, int index_format,
uint32_t* checksum, WOFF2Out* out) { … }
bool ReconstructGlyf(const uint8_t* data, Table* glyf_table,
uint32_t* glyf_checksum, Table * loca_table,
uint32_t* loca_checksum, WOFF2FontInfo* info,
WOFF2Out* out) { … }
Table* FindTable(std::vector<Table*>* tables, uint32_t tag) { … }
bool ReadNumHMetrics(const uint8_t* data, size_t data_size,
uint16_t* num_hmetrics) { … }
bool ReconstructTransformedHmtx(const uint8_t* transformed_buf,
size_t transformed_size,
uint16_t num_glyphs,
uint16_t num_hmetrics,
const std::vector<int16_t>& x_mins,
uint32_t* checksum,
WOFF2Out* out) { … }
bool Woff2Uncompress(uint8_t* dst_buf, size_t dst_size,
const uint8_t* src_buf, size_t src_size) { … }
bool ReadTableDirectory(Buffer* file, std::vector<Table>* tables,
size_t num_tables) { … }
size_t StoreOffsetTable(uint8_t* result, size_t offset, uint32_t flavor,
uint16_t num_tables) { … }
size_t StoreTableEntry(uint8_t* result, uint32_t offset, uint32_t tag) { … }
uint64_t ComputeOffsetToFirstTable(const WOFF2Header& hdr) { … }
std::vector<Table*> Tables(WOFF2Header* hdr, size_t font_index) { … }
bool ReconstructFont(uint8_t* transformed_buf,
const uint32_t transformed_buf_size,
RebuildMetadata* metadata,
WOFF2Header* hdr,
size_t font_index,
WOFF2Out* out) { … }
bool ReadWOFF2Header(const uint8_t* data, size_t length, WOFF2Header* hdr) { … }
bool WriteHeaders(const uint8_t* data, size_t length, RebuildMetadata* metadata,
WOFF2Header* hdr, WOFF2Out* out) { … }
}
size_t ComputeWOFF2FinalSize(const uint8_t* data, size_t length) { … }
bool ConvertWOFF2ToTTF(uint8_t *result, size_t result_length,
const uint8_t *data, size_t length) { … }
bool ConvertWOFF2ToTTF(const uint8_t* data, size_t length,
WOFF2Out* out) { … }
}