[Libreoffice-commits] core.git: sw/qa writerfilter/source
Miklos Vajna
vmiklos at collabora.co.uk
Wed Mar 26 03:53:31 PDT 2014
sw/qa/extras/rtfimport/data/relsize.rtf | 42 ++++++++++++++++++++
sw/qa/extras/rtfimport/rtfimport.cxx | 9 ++++
writerfilter/source/rtftok/rtfsdrimport.cxx | 57 ++++++++++++++++++++++++++++
3 files changed, 108 insertions(+)
New commits:
commit bc5060b32f08b0408fb929faea1f8140a58d3cc5
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Wed Mar 26 11:43:31 2014 +0100
RTF import: handle Relative{Height,Width}{,Relation}
Change-Id: Ic3a578af9c0808b188a4d196b1c132c0b23f15f7
diff --git a/sw/qa/extras/rtfimport/data/relsize.rtf b/sw/qa/extras/rtfimport/data/relsize.rtf
new file mode 100644
index 0000000..b32186a
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/relsize.rtf
@@ -0,0 +1,42 @@
+{\rtf1
+\paperw12240\paperh15840\margl1417\margr1417\margt1417\margb1417
+\pard\plain
+{\rtlch
+{\shp
+{\*\shpinst\shpleft0\shptop0\shpright3739\shpbottom2211\shpwr2\shpwrk0\shpfblwtxt0\shpz0
+{\sp
+{\sn shapeType}
+{\sv 202}
+}
+{\sp
+{\sn posh}
+{\sv 2}
+}
+{\sp
+{\sn dhgt}
+{\sv 251659264}
+}
+{\sp
+{\sn fBehindDocument}
+{\sv 0}
+}
+{\sp
+{\sn pctHoriz}
+{\sv 400}
+}
+{\sp
+{\sn pctVert}
+{\sv 200}
+}
+{\sp
+{\sn sizerelv}
+{\sv 0}
+}
+{\shptxt Textbox text.
+\par}
+}
+}
+}
+{Relative height: 20%, margin.\par}
+{Relative width: 40%, page.\par}
+}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index cb19476..738d1e2 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -1619,6 +1619,15 @@ DECLARE_RTFIMPORT_TEST(testDprectAnchor, "dprect-anchor.rtf")
CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType"));
}
+DECLARE_RTFIMPORT_TEST(testRelsize, "relsize.rtf")
+{
+ uno::Reference<drawing::XShape> xShape = getShape(1);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(40), getProperty<sal_Int16>(xShape, "RelativeWidth"));
+ CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xShape, "RelativeWidthRelation"));
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(20), getProperty<sal_Int16>(xShape, "RelativeHeight"));
+ CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty<sal_Int16>(xShape, "RelativeHeightRelation"));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx
index d9871d9..4b87586 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -242,6 +242,10 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
bool bOpaque = true;
+ boost::optional<sal_Int16> oRelativeWidth, oRelativeHeight;
+ sal_Int16 nRelativeWidthRelation = text::RelOrientation::PAGE_FRAME;
+ sal_Int16 nRelativeHeightRelation = text::RelOrientation::PAGE_FRAME;
+
// The spec doesn't state what is the default for shapeType, Word seems to implement it as a rectangle.
if (std::find_if(rShape.aProperties.begin(),
rShape.aProperties.end(),
@@ -540,6 +544,49 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
oRelBottom.reset(TWIP_TO_MM100(i->second.toInt32()));
else if (i->first == "fBehindDocument")
bOpaque = !i->second.toInt32();
+ else if (i->first == "pctHoriz" || i->first == "pctVert")
+ {
+ sal_Int16 nPercentage = rtl::math::round(i->second.toDouble() / 10);
+ boost::optional<sal_Int16>& rPercentage = i->first == "pctHoriz" ? oRelativeWidth : oRelativeHeight;
+ if (nPercentage)
+ rPercentage = nPercentage;
+ }
+ else if (i->first == "sizerelh")
+ {
+ if (xPropertySet.is())
+ {
+ switch (i->second.toInt32())
+ {
+ case 0: // margin
+ nRelativeWidthRelation = text::RelOrientation::FRAME;
+ break;
+ case 1: // page
+ nRelativeWidthRelation = text::RelOrientation::PAGE_FRAME;
+ break;
+ default:
+ SAL_WARN("writerfilter", "RTFSdrImport::resolve: unhandled sizerelh value: " << i->second);
+ break;
+ }
+ }
+ }
+ else if (i->first == "sizerelv")
+ {
+ if (xPropertySet.is())
+ {
+ switch (i->second.toInt32())
+ {
+ case 0: // margin
+ nRelativeHeightRelation = text::RelOrientation::FRAME;
+ break;
+ case 1: // page
+ nRelativeHeightRelation = text::RelOrientation::PAGE_FRAME;
+ break;
+ default:
+ SAL_WARN("writerfilter", "RTFSdrImport::resolve: unhandled sizerelv value: " << i->second);
+ break;
+ }
+ }
+ }
else
SAL_INFO("writerfilter", "TODO handle shape property '" << i->first << "':'" << i->second << "'");
}
@@ -675,6 +722,16 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
}
xPropertySet->setPropertyValue("AnchorType", uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
xPropertySet->setPropertyValue("Opaque", uno::makeAny(bOpaque));
+ if (oRelativeWidth)
+ {
+ xPropertySet->setPropertyValue("RelativeWidth", uno::makeAny(*oRelativeWidth));
+ xPropertySet->setPropertyValue("RelativeWidthRelation", uno::makeAny(nRelativeWidthRelation));
+ }
+ if (oRelativeHeight)
+ {
+ xPropertySet->setPropertyValue("RelativeHeight", uno::makeAny(*oRelativeHeight));
+ xPropertySet->setPropertyValue("RelativeHeightRelation", uno::makeAny(nRelativeHeightRelation));
+ }
}
if (m_rImport.isInBackground())
More information about the Libreoffice-commits
mailing list