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/texteffectprimitive2d.hxx> 32*cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation2d.hxx> 33*cdf0e10cSrcweir #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx> 34*cdf0e10cSrcweir #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 35*cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 36*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir namespace drawinglayer 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir namespace primitive2d 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir static double fDiscreteSize(1.1); 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir Primitive2DSequence TextEffectPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir Primitive2DSequence aRetval; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir // get the distance of one discrete units from target display. Use between 1.0 and sqrt(2) to 51*cdf0e10cSrcweir // have good results on rotated objects, too 52*cdf0e10cSrcweir const basegfx::B2DVector aDistance(rViewInformation.getInverseObjectToViewTransformation() * 53*cdf0e10cSrcweir basegfx::B2DVector(fDiscreteSize, fDiscreteSize)); 54*cdf0e10cSrcweir const basegfx::B2DVector aDiagonalDistance(aDistance * (1.0 / 1.44)); 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir switch(getTextEffectStyle2D()) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir case TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED: 59*cdf0e10cSrcweir case TEXTEFFECTSTYLE2D_RELIEF_ENGRAVED: 60*cdf0e10cSrcweir case TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED_DEFAULT: 61*cdf0e10cSrcweir case TEXTEFFECTSTYLE2D_RELIEF_ENGRAVED_DEFAULT: 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir // prepare transform of sub-group back to (0,0) and align to X-Axis 64*cdf0e10cSrcweir basegfx::B2DHomMatrix aBackTransform(basegfx::tools::createTranslateB2DHomMatrix( 65*cdf0e10cSrcweir -getRotationCenter().getX(), -getRotationCenter().getY())); 66*cdf0e10cSrcweir aBackTransform.rotate(-getDirection()); 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir // prepare transform of sub-group back to it's position and rotation 69*cdf0e10cSrcweir basegfx::B2DHomMatrix aForwardTransform(basegfx::tools::createRotateB2DHomMatrix(getDirection())); 70*cdf0e10cSrcweir aForwardTransform.translate(getRotationCenter().getX(), getRotationCenter().getY()); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir // create transformation for one discrete unit 73*cdf0e10cSrcweir const bool bEmbossed( 74*cdf0e10cSrcweir TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED == getTextEffectStyle2D() 75*cdf0e10cSrcweir || TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED_DEFAULT == getTextEffectStyle2D()); 76*cdf0e10cSrcweir const bool bDefaultTextColor( 77*cdf0e10cSrcweir TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED_DEFAULT == getTextEffectStyle2D() 78*cdf0e10cSrcweir || TEXTEFFECTSTYLE2D_RELIEF_ENGRAVED_DEFAULT == getTextEffectStyle2D()); 79*cdf0e10cSrcweir basegfx::B2DHomMatrix aTransform(aBackTransform); 80*cdf0e10cSrcweir aRetval.realloc(2); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir if(bEmbossed) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir // to bottom-right 85*cdf0e10cSrcweir aTransform.translate(aDiagonalDistance.getX(), aDiagonalDistance.getY()); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir else 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir // to top-left 90*cdf0e10cSrcweir aTransform.translate(-aDiagonalDistance.getX(), -aDiagonalDistance.getY()); 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir aTransform *= aForwardTransform; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir if(bDefaultTextColor) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir // emboss/engrave in black, original forced to white 98*cdf0e10cSrcweir const basegfx::BColorModifier aBColorModifierToGray(basegfx::BColor(0.0)); 99*cdf0e10cSrcweir const Primitive2DReference xModifiedColor(new ModifiedColorPrimitive2D(getTextContent(), aBColorModifierToGray)); 100*cdf0e10cSrcweir aRetval[0] = Primitive2DReference(new TransformPrimitive2D(aTransform, Primitive2DSequence(&xModifiedColor, 1))); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir // add original, too 103*cdf0e10cSrcweir const basegfx::BColorModifier aBColorModifierToWhite(basegfx::BColor(1.0)); 104*cdf0e10cSrcweir aRetval[1] = Primitive2DReference(new ModifiedColorPrimitive2D(getTextContent(), aBColorModifierToWhite)); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir else 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir // emboss/engrave in gray, keep original's color 109*cdf0e10cSrcweir const basegfx::BColorModifier aBColorModifierToGray(basegfx::BColor(0.75)); // 192 110*cdf0e10cSrcweir const Primitive2DReference xModifiedColor(new ModifiedColorPrimitive2D(getTextContent(), aBColorModifierToGray)); 111*cdf0e10cSrcweir aRetval[0] = Primitive2DReference(new TransformPrimitive2D(aTransform, Primitive2DSequence(&xModifiedColor, 1))); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // add original, too 114*cdf0e10cSrcweir aRetval[1] = Primitive2DReference(new GroupPrimitive2D(getTextContent())); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir break; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir case TEXTEFFECTSTYLE2D_OUTLINE: 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir // create transform primitives in all directions 122*cdf0e10cSrcweir basegfx::B2DHomMatrix aTransform; 123*cdf0e10cSrcweir aRetval.realloc(9); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir aTransform.set(0, 2, aDistance.getX()); 126*cdf0e10cSrcweir aTransform.set(1, 2, 0.0); 127*cdf0e10cSrcweir aRetval[0] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent())); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir aTransform.set(0, 2, aDiagonalDistance.getX()); 130*cdf0e10cSrcweir aTransform.set(1, 2, aDiagonalDistance.getY()); 131*cdf0e10cSrcweir aRetval[1] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent())); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir aTransform.set(0, 2, 0.0); 134*cdf0e10cSrcweir aTransform.set(1, 2, aDistance.getY()); 135*cdf0e10cSrcweir aRetval[2] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent())); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir aTransform.set(0, 2, -aDiagonalDistance.getX()); 138*cdf0e10cSrcweir aTransform.set(1, 2, aDiagonalDistance.getY()); 139*cdf0e10cSrcweir aRetval[3] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent())); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir aTransform.set(0, 2, -aDistance.getX()); 142*cdf0e10cSrcweir aTransform.set(1, 2, 0.0); 143*cdf0e10cSrcweir aRetval[4] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent())); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir aTransform.set(0, 2, -aDiagonalDistance.getX()); 146*cdf0e10cSrcweir aTransform.set(1, 2, -aDiagonalDistance.getY()); 147*cdf0e10cSrcweir aRetval[5] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent())); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir aTransform.set(0, 2, 0.0); 150*cdf0e10cSrcweir aTransform.set(1, 2, -aDistance.getY()); 151*cdf0e10cSrcweir aRetval[6] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent())); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir aTransform.set(0, 2, aDiagonalDistance.getX()); 154*cdf0e10cSrcweir aTransform.set(1, 2, -aDiagonalDistance.getY()); 155*cdf0e10cSrcweir aRetval[7] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent())); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // at last, place original over it, but force to white 158*cdf0e10cSrcweir const basegfx::BColorModifier aBColorModifierToWhite(basegfx::BColor(1.0, 1.0, 1.0)); 159*cdf0e10cSrcweir aRetval[8] = Primitive2DReference(new ModifiedColorPrimitive2D(getTextContent(), aBColorModifierToWhite)); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir break; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir return aRetval; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir TextEffectPrimitive2D::TextEffectPrimitive2D( 169*cdf0e10cSrcweir const Primitive2DSequence& rTextContent, 170*cdf0e10cSrcweir const basegfx::B2DPoint& rRotationCenter, 171*cdf0e10cSrcweir double fDirection, 172*cdf0e10cSrcweir TextEffectStyle2D eTextEffectStyle2D) 173*cdf0e10cSrcweir : BufferedDecompositionPrimitive2D(), 174*cdf0e10cSrcweir maTextContent(rTextContent), 175*cdf0e10cSrcweir maRotationCenter(rRotationCenter), 176*cdf0e10cSrcweir mfDirection(fDirection), 177*cdf0e10cSrcweir meTextEffectStyle2D(eTextEffectStyle2D) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir bool TextEffectPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir if(BasePrimitive2D::operator==(rPrimitive)) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir const TextEffectPrimitive2D& rCompare = (TextEffectPrimitive2D&)rPrimitive; 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir return (getTextContent() == rCompare.getTextContent() 188*cdf0e10cSrcweir && getRotationCenter() == rCompare.getRotationCenter() 189*cdf0e10cSrcweir && getDirection() == rCompare.getDirection() 190*cdf0e10cSrcweir && getTextEffectStyle2D() == rCompare.getTextEffectStyle2D()); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir return false; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir basegfx::B2DRange TextEffectPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir // get range of content and grow by used fDiscreteSize. That way it is not necessary to ask 199*cdf0e10cSrcweir // the whole decomposition for it's ranges (which may be expensive with outline mode which 200*cdf0e10cSrcweir // then will ask 9 times at nearly the same content. This may even be refined here using the 201*cdf0e10cSrcweir // TextEffectStyle information, e.g. for TEXTEFFECTSTYLE2D_RELIEF the grow needs only to 202*cdf0e10cSrcweir // be in two directions 203*cdf0e10cSrcweir basegfx::B2DRange aRetval(getB2DRangeFromPrimitive2DSequence(getTextContent(), rViewInformation)); 204*cdf0e10cSrcweir aRetval.grow(fDiscreteSize); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir return aRetval; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir Primitive2DSequence TextEffectPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir if(getBuffered2DDecomposition().hasElements()) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir if(maLastObjectToViewTransformation != rViewInformation.getObjectToViewTransformation()) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir // conditions of last local decomposition have changed, delete 218*cdf0e10cSrcweir const_cast< TextEffectPrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DSequence()); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir if(!getBuffered2DDecomposition().hasElements()) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir // remember ViewRange and ViewTransformation 225*cdf0e10cSrcweir const_cast< TextEffectPrimitive2D* >(this)->maLastObjectToViewTransformation = rViewInformation.getObjectToViewTransformation(); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir // use parent implementation 229*cdf0e10cSrcweir return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation); 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir // provide unique ID 233*cdf0e10cSrcweir ImplPrimitrive2DIDBlock(TextEffectPrimitive2D, PRIMITIVE2D_ID_TEXTEFFECTPRIMITIVE2D) 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir } // end of namespace primitive2d 236*cdf0e10cSrcweir } // end of namespace drawinglayer 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 239*cdf0e10cSrcweir // eof 240