Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/oox/vml/vmlshape.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_VMLSHAPE_HXX
21
#define INCLUDED_OOX_VML_VMLSHAPE_HXX
22
23
#include <memory>
24
#include <vector>
25
26
#include <com/sun/star/awt/Point.hpp>
27
#include <com/sun/star/uno/Reference.hxx>
28
#include <oox/dllapi.h>
29
#include <oox/vml/vmlformatting.hxx>
30
#include <rtl/ustring.hxx>
31
#include <sal/types.h>
32
33
namespace com::sun::star {
34
    namespace awt { struct Rectangle; }
35
    namespace drawing { class XShape; }
36
    namespace drawing { class XShapes; }
37
    namespace graphic { class XGraphic; }
38
}
39
40
namespace oox::vml {
41
42
class Drawing;
43
struct ShapeParentAnchor;
44
class ShapeContainer;
45
class TextBox;
46
47
const sal_Int32 VML_CLIENTDATA_UNCHECKED        = 0;
48
const sal_Int32 VML_CLIENTDATA_CHECKED          = 1;
49
const sal_Int32 VML_CLIENTDATA_MIXED            = 2;
50
51
const sal_Int32 VML_CLIENTDATA_TEXT             = 0;
52
const sal_Int32 VML_CLIENTDATA_INTEGER          = 1;
53
const sal_Int32 VML_CLIENTDATA_NUMBER           = 2;
54
const sal_Int32 VML_CLIENTDATA_REFERENCE        = 3;
55
const sal_Int32 VML_CLIENTDATA_FORMULA          = 4;
56
57
58
/** The shape model structure contains all properties shared by all types of shapes. */
59
struct ShapeTypeModel
60
{
61
    OUString     maShapeId;              ///< Unique identifier of the shape.
62
    OUString     maLegacyId;             ///< Plaintext identifier of the shape.
63
    OUString     maShapeName;            ///< Name of the shape, if present.
64
    std::optional< sal_Int32 > moShapeType;          ///< Builtin shape type identifier.
65
66
    std::optional< Int32Pair > moCoordPos;           ///< Top-left position of coordinate system for children scaling.
67
    std::optional< Int32Pair > moCoordSize;          ///< Size of coordinate system for children scaling.
68
    OUString     maPosition;             ///< Position type of the shape.
69
    OUString     maZIndex;                ///< ZIndex of the shape
70
    OUString     maLeft;                 ///< X position of the shape bounding box (number with unit).
71
    OUString     maTop;                  ///< Y position of the shape bounding box (number with unit).
72
    OUString     maWidth;                ///< Width of the shape bounding box (number with unit).
73
    OUString     maHeight;               ///< Height of the shape bounding box (number with unit).
74
    OUString     maMarginLeft;           ///< X position of the shape bounding box to shape anchor (number with unit).
75
    OUString     maMarginTop;            ///< Y position of the shape bounding box to shape anchor (number with unit).
76
    OUString     maPositionHorizontalRelative; ///< The X position is relative to this.
77
    OUString     maPositionVerticalRelative; ///< The Y position is relative to this.
78
    OUString     maPositionHorizontal;   ///< The X position orientation (default: absolute).
79
    OUString     maPositionVertical;     ///< The Y position orientation.
80
    OUString     maWidthPercent;         ///< The width in percents of the WidthRelative
81
    OUString     maHeightPercent;        ///< The height in percents of the HeightRelative
82
    OUString     maWidthRelative;        ///< To what the width is relative
83
    OUString     maHeightRelative;       ///< To what the height is relative
84
    OUString     maRotation;             ///< Rotation of the shape, in degrees.
85
    OUString     maFlip;                 ///< Flip type of the shape (can be "x" or "y").
86
    bool         mbAutoHeight;           ///< If true, the height value is a minimum value (mostly used for textboxes)
87
    bool         mbVisible;              ///< Visible or Hidden
88
    bool         mbHorizontalRule = false; ///< o:hr, a horizontal rule with its own layout rules
89
    OUString     maWrapStyle;            ///< Wrapping mode for text.
90
    OUString     maArcsize;              ///< round rectangles arc size
91
    OUString     maEditAs;               ///< Edit As type (e.g. "canvas" etc)
92
    OUString     maAdjustments;          ///< Shape adjustment values
93
94
    StrokeModel         maStrokeModel;          ///< Border line formatting.
95
    FillModel           maFillModel;            ///< Shape fill formatting.
96
    ShadowModel         maShadowModel;          ///< Shape shadow formatting.
97
    TextpathModel       maTextpathModel;        ///< Shape textpath formatting.
98
99
    std::optional< OUString > moGraphicPath;  ///< Path to a graphic for this shape.
100
    std::optional< OUString > moGraphicTitle; ///< Title of the graphic.
101
    std::optional< OUString > moWrapAnchorX;  ///< The base object from which our horizontal positioning should be calculated.
102
    std::optional< OUString > moWrapAnchorY;  ///< The base object from which our vertical positioning should be calculated.
103
    std::optional< OUString > moWrapType;     ///< How to wrap the text around the object
104
    std::optional< OUString > moWrapSide;     ///< On which side to wrap the text around the object
105
    OUString maVTextAnchor; ///< How the text inside the shape is anchored vertically.
106
    OUString maWrapDistanceLeft;         ///< Distance from the left side of the shape to the text that wraps around it.
107
    OUString maWrapDistanceRight;        ///< Distance from the right side of the shape to the text that wraps around it.
108
    OUString maWrapDistanceTop;          ///< Distance from the top of the shape to the text that wraps around it.
109
    OUString maWrapDistanceBottom;       ///< Distance from the bottom of the shape to the text that wraps around it.
110
    std::optional<OUString> moCropBottom; ///< Specifies how much to crop the image from the bottom up as a fraction of picture size.
111
    std::optional<OUString> moCropLeft; ///< Specifies how much to crop the image from the left in as a fraction of picture size.
112
    std::optional<OUString> moCropRight; ///< Specifies how much to crop the image from the right in as a fraction of picture size.
113
    std::optional<OUString> moCropTop; ///< Specifies how much to crop the image from the top down as a fraction of picture size.
114
    OUString maLayoutFlowAlt; ///< Specifies the alternate layout flow for text in textboxes.
115
116
    /// An adjustment for the intensity of all colors, i.e. contrast, on a 0..0x10000 scale.
117
    sal_Int32 mnGain = 0x10000;
118
119
    /// The image brightness, on a 0..0x10000 scale.
120
    sal_Int16 mnBlacklevel = 0;
121
122
    explicit            ShapeTypeModel();
123
124
    void                assignUsed( const ShapeTypeModel& rSource );
125
};
126
127
128
/** A shape template contains all formatting properties of shapes and can serve
129
    as templates for several shapes in a drawing. */
130
class SAL_DLLPUBLIC_RTTI ShapeType
131
{
132
public:
133
    explicit            ShapeType( Drawing& rDrawing );
134
    virtual             ~ShapeType();
135
136
    /** Returns read/write access to the shape template model structure. */
137
23.3k
    ShapeTypeModel& getTypeModel() { return maTypeModel; }
138
    /** Returns read access to the shape template model structure. */
139
15.5k
    const ShapeTypeModel& getTypeModel() const { return maTypeModel; }
140
141
    /** Returns the shape identifier (which is unique through the containing drawing). */
142
5.73k
    const OUString& getShapeId() const { return maTypeModel.maShapeId; }
143
    /** Returns the application defined shape type. */
144
    sal_Int32           getShapeType() const;
145
    /** Returns the fragment path to the embedded graphic used by this shape. */
146
    OUString     getGraphicPath() const;
147
148
20.9k
    const Drawing& getDrawing() const { return mrDrawing; }
149
6
    void setTextBox(bool bSet) {mbTextBox = bSet;}
150
18
    bool isTextBox() const {return mbTextBox;}
151
152
protected:
153
    /** Returns the coordinate system of this shape. */
154
    css::awt::Rectangle getCoordSystem() const;
155
    /** Returns the absolute shape rectangle according to the passed anchor. */
156
    css::awt::Rectangle getRectangle( const ShapeParentAnchor* pParentAnchor ) const;
157
    /** Returns the absolute shape rectangle. */
158
    virtual css::awt::Rectangle getAbsRectangle() const;
159
    /** Returns the rectangle relative to the parent coordinate system. */
160
    virtual css::awt::Rectangle getRelRectangle() const;
161
162
protected:
163
    Drawing&            mrDrawing;          ///< The VML drawing page that contains this shape.
164
    ShapeTypeModel      maTypeModel;        ///< The model structure containing shape type data.
165
    bool                mbTextBox;          //will be set if the shape contains a text box
166
};
167
168
169
/** Excel specific shape client data (such as cell anchor). */
170
struct ClientData
171
{
172
    OUString     maAnchor;           ///< Cell anchor as comma-separated string.
173
    OUString     maFmlaMacro;        ///< Link to macro associated to the control.
174
    OUString     maFmlaPict;         ///< Target cell range of picture links.
175
    OUString     maFmlaLink;         ///< Link to value cell associated to the control.
176
    OUString     maFmlaRange;        ///< Link to cell range used as data source for the control.
177
    OUString     maFmlaGroup;        ///< Link to value cell associated to a group of option buttons.
178
    sal_Int32           mnObjType;          ///< Type of the shape.
179
    sal_Int32           mnTextHAlign;       ///< Horizontal text alignment.
180
    sal_Int32           mnTextVAlign;       ///< Vertical text alignment.
181
    sal_Int32           mnCol;              ///< Column index for spreadsheet cell note.
182
    sal_Int32           mnRow;              ///< Row index for spreadsheet cell note.
183
    sal_Int32           mnChecked;          ///< State for checkboxes and option buttons.
184
    sal_Int32           mnDropStyle;        ///< Drop down box style (read-only or editable).
185
    sal_Int32           mnDropLines;        ///< Number of lines in drop down box.
186
    sal_Int32           mnVal;              ///< Current value of spin buttons and scroll bars.
187
    sal_Int32           mnMin;              ///< Minimum value of spin buttons and scroll bars.
188
    sal_Int32           mnMax;              ///< Maximum value of spin buttons and scroll bars.
189
    sal_Int32           mnInc;              ///< Small increment of spin buttons and scroll bars.
190
    sal_Int32           mnPage;             ///< Large increment of spin buttons and scroll bars.
191
    sal_Int32           mnSelType;          ///< Listbox selection type.
192
    sal_Int32           mnVTEdit;           ///< Data type of the textbox.
193
    bool                mbPrintObject;      ///< True = print the object.
194
    bool                mbVisible;          ///< True = cell note is visible.
195
    bool                mbDde;              ///< True = object is linked through DDE.
196
    bool                mbNo3D;             ///< True = flat style, false = 3D style.
197
    bool                mbNo3D2;            ///< True = flat style, false = 3D style (listboxes and dropdowns).
198
    bool                mbMultiLine;        ///< True = textbox allows line breaks.
199
    bool                mbVScroll;          ///< True = textbox has a vertical scrollbar.
200
    bool                mbSecretEdit;       ///< True = textbox is a password edit field.
201
    bool                mbMoveWithCells;    ///< True = shape moves with the cell (anchored to cell).
202
    bool                mbSizeWithCells;    ///< True = shape resizes with the cell.
203
204
    explicit            ClientData();
205
};
206
207
208
struct ShapeModel
209
{
210
    typedef ::std::vector< css::awt::Point >   PointVector;
211
212
    OUString     maType;             ///< Shape template with default properties.
213
    PointVector         maPoints;           ///< Points for the polyline shape.
214
    std::unique_ptr<TextBox>          mxTextBox;          ///< Text contents and properties.
215
    std::unique_ptr<ClientData>       mxClientData;       ///< Excel specific client data.
216
    OUString     maLegacyDiagramPath;///< Legacy Diagram Fragment Path
217
    OUString     maFrom;             ///< Start point for line shape.
218
    OUString     maTo;               ///< End point for line shape.
219
    OUString     maControl1;         ///< Bezier control point 1
220
    OUString     maControl2;         ///< Bezier control point 2
221
    OUString     maVmlPath;          ///< VML path for this shape
222
    bool         mbIsSignatureLine;  ///< Shape is a signature line
223
    OUString     maSignatureId;      ///< ID of the signature
224
    OUString     maSignatureLineSuggestedSignerName;
225
    OUString     maSignatureLineSuggestedSignerTitle;
226
    OUString     maSignatureLineSuggestedSignerEmail;
227
    OUString     maSignatureLineSigningInstructions;
228
    bool         mbSignatureLineShowSignDate;
229
    bool         mbSignatureLineCanAddComment;
230
    bool         mbInGroup;
231
    OUString     maHyperlink; ///< The hyperlink assigned to the shape
232
233
    explicit            ShapeModel();
234
                        ~ShapeModel();
235
236
    /** Creates and returns a new shape textbox structure. */
237
    TextBox&            createTextBox(ShapeTypeModel& rModel);
238
    /** Creates and returns a new shape client data structure. */
239
    ClientData&         createClientData();
240
};
241
242
243
/** A shape object that is part of a drawing. May inherit properties from a
244
    shape template. */
245
class OOX_DLLPUBLIC ShapeBase : public ShapeType
246
{
247
public:
248
    /** Returns read/write access to the shape model structure. */
249
7.46k
    ShapeModel&  getShapeModel() { return maShapeModel; }
250
    /** Returns read access to the shape model structure. */
251
888
    const ShapeModel& getShapeModel() const { return maShapeModel; }
252
253
    /** Returns read access to the shape textbox. */
254
16.8k
    const TextBox* getTextBox() const { return maShapeModel.mxTextBox.get(); }
255
    /** Returns read access to the shape client data structure. */
256
14.5k
    const ClientData* getClientData() const { return maShapeModel.mxClientData.get(); }
257
258
    /** Final processing after import of the drawing fragment. */
259
    virtual void        finalizeFragmentImport();
260
261
    /** Returns the real shape name if existing, or a generated shape name. */
262
    OUString     getShapeName() const;
263
264
    /** Returns the shape template with the passed identifier from the child shapes. */
265
    virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const;
266
    /** Returns the shape with the passed identifier from the child shapes. */
267
    virtual const ShapeBase* getChildById( const OUString& rShapeId ) const;
268
269
    /** Creates the corresponding XShape and inserts it into the passed container. */
270
    css::uno::Reference< css::drawing::XShape >
271
                        convertAndInsert(
272
                            const css::uno::Reference< css::drawing::XShapes >& rxShapes,
273
                            const ShapeParentAnchor* pParentAnchor = nullptr ) const;
274
275
    /** Returns bounds of Shape */
276
    css::awt::Rectangle getShapeRectangle() const;
277
278
    /** Collects common shape properties such as formatting attributes. */
279
    oox::drawingml::ShapePropertyMap makeShapePropertyMap() const;
280
281
    void setContainer(ShapeContainer* pContainer);
282
    ShapeContainer* getContainer() const;
283
284
protected:
285
    explicit            ShapeBase( Drawing& rDrawing );
286
287
    /** Derived classes create the corresponding XShape and insert it into the passed container. */
288
    virtual css::uno::Reference< css::drawing::XShape >
289
                        implConvertAndInsert(
290
                            const css::uno::Reference< css::drawing::XShapes >& rxShapes,
291
                            const css::awt::Rectangle& rShapeRect ) const = 0;
292
293
    /** Always called after implConvertAndInsert for the same task.*/
294
    virtual css::uno::Reference<css::drawing::XShape> finalImplConvertAndInsert(
295
        const css::uno::Reference<css::drawing::XShape>& rxShape) const
296
2.73k
    {
297
2.73k
        return rxShape;
298
2.73k
    };
299
300
    /** Calculates the final shape rectangle according to the passed anchor,
301
        if present, otherwise according to the own anchor settings. */
302
    css::awt::Rectangle calcShapeRectangle(
303
                            const ShapeParentAnchor* pParentAnchor ) const;
304
305
    /** Converts common shape properties such as formatting attributes. */
306
    void                convertShapeProperties(
307
                            const css::uno::Reference< css::drawing::XShape >& rxShape ) const;
308
309
protected:
310
    ShapeModel          maShapeModel;       ///< The model structure containing shape data.
311
    ShapeContainer*     mpContainer = nullptr;
312
};
313
314
315
/** A simple shape object based on a specific UNO shape service. */
316
class SimpleShape : public ShapeBase
317
{
318
public:
319
    explicit            SimpleShape( Drawing& rDrawing, OUString aService );
320
321
10.0k
    void setService( const OUString& aService ) { maService = aService; }
322
323
protected:
324
    /** Creates the corresponding XShape and inserts it into the passed container. */
325
    virtual css::uno::Reference< css::drawing::XShape >
326
                        implConvertAndInsert(
327
                            const css::uno::Reference< css::drawing::XShapes >& rxShapes,
328
                            const css::awt::Rectangle& rShapeRect ) const override;
329
    virtual css::uno::Reference<css::drawing::XShape> finalImplConvertAndInsert(
330
        const css::uno::Reference<css::drawing::XShape>& rxShape) const override;
331
    /** Used by both RectangleShape and ComplexShape. */
332
    css::uno::Reference<css::drawing::XShape>createEmbeddedPictureObject(
333
        const css::uno::Reference< css::drawing::XShapes >& rxShapes,
334
        const css::awt::Rectangle& rShapeRect, OUString const & rGraphicPath ) const;
335
336
    css::uno::Reference<css::drawing::XShape>createPictureObject(
337
            const css::uno::Reference< css::drawing::XShapes >& rxShapes,
338
            const css::awt::Rectangle& rShapeRect,
339
            css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) const;
340
341
private:
342
    OUString     maService;          ///< Name of the UNO shape service.
343
};
344
345
346
/** A rectangular shape object. */
347
class RectangleShape final : public SimpleShape
348
{
349
public:
350
    explicit            RectangleShape( Drawing& rDrawing );
351
private:
352
    /** Creates the corresponding XShape and inserts it into the passed container. */
353
    virtual css::uno::Reference<css::drawing::XShape>
354
                        implConvertAndInsert(
355
                            const css::uno::Reference<css::drawing::XShapes>& rxShapes,
356
                            const css::awt::Rectangle& rShapeRect) const override;
357
};
358
359
360
/** An oval shape object. */
361
class EllipseShape final : public SimpleShape
362
{
363
public:
364
    explicit            EllipseShape( Drawing& rDrawing );
365
};
366
367
368
/** A polygon shape object. */
369
class PolyLineShape final : public SimpleShape
370
{
371
public:
372
    explicit            PolyLineShape( Drawing& rDrawing );
373
374
private:
375
    /** Creates the corresponding XShape and inserts it into the passed container. */
376
    virtual css::uno::Reference< css::drawing::XShape >
377
                        implConvertAndInsert(
378
                            const css::uno::Reference< css::drawing::XShapes >& rxShapes,
379
                            const css::awt::Rectangle& rShapeRect ) const override;
380
};
381
382
/** A Line shape object. */
383
class LineShape final : public SimpleShape
384
{
385
public:
386
    explicit            LineShape( Drawing& rDrawing );
387
    virtual css::uno::Reference< css::drawing::XShape >
388
                        implConvertAndInsert(
389
                            const css::uno::Reference< css::drawing::XShapes >& rxShapes,
390
                            const css::awt::Rectangle& rShapeRect ) const override;
391
392
393
private:
394
    /** Returns the absolute shape rectangle. */
395
    virtual css::awt::Rectangle getAbsRectangle() const override;
396
    /** Returns the rectangle relative to the parent coordinate system. */
397
    virtual css::awt::Rectangle getRelRectangle() const override;
398
};
399
400
/** Bezier shape object that supports to, from, control1 and control2
401
    attribute or path attribute specification */
402
class BezierShape final : public SimpleShape
403
{
404
public:
405
    explicit             BezierShape( Drawing& rDrawing );
406
407
private:
408
    /** Creates the corresponding XShape and inserts it into the passed container. */
409
    virtual css::uno::Reference< css::drawing::XShape >
410
                        implConvertAndInsert(
411
                            const css::uno::Reference< css::drawing::XShapes >& rxShapes,
412
                            const css::awt::Rectangle& rShapeRect ) const override;
413
};
414
415
416
/** A shape object with custom geometry. */
417
class CustomShape : public SimpleShape
418
{
419
public:
420
    explicit            CustomShape( Drawing& rDrawing );
421
422
protected:
423
    /** Creates the corresponding XShape and inserts it into the passed container. */
424
    virtual css::uno::Reference< css::drawing::XShape >
425
                        implConvertAndInsert(
426
                            const css::uno::Reference< css::drawing::XShapes >& rxShapes,
427
                            const css::awt::Rectangle& rShapeRect ) const override;
428
};
429
430
431
/** A complex shape object. This can be a picture shape, a custom shape, an OLE
432
    object, or an ActiveX form control. */
433
class ComplexShape final : public CustomShape
434
{
435
public:
436
    explicit            ComplexShape( Drawing& rDrawing );
437
438
private:
439
    /** Creates the corresponding XShape and inserts it into the passed container. */
440
    virtual css::uno::Reference< css::drawing::XShape >
441
                        implConvertAndInsert(
442
                            const css::uno::Reference< css::drawing::XShapes >& rxShapes,
443
                            const css::awt::Rectangle& rShapeRect ) const override;
444
};
445
446
447
/** A group shape that extends the basic shape by a container of child shapes. */
448
class GroupShape final : public ShapeBase
449
{
450
public:
451
    explicit            GroupShape( Drawing& rDrawing );
452
    virtual             ~GroupShape() override;
453
454
    /** Returns read/write access to the container of child shapes and templates. */
455
156
    ShapeContainer& getChildren() { return *mxChildren; }
456
    /** Returns read access to the container of child shapes and templates. */
457
0
    const ShapeContainer& getChildren() const { return *mxChildren; }
458
459
    /** Final processing after import of the drawing fragment. */
460
    virtual void        finalizeFragmentImport() override;
461
462
    /** Returns the shape template with the passed identifier from the child shapes. */
463
    virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const override;
464
    /** Returns the shape with the passed identifier from the child shapes. */
465
    virtual const ShapeBase* getChildById( const OUString& rShapeId ) const override;
466
467
private:
468
    /** Creates the corresponding XShape and inserts it into the passed container. */
469
    virtual css::uno::Reference< css::drawing::XShape >
470
                        implConvertAndInsert(
471
                            const css::uno::Reference< css::drawing::XShapes >& rxShapes,
472
                            const css::awt::Rectangle& rShapeRect ) const override;
473
474
private:
475
    std::unique_ptr<ShapeContainer>   mxChildren;         ///< Shapes and templates that are part of this group.
476
};
477
478
479
} // namespace oox::vml
480
481
#endif
482
483
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */