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/horizontal_header_table.h"
18 
19 namespace sfntly {
20 /******************************************************************************
21  * HorizontalHeaderTable class
22  ******************************************************************************/
~HorizontalHeaderTable()23 HorizontalHeaderTable:: ~HorizontalHeaderTable() {}
24 
TableVersion()25 int32_t HorizontalHeaderTable::TableVersion() {
26   return data_->ReadFixed(Offset::kVersion);
27 }
28 
Ascender()29 int32_t HorizontalHeaderTable::Ascender() {
30   return data_->ReadShort(Offset::kAscender);
31 }
32 
Descender()33 int32_t HorizontalHeaderTable::Descender() {
34   return data_->ReadShort(Offset::kDescender);
35 }
36 
LineGap()37 int32_t HorizontalHeaderTable::LineGap() {
38   return data_->ReadShort(Offset::kLineGap);
39 }
40 
AdvanceWidthMax()41 int32_t HorizontalHeaderTable::AdvanceWidthMax() {
42   return data_->ReadUShort(Offset::kAdvanceWidthMax);
43 }
44 
MinLeftSideBearing()45 int32_t HorizontalHeaderTable::MinLeftSideBearing() {
46   return data_->ReadShort(Offset::kMinLeftSideBearing);
47 }
48 
MinRightSideBearing()49 int32_t HorizontalHeaderTable::MinRightSideBearing() {
50   return data_->ReadShort(Offset::kMinRightSideBearing);
51 }
52 
XMaxExtent()53 int32_t HorizontalHeaderTable::XMaxExtent() {
54   return data_->ReadShort(Offset::kXMaxExtent);
55 }
56 
CaretSlopeRise()57 int32_t HorizontalHeaderTable::CaretSlopeRise() {
58   return data_->ReadShort(Offset::kCaretSlopeRise);
59 }
60 
CaretSlopeRun()61 int32_t HorizontalHeaderTable::CaretSlopeRun() {
62   return data_->ReadShort(Offset::kCaretSlopeRun);
63 }
64 
CaretOffset()65 int32_t HorizontalHeaderTable::CaretOffset() {
66   return data_->ReadShort(Offset::kCaretOffset);
67 }
68 
MetricDataFormat()69 int32_t HorizontalHeaderTable::MetricDataFormat() {
70   return data_->ReadShort(Offset::kMetricDataFormat);
71 }
72 
NumberOfHMetrics()73 int32_t HorizontalHeaderTable::NumberOfHMetrics() {
74   return data_->ReadUShort(Offset::kNumberOfHMetrics);
75 }
76 
HorizontalHeaderTable(Header * header,ReadableFontData * data)77 HorizontalHeaderTable:: HorizontalHeaderTable(Header* header,
78                                               ReadableFontData* data)
79     : Table(header, data) {
80 }
81 
82 /******************************************************************************
83  * HorizontalHeaderTable::Builder class
84  ******************************************************************************/
Builder(Header * header,WritableFontData * data)85 HorizontalHeaderTable::Builder::Builder(Header* header, WritableFontData* data)
86     : TableBasedTableBuilder(header, data) {
87 }
88 
Builder(Header * header,ReadableFontData * data)89 HorizontalHeaderTable::Builder::Builder(Header* header, ReadableFontData* data)
90     : TableBasedTableBuilder(header, data) {
91 }
92 
~Builder()93 HorizontalHeaderTable::Builder::~Builder() {}
94 
95 CALLER_ATTACH FontDataTable*
SubBuildTable(ReadableFontData * data)96     HorizontalHeaderTable::Builder::SubBuildTable(ReadableFontData* data) {
97   FontDataTablePtr table = new HorizontalHeaderTable(header(), data);
98   return table.Detach();
99 }
100 
101 CALLER_ATTACH HorizontalHeaderTable::Builder*
CreateBuilder(Header * header,WritableFontData * data)102     HorizontalHeaderTable::Builder::CreateBuilder(Header* header,
103                                                   WritableFontData* data) {
104   Ptr<HorizontalHeaderTable::Builder> builder;
105   builder = new HorizontalHeaderTable::Builder(header, data);
106   return builder.Detach();
107 }
108 
TableVersion()109 int32_t HorizontalHeaderTable::Builder::TableVersion() {
110   return InternalReadData()->ReadFixed(Offset::kVersion);
111 }
112 
SetTableVersion(int32_t version)113 void HorizontalHeaderTable::Builder::SetTableVersion(int32_t version) {
114   InternalWriteData()->WriteFixed(Offset::kVersion, version);
115 }
116 
Ascender()117 int32_t HorizontalHeaderTable::Builder::Ascender() {
118   return InternalReadData()->ReadShort(Offset::kAscender);
119 }
120 
SetAscender(int32_t ascender)121 void HorizontalHeaderTable::Builder::SetAscender(int32_t ascender) {
122   InternalWriteData()->WriteShort(Offset::kVersion, ascender);
123 }
124 
Descender()125 int32_t HorizontalHeaderTable::Builder::Descender() {
126   return InternalReadData()->ReadShort(Offset::kDescender);
127 }
128 
SetDescender(int32_t descender)129 void HorizontalHeaderTable::Builder::SetDescender(int32_t descender) {
130   InternalWriteData()->WriteShort(Offset::kDescender, descender);
131 }
132 
LineGap()133 int32_t HorizontalHeaderTable::Builder::LineGap() {
134   return InternalReadData()->ReadShort(Offset::kLineGap);
135 }
136 
SetLineGap(int32_t line_gap)137 void HorizontalHeaderTable::Builder::SetLineGap(int32_t line_gap) {
138   InternalWriteData()->WriteShort(Offset::kLineGap, line_gap);
139 }
140 
AdvanceWidthMax()141 int32_t HorizontalHeaderTable::Builder::AdvanceWidthMax() {
142   return InternalReadData()->ReadUShort(Offset::kAdvanceWidthMax);
143 }
144 
SetAdvanceWidthMax(int32_t value)145 void HorizontalHeaderTable::Builder::SetAdvanceWidthMax(int32_t value) {
146   InternalWriteData()->WriteUShort(Offset::kAdvanceWidthMax, value);
147 }
148 
MinLeftSideBearing()149 int32_t HorizontalHeaderTable::Builder::MinLeftSideBearing() {
150   return InternalReadData()->ReadShort(Offset::kMinLeftSideBearing);
151 }
152 
SetMinLeftSideBearing(int32_t value)153 void HorizontalHeaderTable::Builder::SetMinLeftSideBearing(int32_t value) {
154   InternalWriteData()->WriteShort(Offset::kMinLeftSideBearing, value);
155 }
156 
MinRightSideBearing()157 int32_t HorizontalHeaderTable::Builder::MinRightSideBearing() {
158   return InternalReadData()->ReadShort(Offset::kMinRightSideBearing);
159 }
160 
SetMinRightSideBearing(int32_t value)161 void HorizontalHeaderTable::Builder::SetMinRightSideBearing(int32_t value) {
162   InternalWriteData()->WriteShort(Offset::kMinRightSideBearing, value);
163 }
164 
XMaxExtent()165 int32_t HorizontalHeaderTable::Builder::XMaxExtent() {
166   return InternalReadData()->ReadShort(Offset::kXMaxExtent);
167 }
168 
SetXMaxExtent(int32_t value)169 void HorizontalHeaderTable::Builder::SetXMaxExtent(int32_t value) {
170   InternalWriteData()->WriteShort(Offset::kXMaxExtent, value);
171 }
172 
CaretSlopeRise()173 int32_t HorizontalHeaderTable::Builder::CaretSlopeRise() {
174   return InternalReadData()->ReadUShort(Offset::kCaretSlopeRise);
175 }
176 
SetCaretSlopeRise(int32_t value)177 void HorizontalHeaderTable::Builder::SetCaretSlopeRise(int32_t value) {
178   InternalWriteData()->WriteUShort(Offset::kCaretSlopeRise, value);
179 }
180 
CaretSlopeRun()181 int32_t HorizontalHeaderTable::Builder::CaretSlopeRun() {
182   return InternalReadData()->ReadUShort(Offset::kCaretSlopeRun);
183 }
184 
SetCaretSlopeRun(int32_t value)185 void HorizontalHeaderTable::Builder::SetCaretSlopeRun(int32_t value) {
186   InternalWriteData()->WriteUShort(Offset::kCaretSlopeRun, value);
187 }
188 
CaretOffset()189 int32_t HorizontalHeaderTable::Builder::CaretOffset() {
190   return InternalReadData()->ReadUShort(Offset::kCaretOffset);
191 }
192 
SetCaretOffset(int32_t value)193 void HorizontalHeaderTable::Builder::SetCaretOffset(int32_t value) {
194   InternalWriteData()->WriteUShort(Offset::kCaretOffset, value);
195 }
196 
MetricDataFormat()197 int32_t HorizontalHeaderTable::Builder::MetricDataFormat() {
198   return InternalReadData()->ReadUShort(Offset::kMetricDataFormat);
199 }
200 
SetMetricDataFormat(int32_t value)201 void HorizontalHeaderTable::Builder::SetMetricDataFormat(int32_t value) {
202   InternalWriteData()->WriteUShort(Offset::kMetricDataFormat, value);
203 }
204 
NumberOfHMetrics()205 int32_t HorizontalHeaderTable::Builder::NumberOfHMetrics() {
206   return InternalReadData()->ReadUShort(Offset::kNumberOfHMetrics);
207 }
208 
SetNumberOfHMetrics(int32_t value)209 void HorizontalHeaderTable::Builder::SetNumberOfHMetrics(int32_t value) {
210   InternalWriteData()->WriteUShort(Offset::kNumberOfHMetrics, value);
211 }
212 
213 }  // namespace sfntly
214