ebsc_table.h revision 158cdcb9cf09418ba8b49f4be7be69e37aa8e9fa
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_BITMAP_EBSC_TABLE_H_
18#define SFNTLY_CPP_SRC_SFNTLY_TABLE_BITMAP_EBSC_TABLE_H_
19
20#include "sfntly/table/bitmap/eblc_table.h"
21
22namespace sfntly {
23
24class EbscTable : public Table,
25                  public RefCounted<EbscTable> {
26 public:
27  struct Offset {
28    enum {
29      // header
30      kVersion = 0,
31      kNumSizes = DataSize::kFixed,
32      kHeaderLength = kNumSizes + DataSize::kULONG,
33      kBitmapScaleTableStart = kHeaderLength,
34
35      // bitmapScaleTable
36      kBitmapScaleTable_hori = 0,
37      kBitmapScaleTable_vert = EblcTable::Offset::kSbitLineMetricsLength,
38      kBitmapScaleTable_ppemX = kBitmapScaleTable_vert +
39                                EblcTable::Offset::kSbitLineMetricsLength,
40      kBitmapScaleTable_ppemY = kBitmapScaleTable_ppemX + DataSize::kBYTE,
41      kBitmapScaleTable_substitutePpemX = kBitmapScaleTable_ppemY +
42                                          DataSize::kBYTE,
43      kBitmapScaleTable_substitutePpemY = kBitmapScaleTable_substitutePpemX +
44                                          DataSize::kBYTE,
45      kBitmapScaleTableLength = kBitmapScaleTable_substitutePpemY +
46                                DataSize::kBYTE,
47    };
48  };
49
50  class BitmapScaleTable : public SubTable,
51                           public RefCounted<BitmapScaleTable> {
52   public:
53    virtual ~BitmapScaleTable();
54    int32_t PpemX();
55    int32_t PpemY();
56    int32_t SubstitutePpemX();
57    int32_t SubstitutePpemY();
58
59   protected:
60    // Note: caller to do data->Slice(offset, Offset::kBitmapScaleTableLength)
61    explicit BitmapScaleTable(ReadableFontData* data);
62  };
63
64  // TODO(stuartg): currently the builder is minimally functional
65  // -just builds from initial data
66  // - need to make fully working
67  class Builder : public Table::Builder,
68                  public RefCounted<Builder> {
69   public:
70    virtual ~Builder();
71
72    static CALLER_ATTACH Builder* CreateBuilder(Header* header,
73                                                WritableFontData* data);
74
75   protected:
76    Builder(Header* header, WritableFontData* data);
77    Builder(Header* header, ReadableFontData* data);
78
79    virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data);
80    virtual void SubDataSet();
81    virtual int32_t SubDataSizeToSerialize();
82    virtual bool SubReadyToSerialize();
83    virtual int32_t SubSerialize(WritableFontData* new_data);
84  };
85
86  virtual ~EbscTable();
87
88  int32_t Version();
89  int32_t NumSizes();
90  // Note: renamed from bitmapScaleTable
91  CALLER_ATTACH BitmapScaleTable* GetBitmapScaleTable(int32_t index);
92
93 private:
94  EbscTable(Header* header, ReadableFontData* data);
95  friend class Builder;
96};
97typedef Ptr<EbscTable> EbscTablePtr;
98typedef Ptr<EbscTable::Builder> EbscTableBuilderPtr;
99
100}  // namespace sfntly
101
102#endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_BITMAP_EBSC_TABLE_H_
103