summaryrefslogtreecommitdiffstats
path: root/gfx/ots/src/head.cc
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-11-14 10:07:01 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-11-14 10:07:01 +0100
commit0f8691a48869932cd3de5195f5211c25e4691b21 (patch)
tree829675d64c457be0b447dfbcf9534cc22f83d392 /gfx/ots/src/head.cc
parent36975f3865948f3faa959fe386e58b22783bd379 (diff)
downloadUXP-0f8691a48869932cd3de5195f5211c25e4691b21.tar
UXP-0f8691a48869932cd3de5195f5211c25e4691b21.tar.gz
UXP-0f8691a48869932cd3de5195f5211c25e4691b21.tar.lz
UXP-0f8691a48869932cd3de5195f5211c25e4691b21.tar.xz
UXP-0f8691a48869932cd3de5195f5211c25e4691b21.zip
Issue #1288 - Part 4: Update the OpenType Sanitizer component to 8.0.0
Diffstat (limited to 'gfx/ots/src/head.cc')
-rw-r--r--gfx/ots/src/head.cc139
1 files changed, 56 insertions, 83 deletions
diff --git a/gfx/ots/src/head.cc b/gfx/ots/src/head.cc
index 229ea71f9..6088504c8 100644
--- a/gfx/ots/src/head.cc
+++ b/gfx/ots/src/head.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009-2017 The OTS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,151 +9,124 @@
// head - Font Header
// http://www.microsoft.com/typography/otspec/head.htm
-#define TABLE_NAME "head"
-
namespace ots {
-bool ots_head_parse(Font* font, const uint8_t *data, size_t length) {
+bool OpenTypeHEAD::Parse(const uint8_t *data, size_t length) {
Buffer table(data, length);
- OpenTypeHEAD *head = new OpenTypeHEAD;
- font->head = head;
uint32_t version = 0;
if (!table.ReadU32(&version) ||
- !table.ReadU32(&head->revision)) {
- return OTS_FAILURE_MSG("Failed to read head header");
+ !table.ReadU32(&this->revision)) {
+ return Error("Failed to read table header");
}
if (version >> 16 != 1) {
- return OTS_FAILURE_MSG("Bad head table version of %d", version);
+ return Error("Unsupported majorVersion: %d", version >> 16);
}
// Skip the checksum adjustment
if (!table.Skip(4)) {
- return OTS_FAILURE_MSG("Failed to read checksum");
+ return Error("Failed to read checksum");
}
uint32_t magic;
if (!table.ReadU32(&magic) || magic != 0x5F0F3CF5) {
- return OTS_FAILURE_MSG("Failed to read font magic number");
+ return Error("Failed to read or incorrect magicNumber");
}
- if (!table.ReadU16(&head->flags)) {
- return OTS_FAILURE_MSG("Failed to read head flags");
+ if (!table.ReadU16(&this->flags)) {
+ return Error("Failed to read flags");
}
// We allow bits 0..4, 11..13
- head->flags &= 0x381f;
-
- if (!table.ReadU16(&head->ppem)) {
- return OTS_FAILURE_MSG("Failed to read pixels per em");
- }
+ this->flags &= 0x381f;
- // ppem must be in range
- if (head->ppem < 16 ||
- head->ppem > 16384) {
- return OTS_FAILURE_MSG("Bad ppm of %d", head->ppem);
+ if (!table.ReadU16(&this->upem)) {
+ return Error("Failed to read unitsPerEm");
}
- // 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 ((head->ppem - 1) & head->ppem) {
- return OTS_FAILURE_MSG("ppm not a power of two: %d", head->ppem);
+ // upem must be in range
+ if (this->upem < 16 ||
+ this->upem > 16384) {
+ return Error("unitsPerEm on in the range [16, 16384]: %d", this->upem);
}
-#endif
- if (!table.ReadR64(&head->created) ||
- !table.ReadR64(&head->modified)) {
- return OTS_FAILURE_MSG("Can't read font dates");
+ if (!table.ReadR64(&this->created) ||
+ !table.ReadR64(&this->modified)) {
+ return Error("Can't read font dates");
}
- 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 (!table.ReadS16(&this->xmin) ||
+ !table.ReadS16(&this->ymin) ||
+ !table.ReadS16(&this->xmax) ||
+ !table.ReadS16(&this->ymax)) {
+ return Error("Failed to read font bounding box");
}
- if (head->xmin > head->xmax) {
- return OTS_FAILURE_MSG("Bad x dimension in the font bounding box (%d, %d)", head->xmin, head->xmax);
+ if (this->xmin > this->xmax) {
+ return Error("Bad x dimension in the font bounding box (%d, %d)",
+ this->xmin, this->xmax);
}
- if (head->ymin > head->ymax) {
- return OTS_FAILURE_MSG("Bad y dimension in the font bounding box (%d, %d)", head->ymin, head->ymax);
+ if (this->ymin > this->ymax) {
+ return Error("Bad y dimension in the font bounding box (%d, %d)",
+ this->ymin, this->ymax);
}
- if (!table.ReadU16(&head->mac_style)) {
- return OTS_FAILURE_MSG("Failed to read font style");
+ if (!table.ReadU16(&this->mac_style)) {
+ return Error("Failed to read macStyle");
}
// We allow bits 0..6
- head->mac_style &= 0x7f;
+ this->mac_style &= 0x7f;
- if (!table.ReadU16(&head->min_ppem)) {
- return OTS_FAILURE_MSG("Failed to read font minimum ppm");
+ if (!table.ReadU16(&this->min_ppem)) {
+ return Error("Failed to read lowestRecPPEM");
}
// We don't care about the font direction hint
if (!table.Skip(2)) {
- return OTS_FAILURE_MSG("Failed to skip font direction hint");
+ return Error("Failed to read fontDirectionHint");
}
- if (!table.ReadS16(&head->index_to_loc_format)) {
- return OTS_FAILURE_MSG("Failed to read index to loc format");
+ if (!table.ReadS16(&this->index_to_loc_format)) {
+ return Error("Failed to read indexToLocFormat");
}
- 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);
+ if (this->index_to_loc_format < 0 ||
+ this->index_to_loc_format > 1) {
+ return Error("Bad indexToLocFormat %d", this->index_to_loc_format);
}
int16_t glyph_data_format;
if (!table.ReadS16(&glyph_data_format) ||
glyph_data_format) {
- return OTS_FAILURE_MSG("Failed to read glyph data format");
+ return Error("Failed to read or bad glyphDataFormat");
}
return true;
}
-bool ots_head_should_serialise(Font *font) {
- return font->head != NULL;
-}
-
-bool ots_head_serialise(OTSStream *out, Font *font) {
- const OpenTypeHEAD *head = font->head;
+bool OpenTypeHEAD::Serialize(OTSStream *out) {
if (!out->WriteU32(0x00010000) ||
- !out->WriteU32(head->revision) ||
+ !out->WriteU32(this->revision) ||
!out->WriteU32(0) || // check sum not filled in yet
!out->WriteU32(0x5F0F3CF5) ||
- !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->WriteU16(this->flags) ||
+ !out->WriteU16(this->upem) ||
+ !out->WriteR64(this->created) ||
+ !out->WriteR64(this->modified) ||
+ !out->WriteS16(this->xmin) ||
+ !out->WriteS16(this->ymin) ||
+ !out->WriteS16(this->xmax) ||
+ !out->WriteS16(this->ymax) ||
+ !out->WriteU16(this->mac_style) ||
+ !out->WriteU16(this->min_ppem) ||
!out->WriteS16(2) ||
- !out->WriteS16(head->index_to_loc_format) ||
+ !out->WriteS16(this->index_to_loc_format) ||
!out->WriteS16(0)) {
- return OTS_FAILURE_MSG("Failed to write head table");
+ return Error("Failed to write table");
}
return true;
}
-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
-
-#undef TABLE_NAME