From b0058366190b63fcbc112b43d387f7600a7fe55d Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 12 Jan 2016 09:06:49 +0100 Subject: tdf#61511 RTF export: handle page background solid color fill Change-Id: I562419b6d4fb791ef5b255effe9a4510d930bdbc --- include/svtools/rtfkeywd.hxx | 1 + sw/qa/extras/rtfexport/data/page-background.rtf | 30 +++++++++++++++++++++++++ sw/qa/extras/rtfexport/rtfexport.cxx | 7 ++++++ sw/qa/extras/rtfimport/data/page-background.rtf | 30 ------------------------- sw/qa/extras/rtfimport/rtfimport.cxx | 7 ------ sw/source/filter/ww8/docxexport.cxx | 16 ------------- sw/source/filter/ww8/docxexport.hxx | 3 --- sw/source/filter/ww8/rtfexport.cxx | 24 ++++++++++++++++++++ sw/source/filter/ww8/wrtww8.cxx | 16 +++++++++++++ sw/source/filter/ww8/wrtww8.hxx | 2 ++ 10 files changed, 80 insertions(+), 56 deletions(-) create mode 100644 sw/qa/extras/rtfexport/data/page-background.rtf delete mode 100644 sw/qa/extras/rtfimport/data/page-background.rtf diff --git a/include/svtools/rtfkeywd.hxx b/include/svtools/rtfkeywd.hxx index d57fd13feb53..55d97f51bd16 100644 --- a/include/svtools/rtfkeywd.hxx +++ b/include/svtools/rtfkeywd.hxx @@ -1207,6 +1207,7 @@ #define LO_STRING_SVTOOLS_RTF_LEVELPICTURE "\\levelpicture" #define LO_STRING_SVTOOLS_RTF_BRDRSH "\\brdrsh" #define LO_STRING_SVTOOLS_RTF_GENERATOR "\\generator" +#define LO_STRING_SVTOOLS_RTF_VIEWBKSP "\\viewbksp" #endif // INCLUDED_SVTOOLS_RTFKEYWD_HXX diff --git a/sw/qa/extras/rtfexport/data/page-background.rtf b/sw/qa/extras/rtfexport/data/page-background.rtf new file mode 100644 index 000000000000..68c3ccf8dc9c --- /dev/null +++ b/sw/qa/extras/rtfexport/data/page-background.rtf @@ -0,0 +1,30 @@ +{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch31506\stshfloch31506\stshfhich31506\stshfbi31507\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0 +\viewbksp1 +{\*\background +{\shp +{\*\shpinst\shpleft0\shptop0\shpright0\shpbottom0\shpfhdr0\shpbxmargin\shpbxignore\shpbymargin\shpbyignore\shpwr0\shpwrk0\shpfblwtxt1 +{\sp +{\sn shapeType} +{\sv 1} +} +{\sp +{\sn fillColor} +{\sv 5296274} +} +{\sp +{\sn fFilled} +{\sv 1} +} +{\sp +{\sn bWMode} +{\sv 9} +} +{\sp +{\sn fBackground} +{\sv 1} +} +} +} +} +\par +} diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index 58dadbc7dddd..f39e01345fc7 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -966,6 +966,13 @@ DECLARE_RTFEXPORT_TEST(testTdf94377, "tdf94377.rtf") CPPUNIT_ASSERT_EQUAL(12.f, getProperty(getRun(getParagraphOfText(2, xText, "asdf12"), 1), "CharHeight")); } +DECLARE_RTFEXPORT_TEST(testPageBackground, "page-background.rtf") +{ + // The problem was that \background was ignored. + uno::Reference xPageStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0x92D050), getProperty(xPageStyle, "BackColor")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/rtfimport/data/page-background.rtf b/sw/qa/extras/rtfimport/data/page-background.rtf deleted file mode 100644 index e19d2d4c3547..000000000000 --- a/sw/qa/extras/rtfimport/data/page-background.rtf +++ /dev/null @@ -1,30 +0,0 @@ -{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch31506\stshfloch31506\stshfhich31506\stshfbi31507\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0 -\viewbksp1 -{\*\background -{\shp -{\*\shpinst\shpleft0\shptop0\shpright0\shpbottom0\shpfhdr0\shpbxmargin\shpbxignore\shpbymargin\shpbyignore\shpwr0\shpwrk0\shpfblwtxt1 -{\sp -{\sn shapeType} -{\sv 1} -} -{\sp -{\sn fillColor} -{\sv 5296274} -} -{\sp -{\sn fFilled} -{\sv 1} -} -{\sp -{\sn bWMode} -{\sv 9} -} -{\sp -{\sn fBackground} -{\sv 1} -} -} -} -} -\par -} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 5e1749fc12ec..43d0fcb891f1 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -1221,13 +1221,6 @@ DECLARE_RTFIMPORT_TEST(testFdo64671, "fdo64671.rtf") getRun(getParagraph(1), 1, OUString("\xC5\xBD", 2, RTL_TEXTENCODING_UTF8)); } -DECLARE_RTFIMPORT_TEST(testPageBackground, "page-background.rtf") -{ - // The problem was that \background was ignored. - uno::Reference xPageStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0x92D050), getProperty(xPageStyle, "BackColor")); -} - DECLARE_RTFIMPORT_TEST(testFdo81944, "fdo81944.rtf") { // font properties in style were not imported diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 2c04e3f82062..6382af4196c2 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -1306,22 +1306,6 @@ bool DocxExport::isMirroredMargin() return bMirroredMargins; } -boost::optional DocxExport::getBackground() -{ - boost::optional oRet; - const SwFrameFormat &rFormat = m_pDoc->GetPageDesc(0).GetMaster(); - SvxBrushItem aBrush(RES_BACKGROUND); - SfxItemState eState = rFormat.GetBackgroundState(aBrush); - - if (SfxItemState::SET == eState) - { - // The 'color' is set for the first page style - take it and use it as the background color of the entire DOCX - if (aBrush.GetColor().GetColor() != COL_AUTO) - oRet.reset(aBrush); - } - return oRet; -} - void DocxExport::WriteMainText() { // setup the namespaces diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx index 124b62614179..42eaecab2c94 100644 --- a/sw/source/filter/ww8/docxexport.hxx +++ b/sw/source/filter/ww8/docxexport.hxx @@ -241,9 +241,6 @@ private: /// Write word/embeddings/Worksheet[n].xlsx void WriteEmbeddings(); - /// Get background color of the document, if there is one. - boost::optional getBackground(); - /// return true if Page Layout is set as Mirrored bool isMirroredMargin(); diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index 29e4ae0436ad..4fed09fa55cd 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -386,6 +386,30 @@ void RtfExport::WriteMainText() { SAL_INFO("sw.rtf", OSL_THIS_FUNC << " start"); + if (boost::optional oBrush = getBackground()) + { + Strm().WriteCharPtr(LO_STRING_SVTOOLS_RTF_VIEWBKSP).WriteChar('1'); + Strm().WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_BACKGROUND); + Strm().WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_SHP); + Strm().WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_SHPINST); + + std::vector< std::pair > aProperties; + aProperties.push_back(std::make_pair("shapeType", "1")); + aProperties.push_back(std::make_pair("fillColor", OString::number(msfilter::util::BGRToRGB(oBrush->GetColor().GetColor())))); + for (size_t i = 0; i < aProperties.size(); ++i) + { + Strm().WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_SP "{"); + Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_SN " "); + Strm().WriteCharPtr(aProperties[i].first.getStr()); + Strm().WriteCharPtr("}{" OOO_STRING_SVTOOLS_RTF_SV " "); + Strm().WriteCharPtr(aProperties[i].second.getStr()); + Strm().WriteCharPtr("}}"); + } + Strm().WriteChar('}'); // shpinst + Strm().WriteChar('}'); // shp + Strm().WriteChar('}'); // background + } + SwTableNode* pTableNode = m_pCurPam->GetNode().FindTableNode(); if (m_pWriter && m_pWriter->bWriteOnlyFirstTable && pTableNode != nullptr) diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index 6503a6886ae0..92a2b41f9f8f 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -1520,6 +1520,22 @@ void WW8Export::AppendBookmark( const OUString& rName, bool bSkip ) m_pBkmks->Append( nSttCP, rName ); } +boost::optional MSWordExportBase::getBackground() +{ + boost::optional oRet; + const SwFrameFormat &rFormat = m_pDoc->GetPageDesc(0).GetMaster(); + SvxBrushItem aBrush(RES_BACKGROUND); + SfxItemState eState = rFormat.GetBackgroundState(aBrush); + + if (SfxItemState::SET == eState) + { + // The 'color' is set for the first page style - take it and use it as the background color of the entire DOCX + if (aBrush.GetColor().GetColor() != COL_AUTO) + oRet.reset(aBrush); + } + return oRet; +} + // #i120928 collect all the graphics of bullets applied to paragraphs int MSWordExportBase::CollectGrfsOfBullets() { diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx index e2ef06c19573..e10075b3c345 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -865,6 +865,8 @@ protected: void SetCurPam(sal_uLong nStt, sal_uLong nEnd); + /// Get background color of the document, if there is one. + boost::optional getBackground(); /// Populates m_vecBulletPic with all the bullet graphics used by numberings. int CollectGrfsOfBullets(); /// Write the numbering picture bullets. -- cgit v1.2.3