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 #include "sfntly/table/core/font_header_table.h" 18 19 namespace sfntly { 20 /****************************************************************************** 21 * FontHeaderTable class 22 ******************************************************************************/ 23 FontHeaderTable::~FontHeaderTable() {} 24 25 int32_t FontHeaderTable::TableVersion() { 26 return data_->ReadFixed(Offset::kTableVersion); 27 } 28 29 int32_t FontHeaderTable::FontRevision() { 30 return data_->ReadFixed(Offset::kFontRevision); 31 } 32 33 int64_t FontHeaderTable::ChecksumAdjustment() { 34 return data_->ReadULong(Offset::kCheckSumAdjustment); 35 } 36 37 int64_t FontHeaderTable::MagicNumber() { 38 return data_->ReadULong(Offset::kMagicNumber); 39 } 40 41 int32_t FontHeaderTable::FlagsAsInt() { 42 return data_->ReadUShort(Offset::kFlags); 43 } 44 45 int32_t FontHeaderTable::UnitsPerEm() { 46 return data_->ReadUShort(Offset::kUnitsPerEm); 47 } 48 49 int64_t FontHeaderTable::Created() { 50 return data_->ReadDateTimeAsLong(Offset::kCreated); 51 } 52 53 int64_t FontHeaderTable::Modified() { 54 return data_->ReadDateTimeAsLong(Offset::kModified); 55 } 56 57 int32_t FontHeaderTable::XMin() { 58 return data_->ReadUShort(Offset::kXMin); 59 } 60 61 int32_t FontHeaderTable::YMin() { 62 return data_->ReadUShort(Offset::kYMin); 63 } 64 65 int32_t FontHeaderTable::XMax() { 66 return data_->ReadUShort(Offset::kXMax); 67 } 68 69 int32_t FontHeaderTable::YMax() { 70 return data_->ReadUShort(Offset::kYMax); 71 } 72 73 int32_t FontHeaderTable::MacStyleAsInt() { 74 return data_->ReadUShort(Offset::kMacStyle); 75 } 76 77 int32_t FontHeaderTable::LowestRecPPEM() { 78 return data_->ReadUShort(Offset::kLowestRecPPEM); 79 } 80 81 int32_t FontHeaderTable::FontDirectionHint() { 82 return data_->ReadShort(Offset::kFontDirectionHint); 83 } 84 85 int32_t FontHeaderTable::IndexToLocFormat() { 86 return data_->ReadShort(Offset::kIndexToLocFormat); 87 } 88 89 int32_t FontHeaderTable::GlyphDataFormat() { 90 return data_->ReadShort(Offset::kGlyphDataFormat); 91 } 92 93 FontHeaderTable::FontHeaderTable(Header* header, ReadableFontData* data) 94 : Table(header, data) { 95 IntegerList checksum_ranges; 96 checksum_ranges.push_back(0); 97 checksum_ranges.push_back(Offset::kCheckSumAdjustment); 98 checksum_ranges.push_back(Offset::kMagicNumber); 99 data_->SetCheckSumRanges(checksum_ranges); 100 } 101 102 /****************************************************************************** 103 * FontHeaderTable::Builder class 104 ******************************************************************************/ 105 FontHeaderTable::Builder::Builder(Header* header, WritableFontData* data) 106 : TableBasedTableBuilder(header, data) { 107 } 108 109 FontHeaderTable::Builder::Builder(Header* header, ReadableFontData* data) 110 : TableBasedTableBuilder(header, data) { 111 } 112 113 FontHeaderTable::Builder::~Builder() {} 114 115 CALLER_ATTACH FontDataTable* FontHeaderTable::Builder::SubBuildTable( 116 ReadableFontData* data) { 117 FontDataTablePtr table = new FontHeaderTable(header(), data); 118 return table.Detach(); 119 } 120 121 int32_t FontHeaderTable::Builder::TableVersion() { 122 return down_cast<FontHeaderTable*>(GetTable())->TableVersion(); 123 } 124 125 void FontHeaderTable::Builder::SetTableVersion(int32_t version) { 126 InternalWriteData()->WriteFixed(Offset::kTableVersion, version); 127 } 128 129 int32_t FontHeaderTable::Builder::FontRevision() { 130 return down_cast<FontHeaderTable*>(GetTable())->FontRevision(); 131 } 132 133 void FontHeaderTable::Builder::SetFontRevision(int32_t revision) { 134 InternalWriteData()->WriteFixed(Offset::kFontRevision, revision); 135 } 136 137 int64_t FontHeaderTable::Builder::ChecksumAdjustment() { 138 return down_cast<FontHeaderTable*>(GetTable())->ChecksumAdjustment(); 139 } 140 141 void FontHeaderTable::Builder::SetChecksumAdjustment(int64_t adjustment) { 142 InternalWriteData()->WriteULong(Offset::kCheckSumAdjustment, adjustment); 143 } 144 145 int64_t FontHeaderTable::Builder::MagicNumber() { 146 return down_cast<FontHeaderTable*>(GetTable())->MagicNumber(); 147 } 148 149 void FontHeaderTable::Builder::SetMagicNumber(int64_t magic_number) { 150 InternalWriteData()->WriteULong(Offset::kMagicNumber, magic_number); 151 } 152 153 int32_t FontHeaderTable::Builder::FlagsAsInt() { 154 return down_cast<FontHeaderTable*>(GetTable())->FlagsAsInt(); 155 } 156 157 void FontHeaderTable::Builder::SetFlagsAsInt(int32_t flags) { 158 InternalWriteData()->WriteUShort(Offset::kFlags, flags); 159 } 160 161 int32_t FontHeaderTable::Builder::UnitsPerEm() { 162 return down_cast<FontHeaderTable*>(GetTable())->UnitsPerEm(); 163 } 164 165 void FontHeaderTable::Builder::SetUnitsPerEm(int32_t units) { 166 InternalWriteData()->WriteUShort(Offset::kUnitsPerEm, units); 167 } 168 169 int64_t FontHeaderTable::Builder::Created() { 170 return down_cast<FontHeaderTable*>(GetTable())->Created(); 171 } 172 173 void FontHeaderTable::Builder::SetCreated(int64_t date) { 174 InternalWriteData()->WriteDateTime(Offset::kCreated, date); 175 } 176 177 int64_t FontHeaderTable::Builder::Modified() { 178 return down_cast<FontHeaderTable*>(GetTable())->Modified(); 179 } 180 181 void FontHeaderTable::Builder::SetModified(int64_t date) { 182 InternalWriteData()->WriteDateTime(Offset::kModified, date); 183 } 184 185 int32_t FontHeaderTable::Builder::XMin() { 186 return down_cast<FontHeaderTable*>(GetTable())->XMin(); 187 } 188 189 void FontHeaderTable::Builder::SetXMin(int32_t xmin) { 190 InternalWriteData()->WriteShort(Offset::kXMin, xmin); 191 } 192 193 int32_t FontHeaderTable::Builder::YMin() { 194 return down_cast<FontHeaderTable*>(GetTable())->YMin(); 195 } 196 197 void FontHeaderTable::Builder::SetYMin(int32_t ymin) { 198 InternalWriteData()->WriteShort(Offset::kYMin, ymin); 199 } 200 201 int32_t FontHeaderTable::Builder::XMax() { 202 return down_cast<FontHeaderTable*>(GetTable())->XMax(); 203 } 204 205 void FontHeaderTable::Builder::SetXMax(int32_t xmax) { 206 InternalWriteData()->WriteShort(Offset::kXMax, xmax); 207 } 208 209 int32_t FontHeaderTable::Builder::YMax() { 210 return down_cast<FontHeaderTable*>(GetTable())->YMax(); 211 } 212 213 void FontHeaderTable::Builder::SetYMax(int32_t ymax) { 214 InternalWriteData()->WriteShort(Offset::kYMax, ymax); 215 } 216 217 int32_t FontHeaderTable::Builder::MacStyleAsInt() { 218 return down_cast<FontHeaderTable*>(GetTable())->MacStyleAsInt(); 219 } 220 221 void FontHeaderTable::Builder::SetMacStyleAsInt(int32_t style) { 222 InternalWriteData()->WriteUShort(Offset::kMacStyle, style); 223 } 224 225 int32_t FontHeaderTable::Builder::LowestRecPPEM() { 226 return down_cast<FontHeaderTable*>(GetTable())->LowestRecPPEM(); 227 } 228 229 void FontHeaderTable::Builder::SetLowestRecPPEM(int32_t size) { 230 InternalWriteData()->WriteUShort(Offset::kLowestRecPPEM, size); 231 } 232 233 int32_t FontHeaderTable::Builder::FontDirectionHint() { 234 return down_cast<FontHeaderTable*>(GetTable())->FontDirectionHint(); 235 } 236 237 void FontHeaderTable::Builder::SetFontDirectionHint(int32_t hint) { 238 InternalWriteData()->WriteShort(Offset::kFontDirectionHint, hint); 239 } 240 241 int32_t FontHeaderTable::Builder::IndexToLocFormat() { 242 return down_cast<FontHeaderTable*>(GetTable())->IndexToLocFormat(); 243 } 244 245 void FontHeaderTable::Builder::SetIndexToLocFormat(int32_t format) { 246 InternalWriteData()->WriteShort(Offset::kIndexToLocFormat, format); 247 } 248 249 int32_t FontHeaderTable::Builder::GlyphDataFormat() { 250 return down_cast<FontHeaderTable*>(GetTable())->GlyphDataFormat(); 251 } 252 253 void FontHeaderTable::Builder::SetGlyphDataFormat(int32_t format) { 254 InternalWriteData()->WriteShort(Offset::kGlyphDataFormat, format); 255 } 256 257 CALLER_ATTACH FontHeaderTable::Builder* 258 FontHeaderTable::Builder::CreateBuilder(Header* header, 259 WritableFontData* data) { 260 Ptr<FontHeaderTable::Builder> builder; 261 builder = new FontHeaderTable::Builder(header, data); 262 return builder.Detach(); 263 } 264 265 } // namespace sfntly 266