Kaydet (Commit) 76c7a6c3 authored tarafından Regina Henschel's avatar Regina Henschel Kaydeden (comit) Thorsten Behrens

Improve ODF enhanced-path command moveTo to follow spec

ODF 1.2 section 19.145 says 'If a moveto is followed by multiple
pairs of coordinates, they are treated as lineto.' The patch does
this on import.

Change-Id: Ib493ca49288cdb2d34b7ee801bd052281617d2e8
Reviewed-on: https://gerrit.libreoffice.org/66888
Tested-by: Jenkins
Reviewed-by: 's avatarRegina Henschel <rb.henschel@t-online.de>
üst ecc855aa
...@@ -50,11 +50,13 @@ public: ...@@ -50,11 +50,13 @@ public:
void testViewBoxLeftTop(); void testViewBoxLeftTop();
void testAccuracyCommandX(); void testAccuracyCommandX();
void testToggleCommandXY(); void testToggleCommandXY();
void testMultipleMoveTo();
CPPUNIT_TEST_SUITE(CustomshapesTest); CPPUNIT_TEST_SUITE(CustomshapesTest);
CPPUNIT_TEST(testViewBoxLeftTop); CPPUNIT_TEST(testViewBoxLeftTop);
CPPUNIT_TEST(testAccuracyCommandX); CPPUNIT_TEST(testAccuracyCommandX);
CPPUNIT_TEST(testToggleCommandXY); CPPUNIT_TEST(testToggleCommandXY);
CPPUNIT_TEST(testMultipleMoveTo);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; };
...@@ -161,6 +163,33 @@ void CustomshapesTest::testToggleCommandXY() ...@@ -161,6 +163,33 @@ void CustomshapesTest::testToggleCommandXY()
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("segment height out of tolerance", 5871.0, fHeight, 16.0); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("segment height out of tolerance", 5871.0, fHeight, 16.0);
} }
void CustomshapesTest::testMultipleMoveTo()
{
// tdf122964 Multiple moveTo has to be treated as lineTo in draw:enhanced-path
// Load a document with path "M 0 0 5 10 10 0 N"
OUString aURL = m_directories.getURLFromSrc(sDataDirectory) + "tdf122964_MultipleMoveTo.odg";
mxComponent = loadFromDesktop(aURL, "com.sun.star.comp.drawing.DrawingDocument");
CPPUNIT_ASSERT_MESSAGE("Could not load document", mxComponent.is());
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent,
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_MESSAGE("Could not get XDrawPagesSupplier", xDrawPagesSupplier.is());
uno::Reference<drawing::XDrawPages> xDrawPages(xDrawPagesSupplier->getDrawPages());
uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY_THROW);
// Error was, that the second and further parameter pairs were treated as moveTo,
// and so the generated path was empty, resulting in zero width and height of the
// bounding box. It has to be treated same as "M 0 0 L 5 10 10 0 N".
uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_MESSAGE("Could not get the shape", xShape.is());
uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeProps.is());
awt::Rectangle aBoundRect;
xShapeProps->getPropertyValue(UNO_NAME_MISC_OBJ_BOUNDRECT) >>= aBoundRect;
bool bIsZero(aBoundRect.Height == 0 && aBoundRect.Width == 0);
CPPUNIT_ASSERT_MESSAGE("Path is empty", !bIsZero);
}
CPPUNIT_TEST_SUITE_REGISTRATION(CustomshapesTest); CPPUNIT_TEST_SUITE_REGISTRATION(CustomshapesTest);
} }
......
...@@ -792,16 +792,33 @@ static void GetEnhancedPath( std::vector< css::beans::PropertyValue >& rDest, ...@@ -792,16 +792,33 @@ static void GetEnhancedPath( std::vector< css::beans::PropertyValue >& rDest,
} }
else if ( nParameterCount >= nParametersNeeded ) else if ( nParameterCount >= nParametersNeeded )
{ {
// check if the last command is identical, // Special rule for moveto in ODF 1.2 section 19.145
// if so, we just need to increment the count // "If a moveto is followed by multiple pairs of coordinates, they are treated as lineto."
if ( !vSegments.empty() && ( vSegments[ vSegments.size() - 1 ].Command == nLatestSegmentCommand ) ) if ( nLatestSegmentCommand == css::drawing::EnhancedCustomShapeSegmentCommand::MOVETO )
vSegments[ vSegments.size() -1 ].Count++;
else
{ {
css::drawing::EnhancedCustomShapeSegment aSegment; css::drawing::EnhancedCustomShapeSegment aSegment;
aSegment.Command = nLatestSegmentCommand; aSegment.Command = css::drawing::EnhancedCustomShapeSegmentCommand::MOVETO;
aSegment.Count = 1; aSegment.Count = 1;
vSegments.push_back( aSegment ); vSegments.push_back( aSegment );
nIndex--;
nLatestSegmentCommand = css::drawing::EnhancedCustomShapeSegmentCommand::LINETO;
nParametersNeeded = 1;
}
else
{
// General rule in ODF 1.2. section 19.145
// "If a command is repeated multiple times, all repeated command characters
// except the first one may be omitted." Thus check if the last command is identical,
// if so, we just need to increment the count
if ( !vSegments.empty() && ( vSegments[ vSegments.size() - 1 ].Command == nLatestSegmentCommand ) )
vSegments[ vSegments.size() -1 ].Count++;
else
{
css::drawing::EnhancedCustomShapeSegment aSegment;
aSegment.Command = nLatestSegmentCommand;
aSegment.Count = 1;
vSegments.push_back( aSegment );
}
} }
nParameterCount = 0; nParameterCount = 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment