874 WERD_IT word_it = row->word_list();
878 for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) {
879 word = word_it.data();
881 blob_count += word->cblob_list()->length();
883 if (blob_count == 0) {
887 std::vector<int32_t> xstarts(blob_count + row->baseline.segments + 1);
889 std::vector<double> coeffs((blob_count + row->baseline.segments) * 3);
893 xstarts[0] = row->baseline.xcoords[0];
894 for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) {
895 word = word_it.data();
897 blob_it.set_to_list(word->cblob_list());
898 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
899 blob = blob_it.data();
900 blob_box = blob->bounding_box();
901 x_centre = (blob_box.left() + blob_box.right()) / 2.0;
902 ydiff = blob_box.bottom() - row->base_line(x_centre);
904 ydiff = -ydiff / row->x_height();
906 ydiff = ydiff / row->x_height();
908 if (ydiff < blshift_maxshift && blob_box.height() / row->x_height() > blshift_xfraction) {
909 if (xstarts[dest_index] >= x_centre) {
910 xstarts[dest_index] = blob_box.left();
912 coeffs[dest_index * 3] = 0;
913 coeffs[dest_index * 3 + 1] = 0;
914 coeffs[dest_index * 3 + 2] = blob_box.bottom();
917 xstarts[dest_index] = blob_box.right() + 1;
919 if (xstarts[dest_index] <= x_centre) {
920 while (row->baseline.xcoords[src_index + 1] <= x_centre &&
921 src_index < row->
baseline.segments - 1) {
922 if (row->baseline.xcoords[src_index + 1] > xstarts[dest_index]) {
923 coeffs[dest_index * 3] = row->baseline.quadratics[src_index].a;
924 coeffs[dest_index * 3 + 1] = row->baseline.quadratics[src_index].b;
925 coeffs[dest_index * 3 + 2] = row->baseline.quadratics[src_index].c;
927 xstarts[dest_index] = row->baseline.xcoords[src_index + 1];
931 coeffs[dest_index * 3] = row->baseline.quadratics[src_index].a;
932 coeffs[dest_index * 3 + 1] = row->baseline.quadratics[src_index].b;
933 coeffs[dest_index * 3 + 2] = row->baseline.quadratics[src_index].c;
935 xstarts[dest_index] = row->baseline.xcoords[src_index + 1];
940 while (src_index < row->
baseline.segments &&
941 row->baseline.xcoords[src_index + 1] <= xstarts[dest_index]) {
944 while (src_index < row->
baseline.segments) {
945 coeffs[dest_index * 3] = row->baseline.quadratics[src_index].a;
946 coeffs[dest_index * 3 + 1] = row->baseline.quadratics[src_index].b;
947 coeffs[dest_index * 3 + 2] = row->baseline.quadratics[src_index].c;
950 xstarts[dest_index] = row->baseline.xcoords[src_index];
953 row->baseline =
QSPLINE(dest_index, &xstarts[0], &coeffs[0]);