Commit c90c2199 for tesseract

commit c90c2199d8e8f0e0b3450b56c0e67ef394787ef0
Author: Stefan Weil <sw@weilnetz.de>
Date:   Wed Nov 25 17:10:39 2026 +0100

    Don't count leaders as image neighbours of text

    The smoothing of the partition types counts every neighbour which is
    neither strong nor weak text as image. A leader, a row of dots or
    dashes, has its own flow type, so it counted as image with the weight of
    up to four blobs. A line of text between two dashed lines had more image
    than text near it in all four directions. It lost its type, even as a
    strong text line, and was deleted with the partitions of unknown type,
    like the line "Insert Table 6 about here" on one of the pages of issue
    3446.

    Skip leaders like the rule lines, which are not used as neighbours
    either.

    Results with tessdata_fast and the default page segmentation mode,
    compared with the previous commit: on 161 pages of AustrianNewspapers
    235,271 instead of 234,966 of 333,385 words are correct, on 167 pages of
    the NZZ ground truth 229,252 instead of 229,193 of 303,723. Compared
    with the code before both commits these are 19 words less and 49 words
    more. One page with stock exchange tables (ONB_nfp_19110701_018) gets
    1,578 words more output and has 232 correct words less than before both
    commits.

    Assisted-by: Claude Fable 5.2 (Anthropic)
    Signed-off-by: Stefan Weil <sw@weilnetz.de>

diff --git a/src/textord/colpartitiongrid.cpp b/src/textord/colpartitiongrid.cpp
index 48cbf72c..e3ffe024 100644
--- a/src/textord/colpartitiongrid.cpp
+++ b/src/textord/colpartitiongrid.cpp
@@ -1672,8 +1672,10 @@ void ColPartitionGrid::AccumulatePartDistances(
                                         nontext_map)) {
       continue; // Text not visible the other side of image.
     }
-    if (BLOBNBOX::IsLineType(n_type)) {
-      continue; // Don't use horizontal lines as neighbours.
+    if (BLOBNBOX::IsLineType(n_type) || neighbour->flow() == BTFT_LEADER) {
+      // Don't use horizontal lines as neighbours, and no leaders, which are
+      // dotted or dashed lines.
+      continue;
     }
     int x_gap = std::max(part_box.x_gap(nbox), 0);
     int y_gap = std::max(part_box.y_gap(nbox), 0);
diff --git a/unittest/layout_test.cc b/unittest/layout_test.cc
index 3d9b73df..7514c8cf 100644
--- a/unittest/layout_test.cc
+++ b/unittest/layout_test.cc
@@ -365,4 +365,21 @@ TEST_F(LayoutTest, PageNumberInsideScanBorder) {
   EXPECT_EQ(CountPageNumberLines(), 1);
 }

+// Tests that a line of text between two dashed lines is found.
+TEST_F(LayoutTest, TextLineBetweenLeaders) {
+  REQUIRE_TRAINEDDATA(TESSDATA_DIR, "eng");
+  Pix *page = MakeTextPage();
+  // Make room in the middle of the text.
+  FillRect(page, 200, 1090, 1600, 250, false);
+  std::string dashes;
+  for (int i = 0; i < 30; ++i) {
+    dashes += "- ";
+  }
+  DrawText(page, dashes.c_str(), 500, 1160);
+  DrawText(page, "Insert Table 6 about here", 700, 1230);
+  DrawText(page, dashes.c_str(), 500, 1300);
+  AnalysePage(page);
+  EXPECT_EQ(CountTextLinesIn(600, 1175, 1400, 1260), 1);
+}
+
 } // namespace tesseract