36 {
38 BLOBNBOX_IT blob_it;
41 int16_t gap_width;
42 int16_t start_of_row;
43 int16_t end_of_row;
44 STATS xht_stats (0, 128);
45 int16_t min_quantum;
46 int16_t max_quantum;
47 int16_t i;
48
49
50
51
52 map = nullptr;
53 min_left = INT16_MAX;
54 max_right = -INT16_MAX;
55 total_rows = 0;
56 any_tabs = false;
57
58
60 for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
61 row = row_it.data ();
63 total_rows++;
64 xht_stats.add (
static_cast<int16_t
>(floor (row->
xheight + 0.5)), 1);
66 start_of_row = blob_it.data ()->bounding_box ().left ();
67 end_of_row = blob_it.data_relative (-1)->bounding_box ().right ();
68 if (min_left > start_of_row)
69 min_left = start_of_row;
70 if (max_right < end_of_row)
71 max_right = end_of_row;
72 }
73 }
74 if ((total_rows < 3) || (min_left >= max_right)) {
75 bucket_size = 0;
76 map_max = 0;
77 total_rows = 0;
78 min_left = max_right = 0;
79 return;
80 }
81 bucket_size = static_cast<int16_t>(floor (xht_stats.median () + 0.5)) / 2;
82 map_max = (max_right - min_left) / bucket_size;
83 map = new int16_t[map_max + 1];
84 for (i = 0; i <= map_max; i++)
85 map[i] = 0;
86
87 for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
88 row = row_it.data ();
91 blob_it.mark_cycle_pt ();
93 prev_blob_box = blob_box;
95
96 gap_width = blob_box.
left () - min_left;
98 && gap_width > 2) {
99 max_quantum = (blob_box.
left () - min_left) / bucket_size;
100 if (max_quantum > map_max) max_quantum = map_max;
101 for (i = 0; i <= max_quantum; i++)
102 map[i]++;
103 }
104 }
105 while (!blob_it.cycled_list ()) {
107 gap_width = blob_box.
left () - prev_blob_box.
right ();
109 && gap_width > 2) {
110 min_quantum =
111 (prev_blob_box.
right () - min_left) / bucket_size;
112 max_quantum = (blob_box.
left () - min_left) / bucket_size;
113 if (max_quantum > map_max) max_quantum = map_max;
114 for (i = min_quantum; i <= max_quantum; i++)
115 map[i]++;
116 }
117 prev_blob_box = blob_box;
118 }
120
121 gap_width = max_right - prev_blob_box.
right ();
123 && gap_width > 2) {
124 min_quantum =
125 (prev_blob_box.
right () - min_left) / bucket_size;
126 if (min_quantum < 0) min_quantum = 0;
127 for (i = min_quantum; i <= map_max; i++)
128 map[i]++;
129 }
130 }
131 }
132 }
133 for (i = 0; i <= map_max; i++) {
134 if (map[i] > total_rows / 2) {
136 (((i == 0) &&
137 (map[i + 1] <= total_rows / 2)) ||
138 ((i == map_max) &&
139 (map[i - 1] <= total_rows / 2)) ||
140 ((i > 0) &&
141 (i < map_max) &&
142 (map[i - 1] <= total_rows / 2) &&
143 (map[i + 1] <= total_rows / 2)))) {
144 map[i] = 0;
145 }
146 else
147 any_tabs = true;
148 }
149 }
152}
TBOX box_next(BLOBNBOX_IT *it)
DLLSYM void tprintf(const char *format,...)
bool gapmap_no_isolated_quanta
BLOBNBOX_LIST * blob_list()