1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sdr/primitive2d/sdrolecontentprimitive2d.hxx>
21 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
22 #include <svx/svdoole2.hxx>
24 #include <vcl/svapp.hxx>
25 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
26 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
27 #include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
28 #include <svtools/colorcfg.hxx>
29 #include <basegfx/polygon/b2dpolygontools.hxx>
30 #include <basegfx/polygon/b2dpolygon.hxx>
31 #include <basegfx/matrix/b2dhommatrixtools.hxx>
34 namespace drawinglayer::primitive2d
36 Primitive2DReference
SdrOleContentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*aViewInformation*/) const
38 rtl::Reference
<SdrOle2Obj
> pSource
= mpSdrOle2Obj
.get();
39 bool bScaleContent(false);
44 const Graphic
* pOLEGraphic
= pSource
->GetGraphic();
48 aGraphic
= *pOLEGraphic
;
49 bScaleContent
= pSource
->IsEmptyPresObj();
52 #ifdef _WIN32 // Little point in displaying the "broken OLE" graphic on OSes that don't have real OLE, maybe?
53 if(GraphicType::NONE
== aGraphic
.GetType())
55 // no source, use fallback resource empty OLE graphic
56 aGraphic
= SdrOle2Obj::GetEmptyOLEReplacementGraphic();
60 if(GraphicType::NONE
== aGraphic
.GetType())
63 const GraphicObject
aGraphicObject(aGraphic
);
64 const GraphicAttr aGraphicAttr
;
65 Primitive2DContainer aContainer
;
68 // get transformation atoms
69 basegfx::B2DVector aScale
, aTranslate
;
70 double fRotate
, fShearX
;
71 getObjectTransform().decompose(aScale
, aTranslate
, fRotate
, fShearX
);
73 // get PrefSize from the graphic in 100th mm
74 Size
aPrefSize(aGraphic
.GetPrefSize());
76 if(MapUnit::MapPixel
== aGraphic
.GetPrefMapMode().GetMapUnit())
78 aPrefSize
= Application::GetDefaultDevice()->PixelToLogic(aPrefSize
, MapMode(MapUnit::Map100thMM
));
82 aPrefSize
= OutputDevice::LogicToLogic(aPrefSize
, aGraphic
.GetPrefMapMode(), MapMode(MapUnit::Map100thMM
));
85 const double fOffsetX((aScale
.getX() - aPrefSize
.getWidth()) / 2.0);
86 const double fOffsetY((aScale
.getY() - aPrefSize
.getHeight()) / 2.0);
88 if(fOffsetX
>= 0.0 && fOffsetY
>= 0.0)
90 // if content fits into frame, create it
91 basegfx::B2DHomMatrix
aInnerObjectMatrix(basegfx::utils::createScaleTranslateB2DHomMatrix(
92 aPrefSize
.getWidth(), aPrefSize
.getHeight(), fOffsetX
, fOffsetY
));
93 aInnerObjectMatrix
= basegfx::utils::createShearXRotateTranslateB2DHomMatrix(fShearX
, fRotate
, aTranslate
)
96 const drawinglayer::primitive2d::Primitive2DReference
aGraphicPrimitive(
97 new drawinglayer::primitive2d::GraphicPrimitive2D(
101 aContainer
.push_back(aGraphicPrimitive
);
106 // create graphic primitive for content
107 const drawinglayer::primitive2d::Primitive2DReference
aGraphicPrimitive(
108 new drawinglayer::primitive2d::GraphicPrimitive2D(
109 getObjectTransform(),
112 aContainer
.push_back(aGraphicPrimitive
);
115 // a standard gray outline is created for scaled content
117 return new GroupPrimitive2D(std::move(aContainer
));
119 const svtools::ColorConfig aColorConfig
;
120 const svtools::ColorConfigValue
aColor(aColorConfig
.GetColorValue(svtools::DOCBOUNDARIES
));
122 if(aColor
.bIsVisible
)
124 basegfx::B2DPolygon
aOutline(basegfx::utils::createUnitPolygon());
125 const Color
aVclColor(aColor
.nColor
);
126 aOutline
.transform(getObjectTransform());
127 const drawinglayer::primitive2d::Primitive2DReference
xOutline(
128 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(std::move(aOutline
), aVclColor
.getBColor()));
129 aContainer
.push_back(xOutline
);
131 return new GroupPrimitive2D(std::move(aContainer
));
134 SdrOleContentPrimitive2D::SdrOleContentPrimitive2D(
135 const SdrOle2Obj
& rSdrOle2Obj
,
136 basegfx::B2DHomMatrix aObjectTransform
,
137 sal_uInt32 nGraphicVersion
139 : mpSdrOle2Obj(const_cast< SdrOle2Obj
* >(&rSdrOle2Obj
)),
140 maObjectTransform(std::move(aObjectTransform
)),
141 mnGraphicVersion(nGraphicVersion
)
145 bool SdrOleContentPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
147 if( BufferedDecompositionPrimitive2D::operator==(rPrimitive
) )
149 const SdrOleContentPrimitive2D
& rCompare
= static_cast<const SdrOleContentPrimitive2D
&>(rPrimitive
);
150 auto xSdrThis
= mpSdrOle2Obj
.get();
151 auto xSdrThat
= rCompare
.mpSdrOle2Obj
.get();
152 const bool bBothNot(!xSdrThis
&& !xSdrThat
);
153 const bool bBothAndEqual(xSdrThis
&& xSdrThat
154 && xSdrThis
.get() == xSdrThat
.get());
156 return ((bBothNot
|| bBothAndEqual
)
157 && getObjectTransform() == rCompare
.getObjectTransform()
159 // #i104867# to find out if the Graphic content of the
160 // OLE has changed, use GraphicVersion number
161 && mnGraphicVersion
== rCompare
.mnGraphicVersion
168 basegfx::B2DRange
SdrOleContentPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
170 basegfx::B2DRange
aRange(0.0, 0.0, 1.0, 1.0);
171 aRange
.transform(getObjectTransform());
177 sal_uInt32
SdrOleContentPrimitive2D::getPrimitive2DID() const
179 return PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D
;
182 } // end of namespace
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */