sc/source/ui/view/output2.cxx | 46 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-)
New commits: commit 4e5df4c2777df3dcddffe0efdfceca55b3101bdf Author: Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de> AuthorDate: Tue Nov 1 11:01:57 2022 +0100 Commit: Armin Le Grand <armin.le.gr...@me.com> CommitDate: Tue Nov 1 12:28:28 2022 +0100 tdf#143377 Handle nAttrRotate and Skew more backward safe Change-Id: I51aad9d1dc1f792bc86ac6793308bd5be1aecfee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142098 Tested-by: Jenkins Reviewed-by: Armin Le Grand <armin.le.gr...@me.com> diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx index abee5a2e8756..dc4ed9a86435 100644 --- a/sc/source/ui/view/output2.cxx +++ b/sc/source/ui/view/output2.cxx @@ -4691,23 +4691,53 @@ void ScOutputData::DrawRotated(bool bPixelToLogic) // tdf#143377 To use the same limits to avoid too big Skew // with TextOrientation in Calc, use 1/2 degree here, too. - // This equals '50' in the notation here - const bool bForbidSkew( - nAttrRotate < Degree100(50) || // range [0..50] - nAttrRotate > Degree100(36000 - 50) || // range [35950..36000[ - (nAttrRotate > Degree100(18000 - 50) && (nAttrRotate < Degree100(18000 + 50)))); // range 50 around 18000 + // This equals '50' in the notation here (100th degree) + static const sal_Int32 nMinRad(50); - if ( bForbidSkew ) + // bring nAttrRotate to the range [0..36000[ + nAttrRotate = Degree100(((nAttrRotate.get() % 36000) + 36000) % 36000); + + // check for to be avoided extreme values and correct + if (nAttrRotate < Degree100(nMinRad)) + { + // range [0..50] + nAttrRotate = Degree100(nMinRad); + eRotMode = SVX_ROTATE_MODE_STANDARD; // no overflow + } + else if (nAttrRotate > Degree100(36000 - nMinRad)) + { + // range [35950..36000[ + nAttrRotate = Degree100(36000 - nMinRad); + eRotMode = SVX_ROTATE_MODE_STANDARD; // no overflow + } + else if (nAttrRotate > Degree100(18000 - nMinRad) && (nAttrRotate < Degree100(18000 + nMinRad))) { + // range 50 around 18000, [17950..18050] + nAttrRotate = (nAttrRotate > Degree100(18000)) + ? Degree100(18000 + nMinRad) + : Degree100(18000 - nMinRad); eRotMode = SVX_ROTATE_MODE_STANDARD; // no overflow } if ( bLayoutRTL ) - nAttrRotate = -nAttrRotate; + { + // keep in range [0..36000[ + nAttrRotate = Degree100(36000 - nAttrRotate.get()); + } double nRealOrient = toRadians(nAttrRotate); // 1/100 degree nCos = cos( nRealOrient ); - nSin = bForbidSkew ? 0 : sin( nRealOrient ); + + // tdf#143377 new strategy: instead of using zero for nSin, which + // would be the *correct* value, continue with the corrected maximum + // allowed value which is then *not* zero. This is silmilar to + // the behaviour before where (just due to numerical unprecisions) + // nSin was also not zero (pure coincidence), but very close to it. + // I checked and tried to make safe all places below that use + // nSin and divide by it, but there is too much going on and that + // would not be safe, so rely on the same values as before, but + // now numerically limited to not get the Skew go havoc + nSin = sin( nRealOrient ); } }