summaryrefslogtreecommitdiff
path: root/sax/source
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2015-10-09 17:51:50 +0200
committerEike Rathke <erack@redhat.com>2015-10-12 21:15:30 +0000
commit76a4665a09542fb67dd99c9a607c162e0b678ead (patch)
treec6cb1346ba7afd88d9fd1879cd5a1c61b238e27a /sax/source
parenta54f0d6c980b880854458b7c685c04632acf91ac (diff)
xmloff: fix ODF import of gradient draw:angle attribute a bit
ODF 1.2 part 3, 18.3.1 angle, says "An angle, as defined in ยง4.1 of [SVG]" and "If no unit identifier is specified, the value is assumed to be in degrees." Unfortunately OOo could only read and write 10th of degree here. See also https://issues.oasis-open.org/browse/OFFICE-3774 As the first step towards fixing that, implement the import for draw:angle values with an angle unit identifier, but leave the import as-is if the angle identifier is missing. Change-Id: Ib88d417c03998ebcfc569b01492f0e1f851bbc85 (cherry picked from commit aadda5d17f6e422da143ea774f759bfc5f629c5b) Reviewed-on: https://gerrit.libreoffice.org/19283 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sax/source')
-rw-r--r--sax/source/tools/converter.cxx56
1 files changed, 56 insertions, 0 deletions
diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx
index 3ef609e2f288..5c9697411131 100644
--- a/sax/source/tools/converter.cxx
+++ b/sax/source/tools/converter.cxx
@@ -640,6 +640,62 @@ bool Converter::convertDouble(double& rValue, const OUString& rString)
return ( eStatus == rtl_math_ConversionStatus_Ok );
}
+/** convert number, 10th of degrees with range [0..3600] to SVG angle */
+void Converter::convertAngle(OUStringBuffer& rBuffer, sal_Int16 const nAngle)
+{
+#if 1
+ // wrong, but backward compatible with OOo/LO < 4.4
+ ::sax::Converter::convertNumber(rBuffer, nAngle);
+#else
+ // maybe in the future... (see other convertAngle)
+ double fAngle(double(nAngle) / 10.0);
+ ::sax::Converter::convertDouble(rBuffer, fAngle);
+ rBuffer.append("deg");
+#endif
+}
+
+/** convert SVG angle to number, 10th of degrees with range [0..3600] */
+bool Converter::convertAngle(sal_Int16& rAngle, OUString const& rString)
+{
+ // 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 :(
+ // So import degrees when we see the "deg" suffix but continue with 10th of
+ // degrees for now for the sake of existing OOo/LO documents, until the
+ // new versions that can read "deg" suffix are widely deployed and we can
+ // start to write the "deg" suffix.
+ sal_Int32 nValue(0);
+ double fValue(0.0);
+ bool bRet = ::sax::Converter::convertDouble(fValue, rString);
+ if (-1 != rString.indexOf("deg"))
+ {
+ nValue = fValue * 10.0;
+ }
+ else if (-1 != rString.indexOf("grad"))
+ {
+ nValue = (fValue * 9.0 / 10.0) * 10.0;
+ }
+ else if (-1 != rString.indexOf("rad"))
+ {
+ nValue = (fValue * 180.0 / M_PI) * 10.0;
+ }
+ else // no explicit unit
+ {
+ nValue = fValue; // wrong, but backward compatible with OOo/LO < 4.4
+ }
+ // limit to valid range [0..3600]
+ nValue = nValue % 3600;
+ if (nValue < 0)
+ {
+ nValue += 3600;
+ }
+ assert(0 <= nValue && nValue <= 3600);
+ if (bRet)
+ {
+ rAngle = sal::static_int_cast<sal_Int16>(nValue);
+ }
+ return bRet;
+}
+
/** convert double to ISO "duration" string; negative durations allowed */
void Converter::convertDuration(OUStringBuffer& rBuffer,
const double fTime)