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