diff options
author | Regényi Balázs <regenyi.balazs@nisz.hu> | 2020-12-01 12:16:12 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-12-10 10:27:33 +0100 |
commit | bda05ba17362222b74727872579b65b3fa14e3d8 (patch) | |
tree | 60d9448754f1a992e7e9695c8f458b55cfb62d69 /sw | |
parent | 7720f8cf22718415adb3db2304916581f864f884 (diff) |
tdf#41466 DOCX import: fix VML v:shape/v:textbox
VML v:shape/v:textbox element was imported only as
a text frame, losing (otherwise recognized) preset
shape geometry, i.e. replacing a callout bubble
(wedgeRectCallout) and other special shapes with a
plain rectangle.
Thanks to Attila Bakos for the initial help.
Change-Id: I03a608822ed54a20ed07406a08c3539e72958f5b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105299
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/textboxhelper.hxx | 7 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/layout-flow-alt-alone.docx | bin | 0 -> 7669 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf41466_testVmlShapeWithTextbox.docx | bin | 0 -> 21651 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 24 | ||||
-rw-r--r-- | sw/source/core/doc/textboxhelper.cxx | 23 | ||||
-rw-r--r-- | sw/source/core/unocore/unodraw.cxx | 9 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 2 |
8 files changed, 71 insertions, 0 deletions
diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx index a0cd4c593082..6d209d2c7140 100644 --- a/sw/inc/textboxhelper.hxx +++ b/sw/inc/textboxhelper.hxx @@ -35,6 +35,10 @@ namespace com::sun::star::drawing { class XShape; } +namespace com::sun::star::text +{ +class XTextFrame; +} /** * A TextBox is a TextFrame, that is tied to a drawinglayer shape. @@ -85,6 +89,9 @@ public: /// If we have an associated TextFrame, then return that. static SwFrameFormat* getOtherTextBoxFormat(css::uno::Reference<css::drawing::XShape> const& xShape); + /// If we have an associated TextFrame, then return its XTextFrame. + static css::uno::Reference<css::text::XTextFrame> + getUnoTextFrame(css::uno::Reference<css::drawing::XShape> const& xShape); /// Return the textbox rectangle of a draw shape (in twips). static tools::Rectangle getTextRectangle(SwFrameFormat* pShape, bool bAbsolute = true); diff --git a/sw/qa/extras/ooxmlexport/data/layout-flow-alt-alone.docx b/sw/qa/extras/ooxmlexport/data/layout-flow-alt-alone.docx Binary files differnew file mode 100644 index 000000000000..59c2db23d588 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/layout-flow-alt-alone.docx diff --git a/sw/qa/extras/ooxmlexport/data/tdf41466_testVmlShapeWithTextbox.docx b/sw/qa/extras/ooxmlexport/data/tdf41466_testVmlShapeWithTextbox.docx Binary files differnew file mode 100644 index 000000000000..2dfeb909cf9d --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf41466_testVmlShapeWithTextbox.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index 251bc2dcb952..47ee7a99b351 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -1622,6 +1622,30 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testAlignmentRelativeFromTopMarginVML, "tdf1 "center"); } +DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testVmlShapeWithTextbox, "tdf41466_testVmlShapeWithTextbox.docx") +{ + // Import as VML. + // tdf#41466: check whether VML DOCX shape with text is imported as shape with a text frame + // (text box). These kind of shapes were imported only as text frames previously, losing the + // preset shape geometry, in this case "wedgeRectCallout". + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + + // the wrong value was "rect" instead of "wedgeRectCallout" + assertXPath(pXmlDoc, + "/w:document/w:body/w:p/w:r/" + "mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:prstGeom", + "prst", "wedgeRectCallout"); +} + +DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testLayoutFlowAltAlone, "layout-flow-alt-alone.docx") +{ + // moved from oox/qa/unit/vml.cxx + // FIXME: now the DML part is checked, but we should check VML part in Fallback (too) + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/" + "a:graphic/a:graphicData/wps:wsp/wps:bodyPr", "vert", "vert270"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index 0d66639baf83..f569cb4ff595 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -44,6 +44,7 @@ #include <com/sun/star/text/TextContentAnchorType.hpp> #include <com/sun/star/text/WrapTextMode.hpp> #include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextFrame.hpp> #include <com/sun/star/table/BorderLine2.hpp> #include <com/sun/star/text/WritingMode.hpp> #include <com/sun/star/text/WritingMode2.hpp> @@ -357,6 +358,25 @@ SwFrameFormat* SwTextBoxHelper::getOtherTextBoxFormat(uno::Reference<drawing::XS return getOtherTextBoxFormat(pFormat, RES_DRAWFRMFMT); } +uno::Reference<text::XTextFrame> +SwTextBoxHelper::getUnoTextFrame(uno::Reference<drawing::XShape> const& xShape) +{ + if (xShape) + { + auto pFrameFormat = SwTextBoxHelper::getOtherTextBoxFormat(xShape); + if (pFrameFormat) + { + auto pSdrObj = pFrameFormat->FindSdrObject(); + if (pSdrObj && pSdrObj->IsTextBox()) + { + return uno::Reference<css::text::XTextFrame>(pSdrObj->getUnoShape(), + uno::UNO_QUERY); + } + } + } + return uno::Reference<css::text::XTextFrame>(); +} + template <typename T> static void lcl_queryInterface(const SwFrameFormat* pShape, uno::Any& rAny) { if (SwFrameFormat* pFormat = SwTextBoxHelper::getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT)) @@ -537,8 +557,11 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, std::u16string_view rP else if (rPropertyName == UNO_NAME_TEXT_WRITINGMODE) { text::WritingMode eMode; + sal_Int16 eMode2; if (rValue >>= eMode) syncProperty(pShape, RES_FRAMEDIR, 0, uno::makeAny(sal_Int16(eMode))); + else if (rValue >>= eMode2) + syncProperty(pShape, RES_FRAMEDIR, 0, uno::makeAny(eMode2)); } } diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index fa2fdfb24944..087949787d89 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -737,6 +737,15 @@ void SwXDrawPage::remove(const uno::Reference< drawing::XShape > & xShape) SolarMutexGuard aGuard; if(!m_pDoc) throw uno::RuntimeException(); + // tdf#41466 remove TextFrame too which is belonged to the actual shape + auto xTextFrame = SwTextBoxHelper::getUnoTextFrame(xShape); + if (xTextFrame) + { + uno::Reference<lang::XComponent> xComp(xTextFrame, uno::UNO_QUERY); + if (xComp) + xComp->dispose(); + } + // remove shape uno::Reference<lang::XComponent> xComp(xShape, uno::UNO_QUERY); xComp->dispose(); } diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 5b246d999254..bf25b3111379 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -4904,6 +4904,12 @@ void DocxAttributeOutput::CacheRelId(BitmapChecksum nChecksum, const OUString& r m_aSdrRelIdCache.top()[nChecksum] = rRelId; } +uno::Reference<css::text::XTextFrame> DocxAttributeOutput::GetUnoTextFrame( + css::uno::Reference<css::drawing::XShape> xShape) +{ + return SwTextBoxHelper::getUnoTextFrame(xShape); +} + OString DocxAttributeOutput::getExistingGraphicRelId(BitmapChecksum nChecksum) { OString aResult; diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index b9278e7f771c..349cab0cb310 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -1025,6 +1025,8 @@ public: virtual void WriteTextBox(css::uno::Reference<css::drawing::XShape> xShape) override; virtual OUString FindRelId(BitmapChecksum nChecksum) override; virtual void CacheRelId(BitmapChecksum nChecksum, const OUString& rRelId) override; + virtual css::uno::Reference<css::text::XTextFrame> GetUnoTextFrame( + css::uno::Reference<css::drawing::XShape> xShape) override; virtual oox::drawingml::DrawingML& GetDrawingML() override; virtual void MaybeOutputBrushItem(SfxItemSet const&) override; |