eblc_table.cc revision 28258feb374913d40c347932937500210ba23d7c
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/eblc_table.h"
18
19namespace sfntly {
20/******************************************************************************
21 * EblcTable class
22 ******************************************************************************/
23int32_t EblcTable::Version() {
24  return data_->ReadFixed(Offset::kVersion);
25}
26
27int32_t EblcTable::NumSizes() {
28  return data_->ReadULongAsInt(Offset::kNumSizes);
29}
30
31BitmapSizeTable* EblcTable::GetBitmapSizeTable(int32_t index) {
32  if (index < 0 || index > NumSizes()) {
33#if !defined (SFNTLY_NO_EXCEPTION)
34    throw IndexOutOfBoundException(
35        "Size table index is outside the range of tables.");
36#endif
37    return NULL;
38  }
39  BitmapSizeTableList* bitmap_size_table_list = GetBitmapSizeTableList();
40  if (bitmap_size_table_list) {
41    return (*bitmap_size_table_list)[index];
42  }
43  return NULL;
44}
45
46EblcTable::EblcTable(Header* header, ReadableFontData* data)
47    : SubTableContainerTable(header, data) {
48}
49
50BitmapSizeTableList* EblcTable::GetBitmapSizeTableList() {
51  // TODO(arthurhsu): thread locking.
52  if (bitmap_size_table_.empty()) {
53    CreateBitmapSizeTable(data_, NumSizes(), &bitmap_size_table_);
54  }
55  return &bitmap_size_table_;
56}
57
58// static
59void EblcTable::CreateBitmapSizeTable(ReadableFontData* data,
60                                      int32_t num_sizes,
61                                      BitmapSizeTableList* output) {
62  assert(data);
63  assert(output);
64  for (int32_t i = 0; i < num_sizes; ++i) {
65    ReadableFontDataPtr new_data;
66    new_data.Attach(down_cast<ReadableFontData*>(
67        data->Slice(Offset::kBitmapSizeTableArrayStart +
68                    i * Offset::kBitmapSizeTableLength,
69                    Offset::kBitmapSizeTableLength)));
70    BitmapSizeTablePtr new_table = new BitmapSizeTable(new_data, data);
71    output->push_back(new_table);
72  }
73}
74
75/******************************************************************************
76 * EblcTable::Builder class
77 ******************************************************************************/
78EblcTable::Builder::Builder(Header* header, WritableFontData* data)
79    : SubTableContainerTable::Builder(header, data) {
80}
81
82EblcTable::Builder::Builder(Header* header, ReadableFontData* data)
83    : SubTableContainerTable::Builder(header, data) {
84}
85
86EblcTable::Builder::~Builder() {
87}
88
89int32_t EblcTable::Builder::SubSerialize(WritableFontData* new_data) {
90  UNREFERENCED_PARAMETER(new_data);
91  return 0;
92}
93
94bool EblcTable::Builder::SubReadyToSerialize() {
95  return false;
96}
97
98int32_t EblcTable::Builder::SubDataSizeToSerialize() {
99  return 0;
100}
101
102void EblcTable::Builder::SubDataSet() {
103  // NOP
104}
105
106CALLER_ATTACH
107FontDataTable* EblcTable::Builder::SubBuildTable(ReadableFontData* data) {
108  Ptr<EblcTable> new_table = new EblcTable(header(), data);
109  return new_table.Detach();
110}
111
112// static
113CALLER_ATTACH EblcTable::Builder*
114    EblcTable::Builder::CreateBuilder(Header* header, WritableFontData* data) {
115  Ptr<EblcTable::Builder> new_builder = new EblcTable::Builder(header, data);
116  return new_builder.Detach();
117}
118
119}  // namespace sfntly
120