Tesseract  3.02
tesseract-ocr/ccstruct/boxread.h
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        boxread.cpp
00003  * Description: Read data from a box file.
00004  * Author:              Ray Smith
00005  * Created:             Fri Aug 24 17:47:23 PDT 2007
00006  *
00007  * (C) Copyright 2007, Google Inc.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  *
00018  **********************************************************************/
00019 
00020 #ifndef TESSERACT_CCUTIL_BOXREAD_H__
00021 #define TESSERACT_CCUTIL_BOXREAD_H__
00022 
00023 #include <stdio.h>
00024 #include "strngs.h"
00025 
00026 class STRING;
00027 class TBOX;
00028 
00029 // Size of buffer used to read a line from a box file.
00030 const int kBoxReadBufSize = 1024;
00031 
00032 // Open the boxfile based on the given image filename.
00033 FILE* OpenBoxFile(const STRING& fname);
00034 
00035 // ReadNextBox factors out the code to interpret a line of a box
00036 // file so that applybox and unicharset_extractor interpret the same way.
00037 // This function returns the next valid box file utf8 string and coords
00038 // and returns true, or false on eof (and closes the file).
00039 // It ignores the utf8 file signature ByteOrderMark (U+FEFF=EF BB BF), checks
00040 // for valid utf-8 and allows space or tab between fields.
00041 // utf8_str is set with the unichar string, and bounding box with the box.
00042 // If there are page numbers in the file, it reads them all.
00043 bool ReadNextBox(int *line_number, FILE* box_file,
00044                  STRING* utf8_str, TBOX* bounding_box);
00045 // As ReadNextBox above, but get a specific page number. (0-based)
00046 // Use -1 to read any page number. Files without page number all
00047 // read as if they are page 0.
00048 bool ReadNextBox(int target_page, int *line_number, FILE* box_file,
00049                  STRING* utf8_str, TBOX* bounding_box);
00050 
00051 // Parses the given box file string into a page_number, utf8_str, and
00052 // bounding_box. Returns true on a successful parse.
00053 bool ParseBoxFileStr(const char* boxfile_str, int* page_number,
00054                      STRING* utf8_str, TBOX* bounding_box);
00055 
00056 // Creates a box file string from a unichar string, TBOX and page number.
00057 void MakeBoxFileStr(const char* unichar_str, const TBOX& box, int page_num,
00058                     STRING* box_str);
00059 
00060 #endif  // TESSERACT_CCUTIL_BOXREAD_H__