Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Unified Diff: src/metrics.cc

Issue 658573004: Updating to new OTS repo from https://github.com/khaledhosny/ots.git (Closed) Base URL: https://chromium.googlesource.com/external/ots@master
Patch Set: Adding Colored Emoji changes from external/git repo Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« .gitmodules ('K') | « src/metrics.h ('k') | src/name.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/metrics.cc
diff --git a/src/metrics.cc b/src/metrics.cc
old mode 100644
new mode 100755
index 2e9190f192e0451f38f3de4c775f9a9a6ae2d373..8d59b953b18ac2cbf973014a812f2b633982b2c5
--- a/src/metrics.cc
+++ b/src/metrics.cc
@@ -8,8 +8,10 @@
#include "maxp.h"
// OpenType horizontal and vertical common header format
-// http://www.microsoft.com/opentype/otspec/hhea.htm
-// http://www.microsoft.com/opentype/otspec/vhea.htm
+// http://www.microsoft.com/typography/otspec/hhea.htm
+// http://www.microsoft.com/typography/otspec/vhea.htm
+
+#define TABLE_NAME "metrics" // XXX: use individual table names
namespace ots {
@@ -25,7 +27,7 @@ bool ParseMetricsHeader(OpenTypeFile *file, Buffer *table,
!table->ReadS16(&header->caret_slope_rise) ||
!table->ReadS16(&header->caret_slope_run) ||
!table->ReadS16(&header->caret_offset)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Failed to read metrics header");
}
if (header->ascent < 0) {
@@ -38,7 +40,7 @@ bool ParseMetricsHeader(OpenTypeFile *file, Buffer *table,
}
if (!file->head) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Missing head font table");
}
// if the font is non-slanted, caret_offset should be zero.
@@ -50,33 +52,34 @@ bool ParseMetricsHeader(OpenTypeFile *file, Buffer *table,
// skip the reserved bytes
if (!table->Skip(8)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Failed to skip reserverd bytes");
}
int16_t data_format;
if (!table->ReadS16(&data_format)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Failed to read data format");
}
if (data_format) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad data format %d", data_format);
}
if (!table->ReadU16(&header->num_metrics)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Failed to read number of metrics");
}
if (!file->maxp) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Missing maxp font table");
}
if (header->num_metrics > file->maxp->num_glyphs) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad number of metrics %d", header->num_metrics);
}
return true;
}
-bool SerialiseMetricsHeader(OTSStream *out,
+bool SerialiseMetricsHeader(const ots::OpenTypeFile *file,
+ OTSStream *out,
const OpenTypeMetricsHeader *header) {
if (!out->WriteU32(header->version) ||
!out->WriteS16(header->ascent) ||
@@ -92,13 +95,14 @@ bool SerialiseMetricsHeader(OTSStream *out,
!out->WriteR64(0) || // reserved
!out->WriteS16(0) || // metric data format
!out->WriteU16(header->num_metrics)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Failed to write metrics");
}
return true;
}
-bool ParseMetricsTable(Buffer *table,
+bool ParseMetricsTable(const ots::OpenTypeFile *file,
+ Buffer *table,
const uint16_t num_glyphs,
const OpenTypeMetricsHeader *header,
OpenTypeMetricsTable *metrics) {
@@ -107,10 +111,10 @@ bool ParseMetricsTable(Buffer *table,
const unsigned num_metrics = header->num_metrics;
if (num_metrics > num_glyphs) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad number of metrics %d", num_metrics);
}
if (!num_metrics) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("No metrics!");
}
const unsigned num_sbs = num_glyphs - num_metrics;
@@ -119,9 +123,11 @@ bool ParseMetricsTable(Buffer *table,
uint16_t adv = 0;
int16_t sb = 0;
if (!table->ReadU16(&adv) || !table->ReadS16(&sb)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Failed to read metric %d", i);
}
+ // This check is bogus, see https://github.com/khaledhosny/ots/issues/36
+#if 0
// Since so many fonts don't have proper value on |adv| and |sb|,
// we should not call ots_failure() here. For example, about 20% of fonts
// in http://www.princexml.com/fonts/ (200+ fonts) fails these tests.
@@ -134,6 +140,7 @@ bool ParseMetricsTable(Buffer *table,
OTS_WARNING("bad sb: %d < %d", sb, header->min_sb1);
sb = header->min_sb1;
}
+#endif
metrics->entries.push_back(std::make_pair(adv, sb));
}
@@ -143,15 +150,18 @@ bool ParseMetricsTable(Buffer *table,
int16_t sb;
if (!table->ReadS16(&sb)) {
// Some Japanese fonts (e.g., mona.ttf) fail this test.
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Failed to read side bearing %d", i + num_metrics);
}
+ // This check is bogus, see https://github.com/khaledhosny/ots/issues/36
+#if 0
if (sb < header->min_sb1) {
// The same as above. Three fonts in http://www.fontsquirrel.com/fontface
// (e.g., Notice2Std.otf) have weird lsb values.
OTS_WARNING("bad lsb: %d < %d", sb, header->min_sb1);
sb = header->min_sb1;
}
+#endif
metrics->sbs.push_back(sb);
}
@@ -159,18 +169,19 @@ bool ParseMetricsTable(Buffer *table,
return true;
}
-bool SerialiseMetricsTable(OTSStream *out,
+bool SerialiseMetricsTable(const ots::OpenTypeFile *file,
+ OTSStream *out,
const OpenTypeMetricsTable *metrics) {
for (unsigned i = 0; i < metrics->entries.size(); ++i) {
if (!out->WriteU16(metrics->entries[i].first) ||
!out->WriteS16(metrics->entries[i].second)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Failed to write metric %d", i);
}
}
for (unsigned i = 0; i < metrics->sbs.size(); ++i) {
if (!out->WriteS16(metrics->sbs[i])) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Failed to write side bearing %ld", i + metrics->entries.size());
}
}
@@ -179,3 +190,4 @@ bool SerialiseMetricsTable(OTSStream *out,
} // namespace ots
+#undef TABLE_NAME
« .gitmodules ('K') | « src/metrics.h ('k') | src/name.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698