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_INDEX_SUBTABLE_FORMAT3_H_
18#define SFNTLY_CPP_SRC_SFNTLY_TABLE_BITMAP_INDEX_SUBTABLE_FORMAT3_H_
19
20#include "sfntly/table/bitmap/index_sub_table.h"
21
22namespace sfntly {
23// Format 3 Index Subtable Entry.
24class IndexSubTableFormat3 : public IndexSubTable,
25                             public RefCounted<IndexSubTableFormat3> {
26 public:
27  class Builder : public IndexSubTable::Builder,
28                  public RefCounted<Builder> {
29   public:
30    class BitmapGlyphInfoIterator
31        : public RefIterator<BitmapGlyphInfo, Builder, IndexSubTable::Builder> {
32     public:
33      explicit BitmapGlyphInfoIterator(Builder* container);
34      virtual ~BitmapGlyphInfoIterator() {}
35
36      virtual bool HasNext();
37      CALLER_ATTACH virtual BitmapGlyphInfo* Next();
38
39     private:
40      int32_t glyph_id_;
41    };
42
43    virtual ~Builder();
44    virtual int32_t NumGlyphs();
45    virtual int32_t GlyphStartOffset(int32_t glyph_id);
46    virtual int32_t GlyphLength(int32_t glyph_id);
47    CALLER_ATTACH virtual BitmapGlyphInfoIterator* GetIterator();
48
49    virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data);
50    virtual void SubDataSet();
51    virtual int32_t SubDataSizeToSerialize();
52    virtual bool SubReadyToSerialize();
53    virtual int32_t SubSerialize(WritableFontData* new_data);
54
55    void SetOffsetArray(const IntegerList& offset_array);
56
57    static CALLER_ATTACH Builder* CreateBuilder();
58    static CALLER_ATTACH Builder* CreateBuilder(ReadableFontData* data,
59                                                int32_t index_sub_table_offset,
60                                                int32_t first_glyph_index,
61                                                int32_t last_glyph_index);
62    static CALLER_ATTACH Builder* CreateBuilder(WritableFontData* data,
63                                                int32_t index_sub_table_offset,
64                                                int32_t first_glyph_index,
65                                                int32_t last_glyph_index);
66
67   protected:
68    void Revert();
69
70   private:
71    Builder();
72    Builder(WritableFontData* data,
73            int32_t first_glyph_index,
74            int32_t last_glyph_index);
75    Builder(ReadableFontData* data,
76            int32_t first_glyph_index,
77            int32_t last_glyph_index);
78    IntegerList* GetOffsetArray();
79    void Initialize(ReadableFontData* data);
80
81    static int32_t DataLength(ReadableFontData* data,
82                              int32_t index_sub_table_offset,
83                              int32_t first_glyph_index,
84                              int32_t last_glyph_index);
85
86    IntegerList offset_array_;
87  };
88
89  virtual ~IndexSubTableFormat3();
90
91  virtual int32_t NumGlyphs();
92  virtual int32_t GlyphStartOffset(int32_t glyph_id);
93  virtual int32_t GlyphLength(int32_t glyph_id);
94
95  static int32_t GetDataLength(ReadableFontData* data,
96                               int32_t offset,
97                               int32_t first,
98                               int32_t last);
99
100 private:
101  IndexSubTableFormat3(ReadableFontData* data,
102                       int32_t first_glyph_index,
103                       int32_t last_glyph_index);
104  int32_t Loca(int32_t loca_index);
105
106  friend class Builder;
107};
108typedef Ptr<IndexSubTableFormat3> IndexSubTableFormat3Ptr;
109typedef Ptr<IndexSubTableFormat3::Builder> IndexSubTableFormat3BuilderPtr;
110
111}  // namespace sfntly
112
113#endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_BITMAP_INDEX_SUBTABLE_FORMAT3_H_
114