• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  ******************************************************************************/
~Table()46 Table::~Table() {}
47 
CalculatedChecksum()48 int64_t Table::CalculatedChecksum() {
49   return data_->Checksum();
50 }
51 
SetFont(Font * font)52 void Table::SetFont(Font* font) {
53   font_ = font;
54 }
55 
Table(Header * header,ReadableFontData * data)56 Table::Table(Header* header, ReadableFontData* data)
57     : FontDataTable(data) {
58   header_ = header;
59 }
60 
61 /******************************************************************************
62  * Table::Builder class
63  ******************************************************************************/
~Builder()64 Table::Builder::~Builder() {
65   header_.Release();
66 }
67 
NotifyPostTableBuild(FontDataTable * table)68 void Table::Builder::NotifyPostTableBuild(FontDataTable* table) {
69   if (model_changed() || data_changed()) {
70     Table* derived_table = down_cast<Table*>(table);
71     derived_table->header_ = new Header(header()->tag(),
72                                         derived_table->DataLength());
73   }
74 }
75 
76 CALLER_ATTACH
GetBuilder(Header * header,WritableFontData * table_data)77 Table::Builder* Table::Builder::GetBuilder(Header* header,
78                                            WritableFontData* table_data) {
79   int32_t tag = header->tag();
80   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   if (tag == Tag::head) {
85     builder_raw = static_cast<Table::Builder*>(
86         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   } else if (tag == Tag::hhea) {
93     builder_raw = static_cast<Table::Builder*>(
94         HorizontalHeaderTable::Builder::CreateBuilder(header, table_data));
95   } else if (tag == Tag::hmtx) {
96     builder_raw = static_cast<Table::Builder*>(
97         HorizontalMetricsTable::Builder::CreateBuilder(header, table_data));
98   } else if (tag == Tag::maxp) {
99     builder_raw = static_cast<Table::Builder*>(
100         MaximumProfileTable::Builder::CreateBuilder(header, table_data));
101   } else if (tag == Tag::name) {
102     builder_raw = static_cast<Table::Builder*>(
103         NameTable::Builder::CreateBuilder(header, table_data));
104   } else if (tag == Tag::OS_2) {
105     builder_raw = static_cast<Table::Builder*>(
106         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   }*/ else if (tag == Tag::glyf) {
114     builder_raw = static_cast<Table::Builder*>(
115         GlyphTable::Builder::CreateBuilder(header, table_data));
116   } else if (tag == Tag::loca) {
117     builder_raw = static_cast<Table::Builder*>(
118         LocaTable::Builder::CreateBuilder(header, table_data));
119   } else if (tag == Tag::EBDT || tag == Tag::bdat) {
120     builder_raw = static_cast<Table::Builder*>(
121         EbdtTable::Builder::CreateBuilder(header, table_data));
122   } else if (tag == Tag::EBLC || tag == Tag::bloc) {
123     builder_raw = static_cast<Table::Builder*>(
124         EblcTable::Builder::CreateBuilder(header, table_data));
125   } else if (tag == Tag::EBSC) {
126     builder_raw = static_cast<Table::Builder*>(
127         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   }*/ else if (tag == Tag::bhed) {
132     builder_raw = static_cast<Table::Builder*>(
133         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         GenericTableBuilder::CreateBuilder(header, table_data));
143   }
144 
145   return builder_raw;
146 }
147 
Builder(Header * header,WritableFontData * data)148 Table::Builder::Builder(Header* header, WritableFontData* data)
149     : FontDataTable::Builder(data) {
150   header_ = header;
151 }
152 
Builder(Header * header,ReadableFontData * data)153 Table::Builder::Builder(Header* header, ReadableFontData* data)
154     : FontDataTable::Builder(data) {
155   header_ = header;
156 }
157 
Builder(Header * header)158 Table::Builder::Builder(Header* header) {
159   header_ = header;
160 }
161 
162 }  // namespace sfntly
163