bool NormalizeGlyphs(Font* font) {
Font::Table* head_table = font->FindTable(kHeadTableTag);
Font::Table* glyf_table = font->FindTable(kGlyfTableTag);
Font::Table* loca_table = font->FindTable(kLocaTableTag); if (head_table == NULL) { return FONT_COMPRESSION_FAILURE();
} // If you don't have glyf/loca this transform isn't very interesting if (loca_table == NULL && glyf_table == NULL) { returntrue;
} // It would be best if you didn't have just one of glyf/loca if ((glyf_table == NULL) != (loca_table == NULL)) { return FONT_COMPRESSION_FAILURE();
} // Must share neither or both loca & glyf if (loca_table->IsReused() != glyf_table->IsReused()) { return FONT_COMPRESSION_FAILURE();
} if (loca_table->IsReused()) { returntrue;
}
int index_fmt = head_table->data[51]; int num_glyphs = NumGlyphs(*font);
// We need to allocate a bit more than its original length for the normalized // glyf table, since it can happen that the glyphs in the original table are // 2-byte aligned, while in the normalized table they are 4-byte aligned. // That gives a maximum of 2 bytes increase per glyph. However, there is no // theoretical guarantee that the total size of the flags plus the coordinates // is the smallest possible in the normalized version, so we have to allow // some general overhead. // TODO(user) Figure out some more precise upper bound on the size of // the overhead.
size_t max_normalized_glyf_size = 1.1 * glyf_table->length + 2 * num_glyphs;
// if we can't write a loca using short's (index_fmt 0) // try again using longs (index_fmt 1) if (!WriteNormalizedLoca(index_fmt, num_glyphs, font)) { if (index_fmt != 0) { return FONT_COMPRESSION_FAILURE();
}
// Rewrite loca with 4-byte entries & update head to match
index_fmt = 1; if (!WriteNormalizedLoca(index_fmt, num_glyphs, font)) { return FONT_COMPRESSION_FAILURE();
}
head_table->buffer[51] = 1;
}
// Start table offsets after TTC Header and Sfnt Headers for (auto& font : font_collection->fonts) { for (auto tag : font.OutputOrderedTags()) {
Font::Table& table = font.tables[tag]; if (table.IsReused()) {
table.offset = table.reuse_of->offset;
} else {
table.offset = offset;
offset += Round4(table.length);
}
}
}
// Now we can fix the checksums for (auto& font : font_collection->fonts) { if (!FixChecksums(&font)) { #ifdef FONT_COMPRESSION_BIN
fprintf(stderr, "Failed to fix checksums\n"); #endif return FONT_COMPRESSION_FAILURE();
}
}
returntrue;
}
} // namespace woff2
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.