[poppler] poppler/poppler: TextOutputDev.cc,1.2,1.3
Kristian Hogsberg
krh at freedesktop.org
Thu Jun 30 21:57:51 PDT 2005
Update of /cvs/poppler/poppler/poppler
In directory gabe:/tmp/cvs-serv22428/poppler
Modified Files:
TextOutputDev.cc
Log Message:
2005-07-01 Kristian Høgsberg <krh at redhat.com>
* poppler/TextOutputDev.cc: Make selection also work when dragging
backwards in the text flow. Currently this is a big pile of
if-statements, and there is certainly room for improvement.
Index: TextOutputDev.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/TextOutputDev.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- TextOutputDev.cc 29 Jun 2005 21:24:57 -0000 1.2
+++ TextOutputDev.cc 1 Jul 2005 04:57:49 -0000 1.3
@@ -3200,9 +3200,10 @@
y2 = ceil (line->yMax + margin);
for (i = 0; i < line->len; i++) {
- if (selection->x1 < line->edge[i + 1] && line->edge[i] < x1)
- x1 = floor (line->edge[i]);
- if (line->edge[i] < selection->x2)
+ if (selection->x1 < line->edge[i + 1] || selection->x2 < line->edge[i + 1])
+ if (line->edge[i] < x1)
+ x1 = floor (line->edge[i]);
+ if (line->edge[i] < selection->x2 || line->edge[i] < selection->x1)
x2 = ceil (line->edge[i + 1]);
}
@@ -3248,9 +3249,10 @@
begin = len + 1;
end = 0;
for (i = 0; i < len; i++) {
- if (selection->x1 < edge[i + 1] && i < begin)
- begin = i;
- if (edge[i] < selection->x2)
+ if (selection->x1 < edge[i + 1] || selection->x2 < edge[i + 1])
+ if (i < begin)
+ begin = i;
+ if (edge[i] < selection->x1 || edge[i] < selection->x2)
end = i + 1;
}
@@ -3264,9 +3266,12 @@
begin = NULL;
end = NULL;
for (p = words; p != NULL; p = p->next) {
- if (selection->x1 < p->xMax && selection->y1 < p->yMax && begin == NULL)
- begin = p;
- if (selection->x2 > p->xMin && selection->y2 > p->yMin)
+ if ((selection->x1 < p->xMax && selection->y1 < p->yMax) ||
+ (selection->x2 < p->xMax && selection->y2 < p->yMax))
+ if (begin == NULL)
+ begin = p;
+ if ((selection->x1 > p->xMin && selection->y1 > p->yMin) ||
+ (selection->x2 > p->xMin && selection->y2 > p->yMin))
end = p->next;
}
@@ -3280,29 +3285,65 @@
PDFRectangle *selection) {
TextLine *p, *begin, *end;
PDFRectangle child_selection;
+ double start_x, start_y, stop_x, stop_y;
begin = NULL;
end = NULL;
for (p = lines; p != NULL; p = p->next) {
- if (selection->x1 < p->xMax && selection->y1 < p->yMax && begin == NULL)
+ if (selection->x1 < p->xMax && selection->y1 < p->yMax &&
+ selection->x2 < p->xMax && selection->y2 < p->yMax && begin == NULL) {
begin = p;
- if (selection->x2 > p->xMin && selection->y2 > p->yMin)
+ if (selection->x1 < selection->x2) {
+ start_x = selection->x1;
+ start_y = selection->y1;
+ } else {
+ start_x = selection->x2;
+ start_y = selection->y2;
+ }
+ } else if (selection->x1 < p->xMax && selection->y1 < p->yMax && begin == NULL) {
+ begin = p;
+ start_x = selection->x1;
+ start_y = selection->y1;
+ } else if (selection->x2 < p->xMax && selection->y2 < p->yMax && begin == NULL) {
+ begin = p;
+ start_x = selection->x2;
+ start_y = selection->y2;
+ }
+
+ if (selection->x1 > p->xMin && selection->y1 > p->yMin &&
+ selection->x2 > p->xMin && selection->y2 > p->yMin) {
+ end = p->next;
+ if (selection->x2 < selection->x1) {
+ stop_x = selection->x1;
+ stop_y = selection->y1;
+ } else {
+ stop_x = selection->x2;
+ stop_y = selection->y2;
+ }
+ } else if (selection->x1 > p->xMin && selection->y1 > p->yMin) {
+ end = p->next;
+ stop_x = selection->x1;
+ stop_y = selection->y1;
+ } else if (selection->x2 > p->xMin && selection->y2 > p->yMin) {
end = p->next;
+ stop_x = selection->x2;
+ stop_y = selection->y2;
+ }
}
visitor->visitBlock (this, begin, end, selection);
for (p = begin; p != end; p = p->next) {
if (p == begin) {
- child_selection.x1 = selection->x1;
- child_selection.y1 = selection->y1;
+ child_selection.x1 = start_x;
+ child_selection.y1 = start_y;
} else {
child_selection.x1 = 0;
child_selection.y1 = 0;
}
if (p->next == end) {
- child_selection.x2 = selection->x2;
- child_selection.y2 = selection->y2;
+ child_selection.x2 = stop_x;
+ child_selection.y2 = stop_y;
} else {
child_selection.x2 = page->pageWidth;
child_selection.y2 = page->pageHeight;
@@ -3317,28 +3358,68 @@
{
int i, begin, end;
PDFRectangle child_selection;
+ double start_x, start_y, stop_x, stop_y;
+ TextBlock *b;
begin = nBlocks;
end = 0;
for (i = 0; i < nBlocks; i++) {
- if (selection->x1 < blocks[i]->xMax &&
- selection->y1 < blocks[i]->yMax && i < begin)
+ b = blocks[i];
+
+ if (selection->x1 < b->xMax && selection->y1 < b->yMax &&
+ selection->x2 < b->xMax && selection->y2 < b->yMax && i < begin) {
begin = i;
- if (selection->x2 > blocks[i]->xMin && selection->y2 > blocks[i]->yMin)
+ if (selection->y1 < selection->y2) {
+ start_x = selection->x1;
+ start_y = selection->y1;
+ } else {
+ start_x = selection->x2;
+ start_y = selection->y2;
+ }
+ } else if (selection->x1 < b->xMax && selection->y1 < b->yMax && i < begin) {
+ begin = i;
+ start_x = selection->x1;
+ start_y = selection->y1;
+ } else if (selection->x2 < b->xMax && selection->y2 < b->yMax && i < begin) {
+ begin = i;
+ start_x = selection->x2;
+ start_y = selection->y2;
+ }
+
+ if (selection->x1 > b->xMin && selection->y1 > b->yMin &&
+ selection->x2 > b->xMin && selection->y2 > b->yMin) {
+ end = i + 1;
+ if (selection->y2 < selection->y1) {
+ stop_x = selection->x1;
+ stop_y = selection->y1;
+ } else {
+ stop_x = selection->x2;
+ stop_y = selection->y2;
+ }
+ } else if (selection->x1 > b->xMin && selection->y1 > b->yMin) {
+ end = i + 1;
+ stop_x = selection->x1;
+ stop_y = selection->y1;
+ } else if (selection->x2 > b->xMin && selection->y2 > b->yMin) {
end = i + 1;
+ stop_x = selection->x2;
+ stop_y = selection->y2;
+ }
}
for (i = begin; i < end; i++) {
- if (i == begin) {
- child_selection.x1 = selection->x1;
- child_selection.y1 = selection->y1;
+ if (blocks[i]->xMin < start_x && start_x < blocks[i]->xMax &&
+ blocks[i]->yMin < start_y && start_y < blocks[i]->yMax) {
+ child_selection.x1 = start_x;
+ child_selection.y1 = start_y;
} else {
child_selection.x1 = 0;
child_selection.y1 = 0;
}
- if (i + 1 == end) {
- child_selection.x2 = selection->x2;
- child_selection.y2 = selection->y2;
+ if (blocks[i]->xMin < stop_x && stop_x < blocks[i]->xMax &&
+ blocks[i]->yMin < stop_y && stop_y < blocks[i]->yMax) {
+ child_selection.x2 = stop_x;
+ child_selection.y2 = stop_y;
} else {
child_selection.x2 = pageWidth;
child_selection.y2 = pageHeight;
More information about the poppler
mailing list