Update to latest brotli. Use size_t more consistently. Remove dead code.
This commit is contained in:
+1
-1
Submodule brotli updated: 9c9bb00f7f...510131d1db
+3
-3
@@ -141,7 +141,7 @@ bool ReadTrueTypeCollection(Buffer* file, const uint8_t* data, size_t len,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint32_t> offsets;
|
std::vector<uint32_t> offsets;
|
||||||
for (auto i = 0; i < num_fonts; i++) {
|
for (size_t i = 0; i < num_fonts; i++) {
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
if (!file->ReadU32(&offset)) {
|
if (!file->ReadU32(&offset)) {
|
||||||
return FONT_COMPRESSION_FAILURE();
|
return FONT_COMPRESSION_FAILURE();
|
||||||
@@ -297,7 +297,7 @@ bool WriteFontCollection(const FontCollection& font_collection, uint8_t* dst,
|
|||||||
|
|
||||||
// Offset Table, zeroed for now
|
// Offset Table, zeroed for now
|
||||||
size_t offset_table = offset; // where to write offsets later
|
size_t offset_table = offset; // where to write offsets later
|
||||||
for (int i = 0; i < font_collection.fonts.size(); i++) {
|
for (size_t i = 0; i < font_collection.fonts.size(); i++) {
|
||||||
StoreU32(0, &offset, dst);
|
StoreU32(0, &offset, dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,7 +308,7 @@ bool WriteFontCollection(const FontCollection& font_collection, uint8_t* dst,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write fonts and their offsets.
|
// Write fonts and their offsets.
|
||||||
for (int i = 0; i < font_collection.fonts.size(); i++) {
|
for (size_t i = 0; i < font_collection.fonts.size(); i++) {
|
||||||
const auto& font = font_collection.fonts[i];
|
const auto& font = font_collection.fonts[i];
|
||||||
StoreU32(offset, &offset_table, dst);
|
StoreU32(offset, &offset_table, dst);
|
||||||
if (!WriteFont(font, &offset, dst, dst_size)) {
|
if (!WriteFont(font, &offset, dst, dst_size)) {
|
||||||
|
|||||||
+3
-3
@@ -122,7 +122,7 @@ bool ReadGlyph(const uint8_t* data, size_t len, Glyph* glyph) {
|
|||||||
uint8_t flag_repeat = 0;
|
uint8_t flag_repeat = 0;
|
||||||
for (int i = 0; i < num_contours; ++i) {
|
for (int i = 0; i < num_contours; ++i) {
|
||||||
flags[i].resize(glyph->contours[i].size());
|
flags[i].resize(glyph->contours[i].size());
|
||||||
for (int j = 0; j < glyph->contours[i].size(); ++j) {
|
for (size_t j = 0; j < glyph->contours[i].size(); ++j) {
|
||||||
if (flag_repeat == 0) {
|
if (flag_repeat == 0) {
|
||||||
if (!buffer.ReadU8(&flag)) {
|
if (!buffer.ReadU8(&flag)) {
|
||||||
return FONT_COMPRESSION_FAILURE();
|
return FONT_COMPRESSION_FAILURE();
|
||||||
@@ -143,7 +143,7 @@ bool ReadGlyph(const uint8_t* data, size_t len, Glyph* glyph) {
|
|||||||
// Read the x coordinates.
|
// Read the x coordinates.
|
||||||
int prev_x = 0;
|
int prev_x = 0;
|
||||||
for (int i = 0; i < num_contours; ++i) {
|
for (int i = 0; i < num_contours; ++i) {
|
||||||
for (int j = 0; j < glyph->contours[i].size(); ++j) {
|
for (size_t j = 0; j < glyph->contours[i].size(); ++j) {
|
||||||
uint8_t flag = flags[i][j];
|
uint8_t flag = flags[i][j];
|
||||||
if (flag & kFLAG_XSHORT) {
|
if (flag & kFLAG_XSHORT) {
|
||||||
// single byte x-delta coord value
|
// single byte x-delta coord value
|
||||||
@@ -170,7 +170,7 @@ bool ReadGlyph(const uint8_t* data, size_t len, Glyph* glyph) {
|
|||||||
// Read the y coordinates.
|
// Read the y coordinates.
|
||||||
int prev_y = 0;
|
int prev_y = 0;
|
||||||
for (int i = 0; i < num_contours; ++i) {
|
for (int i = 0; i < num_contours; ++i) {
|
||||||
for (int j = 0; j < glyph->contours[i].size(); ++j) {
|
for (size_t j = 0; j < glyph->contours[i].size(); ++j) {
|
||||||
uint8_t flag = flags[i][j];
|
uint8_t flag = flags[i][j];
|
||||||
if (flag & kFLAG_YSHORT) {
|
if (flag & kFLAG_YSHORT) {
|
||||||
// single byte y-delta coord value
|
// single byte y-delta coord value
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
#ifndef WOFF2_PORT_H_
|
#ifndef WOFF2_PORT_H_
|
||||||
#define WOFF2_PORT_H_
|
#define WOFF2_PORT_H_
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
namespace woff2 {
|
namespace woff2 {
|
||||||
|
|
||||||
typedef unsigned int uint32;
|
typedef unsigned int uint32;
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ void WriteBytes(std::vector<uint8_t>* out, const uint8_t* data, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WriteBytes(std::vector<uint8_t>* out, const std::vector<uint8_t>& in) {
|
void WriteBytes(std::vector<uint8_t>* out, const std::vector<uint8_t>& in) {
|
||||||
for (int i = 0; i < in.size(); ++i) {
|
for (size_t i = 0; i < in.size(); ++i) {
|
||||||
out->push_back(in[i]);
|
out->push_back(in[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -635,35 +635,6 @@ Table* FindTable(std::vector<Table*>* tables, uint32_t tag) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is linear search, but could be changed to binary because we
|
|
||||||
// do have a guarantee that the tables are sorted by tag. But the total
|
|
||||||
// cpu time is expected to be very small in any case.
|
|
||||||
const Table* FindTable(const std::vector<Table>& tables, uint32_t tag) {
|
|
||||||
size_t n_tables = tables.size();
|
|
||||||
for (size_t i = 0; i < n_tables; ++i) {
|
|
||||||
if (tables[i].tag == tag) {
|
|
||||||
return &tables[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://www.microsoft.com/typography/otspec/maxp.htm
|
|
||||||
bool ReadNumGlyphs(const Table* maxp_table,
|
|
||||||
const uint8_t* dst, size_t dst_length,
|
|
||||||
uint16_t* num_glyphs) {
|
|
||||||
if (PREDICT_FALSE(static_cast<uint64_t>(maxp_table->dst_offset +
|
|
||||||
maxp_table->dst_length) > dst_length)) {
|
|
||||||
return FONT_COMPRESSION_FAILURE();
|
|
||||||
}
|
|
||||||
Buffer buffer(dst + maxp_table->dst_offset, maxp_table->dst_length);
|
|
||||||
// Skip 4 to reach 'maxp' numGlyphs
|
|
||||||
if (PREDICT_FALSE(!buffer.Skip(4) || !buffer.ReadU16(num_glyphs))) {
|
|
||||||
return FONT_COMPRESSION_FAILURE();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get numberOfHMetrics, https://www.microsoft.com/typography/otspec/hhea.htm
|
// Get numberOfHMetrics, https://www.microsoft.com/typography/otspec/hhea.htm
|
||||||
bool ReadNumHMetrics(const uint8_t* data, size_t data_size,
|
bool ReadNumHMetrics(const uint8_t* data, size_t data_size,
|
||||||
uint16_t* num_hmetrics) {
|
uint16_t* num_hmetrics) {
|
||||||
@@ -675,37 +646,6 @@ bool ReadNumHMetrics(const uint8_t* data, size_t data_size,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// x_min for glyph; https://www.microsoft.com/typography/otspec/glyf.htm
|
|
||||||
bool ReadGlyphXMin(Buffer* glyf_buff, Buffer* loca_buff, int16_t loca_format,
|
|
||||||
uint16_t index, int16_t* x_min) {
|
|
||||||
uint32_t offset1, offset2;
|
|
||||||
loca_buff->set_offset((loca_format == 0 ? 2 : 4) * index);
|
|
||||||
if (loca_format == 0) {
|
|
||||||
uint16_t tmp1, tmp2;
|
|
||||||
if (PREDICT_FALSE(!loca_buff->ReadU16(&tmp1) ||
|
|
||||||
!loca_buff->ReadU16(&tmp2))) {
|
|
||||||
return FONT_COMPRESSION_FAILURE();
|
|
||||||
}
|
|
||||||
// https://www.microsoft.com/typography/otspec/loca.htm
|
|
||||||
// "The actual local offset divided by 2 is stored."
|
|
||||||
offset1 = tmp1 * 2;
|
|
||||||
offset2 = tmp2 * 2;
|
|
||||||
} else if (PREDICT_FALSE(!loca_buff->ReadU32(&offset1) ||
|
|
||||||
!loca_buff->ReadU32(&offset2))) {
|
|
||||||
return FONT_COMPRESSION_FAILURE();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (offset1 != offset2) {
|
|
||||||
glyf_buff->set_offset(offset1 + 2);
|
|
||||||
if (!glyf_buff->ReadS16(x_min)) {
|
|
||||||
return FONT_COMPRESSION_FAILURE();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
*x_min = 0;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://dev.w3.org/webfonts/WOFF2/spec/Overview.html#hmtx_table_format
|
// http://dev.w3.org/webfonts/WOFF2/spec/Overview.html#hmtx_table_format
|
||||||
bool ReconstructTransformedHmtx(const uint8_t* transformed_buf,
|
bool ReconstructTransformedHmtx(const uint8_t* transformed_buf,
|
||||||
size_t transformed_size,
|
size_t transformed_size,
|
||||||
@@ -785,18 +725,6 @@ bool ReconstructTransformedHmtx(const uint8_t* transformed_buf,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ComputeChecksum(const Table* table, const uint8_t* dst) {
|
|
||||||
return ComputeULongSum(dst + table->dst_offset, table->dst_length);
|
|
||||||
}
|
|
||||||
|
|
||||||
const Table* FindTable(TtcFont ttc_font, const std::vector<Table>& tables,
|
|
||||||
uint32_t tag) {
|
|
||||||
for (const auto i : ttc_font.table_indices) {
|
|
||||||
if (tables[i].tag == tag) return &tables[i];
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Woff2Uncompress(uint8_t* dst_buf, size_t dst_size,
|
bool Woff2Uncompress(uint8_t* dst_buf, size_t dst_size,
|
||||||
const uint8_t* src_buf, size_t src_size) {
|
const uint8_t* src_buf, size_t src_size) {
|
||||||
size_t uncompressed_size = dst_size;
|
size_t uncompressed_size = dst_size;
|
||||||
|
|||||||
+1
-9
@@ -23,7 +23,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "./encode.h"
|
#include "./compressor.h"
|
||||||
#include "./buffer.h"
|
#include "./buffer.h"
|
||||||
#include "./font.h"
|
#include "./font.h"
|
||||||
#include "./normalize.h"
|
#include "./normalize.h"
|
||||||
@@ -148,14 +148,6 @@ size_t ComputeWoff2Length(const FontCollection& font_collection,
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ComputeTTFLength(const std::vector<Table>& tables) {
|
|
||||||
size_t size = 12 + 16 * tables.size(); // sfnt header
|
|
||||||
for (const auto& table : tables) {
|
|
||||||
size += Round4(table.src_length);
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t ComputeUncompressedLength(const Font& font) {
|
size_t ComputeUncompressedLength(const Font& font) {
|
||||||
// sfnt header + offset table
|
// sfnt header + offset table
|
||||||
size_t size = 12 + 16 * font.num_tables;
|
size_t size = 12 + 16 * font.num_tables;
|
||||||
|
|||||||
Reference in New Issue
Block a user