File: cscheck.hh

package info (click to toggle)
lcdf-typetools 2.106~dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,116 kB
  • ctags: 4,799
  • sloc: cpp: 35,136; ansic: 1,861; sh: 1,254; makefile: 264
file content (136 lines) | stat: -rw-r--r-- 2,878 bytes parent folder | download | duplicates (10)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef CSCHECK_HH
#define CSCHECK_HH
#include <efont/t1interp.hh>
#include <lcdf/point.hh>
#include <lcdf/vector.hh>
#include <lcdf/error.hh>
#include <lcdf/straccum.hh>
#include <ctype.h>

template <typename T>
class CharstringCheckerErrorHandler : public ErrorVeneer { public:

    CharstringCheckerErrorHandler(ErrorHandler *errh, T *checker)
	: ErrorVeneer(errh), _checker(checker) {
    }

    String decorate(const String &str);

  private:

    T *_checker;

};

class CharstringChecker : public Efont::CharstringInterp { public:

    CharstringChecker();
    CharstringChecker(const Vector<double> &weight_vec);

    bool error(int, int);
    bool callothersubr();
    bool type1_command(int);

    bool check(const Efont::CharstringContext &, ErrorHandler *);

    int ncommand() const {
	return _ncommand;
    }
    int subrno() const {
	return _subrno;
    }

  private:

    ErrorHandler *_errh;
    int _ncommand;
    int _subrno;

    Point _cp;

    bool _started;
    bool _flex;
    bool _cp_exists;

    bool _hstem;
    bool _hstem3;
    bool _vstem;
    bool _vstem3;

    bool _just_flexed;
    bool _counter_controlled;
    int _last_command;

    Vector<double> _h_hstem;
    Vector<double> _h_vstem;

    Vector<double> _h_hstem3;
    Vector<double> _h_vstem3;

    void stem(double, double, const char *);
    void check_stem3(const char *);

    void moveto(double, double, bool cp_exists = true);
    void rmoveto(double, double);
    void rlineto(double, double);
    void rrcurveto(double, double, double, double, double, double);

};

class CharstringSubrChecker : public Efont::CharstringInterp { public:

    CharstringSubrChecker();
    CharstringSubrChecker(const Vector<double> &weight_vec);

    bool error(int, int);
    bool type1_command(int);

    bool check(const Efont::CharstringContext &, ErrorHandler *);

    int ncommand() const {
	return -1;
    }
    int subrno() const {
	return -1;
    }

  private:

    ErrorHandler *_errh;

    bool _returned;

};


template <typename T> String
CharstringCheckerErrorHandler<T>::decorate(const String &str)
{
    StringAccum sa;
    const char *s = skip_anno(str.begin(), str.end());
    while (s < str.end() && isspace((unsigned char) *s))
	++s;
    sa.append(str.begin(), s);
    if (_checker->subrno() >= 0)
	sa << "called from ";
    if (_checker->ncommand() >= 0)
	sa << "command " << (_checker->ncommand() - 1) << ':';
    if (sa)
	sa << ' ';
    if (s + 11 < str.end() && memcmp(s, "charstring ", 11) == 0) {
	bool quote_parity = 0;
	const char *last = s + 11;
	for (const char *x = last; x != str.end(); ++x)
	    if (*x == '\'') {
		sa.append(last, x);
		sa << format(quote_parity ? "%>" : "%<");
		quote_parity = !quote_parity;
		last = x + 1;
	    }
	sa.append(last, str.end());
    } else
	sa.append(s, str.end());
    return ErrorVeneer::decorate(sa.take_string());
}

#endif