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 
22 namespace sfntly {
23 
24 class 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 just builds from initial data
65   // - need to make fully working but few if any examples to test with
66   class Builder : public Table::Builder,
67                   public RefCounted<Builder> {
68    public:
69     virtual ~Builder();
70 
71     static CALLER_ATTACH Builder* CreateBuilder(Header* header,
72                                                 WritableFontData* data);
73 
74    protected:
75     Builder(Header* header, WritableFontData* data);
76     Builder(Header* header, ReadableFontData* data);
77 
78     virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data);
79     virtual void SubDataSet();
80     virtual int32_t SubDataSizeToSerialize();
81     virtual bool SubReadyToSerialize();
82     virtual int32_t SubSerialize(WritableFontData* new_data);
83   };
84 
85   virtual ~EbscTable();
86 
87   int32_t Version();
88   int32_t NumSizes();
89   // Note: renamed from bitmapScaleTable
90   CALLER_ATTACH BitmapScaleTable* GetBitmapScaleTable(int32_t index);
91 
92  private:
93   EbscTable(Header* header, ReadableFontData* data);
94   friend class Builder;
95 };
96 typedef Ptr<EbscTable> EbscTablePtr;
97 typedef Ptr<EbscTable::Builder> EbscTableBuilderPtr;
98 
99 }  // namespace sfntly
100 
101 #endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_BITMAP_EBSC_TABLE_H_
102