MCPcopy Create free account
hub / github.com/creatale/node-dv / InitializeRowInfo

Function InitializeRowInfo

deps/tesseract/ccmain/paragraphs.cpp:2412–2505  ·  view source on GitHub ↗

Given a Tesseract Iterator pointing to a text line, fill in the paragraph detector RowInfo with all relevant information from the row.

Source from the content-addressed store, hash-verified

2410// Given a Tesseract Iterator pointing to a text line, fill in the paragraph
2411// detector RowInfo with all relevant information from the row.
2412void InitializeRowInfo(bool after_recognition,
2413 const MutableIterator &it,
2414 RowInfo *info) {
2415 if (it.PageResIt()->row() != NULL) {
2416 ROW *row = it.PageResIt()->row()->row;
2417 info->pix_ldistance = row->lmargin();
2418 info->pix_rdistance = row->rmargin();
2419 info->average_interword_space =
2420 row->space() > 0 ? row->space() : MAX(row->x_height(), 1);
2421 info->pix_xheight = row->x_height();
2422 info->has_leaders = false;
2423 info->has_drop_cap = row->has_drop_cap();
2424 info->ltr = true; // set below depending on word scripts
2425 } else {
2426 info->pix_ldistance = info->pix_rdistance = 0;
2427 info->average_interword_space = 1;
2428 info->pix_xheight = 1.0;
2429 info->has_leaders = false;
2430 info->has_drop_cap = false;
2431 info->ltr = true;
2432 }
2433
2434 info->num_words = 0;
2435 info->lword_indicates_list_item = false;
2436 info->lword_likely_starts_idea = false;
2437 info->lword_likely_ends_idea = false;
2438 info->rword_indicates_list_item = false;
2439 info->rword_likely_starts_idea = false;
2440 info->rword_likely_ends_idea = false;
2441 info->has_leaders = false;
2442 info->ltr = 1;
2443
2444 if (!after_recognition) {
2445 InitializeTextAndBoxesPreRecognition(it, info);
2446 return;
2447 }
2448 info->text = "";
2449 char *text = it.GetUTF8Text(RIL_TEXTLINE);
2450 int trailing_ws_idx = strlen(text); // strip trailing space
2451 while (trailing_ws_idx > 0 &&
2452 // isspace() only takes ASCII
2453 ((text[trailing_ws_idx - 1] & 0x80) == 0) &&
2454 isspace(text[trailing_ws_idx - 1]))
2455 trailing_ws_idx--;
2456 if (trailing_ws_idx > 0) {
2457 int lspaces = info->pix_ldistance / info->average_interword_space;
2458 for (int i = 0; i < lspaces; i++)
2459 info->text += ' ';
2460 for (int i = 0; i < trailing_ws_idx; i++)
2461 info->text += text[i];
2462 }
2463 delete []text;
2464
2465 if (info->text.size() == 0) {
2466 return;
2467 }
2468
2469 PAGE_RES_IT page_res_it = *it.PageResIt();

Callers 1

DetectParagraphsFunction · 0.85

Calls 15

LeftWordAttributesFunction · 0.85
RightWordAttributesFunction · 0.85
PageResItMethod · 0.80
lmarginMethod · 0.80
rmarginMethod · 0.80
has_drop_capMethod · 0.80
restart_rowMethod · 0.80
AnyLtrCharsInWordMethod · 0.80
AnyRtlCharsInWordMethod · 0.80
rowMethod · 0.45
spaceMethod · 0.45

Tested by

no test coverage detected