Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/inc/drawingml/customshapeproperties.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_DRAWINGML_CUSTOMSHAPEPROPERTIES_HXX
21
#define INCLUDED_OOX_DRAWINGML_CUSTOMSHAPEPROPERTIES_HXX
22
23
#include <memory>
24
#include <unordered_map>
25
#include <vector>
26
#include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
27
#include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
28
#include <com/sun/star/drawing/XShape.hpp>
29
#include <oox/helper/helper.hxx>
30
#include <oox/helper/propertymap.hxx>
31
#include <oox/token/tokens.hxx>
32
33
namespace oox::drawingml {
34
35
class CustomShapeProperties;
36
37
typedef std::shared_ptr< CustomShapeProperties > CustomShapePropertiesPtr;
38
39
struct CustomShapeGuide
40
{
41
    OUString   maName;
42
    OUString   maFormula;
43
};
44
45
class CustomShapeGuideContainer
46
{
47
public:
48
    sal_Int32 GetCustomShapeGuideValue( const OUString& rFormulaName ) const;
49
    sal_Int32 SetCustomShapeGuideValue( const CustomShapeGuide& rGuide );
50
51
    void push_back( const CustomShapeGuide& rGuide );
52
3.38k
    size_t size() const { return maGuideList.size(); };
53
18.0k
    bool empty() const { return maGuideList.empty(); };
54
570
    std::vector< CustomShapeGuide >::const_iterator begin() const { return maGuideList.begin(); };
55
570
    std::vector< CustomShapeGuide >::const_iterator end() const { return maGuideList.end(); };
56
200
    const CustomShapeGuide& operator[](size_t nIndex) const { return maGuideList[ nIndex ]; };
57
58
private:
59
    std::vector< CustomShapeGuide > maGuideList;
60
    mutable std::unordered_map< OUString, sal_Int32 > maGuideListLookupMap;
61
    mutable bool mbLookupMapStale = false;
62
    mutable sal_Int32 mnPreviousActSize = 0;
63
64
    void ActualizeLookupMap() const;
65
};
66
67
struct AdjustHandle
68
{
69
    bool                                    polar;
70
    css::drawing::EnhancedCustomShapeParameterPair
71
                                            pos;
72
73
    // depending to the type (polar or not):
74
    std::optional< OUString >               gdRef1; // gdRefX   or gdRefR
75
    std::optional< css::drawing::EnhancedCustomShapeParameter >
76
                                            min1;   // minX     or minR
77
    std::optional< css::drawing::EnhancedCustomShapeParameter >
78
                                            max1;   // maxX     or maxR
79
    std::optional< OUString >               gdRef2; // gdRefY   or gdRefAng
80
    std::optional< css::drawing::EnhancedCustomShapeParameter >
81
                                            min2;   // minX     or minAng
82
    std::optional< css::drawing::EnhancedCustomShapeParameter >
83
                                            max2;   // maxY     or maxAng
84
85
0
    AdjustHandle( bool bPolar ) : polar( bPolar ) {};
86
};
87
88
struct ConnectionSite
89
{
90
    css::drawing::EnhancedCustomShapeParameterPair
91
                                pos;
92
    css::drawing::EnhancedCustomShapeParameter
93
                                ang;
94
};
95
96
struct GeomRect
97
{
98
    css::drawing::EnhancedCustomShapeParameter   l;
99
    css::drawing::EnhancedCustomShapeParameter   t;
100
    css::drawing::EnhancedCustomShapeParameter   r;
101
    css::drawing::EnhancedCustomShapeParameter   b;
102
};
103
104
struct Path2D
105
{
106
    sal_Int64   w;
107
    sal_Int64   h;
108
    sal_Int32   fill;
109
    bool        stroke;
110
    bool        extrusionOk;
111
    std::vector< css::drawing::EnhancedCustomShapeParameterPair > parameter;
112
113
283
    Path2D() : w( 0 ), h( 0 ), fill( XML_norm ), stroke( true ), extrusionOk( true ) {};
114
};
115
116
117
class CustomShapeProperties final
118
{
119
public:
120
    CustomShapeProperties();
121
122
    void pushToPropSet( const css::uno::Reference < css::beans::XPropertySet > & xPropSet,
123
                        const css::awt::Size &aSize );
124
125
46.7k
    sal_Int32 getShapePresetType() const { return mnShapePresetType; }
126
    OUString getShapePresetTypeName() const;
127
72.4k
    void setShapePresetType( sal_Int32 nShapePresetType ){ mnShapePresetType = nShapePresetType; };
128
0
    bool                                getShapeTypeOverride() const { return mbShapeTypeOverride; };
129
404
    void                                setShapeTypeOverride( bool bShapeTypeOverride ) { mbShapeTypeOverride = bShapeTypeOverride; };
130
131
75.3k
    CustomShapeGuideContainer&          getAdjustmentGuideList(){ return maAdjustmentGuideList; };
132
2.13k
    CustomShapeGuideContainer&          getGuideList(){ return maGuideList; };
133
587
    std::vector< AdjustHandle >&        getAdjustHandleList(){ return maAdjustHandleList; };
134
1.11k
    std::vector< ConnectionSite >&      getConnectionSiteList(){ return maConnectionSiteList; };
135
587
    std::optional< GeomRect >&          getTextRect(){ return maTextRect; };
136
984
    std::vector< Path2D >&              getPath2DList(){ return maPath2DList; };
137
591
    std::vector< css::drawing::EnhancedCustomShapeSegment >& getSegments(){ return maSegments; };
138
9
    void                                setMirroredX( bool bMirroredX ) { mbMirroredX = bMirroredX; };
139
30
    void                                setMirroredY( bool bMirroredY ) { mbMirroredY = bMirroredY; };
140
10.2k
    void                                setTextPreRotateAngle( sal_Int32 nAngle ) { mnTextPreRotateAngle = nAngle; };
141
10.2k
    void                                setTextCameraZRotateAngle( sal_Int32 nAngle ) { mnTextCameraZRotateAngle = nAngle; };
142
66
    void                                setTextAreaRotateAngle(sal_Int32 nAngle) { moTextAreaRotateAngle = nAngle; };
143
144
45
    sal_Int32 getArcNum() { return mnArcNum++; }
145
146
    // Whether the path is built from guide equations, which hold a value in 1/100 mm, rather
147
    // than from plain numbers, which hold an ooxml coordinate. The angles of an arcTo do not count.
148
20
    void setPathUsesEquations() { mbPathUsesEquations = true; };
149
62.0k
    PropertyMap& getExtrusionPropertyMap() { return maExtrusionPropertyMap; }
150
151
    /**
152
       Returns whether or not the current CustomShapeProperties
153
       represent a default shape preset that is rectangular.
154
    */
155
    bool representsDefaultShape() const;
156
157
private:
158
159
    sal_Int32                       mnShapePresetType;
160
    bool                            mbShapeTypeOverride;
161
    CustomShapeGuideContainer       maAdjustmentGuideList;
162
    CustomShapeGuideContainer       maGuideList;
163
    std::vector< AdjustHandle >     maAdjustHandleList;
164
    std::vector< ConnectionSite >   maConnectionSiteList;
165
    std::optional< GeomRect >       maTextRect;
166
    std::vector< Path2D >           maPath2DList;
167
168
    std::vector< css::drawing::EnhancedCustomShapeSegment >
169
                                    maSegments;
170
    bool                            mbMirroredX;
171
    bool                            mbMirroredY;
172
    sal_Int32                       mnTextPreRotateAngle; // TextPreRotateAngle
173
    sal_Int32                       mnTextCameraZRotateAngle;
174
    std::optional< sal_Int32 >      moTextAreaRotateAngle; // TextRotateAngle
175
176
    typedef std::unordered_map< sal_Int32, PropertyMap > PresetDataMap;
177
178
    static PresetDataMap maPresetDataMap;
179
    static void initializePresetDataMap();
180
181
    sal_Int32 mnArcNum;
182
    bool mbPathUsesEquations;
183
    PropertyMap maExtrusionPropertyMap;
184
};
185
186
}
187
188
#endif // INCLUDED_OOX_DRAWINGML_CUSTOMSHAPEPROPERTIES_HXX
189
190
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */