1a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com/* 2a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * Copyright 2011 Google Inc. All Rights Reserved. 3a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * 4a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * Licensed under the Apache License, Version 2.0 (the "License"); 5a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * you may not use this file except in compliance with the License. 6a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * You may obtain a copy of the License at 7a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * 8a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * http://www.apache.org/licenses/LICENSE-2.0 9a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * 10a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * Unless required by applicable law or agreed to in writing, software 11a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * distributed under the License is distributed on an "AS IS" BASIS, 12a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * See the License for the specific language governing permissions and 14a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * limitations under the License. 15a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com */ 16a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 17a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com#include "sfntly/table/core/horizontal_device_metrics_table.h" 18a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 19a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comnamespace sfntly { 20a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com/****************************************************************************** 21a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * HorizontalDeviceMetricsTable class 22a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com ******************************************************************************/ 23a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comHorizontalDeviceMetricsTable:: ~HorizontalDeviceMetricsTable() {} 24a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 25a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comint32_t HorizontalDeviceMetricsTable::Version() { 26a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com return data_->ReadUShort(Offset::kVersion); 27a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} 28a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 29a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comint32_t HorizontalDeviceMetricsTable::NumRecords() { 30a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com return data_->ReadShort(Offset::kNumRecords); 31a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} 32a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 33a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comint32_t HorizontalDeviceMetricsTable::RecordSize() { 34a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com return data_->ReadLong(Offset::kSizeDeviceRecord); 35a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} 36a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 37a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comint32_t HorizontalDeviceMetricsTable::PixelSize(int32_t record_index) { 38a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com if (record_index < 0 || record_index >= NumRecords()) { 39a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com#if !defined (SFNTLY_NO_EXCEPTION) 40a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com throw IndexOutOfBoundsException(); 41a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com#endif 42a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com return -1; 43a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com } 44a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com return data_->ReadUByte(Offset::kRecords + record_index * RecordSize() + 45a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com Offset::kDeviceRecordPixelSize); 46a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} 47a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 48a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comint32_t HorizontalDeviceMetricsTable::MaxWidth(int32_t record_index) { 49a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com if (record_index < 0 || record_index >= NumRecords()) { 50a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com#if !defined (SFNTLY_NO_EXCEPTION) 51a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com throw IndexOutOfBoundsException(); 52a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com#endif 53a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com return -1; 54a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com } 55a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com return data_->ReadUByte(Offset::kRecords + record_index * RecordSize() + 56a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com Offset::kDeviceRecordMaxWidth); 57a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} 58a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 59a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comint32_t HorizontalDeviceMetricsTable::Width(int32_t record_index, 60a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com int32_t glyph_num) { 61a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com if (record_index < 0 || record_index >= NumRecords() || 62a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com glyph_num < 0 || glyph_num >= num_glyphs_) { 63a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com#if !defined (SFNTLY_NO_EXCEPTION) 64a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com throw IndexOutOfBoundsException(); 65a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com#endif 66a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com return -1; 67a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com } 68a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com return data_->ReadUByte(Offset::kRecords + record_index * RecordSize() + 69a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com Offset::kDeviceRecordWidths + glyph_num); 70a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} 71a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 72a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comHorizontalDeviceMetricsTable::HorizontalDeviceMetricsTable( 73a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com Header* header, 74a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com ReadableFontData* data, 75a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com int32_t num_glyphs) 76a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com : Table(header, data), num_glyphs_(num_glyphs) { 77a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} 78a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 79a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com/****************************************************************************** 80a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com * HorizontalDeviceMetricsTable::Builder class 81a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com ******************************************************************************/ 82a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comHorizontalDeviceMetricsTable::Builder::Builder(Header* header, 83a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com WritableFontData* data) 84a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com : TableBasedTableBuilder(header, data), num_glyphs_(-1) { 85a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} 86a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 87a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comHorizontalDeviceMetricsTable::Builder::Builder(Header* header, 88a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com ReadableFontData* data) 89a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com : TableBasedTableBuilder(header, data), num_glyphs_(-1) { 90a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} 91a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 92a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comHorizontalDeviceMetricsTable::Builder::~Builder() {} 93a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 94a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comCALLER_ATTACH FontDataTable* 95a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comHorizontalDeviceMetricsTable::Builder::SubBuildTable(ReadableFontData* data) { 96a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com FontDataTablePtr table = new HorizontalDeviceMetricsTable(header(), data, 97a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com num_glyphs_); 98a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com return table.Detach(); 99a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} 100a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 101a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comvoid HorizontalDeviceMetricsTable::Builder::SetNumGlyphs(int32_t num_glyphs) { 102a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com if (num_glyphs < 0) { 103a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com#if !defined (SFNTLY_NO_EXCEPTION) 104a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com throw IllegalArgumentException("Number of glyphs can't be negative."); 105a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com#endif 1065768f5055c95f4fdd9dad479ac1f56604a29aba2arthurhsu@google.com return; 107a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com } 108a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com num_glyphs_ = num_glyphs; 109a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com HorizontalDeviceMetricsTable* table = 110a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com down_cast<HorizontalDeviceMetricsTable*>(GetTable()); 111a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com if (table) { 112a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com table->num_glyphs_ = num_glyphs; 113a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com } 114a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} 115a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 116a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comCALLER_ATTACH HorizontalDeviceMetricsTable::Builder* 117a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.comHorizontalDeviceMetricsTable::Builder::CreateBuilder(Header* header, 118a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com WritableFontData* data) { 119a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com Ptr<HorizontalDeviceMetricsTable::Builder> builder; 120a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com builder = new HorizontalDeviceMetricsTable::Builder(header, data); 121a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com return builder.Detach(); 122a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} 123a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com 124a7acde600e171e08e75138318308de83f38b3097arthurhsu@google.com} // namespace sfntly 125