diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-01-12 09:06:49 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2016-02-04 16:47:47 +0000 |
commit | 7e8be547eb44b0211ab45e21c6961e2dc3995a84 (patch) | |
tree | 7d26b96ad0046fa132bf7a967236d3ba1949a8fc | |
parent | 9c9876c8b63fb47814e05141c74a4fc244cfa56c (diff) |
tdf#61511 RTF export: handle page background solid color fill
(cherry picked from commit b0058366190b63fcbc112b43d387f7600a7fe55d)
Conflicts:
sw/qa/extras/rtfexport/rtfexport.cxx
Change-Id: I562419b6d4fb791ef5b255effe9a4510d930bdbc
Reviewed-on: https://gerrit.libreoffice.org/22085
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r-- | include/svtools/rtfkeywd.hxx | 1 | ||||
-rw-r--r-- | sw/qa/extras/rtfexport/data/page-background.rtf (renamed from sw/qa/extras/rtfimport/data/page-background.rtf) | 2 | ||||
-rw-r--r-- | sw/qa/extras/rtfexport/rtfexport.cxx | 7 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 7 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 16 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.hxx | 3 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfexport.cxx | 24 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.cxx | 16 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.hxx | 2 |
9 files changed, 51 insertions, 27 deletions
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/rtfimport/data/page-background.rtf b/sw/qa/extras/rtfexport/data/page-background.rtf index e19d2d4c3547..68c3ccf8dc9c 100644 --- a/sw/qa/extras/rtfimport/data/page-background.rtf +++ b/sw/qa/extras/rtfexport/data/page-background.rtf @@ -1,6 +1,6 @@ {\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch31506\stshfloch31506\stshfhich31506\stshfbi31507\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0 \viewbksp1 -{\*\background +{\*\background {\shp {\*\shpinst\shpleft0\shptop0\shpright0\shpbottom0\shpfhdr0\shpbxmargin\shpbxignore\shpbymargin\shpbyignore\shpwr0\shpwrk0\shpfblwtxt1 {\sp diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index 33d6ca41f6d2..56040f898327 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -912,6 +912,13 @@ DECLARE_RTFEXPORT_TEST(testTdf90421, "tdf90421.fodt") } } +DECLARE_RTFEXPORT_TEST(testPageBackground, "page-background.rtf") +{ + // The problem was that \background was ignored. + uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0x92D050), getProperty<sal_Int32>(xPageStyle, "BackColor")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 0544b1e829fd..67efc3dd1122 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<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0x92D050), getProperty<sal_Int32>(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 833c21381167..d3000eb2bbc3 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -1507,22 +1507,6 @@ bool DocxExport::isMirroredMargin() return bMirroredMargins; } -boost::optional<SvxBrushItem> DocxExport::getBackground() -{ - boost::optional<SvxBrushItem> 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 c028498ae2a7..3aaa853aad66 100644 --- a/sw/source/filter/ww8/docxexport.hxx +++ b/sw/source/filter/ww8/docxexport.hxx @@ -245,9 +245,6 @@ private: /// Write word/embeddings/Worksheet[n].xlsx void WriteEmbeddings(); - /// Get background color of the document, if there is one. - boost::optional<SvxBrushItem> 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 6c7da6aac393..efbf120ff8ab 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -389,6 +389,30 @@ void RtfExport::WriteMainText() { SAL_INFO("sw.rtf", OSL_THIS_FUNC << " start"); + if (boost::optional<SvxBrushItem> 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<OString, OString> > aProperties; + aProperties.push_back(std::make_pair<OString, OString>("shapeType", "1")); + aProperties.push_back(std::make_pair<OString, OString>("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 != 0) diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index 9dad99d8a424..9525c5be5764 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -1396,6 +1396,22 @@ void WW8Export::AppendBookmark( const OUString& rName, bool bSkip ) m_pBkmks->Append( nSttCP, rName ); } +boost::optional<SvxBrushItem> MSWordExportBase::getBackground() +{ + boost::optional<SvxBrushItem> 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 c0bddbb9117d..863d4671225c 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -876,6 +876,8 @@ protected: void SetCurPam(sal_uLong nStt, sal_uLong nEnd); + /// Get background color of the document, if there is one. + boost::optional<SvxBrushItem> getBackground(); /// Populates m_vecBulletPic with all the bullet graphics used by numberings. int CollectGrfsOfBullets(); /// Write the numbering picture bullets. |