Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion OdfFile/Reader/Converter/oox_drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions OdfFile/Test/test_odf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file not shown.
66 changes: 66 additions & 0 deletions OdfFile/Test/test_odf/odp2pptx_rotation.cpp
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <vector>

namespace
{
// The values of all rot="..." attributes of a part, in document order.
std::vector<long long> rot_values(const std::wstring& xml)
{
std::vector<long long> 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<long long> 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<long long> 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";
}
5 changes: 5 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"