| Index: third_party/ots/src/head.cc
|
| diff --git a/third_party/ots/src/head.cc b/third_party/ots/src/head.cc
|
| index dcd234d24c00cbe19fabc085f59aaf96fbad2ba5..229ea71f9035c5832ee86c343c0b0c79e2d6349c 100644
|
| --- a/third_party/ots/src/head.cc
|
| +++ b/third_party/ots/src/head.cc
|
| @@ -13,13 +13,14 @@
|
|
|
| namespace ots {
|
|
|
| -bool ots_head_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
|
| +bool ots_head_parse(Font* font, const uint8_t *data, size_t length) {
|
| Buffer table(data, length);
|
| - file->head = new OpenTypeHEAD;
|
| + OpenTypeHEAD *head = new OpenTypeHEAD;
|
| + font->head = head;
|
|
|
| uint32_t version = 0;
|
| if (!table.ReadU32(&version) ||
|
| - !table.ReadU32(&file->head->revision)) {
|
| + !table.ReadU32(&head->revision)) {
|
| return OTS_FAILURE_MSG("Failed to read head header");
|
| }
|
|
|
| @@ -33,64 +34,63 @@ bool ots_head_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
|
| }
|
|
|
| uint32_t magic;
|
| - if (!table.ReadTag(&magic) ||
|
| - std::memcmp(&magic, "\x5F\x0F\x3C\xF5", 4)) {
|
| + if (!table.ReadU32(&magic) || magic != 0x5F0F3CF5) {
|
| return OTS_FAILURE_MSG("Failed to read font magic number");
|
| }
|
|
|
| - if (!table.ReadU16(&file->head->flags)) {
|
| + if (!table.ReadU16(&head->flags)) {
|
| return OTS_FAILURE_MSG("Failed to read head flags");
|
| }
|
|
|
| // We allow bits 0..4, 11..13
|
| - file->head->flags &= 0x381f;
|
| + head->flags &= 0x381f;
|
|
|
| - if (!table.ReadU16(&file->head->ppem)) {
|
| + if (!table.ReadU16(&head->ppem)) {
|
| return OTS_FAILURE_MSG("Failed to read pixels per em");
|
| }
|
|
|
| // ppem must be in range
|
| - if (file->head->ppem < 16 ||
|
| - file->head->ppem > 16384) {
|
| - return OTS_FAILURE_MSG("Bad ppm of %d", file->head->ppem);
|
| + if (head->ppem < 16 ||
|
| + head->ppem > 16384) {
|
| + return OTS_FAILURE_MSG("Bad ppm of %d", head->ppem);
|
| }
|
|
|
| // ppem must be a power of two
|
| #if 0
|
| // We don't call ots_failure() for now since lots of TrueType fonts are
|
| // not following this rule. Putting OTS_WARNING here is too noisy.
|
| - if ((file->head->ppem - 1) & file->head->ppem) {
|
| - return OTS_FAILURE_MSG("ppm not a power of two: %d", file->head->ppem);
|
| + if ((head->ppem - 1) & head->ppem) {
|
| + return OTS_FAILURE_MSG("ppm not a power of two: %d", head->ppem);
|
| }
|
| #endif
|
|
|
| - if (!table.ReadR64(&file->head->created) ||
|
| - !table.ReadR64(&file->head->modified)) {
|
| + if (!table.ReadR64(&head->created) ||
|
| + !table.ReadR64(&head->modified)) {
|
| return OTS_FAILURE_MSG("Can't read font dates");
|
| }
|
|
|
| - if (!table.ReadS16(&file->head->xmin) ||
|
| - !table.ReadS16(&file->head->ymin) ||
|
| - !table.ReadS16(&file->head->xmax) ||
|
| - !table.ReadS16(&file->head->ymax)) {
|
| + if (!table.ReadS16(&head->xmin) ||
|
| + !table.ReadS16(&head->ymin) ||
|
| + !table.ReadS16(&head->xmax) ||
|
| + !table.ReadS16(&head->ymax)) {
|
| return OTS_FAILURE_MSG("Failed to read font bounding box");
|
| }
|
|
|
| - if (file->head->xmin > file->head->xmax) {
|
| - return OTS_FAILURE_MSG("Bad x dimension in the font bounding box (%d, %d)", file->head->xmin, file->head->xmax);
|
| + if (head->xmin > head->xmax) {
|
| + return OTS_FAILURE_MSG("Bad x dimension in the font bounding box (%d, %d)", head->xmin, head->xmax);
|
| }
|
| - if (file->head->ymin > file->head->ymax) {
|
| - return OTS_FAILURE_MSG("Bad y dimension in the font bounding box (%d, %d)", file->head->ymin, file->head->ymax);
|
| + if (head->ymin > head->ymax) {
|
| + return OTS_FAILURE_MSG("Bad y dimension in the font bounding box (%d, %d)", head->ymin, head->ymax);
|
| }
|
|
|
| - if (!table.ReadU16(&file->head->mac_style)) {
|
| + if (!table.ReadU16(&head->mac_style)) {
|
| return OTS_FAILURE_MSG("Failed to read font style");
|
| }
|
|
|
| // We allow bits 0..6
|
| - file->head->mac_style &= 0x7f;
|
| + head->mac_style &= 0x7f;
|
|
|
| - if (!table.ReadU16(&file->head->min_ppem)) {
|
| + if (!table.ReadU16(&head->min_ppem)) {
|
| return OTS_FAILURE_MSG("Failed to read font minimum ppm");
|
| }
|
|
|
| @@ -99,12 +99,12 @@ bool ots_head_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
|
| return OTS_FAILURE_MSG("Failed to skip font direction hint");
|
| }
|
|
|
| - if (!table.ReadS16(&file->head->index_to_loc_format)) {
|
| + if (!table.ReadS16(&head->index_to_loc_format)) {
|
| return OTS_FAILURE_MSG("Failed to read index to loc format");
|
| }
|
| - if (file->head->index_to_loc_format < 0 ||
|
| - file->head->index_to_loc_format > 1) {
|
| - return OTS_FAILURE_MSG("Bad index to loc format %d", file->head->index_to_loc_format);
|
| + if (head->index_to_loc_format < 0 ||
|
| + head->index_to_loc_format > 1) {
|
| + return OTS_FAILURE_MSG("Bad index to loc format %d", head->index_to_loc_format);
|
| }
|
|
|
| int16_t glyph_data_format;
|
| @@ -116,27 +116,28 @@ bool ots_head_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
|
| return true;
|
| }
|
|
|
| -bool ots_head_should_serialise(OpenTypeFile *file) {
|
| - return file->head != NULL;
|
| +bool ots_head_should_serialise(Font *font) {
|
| + return font->head != NULL;
|
| }
|
|
|
| -bool ots_head_serialise(OTSStream *out, OpenTypeFile *file) {
|
| +bool ots_head_serialise(OTSStream *out, Font *font) {
|
| + const OpenTypeHEAD *head = font->head;
|
| if (!out->WriteU32(0x00010000) ||
|
| - !out->WriteU32(file->head->revision) ||
|
| + !out->WriteU32(head->revision) ||
|
| !out->WriteU32(0) || // check sum not filled in yet
|
| !out->WriteU32(0x5F0F3CF5) ||
|
| - !out->WriteU16(file->head->flags) ||
|
| - !out->WriteU16(file->head->ppem) ||
|
| - !out->WriteR64(file->head->created) ||
|
| - !out->WriteR64(file->head->modified) ||
|
| - !out->WriteS16(file->head->xmin) ||
|
| - !out->WriteS16(file->head->ymin) ||
|
| - !out->WriteS16(file->head->xmax) ||
|
| - !out->WriteS16(file->head->ymax) ||
|
| - !out->WriteU16(file->head->mac_style) ||
|
| - !out->WriteU16(file->head->min_ppem) ||
|
| + !out->WriteU16(head->flags) ||
|
| + !out->WriteU16(head->ppem) ||
|
| + !out->WriteR64(head->created) ||
|
| + !out->WriteR64(head->modified) ||
|
| + !out->WriteS16(head->xmin) ||
|
| + !out->WriteS16(head->ymin) ||
|
| + !out->WriteS16(head->xmax) ||
|
| + !out->WriteS16(head->ymax) ||
|
| + !out->WriteU16(head->mac_style) ||
|
| + !out->WriteU16(head->min_ppem) ||
|
| !out->WriteS16(2) ||
|
| - !out->WriteS16(file->head->index_to_loc_format) ||
|
| + !out->WriteS16(head->index_to_loc_format) ||
|
| !out->WriteS16(0)) {
|
| return OTS_FAILURE_MSG("Failed to write head table");
|
| }
|
| @@ -144,8 +145,13 @@ bool ots_head_serialise(OTSStream *out, OpenTypeFile *file) {
|
| return true;
|
| }
|
|
|
| -void ots_head_free(OpenTypeFile *file) {
|
| - delete file->head;
|
| +void ots_head_reuse(Font *font, Font *other) {
|
| + font->head = other->head;
|
| + font->head_reused = true;
|
| +}
|
| +
|
| +void ots_head_free(Font *font) {
|
| + delete font->head;
|
| }
|
|
|
| } // namespace
|
|
|