LCOV - app.info - gfx/ots/src/vorg.cc

LCOV - code coverage report
| Current view: | directory - gfx/ots/src - vorg.cc (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 48 | 0 | 0.0 %
| Date: | 2012-04-21 | Functions: | 4 | 0 | 0.0 %

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

Generated by: LCOV version 1.7