16b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com/* 26b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * Copyright 2011 Google Inc. All Rights Reserved. 36b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * 46b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * Licensed under the Apache License, Version 2.0 (the "License"); 56b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * you may not use this file except in compliance with the License. 66b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * You may obtain a copy of the License at 76b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * 86b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * http://www.apache.org/licenses/LICENSE-2.0 96b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * 106b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * Unless required by applicable law or agreed to in writing, software 116b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * distributed under the License is distributed on an "AS IS" BASIS, 126b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * See the License for the specific language governing permissions and 146b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com * limitations under the License. 156b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com */ 166b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com 176b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_BITMAP_INDEX_SUBTABLE_FORMAT4_H_ 186b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com#define SFNTLY_CPP_SRC_SFNTLY_TABLE_BITMAP_INDEX_SUBTABLE_FORMAT4_H_ 196b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com 206b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com#include "sfntly/table/bitmap/index_sub_table.h" 216b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com 226b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.comnamespace sfntly { 236b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com 246b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.comclass IndexSubTableFormat4 : public IndexSubTable, 256b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com public RefCounted<IndexSubTableFormat4> { 266b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com public: 27333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com class CodeOffsetPair { 28333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com public: 29333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t glyph_code() const { return glyph_code_; } 30333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t offset() const { return offset_; } 31333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 32333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com protected: 33333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com CodeOffsetPair(int32_t glyph_code, int32_t offset); 34333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 35333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com // TODO(arthurhsu): C++ style guide prohibits protected members. 36333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t glyph_code_; 37333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t offset_; 38333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com }; 39333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 40333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com class CodeOffsetPairBuilder : public CodeOffsetPair { 41333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com public: 42be87cfe77f08387d23cabc3a403fa53531b687a8arthurhsu@google.com CodeOffsetPairBuilder(); 43be87cfe77f08387d23cabc3a403fa53531b687a8arthurhsu@google.com CodeOffsetPairBuilder(int32_t glyph_code, int32_t offset); 44333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com void set_glyph_code(int32_t v) { glyph_code_ = v; } 45333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com void set_offset(int32_t v) { offset_ = v; } 46333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com }; 47333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 48333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com class CodeOffsetPairGlyphCodeComparator { 49333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com public: 50333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com bool operator()(const CodeOffsetPair& lhs, const CodeOffsetPair& rhs); 51333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com }; 52333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 53333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com class Builder : public IndexSubTable::Builder, 54333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com public RefCounted<Builder> { 55333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com public: 56333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com class BitmapGlyphInfoIterator 57333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com : public RefIterator<BitmapGlyphInfo, Builder, IndexSubTable::Builder> { 58333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com public: 59333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com explicit BitmapGlyphInfoIterator(Builder* container); 60333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com virtual ~BitmapGlyphInfoIterator() {} 61333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 62333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com virtual bool HasNext(); 63333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com CALLER_ATTACH virtual BitmapGlyphInfo* Next(); 64333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 65333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com private: 66333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t code_offset_pair_index_; 67333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com }; 68333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 69333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com virtual ~Builder(); 70333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com virtual int32_t NumGlyphs(); 71333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com virtual int32_t GlyphLength(int32_t glyph_id); 72333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com virtual int32_t GlyphStartOffset(int32_t glyph_id); 73be87cfe77f08387d23cabc3a403fa53531b687a8arthurhsu@google.com CALLER_ATTACH virtual BitmapGlyphInfoIterator* GetIterator(); 74333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 75333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); 76333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com virtual void SubDataSet(); 77333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com virtual int32_t SubDataSizeToSerialize(); 78333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com virtual bool SubReadyToSerialize(); 79333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com virtual int32_t SubSerialize(WritableFontData* new_data); 80333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 81333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com void Revert(); 82333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com void SetOffsetArray(const std::vector<CodeOffsetPairBuilder>& pair_array); 83333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 8453847b66af7e0c1af9928e4da2e978ed3b7c2a25arthurhsu@google.com static CALLER_ATTACH Builder* CreateBuilder(); 85333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com static CALLER_ATTACH Builder* CreateBuilder(ReadableFontData* data, 86333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t index_sub_table_offset, 87333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t first_glyph_index, 88333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t last_glyph_index); 89333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com static CALLER_ATTACH Builder* CreateBuilder(WritableFontData* data, 90333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t index_sub_table_offset, 91333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t first_glyph_index, 92333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t last_glyph_index); 93333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com private: 9453847b66af7e0c1af9928e4da2e978ed3b7c2a25arthurhsu@google.com Builder(); 95333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com Builder(WritableFontData* data, 96333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t first_glyph_index, 97333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t last_glyph_index); 98333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com Builder(ReadableFontData* data, 99333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t first_glyph_index, 100333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t last_glyph_index); 101333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com std::vector<CodeOffsetPairBuilder>* GetOffsetArray(); 102333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com void Initialize(ReadableFontData* data); 103333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t FindCodeOffsetPair(int32_t glyph_id); 104333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 105333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com static int32_t DataLength(ReadableFontData* data, 106333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t index_sub_table_offset, 107333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t first_glyph_index, 108333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t last_glyph_index); 109333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 110333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com std::vector<CodeOffsetPairBuilder> offset_pair_array_; 111333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com }; 112333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 1136b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com virtual ~IndexSubTableFormat4(); 1146b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com 1156b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com virtual int32_t NumGlyphs(); 116333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com virtual int32_t GlyphStartOffset(int32_t glyph_id); 1176b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com virtual int32_t GlyphLength(int32_t glyph_id); 1186b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com 1196b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com private: 120333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com IndexSubTableFormat4(ReadableFontData* data, 121333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t first_glyph_index, 122333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com int32_t last_glyph_index); 123333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 1246b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com int32_t FindCodeOffsetPair(int32_t glyph_id); 125333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com static int32_t NumGlyphs(ReadableFontData* data, int32_t table_offset); 126333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com 127333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.com friend class Builder; 1286b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com}; 129333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.comtypedef Ptr<IndexSubTableFormat4> IndexSubTableFormat4Ptr; 130333edd91cb32d6acfd0307ba2ae8f60baed75ff4arthurhsu@google.comtypedef Ptr<IndexSubTableFormat4::Builder> IndexSubTableFormat4BuilderPtr; 131be87cfe77f08387d23cabc3a403fa53531b687a8arthurhsu@google.comtypedef std::vector<IndexSubTableFormat4::CodeOffsetPairBuilder> 132be87cfe77f08387d23cabc3a403fa53531b687a8arthurhsu@google.com CodeOffsetPairBuilderList; 1336b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com} // namespace sfntly 1346b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com 1356b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_BITMAP_INDEX_SUBTABLE_FORMAT4_H_ 136