1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <drawinglayer/primitive2d/mediaprimitive2d.hxx>
32*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
33*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
34*cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
35*cdf0e10cSrcweir #include <avmedia/mediawindow.hxx>
36*cdf0e10cSrcweir #include <svtools/grfmgr.hxx>
37*cdf0e10cSrcweir #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
38*cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation2d.hxx>
39*cdf0e10cSrcweir #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
40*cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
41*cdf0e10cSrcweir #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace drawinglayer
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir 	namespace primitive2d
48*cdf0e10cSrcweir 	{
49*cdf0e10cSrcweir 		Primitive2DSequence MediaPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
50*cdf0e10cSrcweir 		{
51*cdf0e10cSrcweir 			Primitive2DSequence xRetval(1);
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 			// create background object
54*cdf0e10cSrcweir 			basegfx::B2DPolygon aBackgroundPolygon(basegfx::tools::createUnitPolygon());
55*cdf0e10cSrcweir 			aBackgroundPolygon.transform(getTransform());
56*cdf0e10cSrcweir 			const Primitive2DReference xRefBackground(
57*cdf0e10cSrcweir 				new PolyPolygonColorPrimitive2D(
58*cdf0e10cSrcweir 					basegfx::B2DPolyPolygon(aBackgroundPolygon),
59*cdf0e10cSrcweir 					getBackgroundColor()));
60*cdf0e10cSrcweir 			xRetval[0] = xRefBackground;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 			// try to get graphic snapshot
63*cdf0e10cSrcweir 			const Graphic aGraphic(avmedia::MediaWindow::grabFrame(getURL(), true));
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 			if(GRAPHIC_BITMAP == aGraphic.GetType() || GRAPHIC_GDIMETAFILE == aGraphic.GetType())
66*cdf0e10cSrcweir 			{
67*cdf0e10cSrcweir 				const GraphicObject aGraphicObject(aGraphic);
68*cdf0e10cSrcweir 				const GraphicAttr aGraphicAttr;
69*cdf0e10cSrcweir 				xRetval.realloc(2);
70*cdf0e10cSrcweir 				xRetval[0] = xRefBackground;
71*cdf0e10cSrcweir 				xRetval[1] = Primitive2DReference(new GraphicPrimitive2D(getTransform(), aGraphicObject, aGraphicAttr));
72*cdf0e10cSrcweir 			}
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 			if(getDiscreteBorder())
75*cdf0e10cSrcweir 			{
76*cdf0e10cSrcweir 				const basegfx::B2DVector aDiscreteInLogic(rViewInformation.getInverseObjectToViewTransformation() *
77*cdf0e10cSrcweir                     basegfx::B2DVector((double)getDiscreteBorder(), (double)getDiscreteBorder()));
78*cdf0e10cSrcweir 				const double fDiscreteSize(aDiscreteInLogic.getX() + aDiscreteInLogic.getY());
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 				basegfx::B2DRange aSourceRange(0.0, 0.0, 1.0, 1.0);
81*cdf0e10cSrcweir 				aSourceRange.transform(getTransform());
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 				basegfx::B2DRange aDestRange(aSourceRange);
84*cdf0e10cSrcweir 				aDestRange.grow(-0.5 * fDiscreteSize);
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 				if(basegfx::fTools::equalZero(aDestRange.getWidth()) || basegfx::fTools::equalZero(aDestRange.getHeight()))
87*cdf0e10cSrcweir 				{
88*cdf0e10cSrcweir 					// shrunk primitive has no content (zero size in X or Y), nothing to display. Still create
89*cdf0e10cSrcweir 					// invisible content for HitTest and BoundRect
90*cdf0e10cSrcweir 					const Primitive2DReference xHiddenLines(new HiddenGeometryPrimitive2D(xRetval));
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 					xRetval = Primitive2DSequence(&xHiddenLines, 1);
93*cdf0e10cSrcweir 				}
94*cdf0e10cSrcweir 				else
95*cdf0e10cSrcweir 				{
96*cdf0e10cSrcweir 					// create transformation matrix from original range to shrunk range
97*cdf0e10cSrcweir 					basegfx::B2DHomMatrix aTransform;
98*cdf0e10cSrcweir 					aTransform.translate(-aSourceRange.getMinX(), -aSourceRange.getMinY());
99*cdf0e10cSrcweir 					aTransform.scale(aDestRange.getWidth() / aSourceRange.getWidth(), aDestRange.getHeight() / aSourceRange.getHeight());
100*cdf0e10cSrcweir 					aTransform.translate(aDestRange.getMinX(), aDestRange.getMinY());
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 					// add transform primitive
103*cdf0e10cSrcweir 					const Primitive2DReference aScaled(new TransformPrimitive2D(aTransform, xRetval));
104*cdf0e10cSrcweir 					xRetval = Primitive2DSequence(&aScaled, 1L);
105*cdf0e10cSrcweir 				}
106*cdf0e10cSrcweir 			}
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 			return xRetval;
109*cdf0e10cSrcweir 		}
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 		MediaPrimitive2D::MediaPrimitive2D(
112*cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rTransform,
113*cdf0e10cSrcweir 			const rtl::OUString& rURL,
114*cdf0e10cSrcweir 			const basegfx::BColor& rBackgroundColor,
115*cdf0e10cSrcweir 			sal_uInt32 nDiscreteBorder)
116*cdf0e10cSrcweir 		:	BufferedDecompositionPrimitive2D(),
117*cdf0e10cSrcweir 			maTransform(rTransform),
118*cdf0e10cSrcweir 			maURL(rURL),
119*cdf0e10cSrcweir 			maBackgroundColor(rBackgroundColor),
120*cdf0e10cSrcweir 			mnDiscreteBorder(nDiscreteBorder)
121*cdf0e10cSrcweir 		{
122*cdf0e10cSrcweir 		}
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 		bool MediaPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
125*cdf0e10cSrcweir 		{
126*cdf0e10cSrcweir 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
127*cdf0e10cSrcweir 			{
128*cdf0e10cSrcweir 				const MediaPrimitive2D& rCompare = (MediaPrimitive2D&)rPrimitive;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 				return (getTransform() == rCompare.getTransform()
131*cdf0e10cSrcweir 					&& getURL() == rCompare.getURL()
132*cdf0e10cSrcweir 					&& getBackgroundColor() == rCompare.getBackgroundColor()
133*cdf0e10cSrcweir 					&& getDiscreteBorder() == rCompare.getDiscreteBorder());
134*cdf0e10cSrcweir 			}
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 			return false;
137*cdf0e10cSrcweir 		}
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 		basegfx::B2DRange MediaPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
140*cdf0e10cSrcweir 		{
141*cdf0e10cSrcweir 			basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
142*cdf0e10cSrcweir 			aRetval.transform(getTransform());
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 			if(getDiscreteBorder())
145*cdf0e10cSrcweir 			{
146*cdf0e10cSrcweir 				const basegfx::B2DVector aDiscreteInLogic(rViewInformation.getInverseObjectToViewTransformation() *
147*cdf0e10cSrcweir                     basegfx::B2DVector((double)getDiscreteBorder(), (double)getDiscreteBorder()));
148*cdf0e10cSrcweir 				const double fDiscreteSize(aDiscreteInLogic.getX() + aDiscreteInLogic.getY());
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 				aRetval.grow(-0.5 * fDiscreteSize);
151*cdf0e10cSrcweir 			}
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 			return aRetval;
154*cdf0e10cSrcweir 		}
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 		// provide unique ID
157*cdf0e10cSrcweir 		ImplPrimitrive2DIDBlock(MediaPrimitive2D, PRIMITIVE2D_ID_MEDIAPRIMITIVE2D)
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	} // end of namespace primitive2d
160*cdf0e10cSrcweir } // end of namespace drawinglayer
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
163*cdf0e10cSrcweir // eof
164