From 5b63db9680dd543d1f3629030a6d00e3cf5c8980 Mon Sep 17 00:00:00 2001 From: Anton Oussik Date: Mon, 16 Nov 2026 11:08:16 +0100 Subject: [PATCH 1/2] fix(OdfFile): keep shape rotation between 0 and 360 degrees The ODF reader converts draw:transform rotate(r) to a DrawingML rot of 360 - r degrees and does not bring it into one turn. The writer turns rot back into rotate(-rot), so each open and save of an ODT, ODS or ODP file adds a whole turn to every rotated shape: rotate(-6.283185307179586), one turn, comes back as two. The shape looks the same, but the value grows on each save, and after about 98 saves the int rot overflows. Bring the angle into 0..360 degrees with fmod before it is written. Tested with OdpToPptxShape.RotationIsInOneTurn in test_odf: a slide with rotate(0.3), rotate(-6) and a whole turn, written in full and with 7 decimals. It fails without the fix. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Anton Oussik --- OdfFile/Reader/Converter/oox_drawing.cpp | 3 ++ OdfFile/Test/test_odf/CMakeLists.txt | 1 + .../test_odf/ExampleFiles/rotate_range.odp | Bin 0 -> 1390 bytes OdfFile/Test/test_odf/odp2pptx_rotation.cpp | 49 ++++++++++++++++++ REUSE.toml | 5 ++ 5 files changed, 58 insertions(+) create mode 100644 OdfFile/Test/test_odf/ExampleFiles/rotate_range.odp create mode 100644 OdfFile/Test/test_odf/odp2pptx_rotation.cpp diff --git a/OdfFile/Reader/Converter/oox_drawing.cpp b/OdfFile/Reader/Converter/oox_drawing.cpp index 6602b73d71..5ed16c354b 100644 --- a/OdfFile/Reader/Converter/oox_drawing.cpp +++ b/OdfFile/Reader/Converter/oox_drawing.cpp @@ -889,6 +889,9 @@ void _oox_drawing::serialize_xfrm(std::wostream & strm, const std::wstring & nam if (dRotate) { double d = 360 - dRotate.get() * 180. / 3.14159265358979323846; + // 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) ); //60 000 per 1 gr - 19.5.5 oox } _CP_OPT(bool)bVal; diff --git a/OdfFile/Test/test_odf/CMakeLists.txt b/OdfFile/Test/test_odf/CMakeLists.txt index 194fb4ae45..abb241de0b 100644 --- a/OdfFile/Test/test_odf/CMakeLists.txt +++ b/OdfFile/Test/test_odf/CMakeLists.txt @@ -82,6 +82,7 @@ add_core_gtest( odt2docx_chapter_field.cpp ods2xlsx_fill_character.cpp odf_font_family.cpp + odp2pptx_rotation.cpp ${CORE_ROOT_DIR}/Common/OfficeFileFormatChecker2.cpp WORKING_DIRECTORY "${_test_odf_run_dir}" ) 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 0000000000000000000000000000000000000000..57b208e15e3471ed679673c0e300bf6b7a29dfc3 GIT binary patch literal 1390 zcmWIWW@Zs#fB;1XW3@Fa^nn}@<^bZ{%-qzH%7WCyf`XjP=NTCoM1i!gYlx$+r=OdC zZem_$T555LUPW%s)QOH=hYfgKzgxOqu=_YAk4<>_?s*G}86ImGvqhUt44QSjUpiy< zLXlMPE_8P`c35c;NYJLTu^TRDZ3+#Xrw&#atRxXu2wnq89_Q>fpy)#5_U zk0LlipFVm1Tlwaszj~)O=&-U!DZE$Fm@QGAdEkiO8XnmLb4sEDQ`{t0&0ulXU4El! zmWxTs<$YHJUY?zHs=8>!wt{WmN9Rdrai8_`-a7Afoa&V6J3?yAe1nn>1#Uajb^kWY zvj|Z$vwxOvao-2D+{!FJHJ$H>Eh2H8DvD#54%N$IbPbp zU1lbywXfK3pWXF)5AEYFWtmUeb|^NeletK!b#3vdT~8;SIV$B6x?6R<`Rebz>~7k+ zcQhA?UBAN{-1=}0>!fd+m-748&iYb0M{{M$v8K8n%WHcd`krB)vL^eDP1J->zxXn5 z{8@K6X8-Tx-7ol2gL#q%pYsG@Ft21~VBiJ@b8>!O2`EJZ!+CAUX;3)td9JN9Uuvbw z1QX7!4Kb_g9Dg(R86FYZHu3GAfBUv6PH}N`^7Y^Fc<$YssXm)*KXb{fyyVj*;e1O^Wl(O1CzJ z$l$`%g>`11_DZ?T_BNgMZu0LO=ksYgH=lmnx%1HSjWN@+uU}d&UZnGL&FTdc%JTOd zYkQlge&Kl0moLYQ7I>^(v90pkf!dRWSAWe}7WTWasxRVD4%0fe8z=uH9oBm%USQ#I zXIen7H`kxpuje_5yKiu`xYoAnfTLsaFGud06+B;9Z*g@AU0%OnNv@M)##4sf%q2-X zZ!Z7P`$6qqaM-)GykdMGY!+|0&>FHwd4I$=k%~Q^Hu|z@A6jnUy~ps?o9(_v`3qC- zaY`u~MA$FXkGOxL`;cPo!C(EKmMl0Bk#D0~w5?-$;GU?q*%_brb-i~v?!0LI-uYAh zahWMBZz+sD18vRuooy0Jq!#DjG;g#*5U=-2=uIpFv1ULH6o*;>qAd#2z^_bP*Pri SH!B-Rk_8A~0qHyz5Dx&OXfY-L literal 0 HcmV?d00001 diff --git a/OdfFile/Test/test_odf/odp2pptx_rotation.cpp b/OdfFile/Test/test_odf/odp2pptx_rotation.cpp new file mode 100644 index 0000000000..1f65eda306 --- /dev/null +++ b/OdfFile/Test/test_odf/odp2pptx_rotation.cpp @@ -0,0 +1,49 @@ +// 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"; +} diff --git a/REUSE.toml b/REUSE.toml index 38c3b5af4d..ac12a850fb 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -250,3 +250,8 @@ SPDX-License-Identifier = "AGPL-3.0-only" path = "Common/js/stringserialize.js" SPDX-FileCopyrightText = "2010-2024 Ascensio System SIA" 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" From 1eacc55dccf1e731a853572f8bedf8b7e09a2b1d Mon Sep 17 00:00:00 2001 From: Anton Oussik Date: Mon, 16 Nov 2026 11:08:16 +0100 Subject: [PATCH 2/2] fix(OdfFile): round the rotation angle of a shape, do not truncate it rot counts in 1/60000 of a degree, and the cast to int truncated the angle: rotate(0.3) is 342.81126614... degrees, 20568675.97 units, and was written as 20568675, almost a whole unit less. The angle can creep on each open of a saved file. Round to the nearest unit. A value that rounds up to 360 degrees is written as 0. Tested with OdpToPptxShape.RotationIsRounded in test_odf, on the same fixture: rotate(0.3) and rotate(-6) give 20568676 and 20626481, and the whole turn with 7 decimals, which rounds up to 360 degrees, gives 0. It fails without the fix. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Anton Oussik --- OdfFile/Reader/Converter/oox_drawing.cpp | 2 +- OdfFile/Test/test_odf/odp2pptx_rotation.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/OdfFile/Reader/Converter/oox_drawing.cpp b/OdfFile/Reader/Converter/oox_drawing.cpp index 5ed16c354b..40b2dfe994 100644 --- a/OdfFile/Reader/Converter/oox_drawing.cpp +++ b/OdfFile/Reader/Converter/oox_drawing.cpp @@ -892,7 +892,7 @@ void _oox_drawing::serialize_xfrm(std::wostream & strm, const std::wstring & nam // 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) ); //60 000 per 1 gr - 19.5.5 oox + 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/odp2pptx_rotation.cpp b/OdfFile/Test/test_odf/odp2pptx_rotation.cpp index 1f65eda306..ce0ae9e62a 100644 --- a/OdfFile/Test/test_odf/odp2pptx_rotation.cpp +++ b/OdfFile/Test/test_odf/odp2pptx_rotation.cpp @@ -47,3 +47,20 @@ TEST(OdpToPptxShape, RotationIsInOneTurn) } 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"; +}