1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_drawinglayer.hxx"
26*b1cdbd2cSJim Jagielski 
27*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/mediaprimitive2d.hxx>
28*b1cdbd2cSJim Jagielski #include <basegfx/polygon/b2dpolygon.hxx>
29*b1cdbd2cSJim Jagielski #include <basegfx/polygon/b2dpolygontools.hxx>
30*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
31*b1cdbd2cSJim Jagielski #include <avmedia/mediawindow.hxx>
32*b1cdbd2cSJim Jagielski #include <svtools/grfmgr.hxx>
33*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
34*b1cdbd2cSJim Jagielski #include <drawinglayer/geometry/viewinformation2d.hxx>
35*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
36*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
37*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
38*b1cdbd2cSJim Jagielski 
39*b1cdbd2cSJim Jagielski //////////////////////////////////////////////////////////////////////////////
40*b1cdbd2cSJim Jagielski 
41*b1cdbd2cSJim Jagielski namespace drawinglayer
42*b1cdbd2cSJim Jagielski {
43*b1cdbd2cSJim Jagielski 	namespace primitive2d
44*b1cdbd2cSJim Jagielski 	{
create2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const45*b1cdbd2cSJim Jagielski 		Primitive2DSequence MediaPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
46*b1cdbd2cSJim Jagielski 		{
47*b1cdbd2cSJim Jagielski 			Primitive2DSequence xRetval(1);
48*b1cdbd2cSJim Jagielski 
49*b1cdbd2cSJim Jagielski 			// create background object
50*b1cdbd2cSJim Jagielski 			basegfx::B2DPolygon aBackgroundPolygon(basegfx::tools::createUnitPolygon());
51*b1cdbd2cSJim Jagielski 			aBackgroundPolygon.transform(getTransform());
52*b1cdbd2cSJim Jagielski 			const Primitive2DReference xRefBackground(
53*b1cdbd2cSJim Jagielski 				new PolyPolygonColorPrimitive2D(
54*b1cdbd2cSJim Jagielski 					basegfx::B2DPolyPolygon(aBackgroundPolygon),
55*b1cdbd2cSJim Jagielski 					getBackgroundColor()));
56*b1cdbd2cSJim Jagielski 			xRetval[0] = xRefBackground;
57*b1cdbd2cSJim Jagielski 
58*b1cdbd2cSJim Jagielski 			// try to get graphic snapshot
59*b1cdbd2cSJim Jagielski 			const Graphic aGraphic(avmedia::MediaWindow::grabFrame(getURL(), true));
60*b1cdbd2cSJim Jagielski 
61*b1cdbd2cSJim Jagielski 			if(GRAPHIC_BITMAP == aGraphic.GetType() || GRAPHIC_GDIMETAFILE == aGraphic.GetType())
62*b1cdbd2cSJim Jagielski 			{
63*b1cdbd2cSJim Jagielski 				const GraphicObject aGraphicObject(aGraphic);
64*b1cdbd2cSJim Jagielski 				const GraphicAttr aGraphicAttr;
65*b1cdbd2cSJim Jagielski 				xRetval.realloc(2);
66*b1cdbd2cSJim Jagielski 				xRetval[0] = xRefBackground;
67*b1cdbd2cSJim Jagielski 				xRetval[1] = Primitive2DReference(new GraphicPrimitive2D(getTransform(), aGraphicObject, aGraphicAttr));
68*b1cdbd2cSJim Jagielski 			}
69*b1cdbd2cSJim Jagielski 
70*b1cdbd2cSJim Jagielski 			if(getDiscreteBorder())
71*b1cdbd2cSJim Jagielski 			{
72*b1cdbd2cSJim Jagielski 				const basegfx::B2DVector aDiscreteInLogic(rViewInformation.getInverseObjectToViewTransformation() *
73*b1cdbd2cSJim Jagielski                     basegfx::B2DVector((double)getDiscreteBorder(), (double)getDiscreteBorder()));
74*b1cdbd2cSJim Jagielski 				const double fDiscreteSize(aDiscreteInLogic.getX() + aDiscreteInLogic.getY());
75*b1cdbd2cSJim Jagielski 
76*b1cdbd2cSJim Jagielski 				basegfx::B2DRange aSourceRange(0.0, 0.0, 1.0, 1.0);
77*b1cdbd2cSJim Jagielski 				aSourceRange.transform(getTransform());
78*b1cdbd2cSJim Jagielski 
79*b1cdbd2cSJim Jagielski 				basegfx::B2DRange aDestRange(aSourceRange);
80*b1cdbd2cSJim Jagielski 				aDestRange.grow(-0.5 * fDiscreteSize);
81*b1cdbd2cSJim Jagielski 
82*b1cdbd2cSJim Jagielski 				if(basegfx::fTools::equalZero(aDestRange.getWidth()) || basegfx::fTools::equalZero(aDestRange.getHeight()))
83*b1cdbd2cSJim Jagielski 				{
84*b1cdbd2cSJim Jagielski 					// shrunk primitive has no content (zero size in X or Y), nothing to display. Still create
85*b1cdbd2cSJim Jagielski 					// invisible content for HitTest and BoundRect
86*b1cdbd2cSJim Jagielski 					const Primitive2DReference xHiddenLines(new HiddenGeometryPrimitive2D(xRetval));
87*b1cdbd2cSJim Jagielski 
88*b1cdbd2cSJim Jagielski 					xRetval = Primitive2DSequence(&xHiddenLines, 1);
89*b1cdbd2cSJim Jagielski 				}
90*b1cdbd2cSJim Jagielski 				else
91*b1cdbd2cSJim Jagielski 				{
92*b1cdbd2cSJim Jagielski 					// create transformation matrix from original range to shrunk range
93*b1cdbd2cSJim Jagielski 					basegfx::B2DHomMatrix aTransform;
94*b1cdbd2cSJim Jagielski 					aTransform.translate(-aSourceRange.getMinX(), -aSourceRange.getMinY());
95*b1cdbd2cSJim Jagielski 					aTransform.scale(aDestRange.getWidth() / aSourceRange.getWidth(), aDestRange.getHeight() / aSourceRange.getHeight());
96*b1cdbd2cSJim Jagielski 					aTransform.translate(aDestRange.getMinX(), aDestRange.getMinY());
97*b1cdbd2cSJim Jagielski 
98*b1cdbd2cSJim Jagielski 					// add transform primitive
99*b1cdbd2cSJim Jagielski 					const Primitive2DReference aScaled(new TransformPrimitive2D(aTransform, xRetval));
100*b1cdbd2cSJim Jagielski 					xRetval = Primitive2DSequence(&aScaled, 1L);
101*b1cdbd2cSJim Jagielski 				}
102*b1cdbd2cSJim Jagielski 			}
103*b1cdbd2cSJim Jagielski 
104*b1cdbd2cSJim Jagielski 			return xRetval;
105*b1cdbd2cSJim Jagielski 		}
106*b1cdbd2cSJim Jagielski 
MediaPrimitive2D(const basegfx::B2DHomMatrix & rTransform,const rtl::OUString & rURL,const basegfx::BColor & rBackgroundColor,sal_uInt32 nDiscreteBorder)107*b1cdbd2cSJim Jagielski 		MediaPrimitive2D::MediaPrimitive2D(
108*b1cdbd2cSJim Jagielski 			const basegfx::B2DHomMatrix& rTransform,
109*b1cdbd2cSJim Jagielski 			const rtl::OUString& rURL,
110*b1cdbd2cSJim Jagielski 			const basegfx::BColor& rBackgroundColor,
111*b1cdbd2cSJim Jagielski 			sal_uInt32 nDiscreteBorder)
112*b1cdbd2cSJim Jagielski 		:	BufferedDecompositionPrimitive2D(),
113*b1cdbd2cSJim Jagielski 			maTransform(rTransform),
114*b1cdbd2cSJim Jagielski 			maURL(rURL),
115*b1cdbd2cSJim Jagielski 			maBackgroundColor(rBackgroundColor),
116*b1cdbd2cSJim Jagielski 			mnDiscreteBorder(nDiscreteBorder)
117*b1cdbd2cSJim Jagielski 		{
118*b1cdbd2cSJim Jagielski 		}
119*b1cdbd2cSJim Jagielski 
operator ==(const BasePrimitive2D & rPrimitive) const120*b1cdbd2cSJim Jagielski 		bool MediaPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
121*b1cdbd2cSJim Jagielski 		{
122*b1cdbd2cSJim Jagielski 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
123*b1cdbd2cSJim Jagielski 			{
124*b1cdbd2cSJim Jagielski 				const MediaPrimitive2D& rCompare = (MediaPrimitive2D&)rPrimitive;
125*b1cdbd2cSJim Jagielski 
126*b1cdbd2cSJim Jagielski 				return (getTransform() == rCompare.getTransform()
127*b1cdbd2cSJim Jagielski 					&& getURL() == rCompare.getURL()
128*b1cdbd2cSJim Jagielski 					&& getBackgroundColor() == rCompare.getBackgroundColor()
129*b1cdbd2cSJim Jagielski 					&& getDiscreteBorder() == rCompare.getDiscreteBorder());
130*b1cdbd2cSJim Jagielski 			}
131*b1cdbd2cSJim Jagielski 
132*b1cdbd2cSJim Jagielski 			return false;
133*b1cdbd2cSJim Jagielski 		}
134*b1cdbd2cSJim Jagielski 
getB2DRange(const geometry::ViewInformation2D & rViewInformation) const135*b1cdbd2cSJim Jagielski 		basegfx::B2DRange MediaPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
136*b1cdbd2cSJim Jagielski 		{
137*b1cdbd2cSJim Jagielski 			basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
138*b1cdbd2cSJim Jagielski 			aRetval.transform(getTransform());
139*b1cdbd2cSJim Jagielski 
140*b1cdbd2cSJim Jagielski 			if(getDiscreteBorder())
141*b1cdbd2cSJim Jagielski 			{
142*b1cdbd2cSJim Jagielski 				const basegfx::B2DVector aDiscreteInLogic(rViewInformation.getInverseObjectToViewTransformation() *
143*b1cdbd2cSJim Jagielski                     basegfx::B2DVector((double)getDiscreteBorder(), (double)getDiscreteBorder()));
144*b1cdbd2cSJim Jagielski 				const double fDiscreteSize(aDiscreteInLogic.getX() + aDiscreteInLogic.getY());
145*b1cdbd2cSJim Jagielski 
146*b1cdbd2cSJim Jagielski 				aRetval.grow(-0.5 * fDiscreteSize);
147*b1cdbd2cSJim Jagielski 			}
148*b1cdbd2cSJim Jagielski 
149*b1cdbd2cSJim Jagielski 			return aRetval;
150*b1cdbd2cSJim Jagielski 		}
151*b1cdbd2cSJim Jagielski 
152*b1cdbd2cSJim Jagielski 		// provide unique ID
153*b1cdbd2cSJim Jagielski 		ImplPrimitrive2DIDBlock(MediaPrimitive2D, PRIMITIVE2D_ID_MEDIAPRIMITIVE2D)
154*b1cdbd2cSJim Jagielski 
155*b1cdbd2cSJim Jagielski 	} // end of namespace primitive2d
156*b1cdbd2cSJim Jagielski } // end of namespace drawinglayer
157*b1cdbd2cSJim Jagielski 
158*b1cdbd2cSJim Jagielski //////////////////////////////////////////////////////////////////////////////
159*b1cdbd2cSJim Jagielski // eof
160