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/small_glyph_metrics.h"
18 
19 namespace sfntly {
20 /******************************************************************************
21  * SmallGlyphMetrics class
22  ******************************************************************************/
SmallGlyphMetrics(ReadableFontData * data)23 SmallGlyphMetrics::SmallGlyphMetrics(ReadableFontData* data)
24     : GlyphMetrics(data) {
25 }
26 
~SmallGlyphMetrics()27 SmallGlyphMetrics::~SmallGlyphMetrics() {
28 }
29 
Height()30 int32_t SmallGlyphMetrics::Height() {
31   return data_->ReadByte(Offset::kHeight);
32 }
33 
Width()34 int32_t SmallGlyphMetrics::Width() {
35   return data_->ReadByte(Offset::kWidth);
36 }
37 
BearingX()38 int32_t SmallGlyphMetrics::BearingX() {
39   return data_->ReadByte(Offset::kBearingX);
40 }
41 
BearingY()42 int32_t SmallGlyphMetrics::BearingY() {
43   return data_->ReadByte(Offset::kBearingY);
44 }
45 
Advance()46 int32_t SmallGlyphMetrics::Advance() {
47   return data_->ReadByte(Offset::kAdvance);
48 }
49 
50 /******************************************************************************
51  * SmallGlyphMetrics::Builder class
52  ******************************************************************************/
Builder(WritableFontData * data)53 SmallGlyphMetrics::Builder::Builder(WritableFontData* data)
54     : GlyphMetrics::Builder(data) {
55 }
56 
Builder(ReadableFontData * data)57 SmallGlyphMetrics::Builder::Builder(ReadableFontData* data)
58     : GlyphMetrics::Builder(data) {
59 }
60 
~Builder()61 SmallGlyphMetrics::Builder::~Builder() {
62 }
63 
Height()64 int32_t SmallGlyphMetrics::Builder::Height() {
65   return InternalReadData()->ReadByte(Offset::kHeight);
66 }
67 
SetHeight(uint8_t height)68 void SmallGlyphMetrics::Builder::SetHeight(uint8_t height) {
69   InternalWriteData()->WriteByte(Offset::kHeight, height);
70 }
71 
Width()72 int32_t SmallGlyphMetrics::Builder::Width() {
73   return InternalReadData()->ReadByte(Offset::kWidth);
74 }
75 
SetWidth(uint8_t width)76 void SmallGlyphMetrics::Builder::SetWidth(uint8_t width) {
77   InternalWriteData()->WriteByte(Offset::kWidth, width);
78 }
79 
BearingX()80 int32_t SmallGlyphMetrics::Builder::BearingX() {
81   return InternalReadData()->ReadByte(Offset::kBearingX);
82 }
83 
SetBearingX(uint8_t bearing)84 void SmallGlyphMetrics::Builder::SetBearingX(uint8_t bearing) {
85   InternalWriteData()->WriteByte(Offset::kBearingX, bearing);
86 }
87 
BearingY()88 int32_t SmallGlyphMetrics::Builder::BearingY() {
89   return InternalReadData()->ReadByte(Offset::kBearingY);
90 }
91 
SetBearingY(uint8_t bearing)92 void SmallGlyphMetrics::Builder::SetBearingY(uint8_t bearing) {
93   InternalWriteData()->WriteByte(Offset::kBearingY, bearing);
94 }
95 
Advance()96 int32_t SmallGlyphMetrics::Builder::Advance() {
97   return InternalReadData()->ReadByte(Offset::kAdvance);
98 }
99 
SetAdvance(uint8_t advance)100 void SmallGlyphMetrics::Builder::SetAdvance(uint8_t advance) {
101   InternalWriteData()->WriteByte(Offset::kAdvance, advance);
102 }
103 
104 CALLER_ATTACH FontDataTable*
SubBuildTable(ReadableFontData * data)105     SmallGlyphMetrics::Builder::SubBuildTable(ReadableFontData* data) {
106   SmallGlyphMetricsPtr output = new SmallGlyphMetrics(data);
107   return output.Detach();
108 }
109 
SubDataSet()110 void SmallGlyphMetrics::Builder::SubDataSet() {
111   // NOP.
112 }
113 
SubDataSizeToSerialize()114 int32_t SmallGlyphMetrics::Builder::SubDataSizeToSerialize() {
115   return 0;
116 }
117 
SubReadyToSerialize()118 bool SmallGlyphMetrics::Builder::SubReadyToSerialize() {
119   return false;
120 }
121 
SubSerialize(WritableFontData * new_data)122 int32_t SmallGlyphMetrics::Builder::SubSerialize(WritableFontData* new_data) {
123   return Data()->CopyTo(new_data);
124 }
125 
126 }  // namespace sfntly
127