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_DEVICE_METRICS_TABLE_H_
18#define SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_DEVICE_METRICS_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 Device Metrics table - 'hdmx'
26class HorizontalDeviceMetricsTable
27    : public Table,
28      public RefCounted<HorizontalDeviceMetricsTable> {
29 public:
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    void SetNumGlyphs(int32_t num_glyphs);
43
44   private:
45    int32_t num_glyphs_;
46  };
47
48  virtual ~HorizontalDeviceMetricsTable();
49
50  int32_t Version();
51  int32_t NumRecords();
52  int32_t RecordSize();
53  int32_t PixelSize(int32_t record_index);
54  int32_t MaxWidth(int32_t record_index);
55  int32_t Width(int32_t record_index, int32_t glyph_num);
56
57 private:
58  struct Offset {
59    enum {
60      kVersion = 0,
61      kNumRecords = 2,
62      kSizeDeviceRecord = 4,
63      kRecords = 8,
64
65      // Offsets within a device record
66      kDeviceRecordPixelSize = 0,
67      kDeviceRecordMaxWidth = 1,
68      kDeviceRecordWidths = 2,
69    };
70  };
71  HorizontalDeviceMetricsTable(Header* header,
72                               ReadableFontData* data,
73                               int32_t num_glyphs);
74
75  int32_t num_glyphs_;
76};
77typedef Ptr<HorizontalDeviceMetricsTable> HorizontalDeviceMetricsTablePtr;
78typedef Ptr<HorizontalDeviceMetricsTable::Builder>
79            HorizontalDeviceMetricsTableBuilderPtr;
80}  // namespace sfntly
81
82#endif  // SFNTLY_CPP_SRC_SFNTLY_TABLE_CORE_HORIZONTAL_DEVICE_METRICS_TABLE_H_
83