Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
blread.cpp
Go to the documentation of this file.
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  * Created: Mon Mar 18 14:39:00 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 #include "mfcpch.h"
21 #include <stdlib.h>
22 #ifdef __UNIX__
23 #include <assert.h>
24 #endif
25 #include "scanutils.h"
26 #include "fileerr.h"
27 #include "blread.h"
28 
29 #define UNLV_EXT ".uzn" // unlv zone file
30 
31 /**********************************************************************
32  * read_unlv_file
33  *
34  * Read a whole unlv zone file to make a list of blocks.
35  **********************************************************************/
36 
37 bool read_unlv_file( //print list of sides
38  STRING name, //basename of file
39  inT32 xsize, //image size
40  inT32 ysize, //image size
41  BLOCK_LIST *blocks //output list
42  ) {
43  FILE *pdfp; //file pointer
44  BLOCK *block; //current block
45  int x; //current top-down coords
46  int y;
47  int width; //of current block
48  int height;
49  BLOCK_IT block_it = blocks; //block iterator
50 
51  name += UNLV_EXT; //add extension
52  if ((pdfp = fopen (name.string (), "rb")) == NULL) {
53  return false; //didn't read one
54  }
55  else {
56  while (fscanf (pdfp, "%d %d %d %d %*s", &x, &y, &width, &height) >= 4) {
57  //make rect block
58  block = new BLOCK (name.string (), TRUE, 0, 0,
59  (inT16) x, (inT16) (ysize - y - height),
60  (inT16) (x + width), (inT16) (ysize - y));
61  //on end of list
62  block_it.add_to_end (block);
63  }
64  fclose(pdfp);
65  }
66  return true;
67 }
68 
69 void FullPageBlock(int width, int height, BLOCK_LIST *blocks) {
70  BLOCK_IT block_it(blocks);
71  BLOCK* block = new BLOCK("", TRUE, 0, 0, 0, 0, width, height);
72  block_it.add_to_end(block);
73 }