gfx/ots/src/vorg.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "vorg.h"
michael@0 6
michael@0 7 #include <vector>
michael@0 8
michael@0 9 // VORG - Vertical Origin Table
michael@0 10 // http://www.microsoft.com/typography/otspec/vorg.htm
michael@0 11
michael@0 12 #define TABLE_NAME "VORG"
michael@0 13
michael@0 14 #define DROP_THIS_TABLE \
michael@0 15 do { \
michael@0 16 delete file->vorg; \
michael@0 17 file->vorg = 0; \
michael@0 18 OTS_FAILURE_MSG("Table discarded"); \
michael@0 19 } while (0)
michael@0 20
michael@0 21 namespace ots {
michael@0 22
michael@0 23 bool ots_vorg_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
michael@0 24 Buffer table(data, length);
michael@0 25 file->vorg = new OpenTypeVORG;
michael@0 26 OpenTypeVORG * const vorg = file->vorg;
michael@0 27
michael@0 28 uint16_t num_recs;
michael@0 29 if (!table.ReadU16(&vorg->major_version) ||
michael@0 30 !table.ReadU16(&vorg->minor_version) ||
michael@0 31 !table.ReadS16(&vorg->default_vert_origin_y) ||
michael@0 32 !table.ReadU16(&num_recs)) {
michael@0 33 return OTS_FAILURE_MSG("Failed to read header");
michael@0 34 }
michael@0 35 if (vorg->major_version != 1) {
michael@0 36 OTS_WARNING("bad major version: %u", vorg->major_version);
michael@0 37 DROP_THIS_TABLE;
michael@0 38 return true;
michael@0 39 }
michael@0 40 if (vorg->minor_version != 0) {
michael@0 41 OTS_WARNING("bad minor version: %u", vorg->minor_version);
michael@0 42 DROP_THIS_TABLE;
michael@0 43 return true;
michael@0 44 }
michael@0 45
michael@0 46 // num_recs might be zero (e.g., DFHSMinchoPro5-W3-Demo.otf).
michael@0 47 if (!num_recs) {
michael@0 48 return true;
michael@0 49 }
michael@0 50
michael@0 51 uint16_t last_glyph_index = 0;
michael@0 52 vorg->metrics.reserve(num_recs);
michael@0 53 for (unsigned i = 0; i < num_recs; ++i) {
michael@0 54 OpenTypeVORGMetrics rec;
michael@0 55
michael@0 56 if (!table.ReadU16(&rec.glyph_index) ||
michael@0 57 !table.ReadS16(&rec.vert_origin_y)) {
michael@0 58 return OTS_FAILURE_MSG("Failed to read record %d", i);
michael@0 59 }
michael@0 60 if ((i != 0) && (rec.glyph_index <= last_glyph_index)) {
michael@0 61 OTS_WARNING("the table is not sorted");
michael@0 62 DROP_THIS_TABLE;
michael@0 63 return true;
michael@0 64 }
michael@0 65 last_glyph_index = rec.glyph_index;
michael@0 66
michael@0 67 vorg->metrics.push_back(rec);
michael@0 68 }
michael@0 69
michael@0 70 return true;
michael@0 71 }
michael@0 72
michael@0 73 bool ots_vorg_should_serialise(OpenTypeFile *file) {
michael@0 74 if (!file->cff) return false; // this table is not for fonts with TT glyphs.
michael@0 75 return file->vorg != NULL;
michael@0 76 }
michael@0 77
michael@0 78 bool ots_vorg_serialise(OTSStream *out, OpenTypeFile *file) {
michael@0 79 OpenTypeVORG * const vorg = file->vorg;
michael@0 80
michael@0 81 if (!out->WriteU16(vorg->major_version) ||
michael@0 82 !out->WriteU16(vorg->minor_version) ||
michael@0 83 !out->WriteS16(vorg->default_vert_origin_y) ||
michael@0 84 !out->WriteU16(vorg->metrics.size())) {
michael@0 85 return OTS_FAILURE_MSG("Failed to write table header");
michael@0 86 }
michael@0 87
michael@0 88 for (unsigned i = 0; i < vorg->metrics.size(); ++i) {
michael@0 89 const OpenTypeVORGMetrics& rec = vorg->metrics[i];
michael@0 90 if (!out->WriteU16(rec.glyph_index) ||
michael@0 91 !out->WriteS16(rec.vert_origin_y)) {
michael@0 92 return OTS_FAILURE_MSG("Failed to write record %d", i);
michael@0 93 }
michael@0 94 }
michael@0 95
michael@0 96 return true;
michael@0 97 }
michael@0 98
michael@0 99 void ots_vorg_free(OpenTypeFile *file) {
michael@0 100 delete file->vorg;
michael@0 101 }
michael@0 102
michael@0 103 } // namespace ots

mercurial