/src/libreoffice/oox/source/ppt/pptshapegroupcontext.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #include <memory> |
21 | | #include <com/sun/star/xml/sax/FastToken.hpp> |
22 | | |
23 | | #include <oox/core/xmlfilterbase.hxx> |
24 | | #include <oox/core/fragmenthandler2.hxx> |
25 | | #include <oox/helper/attributelist.hxx> |
26 | | #include <oox/ppt/pptshape.hxx> |
27 | | #include <oox/ppt/pptgraphicshapecontext.hxx> |
28 | | #include <oox/ppt/pptshapecontext.hxx> |
29 | | #include <oox/ppt/pptshapegroupcontext.hxx> |
30 | | #include <oox/drawingml/graphicshapecontext.hxx> |
31 | | #include <oox/drawingml/drawingmltypes.hxx> |
32 | | #include <drawingml/shapepropertiescontext.hxx> |
33 | | #include <oox/drawingml/connectorshapecontext.hxx> |
34 | | #include <drawingml/fillproperties.hxx> |
35 | | #include "extdrawingfragmenthandler.hxx" |
36 | | #include <oox/token/namespaces.hxx> |
37 | | #include <oox/token/tokens.hxx> |
38 | | #include <utility> |
39 | | |
40 | | using namespace oox::core; |
41 | | using namespace ::com::sun::star; |
42 | | using namespace ::com::sun::star::xml::sax; |
43 | | |
44 | | namespace oox::ppt { |
45 | | |
46 | | PPTShapeGroupContext::PPTShapeGroupContext( |
47 | | FragmentHandler2 const & rParent, |
48 | | oox::ppt::SlidePersistPtr pSlidePersistPtr, |
49 | | const ShapeLocation eShapeLocation, |
50 | | const oox::drawingml::ShapePtr& pMasterShapePtr, |
51 | | const oox::drawingml::ShapePtr& pGroupShapePtr ) |
52 | 21.7k | : ShapeGroupContext( rParent, pMasterShapePtr, pGroupShapePtr ) |
53 | 21.7k | , mpSlidePersistPtr(std::move( pSlidePersistPtr )) |
54 | 21.7k | , meShapeLocation( eShapeLocation ) |
55 | 21.7k | { |
56 | 21.7k | } |
57 | | |
58 | | ContextHandlerRef PPTShapeGroupContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs ) |
59 | 198k | { |
60 | 198k | if( getNamespace( aElementToken ) == NMSP_dsp ) |
61 | 0 | aElementToken = NMSP_ppt | getBaseToken( aElementToken ); |
62 | | |
63 | 198k | switch( aElementToken ) |
64 | 198k | { |
65 | 0 | case OOX_TOKEN(dml, extLst): |
66 | 0 | case OOX_TOKEN(dml, ext): |
67 | 0 | break; |
68 | 0 | case OOX_TOKEN(adec, decorative): |
69 | 0 | { |
70 | 0 | mpGroupShapePtr->setDecorative(rAttribs.getBool(XML_val, false)); |
71 | 0 | } |
72 | 0 | break; |
73 | 21.7k | case PPT_TOKEN( cNvPr ): |
74 | 21.7k | { |
75 | | // don't override SmartArt properties for embedded drawing's spTree |
76 | 21.7k | mpGroupShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) ); |
77 | 21.7k | if (mpGroupShapePtr->getId().isEmpty()) |
78 | 21.7k | mpGroupShapePtr->setId(rAttribs.getStringDefaulted(XML_id)); |
79 | 21.7k | if (mpGroupShapePtr->getName().isEmpty()) |
80 | 21.7k | mpGroupShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) ); |
81 | 21.7k | break; |
82 | 0 | } |
83 | 0 | case PPT_TOKEN( ph ): |
84 | 0 | mpGroupShapePtr->setSubType( rAttribs.getToken( XML_type, FastToken::DONTKNOW ) ); |
85 | 0 | if( rAttribs.hasAttribute( XML_idx ) ) |
86 | 0 | mpGroupShapePtr->setSubTypeIndex( rAttribs.getInteger( XML_idx, 0 ) ); |
87 | 0 | break; |
88 | | // nvSpPr CT_ShapeNonVisual end |
89 | | |
90 | 21.7k | case PPT_TOKEN( grpSpPr ): |
91 | 21.7k | return new oox::drawingml::ShapePropertiesContext( *this, *mpGroupShapePtr ); |
92 | 0 | case PPT_TOKEN( spPr ): |
93 | 0 | return new oox::drawingml::ShapePropertiesContext( *this, *mpGroupShapePtr ); |
94 | | /* |
95 | | case PPT_TOKEN( style ): |
96 | | return new ShapeStyleContext( getParser() ); |
97 | | */ |
98 | 136 | case PPT_TOKEN( cxnSp ): // connector shape |
99 | 136 | { |
100 | 136 | auto pShape = std::make_shared<PPTShape>(meShapeLocation, u"com.sun.star.drawing.ConnectorShape"_ustr); |
101 | 136 | return new oox::drawingml::ConnectorShapeContext(*this, mpGroupShapePtr, pShape, |
102 | 136 | pShape->getConnectorShapeProperties()); |
103 | 0 | } |
104 | 13 | case PPT_TOKEN( grpSp ): // group shape |
105 | 13 | return new PPTShapeGroupContext( *this, mpSlidePersistPtr, meShapeLocation, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, u"com.sun.star.drawing.GroupShape"_ustr ) ); |
106 | 88.0k | case PPT_TOKEN( sp ): // Shape |
107 | 88.0k | { |
108 | 88.0k | auto pShape = std::make_shared<PPTShape>( meShapeLocation, u"com.sun.star.drawing.CustomShape"_ustr ); |
109 | 88.0k | const bool bUseBgFill(rAttribs.getBool(XML_useBgFill, false)); |
110 | 88.0k | pShape->getFillProperties().moUseBgFill = bUseBgFill; |
111 | 88.0k | if (bUseBgFill) |
112 | 4 | { |
113 | 4 | pShape->getFillProperties().moFillType = XML_noFill; |
114 | 4 | } |
115 | 88.0k | const OUString aModelID(rAttribs.getStringDefaulted( XML_modelId )); |
116 | 88.0k | pShape->setModelId(aModelID); |
117 | | |
118 | | // also set DataModelID to have these also available for the imported |
119 | | // replacement visualization. This is key to allow changes to |
120 | | // DiagramHelper model changes |
121 | 88.0k | pShape->setDiagramDataModelID(aModelID); |
122 | | |
123 | 88.0k | return new PPTShapeContext( *this, mpSlidePersistPtr, mpGroupShapePtr, pShape ); |
124 | 0 | } |
125 | 1.35k | case PPT_TOKEN( pic ): // CT_Picture |
126 | 1.35k | return new PPTGraphicShapeContext( *this, mpSlidePersistPtr, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, u"com.sun.star.drawing.GraphicObjectShape"_ustr ) ); |
127 | 158 | case PPT_TOKEN( graphicFrame ): // CT_GraphicalObjectFrame |
128 | 158 | { |
129 | 158 | pGraphicShape = std::make_shared<PPTShape>( meShapeLocation, u"com.sun.star.drawing.OLE2Shape"_ustr ); |
130 | 158 | return new oox::drawingml::GraphicalObjectFrameContext( *this, mpGroupShapePtr, pGraphicShape, true ); |
131 | 0 | } |
132 | 198k | } |
133 | | |
134 | 86.9k | return this; |
135 | 198k | } |
136 | | |
137 | | void PPTShapeGroupContext::importExtDrawings( ) |
138 | 158 | { |
139 | 158 | if( !pGraphicShape ) |
140 | 0 | return; |
141 | | |
142 | 158 | for (auto const& extDrawing : pGraphicShape->getExtDrawings()) |
143 | 0 | { |
144 | 0 | OUString aFragmentPath = getFragmentPathFromRelId(extDrawing); |
145 | 0 | static bool bIgnoreExtDrawings(nullptr != std::getenv("DIAGRAM_IGNORE_EXTDRAWINGS")); |
146 | 0 | if (!bIgnoreExtDrawings) |
147 | 0 | { |
148 | 0 | getFilter().importFragment( new ExtDrawingFragmentHandler( getFilter(), aFragmentPath, |
149 | 0 | mpSlidePersistPtr, |
150 | 0 | meShapeLocation, |
151 | 0 | mpGroupShapePtr, |
152 | 0 | pGraphicShape ) ); |
153 | 0 | } |
154 | 0 | pGraphicShape->keepDiagramDrawing(getFilter(), aFragmentPath); |
155 | | |
156 | | // Apply font color imported from color fragment |
157 | 0 | if( pGraphicShape->getFontRefColorForNodes().isUsed() ) |
158 | 0 | applyFontRefColor(mpGroupShapePtr, pGraphicShape->getFontRefColorForNodes()); |
159 | 0 | } |
160 | 158 | pGraphicShape = oox::drawingml::ShapePtr( nullptr ); |
161 | 158 | } |
162 | | |
163 | | void PPTShapeGroupContext::applyFontRefColor(const oox::drawingml::ShapePtr& pShape, const oox::drawingml::Color& rFontRefColor) |
164 | 0 | { |
165 | 0 | pShape->getShapeStyleRefs()[XML_fontRef].maPhClr = rFontRefColor; |
166 | 0 | std::vector< oox::drawingml::ShapePtr >& vChildren = pShape->getChildren(); |
167 | 0 | for (auto const& child : vChildren) |
168 | 0 | { |
169 | 0 | applyFontRefColor(child, rFontRefColor); |
170 | 0 | } |
171 | 0 | } |
172 | | |
173 | | } |
174 | | |
175 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |