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#ifndef SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_HEADER_TABLE_H_
18#define SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_HEADER_TABLE_H_
19
20#include "sfntly/table/table.h"
21#include "sfntly/table/table_based_table_builder.h"
22
23namespace sfntly {
24
25// A Horizontal Header table - 'hhea'.
26class HorizontalHeaderTable : public Table,
27                              public RefCounted<HorizontalHeaderTable> {
28 public:
29  // Builder for a Horizontal Header table - 'hhea'.
30  class Builder : public TableBasedTableBuilder, public RefCounted<Builder> {
31   public:
32    // Constructor scope altered to public because C++ does not allow base
33    // class to instantiate derived class with protected constructors.
34    Builder(Header* header, WritableFontData* data);
35    Builder(Header* header, ReadableFontData* data);
36    virtual ~Builder();
37    virtual CALLER_ATTACH FontDataTable* SubBuildTable(ReadableFontData* data);
38
39    static CALLER_ATTACH Builder* CreateBuilder(Header* header,
40                                                WritableFontData* data);
41
42    int32_t TableVersion();
43    void SetTableVersion(int32_t version);
44    int32_t Ascender();
45    void SetAscender(int32_t ascender);
46    int32_t Descender();
47    void SetDescender(int32_t descender);
48    int32_t LineGap();
49    void SetLineGap(int32_t line_gap);
50    int32_t AdvanceWidthMax();
51    void SetAdvanceWidthMax(int32_t value);
52    int32_t MinLeftSideBearing();
53    void SetMinLeftSideBearing(int32_t value);
54    int32_t MinRightSideBearing();
55    void SetMinRightSideBearing(int32_t value);
56    int32_t XMaxExtent();
57    void SetXMaxExtent(int32_t value);
58    int32_t CaretSlopeRise();
59    void SetCaretSlopeRise(int32_t value);
60    int32_t CaretSlopeRun();
61    void SetCaretSlopeRun(int32_t value);
62    int32_t CaretOffset();
63    void SetCaretOffset(int32_t value);
64    int32_t MetricDataFormat();
65    void SetMetricDataFormat(int32_t value);
66    int32_t NumberOfHMetrics();
67    void SetNumberOfHMetrics(int32_t value);
68  };
69
70  virtual ~HorizontalHeaderTable();
71  int32_t TableVersion();
72  int32_t Ascender();
73  int32_t Descender();
74  int32_t LineGap();
75  int32_t AdvanceWidthMax();
76  int32_t MinLeftSideBearing();
77  int32_t MinRightSideBearing();
78  int32_t XMaxExtent();
79  int32_t CaretSlopeRise();
80  int32_t CaretSlopeRun();
81  int32_t CaretOffset();
82  int32_t MetricDataFormat();
83  int32_t NumberOfHMetrics();
84
85 private:
86  struct Offset {
87    enum {
88      kVersion = 0,
89      kAscender = 4,
90      kDescender = 6,
91      kLineGap = 8,
92      kAdvanceWidthMax = 10,
93      kMinLeftSideBearing = 12,
94      kMinRightSideBearing = 14,
95      kXMaxExtent = 16,
96      kCaretSlopeRise = 18,
97      kCaretSlopeRun = 20,
98      kCaretOffset = 22,
99      kMetricDataFormat = 32,
100      kNumberOfHMetrics = 34,
101    };
102  };
103
104  HorizontalHeaderTable(Header* header, ReadableFontData* data);
105};
106typedef Ptr<HorizontalHeaderTable> HorizontalHeaderTablePtr;
107typedef Ptr<HorizontalHeaderTable::Builder> HorizontalHeaderTableBuilderPtr;
108
109}  // namespace sfntly
110
111#endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_HEADER_TABLE_H_
112