LCOV - code coverage report
Current view: top level - gfx/ots/src - ltsh.cc (source / functions) Hit Total Coverage
Test: output.info Lines: 0 44 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "ltsh.h"
       6             : 
       7             : #include "maxp.h"
       8             : 
       9             : // LTSH - Linear Threshold
      10             : // http://www.microsoft.com/typography/otspec/ltsh.htm
      11             : 
      12             : #define TABLE_NAME "LTSH"
      13             : 
      14             : #define DROP_THIS_TABLE(...) \
      15             :   do { \
      16             :     OTS_FAILURE_MSG_(font->file, TABLE_NAME ": " __VA_ARGS__); \
      17             :     OTS_FAILURE_MSG("Table discarded"); \
      18             :     delete font->ltsh; \
      19             :     font->ltsh = 0; \
      20             :   } while (0)
      21             : 
      22             : namespace ots {
      23             : 
      24           0 : bool ots_ltsh_parse(Font *font, const uint8_t *data, size_t length) {
      25           0 :   Buffer table(data, length);
      26             : 
      27           0 :   if (!font->maxp) {
      28           0 :     return OTS_FAILURE_MSG("Missing maxp table from font needed by ltsh");
      29             :   }
      30             : 
      31           0 :   OpenTypeLTSH *ltsh = new OpenTypeLTSH;
      32           0 :   font->ltsh = ltsh;
      33             : 
      34           0 :   uint16_t num_glyphs = 0;
      35           0 :   if (!table.ReadU16(&ltsh->version) ||
      36           0 :       !table.ReadU16(&num_glyphs)) {
      37           0 :     return OTS_FAILURE_MSG("Failed to read ltsh header");
      38             :   }
      39             : 
      40           0 :   if (ltsh->version != 0) {
      41           0 :     DROP_THIS_TABLE("bad version: %u", ltsh->version);
      42           0 :     return true;
      43             :   }
      44             : 
      45           0 :   if (num_glyphs != font->maxp->num_glyphs) {
      46           0 :     DROP_THIS_TABLE("bad num_glyphs: %u", num_glyphs);
      47           0 :     return true;
      48             :   }
      49             : 
      50           0 :   ltsh->ypels.reserve(num_glyphs);
      51           0 :   for (unsigned i = 0; i < num_glyphs; ++i) {
      52           0 :     uint8_t pel = 0;
      53           0 :     if (!table.ReadU8(&pel)) {
      54           0 :       return OTS_FAILURE_MSG("Failed to read pixels for glyph %d", i);
      55             :     }
      56           0 :     ltsh->ypels.push_back(pel);
      57             :   }
      58             : 
      59           0 :   return true;
      60             : }
      61             : 
      62           0 : bool ots_ltsh_should_serialise(Font *font) {
      63           0 :   if (!font->glyf) return false;  // this table is not for CFF fonts.
      64           0 :   return font->ltsh != NULL;
      65             : }
      66             : 
      67           0 : bool ots_ltsh_serialise(OTSStream *out, Font *font) {
      68           0 :   const OpenTypeLTSH *ltsh = font->ltsh;
      69             : 
      70           0 :   const uint16_t num_ypels = static_cast<uint16_t>(ltsh->ypels.size());
      71           0 :   if (num_ypels != ltsh->ypels.size() ||
      72           0 :       !out->WriteU16(ltsh->version) ||
      73           0 :       !out->WriteU16(num_ypels)) {
      74           0 :     return OTS_FAILURE_MSG("Failed to write pels size");
      75             :   }
      76           0 :   for (uint16_t i = 0; i < num_ypels; ++i) {
      77           0 :     if (!out->Write(&(ltsh->ypels[i]), 1)) {
      78           0 :       return OTS_FAILURE_MSG("Failed to write pixel size for glyph %d", i);
      79             :     }
      80             :   }
      81             : 
      82           0 :   return true;
      83             : }
      84             : 
      85           0 : void ots_ltsh_reuse(Font *font, Font *other) {
      86           0 :   font->ltsh = other->ltsh;
      87           0 :   font->ltsh_reused = true;
      88           0 : }
      89             : 
      90           0 : void ots_ltsh_free(Font *font) {
      91           0 :   delete font->ltsh;
      92           0 : }
      93             : 
      94             : }  // namespace ots
      95             : 
      96             : #undef TABLE_NAME
      97             : #undef DROP_THIS_TABLE

Generated by: LCOV version 1.13