Line data Source code
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 : // type.h needs to be included first because of building issues on Windows
18 : // Type aliases we delcare are defined in other headers and make the build
19 : // fail otherwise.
20 : #include "sfntly/port/type.h"
21 : #include "sfntly/table/table.h"
22 :
23 : #include "sfntly/font.h"
24 : #include "sfntly/tag.h"
25 : #include "sfntly/table/bitmap/ebdt_table.h"
26 : #include "sfntly/table/bitmap/eblc_table.h"
27 : #include "sfntly/table/bitmap/ebsc_table.h"
28 : #include "sfntly/table/core/cmap_table.h"
29 : #include "sfntly/table/core/font_header_table.h"
30 : #include "sfntly/table/core/horizontal_device_metrics_table.h"
31 : #include "sfntly/table/core/horizontal_header_table.h"
32 : #include "sfntly/table/core/horizontal_metrics_table.h"
33 : #include "sfntly/table/core/maximum_profile_table.h"
34 : #include "sfntly/table/core/name_table.h"
35 : #include "sfntly/table/core/os2_table.h"
36 : #include "sfntly/table/generic_table_builder.h"
37 : #include "sfntly/table/table_based_table_builder.h"
38 : #include "sfntly/table/truetype/glyph_table.h"
39 : #include "sfntly/table/truetype/loca_table.h"
40 :
41 : namespace sfntly {
42 :
43 : /******************************************************************************
44 : * Table class
45 : ******************************************************************************/
46 0 : Table::~Table() {}
47 :
48 0 : int64_t Table::CalculatedChecksum() {
49 0 : return data_->Checksum();
50 : }
51 :
52 0 : void Table::SetFont(Font* font) {
53 0 : font_ = font;
54 0 : }
55 :
56 0 : Table::Table(Header* header, ReadableFontData* data)
57 0 : : FontDataTable(data) {
58 0 : header_ = header;
59 0 : }
60 :
61 : /******************************************************************************
62 : * Table::Builder class
63 : ******************************************************************************/
64 0 : Table::Builder::~Builder() {
65 0 : header_.Release();
66 0 : }
67 :
68 0 : void Table::Builder::NotifyPostTableBuild(FontDataTable* table) {
69 0 : if (model_changed() || data_changed()) {
70 0 : Table* derived_table = down_cast<Table*>(table);
71 0 : derived_table->header_ = new Header(header()->tag(),
72 0 : derived_table->DataLength());
73 : }
74 0 : }
75 :
76 : CALLER_ATTACH
77 0 : Table::Builder* Table::Builder::GetBuilder(Header* header,
78 : WritableFontData* table_data) {
79 0 : int32_t tag = header->tag();
80 0 : Table::Builder* builder_raw = NULL;
81 :
82 : // Note: Tables are commented out when they are not used/ported.
83 : // TODO(arthurhsu): IMPLEMENT: finish tables that are not ported.
84 0 : if (tag == Tag::head) {
85 : builder_raw = static_cast<Table::Builder*>(
86 0 : FontHeaderTable::Builder::CreateBuilder(header, table_data));
87 : #if defined (SFNTLY_EXPERIMENTAL)
88 : } else if (tag == Tag::cmap) {
89 : builder_raw = static_cast<Table::Builder*>(
90 : CMapTable::Builder::CreateBuilder(header, table_data));
91 : #endif // SFNTLY_EXPERIMENTAL
92 0 : } else if (tag == Tag::hhea) {
93 : builder_raw = static_cast<Table::Builder*>(
94 0 : HorizontalHeaderTable::Builder::CreateBuilder(header, table_data));
95 0 : } else if (tag == Tag::hmtx) {
96 : builder_raw = static_cast<Table::Builder*>(
97 0 : HorizontalMetricsTable::Builder::CreateBuilder(header, table_data));
98 0 : } else if (tag == Tag::maxp) {
99 : builder_raw = static_cast<Table::Builder*>(
100 0 : MaximumProfileTable::Builder::CreateBuilder(header, table_data));
101 0 : } else if (tag == Tag::name) {
102 : builder_raw = static_cast<Table::Builder*>(
103 0 : NameTable::Builder::CreateBuilder(header, table_data));
104 0 : } else if (tag == Tag::OS_2) {
105 : builder_raw = static_cast<Table::Builder*>(
106 0 : OS2Table::Builder::CreateBuilder(header, table_data));
107 : }/* else if (tag == Tag::PostScript) {
108 : builder_raw = static_cast<Table::Builder*>(
109 : PostScriptTable::Builder::CreateBuilder(header, table_data));
110 : } else if (tag == Tag::cvt) {
111 : builder_raw = static_cast<Table::Builder*>(
112 : ControlValueTable::Builder::CreateBuilder(header, table_data));
113 0 : }*/ else if (tag == Tag::glyf) {
114 : builder_raw = static_cast<Table::Builder*>(
115 0 : GlyphTable::Builder::CreateBuilder(header, table_data));
116 0 : } else if (tag == Tag::loca) {
117 : builder_raw = static_cast<Table::Builder*>(
118 0 : LocaTable::Builder::CreateBuilder(header, table_data));
119 0 : } else if (tag == Tag::EBDT || tag == Tag::bdat) {
120 : builder_raw = static_cast<Table::Builder*>(
121 0 : EbdtTable::Builder::CreateBuilder(header, table_data));
122 0 : } else if (tag == Tag::EBLC || tag == Tag::bloc) {
123 : builder_raw = static_cast<Table::Builder*>(
124 0 : EblcTable::Builder::CreateBuilder(header, table_data));
125 0 : } else if (tag == Tag::EBSC) {
126 : builder_raw = static_cast<Table::Builder*>(
127 0 : EbscTable::Builder::CreateBuilder(header, table_data));
128 : } /* else if (tag == Tag::prep) {
129 : builder_raw = static_cast<Table::Builder*>(
130 : ControlProgramTable::Builder::CreateBuilder(header, table_data));
131 0 : }*/ else if (tag == Tag::bhed) {
132 : builder_raw = static_cast<Table::Builder*>(
133 0 : FontHeaderTable::Builder::CreateBuilder(header, table_data));
134 : #if defined (SFNTLY_EXPERIMENTAL)
135 : } else if (tag == Tag::hdmx) {
136 : builder_raw = static_cast<Table::Builder*>(
137 : HorizontalDeviceMetricsTable::Builder::CreateBuilder(header,
138 : table_data));
139 : #endif // SFNTLY_EXPERIMENTAL
140 : } else {
141 : builder_raw = static_cast<Table::Builder*>(
142 0 : GenericTableBuilder::CreateBuilder(header, table_data));
143 : }
144 :
145 0 : return builder_raw;
146 : }
147 :
148 0 : Table::Builder::Builder(Header* header, WritableFontData* data)
149 0 : : FontDataTable::Builder(data) {
150 0 : header_ = header;
151 0 : }
152 :
153 0 : Table::Builder::Builder(Header* header, ReadableFontData* data)
154 0 : : FontDataTable::Builder(data) {
155 0 : header_ = header;
156 0 : }
157 :
158 0 : Table::Builder::Builder(Header* header) {
159 0 : header_ = header;
160 0 : }
161 :
162 : } // namespace sfntly
|