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