Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/oox/export/DMLPresetShapeExport.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
10
#pragma once
11
12
#include <com/sun/star/uno/Any.hxx>
13
#include <com/sun/star/uno/Reference.hxx>
14
#include <com/sun/star/uno/Sequence.hxx>
15
16
#include <rtl/ustring.hxx>
17
#include <sal/types.h>
18
19
#include <string_view>
20
21
#include <oox/export/drawingml.hxx>
22
23
namespace com::sun::star::beans
24
{
25
struct PropertyValue;
26
}
27
28
namespace com::sun::star::drawing
29
{
30
class XShape;
31
struct EnhancedCustomShapeAdjustmentValue;
32
}
33
34
namespace oox::core
35
{
36
class XmlFilterBase;
37
}
38
39
namespace oox::drawingml
40
{
41
/// Class for exporting the custom shapes to OOXML preset ones, if possible.
42
/// This functionality needed for keeping the information for the office programs
43
/// about the shape type, and geometry data. Before these shapes were exported
44
/// with custom geometry, and they kept their geometry but has no information
45
/// about the shape itself. This lead to lost textbox size/position/padding for
46
/// example.
47
class DMLPresetShapeExporter
48
{
49
private:
50
    // the shape to export
51
    css::uno::Reference<css::drawing::XShape> m_xShape;
52
    // the DMLwriter
53
    DrawingML* m_pDMLexporter;
54
    // the type of the custom shape (diamond/rectangle/circle/triangle...)
55
    OUString m_sPresetShapeType;
56
    // True if the shape has points where its geometry can be modified
57
    bool m_bHasHandleValues;
58
    // The first the x the second the y coordinate, of flipping
59
    std::pair<bool, bool> m_bIsFlipped;
60
61
    // Custom Shape Geometry information for export:
62
63
    // The adjusting values stored in this sequence:
64
    css::uno::Sequence<css::drawing::EnhancedCustomShapeAdjustmentValue> m_AdjustmentValues;
65
    // Shapes what have adjusting points, the range of these points
66
    // and the index of the value stored in this sequence:
67
    css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>> m_HandleValues;
68
69
    //TODO:
70
    //css::awt::Rectangle m_ViewBox;
71
    //css::uno::Sequence<css::beans::PropertyValue> m_Path;
72
    //css::uno::Sequence<OUString> m_Equations;
73
74
public:
75
    DMLPresetShapeExporter() = delete;
76
    ~DMLPresetShapeExporter();
77
78
    DMLPresetShapeExporter(DrawingML* pDMLExporter,
79
                           css::uno::Reference<css::drawing::XShape> xShape);
80
81
    // Writes the preset shape to the xml
82
    bool WriteShape();
83
84
private:
85
    struct AdjustmentPointValueBase
86
    {
87
        std::optional<double> nMaxVal;
88
        std::optional<double> nMinVal;
89
        std::optional<double> nCurrVal;
90
    };
91
92
    typedef AdjustmentPointValueBase RadiusAdjustmentValue;
93
    typedef AdjustmentPointValueBase AngleAdjustmentValue;
94
    typedef AdjustmentPointValueBase XAdjustmentValue;
95
    typedef AdjustmentPointValueBase YAdjustmentValue;
96
97
    // Returns true if the shape flipped.
98
0
    bool IsXFlipped() const { return m_bIsFlipped.first; };
99
0
    bool IsYFlipped() const { return m_bIsFlipped.second; };
100
101
    // Returns with the shape type, like triangle for example
102
    const OUString& GetShapeType() const;
103
    // Returns with the handle points
104
    const css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>>&
105
    GetHandleValues() const;
106
    // Returns with the adjustment values
107
    const css::uno::Sequence<css::drawing::EnhancedCustomShapeAdjustmentValue>&
108
    GetAdjustmentValues() const;
109
    // Returns with the raw value of the given property of the shape geometry.
110
    css::uno::Any GetHandleValueOfModificationPoint(sal_Int32 nPoint, std::u16string_view sType);
111
    // Returns with the appropriate value of the handle point.
112
    RadiusAdjustmentValue GetAdjustmentPointRadiusValue(sal_Int32 nPoint);
113
    AngleAdjustmentValue GetAdjustmentPointAngleValue(sal_Int32 nPoint);
114
    XAdjustmentValue GetAdjustmentPointXValue(sal_Int32 nPoint);
115
    YAdjustmentValue GetAdjustmentPointYValue(sal_Int32 nPoint);
116
117
    // Writes one adjustment point.
118
    bool WriteAV(const OUString& sValName, const OUString& sVal);
119
    // Opens/Closes the AVlist tag.
120
    bool StartAVListWriting();
121
    bool EndAVListWriting();
122
123
    // Finds the given value in the sequence
124
    static css::uno::Any FindHandleValue(css::uno::Sequence<css::beans::PropertyValue> aValues,
125
                                         std::u16string_view sKey);
126
    // Writes and converts the adjustment points from sdr to ooxml ones per shape type.
127
    bool WriteShapeWithAVlist();
128
129
}; // end of DMLPresetShapeExporter class
130
131
} // end of namespace oox::drawingml
132
133
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */