diff --git a/OdfFile/Reader/Converter/oox_drawing.cpp b/OdfFile/Reader/Converter/oox_drawing.cpp index 6602b73d71..40b2dfe994 100644 --- a/OdfFile/Reader/Converter/oox_drawing.cpp +++ b/OdfFile/Reader/Converter/oox_drawing.cpp @@ -889,7 +889,10 @@ void _oox_drawing::serialize_xfrm(std::wostream & strm, const std::wstring & nam if (dRotate) { double d = 360 - dRotate.get() * 180. / 3.14159265358979323846; - CP_XML_ATTR(L"rot", (int)( d * 60000) ); //60 000 per 1 gr - 19.5.5 oox + // ODF rotate() has no range. Without this, each open of a saved file adds a whole turn. + d = fmod(d, 360.); + if (d < 0) d += 360.; + CP_XML_ATTR(L"rot", (int)( d * 60000 + 0.5) % 21600000 ); //60 000 per 1 gr - 19.5.5 oox } _CP_OPT(bool)bVal; if (odf_reader::GetProperty(additional, L"flipH", bVal)) diff --git a/OdfFile/Test/test_odf/CMakeLists.txt b/OdfFile/Test/test_odf/CMakeLists.txt index 016479607c..162b8d8ea2 100644 --- a/OdfFile/Test/test_odf/CMakeLists.txt +++ b/OdfFile/Test/test_odf/CMakeLists.txt @@ -131,6 +131,7 @@ add_core_gtest( ods_formula_function_names.cpp ods2xlsx_optimal_row_height.cpp odf_font_family.cpp + odp2pptx_rotation.cpp docx2odt_line_break_after_text.cpp odt2docx_character_style_based_on.cpp odt2docx_ruby.cpp diff --git a/OdfFile/Test/test_odf/ExampleFiles/rotate_range.odp b/OdfFile/Test/test_odf/ExampleFiles/rotate_range.odp new file mode 100644 index 0000000000..57b208e15e Binary files /dev/null and b/OdfFile/Test/test_odf/ExampleFiles/rotate_range.odp differ diff --git a/OdfFile/Test/test_odf/odp2pptx_rotation.cpp b/OdfFile/Test/test_odf/odp2pptx_rotation.cpp new file mode 100644 index 0000000000..ce0ae9e62a --- /dev/null +++ b/OdfFile/Test/test_odf/odp2pptx_rotation.cpp @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: 2026 Euro-Office contributors +// SPDX-License-Identifier: AGPL-3.0-only + +// Rotation of shapes written by the ODF -> DrawingML converter (oox_drawing.cpp). + +#include "gtest/gtest.h" + +#include "common.h" + +#include +#include + +namespace +{ +// The values of all rot="..." attributes of a part, in document order. +std::vector rot_values(const std::wstring& xml) +{ + std::vector values; + const std::wstring attr = L" rot=\""; + for (size_t pos = xml.find(attr); pos != std::wstring::npos; pos = xml.find(attr, pos + 1)) + { + values.push_back(std::stoll(xml.substr(pos + attr.size()))); + } + return values; +} +} + +// The fixture has rotate(0.3), rotate(-6), rotate(-6.283185307179586), one +// whole turn, and rotate(-6.2831853), one whole turn with 7 decimals. +// a:xfrm/@rot is in 0..21600000 (ST_Angle, 60000ths of a degree). Before, +// rotate(-6) gave 42226480 and the whole turn 43200000. +TEST(OdpToPptxShape, RotationIsInOneTurn) +{ + const std::wstring dir = convert_odf_to_ooxml_dir(L"ExampleFiles/rotate_range.odp"); + ASSERT_FALSE(dir.empty()) << "ODP -> PPTX conversion failed"; + + const std::wstring xml = read_part(dir, L"ppt/slides/slide1.xml"); + ASSERT_FALSE(xml.empty()) << "ppt/slides/slide1.xml is missing"; + EXPECT_TRUE(is_well_formed(xml)); + + const std::vector rot = rot_values(xml); + ASSERT_EQ(rot.size(), 4u) << "one rot per rotated shape"; + for (long long value : rot) + { + EXPECT_GE(value, 0); + EXPECT_LT(value, 21600000); + } + EXPECT_EQ(rot[2], 0) << "a whole turn is no rotation"; +} + +// rotate(0.3) is 342.81126614607... degrees, 20568675.97 in 60000ths: the +// nearest unit is 20568676. A cast to int truncated it to 20568675, and the +// angle crept on each open of a saved file. rotate(-6.2831853) is +// 359.9999996 degrees, 21599999.975 units: it rounds up to 21600000, a whole +// turn, which is written as 0. +TEST(OdpToPptxShape, RotationIsRounded) +{ + const std::wstring dir = convert_odf_to_ooxml_dir(L"ExampleFiles/rotate_range.odp"); + ASSERT_FALSE(dir.empty()) << "ODP -> PPTX conversion failed"; + + const std::vector rot = rot_values(read_part(dir, L"ppt/slides/slide1.xml")); + ASSERT_EQ(rot.size(), 4u) << "one rot per rotated shape"; + EXPECT_EQ(rot[0], 20568676); + EXPECT_EQ(rot[1], 20626481); + EXPECT_EQ(rot[3], 0) << "a value that rounds up to 360 degrees"; +} diff --git a/REUSE.toml b/REUSE.toml index d8c3722d16..ddd3fbd769 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -538,3 +538,8 @@ SPDX-License-Identifier = "AGPL-3.0-only" path = "OdfFile/Test/test_odf/ExampleFiles/ruby_base_text.odt" SPDX-FileCopyrightText = "2026 Euro-Office contributors" SPDX-License-Identifier = "AGPL-3.0-only" + +[[annotations]] +path = "OdfFile/Test/test_odf/ExampleFiles/rotate_range.odp" +SPDX-FileCopyrightText = "2026 Euro-Office contributors" +SPDX-License-Identifier = "AGPL-3.0-only"