Debian Codegraph @

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

raw
1 // -*- related-file-name: "../../libefont/metrics.cc" -*-
2 #ifndef EFONT_METRICS_HH
3 #define EFONT_METRICS_HH
4 #include <lcdf/permstr.hh>
5 #include <lcdf/vector.hh>
6 #include <lcdf/hashmap.hh>
7 #include <efont/encoding.hh>
8 #include <efont/pairop.hh>
9 namespace Efont {
10 class MetricsXt;
11
12 class Metrics { public:
13
14 Metrics();
15 Metrics(PermString font_name, PermString full_name, const Metrics &);
16 ~Metrics();
17
18 void use() { _uses++; }
19 void unuse() { if (--_uses == 0) delete this; }
20
21 // GLOBALS
22
23 PermString font_name() const { return _font_name; }
24 PermString family() const { return _family; }
25 PermString full_name() const { return _full_name; }
26 PermString weight() const { return _weight; }
27 PermString version() const { return _version; }
28
29 void set_font_name(PermString);
30 void set_family(PermString s) { _family = s; }
31 void set_full_name(PermString s) { _full_name = s; }
32 void set_weight(PermString s) { _weight = s; }
33 void set_version(PermString s) { _version = s; }
34
35 // GLYPHS
36
37 int nglyphs() const { return _names.size(); }
38 PermString name(GlyphIndex gi) const { return _names[gi]; }
39 GlyphIndex find(PermString n) const { return _name_map[n]; }
40
41 int code(GlyphIndex gi) const { return _encoding.code(gi); }
42 GlyphIndex find_code(int c) const { return _encoding.find_code(c); }
43 void set_code(GlyphIndex gi, int c) { _encoding.set_code(gi, c); }
44
45 GlyphIndex add_glyph(PermString);
46 void reserve_glyphs(int);
47
48 // DIMENSIONS
49
50 double scale() const { return _scale; }
51 void set_scale(double d) { _scale = d; }
52
53 int nfd() const { return _fdv.size(); }
54 int nkv() const { return _kernv.size(); }
55
56 double fd(int i) const { return _fdv[i]; }
57 double wd(int i) const { return _wdv[i]; }
58 double lf(int i) const { return _lfv[i]; }
59 double rt(int i) const { return _rtv[i]; }
60 double tp(int i) const { return _tpv[i]; }
61 double bt(int i) const { return _btv[i]; }
62 double kv(int i) const { return _kernv[i]; }
63
64 double &fd(int i) { return _fdv[i]; }
65 double &wd(int i) { return _wdv[i]; }
66 double &lf(int i) { return _lfv[i]; }
67 double &rt(int i) { return _rtv[i]; }
68 double &tp(int i) { return _tpv[i]; }
69 double &bt(int i) { return _btv[i]; }
70 double &kv(int i) { return _kernv[i]; }
71
72 inline int add_kv(double d);
73
74 void interpolate_dimens(const Metrics &, double, bool increment);
75
76 // PAIR PROGRAM
77
78 PairProgram *pair_program() { return &_pairp; }
79 const PairProgram *pair_program() const { return &_pairp; }
80 inline bool add_kern(GlyphIndex, GlyphIndex, int);
81 inline bool add_lig(GlyphIndex, GlyphIndex, GlyphIndex, int = opLigSimple);
82
83 // EXTENSIONS
84
85 MetricsXt *find_xt(PermString name) const { return _xt[_xt_map[name]]; }
86 void add_xt(MetricsXt *);
87
88 private:
89
90 PermString _font_name;
91
92 PermString _family;
93 PermString _full_name;
94 PermString _weight;
95 PermString _version;
96
97 HashMap<PermString, GlyphIndex> _name_map;
98 Vector<PermString> _names;
99 Encoding8 _encoding;
100
101 double _scale;
102
103 Vector<double> _fdv;
104 Vector<double> _wdv;
105 Vector<double> _lfv;
106 Vector<double> _rtv;
107 Vector<double> _tpv;
108 Vector<double> _btv;
109
110 PairProgram _pairp;
111 Vector<double> _kernv;
112
113 HashMap<PermString, int> _xt_map;
114 Vector<MetricsXt *> _xt;
115
116 unsigned _uses;
117
118 };
119
120
121 class MetricsXt {
122
123 public:
124
125 MetricsXt() { }
126 virtual ~MetricsXt() { }
127
128 virtual PermString kind() const = 0;
129
130 virtual void reserve_glyphs(int) { }
131
132 };
133
134
135 enum FontDimensionDefs {
136
137 fdCapHeight = 0,
138 fdXHeight,
139 fdAscender,
140 fdDescender,
141
142 fdItalicAngle,
143 fdUnderlinePosition,
144 fdUnderlineThickness,
145
146 fdFontBBllx,
147 fdFontBBlly,
148 fdFontBBurx,
149 fdFontBBury,
150
151 fdStdHW,
152 fdStdVW,
153
154 fdLast
155
156 };
157
158
159 inline bool Metrics::add_kern(GlyphIndex g1, GlyphIndex g2, int ki)
160 {
161 return _pairp.add_kern(g1, g2, ki);
162 }
163
164 inline bool Metrics::add_lig(GlyphIndex g1, GlyphIndex g2, GlyphIndex gr, int kind)
165 {
166 return _pairp.add_lig(g1, g2, gr, kind);
167 }
168
169 inline int Metrics::add_kv(double d)
170 {
171 int k = _kernv.size();
172 _kernv.push_back(d);
173 return k;
174 }
175
176 }
177 #endif