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/wallpaperprimitive2d.hxx> 32*cdf0e10cSrcweir #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> 33*cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 34*cdf0e10cSrcweir #include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx> 35*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 36*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 37*cdf0e10cSrcweir #include <drawinglayer/primitive2d/maskprimitive2d.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir namespace drawinglayer 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir namespace primitive2d 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir Primitive2DSequence WallpaperBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir Primitive2DSequence aRetval; 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir if(!getLocalObjectRange().isEmpty() && !getBitmapEx().IsEmpty()) 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir // get bitmap PIXEL size 52*cdf0e10cSrcweir const Size& rPixelSize = getBitmapEx().GetSizePixel(); 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir if(rPixelSize.Width() > 0 && rPixelSize.Height() > 0) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir if(WALLPAPER_SCALE == getWallpaperStyle()) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir // shortcut for scale; use simple BitmapPrimitive2D 59*cdf0e10cSrcweir basegfx::B2DHomMatrix aObjectTransform; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir aObjectTransform.set(0, 0, getLocalObjectRange().getWidth()); 62*cdf0e10cSrcweir aObjectTransform.set(1, 1, getLocalObjectRange().getHeight()); 63*cdf0e10cSrcweir aObjectTransform.set(0, 2, getLocalObjectRange().getMinX()); 64*cdf0e10cSrcweir aObjectTransform.set(1, 2, getLocalObjectRange().getMinY()); 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir Primitive2DReference xReference( 67*cdf0e10cSrcweir new BitmapPrimitive2D( 68*cdf0e10cSrcweir getBitmapEx(), 69*cdf0e10cSrcweir aObjectTransform)); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir aRetval = Primitive2DSequence(&xReference, 1); 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir else 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir // transform to logic size 76*cdf0e10cSrcweir basegfx::B2DHomMatrix aInverseViewTransformation(getViewTransformation()); 77*cdf0e10cSrcweir aInverseViewTransformation.invert(); 78*cdf0e10cSrcweir basegfx::B2DVector aLogicSize(rPixelSize.Width(), rPixelSize.Height()); 79*cdf0e10cSrcweir aLogicSize = aInverseViewTransformation * aLogicSize; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // apply laout 82*cdf0e10cSrcweir basegfx::B2DPoint aTargetTopLeft(getLocalObjectRange().getMinimum()); 83*cdf0e10cSrcweir bool bUseTargetTopLeft(true); 84*cdf0e10cSrcweir bool bNeedsClipping(false); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir switch(getWallpaperStyle()) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir default: //case WALLPAPER_TILE :, also WALLPAPER_NULL and WALLPAPER_APPLICATIONGRADIENT 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir bUseTargetTopLeft = false; 91*cdf0e10cSrcweir break; 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir case WALLPAPER_SCALE : 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir // handled by shortcut above 96*cdf0e10cSrcweir break; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir case WALLPAPER_TOPLEFT : 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir // nothing to do 101*cdf0e10cSrcweir break; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir case WALLPAPER_TOP : 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter()); 106*cdf0e10cSrcweir aTargetTopLeft.setX(aCenter.getX() - (aLogicSize.getX() * 0.5)); 107*cdf0e10cSrcweir break; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir case WALLPAPER_TOPRIGHT : 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir aTargetTopLeft.setX(getLocalObjectRange().getMaxX() - aLogicSize.getX()); 112*cdf0e10cSrcweir break; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir case WALLPAPER_LEFT : 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter()); 117*cdf0e10cSrcweir aTargetTopLeft.setY(aCenter.getY() - (aLogicSize.getY() * 0.5)); 118*cdf0e10cSrcweir break; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir case WALLPAPER_CENTER : 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter()); 123*cdf0e10cSrcweir aTargetTopLeft = aCenter - (aLogicSize * 0.5); 124*cdf0e10cSrcweir break; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir case WALLPAPER_RIGHT : 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter()); 129*cdf0e10cSrcweir aTargetTopLeft.setX(getLocalObjectRange().getMaxX() - aLogicSize.getX()); 130*cdf0e10cSrcweir aTargetTopLeft.setY(aCenter.getY() - (aLogicSize.getY() * 0.5)); 131*cdf0e10cSrcweir break; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir case WALLPAPER_BOTTOMLEFT : 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir aTargetTopLeft.setY(getLocalObjectRange().getMaxY() - aLogicSize.getY()); 136*cdf0e10cSrcweir break; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir case WALLPAPER_BOTTOM : 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter()); 141*cdf0e10cSrcweir aTargetTopLeft.setX(aCenter.getX() - (aLogicSize.getX() * 0.5)); 142*cdf0e10cSrcweir aTargetTopLeft.setY(getLocalObjectRange().getMaxY() - aLogicSize.getY()); 143*cdf0e10cSrcweir break; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir case WALLPAPER_BOTTOMRIGHT : 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir aTargetTopLeft = getLocalObjectRange().getMaximum() - aLogicSize; 148*cdf0e10cSrcweir break; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir if(bUseTargetTopLeft) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir // fill target range 155*cdf0e10cSrcweir const basegfx::B2DRange aTargetRange(aTargetTopLeft, aTargetTopLeft + aLogicSize); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // create aligned, single BitmapPrimitive2D 158*cdf0e10cSrcweir basegfx::B2DHomMatrix aObjectTransform; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir aObjectTransform.set(0, 0, aTargetRange.getWidth()); 161*cdf0e10cSrcweir aObjectTransform.set(1, 1, aTargetRange.getHeight()); 162*cdf0e10cSrcweir aObjectTransform.set(0, 2, aTargetRange.getMinX()); 163*cdf0e10cSrcweir aObjectTransform.set(1, 2, aTargetRange.getMinY()); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir Primitive2DReference xReference( 166*cdf0e10cSrcweir new BitmapPrimitive2D( 167*cdf0e10cSrcweir getBitmapEx(), 168*cdf0e10cSrcweir aObjectTransform)); 169*cdf0e10cSrcweir aRetval = Primitive2DSequence(&xReference, 1); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir // clip when not completely inside object range 172*cdf0e10cSrcweir bNeedsClipping = !getLocalObjectRange().isInside(aTargetRange); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir else 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir // WALLPAPER_TILE, WALLPAPER_NULL, WALLPAPER_APPLICATIONGRADIENT 177*cdf0e10cSrcweir // convert to relative positions 178*cdf0e10cSrcweir const basegfx::B2DVector aRelativeSize( 179*cdf0e10cSrcweir aLogicSize.getX() / (getLocalObjectRange().getWidth() ? getLocalObjectRange().getWidth() : 1.0), 180*cdf0e10cSrcweir aLogicSize.getY() / (getLocalObjectRange().getHeight() ? getLocalObjectRange().getHeight() : 1.0)); 181*cdf0e10cSrcweir basegfx::B2DPoint aRelativeTopLeft(0.0, 0.0); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir if(WALLPAPER_TILE != getWallpaperStyle()) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir aRelativeTopLeft.setX(0.5 - aRelativeSize.getX()); 186*cdf0e10cSrcweir aRelativeTopLeft.setY(0.5 - aRelativeSize.getY()); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // prepare FillBitmapAttribute 190*cdf0e10cSrcweir const attribute::FillBitmapAttribute aFillBitmapAttribute( 191*cdf0e10cSrcweir getBitmapEx(), 192*cdf0e10cSrcweir aRelativeTopLeft, 193*cdf0e10cSrcweir aRelativeSize, 194*cdf0e10cSrcweir true); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir // create ObjectTransform 197*cdf0e10cSrcweir basegfx::B2DHomMatrix aObjectTransform; 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir aObjectTransform.set(0, 0, getLocalObjectRange().getWidth()); 200*cdf0e10cSrcweir aObjectTransform.set(1, 1, getLocalObjectRange().getHeight()); 201*cdf0e10cSrcweir aObjectTransform.set(0, 2, getLocalObjectRange().getMinX()); 202*cdf0e10cSrcweir aObjectTransform.set(1, 2, getLocalObjectRange().getMinY()); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir // create FillBitmapPrimitive 205*cdf0e10cSrcweir const drawinglayer::primitive2d::Primitive2DReference xFillBitmap( 206*cdf0e10cSrcweir new drawinglayer::primitive2d::FillBitmapPrimitive2D( 207*cdf0e10cSrcweir aObjectTransform, 208*cdf0e10cSrcweir aFillBitmapAttribute)); 209*cdf0e10cSrcweir aRetval = Primitive2DSequence(&xFillBitmap, 1); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir // always embed tiled fill to clipping 212*cdf0e10cSrcweir bNeedsClipping = true; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir if(bNeedsClipping) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir // embed to clipping; this is necessary for tiled fills 218*cdf0e10cSrcweir const basegfx::B2DPolyPolygon aPolyPolygon( 219*cdf0e10cSrcweir basegfx::tools::createPolygonFromRect(getLocalObjectRange())); 220*cdf0e10cSrcweir const drawinglayer::primitive2d::Primitive2DReference xClippedFill( 221*cdf0e10cSrcweir new drawinglayer::primitive2d::MaskPrimitive2D( 222*cdf0e10cSrcweir aPolyPolygon, 223*cdf0e10cSrcweir aRetval)); 224*cdf0e10cSrcweir aRetval = Primitive2DSequence(&xClippedFill, 1); 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir return aRetval; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir WallpaperBitmapPrimitive2D::WallpaperBitmapPrimitive2D( 234*cdf0e10cSrcweir const basegfx::B2DRange& rObjectRange, 235*cdf0e10cSrcweir const BitmapEx& rBitmapEx, 236*cdf0e10cSrcweir WallpaperStyle eWallpaperStyle) 237*cdf0e10cSrcweir : ViewTransformationDependentPrimitive2D(), 238*cdf0e10cSrcweir maObjectRange(rObjectRange), 239*cdf0e10cSrcweir maBitmapEx(rBitmapEx), 240*cdf0e10cSrcweir meWallpaperStyle(eWallpaperStyle) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir bool WallpaperBitmapPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir if(ViewTransformationDependentPrimitive2D::operator==(rPrimitive)) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir const WallpaperBitmapPrimitive2D& rCompare = (WallpaperBitmapPrimitive2D&)rPrimitive; 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir return (getLocalObjectRange() == rCompare.getLocalObjectRange() 251*cdf0e10cSrcweir && getBitmapEx() == rCompare.getBitmapEx() 252*cdf0e10cSrcweir && getWallpaperStyle() == rCompare.getWallpaperStyle()); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir return false; 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir basegfx::B2DRange WallpaperBitmapPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir return getLocalObjectRange(); 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir // provide unique ID 264*cdf0e10cSrcweir ImplPrimitrive2DIDBlock(WallpaperBitmapPrimitive2D, PRIMITIVE2D_ID_WALLPAPERBITMAPPRIMITIVE2D) 265*cdf0e10cSrcweir } // end of namespace primitive2d 266*cdf0e10cSrcweir } // end of namespace drawinglayer 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 269*cdf0e10cSrcweir // eof 270