Finds diacritics and saves their base character in the blob. The objective is to move all diacritics to the noise_blobs list, so they don't mess up early textline finding/merging, or force splits on textlines that overlap a bit. Blobs that become diacritics must be either part of no ColPartition (NULL owner) or in a small partition in which ALL the blobs are diacritics, in which case the partition
| 1451 | // which ALL the blobs are diacritics, in which case the partition is |
| 1452 | // exploded (deleted) back to its blobs. |
| 1453 | void StrokeWidth::TestDiacritics(ColPartitionGrid* part_grid, TO_BLOCK* block) { |
| 1454 | BlobGrid small_grid(gridsize(), bleft(), tright()); |
| 1455 | small_grid.InsertBlobList(&block->noise_blobs); |
| 1456 | small_grid.InsertBlobList(&block->blobs); |
| 1457 | int medium_diacritics = 0; |
| 1458 | int small_diacritics = 0; |
| 1459 | BLOBNBOX_IT small_it(&block->noise_blobs); |
| 1460 | for (small_it.mark_cycle_pt(); !small_it.cycled_list(); small_it.forward()) { |
| 1461 | BLOBNBOX* blob = small_it.data(); |
| 1462 | if (blob->owner() == NULL && !blob->IsDiacritic() && |
| 1463 | DiacriticBlob(&small_grid, blob)) { |
| 1464 | ++small_diacritics; |
| 1465 | } |
| 1466 | } |
| 1467 | BLOBNBOX_IT blob_it(&block->blobs); |
| 1468 | for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) { |
| 1469 | BLOBNBOX* blob = blob_it.data(); |
| 1470 | if (blob->IsDiacritic()) { |
| 1471 | small_it.add_to_end(blob_it.extract()); |
| 1472 | continue; // Already a diacritic. |
| 1473 | } |
| 1474 | ColPartition* part = blob->owner(); |
| 1475 | if (part == NULL && DiacriticBlob(&small_grid, blob)) { |
| 1476 | ++medium_diacritics; |
| 1477 | RemoveBBox(blob); |
| 1478 | small_it.add_to_end(blob_it.extract()); |
| 1479 | } else if (part != NULL && !part->block_owned() && |
| 1480 | part->boxes_count() < 3) { |
| 1481 | // We allow blobs in small partitions to become diacritics if ALL the |
| 1482 | // blobs in the partition qualify as we can then cleanly delete the |
| 1483 | // partition, turn all the blobs in it to diacritics and they can be |
| 1484 | // merged into the base character partition more easily than merging |
| 1485 | // the partitions. |
| 1486 | BLOBNBOX_C_IT box_it(part->boxes()); |
| 1487 | for (box_it.mark_cycle_pt(); !box_it.cycled_list() && |
| 1488 | DiacriticBlob(&small_grid, box_it.data()); |
| 1489 | box_it.forward()); |
| 1490 | if (box_it.cycled_list()) { |
| 1491 | // They are all good. |
| 1492 | while (!box_it.empty()) { |
| 1493 | // Liberate the blob from its partition so it can be treated |
| 1494 | // as a diacritic and merged explicitly with the base part. |
| 1495 | // The blob is really owned by the block. The partition "owner" |
| 1496 | // is NULLed to allow the blob to get merged with its base character |
| 1497 | // partition. |
| 1498 | BLOBNBOX* box = box_it.extract(); |
| 1499 | box->set_owner(NULL); |
| 1500 | box_it.forward(); |
| 1501 | ++medium_diacritics; |
| 1502 | // We remove the blob from the grid so it isn't found by subsequent |
| 1503 | // searches where we might not want to include diacritics. |
| 1504 | RemoveBBox(box); |
| 1505 | } |
| 1506 | // We only move the one blob to the small list here, but the others |
| 1507 | // all get moved by the test at the top of the loop. |
| 1508 | small_it.add_to_end(blob_it.extract()); |
| 1509 | part_grid->RemoveBBox(part); |
| 1510 | delete part; |
nothing calls this directly
no test coverage detected