Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/ccstruct/pdblock.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /********************************************************************** | |
| 2 * File: pdblock.h (Formerly pdblk.h) | |
| 3 * Description: Page block class definition. | |
| 4 * Author: Ray Smith | |
| 5 * | |
| 6 * (C) Copyright 1991, Hewlett-Packard Ltd. | |
| 7 ** Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 ** you may not use this file except in compliance with the License. | |
| 9 ** You may obtain a copy of the License at | |
| 10 ** http://www.apache.org/licenses/LICENSE-2.0 | |
| 11 ** Unless required by applicable law or agreed to in writing, software | |
| 12 ** distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 ** See the License for the specific language governing permissions and | |
| 15 ** limitations under the License. | |
| 16 * | |
| 17 **********************************************************************/ | |
| 18 | |
| 19 #ifndef PDBLOCK_H | |
| 20 #define PDBLOCK_H | |
| 21 | |
| 22 #include "clst.h" | |
| 23 #include "polyblk.h" | |
| 24 | |
| 25 struct Pix; | |
| 26 | |
| 27 namespace tesseract { | |
| 28 | |
| 29 class PDBLK; // forward decl | |
| 30 | |
| 31 CLISTIZEH(PDBLK) | |
| 32 /// page block | |
| 33 class PDBLK { | |
| 34 friend class BLOCK_RECT_IT; ///< block iterator | |
| 35 friend class BLOCK; ///< Page Block | |
| 36 | |
| 37 public: | |
| 38 /// empty constructor | |
| 39 PDBLK() { | |
| 40 hand_poly = nullptr; | |
| 41 index_ = 0; | |
| 42 } | |
| 43 /// simple constructor | |
| 44 PDBLK(TDimension xmin, ///< bottom left | |
| 45 TDimension ymin, | |
| 46 TDimension xmax, ///< top right | |
| 47 TDimension ymax); | |
| 48 | |
| 49 /// set vertex lists | |
| 50 ///@param left list of left vertices | |
| 51 ///@param right list of right vertices | |
| 52 void set_sides(ICOORDELT_LIST *left, ICOORDELT_LIST *right); | |
| 53 | |
| 54 /// destructor | |
| 55 ~PDBLK() { | |
| 56 delete hand_poly; | |
| 57 } | |
| 58 | |
| 59 POLY_BLOCK *poly_block() const { | |
| 60 return hand_poly; | |
| 61 } | |
| 62 /// set the poly block | |
| 63 void set_poly_block(POLY_BLOCK *blk) { | |
| 64 hand_poly = blk; | |
| 65 } | |
| 66 /// get box | |
| 67 void bounding_box(ICOORD &bottom_left, // bottom left | |
| 68 ICOORD &top_right) const { // topright | |
| 69 bottom_left = box.botleft(); | |
| 70 top_right = box.topright(); | |
| 71 } | |
| 72 /// get real box | |
| 73 const TBOX &bounding_box() const { | |
| 74 return box; | |
| 75 } | |
| 76 | |
| 77 int index() const { | |
| 78 return index_; | |
| 79 } | |
| 80 void set_index(int value) { | |
| 81 index_ = value; | |
| 82 } | |
| 83 | |
| 84 /// is pt inside block | |
| 85 bool contains(ICOORD pt); | |
| 86 | |
| 87 /// reposition block | |
| 88 void move(const ICOORD vec); // by vector | |
| 89 | |
| 90 // Returns a binary Pix mask with a 1 pixel for every pixel within the | |
| 91 // block. Rotates the coordinate system by rerotation prior to rendering. | |
| 92 // If not nullptr, mask_box is filled with the position box of the returned | |
| 93 // mask image. | |
| 94 Image render_mask(const FCOORD &rerotation, TBOX *mask_box); | |
| 95 | |
| 96 #ifndef GRAPHICS_DISABLED | |
| 97 /// draw histogram | |
| 98 ///@param window window to draw in | |
| 99 ///@param serial serial number | |
| 100 ///@param colour colour to draw in | |
| 101 void plot(ScrollView *window, int32_t serial, ScrollView::Color colour); | |
| 102 #endif // !GRAPHICS_DISABLED | |
| 103 | |
| 104 /// assignment | |
| 105 ///@param source from this | |
| 106 PDBLK &operator=(const PDBLK &source); | |
| 107 | |
| 108 protected: | |
| 109 POLY_BLOCK *hand_poly; ///< weird as well | |
| 110 ICOORDELT_LIST leftside; ///< left side vertices | |
| 111 ICOORDELT_LIST rightside; ///< right side vertices | |
| 112 TBOX box; ///< bounding box | |
| 113 int index_; ///< Serial number of this block. | |
| 114 }; | |
| 115 | |
| 116 class BLOCK_RECT_IT // rectangle iterator | |
| 117 { | |
| 118 public: | |
| 119 /// constructor | |
| 120 ///@param blkptr block to iterate | |
| 121 BLOCK_RECT_IT(PDBLK *blkptr); | |
| 122 | |
| 123 /// start (new) block | |
| 124 void set_to_block(PDBLK *blkptr); // block to iterate | |
| 125 | |
| 126 /// start iteration | |
| 127 void start_block(); | |
| 128 | |
| 129 /// next rectangle | |
| 130 void forward(); | |
| 131 | |
| 132 /// test end | |
| 133 bool cycled_rects() const { | |
| 134 return left_it.cycled_list() && right_it.cycled_list(); | |
| 135 } | |
| 136 | |
| 137 /// current rectangle | |
| 138 ///@param bleft bottom left | |
| 139 ///@param tright top right | |
| 140 void bounding_box(ICOORD &bleft, ICOORD &tright) { | |
| 141 // bottom left | |
| 142 bleft = ICOORD(left_it.data()->x(), ymin); | |
| 143 // top right | |
| 144 tright = ICOORD(right_it.data()->x(), ymax); | |
| 145 } | |
| 146 | |
| 147 private: | |
| 148 TDimension ymin = 0; ///< bottom of rectangle | |
| 149 TDimension ymax = 0; ///< top of rectangle | |
| 150 PDBLK *block = nullptr; ///< block to iterate | |
| 151 ICOORDELT_IT left_it; ///< boundary iterators | |
| 152 ICOORDELT_IT right_it; | |
| 153 }; | |
| 154 | |
| 155 /// rectangle iterator | |
| 156 class BLOCK_LINE_IT { | |
| 157 public: | |
| 158 /// constructor | |
| 159 ///@param blkptr from block | |
| 160 BLOCK_LINE_IT(PDBLK *blkptr) : rect_it(blkptr) { | |
| 161 block = blkptr; // remember block | |
| 162 } | |
| 163 | |
| 164 /// start (new) block | |
| 165 ///@param blkptr block to start | |
| 166 void set_to_block(PDBLK *blkptr) { | |
| 167 block = blkptr; // remember block | |
| 168 // set iterator | |
| 169 rect_it.set_to_block(blkptr); | |
| 170 } | |
| 171 | |
| 172 /// get a line | |
| 173 ///@param y line to get | |
| 174 ///@param xext output extent | |
| 175 TDimension get_line(TDimension y, TDimension &xext); | |
| 176 | |
| 177 private: | |
| 178 PDBLK *block; ///< block to iterate | |
| 179 BLOCK_RECT_IT rect_it; ///< rectangle iterator | |
| 180 }; | |
| 181 | |
| 182 } // namespace tesseract | |
| 183 | |
| 184 #endif |
