chromium/third_party/woff2/src/woff2_dec.cc

/* Copyright 2014 Google Inc. All Rights Reserved.

   Distributed under MIT license.
   See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/

/* Library for converting WOFF2 format font files to their TTF versions. */

#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 {

// simple glyph flags
const int kGlyfOnCurve =;
const int kGlyfXShort =;
const int kGlyfYShort =;
const int kGlyfRepeat =;
const int kGlyfThisXIsSame =;
const int kGlyfThisYIsSame =;
const int kOverlapSimple =;

// composite glyph flags
// See CompositeGlyph.java in sfntly for full definitions
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 =;

// glyf flags
const int FLAG_OVERLAP_SIMPLE_BITMAP =;

const size_t kCheckSumAdjustmentOffset =;

const size_t kEndPtsOfContoursOffset =;
const size_t kCompositeGlyphBegin =;

// 98% of Google Fonts have no glyph above 5k bytes
// Largest glyph ever observed was 72k bytes
const size_t kDefaultGlyphBuf =;

// Over 14k test fonts the max compression ratio seen to date was ~20.
// >100 suggests you wrote a bad uncompressed size.
const float kMaxPlausibleCompressionRatio =;

// metadata for a TTC font entry
struct TtcFont {};

struct WOFF2Header {};

/**
 * Accumulates data we may need to reconstruct a single font. One per font
 * created for a TTC.
 */
struct WOFF2FontInfo {};

// Accumulates metadata as we rebuild the font
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) {}

// This function stores just the point data. On entry, dst points to the
// beginning of a simple glyph. Returns true on success.
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) {}

// Compute the bounding box of the coordinates, and store into a glyf buffer.
// A precondition is that there are at least 10 bytes available.
// dst should point to the beginning of a 'glyf' record.
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) {}

// Build TrueType loca table
bool StoreLoca(const std::vector<uint32_t>& loca_values, int index_format,
               uint32_t* checksum, WOFF2Out* out) {}

// Reconstruct entire glyf table based on transformed original
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) {}

// Get numberOfHMetrics, https://www.microsoft.com/typography/otspec/hhea.htm
bool ReadNumHMetrics(const uint8_t* data, size_t data_size,
                     uint16_t* num_hmetrics) {}

// http://dev.w3.org/webfonts/WOFF2/spec/Overview.html#hmtx_table_format
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) {}

// Writes a single Offset Table entry
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) {}

// First table goes after all the headers, table directory, etc
uint64_t ComputeOffsetToFirstTable(const WOFF2Header& hdr) {}

std::vector<Table*> Tables(WOFF2Header* hdr, size_t font_index) {}

// Offset tables assumed to have been written in with 0's initially.
// WOFF2Header isn't const so we can use [] instead of at() (which upsets FF)
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) {}

// Write everything before the actual table data
bool WriteHeaders(const uint8_t* data, size_t length, RebuildMetadata* metadata,
                  WOFF2Header* hdr, WOFF2Out* out) {}

}  // namespace

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) {}

} // namespace woff2