20 #include "config_auto.h" 29 static INT_VAR(textord_testregion_left, -1,
"Left edge of debug reporting rectangle");
30 static INT_VAR(textord_testregion_top, -1,
"Top edge of debug reporting rectangle");
31 static INT_VAR(textord_testregion_right, INT32_MAX,
"Right edge of debug rectangle");
32 static INT_VAR(textord_testregion_bottom, INT32_MAX,
"Bottom edge of debug rectangle");
74 int height,
int v_gap_multiple,
136 if (vertical_y > INT16_MAX)
137 factor = vertical_y / INT16_MAX + 1;
145 :
BlobGrid(gridsize, bleft, tright) {
153 return x >= textord_testregion_left && x <= textord_testregion_right &&
154 y <= textord_testregion_top && y >= textord_testregion_bottom;
160 #ifndef GRAPHICS_DISABLED 161 if (tab_win ==
nullptr)
169 int left_x = box.
left();
170 int right_x = box.
right();
171 int top_y = box.
top();
172 int bottom_y = box.
bottom();
183 tab_win->
Line(left_x, top_y, left_x, bottom_y);
195 tab_win->
Line(right_x, top_y, right_x, bottom_y);
205 static bool AtLeast2LineCrossings(BLOBNBOX_CLIST* blobs) {
206 BLOBNBOX_C_IT it(blobs);
207 int total_crossings = 0;
208 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
209 total_crossings += it.data()->line_crossings();
211 return total_crossings >= 2;
229 int ext_start_y, ext_end_y;
230 BLOBNBOX_CLIST good_points;
234 int pt_count = AlignTabs(align_params,
false, bbox, &good_points, &ext_end_y);
235 pt_count += AlignTabs(align_params,
true, bbox, &good_points, &ext_start_y);
236 BLOBNBOX_C_IT it(&good_points);
238 box = it.data()->bounding_box();
239 int end_y = box.
top();
242 box = it.data()->bounding_box();
244 int start_y = box.
bottom();
250 bool at_least_2_crossings = AtLeast2LineCrossings(&good_points);
254 end_y - start_y >= abs(end_x - start_x) * kMinTabGradient)) ||
255 at_least_2_crossings) {
256 int confirmed_points = 0;
258 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
269 if (!align_params.
ragged ||
270 confirmed_points + confirmed_points < pt_count) {
273 tprintf(
"Confirming tab vector of %d pts starting at %d,%d\n",
277 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
291 ext_start_y, ext_end_y,
293 vertical_x, vertical_y);
297 result->
Print(
"After fitting");
301 tprintf(
"Ragged tab used too many used points: %d out of %d\n",
302 confirmed_points, pt_count);
305 tprintf(
"Tab vector failed basic tests: pt count %d vs min %d, " 306 "length %d vs min %d, min grad %g\n",
307 pt_count, align_params.
min_points, end_y - start_y,
308 align_params.
min_length, abs(end_x - start_x) * kMinTabGradient);
319 BLOBNBOX_CLIST* good_points,
int* end_y) {
321 BLOBNBOX_C_IT it(good_points);
326 tprintf(
"Starting alignment run at blob:");
330 while (bbox !=
nullptr) {
336 (it.empty() || it.data() != bbox)) {
338 it.add_before_then_move(bbox);
340 it.add_after_then_move(bbox);
347 bbox = FindAlignedBlob(params, top_to_bottom, bbox, x_start, end_y);
348 if (bbox !=
nullptr) {
355 tprintf(
"Alignment run ended with %d pts at blob:", ptcount);
370 int x_start,
int* end_y) {
373 int left_column_edge = bbox->
left_rule();
378 int start_y = top_to_bottom ? box.
bottom() : box.
top();
380 tprintf(
"Column edges for blob at (%d,%d)->(%d,%d) are [%d, %d]\n",
382 left_column_edge, right_column_edge);
399 int xmin = std::min(x_start, x2) - skew_tolerance;
400 int xmax = std::max(x_start, x2) + skew_tolerance;
412 tprintf(
"Starting %s %s search at %d-%d,%d, search_size=%d, gutter=%d\n",
424 if (neighbour == bbox)
427 int n_y = (nbox.
top() + nbox.
bottom()) / 2;
428 if ((!top_to_bottom && n_y > start_y + p.
max_v_gap) ||
429 (top_to_bottom && n_y < start_y - p.
max_v_gap)) {
431 tprintf(
"Neighbour too far at (%d,%d)->(%d,%d)\n",
440 if ((n_y < start_y) != top_to_bottom || nbox.
y_overlap(box))
444 if (backup_result !=
nullptr && p.
ragged && result ==
nullptr &&
446 return backup_result;
451 if (x_at_n_y < neighbour->left_crossing_rule() ||
454 int n_left = nbox.
left();
455 int n_right = nbox.
right();
456 int n_x = p.
right_tab ? n_right : n_left;
458 tprintf(
"neighbour at (%d,%d)->(%d,%d), n_x=%d, n_y=%d, xatn=%d\n",
468 *end_y = top_to_bottom ? nbox.
top() : nbox.
bottom();
480 *end_y = top_to_bottom ? nbox.
top() : nbox.
bottom();
493 tprintf(
"aligned, seeking%d, l=%d, r=%d\n",
499 if (result ==
nullptr) {
507 int y_diff = (old_box.
top() + old_box.
bottom()) / 2 - start_y;
508 int old_dist = x_diff * x_diff + y_diff * y_diff;
509 x_diff = n_x - x_at_n_y;
510 y_diff = n_y - start_y;
511 int new_dist = x_diff * x_diff + y_diff * y_diff;
512 if (new_dist < old_dist)
515 }
else if (backup_result ==
nullptr) {
518 backup_result = neighbour;
525 backup_result = neighbour;
530 return result !=
nullptr ? result : backup_result;
const double kAlignedFraction
TabType right_tab_type() const
ScrollView * MakeWindow(int x, int y, const char *window_name)
void set_right_tab_type(TabType new_type)
AlignedBlob(int gridsize, const ICOORD &bleft, const ICOORD &tright)
void set_x(int16_t xin)
rewrite function
static TabVector * FitVector(TabAlignment alignment, ICOORD vertical, int extended_start_y, int extended_end_y, BLOBNBOX_CLIST *good_points, int *vertical_x, int *vertical_y)
#define INT_VAR(name, val, comment)
void set_intersects_other_lines(bool value)
ScrollView * DisplayTabs(const char *window_name, ScrollView *tab_win)
bool y_overlap(const TBOX &box) const
void Print(const char *prefix)
const TBOX & bounding_box() const
int16_t y() const
access_function
void set_y(int16_t yin)
rewrite function
bool leader_on_right() const
bool textord_debug_printable
const double kRaggedFraction
BBC * NextVerticalSearch(bool top_to_bottom)
TabType left_tab_type() const
int16_t x() const
access function
DLLSYM void tprintf(const char *format,...)
int textord_debug_tabfind
const int kMinAlignedTabs
int y_gap(const TBOX &box) const
const double kMinTabGradient
void StartVerticalSearch(int xmin, int xmax, int y)
const int kVLineMinLength
const int kVLineAlignment
TabVector * FindVerticalAlignment(AlignedBlobParams align_params, BLOBNBOX *bbox, int *vertical_x, int *vertical_y)
int right_crossing_rule() const
void Line(int x1, int y1, int x2, int y2)
#define BOOL_VAR(name, val, comment)
void set_vertical(int vertical_x, int vertical_y)
void set_left_tab_type(TabType new_type)
const int kVLineSearchSize
static bool WithinTestRegion(int detail_level, int x, int y)
const double kAlignedGapFraction
const double kRaggedGapFraction
bool leader_on_left() const
AlignedBlobParams(int vertical_x, int vertical_y, int height, int v_gap_multiple, int min_gutter_width, int resolution, TabAlignment alignment0)