Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/shape/WpgContext.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
10
#include "WpgContext.hxx"
11
#include "WpsContext.hxx"
12
#include <sal/log.hxx>
13
#include <drawingml/shapepropertiescontext.hxx>
14
#include <oox/drawingml/shapegroupcontext.hxx>
15
#include <oox/drawingml/graphicshapecontext.hxx>
16
#include <oox/token/namespaces.hxx>
17
#include <oox/token/tokens.hxx>
18
19
using namespace com::sun::star;
20
21
namespace oox::shape
22
{
23
WpgContext::WpgContext(FragmentHandler2 const& rParent, const oox::drawingml::ShapePtr& pMaster)
24
134
    : FragmentHandler2(rParent)
25
134
    , m_bFullWPGSupport(false)
26
134
{
27
134
    mpShape = std::make_shared<oox::drawingml::Shape>(u"com.sun.star.drawing.GroupShape"_ustr);
28
134
    mpShape->setWps(true);
29
134
    if (pMaster)
30
0
        pMaster->addChild(mpShape);
31
134
}
32
33
134
WpgContext::~WpgContext() = default;
34
35
oox::core::ContextHandlerRef WpgContext::onCreateContext(sal_Int32 nElementToken,
36
                                                         const oox::AttributeList& /*rAttribs*/)
37
670
{
38
670
    switch (getBaseToken(nElementToken))
39
670
    {
40
134
        case XML_wgp:
41
268
        case XML_cNvGrpSpPr:
42
402
        case XML_grpSpPr:
43
402
            return new oox::drawingml::ShapePropertiesContext(*this, *mpShape);
44
268
        case XML_wsp:
45
268
        {
46
268
            if (m_bFullWPGSupport)
47
268
            {
48
268
                return new oox::shape::WpsContext(*this, uno::Reference<drawing::XShape>(), mpShape,
49
268
                                                  std::make_shared<oox::drawingml::Shape>(
50
268
                                                      u"com.sun.star.drawing.CustomShape"_ustr,
51
268
                                                      /*bDefaultHeight=*/false));
52
268
            }
53
54
            // Don't set default character height, Writer has its own way to set
55
            // the default, and if we don't set it here, editeng properly inherits
56
            // it.
57
0
            return new oox::drawingml::ShapeContext(
58
0
                *this, mpShape,
59
0
                std::make_shared<oox::drawingml::Shape>(u"com.sun.star.drawing.CustomShape"_ustr,
60
0
                                                        /*bDefaultHeight=*/false));
61
268
        }
62
0
        case XML_pic:
63
0
            return new oox::drawingml::GraphicShapeContext(
64
0
                *this, mpShape,
65
0
                std::make_shared<oox::drawingml::Shape>(
66
0
                    u"com.sun.star.drawing.GraphicObjectShape"_ustr));
67
0
        case XML_grpSp:
68
0
        {
69
0
            if (m_bFullWPGSupport)
70
0
            {
71
0
                rtl::Reference<WpgContext> pWPGShape = new oox::shape::WpgContext(*this, mpShape);
72
0
                pWPGShape->setFullWPGSupport(m_bFullWPGSupport);
73
0
                return pWPGShape;
74
0
            }
75
76
0
            return new oox::drawingml::ShapeGroupContext(
77
0
                *this, mpShape,
78
0
                std::make_shared<oox::drawingml::Shape>(u"com.sun.star.drawing.GroupShape"_ustr));
79
0
        }
80
0
        case XML_graphicFrame:
81
0
        {
82
0
            auto pShape = std::make_shared<oox::drawingml::Shape>(
83
0
                u"com.sun.star.drawing.GraphicObjectShape"_ustr);
84
0
            pShape->setWps(true);
85
0
            return new oox::drawingml::GraphicalObjectFrameContext(*this, mpShape, pShape,
86
0
                                                                   /*bEmbedShapesInChart=*/true);
87
0
        }
88
0
        default:
89
0
            SAL_WARN("oox", "WpgContext::createFastChildContext: unhandled element: "
90
0
                                << getBaseToken(nElementToken));
91
0
            break;
92
670
    }
93
0
    return nullptr;
94
670
}
95
}
96
97
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */