svx/source/sdr/contact/viewobjectcontact.cxx |   35 ++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

New commits:
commit 382dfb3e6ee73fc94a556e37d261e8219e08826c
Author:     Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de>
AuthorDate: Wed Aug 23 16:55:07 2023 +0200
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Thu Aug 24 12:34:24 2023 +0200

    Reset buffered GridOffset(s) for suspicious values
    
    Huge offsets of GridOffset(s) are a hint for error -> usually the
    conditions for calculation have changed. E.g. - I saw errors with
    +/-5740, that was in the environment of massive external UNO API
    using LO as target.
    If condtions for this calculation change, it is usually required to
    call
    - ViewObjectContact::resetGridOffset(), or
    - ObjectContact::resetAllGridOffsets() or
    - ScDrawView::resetGridOffsetsForAllSdrPageViews()
    as it is done e.g. when zoom changes (see ScDrawView::RecalcScale()).
    Theoretically these resets have to be done for any precondition
    changed that is used in the calculation of that value (see
    ScDrawView::calculateGridOffsetForSdrObject).
    This is not complete and would be hard to do so. Since it is just a
    buffered value and re-calculation is not expensive (linear O(n)) we
    can just reset suspicious values here  what fixes the problem.
    Hopefully - when that non-linear ViewTransformation problem for the
    calc-view gets solved one day - all this can be removed again. For
    now, let's just reset here and force re-calculation.
    Added a SAL_WARN to inform about this, too.
    
    Change-Id: I09137f7703fd00c2351a288a40bf87a2691ba6e3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155983
    Tested-by: Jenkins
    Reviewed-by: Armin Le Grand <armin.le.gr...@me.com>

diff --git a/svx/source/sdr/contact/viewobjectcontact.cxx 
b/svx/source/sdr/contact/viewobjectcontact.cxx
index 91ee66dff1ae..450b8215482e 100644
--- a/svx/source/sdr/contact/viewobjectcontact.cxx
+++ b/svx/source/sdr/contact/viewobjectcontact.cxx
@@ -576,10 +576,39 @@ void 
ViewObjectContact::getPrimitive2DSequenceSubHierarchy(DisplayInfo& rDisplay
 // (->View) that has then all needed information
 const basegfx::B2DVector& ViewObjectContact::getGridOffset() const
 {
-    if(0.0 == maGridOffset.getX() && 0.0 == maGridOffset.getY() && 
GetObjectContact().supportsGridOffsets())
+    if (GetObjectContact().supportsGridOffsets())
     {
-        // create on-demand
-        
GetObjectContact().calculateGridOffsetForViewOjectContact(const_cast<ViewObjectContact*>(this)->maGridOffset,
 *this);
+        if (fabs(maGridOffset.getX()) > 1000.0)
+        {
+            // Huge offsets are a hint for error -> usually the conditions for
+            // calculation have changed. E.g. - I saw errors with +/-5740, that
+            // was in the environment of massive external UNO API using LO as
+            // target.
+            // If condtions for this calculation change, it is usually 
required to call
+            // - ViewObjectContact::resetGridOffset(), or
+            // - ObjectContact::resetAllGridOffsets() or
+            // - ScDrawView::resetGridOffsetsForAllSdrPageViews()
+            // as it is done e.g. when zoom changes (see 
ScDrawView::RecalcScale()).
+            // Theoretically these resets have to be done for any precondition
+            // changed that is used in the calculation of that value (see
+            // ScDrawView::calculateGridOffsetForSdrObject).
+            // This is not complete and would be hard to do so.
+            // Since it is just a buffered value and re-calculation is not
+            // expensive (linear O(n)) we can just reset suspicious values 
here.
+            // Hopefully - when that non-linear ViewTransformation problem for
+            // the calc-view gets solved one day - all this can be removed
+            // again. For now, let's just reset here and force re-calculation.
+            // Add a SAL_WARN to inform about this.
+            SAL_WARN("svx", "Suspicious GridOffset value resetted (!)");
+            const_cast<ViewObjectContact*>(this)->maGridOffset.setX(0.0);
+            const_cast<ViewObjectContact*>(this)->maGridOffset.setY(0.0);
+        }
+
+        if(0.0 == maGridOffset.getX() && 0.0 == maGridOffset.getY() && 
GetObjectContact().supportsGridOffsets())
+        {
+            // create on-demand
+            
GetObjectContact().calculateGridOffsetForViewOjectContact(const_cast<ViewObjectContact*>(this)->maGridOffset,
 *this);
+        }
     }
 
     return maGridOffset;

Reply via email to