diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-10-15 12:35:47 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-10-15 13:19:08 +0200 |
commit | ecc5cbc69e4c2df4ddbe46bbc2f973cc60a10772 (patch) | |
tree | cf81b967bd41d2818f75907e080c18aadf3bc26b | |
parent | f57ed7edd498d62ca0ed9a8cedd72218985b4daf (diff) |
fdo#82860 RTF export: if shape has textbox, export its contents as shape text
See 8c677716c4707ccd86b152ae504841affb393cc0 (DOCX drawingML export: if
shape has textbox, export its contents as shape text, 2014-06-06).
Change-Id: I5b1afae4d1b80c9b225096677f7d7ae77ff90f5b
-rw-r--r-- | sw/source/filter/ww8/rtfattributeoutput.cxx | 118 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfattributeoutput.hxx | 3 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfexport.cxx | 25 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfexport.hxx | 8 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfsdrexport.cxx | 22 |
5 files changed, 127 insertions, 49 deletions
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index 0a26834dcc51..96c04c604487 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -1592,6 +1592,75 @@ void lcl_TextFrameRelativeSize(std::vector< std::pair<OString, OString> >& rFlyP } } +void RtfAttributeOutput::writeTextFrame(const sw::Frame& rFrame, bool bTextBox) +{ + RtfStringBuffer aRunText; + if (bTextBox) + { + m_rExport.setStream(); + aRunText = m_aRunText; + m_aRunText.clear(); + } + + m_rExport.Strm().WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_SHPTXT); + + { + // Save table state, in case the inner text also contains a table. + ww8::WW8TableInfo::Pointer_t pTableInfoOrig = m_rExport.mpTableInfo; + m_rExport.mpTableInfo = ww8::WW8TableInfo::Pointer_t(new ww8::WW8TableInfo()); + SwWriteTable* pTableWrt = m_pTableWrt; + m_pTableWrt = 0; + sal_uInt32 nTableDepth = m_nTableDepth; + + m_nTableDepth = 0; + /* + * Save m_aRun as we should not lose the opening brace. + * OTOH, just drop the contents of m_aRunText in case something + * would be there, causing a problem later. + */ + OString aSave = m_aRun.makeStringAndClear(); + // Also back m_bInRun and m_bSingleEmptyRun up. + bool bInRunOrig = m_bInRun; + m_bInRun = false; + bool bSingleEmptyRunOrig = m_bSingleEmptyRun; + 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; + m_rExport.SaveData(nStt, nEnd); + m_rExport.mpParentFrame = &rFrame; + m_rExport.WriteText(); + m_rExport.RestoreData(); + + m_rExport.Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PARD); + m_rExport.bRTFFlySyntax = false; + m_aRun->append(aSave); + m_aRunText.clear(); + m_bInRun = bInRunOrig; + m_bSingleEmptyRun = bSingleEmptyRunOrig; + + // Restore table state. + m_rExport.mpTableInfo = pTableInfoOrig; + delete m_pTableWrt; + m_pTableWrt = pTableWrt; + m_nTableDepth = nTableDepth; + } + + m_rExport.mpParentFrame = NULL; + + m_rExport.Strm().WriteChar('}'); // shptxt + + if (bTextBox) + { + m_aRunText = aRunText; + m_aRunText->append(m_rExport.getStream()); + m_rExport.resetStream(); + } +} + void RtfAttributeOutput::OutputFlyFrame_Impl(const sw::Frame& rFrame, const Point& /*rNdTopLeft*/) { const SwNode* pNode = rFrame.GetContent(); @@ -1641,55 +1710,8 @@ void RtfAttributeOutput::OutputFlyFrame_Impl(const sw::Frame& rFrame, const Poin } m_aFlyProperties.clear(); - m_rExport.Strm().WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_SHPTXT); - - { - // Save table state, in case the inner text also contains a table. - ww8::WW8TableInfo::Pointer_t pTableInfoOrig = m_rExport.mpTableInfo; - m_rExport.mpTableInfo = ww8::WW8TableInfo::Pointer_t(new ww8::WW8TableInfo()); - SwWriteTable* pTableWrt = m_pTableWrt; - m_pTableWrt = 0; - sal_uInt32 nTableDepth = m_nTableDepth; - - m_nTableDepth = 0; - /* - * Save m_aRun as we should not lose the opening brace. - * OTOH, just drop the contents of m_aRunText in case something - * would be there, causing a problem later. - */ - OString aSave = m_aRun.makeStringAndClear(); - // Also back m_bInRun and m_bSingleEmptyRun up. - bool bInRunOrig = m_bInRun; - m_bInRun = false; - bool bSingleEmptyRunOrig = m_bSingleEmptyRun; - m_bSingleEmptyRun = false; - m_rExport.bRTFFlySyntax = true; - - const SwNodeIndex* pNodeIndex = rFrmFmt.GetCntnt().GetCntntIdx(); - sal_uLong nStt = pNodeIndex ? pNodeIndex->GetIndex()+1 : 0; - sal_uLong nEnd = pNodeIndex ? pNodeIndex->GetNode().EndOfSectionIndex() : 0; - m_rExport.SaveData(nStt, nEnd); - m_rExport.mpParentFrame = &rFrame; - m_rExport.WriteText(); - m_rExport.RestoreData(); - - m_rExport.Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PARD); - m_rExport.bRTFFlySyntax = false; - m_aRun->append(aSave); - m_aRunText.clear(); - m_bInRun = bInRunOrig; - m_bSingleEmptyRun = bSingleEmptyRunOrig; - - // Restore table state. - m_rExport.mpTableInfo = pTableInfoOrig; - delete m_pTableWrt; - m_pTableWrt = pTableWrt; - m_nTableDepth = nTableDepth; - } - - m_rExport.mpParentFrame = NULL; + writeTextFrame(rFrame); - m_rExport.Strm().WriteChar('}'); // shptxt m_rExport.Strm().WriteChar('}'); // shpinst m_rExport.Strm().WriteChar('}'); // shp diff --git a/sw/source/filter/ww8/rtfattributeoutput.hxx b/sw/source/filter/ww8/rtfattributeoutput.hxx index f59a02922c28..87b23eeeab84 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.hxx +++ b/sw/source/filter/ww8/rtfattributeoutput.hxx @@ -632,6 +632,9 @@ public: static OString WriteHex(const sal_uInt8* pData, sal_uInt32 nSize, SvStream* pStream = 0, sal_uInt32 nLimit = 64); void BulletDefinition(int nId, const Graphic& rGraphic, Size aSize) SAL_OVERRIDE; + + /// Handles just the {\shptxt ...} part of a shape export. + void writeTextFrame(const sw::Frame& rFrame, bool bTextBox = false); }; #endif // INCLUDED_SW_SOURCE_FILTER_WW8_RTFATTRIBUTEOUTPUT_HXX diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index 0d8e1d2c97cb..c776688fdce7 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -840,7 +840,30 @@ RtfExport::~RtfExport() SvStream& RtfExport::Strm() { - return m_pWriter->Strm(); + if (m_pStream) + return *m_pStream; + else + return m_pWriter->Strm(); +} + +void RtfExport::setStream() +{ + m_pStream.reset(new SvMemoryStream()); +} + +OString RtfExport::getStream() +{ + OString aRet; + + if (m_pStream) + aRet = OString(static_cast<const sal_Char*>(m_pStream->GetData()), m_pStream->Tell()); + + return aRet; +} + +void RtfExport::resetStream() +{ + m_pStream.reset(); } SvStream& RtfExport::OutULong(sal_uLong nVal) diff --git a/sw/source/filter/ww8/rtfexport.hxx b/sw/source/filter/ww8/rtfexport.hxx index c384289cff77..80451477c4a8 100644 --- a/sw/source/filter/ww8/rtfexport.hxx +++ b/sw/source/filter/ww8/rtfexport.hxx @@ -173,6 +173,12 @@ public: sal_uLong m_nCurrentNodeIndex; SvStream& Strm(); + /// From now on, let Strm() return a memory stream, not a real one. + void setStream(); + /// Get the contents of the memory stream as a string. + OString getStream(); + /// Return back to the real stream. + void resetStream(); SvStream& OutULong(sal_uLong nVal); SvStream& OutLong(long nVal); void OutUnicode(const sal_Char* pToken, const OUString& rContent, bool bUpr = false); @@ -211,6 +217,8 @@ private: RtfColorTbl m_aColTbl; RtfStyleTbl m_aStyTbl; RtfRedlineTbl m_aRedlineTbl; + /// If set, then Strm() returns this tream, instead of m_pWriter's stream. + std::unique_ptr<SvMemoryStream> m_pStream; }; #endif // INCLUDED_SW_SOURCE_FILTER_WW8_RTFEXPORT_HXX diff --git a/sw/source/filter/ww8/rtfsdrexport.cxx b/sw/source/filter/ww8/rtfsdrexport.cxx index e25ba1d0ed03..e4b86f24f962 100644 --- a/sw/source/filter/ww8/rtfsdrexport.cxx +++ b/sw/source/filter/ww8/rtfsdrexport.cxx @@ -28,6 +28,7 @@ #include <svx/unoapi.hxx> #include <vcl/cvtgrf.hxx> #include <textboxhelper.hxx> +#include <dcontact.hxx> #include <algorithm> @@ -499,6 +500,27 @@ sal_Int32 RtfSdrExport::StartShape() lcl_AppendSP(m_rAttrOutput.RunText(), "wzName", msfilter::rtfutil::OutString(m_pSdrObject->GetTitle(), m_rExport.eCurrentEncoding)); // now check if we have some text + const SwFrmFmt* pShape = FindFrmFmt(m_pSdrObject); + if (pShape) + { + if (SwFrmFmt* pTextBox = SwTextBoxHelper::findTextBox(pShape)) + { + sw::Frame* pFrame = 0; + for (sw::FrameIter it = m_rExport.maFrames.begin(); it != m_rExport.maFrames.end(); ++it) + { + if (pTextBox == &it->GetFrmFmt()) + { + pFrame = &(*it); + break; + } + } + + if (pFrame) + m_rAttrOutput.writeTextFrame(*pFrame, /*bTextBox=*/true); + return m_nShapeType; + } + } + const SdrTextObj* pTxtObj = dynamic_cast<const SdrTextObj*>(m_pSdrObject); if (pTxtObj) { |