1 /**********************************************************************
2 * File: pdblock.h (Formerly pdblk.h)
3 * Description: Page block class definition.
4 * Author: Ray Smith
5 * Created: Thu Mar 14 17:32:01 GMT 1991
6 *
7 * (C) Copyright 1991, Hewlett-Packard Ltd.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 *
18 **********************************************************************/
19
20 #ifndef PDBLOCK_H
21 #define PDBLOCK_H
22
23 #include "img.h"
24 #include "strngs.h"
25 #include "polyblk.h"
26
27 #include "hpddef.h" //must be last (handpd.dll)
28
29 class DLLSYM PDBLK; //forward decl
30
CLISTIZEH(PDBLK)31 CLISTIZEH (PDBLK)
32 class DLLSYM PDBLK //page block
33 {
34 friend class BLOCK_RECT_IT; //block iterator
35
36 public:
37 PDBLK() { //empty constructor
38 hand_poly = NULL;
39 index_ = 0;
40 }
41 PDBLK( //simple constructor
42 inT16 xmin, //bottom left
43 inT16 ymin,
44 inT16 xmax, //top right
45 inT16 ymax);
46
47 void set_sides( //set vertex lists
48 ICOORDELT_LIST *left, //list of left vertices
49 ICOORDELT_LIST *right); //list of right vertices
50
51 ~PDBLK () { //destructor
52 if (hand_poly) delete hand_poly;
53 }
54
55 POLY_BLOCK *poly_block() {
56 return hand_poly;
57 }
58 void set_poly_block( //set the poly block
59 POLY_BLOCK *blk) {
60 hand_poly = blk;
61 }
62 void bounding_box( //get box
63 ICOORD &bottom_left, //bottom left
64 ICOORD &top_right) const { //topright
65 bottom_left = box.botleft ();
66 top_right = box.topright ();
67 }
68 //get real box
69 const TBOX &bounding_box() const {
70 return box;
71 }
72
73 int index() const {
74 return index_;
75 }
76 void set_index(int value) {
77 index_ = value;
78 }
79
80 BOOL8 contains( //is pt inside block
81 ICOORD pt);
82
83 void move( // reposition block
84 const ICOORD vec); // by vector
85
86 void plot( //draw histogram
87 ScrollView* window, //window to draw in
88 inT32 serial, //serial number
89 ScrollView::Color colour); //colour to draw in
90
91 void show( //show image
92 IMAGE *image, //image to show
93 ScrollView* window); //window to show in
94
95 PDBLK & operator= ( //assignment
96 const PDBLK & source); //from this
97
98 protected:
99 POLY_BLOCK *hand_poly; //wierd as well
100 ICOORDELT_LIST leftside; //left side vertices
101 ICOORDELT_LIST rightside; //right side vertices
102 TBOX box; //bounding box
103 int index_; // Serial number of this block.
104 };
105
106 class DLLSYM BLOCK_RECT_IT //rectangle iterator
107 {
108 public:
109 BLOCK_RECT_IT( //constructor
110 PDBLK *blkptr); //block to iterate
111
112 //start (new) block
113 NEWDELETE2 (BLOCK_RECT_IT) void set_to_block (
114 PDBLK * blkptr); //block to iterate
115
116 void start_block(); //start iteration
117
118 void forward(); //next rectangle
119
cycled_rects()120 BOOL8 cycled_rects() { //test end
121 return left_it.cycled_list () && right_it.cycled_list ();
122 }
123
bounding_box(ICOORD & bleft,ICOORD & tright)124 void bounding_box( //current rectangle
125 ICOORD &bleft, //bottom left
126 ICOORD &tright) { //top right
127 //bottom left
128 bleft = ICOORD (left_it.data ()->x (), ymin);
129 //top right
130 tright = ICOORD (right_it.data ()->x (), ymax);
131 }
132
133 private:
134 inT16 ymin; //bottom of rectangle
135 inT16 ymax; //top of rectangle
136 PDBLK *block; //block to iterate
137 ICOORDELT_IT left_it; //boundary iterators
138 ICOORDELT_IT right_it;
139 };
140
141 class DLLSYM BLOCK_LINE_IT //rectangle iterator
142 {
143 public:
BLOCK_LINE_IT(PDBLK * blkptr)144 BLOCK_LINE_IT ( //constructor
145 PDBLK * blkptr) //from block
146 :rect_it (blkptr) {
147 block = blkptr; //remember block
148 }
149
150 //start (new) block
NEWDELETE2(BLOCK_LINE_IT)151 NEWDELETE2 (BLOCK_LINE_IT) void set_to_block (
152 PDBLK * blkptr) { //block to start
153 block = blkptr; //remember block
154 //set iterator
155 rect_it.set_to_block (blkptr);
156 }
157
158 inT16 get_line( //get a line
159 inT16 y, //line to get
160 inT16 &xext); //output extent
161
162 private:
163 PDBLK * block; //block to iterate
164 BLOCK_RECT_IT rect_it; //rectangle iterator
165 };
166
167 int decreasing_top_order( //
168 const void *row1,
169 const void *row2);
170 #endif
171