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 00025 // Size of buffer used to read a line from a box file. 00026 const int kBoxReadBufSize = 256; 00027 00028 // read_next_box factors out the code to interpret a line of a box 00029 // file so that applybox and unicharset_extractor interpret the same way. 00030 // This function returns the next valid box file utf8 string and coords 00031 // and returns true, or false on eof (and closes the file). 00032 // If ignores the uft8 file signature, checks for valid utf-8 and allows 00033 // space or tab between fields. 00034 // utf8_str must be at least kBoxReadBufSize in length. 00035 // If there are page numbers in the file, it reads them all. 00036 bool read_next_box(FILE* box_file, char* utf8_str, 00037 int* x_min, int* y_min, int* x_max, int* y_max); 00038 // As read_next_box above, but get a specific page number. (0-based) 00039 // Use -1 to read any page number. Files without page number all 00040 // read as if they are page 0. 00041 bool read_next_box(int page, FILE* box_file, char* utf8_str, 00042 int* x_min, int* y_min, int* x_max, int* y_max); 00043 00044 #endif // TESSERACT_CCUTIL_BOXREAD_H__