Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Format new code with clang-format
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Mar 2, 2019
1 parent 5de2a21 commit 38fac62
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions src/api/wordstrboxrenderer.cpp
Expand Up @@ -23,9 +23,9 @@
namespace tesseract {

/**
* Create a UTF8 box file with WordStr strings from the internal data structures.
* page_number is a 0-base page index that will appear in the box file.
* Returned string must be freed with the delete [] operator.
* Create a UTF8 box file with WordStr strings from the internal data
* structures. page_number is a 0-base page index that will appear in the box
* file. Returned string must be freed with the delete [] operator.
*/

char* TessBaseAPI::GetWordStrBoxText(int page_number) {
Expand All @@ -44,31 +44,32 @@ char* TessBaseAPI::GetWordStrBoxText(int page_number) {
continue;
}

if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) {
if (!first_line) {
if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) {
if (!first_line) {
wordstr_box_str.add_str_int("\n\t ", right + 1);
wordstr_box_str.add_str_int(" ", image_height_ - bottom);
wordstr_box_str.add_str_int(" ", right + 5);
wordstr_box_str.add_str_int(" ", image_height_ - top);
wordstr_box_str.add_str_int(" ", page_num); // row for tab for EOL
wordstr_box_str += "\n";
} else {
} else {
first_line = false;
}
// Use bounding box for whole line for WordStr
res_it->BoundingBox(RIL_TEXTLINE, &left, &top, &right, &bottom);
wordstr_box_str.add_str_int("WordStr ", left);
wordstr_box_str.add_str_int(" ", image_height_ - bottom);
wordstr_box_str.add_str_int(" ", right);
wordstr_box_str.add_str_int(" ", image_height_ - top);
wordstr_box_str.add_str_int(" ", page_num); // word
wordstr_box_str += " #";
}
// Use bounding box for whole line for WordStr
res_it->BoundingBox(RIL_TEXTLINE, &left, &top, &right, &bottom);
wordstr_box_str.add_str_int("WordStr ", left);
wordstr_box_str.add_str_int(" ", image_height_ - bottom);
wordstr_box_str.add_str_int(" ", right);
wordstr_box_str.add_str_int(" ", image_height_ - top);
wordstr_box_str.add_str_int(" ", page_num); // word
wordstr_box_str += " #";
}
do { wordstr_box_str +=
std::unique_ptr<const char[]>(res_it->GetUTF8Text(RIL_WORD)).get();
wordstr_box_str += " ";
res_it->Next(RIL_WORD);
} while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD));
do {
wordstr_box_str +=
std::unique_ptr<const char[]>(res_it->GetUTF8Text(RIL_WORD)).get();
wordstr_box_str += " ";
res_it->Next(RIL_WORD);
} while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD));
}
wordstr_box_str.add_str_int("\n\t ", right + 1);
wordstr_box_str.add_str_int(" ", image_height_ - bottom);
Expand All @@ -85,12 +86,12 @@ char* TessBaseAPI::GetWordStrBoxText(int page_number) {
/**********************************************************************
* WordStrBox Renderer interface implementation
**********************************************************************/
TessWordStrBoxRenderer::TessWordStrBoxRenderer(const char *outputbase)
: TessResultRenderer(outputbase, "box") {
}
TessWordStrBoxRenderer::TessWordStrBoxRenderer(const char* outputbase)
: TessResultRenderer(outputbase, "box") {}

bool TessWordStrBoxRenderer::AddImageHandler(TessBaseAPI* api) {
const std::unique_ptr<const char[]> wordstrbox(api->GetWordStrBoxText(imagenum()));
const std::unique_ptr<const char[]> wordstrbox(
api->GetWordStrBoxText(imagenum()));
if (wordstrbox == nullptr) return false;

AppendString(wordstrbox.get());
Expand Down

0 comments on commit 38fac62

Please sign in to comment.