{
TBOX best_box = guess_box;
int best_below = 0;
int best_above = 0;
TBOX adjusted = guess_box;
const int kMidGuessY = (guess_box.
bottom() + guess_box.
top()) / 2;
int best_cols = 0;
bool found_good_border = false;
int previous_below = 0;
const int kMaxChances = 10;
int chances = kMaxChances;
while (bottom != last_bottom) {
table->set_bounding_box(adjusted);
if (table->FindWhitespacedStructure() &&
--chances;
} else {
chances = kMaxChances;
double max_row_height =
kMaxRowSize * table->median_cell_height();
table->space_below() >= previous_below) ||
(table->CountFilledCellsInRow(0) > 1 &&
table->row_height(0) < max_row_height)) {
best_below = table->space_below();
best_cols =
MAX(table->column_count(), best_cols);
found_good_border = true;
}
}
previous_below = table->space_below();
} else {
--chances;
}
}
if (chances <= 0)
break;
last_bottom = bottom;
last_bottom, true);
}
if (!found_good_border)
return false;
found_good_border = false;
int previous_above = 0;
chances = kMaxChances;
while (last_top != top) {
table->set_bounding_box(adjusted);
if (table->FindWhitespacedStructure() &&
int last_row = table->row_count() - 1;
--chances;
} else {
chances = kMaxChances;
double max_row_height =
kMaxRowSize * table->median_cell_height();
table->space_above() >= previous_above) ||
(table->CountFilledCellsInRow(last_row) > 1 &&
table->row_height(last_row) < max_row_height)) {
best_above = table->space_above();
best_cols =
MAX(table->column_count(), best_cols);
found_good_border = true;
}
}
previous_above = table->space_above();
} else {
--chances;
}
}
if (chances <= 0)
break;
last_top = top;
last_top, false);
}
if (!found_good_border)
return false;
return false;
table->set_bounding_box(best_box);
return table->FindWhitespacedStructure();
}