Debian Codegraph @

texk/lcdf-typetools/lcdf-typetools-src/include/efont/otffvar.hh

raw
1 // -*- related-file-name: "../../libefont/otffvar.cc" -*-
2 #ifndef EFONT_OTFFVAR_HH
3 #define EFONT_OTFFVAR_HH
4 #include <efont/otf.hh>
5 #include <lcdf/error.hh>
6 #include <utility>
7 namespace Efont { namespace OpenType {
8 class Axis;
9 class FvarInstance;
10
11 class Fvar { public:
12 Fvar(Data);
13 // default destructor
14
15 inline int naxes() const;
16 inline Axis axis(int i) const;
17 inline int ninstances() const;
18 inline FvarInstance instance(int i) const;
19
20 private:
21 const unsigned char* _d;
22 const unsigned char* _id;
23
24 enum { HEADER_SIZE = 16, AXIS_SIZE = 20,
25 X_AXISOFF = 4, X_AXISCOUNT = 8, X_AXISSIZE = 10,
26 X_INSTANCECOUNT = 12, X_INSTANCESIZE = 14 };
27
28 };
29
30 class Axis { public:
31 inline Axis(const unsigned char* d) : _d(d) {}
32
33 inline Tag tag() const;
34 inline double min_value() const;
35 inline double default_value() const;
36 inline double max_value() const;
37 inline uint16_t flags() const;
38 inline int nameid() const;
39
40 private:
41 const unsigned char* _d;
42 };
43
44 class FvarInstance { public:
45 inline FvarInstance(const unsigned char* d, int naxes) : _d(d), _naxes(naxes) {}
46
47 inline int nameid() const;
48 inline double coord(int) const;
49
50 private:
51 const unsigned char* _d;
52 const int _naxes;
53 };
54
55
56 inline int Fvar::naxes() const {
57 return Data::u16_aligned(_d + X_AXISCOUNT);
58 }
59
60 inline Axis Fvar::axis(int i) const {
61 assert(i >= 0 && i < naxes());
62 return Axis(_d + Data::u16_aligned(_d + X_AXISOFF) + i * Data::u16_aligned(_d + X_AXISSIZE));
63 }
64
65 inline int Fvar::ninstances() const {
66 return _id ? Data::u16_aligned(_d + X_INSTANCECOUNT) : 0;
67 }
68
69 inline FvarInstance Fvar::instance(int i) const {
70 assert(i >= 0 && i < ninstances());
71 return FvarInstance(_id + i * Data::u16_aligned(_d + X_INSTANCESIZE), naxes());
72 }
73
74
75 inline Tag Axis::tag() const {
76 return Tag(Data::u32_aligned16(_d));
77 }
78
79 inline double Axis::min_value() const {
80 return Data::fixed_aligned16(_d + 4);
81 }
82
83 inline double Axis::default_value() const {
84 return Data::fixed_aligned16(_d + 8);
85 }
86
87 inline double Axis::max_value() const {
88 return Data::fixed_aligned16(_d + 12);
89 }
90
91 inline uint16_t Axis::flags() const {
92 return Data::u16_aligned(_d + 16);
93 }
94
95 inline int Axis::nameid() const {
96 return Data::u16_aligned(_d + 18);
97 }
98
99
100 inline int FvarInstance::nameid() const {
101 return Data::u16_aligned(_d);
102 }
103
104 inline double FvarInstance::coord(int ax) const {
105 assert(ax >= 0 && ax < _naxes);
106 return Data::fixed_aligned16(_d + 4 + ax * 4);
107 }
108
109 }}
110 #endif