summaryrefslogtreecommitdiff
path: root/sax/source
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2024-06-01 19:50:47 +0200
committerRegina Henschel <rb.henschel@t-online.de>2024-06-11 10:29:17 +0200
commit567dbcf68711402736f65f4a0a47ef57549fe50f (patch)
tree934b9bd3650598d6a04f69a85c2754ef7c878989 /sax/source
parenta2b6ce5d21b7f5c84ced8485f5af279f1bf8135f (diff)
tdf#161327 Interpret angle units in dr3d:end-angle ..
.. and draw:rotation in <draw:hatch> element. ODF 1.1 has not specified the syntax of datatype 'angle'. Since ODF 1.2 it is specified as double with unit "deg", "grad" or "rad", or without unit. The unit-less value is specified to be in degrees. But OOo, AOO and all LO versions had written the value unit-less in 1/10th of a degree in some cases. To fix it, LibreOffic will be enabled to read units. When then the active versions are able to read units, starting with the then actual version, LibreOffice will write angles with unit 'deg'. This has already be done for gradients, see tdf#89475. This patch starts the first step to make LibreOffice able to read units for dr3d:end-angle (UNO D3DEndAngle) and for draw:rotation (UNO FillHatch.Angle). I have not found further cases of writing 1/10deg. The patch still writes unit-less 1/10th of a degree for export to ODF 1.3 and earlier. When it is time to write unit degree or when LibreOffice supports the next ODF versions, some places need to be adapted. They are marked. The converter convertAngle is renamed to convert10thDegAngle() to indicate, that it is special. The parts, which were specific to gradients are moved to the gradients, so that it is now usable for dr3d:angle and draw:rotation too. I intend to write next a patch that enables LibreOffice to read angle units for cases where LibreOffice already writes unit-less values in degree. That is not so urgent, but to bring LibreOffice nearer to ODF, reading angle units should be implemented nevertheless. The file xmlbahdl.hxx is moved from xmloff/source/style to xmloff/inc to have access to it from xmloff/source/draw. Change-Id: I8ffc2735f8bcfefb86efa80eb05f900c32403f31 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168336 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Diffstat (limited to 'sax/source')
-rw-r--r--sax/source/tools/converter.cxx117
1 files changed, 39 insertions, 78 deletions
diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx
index 09156a0a9405..bc2342d5b508 100644
--- a/sax/source/tools/converter.cxx
+++ b/sax/source/tools/converter.cxx
@@ -725,25 +725,24 @@ bool Converter::convertDouble(double& rValue, std::string_view rString)
}
/** convert number, 10th of degrees with range [0..3600] to SVG angle */
-void Converter::convertAngle(OUStringBuffer& rBuffer, sal_Int16 const nAngle,
- SvtSaveOptions::ODFSaneDefaultVersion const nVersion)
+void Converter::convert10thDegAngle(OUStringBuffer& rBuffer, sal_Int16 const nAngle,
+ const bool isWrongOOo10thDegAngle)
{
- if (nVersion < SvtSaveOptions::ODFSVER_012 || nVersion == SvtSaveOptions::ODFSVER_012_EXT_COMPAT)
+ if (isWrongOOo10thDegAngle)
{
- // 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, std::u16string_view rString,
- bool const isWrongOOo10thDegAngle)
+/** convert SVG angle to number in 10th of degrees */
+bool Converter::convert10thDegAngle(sal_Int16& rAngle, std::u16string_view 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 :(
@@ -751,49 +750,30 @@ bool Converter::convertAngle(sal_Int16& rAngle, std::u16string_view rString,
// 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 (std::u16string_view::npos != rString.find(u"deg"))
- {
- nValue = fValue * 10.0;
- }
- else if (std::u16string_view::npos != rString.find(u"grad"))
- {
- nValue = (fValue * 9.0 / 10.0) * 10.0;
- }
- else if (std::u16string_view::npos != rString.find(u"rad"))
- {
- nValue = basegfx::rad2deg<10>(fValue);
- }
- else // no explicit unit
- {
- 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;
- if (nValue < 0)
- {
- nValue += 3600;
- }
- assert(0 <= nValue && nValue <= 3600);
+ double fAngle(0.0);
+ bool bRet = ::sax::Converter::convertDouble(fAngle, rString);
if (bRet)
{
- rAngle = sal::static_int_cast<sal_Int16>(nValue);
+ if (std::u16string_view::npos != rString.find(u"deg"))
+ fAngle *= 10.0;
+ else if (std::u16string_view::npos != rString.find(u"grad"))
+ fAngle *= 9.0; // 360deg = 400grad
+ else if (std::u16string_view::npos != rString.find(u"rad"))
+ fAngle = basegfx::rad2deg<10>(fAngle);
+ else // no explicit unit
+ { // isWrongOOo10thDegAngle = true: nothing to do here. Wrong, but backward compatible.
+ if (!isWrongOOo10thDegAngle)
+ fAngle *= 10.0; // conform to ODF 1.2 and newer
+ }
+ fAngle = std::clamp<double>(basegfx::fround(fAngle), SHRT_MIN, SHRT_MAX);
+ rAngle = static_cast<sal_Int16>(fAngle);
}
return bRet;
}
/** convert SVG angle to number, 10th of degrees with range [0..3600] */
-bool Converter::convertAngle(sal_Int16& rAngle, std::string_view rString,
- bool const isWrongOOo10thDegAngle)
+bool Converter::convert10thDegAngle(sal_Int16& rAngle, std::string_view 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 :(
@@ -801,42 +781,23 @@ bool Converter::convertAngle(sal_Int16& rAngle, std::string_view rString,
// 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 (std::string_view::npos != rString.find("deg"))
- {
- nValue = fValue * 10.0;
- }
- else if (std::string_view::npos != rString.find("grad"))
- {
- nValue = (fValue * 9.0 / 10.0) * 10.0;
- }
- else if (std::string_view::npos != rString.find("rad"))
- {
- nValue = basegfx::rad2deg<10>(fValue);
- }
- else // no explicit unit
- {
- 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;
- if (nValue < 0)
- {
- nValue += 3600;
- }
- assert(0 <= nValue && nValue <= 3600);
+ double fAngle(0.0);
+ bool bRet = ::sax::Converter::convertDouble(fAngle, rString);
if (bRet)
{
- rAngle = sal::static_int_cast<sal_Int16>(nValue);
+ if (std::string_view::npos != rString.find("deg"))
+ fAngle *= 10.0;
+ else if (std::string_view::npos != rString.find("grad"))
+ fAngle *= 9.0; // 360deg = 400grad
+ else if (std::string_view::npos != rString.find("rad"))
+ fAngle = basegfx::rad2deg<10>(fAngle);
+ else // no explicit unit
+ { // isWrongOOo10thDegAngle = true: nothing to do here. Wrong, but backward compatible.
+ if (!isWrongOOo10thDegAngle)
+ fAngle *= 10.0; // conform to ODF 1.2 and newer
+ }
+ fAngle = std::clamp<double>(basegfx::fround(fAngle), SHRT_MIN, SHRT_MAX);
+ rAngle = static_cast<sal_Int16>(fAngle);
}
return bRet;
}