29 #include "config_auto.h" 35 "Max allowed bending of chop cells");
37 "Max distance of chop pt from vertex");
55 int16_t prev_chop_coord;
58 C_OUTLINE_LIST left_coutlines;
59 C_OUTLINE_LIST right_coutlines;
61 C_BLOB_IT cblob_it = &cblobs;
63 WERD_IT word_it = &words;
65 WERD_IT rep_it = &row->rep_words;
70 BLOBNBOX_IT box_it = row->blob_list ();
72 ICOORDELT_IT cell_it = &row->char_cells;
74 #ifndef GRAPHICS_DISABLED 86 rep_left = rep_it.data ()->bounding_box ().left ();
89 xstarts[0] = box_it.data ()->bounding_box ().left ();
90 if (rep_left < xstarts[0]) {
91 xstarts[0] = rep_left;
93 if (cell_it.empty () || row->char_cells.singleton ()) {
94 tprintf (
"Row without enough char cells!\n");
95 tprintf (
"Leftmost blob is at (%d,%d)\n",
96 box_it.data ()->bounding_box ().left (),
97 box_it.data ()->bounding_box ().bottom ());
100 ASSERT_HOST (!cell_it.empty () && !row->char_cells.singleton ());
101 prev_chop_coord = cell_it.data ()->x ();
103 while (rep_left < cell_it.data ()->x ()) {
105 blanks, row->fixed_pitch, &word_it);
107 cell_it.mark_cycle_pt ();
108 if (prev_chop_coord >= cell_it.data ()->x ())
110 for (; !cell_it.cycled_list (); cell_it.forward ()) {
111 chop_coord = cell_it.data ()->x ();
112 while (!box_it.empty ()
113 && box_it.data ()->bounding_box ().left () <= chop_coord) {
114 if (box_it.data ()->bounding_box ().right () > prev_x)
115 prev_x = box_it.data ()->bounding_box ().right ();
121 while (!box_it.empty() && box_it.data()->cblob() ==
nullptr) {
122 delete box_it.extract();
126 if (!right_coutlines.empty() && left_coutlines.empty())
131 if (!left_coutlines.empty()) {
132 cblob_it.add_after_then_move(
new C_BLOB(&left_coutlines));
134 if (rep_left < chop_coord) {
135 if (rep_left > prev_chop_coord)
136 new_blanks = (uint8_t) floor ((rep_left - prev_chop_coord)
137 / row->fixed_pitch + 0.5);
142 if (chop_coord > prev_chop_coord)
143 new_blanks = (uint8_t) floor ((chop_coord - prev_chop_coord)
144 / row->fixed_pitch + 0.5);
148 if (!cblob_it.empty()) {
149 if (blanks < 1 && word != nullptr && !word->flag (
W_REP_CHAR))
151 word =
new WERD (&cblobs, blanks,
nullptr);
152 cblob_it.set_to_list (&cblobs);
154 word_it.add_after_then_move (word);
162 blanks += new_blanks;
163 while (rep_left < chop_coord) {
165 blanks, row->fixed_pitch, &word_it);
168 if (prev_chop_coord < chop_coord)
169 prev_chop_coord = chop_coord;
171 if (!cblob_it.empty()) {
172 word =
new WERD(&cblobs, blanks,
nullptr);
174 word_it.add_after_then_move (word);
179 while (!rep_it.empty ()) {
181 blanks, row->fixed_pitch, &word_it);
185 if (prev_chop_coord > prev_x)
186 prev_x = prev_chop_coord;
187 xstarts[1] = prev_x + 1;
188 real_row =
new ROW (row, (int16_t) row->kern_size, (int16_t) row->space_size);
189 word_it.set_to_list (real_row->
word_list ());
191 word_it.add_list_after (&words);
206 int16_t &prev_chop_coord,
214 if (rep_left > prev_chop_coord) {
215 new_blanks = (uint8_t) floor ((rep_left - prev_chop_coord) / pitch + 0.5);
216 blanks += new_blanks;
218 word = rep_it->extract ();
220 word_it->add_after_then_move (word);
223 if (rep_it->empty ())
224 rep_left = INT16_MAX;
226 rep_left = rep_it->data ()->bounding_box ().left ();
243 C_OUTLINE_LIST *left_coutlines,
244 C_OUTLINE_LIST *right_coutlines) {
247 if (blob !=
nullptr) {
248 real_cblob = blob->
cblob();
250 real_cblob =
nullptr;
252 if (!right_coutlines->empty() || real_cblob !=
nullptr)
273 C_OUTLINE_LIST *left_outlines,
274 C_OUTLINE_LIST *right_outlines
277 C_OUTLINE_LIST new_outlines;
279 C_OUTLINE_IT left_it = left_outlines;
281 C_OUTLINE_IT right_it = right_outlines;
282 C_OUTLINE_IT new_it = &new_outlines;
283 C_OUTLINE_IT blob_it;
285 if (!right_it.empty ()) {
286 while (!right_it.empty ()) {
287 old_right = right_it.extract ();
295 right_it.add_list_before (&new_outlines);
297 if (blob !=
nullptr) {
298 blob_it.set_to_list (blob->
out_list ());
299 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
302 &left_it, &right_it);
319 C_OUTLINE_IT *left_it,
320 C_OUTLINE_IT *right_it
324 C_OUTLINE_LIST left_ch;
325 C_OUTLINE_LIST right_ch;
326 C_OUTLINE_FRAG_LIST left_frags;
327 C_OUTLINE_FRAG_LIST right_frags;;
328 C_OUTLINE_IT left_ch_it = &left_ch;
330 C_OUTLINE_IT right_ch_it = &right_ch;
332 C_OUTLINE_IT child_it = srcline->
child ();
335 if (srcbox.
left() + srcbox.
right() <= chop_coord * 2
336 && srcbox.
right() < chop_coord + pitch_error) {
339 left_it->add_after_then_move(srcline);
340 }
else if (srcbox.
left() + srcbox.
right() > chop_coord * 2
341 && srcbox.
left () > chop_coord - pitch_error) {
344 right_it->add_before_stay_put(srcline);
348 &left_frags, &right_frags)) {
349 for (child_it.mark_cycle_pt(); !child_it.cycled_list();
350 child_it.forward()) {
351 child = child_it.extract();
353 if (srcbox.
right() < chop_coord) {
355 left_ch_it.add_after_then_move(child);
356 }
else if (srcbox.
left() > chop_coord) {
358 right_ch_it.add_after_then_move (child);
363 &left_frags, &right_frags)) {
366 if (srcbox.
left() + srcbox.
right() <= chop_coord * 2)
367 left_ch_it.add_after_then_move(child);
369 right_ch_it.add_after_then_move(child);
380 if (srcbox.
left() + srcbox.
right() <= chop_coord * 2)
381 left_it->add_after_then_move(srcline);
383 right_it->add_before_stay_put(srcline);
401 C_OUTLINE_FRAG_LIST* left_frags,
402 C_OUTLINE_FRAG_LIST* right_frags
414 int16_t first_index = 0;
419 left_edge = pos.
x ();
422 for (stepindex = 0; stepindex < length; stepindex++) {
423 if (pos.
x () < left_edge) {
424 left_edge = pos.
x ();
425 tail_index = stepindex;
428 pos += srcline->
step (stepindex);
430 if (left_edge >= chop_coord - pitch_error)
433 startindex = tail_index;
435 head_index = tail_index;
439 tail_pos += srcline->
step (tail_index);
441 if (tail_index == length)
444 while (tail_pos.
x () != chop_coord && tail_index != startindex);
445 if (tail_index == startindex) {
461 first_index = tail_index;
462 first_pos = tail_pos;
465 while (srcline->
step (tail_index).
x () == 0) {
466 tail_pos += srcline->
step (tail_index);
468 if (tail_index == length)
471 head_index = tail_index;
473 while (srcline->
step (tail_index).
x () > 0) {
475 tail_pos += srcline->
step (tail_index);
477 if (tail_index == length)
480 while (tail_pos.
x () != chop_coord);
488 while (srcline->
step (tail_index).
x () == 0) {
489 tail_pos += srcline->
step (tail_index);
491 if (tail_index == length)
494 head_index = tail_index;
498 while (tail_index != startindex);
520 C_OUTLINE_FRAG_LIST *frags
530 stepcount = tail_index - head_index;
533 jump = tail_pos.
y () - head_pos.
y ();
536 if (jump == stepcount)
538 tail_y = tail_pos.
y ();
540 head_index, tail_index);
568 if (end_index > start_index) {
569 for (
int i = start_index; i < end_index; ++i)
578 for (; i < end_index + len; ++i)
607 C_OUTLINE_FRAG_LIST *frags
610 C_OUTLINE_FRAG_IT frag_it = frags;
612 if (!frags->empty ()) {
613 for (frag_it.mark_cycle_pt (); !frag_it.cycled_list ();
614 frag_it.forward ()) {
615 if (frag_it.data ()->ycoord > frag->
ycoord 616 || (frag_it.data ()->ycoord == frag->
ycoord 618 frag_it.add_before_then_move (frag);
623 frag_it.add_to_end (frag);
635 C_OUTLINE_FRAG_LIST *frags,
636 C_OUTLINE_LIST *children,
638 C_OUTLINE_IT *dest_it
641 C_OUTLINE_FRAG_IT frag_it = frags;
646 C_OUTLINE_IT child_it = children;
647 C_OUTLINE_IT olchild_it;
649 while (!frag_it.empty()) {
650 frag_it.move_to_first();
652 bottom_frag = frag_it.extract();
654 top_frag = frag_it.data();
655 if ((bottom_frag->
steps ==
nullptr && top_frag->
steps ==
nullptr)
656 || (bottom_frag->
steps !=
nullptr && top_frag->
steps !=
nullptr)) {
657 if (frag_it.data_relative(1)->ycoord == top_frag->
ycoord)
660 top_frag = frag_it.extract();
661 if (top_frag->
other_end != bottom_frag) {
666 if (outline !=
nullptr) {
667 olchild_it.set_to_list(outline->
child());
668 for (child_it.mark_cycle_pt(); !child_it.cycled_list();
669 child_it.forward()) {
670 child = child_it.data();
671 if (*child < *outline)
672 olchild_it.add_to_end(child_it.extract());
675 dest_it->add_after_then_move(outline);
681 while (!child_it.empty ()) {
682 dest_it->add_after_then_move (child_it.extract ());
702 if (bottom->
steps ==
nullptr)
703 outline = top->
close ();
705 outline = bottom->
close ();
710 if (bottom->
steps ==
nullptr) {
742 fake_count = top->
start.
y () - bottom->
end.
y ();
743 if (fake_count < 0) {
744 fake_count = -fake_count;
751 steps =
new DIR128[stepcount];
756 delete [] bottom->
steps;
757 bottom->
steps = steps;
772 int32_t new_stepcount;
778 if (fake_count < 0) {
779 fake_count = -fake_count;
788 new_steps =
new DIR128[new_stepcount];
C_OUTLINE_FRAG * other_end
void fixed_chop_cblob(C_BLOB *blob, int16_t chop_coord, float pitch_error, C_OUTLINE_LIST *left_outlines, C_OUTLINE_LIST *right_outlines)
EXTERN bool textord_show_page_cuts
#define double_VAR(name, val, comment)
TBOX bounding_box() const
int16_t y() const
access_function
void save_chop_cfragment(int16_t head_index, ICOORD head_pos, int16_t tail_index, ICOORD tail_pos, C_OUTLINE *srcline, C_OUTLINE_FRAG_LIST *frags)
void split_to_blob(BLOBNBOX *blob, int16_t chop_coord, float pitch_error, C_OUTLINE_LIST *left_coutlines, C_OUTLINE_LIST *right_coutlines)
const ICOORD & start_pos() const
EXTERN double textord_fp_chop_snap
void set_flag(WERD_FLAGS mask, bool value)
void plot_row_cells(ScrollView *win, ScrollView::Color colour, TO_ROW *row, float xshift, ICOORDELT_LIST *cells)
C_OUTLINE_FRAG & operator=(const C_OUTLINE_FRAG &src)
int16_t x() const
access function
C_OUTLINE * join_chopped_fragments(C_OUTLINE_FRAG *bottom, C_OUTLINE_FRAG *top)
void set_blanks(uint8_t new_blanks)
#define ELISTIZE(CLASSNAME)
int32_t pathlength() const
void add_frag_to_list(C_OUTLINE_FRAG *frag, C_OUTLINE_FRAG_LIST *frags)
const TBOX & bounding_box() const
DLLSYM void tprintf(const char *format,...)
EXTERN ScrollView * to_win
void recalc_bounding_box()
void fixed_split_coutline(C_OUTLINE *srcline, int16_t chop_coord, float pitch_error, C_OUTLINE_IT *left_it, C_OUTLINE_IT *right_it)
static const int kMaxOutlineLength
WERD * add_repeated_word(WERD_IT *rep_it, int16_t &rep_left, int16_t &prev_chop_coord, uint8_t &blanks, float pitch, WERD_IT *word_it)
void close_chopped_cfragments(C_OUTLINE_FRAG_LIST *frags, C_OUTLINE_LIST *children, float pitch_error, C_OUTLINE_IT *dest_it)
C_OUTLINE_LIST * out_list()
DIR128 step_dir(int index) const
EXTERN int textord_fp_chop_error
ROW * fixed_pitch_words(TO_ROW *row, FCOORD rotation)
void join_segments(C_OUTLINE_FRAG *bottom, C_OUTLINE_FRAG *top)
bool fixed_chop_coutline(C_OUTLINE *srcline, int16_t chop_coord, float pitch_error, C_OUTLINE_FRAG_LIST *left_frags, C_OUTLINE_FRAG_LIST *right_frags)
ICOORD step(int index) const
#define INT_VAR(name, val, comment)