1464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com/*
2464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * Copyright 2011 Google Inc. All Rights Reserved.
3464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com *
4464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * Licensed under the Apache License, Version 2.0 (the "License");
5464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * you may not use this file except in compliance with the License.
6464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * You may obtain a copy of the License at
7464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com *
8464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com *      http://www.apache.org/licenses/LICENSE-2.0
9464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com *
10464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * Unless required by applicable law or agreed to in writing, software
11464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * distributed under the License is distributed on an "AS IS" BASIS,
12464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * See the License for the specific language governing permissions and
14464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * limitations under the License.
15464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com */
16464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
175af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_TABLE_H_
185af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#define SFNTLY_CPP_SRC_SFNTLY_TABLE_TABLE_H_
19464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
20464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com#include <set>
21464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com#include <map>
22464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com#include <vector>
23464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com#include <utility>
24464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
25464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com#include "sfntly/port/type.h"
265af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#include "sfntly/table/font_data_table.h"
276b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com#include "sfntly/table/header.h"
28464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
29464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comnamespace sfntly {
30464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comclass Font;
31b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com
32b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com// A concrete implementation of a root level table in the font. This is the base
33b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com// class used for all specific table implementations and is used as the generic
34b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com// table for all tables which have no specific implementations.
35b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.comclass Table : public FontDataTable {
36464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com public:
37464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com  // Note: original version is Builder<T extends Table>
38464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com  //       C++ template is not designed that way so plain old inheritance is
39464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com  //       chosen.
40b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  class Builder : public FontDataTable::Builder {
41246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com   public:
42246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com    virtual ~Builder();
43246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com    virtual Header* header() { return header_; }
44246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com    virtual void NotifyPostTableBuild(FontDataTable* table);
45246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com
46b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com    // Get a builder for the table type specified by the data in the header.
47b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com    // @param header the header for the table
48b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com    // @param tableData the data to be used to build the table from
49b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com    // @return builder for the table specified
50b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com    static CALLER_ATTACH Builder* GetBuilder(Header* header,
51b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com                                             WritableFontData* table_data);
52b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com
53b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com    // UNIMPLEMENTED: toString()
54246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com
55464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com   protected:
56b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com    Builder(Header* header, WritableFontData* data);
57b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com    Builder(Header* header, ReadableFontData* data);
58b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com    Builder(Header* header);
59464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
60464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com   private:
61464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com    Ptr<Header> header_;
62464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com  };
63464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
646b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com  // Note: GenericTableBuilder moved to table_based_table_builder.h to avoid
656b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com  //       circular inclusion.
66464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
67246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  virtual ~Table();
68b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com
69b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  // Get the calculated checksum for the data in the table.
70246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  virtual int64_t CalculatedChecksum();
71b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com
72b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  // Get the header for the table.
73246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  virtual Header* header()          { return header_; }
74b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com
75b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  // Get the tag for the table from the record header.
76246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  virtual int32_t header_tag()      { return header_->tag(); }
77b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com
78b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  // Get the offset for the table from the record header.
79246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  virtual int32_t header_offset()   { return header_->offset(); }
80b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com
81b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  // Get the length of the table from the record header.
82246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  virtual int32_t header_length()   { return header_->length(); }
83b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com
84b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  // Get the checksum for the table from the record header.
85246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  virtual int64_t header_checksum() { return header_->checksum(); }
86b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com
87b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  // UNIMPLEMENTED: toString()
88b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com
89246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  virtual void SetFont(Font* font);
90246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com
91464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com protected:
92464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com  Table(Header* header, ReadableFontData* data);
93464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
94464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com private:
95464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com  Ptr<Header> header_;
96464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com  Ptr<Font> font_;
97464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com};
98464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
99464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com// C++ port only
100464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comclass GenericTable : public Table, public RefCounted<GenericTable> {
101464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com public:
102464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com  GenericTable(Header* header, ReadableFontData* data) : Table(header, data) {}
103464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com  virtual ~GenericTable() {}
104464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com};
105464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
106464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comtypedef Ptr<Table> TablePtr;
1076b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.comtypedef std::vector<HeaderPtr> TableHeaderList;
108464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comtypedef Ptr<Table::Builder> TableBuilderPtr;
109464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comtypedef std::map<int32_t, TablePtr> TableMap;
110464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comtypedef std::pair<int32_t, TablePtr> TableMapEntry;
111464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
1126b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.comtypedef std::map<HeaderPtr, WritableFontDataPtr> DataBlockMap;
1136b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.comtypedef std::pair<HeaderPtr, WritableFontDataPtr> DataBlockEntry;
114464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comtypedef std::map<int32_t, TableBuilderPtr> TableBuilderMap;
115464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comtypedef std::pair<int32_t, TableBuilderPtr> TableBuilderEntry;
116464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
117464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com}  // namespace sfntly
118464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com
1195af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_TABLE_H_
120