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/bitmap/big_glyph_metrics.h"
18
19namespace sfntly {
20/******************************************************************************
21 * BigGlyphMetrics class
22 ******************************************************************************/
23BigGlyphMetrics::BigGlyphMetrics(ReadableFontData* data)
24    : GlyphMetrics(data) {
25}
26
27BigGlyphMetrics::~BigGlyphMetrics() {
28}
29
30int32_t BigGlyphMetrics::Height() {
31  return data_->ReadByte(Offset::kHeight);
32}
33
34int32_t BigGlyphMetrics::Width() {
35  return data_->ReadByte(Offset::kWidth);
36}
37
38int32_t BigGlyphMetrics::HoriBearingX() {
39  return data_->ReadByte(Offset::kHoriBearingX);
40}
41
42int32_t BigGlyphMetrics::HoriBearingY() {
43  return data_->ReadByte(Offset::kHoriBearingY);
44}
45
46int32_t BigGlyphMetrics::HoriAdvance() {
47  return data_->ReadByte(Offset::kHoriAdvance);
48}
49
50int32_t BigGlyphMetrics::VertBearingX() {
51  return data_->ReadByte(Offset::kVertBearingX);
52}
53
54int32_t BigGlyphMetrics::VertBearingY() {
55  return data_->ReadByte(Offset::kVertBearingY);
56}
57
58int32_t BigGlyphMetrics::VertAdvance() {
59  return data_->ReadByte(Offset::kVertAdvance);
60}
61
62/******************************************************************************
63 * BigGlyphMetrics::Builder class
64 ******************************************************************************/
65BigGlyphMetrics::Builder::Builder(WritableFontData* data)
66    : GlyphMetrics::Builder(data) {
67}
68
69BigGlyphMetrics::Builder::Builder(ReadableFontData* data)
70    : GlyphMetrics::Builder(data) {
71}
72
73BigGlyphMetrics::Builder::~Builder() {
74}
75
76int32_t BigGlyphMetrics::Builder::Height() {
77  return InternalReadData()->ReadByte(Offset::kHeight);
78}
79
80void BigGlyphMetrics::Builder::SetHeight(byte_t height) {
81  InternalWriteData()->WriteByte(Offset::kHeight, height);
82}
83
84int32_t BigGlyphMetrics::Builder::Width() {
85  return InternalReadData()->ReadByte(Offset::kWidth);
86}
87
88void BigGlyphMetrics::Builder::SetWidth(byte_t width) {
89  InternalWriteData()->WriteByte(Offset::kWidth, width);
90}
91
92int32_t BigGlyphMetrics::Builder::HoriBearingX() {
93  return InternalReadData()->ReadByte(Offset::kHoriBearingX);
94}
95
96void BigGlyphMetrics::Builder::SetHoriBearingX(byte_t bearing) {
97  InternalWriteData()->WriteByte(Offset::kHoriBearingX, bearing);
98}
99
100int32_t BigGlyphMetrics::Builder::HoriBearingY() {
101  return InternalReadData()->ReadByte(Offset::kHoriBearingY);
102}
103
104void BigGlyphMetrics::Builder::SetHoriBearingY(byte_t bearing) {
105  InternalWriteData()->WriteByte(Offset::kHoriBearingY, bearing);
106}
107
108int32_t BigGlyphMetrics::Builder::HoriAdvance() {
109  return InternalReadData()->ReadByte(Offset::kHoriAdvance);
110}
111
112void BigGlyphMetrics::Builder::SetHoriAdvance(byte_t advance) {
113  InternalWriteData()->WriteByte(Offset::kHoriAdvance, advance);
114}
115
116int32_t BigGlyphMetrics::Builder::VertBearingX() {
117  return InternalReadData()->ReadByte(Offset::kVertBearingX);
118}
119
120void BigGlyphMetrics::Builder::SetVertBearingX(byte_t bearing) {
121  InternalWriteData()->WriteByte(Offset::kVertBearingX, bearing);
122}
123
124int32_t BigGlyphMetrics::Builder::VertBearingY() {
125  return InternalReadData()->ReadByte(Offset::kVertBearingY);
126}
127
128void BigGlyphMetrics::Builder::SetVertBearingY(byte_t bearing) {
129  InternalWriteData()->WriteByte(Offset::kVertBearingY, bearing);
130}
131
132int32_t BigGlyphMetrics::Builder::VertAdvance() {
133  return InternalReadData()->ReadByte(Offset::kVertAdvance);
134}
135
136void BigGlyphMetrics::Builder::SetVertAdvance(byte_t advance) {
137  InternalWriteData()->WriteByte(Offset::kVertAdvance, advance);
138}
139
140CALLER_ATTACH FontDataTable*
141    BigGlyphMetrics::Builder::SubBuildTable(ReadableFontData* data) {
142  BigGlyphMetricsPtr output = new BigGlyphMetrics(data);
143  return output.Detach();
144}
145
146void BigGlyphMetrics::Builder::SubDataSet() {
147  // NOP.
148}
149
150int32_t BigGlyphMetrics::Builder::SubDataSizeToSerialize() {
151  return 0;
152}
153
154bool BigGlyphMetrics::Builder::SubReadyToSerialize() {
155  return false;
156}
157
158int32_t BigGlyphMetrics::Builder::SubSerialize(WritableFontData* new_data) {
159  return Data()->CopyTo(new_data);
160}
161
162// static
163CALLER_ATTACH
164BigGlyphMetrics::Builder* BigGlyphMetrics::Builder::CreateBuilder() {
165  WritableFontDataPtr data;
166  data.Attach(WritableFontData::CreateWritableFontData(Offset::kMetricsLength));
167  BigGlyphMetricsBuilderPtr output = new BigGlyphMetrics::Builder(data);
168  return output.Detach();
169}
170
171}  // namespace sfntly
172