1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_svx.hxx"
25 #include <svx/sdr/primitive2d/sdrolecontentprimitive2d.hxx>
26 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
27 #include <svx/svdoole2.hxx>
28 #include <vcl/svapp.hxx>
29 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
30 #include <svtools/colorcfg.hxx>
31 #include <basegfx/polygon/b2dpolygontools.hxx>
32 #include <basegfx/polygon/b2dpolygon.hxx>
33 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
34 #include <basegfx/matrix/b2dhommatrixtools.hxx>
35 
36 //////////////////////////////////////////////////////////////////////////////
37 
38 namespace drawinglayer
39 {
40 	namespace primitive2d
41 	{
create2DDecomposition(const geometry::ViewInformation2D &) const42 		Primitive2DSequence SdrOleContentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
43 		{
44 			Primitive2DSequence aRetval;
45             const SdrOle2Obj* pSource = (mpSdrOle2Obj.is() ? static_cast< SdrOle2Obj* >(mpSdrOle2Obj.get()) : 0);
46             bool bScaleContent(false);
47             Graphic aGraphic;
48 
49             if(pSource)
50             {
51     		    Graphic* pOLEGraphic = (getHighContrast())
52                     ? pSource->getEmbeddedObjectRef().GetHCGraphic()
53                     : pSource->GetGraphic();
54 
55                 if(pOLEGraphic)
56                 {
57                     aGraphic = *pOLEGraphic;
58                     bScaleContent = pSource->IsEmptyPresObj();
59                 }
60             }
61 
62             if(GRAPHIC_NONE == aGraphic.GetType())
63             {
64                 // no source, use fallback ressource emty OLE graphic
65                 const Bitmap aEmptyOLEBitmap(SdrOle2Obj::GetEmtyOLEReplacementBitmap());
66 				aGraphic = Graphic(aEmptyOLEBitmap);
67                 bScaleContent = true;
68             }
69 
70             if(GRAPHIC_NONE != aGraphic.GetType())
71             {
72 		        const GraphicObject aGraphicObject(aGraphic);
73 		        const GraphicAttr aGraphicAttr;
74                 drawinglayer::primitive2d::Primitive2DSequence xOLEContent;
75 
76                 if(bScaleContent)
77                 {
78 				    // get transformation atoms
79 				    basegfx::B2DVector aScale, aTranslate;
80 				    double fRotate, fShearX;
81 				    getObjectTransform().decompose(aScale, aTranslate, fRotate, fShearX);
82 
83                     // get PrefSize from the graphic in 100th mm
84                     Size aPrefSize(aGraphic.GetPrefSize());
85 
86                     if(MAP_PIXEL == aGraphic.GetPrefMapMode().GetMapUnit())
87                     {
88                         aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MAP_100TH_MM);
89                     }
90 			        else
91                     {
92                         aPrefSize = Application::GetDefaultDevice()->LogicToLogic(aPrefSize, aGraphic.GetPrefMapMode(), MAP_100TH_MM);
93                     }
94 
95 					const double fOffsetX((aScale.getX() - aPrefSize.getWidth()) / 2.0);
96 					const double fOffsetY((aScale.getY() - aPrefSize.getHeight()) / 2.0);
97 
98 					if(basegfx::fTools::moreOrEqual(fOffsetX, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY, 0.0))
99 					{
100 						// if content fits into frame, create it
101 						basegfx::B2DHomMatrix aInnerObjectMatrix(basegfx::tools::createScaleTranslateB2DHomMatrix(
102 							aPrefSize.getWidth(), aPrefSize.getHeight(), fOffsetX, fOffsetY));
103 						aInnerObjectMatrix = basegfx::tools::createShearXRotateTranslateB2DHomMatrix(fShearX, fRotate, aTranslate)
104 							* aInnerObjectMatrix;
105 
106                         const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive(
107 		                    new drawinglayer::primitive2d::GraphicPrimitive2D(
108                                 aInnerObjectMatrix,
109                                 aGraphicObject,
110                                 aGraphicAttr));
111                         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aGraphicPrimitive);
112 					}
113 				}
114                 else
115                 {
116 			        // create graphic primitive for content
117                     const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive(
118                         new drawinglayer::primitive2d::GraphicPrimitive2D(
119                             getObjectTransform(),
120                             aGraphicObject,
121                             aGraphicAttr));
122                     drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aGraphicPrimitive);
123                 }
124 
125                 // a standard gray outline is created for scaled content
126                 if(bScaleContent)
127                 {
128                     const svtools::ColorConfig aColorConfig;
129                     const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
130 
131 			        if(aColor.bIsVisible)
132 			        {
133 				        basegfx::B2DPolygon aOutline(basegfx::tools::createUnitPolygon());
134                         const Color aVclColor(aColor.nColor);
135                         aOutline.transform(getObjectTransform());
136                         const drawinglayer::primitive2d::Primitive2DReference xOutline(
137                             new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOutline, aVclColor.getBColor()));
138                         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xOutline);
139                     }
140                 }
141             }
142 
143             // get graphic and check scale content state
144 			return aRetval;
145 		}
146 
SdrOleContentPrimitive2D(const SdrOle2Obj & rSdrOle2Obj,const basegfx::B2DHomMatrix & rObjectTransform,sal_uInt32 nGraphicVersion,bool bHighContrast)147 		SdrOleContentPrimitive2D::SdrOleContentPrimitive2D(
148 			const SdrOle2Obj& rSdrOle2Obj,
149 			const basegfx::B2DHomMatrix& rObjectTransform,
150             sal_uInt32 nGraphicVersion,
151 			bool bHighContrast)
152 		:	BufferedDecompositionPrimitive2D(),
153 			mpSdrOle2Obj(const_cast< SdrOle2Obj* >(&rSdrOle2Obj)),
154             maObjectTransform(rObjectTransform),
155             mnGraphicVersion(nGraphicVersion),
156             mbHighContrast(bHighContrast)
157 		{
158 		}
159 
operator ==(const BasePrimitive2D & rPrimitive) const160 		bool SdrOleContentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
161 		{
162 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
163 			{
164 				const SdrOleContentPrimitive2D& rCompare = (SdrOleContentPrimitive2D&)rPrimitive;
165                 const bool bBothNot(!mpSdrOle2Obj.is() && !rCompare.mpSdrOle2Obj.is());
166                 const bool bBothAndEqual(mpSdrOle2Obj.is() && rCompare.mpSdrOle2Obj.is()
167                     && mpSdrOle2Obj.get() == rCompare.mpSdrOle2Obj.get());
168 
169 				return ((bBothNot || bBothAndEqual)
170                     && getObjectTransform() == rCompare.getObjectTransform()
171 
172                     // #i104867# to find out if the Graphic content of the
173                     // OLE has changed, use GraphicVersion number
174                     && getGraphicVersion() == rCompare.getGraphicVersion()
175 
176                     && getHighContrast() == rCompare.getHighContrast());
177 			}
178 
179 			return false;
180 		}
181 
getB2DRange(const geometry::ViewInformation2D &) const182         basegfx::B2DRange SdrOleContentPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
183         {
184             basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0);
185             aRange.transform(getObjectTransform());
186 
187             return aRange;
188         }
189 
190 		// provide unique ID
191 		ImplPrimitrive2DIDBlock(SdrOleContentPrimitive2D, PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D)
192 
193 	} // end of namespace primitive2d
194 } // end of namespace drawinglayer
195 
196 //////////////////////////////////////////////////////////////////////////////
197 // eof
198