Blame SOURCES/poppler-0.22.5-rotated-words-selection.patch

7677ed
--- poppler-0.22.5/poppler/TextOutputDev.cc
7677ed
+++ poppler-0.22.5/poppler/TextOutputDev.cc
7677ed
@@ -171,6 +171,12 @@
7677ed
 // Max distance between edge of text and edge of link border
7677ed
 #define hyperlinkSlack 2
7677ed
 
7677ed
+// Returns whether x is between a and b or equal to a or b.
7677ed
+// a and b don't need to be sorted.
7677ed
+#define XBetweenAB(x,a,b) (!(((x) > (a) && (x) > (b)) || \
7677ed
+                             ((x) < (a) && (x) < (b))) ? \
7677ed
+                           gTrue : gFalse)
7677ed
+
7677ed
 //------------------------------------------------------------------------
7677ed
 // TextUnderline
7677ed
 //------------------------------------------------------------------------
7677ed
@@ -4220,11 +4226,37 @@ void TextSelectionSizer::visitLine (Text
7677ed
   PDFRectangle *rect;
7677ed
   double x1, y1, x2, y2, margin;
7677ed
 
7677ed
-  margin = (line->yMax - line->yMin) / 8;
7677ed
-  x1 = line->edge[edge_begin];
7677ed
-  y1 = line->yMin - margin;
7677ed
-  x2 = line->edge[edge_end];
7677ed
-  y2 = line->yMax + margin;
7677ed
+  switch (line->rot) {
7677ed
+  default:
7677ed
+  case 0:
7677ed
+    margin = (line->yMax - line->yMin) / 8;
7677ed
+    x1 = line->edge[edge_begin];
7677ed
+    x2 = line->edge[edge_end];
7677ed
+    y1 = line->yMin - margin;
7677ed
+    y2 = line->yMax + margin;
7677ed
+    break;
7677ed
+  case 1:
7677ed
+    margin = (line->xMax - line->xMin) / 8;
7677ed
+    x1 = line->xMin - margin;
7677ed
+    x2 = line->xMax + margin;
7677ed
+    y1 = line->edge[edge_begin];
7677ed
+    y2 = line->edge[edge_end];
7677ed
+    break;
7677ed
+  case 2:
7677ed
+    margin = (line->yMax - line->yMin) / 8;
7677ed
+    x1 = line->edge[edge_end];
7677ed
+    x2 = line->edge[edge_begin];
7677ed
+    y1 = line->yMin - margin;
7677ed
+    y2 = line->yMax + margin;
7677ed
+    break;
7677ed
+  case 3:
7677ed
+    margin = (line->xMax - line->xMin) / 8;
7677ed
+    x1 = line->xMin - margin;
7677ed
+    x2 = line->xMax + margin;
7677ed
+    y1 = line->edge[edge_end];
7677ed
+    y2 = line->edge[edge_begin];
7677ed
+    break;
7677ed
+  }
7677ed
 
7677ed
   rect = new PDFRectangle (floor (x1 * scale), 
7677ed
 			   floor (y1 * scale),
7677ed
@@ -4304,22 +4336,59 @@ void TextSelectionPainter::visitLine (Te
7677ed
   state->setFillColor(box_color);
7677ed
   out->updateFillColor(state);
7677ed
 
7677ed
-  margin = (line->yMax - line->yMin) / 8;
7677ed
-  x1 = floor (line->edge[edge_begin]);
7677ed
-  y1 = floor (line->yMin - margin);
7677ed
-  x2 = ceil (line->edge[edge_end]);
7677ed
-  y2 = ceil (line->yMax + margin);
7677ed
-
7677ed
   state->getCTM (&ctm;;
7677ed
-  ctm.transform(line->edge[edge_begin], line->yMin - margin, &x1, &y1;;
7677ed
-  ctm.transform(line->edge[edge_end], line->yMax + margin, &x2, &y2;;
7677ed
+  ctm.invertTo (&ictm);
7677ed
 
7677ed
-  x1 = floor (x1);
7677ed
-  y1 = floor (y1);
7677ed
-  x2 = ceil (x2);
7677ed
-  y2 = ceil (y2);
7677ed
+  switch (line->rot) {
7677ed
+  case 0:
7677ed
+    margin = (line->yMax - line->yMin) / 8;
7677ed
+    x1 = line->edge[edge_begin];
7677ed
+    x2 = line->edge[edge_end];
7677ed
+    y1 = line->yMin - margin;
7677ed
+    y2 = line->yMax + margin;
7677ed
+    break;
7677ed
+  case 1:
7677ed
+    margin = (line->xMax - line->xMin) / 8;
7677ed
+    x1 = line->xMin - margin;
7677ed
+    x2 = line->xMax + margin;
7677ed
+    y1 = line->edge[edge_begin];
7677ed
+    y2 = line->edge[edge_end];
7677ed
+    break;
7677ed
+  case 2:
7677ed
+    margin = (line->yMax - line->yMin) / 8;
7677ed
+    x1 = line->edge[edge_end];
7677ed
+    x2 = line->edge[edge_begin];
7677ed
+    y1 = line->yMin - margin;
7677ed
+    y2 = line->yMax + margin;
7677ed
+    break;
7677ed
+  case 3:
7677ed
+    margin = (line->xMax - line->xMin) / 8;
7677ed
+    x1 = line->xMin - margin;
7677ed
+    x2 = line->xMax + margin;
7677ed
+    y1 = line->edge[edge_end];
7677ed
+    y2 = line->edge[edge_begin];
7677ed
+    break;
7677ed
+  }
7677ed
+
7677ed
+  ctm.transform(x1, y1, &x1, &y1;;
7677ed
+  ctm.transform(x2, y2, &x2, &y2;;
7677ed
+
7677ed
+  if (x1 < x2) {
7677ed
+    x1 = floor (x1);
7677ed
+    x2 = ceil (x2);
7677ed
+  } else {
7677ed
+    x1 = ceil (x1);
7677ed
+    x2 = floor (x2);
7677ed
+  }
7677ed
+
7677ed
+  if (y1 < y2) {
7677ed
+    y1 = floor (y1);
7677ed
+    y2 = ceil (y2);
7677ed
+  } else {
7677ed
+    y1 = ceil (y1);
7677ed
+    y2 = floor (y2);
7677ed
+  }
7677ed
 
7677ed
-  ctm.invertTo (&ictm);
7677ed
   ictm.transform(x1, y1, &x1, &y1;;
7677ed
   ictm.transform(x2, y2, &x2, &y2;;
7677ed
 
7677ed
@@ -4376,17 +4445,27 @@ void TextWord::visitSelection(TextSelect
7677ed
 			      SelectionStyle style)
7677ed
 {
7677ed
   int i, begin, end;
7677ed
-  double mid;
7677ed
+  double mid, s1, s2;
7677ed
+
7677ed
+  if (rot == 0 || rot == 2) {
7677ed
+    s1 = selection->x1;
7677ed
+    s2 = selection->x2;
7677ed
+  } else {
7677ed
+    s1 = selection->y1;
7677ed
+    s2 = selection->y2;
7677ed
+  }
7677ed
 
7677ed
   begin = len;
7677ed
   end = 0;
7677ed
   for (i = 0; i < len; i++) {
7677ed
     mid = (edge[i] + edge[i + 1]) / 2;
7677ed
-    if (selection->x1 < mid || selection->x2 < mid)
7677ed
-      if (i < begin)
7677ed
-	begin = i;
7677ed
-    if (mid < selection->x1 || mid < selection->x2)
7677ed
-      end = i + 1;
7677ed
+    if (XBetweenAB (mid, s1, s2))
7677ed
+      {
7677ed
+        if (i < begin)
7677ed
+          begin = i;
7677ed
+
7677ed
+        end = i + 1;
7677ed
+      }
7677ed
   }
7677ed
 
7677ed
   /* Skip empty selection. */
7677ed
@@ -4402,30 +4481,41 @@ void TextLine::visitSelection(TextSelect
7677ed
   TextWord *p, *begin, *end, *current;
7677ed
   int i, edge_begin, edge_end;
7677ed
   PDFRectangle child_selection;
7677ed
+  double s1, s2, p_min, p_max;
7677ed
+
7677ed
+  if (rot == 0 || rot == 2) {
7677ed
+    s1 = selection->x1;
7677ed
+    s2 = selection->x2;
7677ed
+  } else {
7677ed
+    s1 = selection->y1;
7677ed
+    s2 = selection->y2;
7677ed
+  }
7677ed
 
7677ed
   begin = NULL;
7677ed
   end = NULL;
7677ed
   current = NULL;
7677ed
   for (p = words; p != NULL; p = p->next) {
7677ed
+    if (rot == 0 || rot == 2) {
7677ed
+      p_min = p->xMin;
7677ed
+      p_max = p->xMax;
7677ed
+    } else {
7677ed
+      p_min = p->yMin;
7677ed
+      p_max = p->yMax;
7677ed
+    }
7677ed
+
7677ed
     if (blk->page->primaryLR) {
7677ed
-      if ((selection->x1 < p->xMax) ||
7677ed
-	  (selection->x2 < p->xMax))
7677ed
-        if (begin == NULL) 
7677ed
-	  begin = p;
7677ed
+      if (((s1 < p_max) || (s2 < p_max)) && begin == NULL)
7677ed
+        begin = p;
7677ed
 
7677ed
-      if (((selection->x1 > p->xMin) ||
7677ed
-	   (selection->x2 > p->xMin)) && (begin != NULL)) {
7677ed
+      if (((s1 > p_min) || (s2 > p_min)) && begin != NULL) {
7677ed
         end = p->next;
7677ed
         current = p;
7677ed
       }
7677ed
     } else {
7677ed
-      if ((selection->x1 > p->xMin) ||
7677ed
-	  (selection->x2 > p->xMin))
7677ed
-        if (begin == NULL) 
7677ed
-	  begin = p;
7677ed
+      if (((s1 > p_min) || (s2 > p_min)) && begin == NULL)
7677ed
+        begin = p;
7677ed
 
7677ed
-      if (((selection->x1 < p->xMax) ||
7677ed
-	   (selection->x2 < p->xMax)) && (begin != NULL)) {
7677ed
+      if (((s1 < p_max) || (s2 < p_max)) && begin != NULL) {
7677ed
         end = p->next;
7677ed
         current = p;
7677ed
       }
7677ed
@@ -4437,23 +4527,42 @@ void TextLine::visitSelection(TextSelect
7677ed
   
7677ed
   child_selection = *selection;
7677ed
   if (style == selectionStyleWord) {
7677ed
-    child_selection.x1 = begin ? begin->xMin : xMin;
7677ed
-    if (end && end->xMax != -1) {
7677ed
-      child_selection.x2 = current->xMax;
7677ed
+    if (rot == 0 || rot == 2) {
7677ed
+      child_selection.x1 = begin ? begin->xMin : xMin;
7677ed
+      if (end && end->xMax != -1) {
7677ed
+        child_selection.x2 = current->xMax;
7677ed
+      } else {
7677ed
+        child_selection.x2 = xMax;
7677ed
+      }
7677ed
     } else {
7677ed
-      child_selection.x2 = xMax;
7677ed
+      child_selection.y1 = begin ? begin->yMin : yMin;
7677ed
+      if (end && end->yMax != -1) {
7677ed
+        child_selection.y2 = current->yMax;
7677ed
+      } else {
7677ed
+        child_selection.y2 = yMax;
7677ed
+      }
7677ed
     }
7677ed
   }
7677ed
 
7677ed
+  if (rot == 0 || rot == 2) {
7677ed
+    s1 = child_selection.x1;
7677ed
+    s2 = child_selection.x2;
7677ed
+  } else {
7677ed
+    s1 = child_selection.y1;
7677ed
+    s2 = child_selection.y2;
7677ed
+  }
7677ed
+
7677ed
   edge_begin = len;
7677ed
   edge_end = 0;
7677ed
   for (i = 0; i < len; i++) {
7677ed
     double mid = (edge[i] + edge[i + 1]) /  2;
7677ed
-    if (child_selection.x1 < mid || child_selection.x2 < mid)
7677ed
-      if (i < edge_begin)
7677ed
-	edge_begin = i;
7677ed
-    if (mid < child_selection.x2 || mid < child_selection.x1)
7677ed
-      edge_end = i + 1;
7677ed
+    if (XBetweenAB (mid, s1, s2))
7677ed
+      {
7677ed
+        if (i < edge_begin)
7677ed
+          edge_begin = i;
7677ed
+
7677ed
+        edge_end = i + 1;
7677ed
+      }
7677ed
   }
7677ed
 
7677ed
   /* Skip empty selection. */