diff --git a/src/woff2_enc.cc b/src/woff2_enc.cc index 48878b5..39e2ddc 100644 --- a/src/woff2_enc.cc +++ b/src/woff2_enc.cc @@ -272,20 +272,22 @@ bool ConvertTTFToWOFF2(const uint8_t *data, size_t length, std::vector compression_buf(compression_buffer_size); uint32_t total_compressed_length = compression_buffer_size; - // Collect all transformed data into one place. + // Collect all transformed data into one place in output order. std::vector transform_buf(total_transform_length); size_t transform_offset = 0; for (const auto& font : font_collection.fonts) { - for (const auto& i : font.tables) { - const Font::Table* table = font.FindTable(i.second.tag ^ 0x80808080); - if (i.second.IsReused()) continue; - if (i.second.tag & 0x80808080) continue; + for (const auto tag : font.OutputOrderedTags()) { + const Font::Table& original = font.tables.at(tag); + if (original.IsReused()) continue; + if (tag & 0x80808080) continue; + const Font::Table* table_to_store = font.FindTable(tag ^ 0x80808080); + if (table_to_store == NULL) table_to_store = &original; - if (table == NULL) table = &i.second; - StoreBytes(table->data, table->length, + StoreBytes(table_to_store->data, table_to_store->length, &transform_offset, &transform_buf[0]); } } + // Compress all transformed data in one stream. if (!Woff2Compress(transform_buf.data(), total_transform_length, &compression_buf[0],