[Libreoffice-commits] core.git: sdext/source

Mike Kaganski mike.kaganski at collabora.com
Mon Oct 31 14:25:15 UTC 2016


 sdext/source/pdfimport/tree/pdfiprocessor.cxx |   28 ++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

New commits:
commit 7de287ba422107f54018f2ba0f054d642c86c966
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Sun Oct 30 10:05:55 2016 +0300

    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 at libreoffice.org>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.cxx b/sdext/source/pdfimport/tree/pdfiprocessor.cxx
index e15f4ad..dbc9436 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


More information about the Libreoffice-commits mailing list