| 1 |
#ifndef OTFTOTFM_SECONDARY_HH |
| 2 |
#define OTFTOTFM_SECONDARY_HH |
| 3 |
#include <efont/otfcmap.hh> |
| 4 |
#include <efont/cff.hh> |
| 5 |
#include "setting.hh" |
| 6 |
class Metrics; |
| 7 |
class Secondary; |
| 8 |
class Transform; |
| 9 |
namespace Efont { class TrueTypeBoundsCharstringProgram; } |
| 10 |
|
| 11 |
struct FontInfo { |
| 12 |
|
| 13 |
const Efont::OpenType::Font *otf; |
| 14 |
const Efont::OpenType::Cmap *cmap; |
| 15 |
|
| 16 |
Efont::Cff *cff_file; |
| 17 |
const Efont::Cff::Font *cff; |
| 18 |
|
| 19 |
const Efont::OpenType::Post *post; |
| 20 |
const Efont::OpenType::Name *name; |
| 21 |
|
| 22 |
FontInfo(const Efont::OpenType::Font *otf, ErrorHandler *); |
| 23 |
~FontInfo(); |
| 24 |
|
| 25 |
bool ok() const; |
| 26 |
|
| 27 |
int nglyphs() const { return _nglyphs; } |
| 28 |
bool glyph_names(Vector<PermString> &) const; |
| 29 |
int glyphid(PermString) const; |
| 30 |
const Efont::CharstringProgram *program() const; |
| 31 |
int units_per_em() const { |
| 32 |
return program()->units_per_em(); |
| 33 |
} |
| 34 |
|
| 35 |
bool is_fixed_pitch() const; |
| 36 |
double italic_angle() const; |
| 37 |
double x_height(const Transform& font_xform) const; |
| 38 |
|
| 39 |
void set_is_fixed_pitch(bool is_fixed_pitch) { |
| 40 |
_override_is_fixed_pitch = true; |
| 41 |
_is_fixed_pitch = is_fixed_pitch; |
| 42 |
} |
| 43 |
void set_italic_angle(double italic_angle) { |
| 44 |
_override_italic_angle = true; |
| 45 |
_italic_angle = italic_angle; |
| 46 |
} |
| 47 |
enum { x_height_auto = 0, x_height_explicit, |
| 48 |
x_height_os2, x_height_x }; |
| 49 |
void set_x_height(int source, double x_height) { |
| 50 |
_override_x_height = source; |
| 51 |
_x_height = x_height; |
| 52 |
} |
| 53 |
|
| 54 |
String family_name() const; |
| 55 |
String postscript_name() const; |
| 56 |
|
| 57 |
private: |
| 58 |
|
| 59 |
int _nglyphs; |
| 60 |
mutable Vector<PermString> _glyph_names; |
| 61 |
mutable bool _got_glyph_names; |
| 62 |
mutable Vector<uint32_t> _unicodes; |
| 63 |
mutable Efont::TrueTypeBoundsCharstringProgram *_ttb_program; |
| 64 |
bool _override_is_fixed_pitch; |
| 65 |
bool _override_italic_angle; |
| 66 |
bool _is_fixed_pitch; |
| 67 |
uint8_t _override_x_height; |
| 68 |
double _italic_angle; |
| 69 |
double _x_height; |
| 70 |
|
| 71 |
}; |
| 72 |
|
| 73 |
class SettingSet { |
| 74 |
public: |
| 75 |
inline SettingSet(Secondary* s, Metrics& m); |
| 76 |
inline SettingSet& push_back(Setting s); |
| 77 |
inline SettingSet& push_back(int op, int x = 0, int y = 0); |
| 78 |
inline SettingSet& move(int x, int y = 0); |
| 79 |
SettingSet& show(int uni); |
| 80 |
inline SettingSet& kernx(bool is_kernx); |
| 81 |
inline bool check(); |
| 82 |
inline void checkpoint(); |
| 83 |
inline Metrics& metrics() const; |
| 84 |
inline const Vector<Setting>& settings() const; |
| 85 |
private: |
| 86 |
Secondary* s_; |
| 87 |
Vector<Setting> v_; |
| 88 |
int original_size_; |
| 89 |
Metrics& metrics_; |
| 90 |
int kern_type_; |
| 91 |
bool ok_; |
| 92 |
typedef Efont::OpenType::Glyph Glyph; |
| 93 |
}; |
| 94 |
|
| 95 |
class Secondary { public: |
| 96 |
Secondary(const FontInfo& finfo) : _finfo(finfo), _next(0) { } |
| 97 |
virtual ~Secondary(); |
| 98 |
void set_next(Secondary *s) { _next = s; } |
| 99 |
typedef Efont::OpenType::Glyph Glyph; |
| 100 |
bool encode_uni(int code, PermString name, const uint32_t* uni_first, const uint32_t* uni_last, Metrics &metrics, ErrorHandler *errh); |
| 101 |
inline bool encode_uni(int code, PermString name, uint32_t uni, Metrics& m, ErrorHandler* errh); |
| 102 |
virtual int setting(uint32_t uni, SettingSet&, ErrorHandler *); |
| 103 |
protected: |
| 104 |
const FontInfo& _finfo; |
| 105 |
|
| 106 |
friend class SettingSet; |
| 107 |
private: |
| 108 |
Secondary *_next; |
| 109 |
}; |
| 110 |
|
| 111 |
class T1Secondary : public Secondary { public: |
| 112 |
T1Secondary(const FontInfo &, const String &font_name, const String &otf_file_name); |
| 113 |
int setting(uint32_t uni, SettingSet&, ErrorHandler *); |
| 114 |
private: |
| 115 |
String _font_name; |
| 116 |
String _otf_file_name; |
| 117 |
int _units_per_em; |
| 118 |
int _xheight; |
| 119 |
int _spacewidth; |
| 120 |
enum { J_NODOT = -1031892 /* unlikely value */ }; |
| 121 |
int dotlessj_font(Metrics &, ErrorHandler *, Glyph &dj_glyph); |
| 122 |
}; |
| 123 |
|
| 124 |
bool char_bounds(double bounds[4], double& width, const FontInfo &, |
| 125 |
const Transform &, uint32_t uni); |
| 126 |
|
| 127 |
double char_one_bound(const FontInfo &, const Transform &, |
| 128 |
int dimen, bool max, double best, int uni, ...); |
| 129 |
|
| 130 |
inline SettingSet::SettingSet(Secondary* s, Metrics& m) |
| 131 |
: s_(s), original_size_(0), metrics_(m), |
| 132 |
kern_type_(Setting::KERN), ok_(true) { |
| 133 |
} |
| 134 |
|
| 135 |
inline SettingSet& SettingSet::kernx(bool is_kernx) { |
| 136 |
kern_type_ = is_kernx ? Setting::KERNX : Setting::KERN; |
| 137 |
return *this; |
| 138 |
} |
| 139 |
|
| 140 |
inline SettingSet& SettingSet::push_back(Setting s) { |
| 141 |
if (ok_) |
| 142 |
v_.push_back(s); |
| 143 |
return *this; |
| 144 |
} |
| 145 |
|
| 146 |
inline SettingSet& SettingSet::push_back(int op, int x, int y) { |
| 147 |
return push_back(Setting(op, x, y)); |
| 148 |
} |
| 149 |
|
| 150 |
inline SettingSet& SettingSet::move(int x, int y) { |
| 151 |
return push_back(Setting(Setting::MOVE, x, y)); |
| 152 |
} |
| 153 |
|
| 154 |
inline bool SettingSet::check() { |
| 155 |
bool ok = ok_; |
| 156 |
ok_ = true; |
| 157 |
return ok; |
| 158 |
} |
| 159 |
|
| 160 |
inline void SettingSet::checkpoint() { |
| 161 |
assert(ok_); |
| 162 |
original_size_ = v_.size(); |
| 163 |
} |
| 164 |
|
| 165 |
inline Metrics& SettingSet::metrics() const { |
| 166 |
return metrics_; |
| 167 |
} |
| 168 |
|
| 169 |
inline const Vector<Setting>& SettingSet::settings() const { |
| 170 |
return v_; |
| 171 |
} |
| 172 |
|
| 173 |
inline bool Secondary::encode_uni(int code, PermString name, uint32_t uni, Metrics& m, ErrorHandler* errh) { |
| 174 |
return encode_uni(code, name, &uni, &uni + 1, m, errh); |
| 175 |
} |
| 176 |
|
| 177 |
#endif |