summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-04-21 12:17:27 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-04-21 13:02:16 +0200
commit7546a904265cc0d0a0e3795cdb411cbb945a39fe (patch)
treeed6870b3998d89c0ecca8b5240287447fe5ba86e
parent59cea45ec247df1acb691308c940ff97673e4c48 (diff)
RTF import: handle d{x,y}WrapDist* picture properties
Commit e789c7f0f15a6b571de95b81e77e3a323e9f540e (RTF import of d{x,y}WrapDist* shape properties, 2013-04-09) added support for wrap distance of shapes, but that was ignored for shapes, as dmapper later overwrote the set margins. Fix this by generating the expected tokens in case of pictures, then dmapper will take care of the rest. Also add testcases for the original shape wrap distance feature that was missing. Change-Id: I6f219ee6fef71328368409d142897dbae77a0f2f
-rw-r--r--sw/qa/extras/rtfimport/data/wrap-distance.rtf69
-rw-r--r--sw/qa/extras/rtfimport/rtfimport.cxx18
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx5
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.hxx2
-rw-r--r--writerfilter/source/rtftok/rtfsdrimport.cxx19
-rw-r--r--writerfilter/source/rtftok/rtfsdrimport.hxx2
6 files changed, 108 insertions, 7 deletions
diff --git a/sw/qa/extras/rtfimport/data/wrap-distance.rtf b/sw/qa/extras/rtfimport/data/wrap-distance.rtf
new file mode 100644
index 000000000000..217f6d955fde
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/wrap-distance.rtf
@@ -0,0 +1,69 @@
+{\rtf1
+{\shp
+{\*\shpinst\shpleft3338\shptop1718\shpright6398\shpbottom3578\shpfhdr0\shpbxcolumn\shpbxignore\shpbypara\shpbyignore\shpwr2\shpwrk0\shpfblwtxt0\shpz1\shplid1027
+{\sp
+{\sn shapeType}
+{\sv 3}
+}
+{\sp
+{\sn dxWrapDistLeft}
+{\sv 1080135}
+}
+{\sp
+{\sn dyWrapDistTop}
+{\sv 360045}
+}
+{\sp
+{\sn dxWrapDistRight}
+{\sv 1440180}
+}
+{\sp
+{\sn dyWrapDistBottom}
+{\sv 720090}
+}
+}
+}
+{\shp
+{\*\shpinst\shpleft-7\shptop-7\shpright1019\shpbottom1019\shpfhdr0\shpbxcolumn\shpbxignore\shpbypara\shpbyignore\shpwr2\shpwrk0\shpfblwtxt0\shpz0\shplid1028
+{\sp
+{\sn shapeType}
+{\sv 75}
+}
+{\sp
+{\sn pib}
+{\sv
+{\pict\picscalex100\picscaley100\piccropl0\piccropr0\piccropt0\piccropb0\picw1806\pich1806\picwgoal1024\pichgoal1024\pngblip\bliptag133373369
+{\*\blipuid 07f31db965a497c78cd3b098b1fb8f43}
+89504e470d0a1a0a0000000d49484452000000400000004008040000000060b9550000000467414d410000b18f0bfc6105000000017352474200aece1ce90000
+00206348524d00007a26000080840000fa00000080e8000075300000ea6000003a98000017709cba513c00000002624b47440000aa8d2332000000096f464673
+0000000600000000000c7355d3000000097048597300000dd700000dd70142289b7800000009767041670000004c00000040009d31381b000001cd4944415468
+deedd93d4fc24018c0f17f89c6cdc44940e3e222be2c0e7e0417e3a8113571707632514012a320c6f84d34be2c2ec2b750f40be8e6e4a00113cfe14a5b69b108
+f4589ee71652eefafce0b9f42e3d7063822aaac3f641d173a75d3efee85b6582c0c8749c5eb7332cfb4e6f213d336ed29807304477b1c7a94db80ae9e9c934d0
+fcdd12e7ffcefcc9168f9a0059143b8cb0d2de581f609854073fbecc220f60b18722479d0d14abed8c8cb5d3293ce2949903b0d8a7047cb1c98541008cba840c
+a736e1d2200046b967567f740961d3b197008873cf74835002eaac7363100009ca0d4296121675d2dc1a0440d2256428625163ed2f42cf011e8245d621b42c44
+0400485261a699706d1000092fa100d4490713220240dc25e438b1090185880ca09f8ece5c28d9843b009e82471ca25069d5cb785529bd007fdbfb8541b65b2f
+531100947a51530d42c1d92f9829818e31ca4ce9421c70e427440e80712a7a89b7c8fb0906003046a5311df31cf501a01f4d0ee1b80f00bd4c398558ee0340ff
+0b939a30df17002459f05d330a080a0108400002108000042000010840000210800004200001f8ce0ddf798e30dd7b38e0ce7ea16d2abc25a819cbda225337c7
+f7ff69bf8eef7f0084e08d42bdf8a03e00000025744558746372656174652d6461746500323031302d31322d32305431373a30383a33362b30313a30307ae51b1c00000025744558746d6f646966792d6461746500323031302d31322d32305431373a30383a33372b30313a30308323669c0000000049454e44ae426082}
+}
+}
+{\sp
+{\sn dxWrapDistLeft}
+{\sv 1080135}
+}
+{\sp
+{\sn dyWrapDistTop}
+{\sv 360045}
+}
+{\sp
+{\sn dxWrapDistRight}
+{\sv 1440180}
+}
+{\sp
+{\sn dyWrapDistBottom}
+{\sv 720090}
+}
+}
+}
+\par
+}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index f4c14c77b63a..ae2873e2a120 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -2245,6 +2245,24 @@ DECLARE_RTFIMPORT_TEST(testTdf86182, "tdf86182.rtf")
CPPUNIT_ASSERT_EQUAL(text::WritingMode2::RL_TB, getProperty<sal_Int16>(getParagraph(1), "WritingMode"));
}
+DECLARE_RTFIMPORT_TEST(testWrapDistance, "wrap-distance.rtf")
+{
+ // Custom shape, handled directly in RTFSdrImport.
+ uno::Reference<drawing::XShape> xShape = getShape(1);
+ CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.CustomShape"), xShape->getShapeType());
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), getProperty<sal_Int32>(xShape, "TopMargin") / 1000);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), getProperty<sal_Int32>(xShape, "BottomMargin") / 1000);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), getProperty<sal_Int32>(xShape, "LeftMargin") / 1000);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), getProperty<sal_Int32>(xShape, "RightMargin") / 1000);
+
+ // Picture, handled in GraphicImport, shared with DOCX.
+ xShape = getShape(2);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), getProperty<sal_Int32>(xShape, "TopMargin") / 1000);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), getProperty<sal_Int32>(xShape, "BottomMargin") / 1000);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), getProperty<sal_Int32>(xShape, "LeftMargin") / 1000);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), getProperty<sal_Int32>(xShape, "RightMargin") / 1000);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index d8e5d6ab9fb8..cfa7992e7d4f 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -926,8 +926,7 @@ RTFError RTFDocumentImpl::resolvePict(bool const bInline, uno::Reference<drawing
{
// wrap sprm
RTFSprms aAnchorWrapAttributes;
- RTFSprms aAnchorAttributes;
- aAnchorAttributes.set(NS_ooxml::LN_CT_Anchor_behindDoc, std::make_shared<RTFValue>((m_aStates.top().aShape.bInBackground) ? 1 : 0));
+ m_aStates.top().aShape.aAnchorAttributes.set(NS_ooxml::LN_CT_Anchor_behindDoc, std::make_shared<RTFValue>((m_aStates.top().aShape.bInBackground) ? 1 : 0));
RTFSprms aAnchorSprms;
for (RTFSprms::Iterator_t i = m_aStates.top().aCharacterAttributes.begin(); i != m_aStates.top().aCharacterAttributes.end(); ++i)
{
@@ -979,7 +978,7 @@ RTFError RTFDocumentImpl::resolvePict(bool const bInline, uno::Reference<drawing
aAnchorSprms.set(NS_ooxml::LN_CT_Anchor_docPr, pDocprValue);
aAnchorSprms.set(NS_ooxml::LN_graphic_graphic, pGraphicValue);
// anchor sprm
- auto pValue = std::make_shared<RTFValue>(aAnchorAttributes, aAnchorSprms);
+ auto pValue = std::make_shared<RTFValue>(m_aStates.top().aShape.aAnchorAttributes, aAnchorSprms);
aSprms.set(NS_ooxml::LN_anchor_anchor, pValue);
}
writerfilter::Reference<Properties>::Pointer_t pProperties = std::make_shared<RTFReferenceProperties>(aAttributes, aSprms);
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index dddd0eeb6509..45d3f6fa9018 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -142,6 +142,8 @@ public:
bool bInBackground;
/// Wrap polygon, written by RTFSdrImport::resolve(), read by RTFDocumentImpl::resolvePict().
RTFSprms aWrapPolygonSprms;
+ /// Anchor attributes like wrap distance, written by RTFSdrImport::resolve(), read by RTFDocumentImpl::resolvePict().
+ RTFSprms aAnchorAttributes;
};
/// Stores the properties of a drawing object.
diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx
index aad5c01b0758..400a26b017dc 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -45,6 +45,7 @@ RTFSdrImport::RTFSdrImport(RTFDocumentImpl& rDocument,
uno::Reference<lang::XComponent> const& xDstDoc)
: m_rImport(rDocument)
, m_bTextFrame(false)
+ , m_bTextGraphicObject(false)
, m_bFakePict(false)
{
uno::Reference<drawing::XDrawPageSupplier> xDrawings(xDstDoc, uno::UNO_QUERY);
@@ -257,6 +258,7 @@ int RTFSdrImport::initShape(uno::Reference<drawing::XShape>& o_xShape,
{
case ESCHER_ShpInst_PictureFrame:
createShape("com.sun.star.drawing.GraphicObjectShape", o_xShape, o_xPropSet);
+ m_bTextGraphicObject = true;
break;
case ESCHER_ShpInst_Line:
createShape("com.sun.star.drawing.LineShape", o_xShape, o_xPropSet);
@@ -293,6 +295,7 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose, ShapeOrPict const shap
{
bool bPib = false;
m_bTextFrame = false;
+ m_bTextGraphicObject = false;
uno::Reference<drawing::XShape> xShape;
uno::Reference<beans::XPropertySet> xPropertySet;
@@ -524,22 +527,30 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose, ShapeOrPict const shap
}
else if (i->first == "dxWrapDistLeft")
{
- if (xPropertySet.is())
+ if (m_bTextGraphicObject)
+ rShape.aAnchorAttributes.set(NS_ooxml::LN_CT_Anchor_distL, std::make_shared<RTFValue>(i->second.toInt32()));
+ else if (xPropertySet.is())
xPropertySet->setPropertyValue("LeftMargin", uno::makeAny(i->second.toInt32() / 360));
}
else if (i->first == "dyWrapDistTop")
{
- if (xPropertySet.is())
+ if (m_bTextGraphicObject)
+ rShape.aAnchorAttributes.set(NS_ooxml::LN_CT_Anchor_distT, std::make_shared<RTFValue>(i->second.toInt32()));
+ else if (xPropertySet.is())
xPropertySet->setPropertyValue("TopMargin", uno::makeAny(i->second.toInt32() / 360));
}
else if (i->first == "dxWrapDistRight")
{
- if (xPropertySet.is())
+ if (m_bTextGraphicObject)
+ rShape.aAnchorAttributes.set(NS_ooxml::LN_CT_Anchor_distR, std::make_shared<RTFValue>(i->second.toInt32()));
+ else if (xPropertySet.is())
xPropertySet->setPropertyValue("RightMargin", uno::makeAny(i->second.toInt32() / 360));
}
else if (i->first == "dyWrapDistBottom")
{
- if (xPropertySet.is())
+ if (m_bTextGraphicObject)
+ rShape.aAnchorAttributes.set(NS_ooxml::LN_CT_Anchor_distB, std::make_shared<RTFValue>(i->second.toInt32()));
+ else if (xPropertySet.is())
xPropertySet->setPropertyValue("BottomMargin", uno::makeAny(i->second.toInt32() / 360));
}
else if (i->first == "fillType")
diff --git a/writerfilter/source/rtftok/rtfsdrimport.hxx b/writerfilter/source/rtftok/rtfsdrimport.hxx
index 8cdaabb3f92e..f6a94e8deeb0 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.hxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.hxx
@@ -67,6 +67,8 @@ private:
css::uno::Reference<css::drawing::XShape> m_xShape;
/// If m_xShape is imported as a Writer text frame (instead of a drawinglayer rectangle).
bool m_bTextFrame;
+ /// If m_xShape is imported as a Writer text graphic object (instead of a drawinglayer shape).
+ bool m_bTextGraphicObject;
/// if inside \pict, but actually it's a shape (not a picture)
bool m_bFakePict;
writerfilter::dmapper::GraphicZOrderHelper m_aGraphicZOrderHelper;