Home | History | Annotate | Download | only in table
      1 /*
      2  * Copyright 2011 Google Inc. All Rights Reserved.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_SUBTABLE_H_
     18 #define SFNTLY_CPP_SRC_SFNTLY_TABLE_SUBTABLE_H_
     19 
     20 #include "sfntly/table/font_data_table.h"
     21 
     22 namespace sfntly {
     23 
     24 // An abstract base class for subtables. Subtables are smaller tables nested
     25 // within other tables and don't have an entry in the main font index. Examples
     26 // of these are the CMap subtables within CMap table (cmap) or a glyph within
     27 // the glyph table (glyf).
     28 class SubTable : public FontDataTable {
     29  public:
     30   class Builder : public FontDataTable::Builder {
     31    public:
     32     virtual ~Builder();
     33 
     34    protected:
     35     // @param data the data for the subtable being built
     36     // @param master_data the data for the full table
     37     Builder(int32_t data_size);
     38     Builder(WritableFontData* data, ReadableFontData* master_data);
     39     Builder(ReadableFontData* data, ReadableFontData* master_data);
     40     explicit Builder(WritableFontData* data);
     41     explicit Builder(ReadableFontData* data);
     42 
     43     ReadableFontData* master_read_data() { return master_data_; }
     44 
     45    private:
     46     ReadableFontDataPtr master_data_;
     47   };
     48 
     49   virtual ~SubTable();
     50   virtual int32_t Padding() { return padding_; }
     51 
     52   // Sets the amount of padding that is part of the data being used by this
     53   // subtable.
     54   void set_padding(int32_t padding) { padding_ = padding; }
     55 
     56  protected:
     57   SubTable(ReadableFontData* data, ReadableFontData* master_data);
     58 
     59   // Note: constructor refactored in C++ to avoid heavy lifting.
     60   //       caller need to do data->Slice(offset, length) beforehand.
     61   explicit SubTable(ReadableFontData* data);
     62 
     63   ReadableFontData* master_read_data() { return master_data_; }
     64 
     65  private:
     66   // The data for the whole table in which this subtable is contained.
     67   ReadableFontDataPtr master_data_;
     68   int32_t padding_;
     69 };
     70 
     71 }  // namespace sfntly
     72 
     73 #endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_SUBTABLE_H_
     74