tdf#131098 docx export: write fill property of graphic
[LibreOffice.git] / oox / source / shape / WordprocessingCanvasContext.cxx
blobb03886441d6a2c95e14c01c62672ceef190d9318
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "WordprocessingCanvasContext.hxx"
11 #include "WpsContext.hxx"
12 #include "WpgContext.hxx"
13 #include <drawingml/customshapeproperties.hxx>
14 #include <drawingml/effectpropertiescontext.hxx>
15 #include <drawingml/fillproperties.hxx>
16 #include <drawingml/shapepropertiescontext.hxx>
17 #include <oox/drawingml/connectorshapecontext.hxx>
18 #include <oox/drawingml/drawingmltypes.hxx>
19 #include <oox/drawingml/graphicshapecontext.hxx>
20 #include <oox/drawingml/shape.hxx>
21 #include <oox/drawingml/shapecontext.hxx>
22 #include <oox/drawingml/shapegroupcontext.hxx>
23 #include <oox/helper/attributelist.hxx>
24 #include <oox/token/namespaces.hxx>
25 #include <oox/token/tokens.hxx>
26 #include <sal/log.hxx>
27 #include <svx/svdoedge.hxx>
28 #include <svx/svdobj.hxx>
30 using namespace com::sun::star;
32 namespace oox::shape
34 WordprocessingCanvasContext::WordprocessingCanvasContext(FragmentHandler2 const& rParent,
35 css::awt::Size& rSize)
36 : FragmentHandler2(rParent)
37 , m_bFullWPGSupport(true)
39 mpShapePtr = std::make_shared<oox::drawingml::Shape>(u"com.sun.star.drawing.GroupShape"_ustr);
40 mpShapePtr->setSize(rSize);
41 mpShapePtr->setWordprocessingCanvas(true); // will be "WordprocessingCanvas" in InteropGrabBag
42 mpShapePtr->setWps(true);
43 oox::drawingml::ShapePtr pBackground
44 = std::make_shared<oox::drawingml::Shape>(u"com.sun.star.drawing.CustomShape"_ustr);
45 pBackground->getCustomShapeProperties()->setShapePresetType(XML_rect);
46 pBackground->setSize(rSize);
47 pBackground->setWordprocessingCanvas(true);
48 pBackground->setWPGChild(true);
49 pBackground->setWps(true);
50 // Fill and Line properties will follow in wpc:bg and wpc:whole child elements of wpc element
51 mpShapePtr->addChild(pBackground);
52 mpShapePtr->setChildSize(rSize);
55 WordprocessingCanvasContext::~WordprocessingCanvasContext() = default;
57 ::oox::core::ContextHandlerRef
58 WordprocessingCanvasContext::onCreateContext(sal_Int32 nElementToken,
59 const ::oox::AttributeList& /*rAttribs*/)
61 switch (getBaseToken(nElementToken))
63 case XML_wpc:
64 SAL_INFO("oox", "WordprocessingCanvasContext::createFastChildContext: wpc: "
65 << getBaseToken(nElementToken));
66 break;
67 case XML_bg: //CT_BackgroundFormatting
68 return new oox::drawingml::ShapePropertiesContext(*this,
69 *(getShape()->getChildren().front()));
70 case XML_whole: // CT_WholeE2oFormatting
71 return new oox::drawingml::ShapePropertiesContext(*this,
72 *(getShape()->getChildren().front()));
73 case XML_wsp: // CT_WordprocessingShape
75 oox::drawingml::ShapePtr pShape = std::make_shared<oox::drawingml::Shape>(
76 u"com.sun.star.drawing.CustomShape"_ustr, /*bDefaultHeight=*/false);
77 return new oox::shape::WpsContext(*this, uno::Reference<drawing::XShape>(), mpShapePtr,
78 pShape);
80 case XML_pic: // CT_Picture
81 return new oox::drawingml::GraphicShapeContext(
82 *this, mpShapePtr,
83 std::make_shared<oox::drawingml::Shape>(
84 u"com.sun.star.drawing.GraphicObjectShape"_ustr));
85 break;
86 case XML_graphicFrame: // CT_GraphicFrame
87 SAL_INFO("oox",
88 "WordprocessingCanvasContext::createFastChildContext: ToDo: graphicFrame: "
89 << getBaseToken(nElementToken));
90 break;
91 case XML_wgp: // CT_WordprocessingGroup
93 rtl::Reference<WpgContext> pWPGContext = new oox::shape::WpgContext(*this, mpShapePtr);
94 pWPGContext->setFullWPGSupport(m_bFullWPGSupport);
95 return pWPGContext;
97 default:
98 // includes case XML_contentPart
99 // Word uses this for Ink, as <w14:contentPart r:id="rId4"> for example. Thereby rId4 is
100 // a reference into the 'ink' folder in the docx package. Import of Ink is not
101 // implemented yet. In general it refers to arbitrary XML source.
102 SAL_WARN("oox",
103 "WordprocessingCanvasContext::createFastChildContext: unhandled element:"
104 << getBaseToken(nElementToken));
105 break;
107 return nullptr;
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */