Add a bi-directional partner relationship between the left and the right. If one (or both) of the vectors is a separator, extend a nearby extendable vector or create a new one of the correct type, using the given left or right blob as a guide.
| 1192 | // extend a nearby extendable vector or create a new one of the |
| 1193 | // correct type, using the given left or right blob as a guide. |
| 1194 | void TabFind::AddPartnerVector(BLOBNBOX* left_blob, BLOBNBOX* right_blob, |
| 1195 | TabVector* left, TabVector* right) { |
| 1196 | const TBOX& left_box = left_blob->bounding_box(); |
| 1197 | const TBOX& right_box = right_blob->bounding_box(); |
| 1198 | if (left->IsSeparator()) { |
| 1199 | // Try to find a nearby left edge to extend. |
| 1200 | TabVector* v = LeftTabForBox(left_box, true, true); |
| 1201 | if (v != NULL && v != left && v->IsLeftTab() && |
| 1202 | v->XAtY(left_box.top()) > left->XAtY(left_box.top())) { |
| 1203 | left = v; // Found a good replacement. |
| 1204 | left->ExtendToBox(left_blob); |
| 1205 | } else { |
| 1206 | // Fake a vector. |
| 1207 | left = new TabVector(*left, TA_LEFT_RAGGED, vertical_skew_, left_blob); |
| 1208 | vectors_.add_sorted(TabVector::SortVectorsByKey, left); |
| 1209 | v_it_.move_to_first(); |
| 1210 | } |
| 1211 | } |
| 1212 | if (right->IsSeparator()) { |
| 1213 | // Try to find a nearby left edge to extend. |
| 1214 | if (WithinTestRegion(3, right_box.right(), right_box.bottom())) { |
| 1215 | tprintf("Box edge (%d,%d-%d)", |
| 1216 | right_box.right(), right_box.bottom(), right_box.top()); |
| 1217 | right->Print(" looking for improvement for"); |
| 1218 | } |
| 1219 | TabVector* v = RightTabForBox(right_box, true, true); |
| 1220 | if (v != NULL && v != right && v->IsRightTab() && |
| 1221 | v->XAtY(right_box.top()) < right->XAtY(right_box.top())) { |
| 1222 | right = v; // Found a good replacement. |
| 1223 | right->ExtendToBox(right_blob); |
| 1224 | if (WithinTestRegion(3, right_box.right(), right_box.bottom())) { |
| 1225 | right->Print("Extended vector"); |
| 1226 | } |
| 1227 | } else { |
| 1228 | // Fake a vector. |
| 1229 | right = new TabVector(*right, TA_RIGHT_RAGGED, vertical_skew_, |
| 1230 | right_blob); |
| 1231 | vectors_.add_sorted(TabVector::SortVectorsByKey, right); |
| 1232 | v_it_.move_to_first(); |
| 1233 | if (WithinTestRegion(3, right_box.right(), right_box.bottom())) { |
| 1234 | right->Print("Created new vector"); |
| 1235 | } |
| 1236 | } |
| 1237 | } |
| 1238 | left->AddPartner(right); |
| 1239 | right->AddPartner(left); |
| 1240 | } |
| 1241 | |
| 1242 | // Remove separators and unused tabs from the main vectors_ list |
| 1243 | // to the dead_vectors_ list. |
nothing calls this directly
no test coverage detected