2
/******************************************************************************
4
* DESCRIPTION: the low level box structure
5
* and formatting routines
6
* COPYRIGHT : (C) 1999 Joris van der Hoeven
7
*******************************************************************************
8
* This software falls under the GNU general public license and comes WITHOUT
9
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
10
* If you don't have this file, write to the Free Software Foundation, Inc.,
11
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
12
******************************************************************************/
17
#include "rectangles.hpp"
19
#include "ps_device.hpp"
21
#include "language.hpp"
22
#include "hashmap.hpp"
23
#include "Graphics/frame.hpp"
25
#define MAX_SI 0x7fffffff
26
#define MIN_SI 0x80000000
33
/******************************************************************************
35
******************************************************************************/
37
struct cursor_rep: concrete_struct {
38
SI ox, oy; // main cursor position
39
SI delta; // infinitesimal shift to the right
40
SI y1; // under base line
41
SI y2; // upper base line
42
double slope; // slope of cursor
43
bool valid; // the cursor is valid
48
cursor (SI x=0, SI y=0, SI delta=0, SI y1=0, SI y2=0,
49
double slope=0.0, bool valid=true);
51
CONCRETE_CODE(cursor);
53
cursor copy (cursor cu);
54
bool operator == (cursor cu1, cursor cu2);
55
bool operator != (cursor cu1, cursor cu2);
56
ostream& operator << (ostream& out, cursor cu);
58
/******************************************************************************
60
******************************************************************************/
62
struct selection_rep: concrete_struct {
71
selection (rectangles rs= rectangles(),
72
path start= path(), path end= path ());
74
CONCRETE_CODE(selection);
76
bool operator == (selection sel1, selection sel2);
77
bool operator != (selection sel1, selection sel2);
78
ostream& operator << (ostream& out, selection sel);
80
/******************************************************************************
82
******************************************************************************/
86
typedef array<double> point;
90
inline box operator [] (int i);
92
bool operator == (box b2);
93
bool operator != (box b2);
94
friend inline int N (box b);
97
class box_rep: public abstract_struct {
99
SI x0, y0; // offset w.r.t. parent box
102
SI x1, y1; // under left corner (logical)
103
SI x2, y2; // upper right corner (logical)
104
SI x3, y3; // under left corner (ink)
105
SI x4, y4; // upper right corner (ink)
107
path ip; // corresponding inverse path in source tree
109
/****************************** main routines ******************************/
111
inline box_rep (path ip);
112
inline virtual ~box_rep ();
113
void relocate (path p, bool force= false);
114
virtual operator tree () = 0;
115
virtual bool display_background (ps_device dev, color& col);
116
virtual void display (ps_device dev) = 0;
117
virtual void clear_incomplete (rectangles& rs, SI pixel,
118
int i, int i1, int i2);
119
virtual int subnr ();
120
virtual box subbox (int i);
121
virtual tree action (tree t, SI x, SI y, SI delta);
122
virtual void position_at (SI x, SI y, rectangles& change_log);
123
virtual void collect_page_numbers (hashmap<string,tree>& h, tree page);
124
virtual path find_tag (string name);
126
void redraw (ps_device dev, path p, rectangles& l);
127
void redraw (ps_device dev, path p, rectangles& l, SI x, SI y);
129
/*************************** positioning routines **************************/
133
inline SI& sx (int i);
134
inline SI& sy (int i);
135
inline SI sx1 (int i);
136
inline SI sy1 (int i);
137
inline SI sx2 (int i);
138
inline SI sy2 (int i);
139
inline SI sx3 (int i);
140
inline SI sy3 (int i);
141
inline SI sx4 (int i);
142
inline SI sy4 (int i);
143
inline bool test_in (SI x, SI y);
145
inline bool accessible ();
146
inline bool decoration ();
148
SI distance (int i, SI x, SI y, SI delta);
150
/******************* path conversions and cursor routines ******************/
152
virtual path find_lip ();
153
virtual path find_rip ();
154
virtual path find_left_box_path ();
155
virtual path find_right_box_path ();
156
virtual path find_box_path (SI x, SI y, SI delta, bool force);
157
virtual cursor find_cursor (path bp);
158
virtual selection find_selection (path lbp, path rbp);
159
virtual path find_tree_path (path bp);
160
virtual path find_box_path (path p, bool& found);
162
path find_tree_path (SI x, SI y, SI delta);
163
cursor find_check_cursor (path p);
164
selection find_check_selection (path lp, path rp);
166
/************************ fine typesetting routines ************************/
168
virtual double left_slope ();
169
virtual double right_slope ();
170
virtual SI left_correction ();
171
virtual SI right_correction ();
172
virtual SI lsub_correction ();
173
virtual SI lsup_correction ();
174
virtual SI rsub_correction ();
175
virtual SI rsup_correction ();
176
virtual SI sub_lo_base (int level);
177
virtual SI sub_hi_lim (int level);
178
virtual SI sup_lo_lim (int level);
179
virtual SI sup_lo_base (int level);
180
virtual SI sup_hi_lim (int level);
182
/*************************** for graphical boxes ***************************/
184
virtual frame get_frame ();
185
virtual void get_limits (point& lim1, point& lim2);
187
frame find_frame (path bp);
188
void find_limits (path bp, point& lim1, point& lim2);
190
/************************** retrieving information *************************/
192
virtual int get_type ();
193
virtual tree get_info ();
194
virtual int get_leaf_left_pos ();
195
virtual int get_leaf_right_pos ();
196
virtual string get_leaf_string ();
197
virtual font get_leaf_font ();
198
virtual color get_leaf_color ();
199
virtual language get_leaf_language ();
200
virtual tree get_leaf_tree ();
201
virtual lazy get_leaf_lazy ();
202
virtual SI get_leaf_offset (string search);
204
/********************************* obsolete ********************************/
206
friend struct page_box_rep; // temporary friends for accessing x0 and y0
207
friend struct lazy_paragraph_rep;
208
friend class phrase_box_rep;
210
ABSTRACT_NULL_CODE(box);
212
extern int box_count;
213
inline box_rep::box_rep (path ip2):
214
x0(0), y0(0), x1(0), y1(0), x2(0), y2(0), x3(0), y3(0), x4(0), y4(0),
215
ip (ip2) { DEBUG(box_count++); }
216
inline box_rep::~box_rep () { DEBUG(box_count--); }
217
inline bool box_rep::test_in (SI x, SI y) {
218
return (x>=x1) && (x<x2) && (y>=y1) && (y<y2); }
219
inline SI box_rep::w () { return x2-x1; }
220
inline SI box_rep::h () { return y2-y1; }
221
inline SI& box_rep::sx (int i) { return subbox(i)->x0; }
222
inline SI& box_rep::sy (int i) { return subbox(i)->y0; }
223
inline SI box_rep::sx1 (int i) { box b= subbox(i); return b->x0+ b->x1; }
224
inline SI box_rep::sy1 (int i) { box b= subbox(i); return b->y0+ b->y1; }
225
inline SI box_rep::sx2 (int i) { box b= subbox(i); return b->x0+ b->x2; }
226
inline SI box_rep::sy2 (int i) { box b= subbox(i); return b->y0+ b->y2; }
227
inline SI box_rep::sx3 (int i) { box b= subbox(i); return b->x0+ b->x3; }
228
inline SI box_rep::sy3 (int i) { box b= subbox(i); return b->y0+ b->y3; }
229
inline SI box_rep::sx4 (int i) { box b= subbox(i); return b->x0+ b->x4; }
230
inline SI box_rep::sy4 (int i) { box b= subbox(i); return b->y0+ b->y4; }
232
inline box box::operator [] (int i) { return rep->subbox(i); }
233
inline int N (box b) { return b.rep->subnr(); }
234
ostream& operator << (ostream& out, box b);
235
SI get_delta (SI x, SI x1, SI x2);
236
bool outside (SI x, SI delta, SI x1, SI x2);
238
#define DECORATION (-1)
239
#define DECORATION_LEFT (-2)
240
#define DECORATION_MIDDLE (-3)
241
#define DECORATION_RIGHT (-4)
242
#define is_accessible(p) ((nil (p)) || ((p)->item >= 0))
243
#define is_decoration(p) ((!nil (p)) && ((p)->item < 0))
244
inline path descend (path ip, int i) {
245
return (nil (ip) || (ip->item >= 0))? path (i, ip): ip; }
246
inline path decorate () {
247
return path (DECORATION); }
248
inline path decorate (path ip) {
249
return (nil (ip) || (ip->item >= 0))? path (DECORATION, ip): ip; }
250
inline path decorate_left (path ip) {
251
return (nil (ip) || (ip->item >= 0))? path (DECORATION_LEFT, ip): ip; }
252
inline path decorate_middle (path ip) {
253
return (nil (ip) || (ip->item >= 0))? path (DECORATION_MIDDLE, ip): ip; }
254
inline path decorate_right (path ip) {
255
return (nil (ip) || (ip->item >= 0))? path (DECORATION_RIGHT, ip): ip; }
256
path descend_decode (path ip, int side);
258
inline bool box_rep::accessible () { return is_accessible (find_lip ()); }
259
inline bool box_rep::decoration () { return is_decoration (find_lip ()); }
261
#endif // defined BOXES_H