Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/oox/vml/vmlshapecontainer.hxx
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
#ifndef INCLUDED_OOX_VML_VMLSHAPECONTAINER_HXX
21
#define INCLUDED_OOX_VML_VMLSHAPECONTAINER_HXX
22
23
#include <cstddef>
24
#include <memory>
25
#include <stack>
26
27
#include <com/sun/star/awt/Rectangle.hpp>
28
#include <com/sun/star/uno/Reference.hxx>
29
#include <oox/helper/refmap.hxx>
30
#include <oox/helper/refvector.hxx>
31
#include <rtl/ustring.hxx>
32
33
namespace com::sun::star {
34
    namespace drawing { class XShapes; }
35
}
36
37
namespace oox::vml {
38
39
class Drawing;
40
class ShapeType;
41
class ShapeBase;
42
43
44
struct ShapeParentAnchor
45
{
46
    css::awt::Rectangle maShapeRect;
47
    css::awt::Rectangle maCoordSys;
48
};
49
50
51
/** Container that holds a list of shapes and shape templates. */
52
class ShapeContainer
53
{
54
public:
55
    typedef RefVector< ShapeBase >                  ShapeVector;
56
57
    explicit            ShapeContainer( Drawing& rDrawing );
58
                        ~ShapeContainer();
59
60
    /** Returns the drawing this shape container is part of. */
61
202
    Drawing&     getDrawing() { return mrDrawing; }
62
63
    /** Creates and returns a new shape template object. */
64
    std::shared_ptr<ShapeType> createShapeType();
65
    /** Creates and returns a new shape object of the specified type. */
66
    template< typename ShapeT >
67
    std::shared_ptr<ShapeT> createShape();
68
69
    /** Final processing after import of the drawing fragment. */
70
    void                finalizeFragmentImport();
71
72
    /** Returns true, if this container does not contain any shapes. */
73
108
    bool         empty() const { return maShapes.empty(); }
74
75
    /** Returns the shape template with the passed identifier.
76
        Searches in all group shapes too. */
77
    const ShapeType*    getShapeTypeById( const OUString& rShapeId ) const;
78
    /** Returns the shape with the passed identifier.
79
        Searches in all group shapes too. */
80
    const ShapeBase*    getShapeById( const OUString& rShapeId ) const;
81
82
    /**
83
      (Word only) Returns the last shape in the collection, if it is after the last
84
      mark from pushMark(), and removes it.
85
    */
86
    std::shared_ptr< ShapeBase > takeLastShape();
87
    /**
88
      Adds a recursion mark to the stack. It is possible that a shape contains <w:txbxContent>
89
      which contains another shape, and writerfilter needs to know which shape is from the inner
90
      ooxml context and which from the outer ooxml context, while it is necessary to keep
91
      at least shape types across such blocks. Therefore this function marks beginning
92
      of each shape xml block, and takeLastShape() returns only shapes from this block.
93
    */
94
    void pushMark();
95
    /**
96
      Removes a recursion mark.
97
    */
98
    void popMark();
99
100
    /** Creates and inserts all UNO shapes into the passed container. */
101
    void                convertAndInsert(
102
                            const css::uno::Reference< css::drawing::XShapes >& rxShapes,
103
                            const ShapeParentAnchor* pParentAnchor = nullptr ) const;
104
105
8.91k
    const ShapeVector & getAllShapes() const { return maShapes; }
106
107
private:
108
    typedef RefVector< ShapeType >                  ShapeTypeVector;
109
    typedef RefMap< OUString, ShapeType >    ShapeTypeMap;
110
    typedef RefMap< OUString, ShapeBase >    ShapeMap;
111
112
    Drawing&            mrDrawing;          ///< The VML drawing page that contains this shape.
113
    ShapeTypeVector     maTypes;            ///< All shape templates.
114
    ShapeVector         maShapes;           ///< All shape definitions.
115
    ShapeTypeMap        maTypesById;        ///< All shape templates mapped by identifier.
116
    ShapeMap            maShapesById;       ///< All shape definitions mapped by identifier.
117
    std::stack< size_t > markStack;         ///< Recursion marks from pushMark()/popMark().
118
};
119
120
121
template< typename ShapeT >
122
std::shared_ptr<ShapeT> ShapeContainer::createShape()
123
6.99k
{
124
6.99k
    auto xShape = std::make_shared<ShapeT>( mrDrawing );
125
6.99k
    xShape->setContainer(this);
126
6.99k
    maShapes.push_back( xShape );
127
6.99k
    return xShape;
128
6.99k
}
std::__1::shared_ptr<oox::vml::GroupShape> oox::vml::ShapeContainer::createShape<oox::vml::GroupShape>()
Line
Count
Source
123
108
{
124
108
    auto xShape = std::make_shared<ShapeT>( mrDrawing );
125
108
    xShape->setContainer(this);
126
108
    maShapes.push_back( xShape );
127
108
    return xShape;
128
108
}
std::__1::shared_ptr<oox::vml::BezierShape> oox::vml::ShapeContainer::createShape<oox::vml::BezierShape>()
Line
Count
Source
123
463
{
124
463
    auto xShape = std::make_shared<ShapeT>( mrDrawing );
125
463
    xShape->setContainer(this);
126
463
    maShapes.push_back( xShape );
127
463
    return xShape;
128
463
}
std::__1::shared_ptr<oox::vml::ComplexShape> oox::vml::ShapeContainer::createShape<oox::vml::ComplexShape>()
Line
Count
Source
123
5.45k
{
124
5.45k
    auto xShape = std::make_shared<ShapeT>( mrDrawing );
125
5.45k
    xShape->setContainer(this);
126
5.45k
    maShapes.push_back( xShape );
127
5.45k
    return xShape;
128
5.45k
}
std::__1::shared_ptr<oox::vml::RectangleShape> oox::vml::ShapeContainer::createShape<oox::vml::RectangleShape>()
Line
Count
Source
123
587
{
124
587
    auto xShape = std::make_shared<ShapeT>( mrDrawing );
125
587
    xShape->setContainer(this);
126
587
    maShapes.push_back( xShape );
127
587
    return xShape;
128
587
}
std::__1::shared_ptr<oox::vml::EllipseShape> oox::vml::ShapeContainer::createShape<oox::vml::EllipseShape>()
Line
Count
Source
123
149
{
124
149
    auto xShape = std::make_shared<ShapeT>( mrDrawing );
125
149
    xShape->setContainer(this);
126
149
    maShapes.push_back( xShape );
127
149
    return xShape;
128
149
}
Unexecuted instantiation: std::__1::shared_ptr<oox::vml::PolyLineShape> oox::vml::ShapeContainer::createShape<oox::vml::PolyLineShape>()
std::__1::shared_ptr<oox::vml::LineShape> oox::vml::ShapeContainer::createShape<oox::vml::LineShape>()
Line
Count
Source
123
234
{
124
234
    auto xShape = std::make_shared<ShapeT>( mrDrawing );
125
234
    xShape->setContainer(this);
126
234
    maShapes.push_back( xShape );
127
234
    return xShape;
128
234
}
129
130
} // namespace oox::vml
131
132
#endif
133
134
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */