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_COMPOSITE_BITMAP_GLYPH_H_
18 #define SFNTLY_CPP_SRC_SFNTLY_TABLE_BITMAP_COMPOSITE_BITMAP_GLYPH_H_
19 
20 #include "sfntly/table/bitmap/bitmap_glyph.h"
21 
22 namespace sfntly {
23 
24 class CompositeBitmapGlyph : public BitmapGlyph,
25                              public RefCounted<CompositeBitmapGlyph> {
26  public:
27   class Component {
28    public:
29     Component(const Component& rhs);
30 
glyph_code()31     int32_t glyph_code() { return glyph_code_; }
x_offset()32     int32_t x_offset() { return x_offset_; }
y_offset()33     int32_t y_offset() { return y_offset_; }
34 
35     // UNIMPLEMENTED: int hashCode()
36     bool operator==(const Component& rhs);
37     Component& operator=(const Component& rhs);
38 
39    protected:
40     Component(int32_t glyph_code, int32_t x_offset, int32_t y_offset);
41 
42    private:
43     int32_t glyph_code_;
44     int32_t x_offset_;
45     int32_t y_offset_;
46 
47     friend class CompositeBitmapGlyph;
48   };
49 
50   class Builder : public BitmapGlyph::Builder,
51                   public RefCounted<Builder> {
52    public:
53     Builder(WritableFontData* data, int32_t format);
54     Builder(ReadableFontData* data, int32_t format);
55     virtual ~Builder();
56 
57     virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data);
58   };
59 
60   CompositeBitmapGlyph(ReadableFontData* data, int32_t format);
61   virtual ~CompositeBitmapGlyph();
62   int32_t NumComponents();
63   // Note: returned immutable object over stack.
64   Component GetComponent(int32_t component_num) const;
65 
66  private:
67   void Initialize(int32_t format);
68 
69   int32_t num_components_offset_;
70   int32_t component_array_offset_;
71 };
72 
73 }  // namespace sfntly
74 
75 #endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_BITMAP_COMPOSITE_BITMAP_GLYPH_H_
76