Debian Codegraph @

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

raw
1 // -*- related-file-name: "../../libefont/t1csgen.cc" -*-
2 #ifndef EFONT_T1CSGEN_HH
3 #define EFONT_T1CSGEN_HH
4 #include <efont/t1interp.hh>
5 #include <lcdf/straccum.hh>
6 namespace Efont {
7 class Type1Font;
8
9 class Type1CharstringGen { public:
10
11 Type1CharstringGen(int precision = 5);
12
13 int precision() const { return _precision; }
14
15 void clear();
16 char *data() { return _ncs.data(); }
17 const char *data() const { return _ncs.data(); }
18 int length() const { return _ncs.length(); }
19
20 void gen_number(double, int kind = 0);
21 void gen_command(int);
22 void gen_stack(CharstringInterp &, int for_cmd);
23
24 void append_charstring(const String &);
25
26 const Point &current_point(bool real) const { return (real ? _true : _false); }
27 void gen_moveto(const Point &, bool closepath, bool always);
28
29 inline String take_string();
30 Type1Charstring *output();
31 void output(Type1Charstring &);
32
33 static String callsubr_string(int subr);
34
35 private:
36
37 StringAccum _ncs;
38 int _precision;
39 double _f_precision;
40
41 Point _true;
42 Point _false;
43
44 enum State { S_INITIAL, S_GEN };
45 State _state;
46
47 void gen_rational(int big_val, int divisor);
48 bool gen_stem3_stack(CharstringInterp &interp);
49
50 };
51
52 class Type1CharstringGenInterp : public CharstringInterp { public:
53
54 Type1CharstringGenInterp(int precision);
55
56 int precision() const { return _csgen.precision(); }
57 void set_direct_hint_replacement(bool dhr) { _direct_hr = dhr; }
58 void set_hint_replacement_storage(Type1Font *);
59
60 int nhints() const { return _stem_hstem.size(); }
61 double max_flex_height() const { return _max_flex_height; }
62 bool had_flex() const { return _had_flex; }
63 bool had_bad_flex() const { return _had_bad_flex; }
64 bool had_hr() const { return _had_hr; }
65
66 const Type1CharstringGen &csgen() const { return _csgen; }
67
68 void act_width(int, const Point &);
69 void act_seac(int, double, double, double, int, int);
70
71 void act_hstem(int, double, double);
72 void act_vstem(int, double, double);
73 void act_hintmask(int, const unsigned char *, int);
74
75 void act_line(int, const Point &, const Point &);
76 void act_curve(int, const Point &, const Point &, const Point &, const Point &);
77 void act_closepath(int);
78 void act_flex(int, const Point &, const Point &, const Point &, const Point &, const Point &, const Point &, const Point &, double);
79
80 void intermediate_output(Type1Charstring &out);
81 void run(const CharstringContext &g, Type1Charstring &out);
82
83 private:
84
85 // output
86 Type1CharstringGen _csgen;
87 mutable Type1CharstringGen _hint_csgen;
88
89 // current glyph
90 Point _width;
91 enum State { S_INITIAL, S_OPEN, S_CLOSED, S_SEAC };
92 State _state;
93
94 // hints and hint replacement
95 Vector<double> _stem_pos;
96 Vector<double> _stem_width;
97 Vector<int> _stem_hstem;
98 String _last_hints;
99
100 bool _in_hr;
101 bool _direct_hr;
102 int _hr_firstsubr;
103 Type1Font *_hr_storage;
104
105 // Flex
106 double _max_flex_height;
107 bool _had_flex;
108 bool _had_bad_flex;
109 bool _had_hr;
110
111 inline void gen_number(double, int = 0);
112 inline void gen_command(int);
113 void gen_sbw(bool hints_follow);
114 String gen_hints(const unsigned char *, int) const;
115 void swap_stem_hints();
116
117 };
118
119 inline String Type1CharstringGen::take_string()
120 {
121 String s = _ncs.take_string();
122 clear();
123 return s;
124 }
125
126 }
127 #endif