| 1 |
#ifndef CSCHECK_HH |
| 2 |
#define CSCHECK_HH |
| 3 |
#include <efont/t1interp.hh> |
| 4 |
#include <lcdf/point.hh> |
| 5 |
#include <lcdf/vector.hh> |
| 6 |
#include <lcdf/error.hh> |
| 7 |
#include <lcdf/straccum.hh> |
| 8 |
#include <ctype.h> |
| 9 |
|
| 10 |
template <typename T> |
| 11 |
class CharstringCheckerErrorHandler : public ErrorVeneer { public: |
| 12 |
|
| 13 |
CharstringCheckerErrorHandler(ErrorHandler *errh, T *checker) |
| 14 |
: ErrorVeneer(errh), _checker(checker) { |
| 15 |
} |
| 16 |
|
| 17 |
String decorate(const String &str); |
| 18 |
|
| 19 |
private: |
| 20 |
|
| 21 |
T *_checker; |
| 22 |
|
| 23 |
}; |
| 24 |
|
| 25 |
class CharstringChecker : public Efont::CharstringInterp { public: |
| 26 |
|
| 27 |
CharstringChecker(); |
| 28 |
CharstringChecker(const Vector<double> &weight_vec); |
| 29 |
|
| 30 |
bool error(int, int); |
| 31 |
bool callothersubr(); |
| 32 |
bool type1_command(int); |
| 33 |
|
| 34 |
bool check(const Efont::CharstringContext &, ErrorHandler *); |
| 35 |
|
| 36 |
int ncommand() const { |
| 37 |
return _ncommand; |
| 38 |
} |
| 39 |
int subrno() const { |
| 40 |
return _subrno; |
| 41 |
} |
| 42 |
|
| 43 |
private: |
| 44 |
|
| 45 |
ErrorHandler *_errh; |
| 46 |
int _ncommand; |
| 47 |
int _subrno; |
| 48 |
|
| 49 |
Point _cp; |
| 50 |
|
| 51 |
bool _started; |
| 52 |
bool _flex; |
| 53 |
bool _cp_exists; |
| 54 |
|
| 55 |
bool _hstem; |
| 56 |
bool _hstem3; |
| 57 |
bool _vstem; |
| 58 |
bool _vstem3; |
| 59 |
|
| 60 |
bool _just_flexed; |
| 61 |
bool _counter_controlled; |
| 62 |
int _last_command; |
| 63 |
|
| 64 |
Vector<double> _h_hstem; |
| 65 |
Vector<double> _h_vstem; |
| 66 |
|
| 67 |
Vector<double> _h_hstem3; |
| 68 |
Vector<double> _h_vstem3; |
| 69 |
|
| 70 |
void stem(double, double, const char *); |
| 71 |
void check_stem3(const char *); |
| 72 |
|
| 73 |
void moveto(double, double, bool cp_exists = true); |
| 74 |
void rmoveto(double, double); |
| 75 |
void rlineto(double, double); |
| 76 |
void rrcurveto(double, double, double, double, double, double); |
| 77 |
|
| 78 |
}; |
| 79 |
|
| 80 |
class CharstringSubrChecker : public Efont::CharstringInterp { public: |
| 81 |
|
| 82 |
CharstringSubrChecker(); |
| 83 |
CharstringSubrChecker(const Vector<double> &weight_vec); |
| 84 |
|
| 85 |
bool error(int, int); |
| 86 |
bool type1_command(int); |
| 87 |
|
| 88 |
bool check(const Efont::CharstringContext &, ErrorHandler *); |
| 89 |
|
| 90 |
int ncommand() const { |
| 91 |
return -1; |
| 92 |
} |
| 93 |
int subrno() const { |
| 94 |
return -1; |
| 95 |
} |
| 96 |
|
| 97 |
private: |
| 98 |
|
| 99 |
ErrorHandler *_errh; |
| 100 |
|
| 101 |
bool _returned; |
| 102 |
|
| 103 |
}; |
| 104 |
|
| 105 |
|
| 106 |
template <typename T> String |
| 107 |
CharstringCheckerErrorHandler<T>::decorate(const String &str) |
| 108 |
{ |
| 109 |
StringAccum sa; |
| 110 |
const char *s = skip_anno(str.begin(), str.end()); |
| 111 |
while (s < str.end() && isspace((unsigned char) *s)) |
| 112 |
++s; |
| 113 |
sa.append(str.begin(), s); |
| 114 |
if (_checker->subrno() >= 0) |
| 115 |
sa << "called from "; |
| 116 |
if (_checker->ncommand() >= 0) |
| 117 |
sa << "command " << (_checker->ncommand() - 1) << ':'; |
| 118 |
if (sa) |
| 119 |
sa << ' '; |
| 120 |
if (s + 11 < str.end() && memcmp(s, "charstring ", 11) == 0) { |
| 121 |
bool quote_parity = 0; |
| 122 |
const char *last = s + 11; |
| 123 |
for (const char *x = last; x != str.end(); ++x) |
| 124 |
if (*x == '\'') { |
| 125 |
sa.append(last, x); |
| 126 |
sa << format(quote_parity ? "%>" : "%<"); |
| 127 |
quote_parity = !quote_parity; |
| 128 |
last = x + 1; |
| 129 |
} |
| 130 |
sa.append(last, str.end()); |
| 131 |
} else |
| 132 |
sa.append(s, str.end()); |
| 133 |
return ErrorVeneer::decorate(sa.take_string()); |
| 134 |
} |
| 135 |
|
| 136 |
#endif |