Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrolecontentprimitive2d.cxx
blobd5ead8c71cd4288efd8380c446ff653b6d45b8ef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
23 #include <utility>
24 #include <vcl/svapp.hxx>
25 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
26 #include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
27 #include <svtools/colorcfg.hxx>
28 #include <basegfx/polygon/b2dpolygontools.hxx>
29 #include <basegfx/polygon/b2dpolygon.hxx>
30 #include <basegfx/matrix/b2dhommatrixtools.hxx>
33 namespace drawinglayer::primitive2d
35 void SdrOleContentPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const
37 rtl::Reference<SdrOle2Obj> pSource = mpSdrOle2Obj.get();
38 bool bScaleContent(false);
39 Graphic aGraphic;
41 if(pSource)
43 const Graphic* pOLEGraphic = pSource->GetGraphic();
45 if(pOLEGraphic)
47 aGraphic = *pOLEGraphic;
48 bScaleContent = pSource->IsEmptyPresObj();
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())
54 // no source, use fallback resource empty OLE graphic
55 aGraphic = SdrOle2Obj::GetEmptyOLEReplacementGraphic();
56 bScaleContent = true;
58 #endif
59 if(GraphicType::NONE == aGraphic.GetType())
60 return;
62 const GraphicObject aGraphicObject(aGraphic);
63 const GraphicAttr aGraphicAttr;
65 if(bScaleContent)
67 // get transformation atoms
68 basegfx::B2DVector aScale, aTranslate;
69 double fRotate, fShearX;
70 getObjectTransform().decompose(aScale, aTranslate, fRotate, fShearX);
72 // get PrefSize from the graphic in 100th mm
73 Size aPrefSize(aGraphic.GetPrefSize());
75 if(MapUnit::MapPixel == aGraphic.GetPrefMapMode().GetMapUnit())
77 aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM));
79 else
81 aPrefSize = OutputDevice::LogicToLogic(aPrefSize, aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM));
84 const double fOffsetX((aScale.getX() - aPrefSize.getWidth()) / 2.0);
85 const double fOffsetY((aScale.getY() - aPrefSize.getHeight()) / 2.0);
87 if(basegfx::fTools::moreOrEqual(fOffsetX, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY, 0.0))
89 // if content fits into frame, create it
90 basegfx::B2DHomMatrix aInnerObjectMatrix(basegfx::utils::createScaleTranslateB2DHomMatrix(
91 aPrefSize.getWidth(), aPrefSize.getHeight(), fOffsetX, fOffsetY));
92 aInnerObjectMatrix = basegfx::utils::createShearXRotateTranslateB2DHomMatrix(fShearX, fRotate, aTranslate)
93 * aInnerObjectMatrix;
95 const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive(
96 new drawinglayer::primitive2d::GraphicPrimitive2D(
97 aInnerObjectMatrix,
98 aGraphicObject,
99 aGraphicAttr));
100 rContainer.push_back(aGraphicPrimitive);
103 else
105 // create graphic primitive for content
106 const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive(
107 new drawinglayer::primitive2d::GraphicPrimitive2D(
108 getObjectTransform(),
109 aGraphicObject,
110 aGraphicAttr));
111 rContainer.push_back(aGraphicPrimitive);
114 // a standard gray outline is created for scaled content
115 if(!bScaleContent)
116 return;
118 const svtools::ColorConfig aColorConfig;
119 const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
121 if(aColor.bIsVisible)
123 basegfx::B2DPolygon aOutline(basegfx::utils::createUnitPolygon());
124 const Color aVclColor(aColor.nColor);
125 aOutline.transform(getObjectTransform());
126 const drawinglayer::primitive2d::Primitive2DReference xOutline(
127 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(std::move(aOutline), aVclColor.getBColor()));
128 rContainer.push_back(xOutline);
132 SdrOleContentPrimitive2D::SdrOleContentPrimitive2D(
133 const SdrOle2Obj& rSdrOle2Obj,
134 basegfx::B2DHomMatrix aObjectTransform,
135 sal_uInt32 nGraphicVersion
137 : mpSdrOle2Obj(const_cast< SdrOle2Obj* >(&rSdrOle2Obj)),
138 maObjectTransform(std::move(aObjectTransform)),
139 mnGraphicVersion(nGraphicVersion)
143 bool SdrOleContentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
145 if( BufferedDecompositionPrimitive2D::operator==(rPrimitive) )
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());
154 return ((bBothNot || bBothAndEqual)
155 && getObjectTransform() == rCompare.getObjectTransform()
157 // #i104867# to find out if the Graphic content of the
158 // OLE has changed, use GraphicVersion number
159 && mnGraphicVersion == rCompare.mnGraphicVersion
163 return false;
166 basegfx::B2DRange SdrOleContentPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
168 basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0);
169 aRange.transform(getObjectTransform());
171 return aRange;
174 // provide unique ID
175 sal_uInt32 SdrOleContentPrimitive2D::getPrimitive2DID() const
177 return PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D;
180 } // end of namespace
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */