mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-30 23:49:05 +08:00
Merge pull request #896 from rfschtkt/toomanywarnings
Too many warnings!
This commit is contained in:
commit
2b373d1cca
@ -670,7 +670,7 @@ bool TessPDFRenderer::BeginDocumentHandler() {
|
||||
long int size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
const std::unique_ptr</*non-const*/ char[]> buffer(new char[size]);
|
||||
if (fread(buffer.get(), 1, size, fp) != size) {
|
||||
if (fread(buffer.get(), 1, size, fp) != static_cast<unsigned long>(size)) {
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
@ -945,7 +945,7 @@ bool TessPDFRenderer::EndDocumentHandler() {
|
||||
if (n >= sizeof(buf)) return false;
|
||||
AppendString(buf);
|
||||
size_t pages_objsize = strlen(buf);
|
||||
for (size_t i = 0; i < pages_.size(); i++) {
|
||||
for (size_t i = 0; i < pages_.unsigned_size(); i++) {
|
||||
n = snprintf(buf, sizeof(buf),
|
||||
"%ld 0 R ", pages_[i]);
|
||||
if (n >= sizeof(buf)) return false;
|
||||
|
@ -513,7 +513,7 @@ BOOL8 Tesseract::terrible_word_crunch(WERD_RES *word,
|
||||
|
||||
if ((word->best_choice->unichar_string().length () == 0) ||
|
||||
(strspn (word->best_choice->unichar_string().string(), " ") ==
|
||||
word->best_choice->unichar_string().length ()))
|
||||
word->best_choice->unichar_string().unsigned_size ()))
|
||||
crunch_mode = 1;
|
||||
else {
|
||||
adjusted_len = word->reject_map.length ();
|
||||
|
@ -72,6 +72,12 @@ class GenericVector {
|
||||
int size() const {
|
||||
return size_used_;
|
||||
}
|
||||
// Workaround to avoid g++ -Wsign-compare warnings.
|
||||
unsigned int unsigned_size() const {
|
||||
static_assert(sizeof(size_used_) <= sizeof(unsigned int), "");
|
||||
assert(0 <= size_used_);
|
||||
return static_cast<unsigned int>(size_used_);
|
||||
}
|
||||
int size_reserved() const {
|
||||
return size_reserved_;
|
||||
}
|
||||
@ -880,7 +886,7 @@ bool GenericVector<T>::write(
|
||||
}
|
||||
delete cb;
|
||||
} else {
|
||||
if (fwrite(data_, sizeof(T), size_used_, f) != size_used_) return false;
|
||||
if (fwrite(data_, sizeof(T), size_used_, f) != unsigned_size()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -912,7 +918,7 @@ bool GenericVector<T>::read(
|
||||
template <typename T>
|
||||
bool GenericVector<T>::Serialize(FILE* fp) const {
|
||||
if (fwrite(&size_used_, sizeof(size_used_), 1, fp) != 1) return false;
|
||||
if (fwrite(data_, sizeof(*data_), size_used_, fp) != size_used_) return false;
|
||||
if (fwrite(data_, sizeof(*data_), size_used_, fp) != unsigned_size()) return false;
|
||||
return true;
|
||||
}
|
||||
template <typename T>
|
||||
@ -933,7 +939,7 @@ bool GenericVector<T>::DeSerialize(bool swap, FILE* fp) {
|
||||
if (swap) Reverse32(&reserved);
|
||||
reserve(reserved);
|
||||
size_used_ = reserved;
|
||||
if (fread(data_, sizeof(T), size_used_, fp) != size_used_) return false;
|
||||
if (fread(data_, sizeof(T), size_used_, fp) != unsigned_size()) return false;
|
||||
if (swap) {
|
||||
for (int i = 0; i < size_used_; ++i)
|
||||
ReverseN(&data_[i], sizeof(data_[i]));
|
||||
@ -982,7 +988,7 @@ bool GenericVector<T>::SerializeClasses(tesseract::TFile* fp) const {
|
||||
// If swap is true, assumes a big/little-endian swap is needed.
|
||||
template <typename T>
|
||||
bool GenericVector<T>::DeSerializeClasses(bool swap, FILE* fp) {
|
||||
uinT32 reserved;
|
||||
inT32 reserved;
|
||||
if (fread(&reserved, sizeof(reserved), 1, fp) != 1) return false;
|
||||
if (swap) Reverse32(&reserved);
|
||||
T empty;
|
||||
@ -994,7 +1000,7 @@ bool GenericVector<T>::DeSerializeClasses(bool swap, FILE* fp) {
|
||||
}
|
||||
template <typename T>
|
||||
bool GenericVector<T>::DeSerializeClasses(tesseract::TFile* fp) {
|
||||
uinT32 reserved;
|
||||
inT32 reserved;
|
||||
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) return false;
|
||||
T empty;
|
||||
init_to_size(reserved, empty);
|
||||
@ -1005,7 +1011,7 @@ bool GenericVector<T>::DeSerializeClasses(tesseract::TFile* fp) {
|
||||
}
|
||||
template <typename T>
|
||||
bool GenericVector<T>::SkipDeSerializeClasses(tesseract::TFile* fp) {
|
||||
uinT32 reserved;
|
||||
inT32 reserved;
|
||||
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) return false;
|
||||
for (int i = 0; i < reserved; ++i) {
|
||||
if (!T::SkipDeSerialize(fp)) return false;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#ifndef STRNGS_H
|
||||
#define STRNGS_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "platform.h"
|
||||
@ -66,6 +67,12 @@ class TESS_API STRING
|
||||
BOOL8 contains(const char c) const;
|
||||
inT32 length() const;
|
||||
inT32 size() const { return length(); }
|
||||
// Workaround to avoid g++ -Wsign-compare warnings.
|
||||
uinT32 unsigned_size() const {
|
||||
const inT32 len = length();
|
||||
assert(0 <= len);
|
||||
return static_cast<uinT32>(len);
|
||||
}
|
||||
const char *string() const;
|
||||
const char *c_str() const;
|
||||
|
||||
|
@ -97,7 +97,7 @@ void Classify::LearnBlob(const STRING& fontname, TBLOB* blob,
|
||||
bool Classify::WriteTRFile(const STRING& filename) {
|
||||
STRING tr_filename = filename + ".tr";
|
||||
FILE* fp = Efopen(tr_filename.string(), "wb");
|
||||
int len = tr_file_data_.length();
|
||||
size_t len = tr_file_data_.length();
|
||||
bool result =
|
||||
fwrite(&tr_file_data_[0], sizeof(tr_file_data_[0]), len, fp) == len;
|
||||
fclose(fp);
|
||||
|
@ -139,10 +139,8 @@ void InitFeatureDefs(FEATURE_DEFS_STRUCT *featuredefs) {
|
||||
* @note History: Wed May 23 13:52:19 1990, DSJ, Created.
|
||||
*/
|
||||
void FreeCharDescription(CHAR_DESC CharDesc) {
|
||||
int i;
|
||||
|
||||
if (CharDesc) {
|
||||
for (i = 0; i < CharDesc->NumFeatureSets; i++)
|
||||
for (size_t i = 0; i < CharDesc->NumFeatureSets; i++)
|
||||
FreeFeatureSet (CharDesc->FeatureSets[i]);
|
||||
Efree(CharDesc);
|
||||
}
|
||||
@ -163,12 +161,10 @@ void FreeCharDescription(CHAR_DESC CharDesc) {
|
||||
*/
|
||||
CHAR_DESC NewCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs) {
|
||||
CHAR_DESC CharDesc;
|
||||
int i;
|
||||
|
||||
CharDesc = (CHAR_DESC) Emalloc (sizeof (CHAR_DESC_STRUCT));
|
||||
CharDesc->NumFeatureSets = FeatureDefs.NumFeatureTypes;
|
||||
|
||||
for (i = 0; i < CharDesc->NumFeatureSets; i++)
|
||||
for (size_t i = 0; i < CharDesc->NumFeatureSets; i++)
|
||||
CharDesc->FeatureSets[i] = NULL;
|
||||
|
||||
return (CharDesc);
|
||||
@ -196,16 +192,15 @@ CHAR_DESC NewCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs) {
|
||||
*/
|
||||
void WriteCharDescription(const FEATURE_DEFS_STRUCT& FeatureDefs,
|
||||
CHAR_DESC CharDesc, STRING* str) {
|
||||
int Type;
|
||||
int NumSetsToWrite = 0;
|
||||
|
||||
for (Type = 0; Type < CharDesc->NumFeatureSets; Type++)
|
||||
for (size_t Type = 0; Type < CharDesc->NumFeatureSets; Type++)
|
||||
if (CharDesc->FeatureSets[Type])
|
||||
NumSetsToWrite++;
|
||||
|
||||
str->add_str_int(" ", NumSetsToWrite);
|
||||
*str += "\n";
|
||||
for (Type = 0; Type < CharDesc->NumFeatureSets; Type++) {
|
||||
for (size_t Type = 0; Type < CharDesc->NumFeatureSets; Type++) {
|
||||
if (CharDesc->FeatureSets[Type]) {
|
||||
*str += FeatureDefs.FeatureDesc[Type]->ShortName;
|
||||
*str += " ";
|
||||
@ -220,7 +215,7 @@ bool ValidCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs,
|
||||
CHAR_DESC CharDesc) {
|
||||
bool anything_written = false;
|
||||
bool well_formed = true;
|
||||
for (int Type = 0; Type < CharDesc->NumFeatureSets; Type++) {
|
||||
for (size_t Type = 0; Type < CharDesc->NumFeatureSets; Type++) {
|
||||
if (CharDesc->FeatureSets[Type]) {
|
||||
for (int i = 0; i < CharDesc->FeatureSets[Type]->NumFeatures; i++) {
|
||||
FEATURE feat = CharDesc->FeatureSets[Type]->Features[i];
|
||||
|
@ -184,7 +184,7 @@ void NetworkIO::FromPixes(const StaticShape& shape,
|
||||
stride_map_.SetStride(h_w_pairs);
|
||||
ResizeToMap(int_mode(), stride_map_, shape.depth());
|
||||
// Iterate over the images again to copy the data.
|
||||
for (int b = 0; b < pixes.size(); ++b) {
|
||||
for (size_t b = 0; b < pixes.size(); ++b) {
|
||||
Pix* pix = const_cast<Pix*>(pixes[b]);
|
||||
float black = 0.0f, white = 255.0f;
|
||||
if (shape.depth() != 3) ComputeBlackWhite(pix, &black, &white);
|
||||
|
@ -43,7 +43,8 @@ bool StrideMap::Index::IsLast(FlexDimensions dimension) const {
|
||||
int StrideMap::Index::MaxIndexOfDim(FlexDimensions dim) const {
|
||||
int max_index = stride_map_->shape_[dim] - 1;
|
||||
if (dim == FD_BATCH) return max_index;
|
||||
int batch = indices_[FD_BATCH];
|
||||
assert(0 <= indices_[FD_BATCH]);
|
||||
const size_t batch = indices_[FD_BATCH];
|
||||
if (dim == FD_HEIGHT) {
|
||||
if (batch >= stride_map_->heights_.size() ||
|
||||
stride_map_->heights_[batch] > max_index)
|
||||
|
@ -285,6 +285,8 @@ void Textord::TextordPage(PageSegMode pageseg_mode, const FCOORD& reskew,
|
||||
// RAW_LINE, SINGLE_LINE, SINGLE_WORD and SINGLE_CHAR all need a single row.
|
||||
gradient = make_single_row(page_tr_, pageseg_mode != PSM_RAW_LINE,
|
||||
to_block, to_blocks);
|
||||
} else {
|
||||
gradient = 0.0f;
|
||||
}
|
||||
BaselineDetect baseline_detector(textord_baseline_debug,
|
||||
reskew, to_blocks);
|
||||
|
@ -51,7 +51,7 @@ void BoxChar::AddBox(int x, int y, int width, int height) {
|
||||
/* static */
|
||||
void BoxChar::TranslateBoxes(int xshift, int yshift,
|
||||
std::vector<BoxChar*>* boxes) {
|
||||
for (int i = 0; i < boxes->size(); ++i) {
|
||||
for (size_t i = 0; i < boxes->size(); ++i) {
|
||||
BOX* box = (*boxes)[i]->box_;
|
||||
if (box != nullptr) {
|
||||
box->x += xshift;
|
||||
@ -68,8 +68,8 @@ void BoxChar::PrepareToWrite(std::vector<BoxChar*>* boxes) {
|
||||
bool vertical_rules = MostlyVertical(*boxes);
|
||||
InsertNewlines(rtl_rules, vertical_rules, boxes);
|
||||
InsertSpaces(rtl_rules, vertical_rules, boxes);
|
||||
for (int i = 0; i < boxes->size(); ++i) {
|
||||
if ((*boxes)[i]->box_ == nullptr) tprintf("Null box at index %d\n", i);
|
||||
for (unsigned int i = 0; i < boxes->size(); ++i) {
|
||||
if ((*boxes)[i]->box_ == nullptr) tprintf("Null box at index %u\n", i);
|
||||
}
|
||||
if (rtl_rules) {
|
||||
ReorderRTLText(boxes);
|
||||
@ -82,16 +82,16 @@ void BoxChar::InsertNewlines(bool rtl_rules, bool vertical_rules,
|
||||
std::vector<BoxChar*>* boxes) {
|
||||
int prev_i = -1;
|
||||
int max_shift = 0;
|
||||
for (int i = 0; i < boxes->size(); ++i) {
|
||||
for (int i = 0; static_cast<unsigned int>(i) < boxes->size(); ++i) {
|
||||
Box* box = (*boxes)[i]->box_;
|
||||
if (box == nullptr) {
|
||||
if (prev_i < 0 || prev_i < i - 1 || i + 1 == boxes->size()) {
|
||||
if (prev_i < 0 || prev_i < i - 1 || static_cast<unsigned int>(i) + 1 == boxes->size()) {
|
||||
// Erase null boxes at the start of a line and after another null box.
|
||||
do {
|
||||
delete (*boxes)[i];
|
||||
boxes->erase(boxes->begin() + i);
|
||||
--i;
|
||||
} while (i >= 0 && i + 1 == boxes->size() &&
|
||||
} while (i >= 0 && static_cast<unsigned int>(i) + 1 == boxes->size() &&
|
||||
(*boxes)[i]->box_ == nullptr);
|
||||
}
|
||||
continue;
|
||||
@ -146,7 +146,7 @@ void BoxChar::InsertSpaces(bool rtl_rules, bool vertical_rules,
|
||||
std::vector<BoxChar*>* boxes) {
|
||||
// After InsertNewlines, any remaining null boxes are not newlines, and are
|
||||
// singletons, so add a box to each remaining null box.
|
||||
for (int i = 1; i + 1 < boxes->size(); ++i) {
|
||||
for (int i = 1; static_cast<unsigned int>(i) + 1 < boxes->size(); ++i) {
|
||||
Box* box = (*boxes)[i]->box_;
|
||||
if (box == nullptr) {
|
||||
Box* prev = (*boxes)[i - 1]->box_;
|
||||
@ -178,8 +178,8 @@ void BoxChar::InsertSpaces(bool rtl_rules, bool vertical_rules,
|
||||
}
|
||||
// Left becomes the max right of all next boxes forward to the first
|
||||
// space or newline.
|
||||
for (int j = i + 2; j < boxes->size() && (*boxes)[j]->box_ != nullptr &&
|
||||
(*boxes)[j]->ch_ != "\t";
|
||||
for (size_t j = i + 2; j < boxes->size() && (*boxes)[j]->box_ != nullptr &&
|
||||
(*boxes)[j]->ch_ != "\t";
|
||||
++j) {
|
||||
next = (*boxes)[j]->box_;
|
||||
if (next->x + next->w > left) {
|
||||
@ -203,8 +203,8 @@ void BoxChar::ReorderRTLText(std::vector<BoxChar*>* boxes) {
|
||||
// After adding newlines and spaces, this task is simply a matter of sorting
|
||||
// by left each group of boxes between newlines.
|
||||
BoxCharPtrSort sorter;
|
||||
int end = 0;
|
||||
for (int start = 0; start < boxes->size(); start = end + 1) {
|
||||
size_t end = 0;
|
||||
for (size_t start = 0; start < boxes->size(); start = end + 1) {
|
||||
end = start + 1;
|
||||
while (end < boxes->size() && (*boxes)[end]->ch_ != "\t") ++end;
|
||||
std::sort(boxes->begin() + start, boxes->begin() + end, sorter);
|
||||
@ -215,13 +215,13 @@ void BoxChar::ReorderRTLText(std::vector<BoxChar*>* boxes) {
|
||||
/* static */
|
||||
bool BoxChar::ContainsMostlyRTL(const std::vector<BoxChar*>& boxes) {
|
||||
int num_rtl = 0, num_ltr = 0;
|
||||
for (int i = 0; i < boxes.size(); ++i) {
|
||||
for (unsigned int i = 0; i < boxes.size(); ++i) {
|
||||
// Convert the unichar to UTF32 representation
|
||||
GenericVector<char32> uni_vector;
|
||||
if (!UNICHAR::UTF8ToUnicode(boxes[i]->ch_.c_str(), &uni_vector)) {
|
||||
tprintf("Illegal utf8 in boxchar %d string:%s = ", i,
|
||||
tprintf("Illegal utf8 in boxchar %u string:%s = ", i,
|
||||
boxes[i]->ch_.c_str());
|
||||
for (int c = 0; c < boxes[i]->ch_.size(); ++c) {
|
||||
for (size_t c = 0; c < boxes[i]->ch_.size(); ++c) {
|
||||
tprintf(" 0x%x", boxes[i]->ch_[c]);
|
||||
}
|
||||
tprintf("\n");
|
||||
@ -244,7 +244,7 @@ bool BoxChar::ContainsMostlyRTL(const std::vector<BoxChar*>& boxes) {
|
||||
/* static */
|
||||
bool BoxChar::MostlyVertical(const std::vector<BoxChar*>& boxes) {
|
||||
inT64 total_dx = 0, total_dy = 0;
|
||||
for (int i = 1; i < boxes.size(); ++i) {
|
||||
for (size_t i = 1; i < boxes.size(); ++i) {
|
||||
if (boxes[i - 1]->box_ != nullptr && boxes[i]->box_ != nullptr &&
|
||||
boxes[i - 1]->page_ == boxes[i]->page_) {
|
||||
int dx = boxes[i]->box_->x - boxes[i - 1]->box_->x;
|
||||
@ -263,7 +263,7 @@ bool BoxChar::MostlyVertical(const std::vector<BoxChar*>& boxes) {
|
||||
/* static */
|
||||
int BoxChar::TotalByteLength(const std::vector<BoxChar*>& boxes) {
|
||||
int total_length = 0;
|
||||
for (int i = 0; i < boxes.size(); ++i) total_length += boxes[i]->ch_.size();
|
||||
for (size_t i = 0; i < boxes.size(); ++i) total_length += boxes[i]->ch_.size();
|
||||
return total_length;
|
||||
}
|
||||
|
||||
@ -302,7 +302,7 @@ string BoxChar::GetTesseractBoxStr(int height,
|
||||
const std::vector<BoxChar*>& boxes) {
|
||||
string output;
|
||||
char buffer[kMaxLineLength];
|
||||
for (int i = 0; i < boxes.size(); ++i) {
|
||||
for (size_t i = 0; i < boxes.size(); ++i) {
|
||||
const Box* box = boxes[i]->box_;
|
||||
if (box == nullptr) {
|
||||
tprintf("Error: Call PrepareToWrite before WriteTesseractBoxFile!!\n");
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "tprintf.h"
|
||||
#include "unicity_table.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
using tesseract::CCUtil;
|
||||
@ -368,8 +369,9 @@ void ReadTrainingSamples(const FEATURE_DEFS_STRUCT& feature_defs,
|
||||
LABELEDLIST char_sample;
|
||||
FEATURE_SET feature_samples;
|
||||
CHAR_DESC char_desc;
|
||||
int i;
|
||||
int feature_type = ShortNameToFeatureType(feature_defs, feature_name);
|
||||
int ShortNameToFeatureType_res = ShortNameToFeatureType(feature_defs, feature_name);
|
||||
assert(0 <= ShortNameToFeatureType_res);
|
||||
unsigned int feature_type = static_cast<unsigned int>(ShortNameToFeatureType_res);
|
||||
// Zero out the font_sample_count for all the classes.
|
||||
LIST it = *training_samples;
|
||||
iterate(it) {
|
||||
@ -404,7 +406,7 @@ void ReadTrainingSamples(const FEATURE_DEFS_STRUCT& feature_defs,
|
||||
} else {
|
||||
FreeFeatureSet(feature_samples);
|
||||
}
|
||||
for (i = 0; i < char_desc->NumFeatureSets; i++) {
|
||||
for (size_t i = 0; i < char_desc->NumFeatureSets; i++) {
|
||||
if (feature_type != i)
|
||||
FreeFeatureSet(char_desc->FeatureSets[i]);
|
||||
}
|
||||
|
@ -173,10 +173,6 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool best_dumped = true;
|
||||
char* best_model_dump = nullptr;
|
||||
size_t best_model_size = 0;
|
||||
STRING best_model_name;
|
||||
tesseract::LSTMTester tester(static_cast<inT64>(FLAGS_max_image_MB) *
|
||||
1048576);
|
||||
tesseract::TestCallback tester_callback = nullptr;
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "normstrngs.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include "icuerrorcode.h"
|
||||
#include "unichar.h"
|
||||
#include "unicode/normalizer2.h" // From libicu
|
||||
@ -181,7 +182,13 @@ bool IsWhitespace(const char32 ch) {
|
||||
}
|
||||
|
||||
bool IsUTF8Whitespace(const char* text) {
|
||||
#if 0 // intent
|
||||
return SpanUTF8Whitespace(text) == strlen(text);
|
||||
#else // avoiding g++ -Wsign-compare warning
|
||||
const int res = SpanUTF8Whitespace(text);
|
||||
assert(0 <= res);
|
||||
return static_cast<unsigned int>(res) == strlen(text);
|
||||
#endif
|
||||
}
|
||||
|
||||
int SpanUTF8Whitespace(const char* text) {
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "stringrenderer.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
@ -241,7 +242,7 @@ void StringRenderer::SetWordUnderlineAttributes(const string& page_text) {
|
||||
PangoAttrList* attr_list = pango_layout_get_attributes(layout_);
|
||||
|
||||
const char* text = page_text.c_str();
|
||||
int offset = 0;
|
||||
size_t offset = 0;
|
||||
TRand rand;
|
||||
bool started_underline = false;
|
||||
PangoAttribute* und_attr = nullptr;
|
||||
@ -341,7 +342,7 @@ void StringRenderer::RotatePageBoxes(float rotation) {
|
||||
|
||||
|
||||
void StringRenderer::ClearBoxes() {
|
||||
for (int i = 0; i < boxchars_.size(); ++i)
|
||||
for (size_t i = 0; i < boxchars_.size(); ++i)
|
||||
delete boxchars_[i];
|
||||
boxchars_.clear();
|
||||
boxaDestroy(&page_boxes_);
|
||||
@ -416,7 +417,7 @@ bool StringRenderer::GetClusterStrings(std::vector<string>* cluster_text) {
|
||||
static void MergeBoxCharsToWords(std::vector<BoxChar*>* boxchars) {
|
||||
std::vector<BoxChar*> result;
|
||||
bool started_word = false;
|
||||
for (int i = 0; i < boxchars->size(); ++i) {
|
||||
for (size_t i = 0; i < boxchars->size(); ++i) {
|
||||
if (boxchars->at(i)->ch() == " " || boxchars->at(i)->box() == nullptr) {
|
||||
result.push_back(boxchars->at(i));
|
||||
boxchars->at(i) = nullptr;
|
||||
@ -480,7 +481,7 @@ void StringRenderer::ComputeClusterBoxes() {
|
||||
// Sort the indices and create a map from start to end indices.
|
||||
std::sort(cluster_start_indices.begin(), cluster_start_indices.end());
|
||||
std::map<int, int> cluster_start_to_end_index;
|
||||
for (int i = 0; i < cluster_start_indices.size() - 1; ++i) {
|
||||
for (size_t i = 0; i + 1 < cluster_start_indices.size(); ++i) {
|
||||
cluster_start_to_end_index[cluster_start_indices[i]]
|
||||
= cluster_start_indices[i + 1];
|
||||
}
|
||||
@ -592,7 +593,7 @@ void StringRenderer::ComputeClusterBoxes() {
|
||||
// Compute the page bounding box
|
||||
Box* page_box = nullptr;
|
||||
Boxa* all_boxes = nullptr;
|
||||
for (int i = 0; i < page_boxchars.size(); ++i) {
|
||||
for (size_t i = 0; i < page_boxchars.size(); ++i) {
|
||||
if (page_boxchars[i]->box() == nullptr) continue;
|
||||
if (all_boxes == nullptr) all_boxes = boxaCreate(0);
|
||||
boxaAddBox(all_boxes, page_boxchars[i]->mutable_box(), L_CLONE);
|
||||
@ -622,7 +623,7 @@ void StringRenderer::CorrectBoxPositionsToLayout(
|
||||
int StringRenderer::StripUnrenderableWords(string* utf8_text) const {
|
||||
string output_text;
|
||||
const char* text = utf8_text->c_str();
|
||||
int offset = 0;
|
||||
size_t offset = 0;
|
||||
int num_dropped = 0;
|
||||
while (offset < utf8_text->length()) {
|
||||
int space_len = SpanUTF8Whitespace(text + offset);
|
||||
@ -866,7 +867,8 @@ int StringRenderer::RenderAllFontsToImage(double min_coverage,
|
||||
tprintf("Total chars = %d\n", total_chars_);
|
||||
}
|
||||
const std::vector<string>& all_fonts = FontUtils::ListAvailableFonts();
|
||||
for (int i = font_index_; i < all_fonts.size(); ++i) {
|
||||
assert(0 <= font_index_);
|
||||
for (unsigned int i = static_cast<unsigned int>(font_index_); i < all_fonts.size(); ++i) {
|
||||
++font_index_;
|
||||
int raw_score = 0;
|
||||
int ok_chars =
|
||||
|
@ -190,14 +190,12 @@ static bool IsWhitespaceBox(const BoxChar* boxchar) {
|
||||
static string StringReplace(const string& in,
|
||||
const string& oldsub, const string& newsub) {
|
||||
string out;
|
||||
int start_pos = 0;
|
||||
do {
|
||||
int pos = in.find(oldsub, start_pos);
|
||||
if (pos == string::npos) break;
|
||||
size_t start_pos = 0, pos;
|
||||
while ((pos = in.find(oldsub, start_pos)) != string::npos) {
|
||||
out.append(in.data() + start_pos, pos - start_pos);
|
||||
out.append(newsub.data(), newsub.length());
|
||||
start_pos = pos + oldsub.length();
|
||||
} while (true);
|
||||
}
|
||||
out.append(in.data() + start_pos, in.length() - start_pos);
|
||||
return out;
|
||||
}
|
||||
@ -239,7 +237,7 @@ void ExtractFontProperties(const string &utf8_text,
|
||||
offset -= boxes[boxes.size() - 1]->ch().size();
|
||||
}
|
||||
|
||||
for (int b = 0; b < boxes.size(); b += 2) {
|
||||
for (size_t b = 0; b < boxes.size(); b += 2) {
|
||||
while (b < boxes.size() && IsWhitespaceBox(boxes[b])) ++b;
|
||||
if (b + 1 >= boxes.size()) break;
|
||||
const string &ch0 = boxes[b]->ch();
|
||||
@ -422,8 +420,8 @@ int main(int argc, char** argv) {
|
||||
|
||||
if (FLAGS_list_available_fonts) {
|
||||
const std::vector<string>& all_fonts = FontUtils::ListAvailableFonts();
|
||||
for (int i = 0; i < all_fonts.size(); ++i) {
|
||||
printf("%3d: %s\n", i, all_fonts[i].c_str());
|
||||
for (unsigned int i = 0; i < all_fonts.size(); ++i) {
|
||||
printf("%3u: %s\n", i, all_fonts[i].c_str());
|
||||
ASSERT_HOST_MSG(FontUtils::IsAvailableFont(all_fonts[i].c_str()),
|
||||
"Font %s is unrecognized.\n", all_fonts[i].c_str());
|
||||
}
|
||||
@ -517,10 +515,10 @@ int main(int argc, char** argv) {
|
||||
// Try to preserve behavior of old text2image by expanding inter-word
|
||||
// spaces by a factor of 4.
|
||||
const string kSeparator = FLAGS_render_ngrams ? " " : " ";
|
||||
// Also restrict the number of charactes per line to try and avoid
|
||||
// Also restrict the number of characters per line to try and avoid
|
||||
// line-breaking in the middle of words like "-A", "R$" etc. which are
|
||||
// otherwise allowed by the standard unicode line-breaking rules.
|
||||
const int kCharsPerLine = (FLAGS_ptsize > 20) ? 50 : 100;
|
||||
const unsigned int kCharsPerLine = (FLAGS_ptsize > 20) ? 50 : 100;
|
||||
string rand_utf8;
|
||||
UNICHARSET unicharset;
|
||||
if (FLAGS_render_ngrams && !FLAGS_unicharset_file.empty() &&
|
||||
@ -547,7 +545,7 @@ int main(int argc, char** argv) {
|
||||
if (FLAGS_render_ngrams)
|
||||
std::random_shuffle(offsets.begin(), offsets.end());
|
||||
|
||||
for (int i = 0, line = 1; i < offsets.size(); ++i) {
|
||||
for (size_t i = 0, line = 1; i < offsets.size(); ++i) {
|
||||
const char *curr_pos = str8 + offsets[i].first;
|
||||
int ngram_len = offsets[i].second;
|
||||
// Skip words that contain characters not in found in unicharset.
|
||||
@ -588,7 +586,7 @@ int main(int argc, char** argv) {
|
||||
for (int pass = 0; pass < num_pass; ++pass) {
|
||||
int page_num = 0;
|
||||
string font_used;
|
||||
for (int offset = 0; offset < strlen(to_render_utf8); ++im, ++page_num) {
|
||||
for (size_t offset = 0; offset < strlen(to_render_utf8); ++im, ++page_num) {
|
||||
tlog(1, "Starting page %d\n", im);
|
||||
Pix* pix = nullptr;
|
||||
if (FLAGS_find_fonts) {
|
||||
@ -664,7 +662,7 @@ int main(int argc, char** argv) {
|
||||
if (fp == nullptr) {
|
||||
tprintf("Failed to create output font list %s\n", filename.c_str());
|
||||
} else {
|
||||
for (int i = 0; i < font_names.size(); ++i) {
|
||||
for (size_t i = 0; i < font_names.size(); ++i) {
|
||||
fprintf(fp, "%s\n", font_names[i].c_str());
|
||||
}
|
||||
fclose(fp);
|
||||
|
Loading…
Reference in New Issue
Block a user