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_BITMAP_GLYPH_H_
18 #define SFNTLY_CPP_SRC_SFNTLY_TABLE_BITMAP_BITMAP_GLYPH_H_
19 
20 #include <vector>
21 #include <map>
22 
23 #include "sfntly/table/subtable.h"
24 
25 namespace sfntly {
26 
27 class BitmapGlyph : public SubTable {
28  public:
29   struct Offset {
30     enum {
31       // header
32       kVersion = 0,
33 
34       kSmallGlyphMetricsLength = 5,
35       kBigGlyphMetricsLength = 8,
36       // format 1
37       kGlyphFormat1_imageData = kSmallGlyphMetricsLength,
38 
39       // format 2
40       kGlyphFormat2_imageData = kSmallGlyphMetricsLength,
41 
42       // format 3
43 
44       // format 4
45 
46       // format 5
47       kGlyphFormat5_imageData = 0,
48 
49       // format 6
50       kGlyphFormat6_imageData = kBigGlyphMetricsLength,
51 
52       // format 7
53       kGlyphFormat7_imageData = kBigGlyphMetricsLength,
54 
55       // format 8
56       kGlyphFormat8_numComponents = kSmallGlyphMetricsLength + 1,
57       kGlyphFormat8_componentArray = kGlyphFormat8_numComponents +
58                                      DataSize::kUSHORT,
59 
60       // format 9
61       kGlyphFormat9_numComponents = kBigGlyphMetricsLength,
62       kGlyphFormat9_componentArray = kGlyphFormat9_numComponents +
63                                      DataSize::kUSHORT,
64 
65       // ebdtComponent
66       kEbdtComponentLength = DataSize::kUSHORT + 2 * DataSize::kCHAR,
67       kEbdtComponent_glyphCode = 0,
68       kEbdtComponent_xOffset = 2,
69       kEbdtComponent_yOffset = 3,
70     };
71   };
72 
73   // TODO(stuartg): builder is not functional at all
74   // - need to add subclasses for each type of bitmap glyph
75   class Builder : public SubTable::Builder {
76    public:
77     virtual ~Builder();
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 
format()85     int32_t format() { return format_; }
86 
87     static CALLER_ATTACH Builder* CreateGlyphBuilder(ReadableFontData* data,
88                                                      int32_t format);
89 
90    protected:
91     Builder(WritableFontData* data, int32_t format);
92     Builder(ReadableFontData* data, int32_t format);
93 
94    private:
95     int32_t format_;
96   };
97 
98   virtual ~BitmapGlyph();
99 
100   static CALLER_ATTACH BitmapGlyph* CreateGlyph(ReadableFontData* data,
101                                                 int32_t format);
format()102   int32_t format() { return format_; }
103 
104   // UNIMPLEMENTED: toString()
105 
106  protected:
107   BitmapGlyph(ReadableFontData* data, int32_t format);
108 
109  private:
110   int32_t format_;
111 };
112 typedef Ptr<BitmapGlyph> BitmapGlyphPtr;
113 typedef Ptr<BitmapGlyph::Builder> BitmapGlyphBuilderPtr;
114 typedef std::map<int32_t, BitmapGlyphBuilderPtr> BitmapGlyphBuilderMap;
115 typedef std::vector<BitmapGlyphBuilderMap> BitmapGlyphBuilderList;
116 
117 }  // namespace sfntly
118 
119 #endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_BITMAP_BITMAP_GLYPH_H_
120