RTF import: handle Relative{Height,Width}{,Relation}
Change-Id: Ic3a578af9c0808b188a4d196b1c132c0b23f15f7
This commit is contained in:
parent
3952fab4ed
commit
bc5060b32f
42
sw/qa/extras/rtfimport/data/relsize.rtf
Normal file
42
sw/qa/extras/rtfimport/data/relsize.rtf
Normal file
@ -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}
|
||||
}
|
@ -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: */
|
||||
|
@ -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())
|
||||
|
Loading…
x
Reference in New Issue
Block a user