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

New commits:
commit fe2ffc168d7beee2cec10d559b8da5e9d915ddc9
Author:     Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de>
AuthorDate: Wed Aug 23 16:55:07 2023 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Thu Aug 24 17:35:35 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>
    (cherry picked from commit 382dfb3e6ee73fc94a556e37d261e8219e08826c)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155998
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/svx/source/sdr/contact/viewobjectcontact.cxx 
b/svx/source/sdr/contact/viewobjectcontact.cxx
index 3f2ce8dc34fa..2a62e15cb2e3 100644
--- a/svx/source/sdr/contact/viewobjectcontact.cxx
+++ b/svx/source/sdr/contact/viewobjectcontact.cxx
@@ -579,10 +579,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