diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-06-06 14:01:21 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-06-06 14:24:26 +0200 |
commit | 8c677716c4707ccd86b152ae504841affb393cc0 (patch) | |
tree | 201862387e9d7f6357157ccc2bfb9b3a8c9cdb3d | |
parent | ff1c74f53a66695f20906fe3a0aebd15b6b0cd51 (diff) |
DOCX drawingML export: if shape has textbox, export its contents as shape text
Change-Id: I54a51189e1c595841b8b02f3b4436da4a29f1dac
-rw-r--r-- | include/oox/export/drawingml.hxx | 4 | ||||
-rw-r--r-- | oox/source/export/shapes.cxx | 15 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 11 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxsdrexport.cxx | 84 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxsdrexport.hxx | 2 |
6 files changed, 78 insertions, 40 deletions
diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx index e97f05da8cf5..6f64fcf5ac8f 100644 --- a/include/oox/export/drawingml.hxx +++ b/include/oox/export/drawingml.hxx @@ -71,6 +71,8 @@ class OOX_DLLPUBLIC DMLTextExport { public: virtual void WriteOutliner(const OutlinerParaObject& rParaObj) = 0; + /// Write the contents of the textbox that is associated to this shape. + virtual void WriteTextBox(css::uno::Reference<css::drawing::XShape> xShape) = 0; protected: DMLTextExport() {} virtual ~DMLTextExport() {} @@ -120,6 +122,8 @@ public: ::sax_fastparser::FSHelperPtr GetFS() { return mpFS; } ::oox::core::XmlFilterBase* GetFB() { return mpFB; } DocumentType GetDocumentType() { return meDocumentType; } + /// The application-specific text exporter callback, if there is one. + DMLTextExport* GetTextExport() { return mpTextExport; } /// If bRelPathToMedia is true add "../" to image folder path while adding the image relationship OUString WriteImage( const Graphic &rGraphic , bool bRelPathToMedia = false); diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index 82d2b5e7e793..7c3627e24fe4 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -812,6 +812,21 @@ ShapeExport& ShapeExport::WriteShape( Reference< XShape > xShape ) ShapeExport& ShapeExport::WriteTextBox( Reference< XInterface > xIface, sal_Int32 nXmlNamespace ) { + // In case this shape has an associated textbox, then export that, and we're done. + if (GetDocumentType() == DOCUMENT_DOCX && GetTextExport()) + { + uno::Reference<beans::XPropertySet> xPropertySet(xIface, uno::UNO_QUERY); + if (xPropertySet.is()) + { + uno::Reference<beans::XPropertySetInfo> xPropertySetInfo = xPropertySet->getPropertySetInfo(); + if (xPropertySetInfo->hasPropertyByName("TextBox") && xPropertySet->getPropertyValue("TextBox").get<bool>()) + { + GetTextExport()->WriteTextBox(uno::Reference<drawing::XShape>(xIface, uno::UNO_QUERY_THROW)); + return *this; + } + } + } + if( NonEmptyText( xIface ) ) { FSHelperPtr pFS = GetFS(); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index d3cfad8d2f42..41630d4b92cb 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -29,10 +29,13 @@ #include "fchrfmt.hxx" #include "tgrditem.hxx" #include "fmtruby.hxx" +#include "fmtanchr.hxx" #include "breakit.hxx" #include "redline.hxx" #include "unocoll.hxx" #include "unoframe.hxx" +#include "unodraw.hxx" +#include "textboxhelper.hxx" #include "wrtww8.hxx" #include "wrtww8.hxx" @@ -4549,6 +4552,14 @@ void DocxAttributeOutput::WriteOutliner(const OutlinerParaObject& rParaObj) m_pSerializer->endElementNS( XML_w, XML_txbxContent ); } +void DocxAttributeOutput::WriteTextBox(uno::Reference<drawing::XShape> xShape) +{ + SwFrmFmt* pTextBox = SwTextBoxHelper::findTextBox(xShape); + const SwPosition* pAnchor = pTextBox->GetAnchor().GetCntntAnchor(); + sw::Frame aFrame(*pTextBox, *pAnchor); + m_rExport.SdrExporter().writeDMLTextFrame(&aFrame, m_anchorId++, /*bTextBoxOnly=*/true); +} + oox::drawingml::DrawingML& DocxAttributeOutput::GetDrawingML() { return m_rDrawingML; diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 9e015119b037..7990ed8749af 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -918,6 +918,8 @@ public: /// VMLTextExport virtual void WriteOutliner(const OutlinerParaObject& rParaObj) SAL_OVERRIDE; + /// DMLTextExport + virtual void WriteTextBox(css::uno::Reference<css::drawing::XShape> xShape) SAL_OVERRIDE; virtual oox::drawingml::DrawingML& GetDrawingML() SAL_OVERRIDE; virtual void switchHeaderFooter(bool isHeaderFooter, sal_Int32 index); diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx index c389d759b48e..ae6445ea53f6 100644 --- a/sw/source/filter/ww8/docxsdrexport.cxx +++ b/sw/source/filter/ww8/docxsdrexport.cxx @@ -1172,7 +1172,7 @@ void DocxSdrExport::writeDiagram(const SdrObject* sdrObject, const SwFrmFmt& rFr } } -void DocxSdrExport::writeDMLTextFrame(sw::Frame* pParentFrame, int nAnchorId) +void DocxSdrExport::writeDMLTextFrame(sw::Frame* pParentFrame, int nAnchorId, bool bTextBoxOnly) { sax_fastparser::FSHelperPtr pFS = m_pImpl->m_pSerializer; const SwFrmFmt& rFrmFmt = pParentFrame->GetFrmFmt(); @@ -1188,21 +1188,24 @@ void DocxSdrExport::writeDMLTextFrame(sw::Frame* pParentFrame, int nAnchorId) // to lots of contents, this size contains the real size. const Size aSize = pParentFrame->GetSize(); - startDMLAnchorInline(&rFrmFmt, aSize); + if (!bTextBoxOnly) + { + startDMLAnchorInline(&rFrmFmt, aSize); - sax_fastparser::FastAttributeList* pDocPrAttrList = pFS->createAttrList(); - pDocPrAttrList->add(XML_id, OString::number(nAnchorId).getStr()); - pDocPrAttrList->add(XML_name, OUStringToOString(rFrmFmt.GetName(), RTL_TEXTENCODING_UTF8).getStr()); - sax_fastparser::XFastAttributeListRef xDocPrAttrListRef(pDocPrAttrList); - pFS->singleElementNS(XML_wp, XML_docPr, xDocPrAttrListRef); + sax_fastparser::FastAttributeList* pDocPrAttrList = pFS->createAttrList(); + pDocPrAttrList->add(XML_id, OString::number(nAnchorId).getStr()); + pDocPrAttrList->add(XML_name, OUStringToOString(rFrmFmt.GetName(), RTL_TEXTENCODING_UTF8).getStr()); + sax_fastparser::XFastAttributeListRef xDocPrAttrListRef(pDocPrAttrList); + pFS->singleElementNS(XML_wp, XML_docPr, xDocPrAttrListRef); - pFS->startElementNS(XML_a, XML_graphic, - FSNS(XML_xmlns, XML_a), "http://schemas.openxmlformats.org/drawingml/2006/main", - FSEND); - pFS->startElementNS(XML_a, XML_graphicData, - XML_uri, "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", - FSEND); - pFS->startElementNS(XML_wps, XML_wsp, FSEND); + pFS->startElementNS(XML_a, XML_graphic, + FSNS(XML_xmlns, XML_a), "http://schemas.openxmlformats.org/drawingml/2006/main", + FSEND); + pFS->startElementNS(XML_a, XML_graphicData, + XML_uri, "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", + FSEND); + pFS->startElementNS(XML_wps, XML_wsp, FSEND); + } pFS->singleElementNS(XML_wps, XML_cNvSpPr, XML_txBox, "1", FSEND); @@ -1362,33 +1365,36 @@ void DocxSdrExport::writeDMLTextFrame(sw::Frame* pParentFrame, int nAnchorId) pFS->singleElementNS(XML_a, (rSize.GetHeightSizeType() == ATT_VAR_SIZE ? XML_spAutoFit : XML_noAutofit), FSEND); pFS->endElementNS(XML_wps, XML_bodyPr); - pFS->endElementNS(XML_wps, XML_wsp); - pFS->endElementNS(XML_a, XML_graphicData); - pFS->endElementNS(XML_a, XML_graphic); - - // Relative size of the Text Frame. - if (rSize.GetWidthPercent()) + if (!bTextBoxOnly) { - pFS->startElementNS(XML_wp14, XML_sizeRelH, - XML_relativeFrom, (rSize.GetWidthPercentRelation() == text::RelOrientation::PAGE_FRAME ? "page" : "margin"), - FSEND); - pFS->startElementNS(XML_wp14, XML_pctWidth, FSEND); - pFS->writeEscaped(OUString::number(rSize.GetWidthPercent() * oox::drawingml::PER_PERCENT)); - pFS->endElementNS(XML_wp14, XML_pctWidth); - pFS->endElementNS(XML_wp14, XML_sizeRelH); - } - if (rSize.GetHeightPercent()) - { - pFS->startElementNS(XML_wp14, XML_sizeRelV, - XML_relativeFrom, (rSize.GetHeightPercentRelation() == text::RelOrientation::PAGE_FRAME ? "page" : "margin"), - FSEND); - pFS->startElementNS(XML_wp14, XML_pctHeight, FSEND); - pFS->writeEscaped(OUString::number(rSize.GetHeightPercent() * oox::drawingml::PER_PERCENT)); - pFS->endElementNS(XML_wp14, XML_pctHeight); - pFS->endElementNS(XML_wp14, XML_sizeRelV); - } + pFS->endElementNS(XML_wps, XML_wsp); + pFS->endElementNS(XML_a, XML_graphicData); + pFS->endElementNS(XML_a, XML_graphic); - endDMLAnchorInline(&rFrmFmt); + // Relative size of the Text Frame. + if (rSize.GetWidthPercent()) + { + pFS->startElementNS(XML_wp14, XML_sizeRelH, + XML_relativeFrom, (rSize.GetWidthPercentRelation() == text::RelOrientation::PAGE_FRAME ? "page" : "margin"), + FSEND); + pFS->startElementNS(XML_wp14, XML_pctWidth, FSEND); + pFS->writeEscaped(OUString::number(rSize.GetWidthPercent() * oox::drawingml::PER_PERCENT)); + pFS->endElementNS(XML_wp14, XML_pctWidth); + pFS->endElementNS(XML_wp14, XML_sizeRelH); + } + if (rSize.GetHeightPercent()) + { + pFS->startElementNS(XML_wp14, XML_sizeRelV, + XML_relativeFrom, (rSize.GetHeightPercentRelation() == text::RelOrientation::PAGE_FRAME ? "page" : "margin"), + FSEND); + pFS->startElementNS(XML_wp14, XML_pctHeight, FSEND); + pFS->writeEscaped(OUString::number(rSize.GetHeightPercent() * oox::drawingml::PER_PERCENT)); + pFS->endElementNS(XML_wp14, XML_pctHeight); + pFS->endElementNS(XML_wp14, XML_sizeRelV); + } + + endDMLAnchorInline(&rFrmFmt); + } } void DocxSdrExport::writeVMLTextFrame(sw::Frame* pParentFrame) diff --git a/sw/source/filter/ww8/docxsdrexport.hxx b/sw/source/filter/ww8/docxsdrexport.hxx index 8760a6b1cb4e..c05979fd5ba5 100644 --- a/sw/source/filter/ww8/docxsdrexport.hxx +++ b/sw/source/filter/ww8/docxsdrexport.hxx @@ -92,7 +92,7 @@ public: com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > xOutStream, const OUString& sGrabBagProperyName, int nAnchorId); /// Writes text frame in DML format. - void writeDMLTextFrame(sw::Frame* pParentFrame, int nAnchorId); + void writeDMLTextFrame(sw::Frame* pParentFrame, int nAnchorId, bool bTextBoxOnly = false); /// Writes text frame in VML format. void writeVMLTextFrame(sw::Frame* pParentFrame); /// Undo the text direction mangling done by the frame btLr handler in writerfilter::dmapper::DomainMapper::lcl_startCharacterGroup() |