--- TextOutputDev-old.cc 2006-09-20 20:53:32.000000000 -0400 +++ TextOutputDev.cc 2006-10-29 12:56:10.000000000 -0500 @@ -2661,6 +2661,7 @@ double xMin0, yMin0, xMax0, yMax0; double xMin1, yMin1, xMax1, yMax1; GBool found; + GBool searchBackwards; //depending on rotation //~ needs to handle right-to-left text @@ -2716,6 +2717,12 @@ break; } + // check: is the block past what I've already found? + if (found && (backward? blk->yMax < yMin0 : blk->yMin > yMax0)) { + //blocks are in yx order so it's safe to suicide + break; + } + for (line = blk->lines; line; line = line->next) { // check: is the line above the top limit? @@ -2727,7 +2734,18 @@ // check: is the line below the bottom limit? if (!stopAtBottom && (backward ? line->yMin < yStop : line->yMin > yStop)) { - continue; + if (backward) //wrong order + continue; + else + break; + } + + // check: is the line past what I've already found? + if (found && (backward? line->yMax < yMin0 : line->yMin > yMax0)) { + if (backward) //wrong order + continue; + else + break; } if (!line->normalized) @@ -2748,10 +2766,13 @@ txt = line->normalized; } + // do we search forwards or backwards? + searchBackwards = (line->rot < 2 && backward) || (line->rot >= 2 && !backward); + // search each position in this line - j = backward ? m - len : 0; + j = searchBackwards ? m - len : 0; p = txt + j; - while (backward ? j >= 0 : j <= m - len) { + while (searchBackwards ? j >= 0 : j <= m - len) { // compare the strings for (k = 0; k < len; ++k) { @@ -2800,6 +2821,8 @@ yMin0 = yMin1; yMax0 = yMax1; found = gTrue; + + break; //searchBackwards allowed us to suicide, so we might as well } } } else { @@ -2814,6 +2837,8 @@ yMin0 = yMin1; yMax0 = yMax1; found = gTrue; + + break; //searchBackwards allowed us to suicide, so we might as well } } }