| 1 |
// -*- related-file-name: "../../libefont/t1item.cc" -*- |
| 2 |
#ifndef EFONT_T1ITEM_HH |
| 3 |
#define EFONT_T1ITEM_HH |
| 4 |
#include <efont/t1cs.hh> |
| 5 |
#include <lcdf/straccum.hh> |
| 6 |
namespace Efont { |
| 7 |
class Type1Reader; |
| 8 |
class Type1Writer; |
| 9 |
class CharstringInterp; |
| 10 |
class Type1Font; |
| 11 |
class Type1CopyItem; |
| 12 |
class Type1Subr; |
| 13 |
class Type1SubrGroupItem; |
| 14 |
class Type1Definition; |
| 15 |
|
| 16 |
class Type1Item { public: |
| 17 |
|
| 18 |
Type1Item() { } |
| 19 |
virtual ~Type1Item() { } |
| 20 |
|
| 21 |
virtual void gen(Type1Writer &) = 0; |
| 22 |
|
| 23 |
virtual Type1CopyItem *cast_copy() { return 0; } |
| 24 |
virtual Type1Subr *cast_subr() { return 0; } |
| 25 |
virtual Type1Definition *cast_definition() { return 0; } |
| 26 |
virtual Type1SubrGroupItem *cast_subr_group() { return 0; } |
| 27 |
|
| 28 |
private: |
| 29 |
|
| 30 |
Type1Item(const Type1Item &); |
| 31 |
Type1Item &operator=(const Type1Item &); |
| 32 |
|
| 33 |
}; |
| 34 |
|
| 35 |
class Type1NullItem : public Type1Item { public: |
| 36 |
|
| 37 |
Type1NullItem() { } |
| 38 |
|
| 39 |
void gen(Type1Writer &); |
| 40 |
|
| 41 |
}; |
| 42 |
|
| 43 |
class Type1CopyItem : public Type1Item { public: |
| 44 |
|
| 45 |
Type1CopyItem(const String &s) : _value(s) { } |
| 46 |
~Type1CopyItem() { } |
| 47 |
|
| 48 |
const String &value() const { return _value; } |
| 49 |
int length() const { return _value.length(); } |
| 50 |
|
| 51 |
void set_value(const String &s) { _value = s; } |
| 52 |
|
| 53 |
void gen(Type1Writer &); |
| 54 |
|
| 55 |
Type1CopyItem *cast_copy() { return this; } |
| 56 |
|
| 57 |
private: |
| 58 |
|
| 59 |
String _value; |
| 60 |
|
| 61 |
}; |
| 62 |
|
| 63 |
class Type1EexecItem : public Type1Item { public: |
| 64 |
|
| 65 |
Type1EexecItem(bool on) : _eexec_on(on) { } |
| 66 |
|
| 67 |
void gen(Type1Writer &w); |
| 68 |
|
| 69 |
private: |
| 70 |
|
| 71 |
bool _eexec_on; |
| 72 |
|
| 73 |
}; |
| 74 |
|
| 75 |
class Type1Definition : public Type1Item { public: |
| 76 |
|
| 77 |
typedef Vector<double> NumVector; |
| 78 |
|
| 79 |
Type1Definition(PermString, const String &, PermString); |
| 80 |
~Type1Definition() { } |
| 81 |
static Type1Definition *make(StringAccum &, Type1Reader * = 0, bool force = false); |
| 82 |
static Type1Definition *make_string(PermString, const String &, PermString); |
| 83 |
static inline Type1Definition *make_literal(PermString, const String &, PermString); |
| 84 |
static inline Type1Definition *make(PermString, double, PermString); |
| 85 |
|
| 86 |
PermString name() const { return _name; } |
| 87 |
const String &value() const { return _val; } |
| 88 |
PermString definer() const { return _definer; } |
| 89 |
|
| 90 |
bool value_bool(bool &) const; |
| 91 |
bool value_int(int &) const; |
| 92 |
bool value_num(double &) const; |
| 93 |
bool value_string(String &) const; |
| 94 |
bool value_name(PermString &) const; |
| 95 |
bool value_numvec(NumVector &) const; |
| 96 |
bool value_numvec_vec(Vector<NumVector> &) const; |
| 97 |
bool value_normalize(Vector<NumVector> &in, Vector<NumVector> &out) const; |
| 98 |
bool value_namevec(Vector<PermString> &) const; |
| 99 |
|
| 100 |
void set_bool(bool); |
| 101 |
void set_int(int); |
| 102 |
void set_num(double); |
| 103 |
void set_string(const String &); |
| 104 |
void set_name(PermString, bool name = true); |
| 105 |
void set_code(const char *s) { set_val(s); } |
| 106 |
void set_numvec(const NumVector &, bool executable = false); |
| 107 |
void set_numvec_vec(const Vector<NumVector> &); |
| 108 |
void set_normalize(const Vector<NumVector> &, const Vector<NumVector> &); |
| 109 |
void set_namevec(const Vector<PermString> &, bool executable = true); |
| 110 |
|
| 111 |
void gen(Type1Writer &); |
| 112 |
void gen(StringAccum &); |
| 113 |
|
| 114 |
Type1Definition *cast_definition() { return this; } |
| 115 |
|
| 116 |
private: |
| 117 |
|
| 118 |
PermString _name; |
| 119 |
String _val; |
| 120 |
PermString _definer; |
| 121 |
|
| 122 |
static int slurp_string(StringAccum &, int, Type1Reader *); |
| 123 |
static int slurp_proc(StringAccum &, int, Type1Reader *); |
| 124 |
|
| 125 |
inline void set_val(const String &); |
| 126 |
inline void set_val(StringAccum &); |
| 127 |
|
| 128 |
}; |
| 129 |
|
| 130 |
class Type1Encoding : public Type1Item { public: |
| 131 |
|
| 132 |
Type1Encoding(); |
| 133 |
Type1Encoding(const Type1Encoding &); |
| 134 |
~Type1Encoding(); |
| 135 |
|
| 136 |
void clear(); |
| 137 |
void unshare(); |
| 138 |
|
| 139 |
PermString operator[](int e) const { assert(e>=0&&e<256); return _v[e]; } |
| 140 |
PermString elt(int e) const { return (*this)[e]; } |
| 141 |
PermString operator[](unsigned char e) const { return _v[e]; } |
| 142 |
PermString elt(unsigned char e) const { return operator[](e); } |
| 143 |
inline void put(int e, PermString p); |
| 144 |
|
| 145 |
void set_definer(PermString s) { _definer = s; } |
| 146 |
|
| 147 |
static Type1Encoding *standard_encoding(); |
| 148 |
|
| 149 |
void gen(Type1Writer &); |
| 150 |
|
| 151 |
private: |
| 152 |
|
| 153 |
PermString *_v; |
| 154 |
Type1Encoding *_copy_of; |
| 155 |
PermString _definer; |
| 156 |
|
| 157 |
Type1Encoding(Type1Encoding *); |
| 158 |
Type1Encoding &operator=(const Type1Encoding &); |
| 159 |
|
| 160 |
}; |
| 161 |
|
| 162 |
class Type1Subr : public Type1Item { public: |
| 163 |
|
| 164 |
static Type1Subr *make(const char *, int, int cs_start, int cs_len, int lenIV); |
| 165 |
static Type1Subr *make_subr(int, const Type1Charstring &, PermString); |
| 166 |
static Type1Subr *make_glyph(PermString, const Type1Charstring &, PermString); |
| 167 |
|
| 168 |
bool is_subr() const { return !_name; } |
| 169 |
PermString name() const { return _name; } |
| 170 |
int subrno() const { return _subrno; } |
| 171 |
PermString definer() const { return _definer; } |
| 172 |
|
| 173 |
Type1Charstring &t1cs() { return _cs; } |
| 174 |
const Type1Charstring &t1cs() const { return _cs; } |
| 175 |
operator Type1Charstring &() { return _cs; } |
| 176 |
operator const Type1Charstring &() const { return _cs; } |
| 177 |
|
| 178 |
void gen(Type1Writer &); |
| 179 |
|
| 180 |
virtual Type1Subr *cast_subr() { return this; } |
| 181 |
|
| 182 |
private: |
| 183 |
|
| 184 |
PermString _name; |
| 185 |
int _subrno; |
| 186 |
PermString _definer; |
| 187 |
|
| 188 |
Type1Charstring _cs; |
| 189 |
|
| 190 |
static PermString cached_definer; |
| 191 |
|
| 192 |
Type1Subr(PermString, int, PermString, int, const String &); |
| 193 |
Type1Subr(PermString, int, PermString, const Type1Charstring &); |
| 194 |
|
| 195 |
}; |
| 196 |
|
| 197 |
class Type1SubrGroupItem : public Type1Item { public: |
| 198 |
|
| 199 |
Type1SubrGroupItem(Type1Font *, bool, const String &); |
| 200 |
Type1SubrGroupItem(const Type1SubrGroupItem &, Type1Font *); |
| 201 |
~Type1SubrGroupItem() { } |
| 202 |
|
| 203 |
void set_end_text(const String &s) { _end_text = s; } |
| 204 |
void add_end_text(const String &); |
| 205 |
|
| 206 |
bool is_subrs() const { return _is_subrs; } |
| 207 |
const String &end_text() const { return _end_text; } |
| 208 |
|
| 209 |
void gen(Type1Writer &); |
| 210 |
|
| 211 |
Type1SubrGroupItem *cast_subr_group() { return this; } |
| 212 |
|
| 213 |
private: |
| 214 |
|
| 215 |
Type1Font *_font; |
| 216 |
bool _is_subrs; |
| 217 |
String _value; |
| 218 |
String _end_text; |
| 219 |
|
| 220 |
}; |
| 221 |
|
| 222 |
class Type1IncludedFont : public Type1Item { public: |
| 223 |
|
| 224 |
Type1IncludedFont(Type1Font *, int); |
| 225 |
~Type1IncludedFont(); |
| 226 |
|
| 227 |
Type1Font *included_font() const { return _included_font; } |
| 228 |
|
| 229 |
void gen(Type1Writer &); |
| 230 |
|
| 231 |
private: |
| 232 |
|
| 233 |
Type1Font *_included_font; |
| 234 |
int _unique_id; |
| 235 |
|
| 236 |
}; |
| 237 |
|
| 238 |
|
| 239 |
inline Type1Definition *Type1Definition::make_literal(PermString n, const String &v, PermString d) |
| 240 |
{ |
| 241 |
return new Type1Definition(n, v, d); |
| 242 |
} |
| 243 |
|
| 244 |
inline Type1Definition *Type1Definition::make(PermString n, double v, PermString d) |
| 245 |
{ |
| 246 |
return new Type1Definition(n, String(v), d); |
| 247 |
} |
| 248 |
|
| 249 |
inline void Type1Definition::set_val(const String &v) |
| 250 |
{ |
| 251 |
_val = v; |
| 252 |
} |
| 253 |
|
| 254 |
inline void Type1Definition::set_val(StringAccum &sa) |
| 255 |
{ |
| 256 |
_val = sa.take_string(); |
| 257 |
} |
| 258 |
|
| 259 |
inline void Type1Encoding::put(int e, PermString glyph) |
| 260 |
{ |
| 261 |
if (_copy_of) |
| 262 |
unshare(); |
| 263 |
assert(e >= 0 && e < 256); |
| 264 |
_v[e] = glyph; |
| 265 |
} |
| 266 |
|
| 267 |
} |
| 268 |
#endif |