| 1 |
// -*- related-file-name: "../../libefont/t1rw.cc" -*- |
| 2 |
#ifndef EFONT_T1RW_HH |
| 3 |
#define EFONT_T1RW_HH |
| 4 |
#include <stdio.h> |
| 5 |
#include <lcdf/string.hh> |
| 6 |
#include <lcdf/straccum.hh> |
| 7 |
namespace Efont { |
| 8 |
|
| 9 |
class Type1Reader { public: |
| 10 |
|
| 11 |
Type1Reader(); |
| 12 |
virtual ~Type1Reader(); |
| 13 |
|
| 14 |
int get_data(unsigned char *, int); |
| 15 |
virtual int more_data(unsigned char *, int) = 0; |
| 16 |
virtual bool preserve_whitespace() const { return false; } |
| 17 |
|
| 18 |
void switch_eexec(bool, unsigned char *, int); |
| 19 |
virtual void set_charstring_definer(PermString); |
| 20 |
|
| 21 |
bool next_line(StringAccum &); |
| 22 |
bool was_charstring() const { return _charstring_len > 0; } |
| 23 |
int charstring_start() const { return _charstring_start; } |
| 24 |
int charstring_length() const { return _charstring_len; } |
| 25 |
|
| 26 |
private: |
| 27 |
|
| 28 |
enum { DATA_SIZE = 1024 }; |
| 29 |
|
| 30 |
unsigned char *_data; |
| 31 |
int _len; |
| 32 |
int _pos; |
| 33 |
|
| 34 |
PermString _charstring_definer; |
| 35 |
int _charstring_start; |
| 36 |
int _charstring_len; |
| 37 |
|
| 38 |
int _ungot; |
| 39 |
int _crlf; |
| 40 |
|
| 41 |
bool _eexec; |
| 42 |
bool _binary_eexec; |
| 43 |
int _r; |
| 44 |
|
| 45 |
Type1Reader(const Type1Reader &); |
| 46 |
Type1Reader &operator=(const Type1Reader &); |
| 47 |
|
| 48 |
int more_data(); |
| 49 |
|
| 50 |
inline int eexec(int); |
| 51 |
int ascii_eexec_get(); |
| 52 |
inline int get_base(); |
| 53 |
inline int get(); |
| 54 |
|
| 55 |
void start_eexec(int ascii_chars); |
| 56 |
|
| 57 |
bool test_charstring(StringAccum &); |
| 58 |
|
| 59 |
static unsigned char xvalue_store[]; |
| 60 |
static unsigned char *xvalue; |
| 61 |
static void static_initialize(); |
| 62 |
|
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
class Type1PFAReader : public Type1Reader { |
| 67 |
|
| 68 |
FILE *_f; |
| 69 |
|
| 70 |
public: |
| 71 |
|
| 72 |
Type1PFAReader(FILE *); |
| 73 |
|
| 74 |
int more_data(unsigned char *, int); |
| 75 |
|
| 76 |
}; |
| 77 |
|
| 78 |
class Type1PFBReader : public Type1Reader { |
| 79 |
|
| 80 |
FILE *_f; |
| 81 |
bool _binary; |
| 82 |
int _left; |
| 83 |
|
| 84 |
public: |
| 85 |
|
| 86 |
Type1PFBReader(FILE *); |
| 87 |
|
| 88 |
int more_data(unsigned char *, int); |
| 89 |
bool preserve_whitespace() const; |
| 90 |
|
| 91 |
}; |
| 92 |
|
| 93 |
class Type1SubsetReader : public Type1Reader { |
| 94 |
|
| 95 |
Type1Reader *_reader; |
| 96 |
int _left; |
| 97 |
|
| 98 |
public: |
| 99 |
|
| 100 |
Type1SubsetReader(Type1Reader *, int); |
| 101 |
|
| 102 |
int more_data(unsigned char *, int); |
| 103 |
bool preserve_whitespace() const; |
| 104 |
|
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
/***** |
| 109 |
* Writers |
| 110 |
**/ |
| 111 |
|
| 112 |
class Type1Writer { public: |
| 113 |
|
| 114 |
Type1Writer(); |
| 115 |
virtual ~Type1Writer(); |
| 116 |
|
| 117 |
bool eexecing() const { return _eexec; } |
| 118 |
|
| 119 |
inline void print(int); |
| 120 |
void print(const char *, int); |
| 121 |
|
| 122 |
inline Type1Writer &operator<<(char); |
| 123 |
inline Type1Writer &operator<<(unsigned char); |
| 124 |
Type1Writer &operator<<(int); |
| 125 |
Type1Writer &operator<<(double); |
| 126 |
|
| 127 |
virtual void flush(); |
| 128 |
virtual void switch_eexec(bool); |
| 129 |
virtual void print0(const unsigned char *, int) = 0; |
| 130 |
|
| 131 |
PermString charstring_start() const { return _charstring_start; } |
| 132 |
int lenIV() const { return _lenIV; } |
| 133 |
void set_charstring_start(PermString p) { _charstring_start = p; } |
| 134 |
void set_lenIV(int l) { _lenIV = l; } |
| 135 |
|
| 136 |
private: |
| 137 |
|
| 138 |
enum { BufSize = 1024 }; |
| 139 |
|
| 140 |
unsigned char *_buf; |
| 141 |
int _pos; |
| 142 |
|
| 143 |
bool _eexec; |
| 144 |
int _eexec_start; |
| 145 |
int _eexec_end; |
| 146 |
int _r; |
| 147 |
|
| 148 |
PermString _charstring_start; |
| 149 |
int _lenIV; |
| 150 |
|
| 151 |
void local_flush(); |
| 152 |
inline unsigned char eexec(int); |
| 153 |
|
| 154 |
Type1Writer(const Type1Writer &); |
| 155 |
Type1Writer &operator=(const Type1Writer &); |
| 156 |
|
| 157 |
}; |
| 158 |
|
| 159 |
|
| 160 |
class Type1PFAWriter: public Type1Writer { |
| 161 |
|
| 162 |
FILE *_f; |
| 163 |
int _hex_line; |
| 164 |
|
| 165 |
public: |
| 166 |
|
| 167 |
Type1PFAWriter(FILE *); |
| 168 |
~Type1PFAWriter(); |
| 169 |
|
| 170 |
void switch_eexec(bool); |
| 171 |
void print0(const unsigned char *, int); |
| 172 |
|
| 173 |
}; |
| 174 |
|
| 175 |
|
| 176 |
class Type1PFBWriter: public Type1Writer { |
| 177 |
|
| 178 |
StringAccum _save; |
| 179 |
FILE *_f; |
| 180 |
bool _binary; |
| 181 |
|
| 182 |
public: |
| 183 |
|
| 184 |
Type1PFBWriter(FILE *); |
| 185 |
~Type1PFBWriter(); |
| 186 |
|
| 187 |
void flush(); |
| 188 |
void switch_eexec(bool); |
| 189 |
void print0(const unsigned char *, int); |
| 190 |
|
| 191 |
}; |
| 192 |
|
| 193 |
|
| 194 |
inline void Type1Writer::print(int c) |
| 195 |
{ |
| 196 |
if (_pos >= BufSize) |
| 197 |
local_flush(); |
| 198 |
_buf[_pos++] = c; |
| 199 |
} |
| 200 |
|
| 201 |
inline Type1Writer &operator<<(Type1Writer &w, const char *cc) |
| 202 |
{ |
| 203 |
w.print(cc, strlen(cc)); |
| 204 |
return w; |
| 205 |
} |
| 206 |
|
| 207 |
inline Type1Writer &operator<<(Type1Writer &w, PermString p) |
| 208 |
{ |
| 209 |
w.print(p.c_str(), p.length()); |
| 210 |
return w; |
| 211 |
} |
| 212 |
|
| 213 |
inline Type1Writer &operator<<(Type1Writer &w, const String &s) |
| 214 |
{ |
| 215 |
w.print(s.data(), s.length()); |
| 216 |
return w; |
| 217 |
} |
| 218 |
|
| 219 |
inline Type1Writer &Type1Writer::operator<<(char c) |
| 220 |
{ |
| 221 |
print((unsigned char)c); |
| 222 |
return *this; |
| 223 |
} |
| 224 |
|
| 225 |
inline Type1Writer &Type1Writer::operator<<(unsigned char c) |
| 226 |
{ |
| 227 |
print(c); |
| 228 |
return *this; |
| 229 |
} |
| 230 |
|
| 231 |
} |
| 232 |
#endif |