summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2020-05-18 18:43:51 +0200
committerMichael Stahl <michael.stahl@cib.de>2020-05-19 17:04:33 +0200
commit693cefb59286daf6ff86f1db16f0d64b4b9b4588 (patch)
tree85ffc717387c77c159ac3dcc3111fb91d2fde7c2
parent34a513428d0786578c1c5f38fdc8a0fbd3b8f82f (diff)
tdf#89475 xmloff: ODF import/export: continue fixing draw:angle
Continue what commit aadda5d17f6e422da143ea774f759bfc5f629c5b started wrt. unit-less draw:angle attributes in ODF >= 1.2: * ODF 1.3 files don't ever have unit-less draw:angle interpreted as 10th of degree * import unit-less draw:angle as degree, except if it's ODF 1.0/1.1 or it's ODF 1.2 written by OOo/LO < 7.0, then 10th of degree * export draw:angle with "deg", which LO 4.4 and newer can read; except if exporting ODF 1.0/1.1 or ODF 1.2 Extended (compatibility mode), then 10th of degree (unit-less) The only problem with this is that if you store a file as ODF 1.2 Extended (compatibility mode) and load it with LO 7.0 it will interpret the angle wrong, but nothing's perfect... Change-Id: I3771e6571afd40e44b6f7890dacf18c28841610f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94443 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r--include/sax/tools/converter.hxx7
-rw-r--r--sax/source/tools/converter.cxx35
-rw-r--r--xmloff/source/style/GradientStyle.cxx11
-rw-r--r--xmloff/source/style/TransGradientStyle.cxx11
4 files changed, 46 insertions, 18 deletions
diff --git a/include/sax/tools/converter.hxx b/include/sax/tools/converter.hxx
index 9f7f5b3df50f..e5e6d5764d0f 100644
--- a/include/sax/tools/converter.hxx
+++ b/include/sax/tools/converter.hxx
@@ -31,6 +31,7 @@
#include <rtl/ustrbuf.hxx>
#include <com/sun/star/util/MeasureUnit.hpp>
#include <tools/color.hxx>
+#include <unotools/saveopt.hxx>
namespace com::sun::star {
namespace uno {
@@ -146,10 +147,12 @@ public:
static bool convertDouble(double& rValue, const OUString& rString);
/** convert number, 10th of degrees with range [0..3600] to SVG angle */
- static void convertAngle(OUStringBuffer& rBuffer, sal_Int16 nAngle);
+ static void convertAngle(OUStringBuffer& rBuffer, sal_Int16 nAngle,
+ SvtSaveOptions::ODFSaneDefaultVersion nVersion);
/** convert SVG angle to number, 10th of degrees with range [0..3600] */
- static bool convertAngle(sal_Int16& rAngle, OUString const& rString);
+ static bool convertAngle(sal_Int16& rAngle, OUString const& rString,
+ bool isWrongOOo10thDegAngle);
/** convert double to XMLSchema-2 "duration" string; negative durations allowed */
static void convertDuration(OUStringBuffer& rBuffer,
diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx
index 9c19ef5d0b7d..ac6eba928526 100644
--- a/sax/source/tools/converter.cxx
+++ b/sax/source/tools/converter.cxx
@@ -623,21 +623,25 @@ bool Converter::convertDouble(double& rValue, const OUString& rString)
}
/** convert number, 10th of degrees with range [0..3600] to SVG angle */
-void Converter::convertAngle(OUStringBuffer& rBuffer, sal_Int16 const nAngle)
+void Converter::convertAngle(OUStringBuffer& rBuffer, sal_Int16 const nAngle,
+ SvtSaveOptions::ODFSaneDefaultVersion const nVersion)
{
-#if 1
- // wrong, but backward compatible with OOo/LO < 4.4
- rBuffer.append(static_cast<sal_Int32>(nAngle));
-#else
- // maybe in the future... (see other convertAngle)
- double fAngle(double(nAngle) / 10.0);
- ::sax::Converter::convertDouble(rBuffer, fAngle);
- rBuffer.append("deg");
-#endif
+ if (nVersion < SvtSaveOptions::ODFSVER_012 || nVersion == SvtSaveOptions::ODFSVER_012_EXT_COMPAT)
+ {
+ // wrong, but backward compatible with OOo/LO < 4.4
+ rBuffer.append(static_cast<sal_Int32>(nAngle));
+ }
+ else
+ { // OFFICE-3774 tdf#89475 write valid ODF 1.2 angle; needs LO 4.4 to import
+ double fAngle(double(nAngle) / 10.0);
+ ::sax::Converter::convertDouble(rBuffer, fAngle);
+ rBuffer.append("deg");
+ }
}
/** convert SVG angle to number, 10th of degrees with range [0..3600] */
-bool Converter::convertAngle(sal_Int16& rAngle, OUString const& rString)
+bool Converter::convertAngle(sal_Int16& rAngle, OUString const& rString,
+ bool const isWrongOOo10thDegAngle)
{
// ODF 1.1 leaves it undefined what the number means, but ODF 1.2 says it's
// degrees, while OOo has historically used 10th of degrees :(
@@ -662,7 +666,14 @@ bool Converter::convertAngle(sal_Int16& rAngle, OUString const& rString)
}
else // no explicit unit
{
- nValue = fValue; // wrong, but backward compatible with OOo/LO < 4.4
+ if (isWrongOOo10thDegAngle)
+ {
+ nValue = fValue; // wrong, but backward compatible with OOo/LO < 7.0
+ }
+ else
+ {
+ nValue = fValue * 10.0; // ODF 1.2
+ }
}
// limit to valid range [0..3600]
nValue = nValue % 3600;
diff --git a/xmloff/source/style/GradientStyle.cxx b/xmloff/source/style/GradientStyle.cxx
index 97721db74ea3..3a8a5bedc444 100644
--- a/xmloff/source/style/GradientStyle.cxx
+++ b/xmloff/source/style/GradientStyle.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/awt/Gradient.hpp>
#include <sax/tools/converter.hxx>
+#include <comphelper/documentconstants.hxx>
#include <xmloff/nmspmap.hxx>
#include <xmloff/xmluconv.hxx>
@@ -160,8 +161,14 @@ void XMLGradientStyleImport::importXML(
break;
case XML_TOK_GRADIENT_ANGLE:
{
+ auto const cmp12(rImport.GetODFVersion().compareTo(ODFVER_012_TEXT));
bool const bSuccess =
- ::sax::Converter::convertAngle(aGradient.Angle, rStrValue);
+ ::sax::Converter::convertAngle(aGradient.Angle, rStrValue,
+ // tdf#89475 try to detect borked OOo angles
+ (cmp12 < 0) || (cmp12 == 0
+ && (rImport.isGeneratorVersionOlderThan(SvXMLImport::AOO_4x, SvXMLImport::LO_7x)
+ // also for AOO 4.x, assume there won't ever be a 4.2
+ || rImport.getGeneratorVersion() == SvXMLImport::AOO_4x)));
SAL_INFO_IF(!bSuccess, "xmloff.style", "failed to import draw:angle");
}
break;
@@ -260,7 +267,7 @@ void XMLGradientStyleExport::exportXML(
// Angle
if( aGradient.Style != awt::GradientStyle_RADIAL )
{
- ::sax::Converter::convertAngle(aOut, aGradient.Angle);
+ ::sax::Converter::convertAngle(aOut, aGradient.Angle, rExport.getSaneDefaultVersion());
aStrValue = aOut.makeStringAndClear();
rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_GRADIENT_ANGLE, aStrValue );
}
diff --git a/xmloff/source/style/TransGradientStyle.cxx b/xmloff/source/style/TransGradientStyle.cxx
index 0dce37fcae3e..536ba39d26b3 100644
--- a/xmloff/source/style/TransGradientStyle.cxx
+++ b/xmloff/source/style/TransGradientStyle.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/awt/Gradient.hpp>
#include <sax/tools/converter.hxx>
+#include <comphelper/documentconstants.hxx>
#include <xmloff/nmspmap.hxx>
#include <xmloff/xmluconv.hxx>
@@ -171,8 +172,14 @@ void XMLTransGradientStyleImport::importXML(
break;
case XML_TOK_GRADIENT_ANGLE:
{
+ auto const cmp12(rImport.GetODFVersion().compareTo(ODFVER_012_TEXT));
bool const bSuccess =
- ::sax::Converter::convertAngle(aGradient.Angle, rStrValue);
+ ::sax::Converter::convertAngle(aGradient.Angle, rStrValue,
+ // tdf#89475 try to detect borked OOo angles
+ (cmp12 < 0) || (cmp12 == 0
+ && (rImport.isGeneratorVersionOlderThan(SvXMLImport::AOO_4x, SvXMLImport::LO_7x)
+ // also for AOO 4.x, assume there won't ever be a 4.2
+ || rImport.getGeneratorVersion() == SvXMLImport::AOO_4x)));
SAL_INFO_IF(!bSuccess, "xmloff.style", "failed to import draw:angle");
}
break;
@@ -265,7 +272,7 @@ void XMLTransGradientStyleExport::exportXML(
// Angle
if( aGradient.Style != awt::GradientStyle_RADIAL )
{
- ::sax::Converter::convertAngle(aOut, aGradient.Angle);
+ ::sax::Converter::convertAngle(aOut, aGradient.Angle, rExport.getSaneDefaultVersion());
aStrValue = aOut.makeStringAndClear();
rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_GRADIENT_ANGLE, aStrValue );
}