Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/wordrec/render.cpp @ 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 * | |
| 3 * File: render.cpp (Formerly render.c) | |
| 4 * Description: Convert the various data type into line lists | |
| 5 * Author: Mark Seaman, OCR Technology | |
| 6 * | |
| 7 * (c) Copyright 1989, Hewlett-Packard Company. | |
| 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 // Include automatically generated configuration file if running autoconf. | |
| 21 #ifdef HAVE_CONFIG_H | |
| 22 # include "config_auto.h" | |
| 23 #endif | |
| 24 | |
| 25 #include "render.h" | |
| 26 | |
| 27 #include "blobs.h" | |
| 28 | |
| 29 #include <cmath> | |
| 30 | |
| 31 namespace tesseract { | |
| 32 | |
| 33 /*---------------------------------------------------------------------- | |
| 34 V a r i a b l e s | |
| 35 ----------------------------------------------------------------------*/ | |
| 36 ScrollView *blob_window = nullptr; | |
| 37 | |
| 38 ScrollView::Color color_list[] = {ScrollView::RED, ScrollView::CYAN, ScrollView::YELLOW, | |
| 39 ScrollView::BLUE, ScrollView::GREEN, ScrollView::WHITE}; | |
| 40 | |
| 41 BOOL_VAR(wordrec_display_all_blobs, 0, "Display Blobs"); | |
| 42 | |
| 43 BOOL_VAR(wordrec_blob_pause, 0, "Blob pause"); | |
| 44 | |
| 45 /*---------------------------------------------------------------------- | |
| 46 F u n c t i o n s | |
| 47 ----------------------------------------------------------------------*/ | |
| 48 #ifndef GRAPHICS_DISABLED | |
| 49 /********************************************************************** | |
| 50 * display_blob | |
| 51 * | |
| 52 * Macro to display blob in a window. | |
| 53 **********************************************************************/ | |
| 54 void display_blob(TBLOB *blob, ScrollView::Color color) { | |
| 55 /* Size of drawable */ | |
| 56 if (blob_window == nullptr) { | |
| 57 blob_window = new ScrollView("Blobs", 520, 10, 500, 256, 2000, 256, true); | |
| 58 } else { | |
| 59 blob_window->Clear(); | |
| 60 } | |
| 61 | |
| 62 render_blob(blob_window, blob, color); | |
| 63 } | |
| 64 | |
| 65 /********************************************************************** | |
| 66 * render_blob | |
| 67 * | |
| 68 * Create a list of line segments that represent the expanded outline | |
| 69 * that was supplied as input. | |
| 70 **********************************************************************/ | |
| 71 void render_blob(ScrollView *window, TBLOB *blob, ScrollView::Color color) { | |
| 72 /* No outline */ | |
| 73 if (!blob) { | |
| 74 return; | |
| 75 } | |
| 76 | |
| 77 render_outline(window, blob->outlines, color); | |
| 78 } | |
| 79 | |
| 80 /********************************************************************** | |
| 81 * render_edgepts | |
| 82 * | |
| 83 * Create a list of line segments that represent the expanded outline | |
| 84 * that was supplied as input. | |
| 85 **********************************************************************/ | |
| 86 void render_edgepts(ScrollView *window, EDGEPT *edgept, ScrollView::Color color) { | |
| 87 if (!edgept) { | |
| 88 return; | |
| 89 } | |
| 90 | |
| 91 float x = edgept->pos.x; | |
| 92 float y = edgept->pos.y; | |
| 93 EDGEPT *this_edge = edgept; | |
| 94 | |
| 95 window->Pen(color); | |
| 96 window->SetCursor(x, y); | |
| 97 do { | |
| 98 this_edge = this_edge->next; | |
| 99 x = this_edge->pos.x; | |
| 100 y = this_edge->pos.y; | |
| 101 window->DrawTo(x, y); | |
| 102 } while (edgept != this_edge); | |
| 103 } | |
| 104 | |
| 105 /********************************************************************** | |
| 106 * render_outline | |
| 107 * | |
| 108 * Create a list of line segments that represent the expanded outline | |
| 109 * that was supplied as input. | |
| 110 **********************************************************************/ | |
| 111 void render_outline(ScrollView *window, TESSLINE *outline, ScrollView::Color color) { | |
| 112 /* No outline */ | |
| 113 if (!outline) { | |
| 114 return; | |
| 115 } | |
| 116 /* Draw Compact outline */ | |
| 117 if (outline->loop) { | |
| 118 render_edgepts(window, outline->loop, color); | |
| 119 } | |
| 120 /* Add on next outlines */ | |
| 121 render_outline(window, outline->next, color); | |
| 122 } | |
| 123 | |
| 124 #endif // !GRAPHICS_DISABLED | |
| 125 | |
| 126 } // namespace tesseract |
