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