1464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com/* 2464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * Copyright 2011 Google Inc. All Rights Reserved. 3464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * 4464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * Licensed under the Apache License, Version 2.0 (the "License"); 5464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * you may not use this file except in compliance with the License. 6464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * You may obtain a copy of the License at 7464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * 8464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * http://www.apache.org/licenses/LICENSE-2.0 9464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * 10464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * Unless required by applicable law or agreed to in writing, software 11464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * distributed under the License is distributed on an "AS IS" BASIS, 12464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * See the License for the specific language governing permissions and 14464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * limitations under the License. 15464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com */ 16464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 175af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_METRICS_TABLE_H_ 185af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#define SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_METRICS_TABLE_H_ 19464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 205af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#include "sfntly/table/table.h" 216b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com#include "sfntly/table/table_based_table_builder.h" 22464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 23464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comnamespace sfntly { 24464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 25b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com// A Horizontal Metrics table - 'hmtx'. 26464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comclass HorizontalMetricsTable : public Table, 27464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com public RefCounted<HorizontalMetricsTable> { 28464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com public: 29b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com // Builder for a Horizontal Metrics Table - 'hmtx'. 306b8e073e978eed96605da6f92d6db740a39864baarthurhsu@google.com class Builder : public TableBasedTableBuilder, public RefCounted<Builder> { 31464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com public: 32464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com // Constructor scope altered to public because C++ does not allow base 33464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com // class to instantiate derived class with protected constructors. 34b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com Builder(Header* header, WritableFontData* data); 35b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com Builder(Header* header, ReadableFontData* data); 36464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com virtual ~Builder(); 37464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 38246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data); 39b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com static CALLER_ATTACH Builder* CreateBuilder(Header* header, 40b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com WritableFontData* data); 41b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com 42246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com void SetNumberOfHMetrics(int32_t num_hmetrics); 43246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com void SetNumGlyphs(int32_t num_glyphs); 44464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 45464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com private: 46464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com int32_t num_hmetrics_; 47464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com int32_t num_glyphs_; 48464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com }; 49464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 50246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com virtual ~HorizontalMetricsTable(); 51246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t NumberOfHMetrics(); 52246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t NumberOfLSBs(); 53246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t HMetricAdvanceWidth(int32_t entry); 54246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t HMetricLSB(int32_t entry); 55246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t LsbTableEntry(int32_t entry); 56246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t AdvanceWidth(int32_t glyph_id); 57f7c13bf6ff210e3c018971a6f219bb626ae00378arthurhsu@google.com int32_t LeftSideBearing(int32_t glyph_id); 58246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com 59464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com private: 60246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com struct Offset { 61246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com enum { 62246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com // hMetrics 63246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com kHMetricsStart = 0, 64246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com kHMetricsSize = 4, 65246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com 66246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com // Offset within an hMetric 67246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com kHMetricsAdvanceWidth = 0, 68246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com kHMetricsLeftSideBearing = 2, 69246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com 70246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com kLeftSideBearingSize = 2 71246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com }; 72246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com }; 73246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com 74246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com HorizontalMetricsTable(Header* header, 75246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com ReadableFontData* data, 76246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t num_hmetrics, 77246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t num_glyphs); 78246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com 79464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com int32_t num_hmetrics_; 80464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com int32_t num_glyphs_; 81464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com}; 82464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comtypedef Ptr<HorizontalMetricsTable> HorizontalMetricsTablePtr; 83464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comtypedef Ptr<HorizontalMetricsTable::Builder> HorizontalMetricsTableBuilderPtr; 84464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 85464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com} // namespace sfntly 86464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 875af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#endif // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_METRICS_TABLE_H_ 88