mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-27 20:59:36 +08:00
commit
7cc97c25ca
@ -2,7 +2,6 @@
|
||||
* File: points.h (Formerly coords.h)
|
||||
* Description: Coordinate class definitions.
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Mar 15 08:32:45 GMT 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -72,12 +71,12 @@ class ICOORD
|
||||
|
||||
///find sq length
|
||||
float sqlength() const {
|
||||
return (float) (xcoord * xcoord + ycoord * ycoord);
|
||||
return xcoord * xcoord + ycoord * ycoord;
|
||||
}
|
||||
|
||||
///find length
|
||||
float length() const {
|
||||
return (float) sqrt (sqlength ());
|
||||
return std::sqrt(sqlength());
|
||||
}
|
||||
|
||||
///sq dist between pts
|
||||
@ -91,12 +90,12 @@ class ICOORD
|
||||
|
||||
///Distance between pts
|
||||
float pt_to_pt_dist(const ICOORD &pt) const {
|
||||
return (float) sqrt (pt_to_pt_sqdist (pt));
|
||||
return std::sqrt(pt_to_pt_sqdist(pt));
|
||||
}
|
||||
|
||||
///find angle
|
||||
float angle() const {
|
||||
return (float) atan2 ((double) ycoord, (double) xcoord);
|
||||
return std::atan2(ycoord, xcoord);
|
||||
}
|
||||
|
||||
///test equality
|
||||
@ -227,7 +226,7 @@ class DLLSYM FCOORD
|
||||
|
||||
///find length
|
||||
float length() const {
|
||||
return (float) sqrt (sqlength ());
|
||||
return std::sqrt(sqlength());
|
||||
}
|
||||
|
||||
///sq dist between pts
|
||||
@ -241,12 +240,12 @@ class DLLSYM FCOORD
|
||||
|
||||
///Distance between pts
|
||||
float pt_to_pt_dist(const FCOORD &pt) const {
|
||||
return (float) sqrt (pt_to_pt_sqdist (pt));
|
||||
return std::sqrt(pt_to_pt_sqdist(pt));
|
||||
}
|
||||
|
||||
///find angle
|
||||
float angle() const {
|
||||
return (float) atan2 (ycoord, xcoord);
|
||||
return std::atan2(ycoord, xcoord);
|
||||
}
|
||||
// Returns the standard feature direction corresponding to this.
|
||||
// See binary_angle_plus_pi below for a description of the direction.
|
||||
@ -536,10 +535,10 @@ int16_t scale) {
|
||||
|
||||
inline void ICOORD::rotate( //rotate by vector
|
||||
const FCOORD& vec) {
|
||||
int16_t tmp;
|
||||
|
||||
tmp = (int16_t) floor (xcoord * vec.x () - ycoord * vec.y () + 0.5);
|
||||
ycoord = (int16_t) floor (ycoord * vec.x () + xcoord * vec.y () + 0.5);
|
||||
int16_t tmp = static_cast<int16_t>(std::floor(xcoord * vec.x() -
|
||||
ycoord * vec.y() + 0.5f));
|
||||
ycoord = static_cast<int16_t>(std::floor(ycoord * vec.x() +
|
||||
xcoord * vec.y() + 0.5f));
|
||||
xcoord = tmp;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
* is rotated for degradation. Also includes routines to output
|
||||
* the character-tagged boxes to a boxfile.
|
||||
* Author: Ray Smith
|
||||
* Created: Mon Nov 18 2013
|
||||
*
|
||||
* (C) Copyright 2013, Google Inc.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -54,7 +53,7 @@ void BoxChar::GetDirection(int* num_rtl, int* num_ltr) const {
|
||||
std::vector<char32> uni_vector = UNICHAR::UTF8ToUTF32(ch_.c_str());
|
||||
if (uni_vector.empty()) {
|
||||
tprintf("Illegal utf8 in boxchar string:%s = ", ch_.c_str());
|
||||
for (int c = 0; c < ch_.size(); ++c) {
|
||||
for (size_t c = 0; c < ch_.size(); ++c) {
|
||||
tprintf(" 0x%x", ch_[c]);
|
||||
}
|
||||
tprintf("\n");
|
||||
@ -100,7 +99,7 @@ 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 (unsigned int i = 0; i < boxes->size(); ++i) {
|
||||
for (size_t i = 0; i < boxes->size(); ++i) {
|
||||
if ((*boxes)[i]->box_ == nullptr) tprintf("Null box at index %u\n", i);
|
||||
}
|
||||
if (rtl_rules) {
|
||||
@ -112,12 +111,12 @@ void BoxChar::PrepareToWrite(std::vector<BoxChar*>* boxes) {
|
||||
/* static */
|
||||
void BoxChar::InsertNewlines(bool rtl_rules, bool vertical_rules,
|
||||
std::vector<BoxChar*>* boxes) {
|
||||
int prev_i = -1;
|
||||
size_t prev_i = SIZE_MAX;
|
||||
int max_shift = 0;
|
||||
for (size_t i = 0; i < boxes->size(); ++i) {
|
||||
Box* box = (*boxes)[i]->box_;
|
||||
if (box == nullptr) {
|
||||
if (prev_i < 0 || prev_i + 1 < i || i + 1 == boxes->size()) {
|
||||
if (prev_i == SIZE_MAX || prev_i + 1 < i || i + 1 == boxes->size()) {
|
||||
// Erase null boxes at the start of a line and after another null box.
|
||||
do {
|
||||
delete (*boxes)[i];
|
||||
@ -127,7 +126,7 @@ void BoxChar::InsertNewlines(bool rtl_rules, bool vertical_rules,
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (prev_i >= 0) {
|
||||
if (prev_i != SIZE_MAX) {
|
||||
Box* prev_box = (*boxes)[prev_i]->box_;
|
||||
int shift = box->x - prev_box->x;
|
||||
if (vertical_rules) {
|
||||
@ -238,8 +237,8 @@ void BoxChar::ReorderRTLText(std::vector<BoxChar*>* boxes) {
|
||||
// For now, let's try a sort that reverses original positions for RTL
|
||||
// characters, otherwise by x-position. This should be much closer to
|
||||
// correct than just sorting by x-position.
|
||||
int num_boxes = boxes->size();
|
||||
for (int i = 0; i < num_boxes; ++i) {
|
||||
size_t num_boxes = boxes->size();
|
||||
for (size_t i = 0; i < num_boxes; ++i) {
|
||||
int num_rtl = 0, num_ltr = 0;
|
||||
(*boxes)[i]->GetDirection(&num_rtl, &num_ltr);
|
||||
if (num_rtl > num_ltr) {
|
||||
@ -260,7 +259,7 @@ 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 (size_t i = 0; i < boxes.size(); ++i) {
|
||||
boxes[i]->GetDirection(&num_rtl, &num_ltr);
|
||||
}
|
||||
return num_rtl > num_ltr;
|
||||
|
@ -166,7 +166,7 @@ void ParseCommandLineFlags(const char* usage,
|
||||
exit(0);
|
||||
}
|
||||
|
||||
unsigned int i = 1;
|
||||
int i;
|
||||
for (i = 1; i < *argc; ++i) {
|
||||
const char* current_arg = (*argv)[i];
|
||||
// If argument does not start with a hyphen then break.
|
||||
|
@ -120,7 +120,7 @@ bool ValidateIndic::ConsumeViramaIfValid(IndicPair joiner, bool post_matra) {
|
||||
ASSERT_HOST(!CodeOnlyToOutput());
|
||||
} else {
|
||||
// Half-form with optional Nukta.
|
||||
int len = output_.size() + 1 - output_used_;
|
||||
unsigned len = output_.size() + 1 - output_used_;
|
||||
if (UseMultiCode(len)) return true;
|
||||
}
|
||||
if (codes_used_ < num_codes &&
|
||||
@ -179,7 +179,7 @@ bool ValidateIndic::ConsumeConsonantHeadIfValid() {
|
||||
CodeOnlyToOutput();
|
||||
// Special Sinhala case of [H Z Yayana/Rayana].
|
||||
int index = output_.size() - 3;
|
||||
if (output_used_ <= index &&
|
||||
if (output_used_ + 3 <= output_.size() &&
|
||||
(output_.back() == kYayana || output_.back() == kRayana) &&
|
||||
IsVirama(output_[index]) && output_[index + 1] == kZeroWidthJoiner) {
|
||||
MultiCodePart(3);
|
||||
@ -192,7 +192,7 @@ bool ValidateIndic::ConsumeConsonantHeadIfValid() {
|
||||
}
|
||||
// Test for subscript conjunct.
|
||||
index = output_.size() - 2 - have_nukta;
|
||||
if (output_used_ <= index && IsSubscriptScript() &&
|
||||
if (output_used_ + 2 + have_nukta <= output_.size() && IsSubscriptScript() &&
|
||||
IsVirama(output_[index])) {
|
||||
// Output previous virama, consonant + optional nukta.
|
||||
MultiCodePart(2 + have_nukta);
|
||||
|
@ -2,7 +2,6 @@
|
||||
* File: validate_javanese.cpp
|
||||
* Description: Text validator for Javanese Script - aksara jawa.
|
||||
* Author: Shree Devi Kumar
|
||||
* Created: August 03, 2018
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -90,7 +89,7 @@ bool ValidateJavanese::ConsumeViramaIfValid(IndicPair joiner, bool post_matra) {
|
||||
ASSERT_HOST(!CodeOnlyToOutput());
|
||||
} else {
|
||||
// Half-form with optional Nukta.
|
||||
int len = output_.size() + 1 - output_used_;
|
||||
unsigned len = output_.size() + 1 - output_used_;
|
||||
if (UseMultiCode(len)) return true;
|
||||
}
|
||||
if (codes_used_ < num_codes &&
|
||||
@ -149,7 +148,7 @@ bool ValidateJavanese::ConsumeConsonantHeadIfValid() {
|
||||
CodeOnlyToOutput();
|
||||
// Special Sinhala case of [H Z Yayana/Rayana].
|
||||
int index = output_.size() - 3;
|
||||
if (output_used_ <= index &&
|
||||
if (output_used_ + 3 <= output_.size() &&
|
||||
(output_.back() == kPengkal || output_.back() == kCakra) &&
|
||||
IsVirama(output_[index]) && output_[index + 1] == kZeroWidthJoiner) {
|
||||
MultiCodePart(3);
|
||||
@ -162,7 +161,7 @@ bool ValidateJavanese::ConsumeConsonantHeadIfValid() {
|
||||
}
|
||||
// Test for subscript conjunct.
|
||||
index = output_.size() - 2 - have_nukta;
|
||||
if (output_used_ <= index && IsSubscriptScript() &&
|
||||
if (output_used_ + 2 + have_nukta <= output_.size() && IsSubscriptScript() &&
|
||||
IsVirama(output_[index])) {
|
||||
// Output previous virama, consonant + optional nukta.
|
||||
MultiCodePart(2 + have_nukta);
|
||||
|
@ -45,7 +45,7 @@ bool ValidateKhmer::ConsumeGraphemeIfValid() {
|
||||
if (UseMultiCode(1)) return true;
|
||||
}
|
||||
}
|
||||
int num_matra_parts = 0;
|
||||
unsigned num_matra_parts = 0;
|
||||
if (codes_[codes_used_].second == kZeroWidthJoiner ||
|
||||
codes_[codes_used_].second == kZeroWidthNonJoiner) {
|
||||
if (CodeOnlyToOutput()) {
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Description: Base class for various text validators. Intended mainly for
|
||||
* scripts that use a virama character.
|
||||
* Author: Ray Smith
|
||||
* Created: Tue May 23 2017
|
||||
*
|
||||
* (C) Copyright 2017, Google Inc.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -179,7 +178,7 @@ class Validator {
|
||||
// output_, adds unicodes as single-element vectors to parts_ to catch
|
||||
// output_used_ up to output->size() - length before adding the length-element
|
||||
// vector.
|
||||
void MultiCodePart(int length) {
|
||||
void MultiCodePart(unsigned length) {
|
||||
while (output_used_ + length < output_.size()) {
|
||||
parts_.emplace_back(
|
||||
std::initializer_list<char32>{output_[output_used_++]});
|
||||
@ -193,7 +192,7 @@ class Validator {
|
||||
// Helper function appends the next element of codes_ to output_, and then
|
||||
// calls MultiCodePart to add the appropriate components to parts_.
|
||||
// Returns true at the end of codes_.
|
||||
bool UseMultiCode(int length) {
|
||||
bool UseMultiCode(unsigned length) {
|
||||
output_.push_back(codes_[codes_used_].second);
|
||||
MultiCodePart(length);
|
||||
return ++codes_used_ == codes_.size();
|
||||
|
Loading…
Reference in New Issue
Block a user