@@ -189,10 +189,6 @@ double TextOutputDev::minColSpacing1_default = 0.7;
189189// to read the underlying image. Issue #157
190190#define glyphlessSelectionOpacity 0.4
191191
192- // Returns whether x is between a and b or equal to a or b.
193- // a and b don't need to be sorted.
194- #define XBetweenAB (x, a, b ) (!(((x) > (a) && (x) > (b)) || ((x) < (a) && (x) < (b))) ? true : false )
195-
196192namespace {
197193
198194inline bool isAscii7 (Unicode uchar)
@@ -4560,37 +4556,11 @@ void TextSelectionSizer::visitLine(TextLine *line, TextWord *begin, TextWord *en
45604556 PDFRectangle *rect;
45614557 double x1, y1, x2, y2, margin;
45624558
4563- switch (line->rot ) {
4564- default :
4565- case 0 :
4566- margin = (line->yMax - line->yMin ) / 8 ;
4567- x1 = line->edge [edge_begin];
4568- x2 = line->edge [edge_end];
4569- y1 = line->yMin - margin;
4570- y2 = line->yMax + margin;
4571- break ;
4572- case 1 :
4573- margin = (line->xMax - line->xMin ) / 8 ;
4574- x1 = line->xMin - margin;
4575- x2 = line->xMax + margin;
4576- y1 = line->edge [edge_begin];
4577- y2 = line->edge [edge_end];
4578- break ;
4579- case 2 :
4580- margin = (line->yMax - line->yMin ) / 8 ;
4581- x1 = line->edge [edge_end];
4582- x2 = line->edge [edge_begin];
4583- y1 = line->yMin - margin;
4584- y2 = line->yMax + margin;
4585- break ;
4586- case 3 :
4587- margin = (line->xMax - line->xMin ) / 8 ;
4588- x1 = line->xMin - margin;
4589- x2 = line->xMax + margin;
4590- y1 = line->edge [edge_end];
4591- y2 = line->edge [edge_begin];
4592- break ;
4593- }
4559+ margin = (line->yMax - line->yMin ) / 8 ;
4560+ x1 = line->edge [edge_begin];
4561+ y1 = line->yMin - margin;
4562+ x2 = line->edge [edge_end];
4563+ y2 = line->yMax + margin;
45944564
45954565 rect = new PDFRectangle (floor (x1 * scale), floor (y1 * scale), ceil (x2 * scale), ceil (y2 * scale));
45964566 list->push_back (rect);
@@ -4647,56 +4617,19 @@ void TextSelectionPainter::visitLine(TextLine *line, TextWord *begin, TextWord *
46474617{
46484618 double x1, y1, x2, y2, margin;
46494619
4650- switch (line->rot ) {
4651- default :
4652- case 0 :
4653- margin = (line->yMax - line->yMin ) / 8 ;
4654- x1 = line->edge [edge_begin];
4655- x2 = line->edge [edge_end];
4656- y1 = line->yMin - margin;
4657- y2 = line->yMax + margin;
4658- break ;
4659- case 1 :
4660- margin = (line->xMax - line->xMin ) / 8 ;
4661- x1 = line->xMin - margin;
4662- x2 = line->xMax + margin;
4663- y1 = line->edge [edge_begin];
4664- y2 = line->edge [edge_end];
4665- break ;
4666- case 2 :
4667- margin = (line->yMax - line->yMin ) / 8 ;
4668- x1 = line->edge [edge_end];
4669- x2 = line->edge [edge_begin];
4670- y1 = line->yMin - margin;
4671- y2 = line->yMax + margin;
4672- break ;
4673- case 3 :
4674- margin = (line->xMax - line->xMin ) / 8 ;
4675- x1 = line->xMin - margin;
4676- x2 = line->xMax + margin;
4677- y1 = line->edge [edge_end];
4678- y2 = line->edge [edge_begin];
4679- break ;
4680- }
4681-
4682- ctm.transform (x1, y1, &x1, &y1);
4683- ctm.transform (x2, y2, &x2, &y2);
4620+ margin = (line->yMax - line->yMin ) / 8 ;
4621+ x1 = floor (line->edge [edge_begin]);
4622+ y1 = floor (line->yMin - margin);
4623+ x2 = ceil (line->edge [edge_end]);
4624+ y2 = ceil (line->yMax + margin);
46844625
4685- if (x1 < x2) {
4686- x1 = floor (x1);
4687- x2 = ceil (x2);
4688- } else {
4689- x1 = ceil (x1);
4690- x2 = floor (x2);
4691- }
4626+ ctm.transform (line->edge [edge_begin], line->yMin - margin, &x1, &y1);
4627+ ctm.transform (line->edge [edge_end], line->yMax + margin, &x2, &y2);
46924628
4693- if (y1 < y2) {
4694- y1 = floor (y1);
4695- y2 = ceil (y2);
4696- } else {
4697- y1 = ceil (y1);
4698- y2 = floor (y2);
4699- }
4629+ x1 = floor (x1);
4630+ y1 = floor (y1);
4631+ x2 = ceil (x2);
4632+ y2 = ceil (y2);
47004633
47014634 ictm.transform (x1, y1, &x1, &y1);
47024635 ictm.transform (x2, y2, &x2, &y2);
@@ -4784,26 +4717,17 @@ void TextSelectionPainter::endPage()
47844717void TextWord::visitSelection (TextSelectionVisitor *visitor, const PDFRectangle *selection, SelectionStyle style)
47854718{
47864719 int i, begin, end;
4787- double mid, s1, s2;
4788-
4789- if (rot == 0 || rot == 2 ) {
4790- s1 = selection->x1 ;
4791- s2 = selection->x2 ;
4792- } else {
4793- s1 = selection->y1 ;
4794- s2 = selection->y2 ;
4795- }
4720+ double mid;
47964721
47974722 begin = len;
47984723 end = 0 ;
47994724 for (i = 0 ; i < len; i++) {
48004725 mid = (edge[i] + edge[i + 1 ]) / 2 ;
4801- if (XBetweenAB ( mid, s1, s2)) {
4726+ if (selection-> x1 < mid || selection-> x2 < mid)
48024727 if (i < begin)
48034728 begin = i;
4804-
4729+ if (mid < selection-> x1 || mid < selection-> x2 )
48054730 end = i + 1 ;
4806- }
48074731 }
48084732
48094733 /* Skip empty selection. */
@@ -4818,41 +4742,26 @@ void TextLine::visitSelection(TextSelectionVisitor *visitor, const PDFRectangle
48184742 TextWord *p, *begin, *end, *current;
48194743 int i, edge_begin, edge_end;
48204744 PDFRectangle child_selection;
4821- double s1, s2, pMin, pMax;
4822-
4823- if (rot == 0 || rot == 2 ) {
4824- s1 = selection->x1 ;
4825- s2 = selection->x2 ;
4826- } else {
4827- s1 = selection->y1 ;
4828- s2 = selection->y2 ;
4829- }
48304745
48314746 begin = nullptr ;
48324747 end = nullptr ;
48334748 current = nullptr ;
48344749 for (p = words; p != nullptr ; p = p->next ) {
4835- if (rot == 0 || rot == 2 ) {
4836- pMin = p->xMin ;
4837- pMax = p->xMax ;
4838- } else {
4839- pMin = p->yMin ;
4840- pMax = p->yMax ;
4841- }
4842-
48434750 if (blk->page ->primaryLR ) {
4844- if (((s1 < pMax) || (s2 < pMax)) && begin == nullptr )
4845- begin = p;
4751+ if ((selection->x1 < p->xMax ) || (selection->x2 < p->xMax ))
4752+ if (begin == nullptr )
4753+ begin = p;
48464754
4847- if (((s1 > pMin ) || (s2 > pMin )) && begin != nullptr ) {
4755+ if (((selection-> x1 > p-> xMin ) || (selection-> x2 > p-> xMin )) && ( begin != nullptr ) ) {
48484756 end = p->next ;
48494757 current = p;
48504758 }
48514759 } else {
4852- if (((s1 > pMin) || (s2 > pMin)) && begin == nullptr )
4853- begin = p;
4760+ if ((selection->x1 > p->xMin ) || (selection->x2 > p->xMin ))
4761+ if (begin == nullptr )
4762+ begin = p;
48544763
4855- if (((s1 < pMax ) || (s2 < pMax )) && begin != nullptr ) {
4764+ if (((selection-> x1 < p-> xMax ) || (selection-> x2 < p-> xMax )) && ( begin != nullptr ) ) {
48564765 end = p->next ;
48574766 current = p;
48584767 }
@@ -4864,41 +4773,23 @@ void TextLine::visitSelection(TextSelectionVisitor *visitor, const PDFRectangle
48644773
48654774 child_selection = *selection;
48664775 if (style == selectionStyleWord) {
4867- if (rot == 0 || rot == 2 ) {
4868- child_selection.x1 = begin ? begin->xMin : xMin;
4869- if (end && end->xMax != -1 ) {
4870- child_selection.x2 = current->xMax ;
4871- } else {
4872- child_selection.x2 = xMax;
4873- }
4776+ child_selection.x1 = begin ? begin->xMin : xMin;
4777+ if (end && end->xMax != -1 ) {
4778+ child_selection.x2 = current->xMax ;
48744779 } else {
4875- child_selection.y1 = begin ? begin->yMin : yMin;
4876- if (end && end->yMax != -1 ) {
4877- child_selection.y2 = current->yMax ;
4878- } else {
4879- child_selection.y2 = yMax;
4880- }
4780+ child_selection.x2 = xMax;
48814781 }
48824782 }
48834783
4884- if (rot == 0 || rot == 2 ) {
4885- s1 = child_selection.x1 ;
4886- s2 = child_selection.x2 ;
4887- } else {
4888- s1 = child_selection.y1 ;
4889- s2 = child_selection.y2 ;
4890- }
4891-
48924784 edge_begin = len;
48934785 edge_end = 0 ;
48944786 for (i = 0 ; i < len; i++) {
48954787 double mid = (edge[i] + edge[i + 1 ]) / 2 ;
4896- if (XBetweenAB ( mid, s1, s2)) {
4788+ if (child_selection. x1 < mid || child_selection. x2 < mid)
48974789 if (i < edge_begin)
48984790 edge_begin = i;
4899-
4791+ if (mid < child_selection. x2 || mid < child_selection. x1 )
49004792 edge_end = i + 1 ;
4901- }
49024793 }
49034794
49044795 /* Skip empty selection. */
0 commit comments