34 ColPartition_IT it(&parts_);
35 it.add_list_after(partitions);
40 ColPartition_IT it(&parts_);
41 it.add_after_then_move(part);
50 ColPartition_IT it(&parts_);
52 for (
int i = 0; i < index && !it.cycled_list(); ++i, it.forward());
60 ColPartition_IT it(&parts_);
61 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
71 ColPartition_IT it(&parts_);
81 int set_size = src_sets->
size();
84 for (
int i = 0; i < set_size; ++i) {
86 if (column_set ==
NULL)
90 ColPartition_IT part_it(&parts_);
93 part_it.mark_cycle_pt();
94 ColPartition_IT col_it(&column_set->parts_);
95 for (col_it.mark_cycle_pt(); !col_it.cycled_list(); col_it.forward()) {
103 while (!part_it.at_last() && part->
right_key() < col_left) {
106 part = part_it.data();
110 if (part_right < col_left || col_right < part_left) {
116 bool part_width_ok = cb->
Run(part->
KeyWidth(part_left, part_right));
117 if (col_left < part_left && col_left > prev_right) {
121 bool tab_width_ok = cb->
Run(part->
KeyWidth(col_left, part_right));
122 bool box_width_ok = cb->
Run(part->
KeyWidth(col_box_left, part_right));
123 if (tab_width_ok || (!part_width_ok )) {
128 }
else if (col_box_left < part_left &&
129 (box_width_ok || !part_width_ok)) {
137 if (col_right > part_right &&
138 (part_it.at_last() ||
139 part_it.data_relative(1)->left_key() > col_right)) {
142 bool tab_width_ok = cb->
Run(part->
KeyWidth(part_left, col_right));
143 bool box_width_ok = cb->
Run(part->
KeyWidth(part_left, col_box_right));
144 if (tab_width_ok || (!part_width_ok )) {
149 }
else if (col_box_right > part_right &&
150 (box_width_ok || !part_width_ok)) {
169 tprintf(
"Considering new column candidate:\n");
174 tprintf(
"Not a legal column candidate:\n");
180 for (
int i = 0; i < column_sets->
size(); ++i) {
184 bool better = good_coverage_ > columns->good_coverage_;
185 if (good_coverage_ == columns->good_coverage_) {
186 better = good_column_count_ > columns->good_column_count_;
187 if (good_column_count_ == columns->good_column_count_) {
188 better = bad_coverage_ > columns->bad_coverage_;
195 column_sets->
insert(
this, i);
215 tprintf(
"CompatibleColumns testing compatibility\n");
219 if (other->parts_.empty()) {
221 tprintf(
"CompatibleColumns true due to empty other\n");
224 ColPartition_IT it(&other->parts_);
225 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
229 tprintf(
"CompatibleColumns ignoring image partition\n");
234 int y = part->
MidY();
239 if (right_col ==
NULL || left_col ==
NULL) {
241 tprintf(
"CompatibleColumns false due to partition edge outside\n");
246 if (right_col != left_col && cb->
Run(right - left)) {
248 tprintf(
"CompatibleColumns false due to good width in multiple cols\n");
254 ColPartition_IT it2= it;
255 while (!it2.at_last()) {
261 if (next_left == right) {
266 if (right_col == next_left_col) {
276 tprintf(
"CompatibleColumns false due to 2 parts of good width\n");
277 tprintf(
"part1 %d-%d, part2 %d-%d\n",
278 left, right, next_left, next_right);
288 tprintf(
"CompatibleColumns true!\n");
297 ColPartition_IT it(&part_set->parts_);
298 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
303 int y = part->
MidY();
304 BLOBNBOX_C_IT box_it(part->
boxes());
305 for (box_it.mark_cycle_pt(); !box_it.cycled_list(); box_it.forward()) {
306 const TBOX& box = it.data()->bounding_box();
312 total_width += box.
width();
321 ColPartition_IT it(&parts_);
324 bool any_text_parts =
false;
325 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
330 any_text_parts =
true;
339 return any_text_parts;
344 ColPartition_LIST copy_parts;
345 ColPartition_IT src_it(&parts_);
346 ColPartition_IT dest_it(©_parts);
347 for (src_it.mark_cycle_pt(); !src_it.cycled_list(); src_it.forward()) {
360 ColSegment_LIST *segments) {
361 ColPartition_IT it(&parts_);
362 ColSegment_IT col_it(segments);
363 col_it.move_to_last();
364 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
369 col_seg->InsertBox(
TBOX(bot_left, top_right));
370 col_it.add_after_then_move(col_seg);
377 #ifndef GRAPHICS_DISABLED
378 ColPartition_IT it(&parts_);
379 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
384 #endif // GRAPHICS_DISABLED
395 int left,
int right,
int y,
400 int* first_spanned_col) {
403 *first_spanned_col = -1;
404 int margin_columns = 0;
405 ColPartition_IT it(&parts_);
407 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward(), col_index += 2) {
414 *first_col = col_index;
417 *last_col = col_index;
420 if (left_margin <= part->LeftAtY(y)) {
422 *first_spanned_col = col_index;
426 if (*first_col < 0) {
428 *first_col = col_index - 1;
430 if (right_margin >= part->
RightAtY(y)) {
432 if (margin_columns == 0)
433 *first_spanned_col = col_index;
436 *last_col = col_index;
438 }
else if (left < part->LeftAtY(y) && right > part->
RightAtY(y)) {
441 if (*first_col < 0) {
443 *first_col = col_index - 1;
445 if (margin_columns == 0)
446 *first_spanned_col = col_index;
447 *last_col = col_index;
448 }
else if (right < part->LeftAtY(y)) {
450 *last_col = col_index - 1;
451 if (*first_col < 0) {
453 *first_col = col_index - 1;
459 *first_col = col_index - 1;
461 *last_col = col_index - 1;
464 if (*first_col == *last_col && right - left <
kMinColumnWidth * resolution) {
468 }
else if (margin_columns <= 1) {
470 if (margin_columns == 1 && parts_.singleton()) {
488 ColPartition_LIST* used_parts,
489 WorkingPartSet_LIST* working_set_list) {
492 WorkingPartSet_LIST work_src;
493 WorkingPartSet_IT src_it(&work_src);
494 src_it.add_list_after(working_set_list);
495 src_it.move_to_first();
496 WorkingPartSet_IT dest_it(working_set_list);
499 BLOCK_LIST completed_blocks;
500 TO_BLOCK_LIST to_blocks;
503 ColPartition_IT col_it(&parts_);
504 for (col_it.mark_cycle_pt(); !col_it.cycled_list(); col_it.forward()) {
507 while (!src_it.empty() &&
508 ((working_set = src_it.data())->column() ==
NULL ||
512 used_parts, &completed_blocks,
519 dest_it.add_after_then_move(working_set);
520 if (first_new_set ==
NULL)
521 first_new_set = working_set;
524 working_set = src_it.empty() ?
NULL : src_it.data();
525 if (working_set !=
NULL &&
528 dest_it.add_after_then_move(src_it.extract());
531 first_new_set =
NULL;
535 dest_it.add_after_then_move(working_set);
539 while (!src_it.empty()) {
540 working_set = src_it.extract();
542 used_parts, &completed_blocks,
549 dest_it.add_after_then_move(working_set);
550 if (first_new_set ==
NULL)
551 first_new_set = working_set;
561 ColPartition_IT it(&parts_);
562 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
577 ColPartition_IT it(&parts_);
578 tprintf(
"Partition set of %d parts, %d good, coverage=%d+%d"
579 " (%d,%d)->(%d,%d)\n",
580 it.length(), good_column_count_, good_coverage_, bad_coverage_,
582 bounding_box_.
right(), bounding_box_.
top());
583 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
592 void ColPartitionSet::AddPartition(
ColPartition* new_part,
593 ColPartition_IT* it) {
594 AddPartitionCoverageAndBox(*new_part);
596 if (it->data()->left_key() >= new_right)
597 it->add_before_stay_put(new_part);
599 it->add_after_stay_put(new_part);
619 void ColPartitionSet::ComputeCoverage() {
621 ColPartition_IT it(&parts_);
622 good_column_count_ = 0;
625 bounding_box_ =
TBOX();
626 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
627 ColPartition* part = it.data();
628 AddPartitionCoverageAndBox(*part);
634 void ColPartitionSet::AddPartitionCoverageAndBox(
const ColPartition& part) {
635 bounding_box_ += part.bounding_box();
636 int coverage = part.ColumnWidth();
637 if (part.good_width()) {
638 good_coverage_ += coverage;
639 good_column_count_ += 2;
643 if (part.good_column())
644 ++good_column_count_;
645 bad_coverage_ += coverage;