LibreOffice Module svx (master) 1
sdrolecontentprimitive2d.cxx
Go to the documentation of this file.
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
22#include <svx/svdoole2.hxx>
23#include <utility>
24#include <vcl/svapp.hxx>
27#include <svtools/colorcfg.hxx>
31
32
34{
36 {
38 bool bScaleContent(false);
39 Graphic aGraphic;
40
41 if(pSource)
42 {
43 const Graphic* pOLEGraphic = pSource->GetGraphic();
44
45 if(pOLEGraphic)
46 {
47 aGraphic = *pOLEGraphic;
48 bScaleContent = pSource->IsEmptyPresObj();
49 }
50 }
51#ifdef _WIN32 // Little point in displaying the "broken OLE" graphic on OSes that don't have real OLE, maybe?
52 if(GraphicType::NONE == aGraphic.GetType())
53 {
54 // no source, use fallback resource empty OLE graphic
56 bScaleContent = true;
57 }
58#endif
59 if(GraphicType::NONE == aGraphic.GetType())
60 return;
61
62 const GraphicObject aGraphicObject(aGraphic);
63 const GraphicAttr aGraphicAttr;
64
65 if(bScaleContent)
66 {
67 // get transformation atoms
68 basegfx::B2DVector aScale, aTranslate;
69 double fRotate, fShearX;
70 getObjectTransform().decompose(aScale, aTranslate, fRotate, fShearX);
71
72 // get PrefSize from the graphic in 100th mm
73 Size aPrefSize(aGraphic.GetPrefSize());
74
75 if(MapUnit::MapPixel == aGraphic.GetPrefMapMode().GetMapUnit())
76 {
77 aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM));
78 }
79 else
80 {
81 aPrefSize = OutputDevice::LogicToLogic(aPrefSize, aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM));
82 }
83
84 const double fOffsetX((aScale.getX() - aPrefSize.getWidth()) / 2.0);
85 const double fOffsetY((aScale.getY() - aPrefSize.getHeight()) / 2.0);
86
87 if(basegfx::fTools::moreOrEqual(fOffsetX, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY, 0.0))
88 {
89 // if content fits into frame, create it
91 aPrefSize.getWidth(), aPrefSize.getHeight(), fOffsetX, fOffsetY));
92 aInnerObjectMatrix = basegfx::utils::createShearXRotateTranslateB2DHomMatrix(fShearX, fRotate, aTranslate)
93 * aInnerObjectMatrix;
94
97 aInnerObjectMatrix,
98 aGraphicObject,
99 aGraphicAttr));
100 rContainer.push_back(aGraphicPrimitive);
101 }
102 }
103 else
104 {
105 // create graphic primitive for content
109 aGraphicObject,
110 aGraphicAttr));
111 rContainer.push_back(aGraphicPrimitive);
112 }
113
114 // a standard gray outline is created for scaled content
115 if(!bScaleContent)
116 return;
117
118 const svtools::ColorConfig aColorConfig;
120
121 if(aColor.bIsVisible)
122 {
124 const Color aVclColor(aColor.nColor);
125 aOutline.transform(getObjectTransform());
127 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(std::move(aOutline), aVclColor.getBColor()));
128 rContainer.push_back(xOutline);
129 }
130 }
131
133 const SdrOle2Obj& rSdrOle2Obj,
134 basegfx::B2DHomMatrix aObjectTransform,
135 sal_uInt32 nGraphicVersion
136 )
137 : mpSdrOle2Obj(const_cast< SdrOle2Obj* >(&rSdrOle2Obj)),
138 maObjectTransform(std::move(aObjectTransform)),
139 mnGraphicVersion(nGraphicVersion)
140 {
141 }
142
144 {
145 if( BufferedDecompositionPrimitive2D::operator==(rPrimitive) )
146 {
147 const SdrOleContentPrimitive2D& rCompare = static_cast<const SdrOleContentPrimitive2D&>(rPrimitive);
148 auto xSdrThis = mpSdrOle2Obj.get();
149 auto xSdrThat = rCompare.mpSdrOle2Obj.get();
150 const bool bBothNot(!xSdrThis && !xSdrThat);
151 const bool bBothAndEqual(xSdrThis && xSdrThat
152 && xSdrThis.get() == xSdrThat.get());
153
154 return ((bBothNot || bBothAndEqual)
155 && getObjectTransform() == rCompare.getObjectTransform()
156
157 // #i104867# to find out if the Graphic content of the
158 // OLE has changed, use GraphicVersion number
160 );
161 }
162
163 return false;
164 }
165
167 {
168 basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0);
170
171 return aRange;
172 }
173
174 // provide unique ID
176 {
178 }
179
180} // end of namespace
181
182/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OutputDevice * GetDefaultDevice()
basegfx::BColor getBColor() const
Size GetPrefSize() const
GraphicType GetType() const
MapMode GetPrefMapMode() const
MapUnit GetMapUnit() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
static Graphic GetEmptyOLEReplacementGraphic()
Definition: svdoole2.cxx:1984
constexpr tools::Long getHeight() const
constexpr tools::Long getWidth() const
bool decompose(B2DTuple &rScale, B2DTuple &rTranslate, double &rRotate, double &rShearX) const
void transform(const basegfx::B2DHomMatrix &rMatrix)
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
TYPE getX() const
TYPE getY() const
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &aViewInformation) const override
const basegfx::B2DHomMatrix & getObjectTransform() const
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &rViewInformation) const override
SdrOleContentPrimitive2D(const SdrOle2Obj &rSdrOle2Obj, basegfx::B2DHomMatrix aObjectTransform, sal_uInt32 nGraphicVersion)
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart=true) const
rtl::Reference< interface_type > SAL_CALL get() const
bool moreOrEqual(const T &rfValA, const T &rfValB)
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
B2DHomMatrix createShearXRotateTranslateB2DHomMatrix(double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
B2DPolygon const & createUnitPolygon()
#define PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D