Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/ccstruct/blread.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 * File: blread.cpp (Formerly pdread.c) | |
| 3 * Description: Friend function of BLOCK to read the uscan pd file. | |
| 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 #include "blread.h" | |
| 20 | |
| 21 #include "ocrblock.h" // for BLOCK_IT, BLOCK, BLOCK_LIST (ptr only) | |
| 22 #include "scanutils.h" // for tfscanf | |
| 23 | |
| 24 #include <cstdio> // for fclose, fopen, FILE | |
| 25 | |
| 26 namespace tesseract { | |
| 27 | |
| 28 #define UNLV_EXT ".uzn" // unlv zone file | |
| 29 | |
| 30 /********************************************************************** | |
| 31 * read_unlv_file | |
| 32 * | |
| 33 * Read a whole unlv zone file to make a list of blocks. | |
| 34 **********************************************************************/ | |
| 35 | |
| 36 bool read_unlv_file( // print list of sides | |
| 37 std::string &name, // basename of file | |
| 38 int32_t xsize, // image size | |
| 39 int32_t ysize, // image size | |
| 40 BLOCK_LIST *blocks // output list | |
| 41 ) { | |
| 42 FILE *pdfp; // file pointer | |
| 43 BLOCK *block; // current block | |
| 44 int x; // current top-down coords | |
| 45 int y; | |
| 46 int width; // of current block | |
| 47 int height; | |
| 48 BLOCK_IT block_it = blocks; // block iterator | |
| 49 | |
| 50 name += UNLV_EXT; // add extension | |
| 51 if ((pdfp = fopen(name.c_str(), "rb")) == nullptr) { | |
| 52 return false; // didn't read one | |
| 53 } else { | |
| 54 while (tfscanf(pdfp, "%d %d %d %d %*s", &x, &y, &width, &height) >= 4) { | |
| 55 // make rect block | |
| 56 block = new BLOCK(name.c_str(), true, 0, 0, static_cast<int16_t>(x), | |
| 57 static_cast<int16_t>(ysize - y - height), static_cast<int16_t>(x + width), | |
| 58 static_cast<int16_t>(ysize - y)); | |
| 59 // on end of list | |
| 60 block_it.add_to_end(block); | |
| 61 } | |
| 62 fclose(pdfp); | |
| 63 } | |
| 64 tprintf("UZN file %s loaded.\n", name.c_str()); | |
| 65 return true; | |
| 66 } | |
| 67 | |
| 68 void FullPageBlock(int width, int height, BLOCK_LIST *blocks) { | |
| 69 BLOCK_IT block_it(blocks); | |
| 70 auto *block = new BLOCK("", true, 0, 0, 0, 0, width, height); | |
| 71 block_it.add_to_end(block); | |
| 72 } | |
| 73 | |
| 74 } // namespace tesseract |
