Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/sdr/contact/viewcontactofsdrole2obj.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
 * 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
#include <drawinglayer/primitive2d/Tools.hxx>
21
#include <sdr/contact/viewcontactofsdrole2obj.hxx>
22
#include <svx/svdoole2.hxx>
23
#include <sdr/contact/viewobjectcontactofsdrole2obj.hxx>
24
#include <basegfx/matrix/b2dhommatrix.hxx>
25
#include <sdr/primitive2d/sdrole2primitive2d.hxx>
26
#include <sdr/primitive2d/sdrattributecreator.hxx>
27
#include <vcl/canvastools.hxx>
28
#include <tools/debug.hxx>
29
#include <sdr/primitive2d/sdrolecontentprimitive2d.hxx>
30
#include <basegfx/matrix/b2dhommatrixtools.hxx>
31
#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
32
#include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
33
#include <svx/charthelper.hxx>
34
#include <svtools/embedhlp.hxx>
35
36
namespace sdr::contact {
37
38
// Create an Object-Specific ViewObjectContact, set ViewContact and
39
// ObjectContact. Always needs to return something.
40
ViewObjectContact& ViewContactOfSdrOle2Obj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
41
0
{
42
0
    ViewObjectContact* pRetval = new ViewObjectContactOfSdrOle2Obj(rObjectContact, *this);
43
0
    DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
44
45
0
    return *pRetval;
46
0
}
47
48
ViewContactOfSdrOle2Obj::ViewContactOfSdrOle2Obj(SdrOle2Obj& rOle2Obj)
49
590
:   ViewContactOfSdrRectObj(rOle2Obj)
50
590
{
51
590
}
52
53
ViewContactOfSdrOle2Obj::~ViewContactOfSdrOle2Obj()
54
590
{
55
590
}
56
57
basegfx::B2DHomMatrix ViewContactOfSdrOle2Obj::createObjectTransform() const
58
0
{
59
    // take unrotated snap rect (direct model data) for position and size
60
0
    const tools::Rectangle aRectangle(GetOle2Obj().GetGeoRect());
61
0
    const basegfx::B2DRange aObjectRange = vcl::unotools::b2DRectangleFromRectangle(aRectangle);
62
63
    // create object matrix
64
0
    const GeoStat& rGeoStat(GetOle2Obj().GetGeoStat());
65
0
    const double fShearX(-rGeoStat.mfTanShearAngle);
66
0
    const double fRotate(rGeoStat.m_nRotationAngle ? toRadians(36000_deg100 - rGeoStat.m_nRotationAngle) : 0.0);
67
68
0
    return basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix(
69
0
        aObjectRange.getWidth(), aObjectRange.getHeight(),
70
0
        fShearX,
71
0
        fRotate,
72
0
        aObjectRange.getMinX(), aObjectRange.getMinY());
73
0
}
74
75
void ViewContactOfSdrOle2Obj::createPrimitive2DSequenceWithParameters(drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
76
0
{
77
    // get object transformation
78
0
    const basegfx::B2DHomMatrix aObjectMatrix(createObjectTransform());
79
80
    // Prepare attribute settings, will be used soon anyways
81
0
    const SfxItemSet& rItemSet = GetOle2Obj().GetMergedItemSet();
82
83
    // this may be refined more granular; if no content, attributes may get simpler
84
0
    const drawinglayer::attribute::SdrLineFillEffectsTextAttribute aAttribute(
85
0
        drawinglayer::primitive2d::createNewSdrLineFillEffectsTextAttribute(
86
0
            rItemSet,
87
0
            GetOle2Obj().getText(0),
88
0
            true));
89
0
    drawinglayer::primitive2d::Primitive2DContainer xContent;
90
91
0
    if(GetOle2Obj().IsChart())
92
0
    {
93
        // try to get chart primitives and chart range directly from xChartModel
94
0
        basegfx::B2DRange aChartContentRange;
95
0
        drawinglayer::primitive2d::Primitive2DContainer aChartSequence(
96
0
            ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
97
0
                GetOle2Obj().getXModel(),
98
0
                aChartContentRange));
99
0
        const double fWidth(aChartContentRange.getWidth());
100
0
        const double fHeight(aChartContentRange.getHeight());
101
102
0
        if(!aChartSequence.empty() && fWidth > 0.0 && fHeight > 0.0)
103
0
        {
104
            // create embedding transformation
105
0
            basegfx::B2DHomMatrix aEmbed(
106
0
                basegfx::utils::createTranslateB2DHomMatrix(
107
0
                    -aChartContentRange.getMinX(),
108
0
                    -aChartContentRange.getMinY()));
109
110
0
            aEmbed.scale(1.0 / fWidth, 1.0 / fHeight);
111
0
            aEmbed = aObjectMatrix * aEmbed;
112
0
            xContent = drawinglayer::primitive2d::Primitive2DContainer{
113
0
                new drawinglayer::primitive2d::TransformPrimitive2D(aEmbed,
114
0
                                                                    std::move(aChartSequence))
115
0
            };
116
0
        }
117
0
    }
118
119
0
    if(xContent.empty())
120
0
    {
121
        // #i102063# embed OLE content in an own primitive; this will be able to decompose accessing
122
        // the weak SdrOle2 reference and will also implement getB2DRange() for fast BoundRect
123
        // calculations without OLE Graphic access (which may trigger e.g. chart recalculation).
124
        // It will also take care of HighContrast and ScaleContent
125
0
        xContent = drawinglayer::primitive2d::Primitive2DContainer{
126
0
            new drawinglayer::primitive2d::SdrOleContentPrimitive2D(
127
0
                GetOle2Obj(), aObjectMatrix,
128
129
                // #i104867# add GraphicVersion number to be able to check for
130
                // content change in the primitive later
131
0
                GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion())
132
0
        };
133
0
    }
134
135
0
    if (!GetOle2Obj().GetName().isEmpty() || !GetOle2Obj().GetTitle().isEmpty()
136
0
        || !GetOle2Obj().GetDescription().isEmpty())
137
0
    {
138
0
        xContent = drawinglayer::primitive2d::Primitive2DContainer{
139
0
                new drawinglayer::primitive2d::ObjectInfoPrimitive2D(
140
0
                    std::move(xContent), GetOle2Obj().GetName(), GetOle2Obj().GetTitle(),
141
0
                    GetOle2Obj().GetDescription())
142
0
        };
143
0
    }
144
145
    // create primitive. Use Ole2 primitive here. Prepare attribute settings, will
146
    // be used soon anyways. Always create primitives to allow the decomposition of
147
    // SdrOle2Primitive2D to create needed invisible elements for HitTest and/or BoundRect
148
0
    const drawinglayer::primitive2d::Primitive2DReference xReference(
149
0
        new drawinglayer::primitive2d::SdrOle2Primitive2D(
150
0
            std::move(xContent),
151
0
            aObjectMatrix,
152
0
            aAttribute));
153
154
0
    rVisitor.visit(xReference);
155
0
}
156
157
basegfx::B2DRange ViewContactOfSdrOle2Obj::getRange( const drawinglayer::geometry::ViewInformation2D& rViewInfo2D ) const
158
0
{
159
    // this may be refined more granular; if no content, attributes may get simpler
160
0
    const drawinglayer::attribute::SdrLineFillEffectsTextAttribute aAttribute =
161
0
        drawinglayer::primitive2d::createNewSdrLineFillEffectsTextAttribute(
162
0
            GetOle2Obj().GetMergedItemSet(),
163
0
            GetOle2Obj().getText(0),
164
0
            true);
165
166
0
    basegfx::B2DHomMatrix aObjectMatrix = createObjectTransform();
167
168
0
    const drawinglayer::primitive2d::Primitive2DReference xReference(
169
0
        new drawinglayer::primitive2d::SdrOle2Primitive2D(
170
0
            drawinglayer::primitive2d::Primitive2DContainer {
171
0
                    new drawinglayer::primitive2d::SdrOleContentPrimitive2D(
172
0
                        GetOle2Obj(),
173
0
                        aObjectMatrix,
174
0
                        GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion())
175
0
            },
176
0
            aObjectMatrix,
177
0
            aAttribute));
178
179
0
    return drawinglayer::primitive2d::getB2DRangeFromPrimitive2DReference(xReference, rViewInfo2D);
180
0
}
181
182
void ViewContactOfSdrOle2Obj::createViewIndependentPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
183
0
{
184
0
    createPrimitive2DSequenceWithParameters(rVisitor);
185
0
}
186
187
}
188
189
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */