diff options
author | Norbert Preining <norbert@preining.info> | 2022-08-14 03:00:41 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-08-14 03:00:41 +0000 |
commit | e874d39878309e456c7ffe8d5fc6a91be571b50c (patch) | |
tree | 818c806809254f29f08c3e436a764cbdc566d59a /dviware/dvisvgm/libs/woff2/src | |
parent | b229ca426d9d7fee0e3c48c58a00ffcf3da66cb0 (diff) |
CTAN sync 202208140300
Diffstat (limited to 'dviware/dvisvgm/libs/woff2/src')
-rw-r--r-- | dviware/dvisvgm/libs/woff2/src/glyph.cc | 17 | ||||
-rw-r--r-- | dviware/dvisvgm/libs/woff2/src/glyph.h | 12 | ||||
-rw-r--r-- | dviware/dvisvgm/libs/woff2/src/normalize.cc | 2 | ||||
-rw-r--r-- | dviware/dvisvgm/libs/woff2/src/transform.cc | 20 | ||||
-rw-r--r-- | dviware/dvisvgm/libs/woff2/src/woff2_enc.cc | 8 | ||||
-rw-r--r-- | dviware/dvisvgm/libs/woff2/src/woff2_out.cc | 8 |
6 files changed, 47 insertions, 20 deletions
diff --git a/dviware/dvisvgm/libs/woff2/src/glyph.cc b/dviware/dvisvgm/libs/woff2/src/glyph.cc index 1b4408b924..5b4948679c 100644 --- a/dviware/dvisvgm/libs/woff2/src/glyph.cc +++ b/dviware/dvisvgm/libs/woff2/src/glyph.cc @@ -21,6 +21,7 @@ static const int32_t kFLAG_YSHORT = 1 << 2; static const int32_t kFLAG_REPEAT = 1 << 3; static const int32_t kFLAG_XREPEATSIGN = 1 << 4; static const int32_t kFLAG_YREPEATSIGN = 1 << 5; +static const int32_t kFLAG_OVERLAP_SIMPLE = 1 << 6; static const int32_t kFLAG_ARG_1_AND_2_ARE_WORDS = 1 << 0; static const int32_t kFLAG_WE_HAVE_A_SCALE = 1 << 3; static const int32_t kFLAG_MORE_COMPONENTS = 1 << 5; @@ -134,6 +135,10 @@ bool ReadGlyph(const uint8_t* data, size_t len, Glyph* glyph) { } } + if (!flags.empty() && !flags[0].empty()) { + glyph->overlap_simple_flag_set = (flags[0][0] & kFLAG_OVERLAP_SIMPLE); + } + // Read the x coordinates. int prev_x = 0; for (int i = 0; i < num_contours; ++i) { @@ -239,7 +244,7 @@ bool StoreEndPtsOfContours(const Glyph& glyph, size_t* offset, uint8_t* dst) { bool StorePoints(const Glyph& glyph, size_t* offset, uint8_t* dst, size_t dst_size) { - int last_flag = -1; + int previous_flag = -1; int repeat_count = 0; int last_x = 0; int last_y = 0; @@ -250,6 +255,10 @@ bool StorePoints(const Glyph& glyph, size_t* offset, for (const auto& contour : glyph.contours) { for (const auto& point : contour) { int flag = point.on_curve ? kFLAG_ONCURVE : 0; + if (previous_flag == -1 && glyph.overlap_simple_flag_set) { + // First flag needs to have overlap simple bit set. + flag = flag | kFLAG_OVERLAP_SIMPLE; + } int dx = point.x - last_x; int dy = point.y - last_y; if (dx == 0) { @@ -268,7 +277,7 @@ bool StorePoints(const Glyph& glyph, size_t* offset, } else { y_bytes += 2; } - if (flag == last_flag && repeat_count != 255) { + if (flag == previous_flag && repeat_count != 255) { dst[*offset - 1] |= kFLAG_REPEAT; repeat_count++; } else { @@ -286,7 +295,7 @@ bool StorePoints(const Glyph& glyph, size_t* offset, } last_x = point.x; last_y = point.y; - last_flag = flag; + previous_flag = flag; } } if (repeat_count != 0) { @@ -350,7 +359,7 @@ bool StoreGlyph(const Glyph& glyph, uint8_t* dst, size_t* dst_size) { } } else if (glyph.contours.size() > 0) { // Simple glyph. - if (glyph.contours.size() > size_t(std::numeric_limits<int16_t>::max())) { + if (glyph.contours.size() > std::numeric_limits<int16_t>::max()) { return FONT_COMPRESSION_FAILURE(); } if (*dst_size < ((12ULL + 2 * glyph.contours.size()) + diff --git a/dviware/dvisvgm/libs/woff2/src/glyph.h b/dviware/dvisvgm/libs/woff2/src/glyph.h index f24056f4c8..c38eb5f2bc 100644 --- a/dviware/dvisvgm/libs/woff2/src/glyph.h +++ b/dviware/dvisvgm/libs/woff2/src/glyph.h @@ -10,8 +10,10 @@ #ifndef WOFF2_GLYPH_H_ #define WOFF2_GLYPH_H_ -#include <stddef.h> #include <inttypes.h> +#include <stddef.h> + +#include <cstdint> #include <vector> namespace woff2 { @@ -22,7 +24,10 @@ namespace woff2 { // is around. class Glyph { public: - Glyph() : instructions_size(0), composite_data_size(0) {} + Glyph() + : instructions_size(0), + overlap_simple_flag_set(false), + composite_data_size(0) {} // Bounding box. int16_t x_min; @@ -34,6 +39,9 @@ class Glyph { uint16_t instructions_size; const uint8_t* instructions_data; + // Flags. + bool overlap_simple_flag_set; + // Data model for simple glyphs. struct Point { int x; diff --git a/dviware/dvisvgm/libs/woff2/src/normalize.cc b/dviware/dvisvgm/libs/woff2/src/normalize.cc index dc4bfe6c5c..f7538a1ef3 100644 --- a/dviware/dvisvgm/libs/woff2/src/normalize.cc +++ b/dviware/dvisvgm/libs/woff2/src/normalize.cc @@ -93,7 +93,7 @@ bool MakeEditableBuffer(Font* font, int tableTag) { if (table->IsReused()) { return true; } - uint32_t sz = Round4(table->length); + unsigned sz = Round4(table->length); table->buffer.resize(sz); uint8_t* buf = &table->buffer[0]; memcpy(buf, table->data, table->length); diff --git a/dviware/dvisvgm/libs/woff2/src/transform.cc b/dviware/dvisvgm/libs/woff2/src/transform.cc index 999bef3745..1016efcd2b 100644 --- a/dviware/dvisvgm/libs/woff2/src/transform.cc +++ b/dviware/dvisvgm/libs/woff2/src/transform.cc @@ -22,6 +22,7 @@ namespace { const int FLAG_ARG_1_AND_2_ARE_WORDS = 1 << 0; const int FLAG_WE_HAVE_INSTRUCTIONS = 1 << 8; +const int FLAG_OVERLAP_SIMPLE_BITMAP = 1 << 0; void WriteBytes(std::vector<uint8_t>* out, const uint8_t* data, size_t len) { if (len == 0) return; @@ -69,7 +70,10 @@ class GlyfEncoder { } void GetTransformedGlyfBytes(std::vector<uint8_t>* result) { - WriteLong(result, 0); // version + WriteUShort(result, 0); // Version + WriteUShort(result, overlap_bitmap_.empty() + ? 0x00 + : FLAG_OVERLAP_SIMPLE_BITMAP); // Flags WriteUShort(result, n_glyphs_); WriteUShort(result, 0); // index_format, will be set later WriteLong(result, n_contour_stream_.size()); @@ -87,6 +91,9 @@ class GlyfEncoder { WriteBytes(result, bbox_bitmap_); WriteBytes(result, bbox_stream_); WriteBytes(result, instruction_stream_); + if (!overlap_bitmap_.empty()) { + WriteBytes(result, overlap_bitmap_); + } } private: @@ -127,6 +134,10 @@ class GlyfEncoder { } void WriteSimpleGlyph(int glyph_id, const Glyph& glyph) { + if (glyph.overlap_simple_flag_set) { + EnsureOverlapBitmap(); + overlap_bitmap_[glyph_id >> 3] |= 0x80 >> (glyph_id & 7); + } int num_contours = glyph.contours.size(); WriteUShort(&n_contour_stream_, num_contours); if (ShouldWriteSimpleGlyphBbox(glyph)) { @@ -214,6 +225,12 @@ class GlyfEncoder { } } + void EnsureOverlapBitmap() { + if (overlap_bitmap_.empty()) { + overlap_bitmap_.resize((n_glyphs_ + 7) >> 3); + } + } + std::vector<uint8_t> n_contour_stream_; std::vector<uint8_t> n_points_stream_; std::vector<uint8_t> flag_byte_stream_; @@ -222,6 +239,7 @@ class GlyfEncoder { std::vector<uint8_t> bbox_stream_; std::vector<uint8_t> glyph_stream_; std::vector<uint8_t> instruction_stream_; + std::vector<uint8_t> overlap_bitmap_; int n_glyphs_; }; diff --git a/dviware/dvisvgm/libs/woff2/src/woff2_enc.cc b/dviware/dvisvgm/libs/woff2/src/woff2_enc.cc index 9f32df90ee..43c8bdc9d8 100644 --- a/dviware/dvisvgm/libs/woff2/src/woff2_enc.cc +++ b/dviware/dvisvgm/libs/woff2/src/woff2_enc.cc @@ -28,12 +28,8 @@ namespace woff2 { -namespace { - - -using std::string; -using std::vector; +namespace { const size_t kWoff2HeaderSize = 48; const size_t kWoff2EntrySize = 20; @@ -183,7 +179,7 @@ size_t MaxWOFF2CompressedSize(const uint8_t* data, size_t length) { } size_t MaxWOFF2CompressedSize(const uint8_t* data, size_t length, - const string& extended_metadata) { + const std::string& extended_metadata) { // Except for the header size, which is 32 bytes larger in woff2 format, // all other parts should be smaller (table header in short format, // transformations and compression). Just to be sure, we will give some diff --git a/dviware/dvisvgm/libs/woff2/src/woff2_out.cc b/dviware/dvisvgm/libs/woff2/src/woff2_out.cc index 8ab32681f1..a22d3bf8be 100644 --- a/dviware/dvisvgm/libs/woff2/src/woff2_out.cc +++ b/dviware/dvisvgm/libs/woff2/src/woff2_out.cc @@ -8,14 +8,10 @@ #include <woff2/output.h> -using std::string; - namespace woff2 { -WOFF2StringOut::WOFF2StringOut(string* buf) - : buf_(buf), - max_size_(kDefaultMaxSize), - offset_(0) {} +WOFF2StringOut::WOFF2StringOut(std::string *buf) + : buf_(buf), max_size_(kDefaultMaxSize), offset_(0) {} bool WOFF2StringOut::Write(const void *buf, size_t n) { return Write(buf, offset_, n); |