Line data Source code
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_device_metrics_table.h"
18 :
19 : namespace sfntly {
20 : /******************************************************************************
21 : * HorizontalDeviceMetricsTable class
22 : ******************************************************************************/
23 0 : HorizontalDeviceMetricsTable:: ~HorizontalDeviceMetricsTable() {}
24 :
25 0 : int32_t HorizontalDeviceMetricsTable::Version() {
26 0 : return data_->ReadUShort(Offset::kVersion);
27 : }
28 :
29 0 : int32_t HorizontalDeviceMetricsTable::NumRecords() {
30 0 : return data_->ReadShort(Offset::kNumRecords);
31 : }
32 :
33 0 : int32_t HorizontalDeviceMetricsTable::RecordSize() {
34 0 : return data_->ReadLong(Offset::kSizeDeviceRecord);
35 : }
36 :
37 0 : int32_t HorizontalDeviceMetricsTable::PixelSize(int32_t record_index) {
38 0 : if (record_index < 0 || record_index >= NumRecords()) {
39 : #if !defined (SFNTLY_NO_EXCEPTION)
40 : throw IndexOutOfBoundsException();
41 : #endif
42 0 : return -1;
43 : }
44 0 : return data_->ReadUByte(Offset::kRecords + record_index * RecordSize() +
45 0 : Offset::kDeviceRecordPixelSize);
46 : }
47 :
48 0 : int32_t HorizontalDeviceMetricsTable::MaxWidth(int32_t record_index) {
49 0 : if (record_index < 0 || record_index >= NumRecords()) {
50 : #if !defined (SFNTLY_NO_EXCEPTION)
51 : throw IndexOutOfBoundsException();
52 : #endif
53 0 : return -1;
54 : }
55 0 : return data_->ReadUByte(Offset::kRecords + record_index * RecordSize() +
56 0 : Offset::kDeviceRecordMaxWidth);
57 : }
58 :
59 0 : int32_t HorizontalDeviceMetricsTable::Width(int32_t record_index,
60 : int32_t glyph_num) {
61 0 : if (record_index < 0 || record_index >= NumRecords() ||
62 0 : glyph_num < 0 || glyph_num >= num_glyphs_) {
63 : #if !defined (SFNTLY_NO_EXCEPTION)
64 : throw IndexOutOfBoundsException();
65 : #endif
66 0 : return -1;
67 : }
68 0 : return data_->ReadUByte(Offset::kRecords + record_index * RecordSize() +
69 0 : Offset::kDeviceRecordWidths + glyph_num);
70 : }
71 :
72 0 : HorizontalDeviceMetricsTable::HorizontalDeviceMetricsTable(
73 : Header* header,
74 : ReadableFontData* data,
75 0 : int32_t num_glyphs)
76 0 : : Table(header, data), num_glyphs_(num_glyphs) {
77 0 : }
78 :
79 : /******************************************************************************
80 : * HorizontalDeviceMetricsTable::Builder class
81 : ******************************************************************************/
82 0 : HorizontalDeviceMetricsTable::Builder::Builder(Header* header,
83 0 : WritableFontData* data)
84 0 : : TableBasedTableBuilder(header, data), num_glyphs_(-1) {
85 0 : }
86 :
87 0 : HorizontalDeviceMetricsTable::Builder::Builder(Header* header,
88 0 : ReadableFontData* data)
89 0 : : TableBasedTableBuilder(header, data), num_glyphs_(-1) {
90 0 : }
91 :
92 0 : HorizontalDeviceMetricsTable::Builder::~Builder() {}
93 :
94 : CALLER_ATTACH FontDataTable*
95 0 : HorizontalDeviceMetricsTable::Builder::SubBuildTable(ReadableFontData* data) {
96 0 : FontDataTablePtr table = new HorizontalDeviceMetricsTable(header(), data,
97 0 : num_glyphs_);
98 0 : return table.Detach();
99 : }
100 :
101 0 : void HorizontalDeviceMetricsTable::Builder::SetNumGlyphs(int32_t num_glyphs) {
102 0 : if (num_glyphs < 0) {
103 : #if !defined (SFNTLY_NO_EXCEPTION)
104 : throw IllegalArgumentException("Number of glyphs can't be negative.");
105 : #endif
106 0 : return;
107 : }
108 0 : num_glyphs_ = num_glyphs;
109 : HorizontalDeviceMetricsTable* table =
110 0 : down_cast<HorizontalDeviceMetricsTable*>(GetTable());
111 0 : if (table) {
112 0 : table->num_glyphs_ = num_glyphs;
113 : }
114 : }
115 :
116 : CALLER_ATTACH HorizontalDeviceMetricsTable::Builder*
117 0 : HorizontalDeviceMetricsTable::Builder::CreateBuilder(Header* header,
118 : WritableFontData* data) {
119 0 : Ptr<HorizontalDeviceMetricsTable::Builder> builder;
120 0 : builder = new HorizontalDeviceMetricsTable::Builder(header, data);
121 0 : return builder.Detach();
122 : }
123 :
124 : } // namespace sfntly
|