summaryrefslogtreecommitdiff
path: root/sdext
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2016-10-30 10:05:55 +0300
committerStephan Bergmann <sbergman@redhat.com>2016-10-31 14:24:50 +0000
commit7de287ba422107f54018f2ba0f054d642c86c966 (patch)
tree105f233c23fedc7c9c99c07bffa0534cbadb8e03 /sdext
parent06babf60ce9edd17e02930e60b9afdc12b40b553 (diff)
Make stable sort more stable :)
Account for negative widths/heights; only apply text fudge factor to text elements. This prevents debug asserts that "less" comparison is invalid. Change-Id: Ifb46bb873bfc80fc8c07af4923073d2042d30b3a Reviewed-on: https://gerrit.libreoffice.org/30391 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sdext')
-rw-r--r--sdext/source/pdfimport/tree/pdfiprocessor.cxx28
1 files changed, 20 insertions, 8 deletions
diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.cxx b/sdext/source/pdfimport/tree/pdfiprocessor.cxx
index e15f4ad27185..dbc94360ca61 100644
--- a/sdext/source/pdfimport/tree/pdfiprocessor.cxx
+++ b/sdext/source/pdfimport/tree/pdfiprocessor.cxx
@@ -642,29 +642,41 @@ static bool lr_tb_sort( Element* pLeft, Element* pRight )
// Note: allow for 10% overlap on text lines since text lines are usually
// of the same order as font height whereas the real paint area
// of text is usually smaller
- double fudge_factor = 1.0;
- if( dynamic_cast< TextElement* >(pLeft) || dynamic_cast< TextElement* >(pRight) )
- fudge_factor = 0.9;
-
+ double fudge_factor_left = 0.0, fudge_factor_right = 0.0;
+ if( dynamic_cast< TextElement* >(pLeft) )
+ fudge_factor_left = 0.1;
+ if (dynamic_cast< TextElement* >(pRight))
+ fudge_factor_right = 0.1;
+
+ // Allow negative height
+ double lower_boundary_left = pLeft->y + std::max(pLeft->h, 0.0) - fabs(pLeft->h) * fudge_factor_left;
+ double lower_boundary_right = pRight->y + std::max(pRight->h, 0.0) - fabs(pRight->h) * fudge_factor_right;
+ double upper_boundary_left = pLeft->y + std::min(pLeft->h, 0.0);
+ double upper_boundary_right = pRight->y + std::min(pRight->h, 0.0);
// if left's lower boundary is above right's upper boundary
// then left is smaller
- if( pLeft->y+pLeft->h*fudge_factor < pRight->y )
+ if( lower_boundary_left < upper_boundary_right )
return true;
// if right's lower boundary is above left's upper boundary
// then left is definitely not smaller
- if( pRight->y+pRight->h*fudge_factor < pLeft->y )
+ if( lower_boundary_right < upper_boundary_left )
return false;
+ // Allow negative width
+ double left_boundary_left = pLeft->y + std::min(pLeft->w, 0.0);
+ double left_boundary_right = pRight->y + std::min(pRight->w, 0.0);
+ double right_boundary_left = pLeft->y + std::max(pLeft->w, 0.0);
+ double right_boundary_right = pRight->y + std::max(pRight->w, 0.0);
// by now we have established that left and right are inside
// a "line", that is they have vertical overlap
// second: left-right sorting
// if left's right boundary is left to right's left boundary
// then left is smaller
- if( pLeft->x+pLeft->w < pRight->x )
+ if( right_boundary_left < left_boundary_right )
return true;
// if right's right boundary is left to left's left boundary
// then left is definitely not smaller
- if( pRight->x+pRight->w < pLeft->x )
+ if( right_boundary_right < left_boundary_left )
return false;
// here we have established vertical and horizontal overlap