• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**********************************************************************
2  * File:        polyblk.h  (Formerly poly_block.h)
3  * Description: Polygonal blocks
4  * Author:					Sheelagh Lloyd?
5  * Created:
6  *
7  * (C) Copyright 1993, 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 #ifndef           POLYBLK_H
20 #define           POLYBLK_H
21 
22 #include          "rect.h"
23 #include          "points.h"
24 #include          "scrollview.h"
25 #include          "elst.h"
26 
27 #include          "hpddef.h"     //must be last (handpd.dll)
28 
29 // Possible types for a POLY_BLOCK or ColPartition. Must be kept in sync with
30 // kPBColors. Used extensively by ColPartition, but polyblk is a lower-level
31 // file.
32 enum PolyBlockType {
33   PT_UNKNOWN,        // Type is not yet known. Keep as the first element.
34   PT_FLOWING_TEXT,   // Text that lives inside a column.
35   PT_HEADING_TEXT,   // Text that spans more than one column.
36   PT_PULLOUT_TEXT,   // Text that is in a cross-column pull-out region.
37   PT_TABLE,          // Partition belonging to a table region.
38   PT_VERTICAL_TEXT,  // Text-line runs vertically.
39   PT_FLOWING_IMAGE,  // Image that lives inside a column.
40   PT_HEADING_IMAGE,  // Image that spans more than one column.
41   PT_PULLOUT_IMAGE,  // Image that is in a cross-column pull-out region.
42   PT_FLOWING_LINE,   // H-Line that lives inside a column.
43   PT_HEADING_LINE,   // H-Line that spans more than one column.
44   PT_PULLOUT_LINE,   // H-Line that is in a cross-column pull-out region.
45   PT_NOISE,          // Lies outside of any column.
46   PT_COUNT
47 };
48 
49 class DLLSYM POLY_BLOCK {
50   public:
POLY_BLOCK()51     POLY_BLOCK() {
52   }
53   POLY_BLOCK(ICOORDELT_LIST *points, PolyBlockType type);
~POLY_BLOCK()54     ~POLY_BLOCK () {
55   }
56 
bounding_box()57     TBOX *bounding_box() {  // access function
58       return &box;
59     }
60 
points()61     ICOORDELT_LIST *points() {  // access function
62       return &vertices;
63     }
64 
65     void compute_bb();
66 
isA()67   PolyBlockType isA() const {
68       return type;
69     }
70 
IsText()71   bool IsText() const {
72     return IsTextType(type);
73   }
74 
75   // Rotate about the origin by the given rotation. (Analogous to
76   // multiplying by a complex number.
77   void rotate(FCOORD rotation);
78   // Move by adding shift to all coordinates.
79   void move(ICOORD shift);
80 
81   void plot(ScrollView* window, inT32 num);
82 
83     void fill(ScrollView* window, ScrollView::Color colour);
84 
85   // Returns true if other is inside this.
86   bool contains(POLY_BLOCK *other);
87 
88   // Returns true if the polygons of other and this overlap.
89   bool overlap(POLY_BLOCK *other);
90 
91   // Returns the winding number of this around the test_pt.
92   // Positive for anticlockwise, negative for clockwise, and zero for
93   // test_pt outside this.
94   inT16 winding_number(const ICOORD &test_pt);
95 
96   // Serialization.
prep_serialise()97     void prep_serialise() {
98       vertices.prep_serialise ();
99     }
dump(FILE * f)100     void dump(FILE *f) {
101       vertices.dump (f);
102     }
de_dump(FILE * f)103     void de_dump(FILE *f) {
104       vertices.de_dump (f);
105     }
106   make_serialise(POLY_BLOCK)
107   void serialise_asc(FILE * f);
108   void de_serialise_asc(FILE *f);
109 
110   // Static utility functions to handle the PolyBlockType.
111 
112   // Returns a color to draw the given type.
113   static ScrollView::Color ColorForPolyBlockType(PolyBlockType type);
114 
115   // Returns true if PolyBlockType is of horizontal line type
IsLineType(PolyBlockType type)116   static bool IsLineType(PolyBlockType type) {
117     return (type == PT_FLOWING_LINE) || (type == PT_HEADING_LINE) ||
118         (type == PT_PULLOUT_LINE);
119   }
120   // Returns true if PolyBlockType is of image type
IsImageType(PolyBlockType type)121   static bool IsImageType(PolyBlockType type) {
122     return (type == PT_FLOWING_IMAGE) || (type == PT_HEADING_IMAGE) ||
123            (type == PT_PULLOUT_IMAGE);
124   }
125   // Returns true if PolyBlockType is of text type
IsTextType(PolyBlockType type)126   static bool IsTextType(PolyBlockType type) {
127     return (type == PT_FLOWING_TEXT) || (type == PT_HEADING_TEXT) ||
128            (type == PT_PULLOUT_TEXT) || (type == PT_TABLE) ||
129            (type == PT_VERTICAL_TEXT);
130   }
131 
132   private:
133     ICOORDELT_LIST vertices;     // vertices
134     TBOX box;                     // bounding box
135   PolyBlockType type;              // Type of this region.
136 };
137 
138 // Class to iterate the scanlines of a polygon.
139 class DLLSYM PB_LINE_IT {
140   public:
PB_LINE_IT(POLY_BLOCK * blkptr)141   PB_LINE_IT(POLY_BLOCK *blkptr) {
142       block = blkptr;
143     }
144 
NEWDELETE2(PB_LINE_IT)145   NEWDELETE2(PB_LINE_IT)
146 
147   void set_to_block(POLY_BLOCK * blkptr) {
148       block = blkptr;
149     }
150 
151   // Returns a list of runs of pixels for the given y coord.
152   // Each element of the returned list is the start (x) and extent(y) of
153   // a run inside the region.
154   // Delete the returned list after use.
155     ICOORDELT_LIST *get_line(inT16 y);
156 
157   private:
158     POLY_BLOCK * block;
159 };
160 #endif
161