diff options
author | Michael Stahl <mstahl@redhat.com> | 2015-10-09 17:51:50 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-10-09 18:03:49 +0200 |
commit | aadda5d17f6e422da143ea774f759bfc5f629c5b (patch) | |
tree | 753fcbc7c0da18a7f4f2b2152db79a1c84d4f688 /sax/source | |
parent | a8f053697c6c6cfa07ce200165df8a1c9968a9de (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
Diffstat (limited to 'sax/source')
-rw-r--r-- | sax/source/tools/converter.cxx | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx index a223c4c53c1a..ef3ebe521655 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) |