| 1 |
// -*- related-file-name: "../../libefont/t1bounds.cc" -*- |
| 2 |
#ifndef EFONT_T1BOUNDS_HH |
| 3 |
#define EFONT_T1BOUNDS_HH |
| 4 |
#include <efont/t1interp.hh> |
| 5 |
#include <lcdf/transform.hh> |
| 6 |
namespace Efont { |
| 7 |
|
| 8 |
class CharstringBounds : public CharstringInterp { public: |
| 9 |
|
| 10 |
CharstringBounds(); |
| 11 |
CharstringBounds(const Transform&); |
| 12 |
CharstringBounds(const Transform&, const Vector<double>& weight_vec); |
| 13 |
~CharstringBounds() { } |
| 14 |
|
| 15 |
const Point& width() const { return _width; } |
| 16 |
double x_width() const { return _width.x; } |
| 17 |
bool bb_known() const { return KNOWN(_lb.x); } |
| 18 |
double bb_left() const { return _lb.x; } |
| 19 |
double bb_top() const { return _rt.y; } |
| 20 |
double bb_right() const { return _rt.x; } |
| 21 |
double bb_bottom() const { return _lb.y; } |
| 22 |
const Point& bb_bottom_left() const { return _lb; } |
| 23 |
const Point& bb_top_right() const { return _rt; } |
| 24 |
|
| 25 |
void act_width(int, const Point&); |
| 26 |
void act_line(int, const Point&, const Point&); |
| 27 |
void act_curve(int, const Point&, const Point&, const Point&, const Point&); |
| 28 |
inline void mark(const Point&); |
| 29 |
|
| 30 |
void clear(); |
| 31 |
bool char_bounds(const CharstringContext&, bool shift = true); |
| 32 |
void translate(double dx, double dy); |
| 33 |
inline Point transform(const Point& p) const; |
| 34 |
|
| 35 |
// output: [left, bottom, right, top] |
| 36 |
bool output(double bb[4], double& width, bool use_cur_width = false) const; |
| 37 |
static bool bounds(const CharstringContext&, |
| 38 |
double bounds[4], double& width); |
| 39 |
static bool bounds(const Transform&, const CharstringContext&, |
| 40 |
double bounds[4], double& width); |
| 41 |
|
| 42 |
private: |
| 43 |
|
| 44 |
Point _lb; |
| 45 |
Point _rt; |
| 46 |
Point _width; |
| 47 |
Transform _xf; |
| 48 |
Transform _nonfont_xf; |
| 49 |
const CharstringProgram* _last_xf_program; |
| 50 |
|
| 51 |
void set_xf(const CharstringProgram*); |
| 52 |
|
| 53 |
inline void xf_mark(const Point&); |
| 54 |
void xf_mark(const Bezier&); |
| 55 |
|
| 56 |
inline bool xf_inside(const Point&) const; |
| 57 |
inline bool xf_controls_inside(const Bezier&) const; |
| 58 |
|
| 59 |
}; |
| 60 |
|
| 61 |
inline void CharstringBounds::xf_mark(const Point& p) |
| 62 |
{ |
| 63 |
if (!KNOWN(_lb.x)) |
| 64 |
_lb = _rt = p; |
| 65 |
if (p.x < _lb.x) |
| 66 |
_lb.x = p.x; |
| 67 |
else if (p.x > _rt.x) |
| 68 |
_rt.x = p.x; |
| 69 |
if (p.y < _lb.y) |
| 70 |
_lb.y = p.y; |
| 71 |
else if (p.y > _rt.y) |
| 72 |
_rt.y = p.y; |
| 73 |
} |
| 74 |
|
| 75 |
inline void CharstringBounds::mark(const Point& p) |
| 76 |
{ |
| 77 |
xf_mark(p * _xf); |
| 78 |
} |
| 79 |
|
| 80 |
inline bool CharstringBounds::xf_inside(const Point& p) const |
| 81 |
{ |
| 82 |
return p.x >= _lb.x && p.x <= _rt.x && p.y >= _lb.y && p.y <= _rt.y; |
| 83 |
} |
| 84 |
|
| 85 |
inline bool CharstringBounds::xf_controls_inside(const Bezier& b) const |
| 86 |
{ |
| 87 |
return xf_inside(b.point(1)) && xf_inside(b.point(2)); |
| 88 |
} |
| 89 |
|
| 90 |
inline Point CharstringBounds::transform(const Point& p) const |
| 91 |
{ |
| 92 |
return p * _xf; |
| 93 |
} |
| 94 |
|
| 95 |
} |
| 96 |
#endif |