sw/qa/extras/rtfexport/data/textframe-borders.rtf | 49 +++++++++++++++++ sw/qa/extras/rtfexport/rtfexport.cxx | 21 +++++++ sw/source/filter/ww8/rtfattributeoutput.cxx | 61 +++++++++++++++++++++- 3 files changed, 129 insertions(+), 2 deletions(-)
New commits: commit bb9fce28d6d5f1cabc2af533bfdc7997ffb7184a Author: Miklos Vajna <[email protected]> Date: Mon Apr 15 13:31:01 2013 +0200 sw: RTF export of TextFrame border/shadow testcase Change-Id: I85b85afb6d1b170d71633f93d56f7ce4fffdf0a3 diff --git a/sw/qa/extras/rtfexport/data/textframe-borders.rtf b/sw/qa/extras/rtfexport/data/textframe-borders.rtf new file mode 100644 index 0000000..9aa1805 --- /dev/null +++ b/sw/qa/extras/rtfexport/data/textframe-borders.rtf @@ -0,0 +1,49 @@ +{\rtf1 +{\shp +{\*\shpinst\shpleft-540\shptop152\shpright9900\shpbottom1592\shpfhdr0\shpbxcolumn\shpbxignore\shpbypara\shpbyignore\shpwr3\shpwrk0\shpfblwtxt0\shpz0\shplid1026 +{\sp +{\sn shapeType} +{\sv 1} +} +{\sp +{\sn fFitShapeToText} +{\sv 1} +} +{\sp +{\sn fillColor} +{\sv 9737689} +} +{\sp +{\sn lineColor} +{\sv 5066944} +} +{\sp +{\sn lineWidth} +{\sv 12700} +} +{\sp +{\sn shadowType} +{\sv 2} +} +{\sp +{\sn shadowColor} +{\sv 2303074} +} +{\sp +{\sn shadowOffsetX} +{\sv 12700} +} +{\sp +{\sn shadowSecondOffsetX} +{\sv -38100} +} +{\sp +{\sn fShadow} +{\sv 1} +} +{\shptxt aaa +} +} +} +\par +} diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index ba8defd..f9ca432 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -28,6 +28,8 @@ #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp> #include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/table/BorderLine2.hpp> +#include <com/sun/star/table/ShadowFormat.hpp> #include <com/sun/star/text/XFootnotesSupplier.hpp> #include <com/sun/star/text/XPageCursor.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> @@ -77,6 +79,7 @@ public: void testI120928(); void testBookmark(); void testHyperlink(); + void testTextFrameBorders(); CPPUNIT_TEST_SUITE(Test); #if !defined(MACOSX) && !defined(WNT) @@ -128,6 +131,7 @@ void Test::run() {"i120928.rtf", &Test::testI120928}, {"bookmark.rtf", &Test::testBookmark}, {"hyperlink.rtf", &Test::testHyperlink}, + {"textframe-borders.rtf", &Test::testTextFrameBorders}, }; // Don't test the first import of these, for some reason those tests fail const char* aBlacklist[] = { @@ -557,6 +561,23 @@ void Test::testHyperlink() CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(getRun(getParagraph(1), 3, "!"), "HyperLinkURL")); } +void Test::testTextFrameBorders() +{ + uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xFrame(xIndexAccess->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xD99594), getProperty<sal_Int32>(xFrame, "BackColor")); + + table::BorderLine2 aBorder = getProperty<table::BorderLine2>(xFrame, "TopBorder"); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xC0504D), aBorder.Color); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(35), aBorder.LineWidth); + + table::ShadowFormat aShadowFormat = getProperty<table::ShadowFormat>(xFrame, "ShadowFormat"); + CPPUNIT_ASSERT_EQUAL(table::ShadowLocation_BOTTOM_RIGHT, aShadowFormat.Location); + CPPUNIT_ASSERT_EQUAL(sal_Int16(48), aShadowFormat.ShadowWidth); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0x622423), aShadowFormat.Color); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); commit d74ba0c4147f33abd9d0c03883cc88f15e160ee5 Author: Miklos Vajna <[email protected]> Date: Mon Apr 15 13:01:22 2013 +0200 RtfAttributeOutput::FormatBackground: export fillColor Change-Id: I9d187fc5b52a27ff5b8bc847a52fe95c63558a40 diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index 5c92b3a..f645c87 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -2950,7 +2950,13 @@ void RtfAttributeOutput::FormatBackground( const SvxBrushItem& rBrush ) { SAL_INFO("sw.rtf", OSL_THIS_FUNC); - if( !rBrush.GetColor().GetTransparency() ) + if (m_rExport.bRTFFlySyntax) + { + const Color& rColor = rBrush.GetColor(); + // We in fact need RGB to BGR, but the transformation is symmetric. + m_aFlyProperties.push_back(std::make_pair<OString, OString>("fillColor", OString::number(msfilter::util::BGRToRGB(rColor.GetColor())))); + } + else if( !rBrush.GetColor().GetTransparency() ) { m_aStyles.append(OOO_STRING_SVTOOLS_RTF_CBPAT); m_aStyles.append((sal_Int32)m_rExport.GetColor(rBrush.GetColor())); commit d897033777400e029de8751df98f2fc0b0cf34f5 Author: Miklos Vajna <[email protected]> Date: Mon Apr 15 12:53:16 2013 +0200 RtfAttributeOutput: export fShadow, shadowColor, shadowOffset* Change-Id: Ia6d27eadb41d66de558c290bc07b6d1c491f5f1c diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index 1521b75..5c92b3a 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -64,6 +64,7 @@ #include <editeng/frmdiritem.hxx> #include <editeng/blinkitem.hxx> #include <editeng/charhiddenitem.hxx> +#include <editeng/shaditem.hxx> #include <svx/svdmodel.hxx> #include <svx/fmglob.hxx> #include <svx/svdouno.hxx> @@ -1487,6 +1488,38 @@ void RtfAttributeOutput::WriteHeaderFooter_Impl( const SwFrmFmt& rFmt, bool bHea m_aRun = aRun; } +void lcl_TextFrameShadow(std::vector< std::pair<OString, OString> >& rFlyProperties, const SwFrmFmt& rFrmFmt) +{ + SvxShadowItem aShadowItem = rFrmFmt.GetShadow(); + if (aShadowItem.GetLocation() == SVX_SHADOW_NONE) + return; + + rFlyProperties.push_back(std::make_pair<OString, OString>("fShadow", OString::number(1))); + + const Color& rColor = aShadowItem.GetColor(); + // We in fact need RGB to BGR, but the transformation is symmetric. + rFlyProperties.push_back(std::make_pair<OString, OString>("shadowColor", OString::number(msfilter::util::BGRToRGB(rColor.GetColor())))); + + // Twips -> points -> EMUs -- hacky, the intermediate step hides rounding errors on roundtrip. + OString aShadowWidth = OString::number(sal_Int32(aShadowItem.GetWidth() / 20) * 12700); + OString aOffsetX; + OString aOffsetY; + switch (aShadowItem.GetLocation()) + { + case SVX_SHADOW_TOPLEFT: aOffsetX = "-" + aShadowWidth; aOffsetY = "-" + aShadowWidth; break; + case SVX_SHADOW_TOPRIGHT: aOffsetX = aShadowWidth; aOffsetY = "-" + aShadowWidth; break; + case SVX_SHADOW_BOTTOMLEFT: aOffsetX = "-" + aShadowWidth; aOffsetY = aShadowWidth; break; + case SVX_SHADOW_BOTTOMRIGHT: aOffsetX = aShadowWidth; aOffsetY = aShadowWidth; break; + case SVX_SHADOW_NONE: + case SVX_SHADOW_END: + break; + } + if (!aOffsetX.isEmpty()) + rFlyProperties.push_back(std::make_pair<OString, OString>("shadowOffsetX", OString(aOffsetX))); + if (!aOffsetY.isEmpty()) + rFlyProperties.push_back(std::make_pair<OString, OString>("shadowOffsetY", OString(aOffsetY))); +} + void RtfAttributeOutput::OutputFlyFrame_Impl( const sw::Frame& rFrame, const Point& /*rNdTopLeft*/ ) { SAL_INFO("sw.rtf", OSL_THIS_FUNC); @@ -1519,6 +1552,9 @@ void RtfAttributeOutput::OutputFlyFrame_Impl( const sw::Frame& rFrame, const Poi m_rExport.bOutFlyFrmAttrs = m_rExport.bRTFFlySyntax = false; m_pFlyFrameSize = 0; + const SwFrmFmt& rFrmFmt = rFrame.GetFrmFmt(); + lcl_TextFrameShadow(m_aFlyProperties, rFrmFmt); + for (size_t i = 0; i < m_aFlyProperties.size(); ++i) { m_rExport.Strm() << "{" OOO_STRING_SVTOOLS_RTF_SP "{"; @@ -1546,7 +1582,6 @@ void RtfAttributeOutput::OutputFlyFrame_Impl( const sw::Frame& rFrame, const Poi m_bSingleEmptyRun = false; m_rExport.bRTFFlySyntax = true; - const SwFrmFmt& rFrmFmt = rFrame.GetFrmFmt( ); const SwNodeIndex* pNodeIndex = rFrmFmt.GetCntnt().GetCntntIdx(); sal_uLong nStt = pNodeIndex ? pNodeIndex->GetIndex()+1 : 0; sal_uLong nEnd = pNodeIndex ? pNodeIndex->GetNode().EndOfSectionIndex() : 0; commit 9e6a5b94e00f0054b058dbb42c2c0b6c75236c9d Author: Miklos Vajna <[email protected]> Date: Mon Apr 15 11:52:44 2013 +0200 RtfAttributeOutput::FormatBox: export line{Color,Width} shape properties Change-Id: Id1fd8b4c7ebcc8ffd3b6914596385eb3eda922c6 diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index 2918e5d..1521b75 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -2948,6 +2948,22 @@ void RtfAttributeOutput::FormatBox( const SvxBoxItem& rBox ) m_aFlyProperties.push_back(std::make_pair<OString, OString>("dyTextTop", OString::number(rBox.GetDistance(BOX_LINE_TOP) * 635))); m_aFlyProperties.push_back(std::make_pair<OString, OString>("dxTextRight", OString::number(rBox.GetDistance(BOX_LINE_RIGHT) * 635))); m_aFlyProperties.push_back(std::make_pair<OString, OString>("dyTextBottom", OString::number(rBox.GetDistance(BOX_LINE_BOTTOM) * 635))); + + const SvxBorderLine* pLeft = rBox.GetLine(BOX_LINE_LEFT); + const SvxBorderLine* pRight = rBox.GetLine(BOX_LINE_RIGHT); + const SvxBorderLine* pTop = rBox.GetLine(BOX_LINE_TOP); + const SvxBorderLine* pBottom = rBox.GetLine(BOX_LINE_BOTTOM); + if (pLeft && pRight && pTop && pBottom && *pLeft == *pRight && *pLeft == *pTop && *pLeft == *pBottom) + { + const Color& rColor = pTop->GetColor(); + // We in fact need RGB to BGR, but the transformation is symmetric. + m_aFlyProperties.push_back(std::make_pair<OString, OString>("lineColor", OString::number(msfilter::util::BGRToRGB(rColor.GetColor())))); + + double const fConverted(editeng::ConvertBorderWidthToWord(pTop->GetBorderLineStyle(), pTop->GetWidth())); + sal_Int32 nWidth = sal_Int32(fConverted * 635); // Twips -> EMUs + m_aFlyProperties.push_back(std::make_pair<OString, OString>("lineWidth", OString::number(nWidth))); + } + return; } _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
