summaryrefslogtreecommitdiffstats
path: root/gfx/ots/src/layout.h
blob: f0bc133e66ea417883a56613f80e10292130e32c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2011-2017 The OTS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef OTS_LAYOUT_H_
#define OTS_LAYOUT_H_

#include "ots.h"

// Utility functions for OpenType layout common table formats.
// http://www.microsoft.com/typography/otspec/chapter2.htm

namespace ots {

// The maximum number of class value.
const uint16_t kMaxClassDefValue = 0xFFFF;

class OpenTypeLayoutTable : public Table {
  public:
    explicit OpenTypeLayoutTable(Font *font, uint32_t tag, uint32_t type)
      : Table(font, tag, type) { }

    bool Parse(const uint8_t *data, size_t length);
    bool Serialize(OTSStream *out);

  protected:
    bool ParseContextSubtable(const uint8_t *data, const size_t length);
    bool ParseChainingContextSubtable(const uint8_t *data, const size_t length);
    bool ParseExtensionSubtable(const uint8_t *data, const size_t length);

  private:
    bool ParseScriptListTable(const uint8_t *data, const size_t length);
    bool ParseFeatureListTable(const uint8_t *data, const size_t length);
    bool ParseLookupListTable(const uint8_t *data, const size_t length);
    bool ParseFeatureVariationsTable(const uint8_t *data, const size_t length);
    bool ParseLookupTable(const uint8_t *data, const size_t length);

    virtual bool ValidLookupSubtableType(const uint16_t lookup_type,
                                         bool extension = false) const = 0;
    virtual bool ParseLookupSubtable(const uint8_t *data, const size_t length,
                                     const uint16_t lookup_type) = 0;

    const uint8_t *m_data = nullptr;
    size_t m_length = 0;
    uint16_t m_num_features = 0;
    uint16_t m_num_lookups = 0;
};

bool ParseClassDefTable(const ots::Font *font,
                        const uint8_t *data, size_t length,
                        const uint16_t num_glyphs,
                        const uint16_t num_classes);

bool ParseCoverageTable(const ots::Font *font,
                        const uint8_t *data, size_t length,
                        const uint16_t num_glyphs,
                        const uint16_t expected_num_glyphs = 0);

bool ParseDeviceTable(const ots::Font *font,
                      const uint8_t *data, size_t length);

}  // namespace ots

#endif  // OTS_LAYOUT_H_