Skip to content

Commit d8ab3b1

Browse files
committed
Revert "TextOutputDev: Respect orientation when selecting words"
This reverts commit a4e927b.
1 parent 45d43f4 commit d8ab3b1

1 file changed

Lines changed: 37 additions & 140 deletions

File tree

poppler/TextOutputDev.cc

Lines changed: 37 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ double TextOutputDev::minColSpacing1_default = 0.7;
194194
// to read the underlying image. Issue #157
195195
#define glyphlessSelectionOpacity 0.4
196196

197-
// Returns whether x is between a and b or equal to a or b.
198-
// a and b don't need to be sorted.
199-
#define XBetweenAB(x, a, b) (!(((x) > (a) && (x) > (b)) || ((x) < (a) && (x) < (b))) ? true : false)
200-
201197
namespace {
202198

203199
inline bool isAscii7(Unicode uchar)
@@ -4619,37 +4615,11 @@ void TextSelectionSizer::visitLine(TextLine *line, TextWord *begin, TextWord *en
46194615
PDFRectangle *rect;
46204616
double x1, y1, x2, y2, margin;
46214617

4622-
switch (line->rot) {
4623-
default:
4624-
case 0:
4625-
margin = (line->yMax - line->yMin) / 8;
4626-
x1 = line->edge[edge_begin];
4627-
x2 = line->edge[edge_end];
4628-
y1 = line->yMin - margin;
4629-
y2 = line->yMax + margin;
4630-
break;
4631-
case 1:
4632-
margin = (line->xMax - line->xMin) / 8;
4633-
x1 = line->xMin - margin;
4634-
x2 = line->xMax + margin;
4635-
y1 = line->edge[edge_begin];
4636-
y2 = line->edge[edge_end];
4637-
break;
4638-
case 2:
4639-
margin = (line->yMax - line->yMin) / 8;
4640-
x1 = line->edge[edge_end];
4641-
x2 = line->edge[edge_begin];
4642-
y1 = line->yMin - margin;
4643-
y2 = line->yMax + margin;
4644-
break;
4645-
case 3:
4646-
margin = (line->xMax - line->xMin) / 8;
4647-
x1 = line->xMin - margin;
4648-
x2 = line->xMax + margin;
4649-
y1 = line->edge[edge_end];
4650-
y2 = line->edge[edge_begin];
4651-
break;
4652-
}
4618+
margin = (line->yMax - line->yMin) / 8;
4619+
x1 = line->edge[edge_begin];
4620+
y1 = line->yMin - margin;
4621+
x2 = line->edge[edge_end];
4622+
y2 = line->yMax + margin;
46534623

46544624
rect = new PDFRectangle(floor(x1 * scale), floor(y1 * scale), ceil(x2 * scale), ceil(y2 * scale));
46554625
list->push_back(rect);
@@ -4709,56 +4679,19 @@ void TextSelectionPainter::visitLine(TextLine *line, TextWord *begin, TextWord *
47094679
{
47104680
double x1, y1, x2, y2, margin;
47114681

4712-
switch (line->rot) {
4713-
default:
4714-
case 0:
4715-
margin = (line->yMax - line->yMin) / 8;
4716-
x1 = line->edge[edge_begin];
4717-
x2 = line->edge[edge_end];
4718-
y1 = line->yMin - margin;
4719-
y2 = line->yMax + margin;
4720-
break;
4721-
case 1:
4722-
margin = (line->xMax - line->xMin) / 8;
4723-
x1 = line->xMin - margin;
4724-
x2 = line->xMax + margin;
4725-
y1 = line->edge[edge_begin];
4726-
y2 = line->edge[edge_end];
4727-
break;
4728-
case 2:
4729-
margin = (line->yMax - line->yMin) / 8;
4730-
x1 = line->edge[edge_end];
4731-
x2 = line->edge[edge_begin];
4732-
y1 = line->yMin - margin;
4733-
y2 = line->yMax + margin;
4734-
break;
4735-
case 3:
4736-
margin = (line->xMax - line->xMin) / 8;
4737-
x1 = line->xMin - margin;
4738-
x2 = line->xMax + margin;
4739-
y1 = line->edge[edge_end];
4740-
y2 = line->edge[edge_begin];
4741-
break;
4742-
}
4743-
4744-
ctm.transform(x1, y1, &x1, &y1);
4745-
ctm.transform(x2, y2, &x2, &y2);
4682+
margin = (line->yMax - line->yMin) / 8;
4683+
x1 = floor(line->edge[edge_begin]);
4684+
y1 = floor(line->yMin - margin);
4685+
x2 = ceil(line->edge[edge_end]);
4686+
y2 = ceil(line->yMax + margin);
47464687

4747-
if (x1 < x2) {
4748-
x1 = floor(x1);
4749-
x2 = ceil(x2);
4750-
} else {
4751-
x1 = ceil(x1);
4752-
x2 = floor(x2);
4753-
}
4688+
ctm.transform(line->edge[edge_begin], line->yMin - margin, &x1, &y1);
4689+
ctm.transform(line->edge[edge_end], line->yMax + margin, &x2, &y2);
47544690

4755-
if (y1 < y2) {
4756-
y1 = floor(y1);
4757-
y2 = ceil(y2);
4758-
} else {
4759-
y1 = ceil(y1);
4760-
y2 = floor(y2);
4761-
}
4691+
x1 = floor(x1);
4692+
y1 = floor(y1);
4693+
x2 = ceil(x2);
4694+
y2 = ceil(y2);
47624695

47634696
ictm.transform(x1, y1, &x1, &y1);
47644697
ictm.transform(x2, y2, &x2, &y2);
@@ -4857,15 +4790,7 @@ void TextSelectionPainter::endPage()
48574790

48584791
void TextWord::visitSelection(TextSelectionVisitor *visitor, const PDFRectangle *selection, SelectionStyle style)
48594792
{
4860-
double mid, s1, s2;
4861-
4862-
if (rot == 0 || rot == 2) {
4863-
s1 = selection->x1;
4864-
s2 = selection->x2;
4865-
} else {
4866-
s1 = selection->y1;
4867-
s2 = selection->y2;
4868-
}
4793+
double mid;
48694794

48704795
size_t begin = len();
48714796
size_t end = 0;
@@ -4875,11 +4800,12 @@ void TextWord::visitSelection(TextSelectionVisitor *visitor, const PDFRectangle
48754800
} else {
48764801
mid = (chars[i].edge + edgeEnd) / 2;
48774802
}
4878-
if (XBetweenAB(mid, s1, s2)) {
4803+
if (selection->x1 < mid || selection->x2 < mid) {
48794804
if (i < begin) {
48804805
begin = i;
48814806
}
4882-
4807+
}
4808+
if (mid < selection->x1 || mid < selection->x2) {
48834809
end = i + 1;
48844810
}
48854811
}
@@ -4897,43 +4823,30 @@ void TextLine::visitSelection(TextSelectionVisitor *visitor, const PDFRectangle
48974823
TextWord *p, *begin, *end, *current;
48984824
int i, edge_begin, edge_end;
48994825
PDFRectangle child_selection;
4900-
double s1, s2, pMin, pMax;
4901-
4902-
if (rot == 0 || rot == 2) {
4903-
s1 = selection->x1;
4904-
s2 = selection->x2;
4905-
} else {
4906-
s1 = selection->y1;
4907-
s2 = selection->y2;
4908-
}
49094826

49104827
begin = nullptr;
49114828
end = nullptr;
49124829
current = nullptr;
49134830
for (p = words; p != nullptr; p = p->next) {
4914-
if (rot == 0 || rot == 2) {
4915-
pMin = p->xMin;
4916-
pMax = p->xMax;
4917-
} else {
4918-
pMin = p->yMin;
4919-
pMax = p->yMax;
4920-
}
4921-
49224831
if (blk->page->primaryLR) {
4923-
if (((s1 < pMax) || (s2 < pMax)) && begin == nullptr) {
4924-
begin = p;
4832+
if ((selection->x1 < p->xMax) || (selection->x2 < p->xMax)) {
4833+
if (begin == nullptr) {
4834+
begin = p;
4835+
}
49254836
}
49264837

4927-
if (((s1 > pMin) || (s2 > pMin)) && begin != nullptr) {
4838+
if (((selection->x1 > p->xMin) || (selection->x2 > p->xMin)) && (begin != nullptr)) {
49284839
end = p->next;
49294840
current = p;
49304841
}
49314842
} else {
4932-
if (((s1 > pMin) || (s2 > pMin)) && begin == nullptr) {
4933-
begin = p;
4843+
if ((selection->x1 > p->xMin) || (selection->x2 > p->xMin)) {
4844+
if (begin == nullptr) {
4845+
begin = p;
4846+
}
49344847
}
49354848

4936-
if (((s1 < pMax) || (s2 < pMax)) && begin != nullptr) {
4849+
if (((selection->x1 < p->xMax) || (selection->x2 < p->xMax)) && (begin != nullptr)) {
49374850
end = p->next;
49384851
current = p;
49394852
}
@@ -4946,40 +4859,24 @@ void TextLine::visitSelection(TextSelectionVisitor *visitor, const PDFRectangle
49464859

49474860
child_selection = *selection;
49484861
if (style == selectionStyleWord) {
4949-
if (rot == 0 || rot == 2) {
4950-
child_selection.x1 = begin ? begin->xMin : xMin;
4951-
if (end && end->xMax != -1) {
4952-
child_selection.x2 = current->xMax;
4953-
} else {
4954-
child_selection.x2 = xMax;
4955-
}
4862+
child_selection.x1 = begin ? begin->xMin : xMin;
4863+
if (end && end->xMax != -1) {
4864+
child_selection.x2 = current->xMax;
49564865
} else {
4957-
child_selection.y1 = begin ? begin->yMin : yMin;
4958-
if (end && end->yMax != -1) {
4959-
child_selection.y2 = current->yMax;
4960-
} else {
4961-
child_selection.y2 = yMax;
4962-
}
4866+
child_selection.x2 = xMax;
49634867
}
49644868
}
49654869

4966-
if (rot == 0 || rot == 2) {
4967-
s1 = child_selection.x1;
4968-
s2 = child_selection.x2;
4969-
} else {
4970-
s1 = child_selection.y1;
4971-
s2 = child_selection.y2;
4972-
}
4973-
49744870
edge_begin = len;
49754871
edge_end = 0;
49764872
for (i = 0; i < len; i++) {
49774873
double mid = (edge[i] + edge[i + 1]) / 2;
4978-
if (XBetweenAB(mid, s1, s2)) {
4874+
if (child_selection.x1 < mid || child_selection.x2 < mid) {
49794875
if (i < edge_begin) {
49804876
edge_begin = i;
49814877
}
4982-
4878+
}
4879+
if (mid < child_selection.x2 || mid < child_selection.x1) {
49834880
edge_end = i + 1;
49844881
}
49854882
}

0 commit comments

Comments
 (0)