update dev300-m58
[ooovba.git] / drawinglayer / source / primitive2d / texteffectprimitive2d.cxx
blob6c5952e6aa939994cf5f785765891ca6623bd36e
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: texteffectprimitive2d.cxx,v $
7 * $Revision: 1.4 $
9 * last change: $Author: aw $ $Date: 2008-06-24 15:31:08 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/primitive2d/texteffectprimitive2d.hxx>
40 #include <drawinglayer/geometry/viewinformation2d.hxx>
41 #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
42 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
43 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
45 //////////////////////////////////////////////////////////////////////////////
47 namespace drawinglayer
49 namespace primitive2d
51 static double fDiscreteSize(1.1);
53 Primitive2DSequence TextEffectPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& rViewInformation) const
55 Primitive2DSequence aRetval;
57 // get the distance of one discrete units from target display. Use between 1.0 and sqrt(2) to
58 // have good results on rotated objects, too
59 const basegfx::B2DVector aDistance(rViewInformation.getInverseObjectToViewTransformation() *
60 basegfx::B2DVector(fDiscreteSize, fDiscreteSize));
61 const basegfx::B2DVector aDiagonalDistance(aDistance * (1.0 / 1.44));
63 switch(getTextEffectStyle2D())
65 case TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED:
66 case TEXTEFFECTSTYLE2D_RELIEF_ENGRAVED:
67 case TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED_DEFAULT:
68 case TEXTEFFECTSTYLE2D_RELIEF_ENGRAVED_DEFAULT:
70 // prepare transform of sub-group back to (0,0) and align to X-Axis
71 basegfx::B2DHomMatrix aBackTransform;
72 aBackTransform.translate(-getRotationCenter().getX(), -getRotationCenter().getY());
73 aBackTransform.rotate(-getDirection());
75 // prepare transform of sub-group back to it's position and rotation
76 basegfx::B2DHomMatrix aForwardTransform;
77 aForwardTransform.rotate(getDirection());
78 aForwardTransform.translate(getRotationCenter().getX(), getRotationCenter().getY());
80 // create transformation for one discrete unit
81 const bool bEmbossed(
82 TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED == getTextEffectStyle2D()
83 || TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED_DEFAULT == getTextEffectStyle2D());
84 const bool bDefaultTextColor(
85 TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED_DEFAULT == getTextEffectStyle2D()
86 || TEXTEFFECTSTYLE2D_RELIEF_ENGRAVED_DEFAULT == getTextEffectStyle2D());
87 basegfx::B2DHomMatrix aTransform(aBackTransform);
88 aRetval.realloc(2);
90 if(bEmbossed)
92 // to bottom-right
93 aTransform.translate(aDiagonalDistance.getX(), aDiagonalDistance.getY());
95 else
97 // to top-left
98 aTransform.translate(-aDiagonalDistance.getX(), -aDiagonalDistance.getY());
101 aTransform *= aForwardTransform;
103 if(bDefaultTextColor)
105 // emboss/engrave in black, original forced to white
106 const basegfx::BColorModifier aBColorModifierToGray(basegfx::BColor(0.0));
107 const Primitive2DReference xModifiedColor(new ModifiedColorPrimitive2D(getChildren(), aBColorModifierToGray));
108 aRetval[0] = Primitive2DReference(new TransformPrimitive2D(aTransform, Primitive2DSequence(&xModifiedColor, 1)));
110 // add original, too
111 const basegfx::BColorModifier aBColorModifierToWhite(basegfx::BColor(1.0));
112 aRetval[1] = Primitive2DReference(new ModifiedColorPrimitive2D(getChildren(), aBColorModifierToWhite));
114 else
116 // emboss/engrave in gray, keep original's color
117 const basegfx::BColorModifier aBColorModifierToGray(basegfx::BColor(0.75)); // 192
118 const Primitive2DReference xModifiedColor(new ModifiedColorPrimitive2D(getChildren(), aBColorModifierToGray));
119 aRetval[0] = Primitive2DReference(new TransformPrimitive2D(aTransform, Primitive2DSequence(&xModifiedColor, 1)));
121 // add original, too
122 aRetval[1] = Primitive2DReference(new GroupPrimitive2D(getChildren()));
125 break;
127 case TEXTEFFECTSTYLE2D_OUTLINE:
129 // create transform primitives in all directions
130 basegfx::B2DHomMatrix aTransform;
131 aRetval.realloc(9);
133 aTransform.set(0, 2, aDistance.getX());
134 aTransform.set(1, 2, 0.0);
135 aRetval[0] = Primitive2DReference(new TransformPrimitive2D(aTransform, getChildren()));
137 aTransform.set(0, 2, aDiagonalDistance.getX());
138 aTransform.set(1, 2, aDiagonalDistance.getY());
139 aRetval[1] = Primitive2DReference(new TransformPrimitive2D(aTransform, getChildren()));
141 aTransform.set(0, 2, 0.0);
142 aTransform.set(1, 2, aDistance.getY());
143 aRetval[2] = Primitive2DReference(new TransformPrimitive2D(aTransform, getChildren()));
145 aTransform.set(0, 2, -aDiagonalDistance.getX());
146 aTransform.set(1, 2, aDiagonalDistance.getY());
147 aRetval[3] = Primitive2DReference(new TransformPrimitive2D(aTransform, getChildren()));
149 aTransform.set(0, 2, -aDistance.getX());
150 aTransform.set(1, 2, 0.0);
151 aRetval[4] = Primitive2DReference(new TransformPrimitive2D(aTransform, getChildren()));
153 aTransform.set(0, 2, -aDiagonalDistance.getX());
154 aTransform.set(1, 2, -aDiagonalDistance.getY());
155 aRetval[5] = Primitive2DReference(new TransformPrimitive2D(aTransform, getChildren()));
157 aTransform.set(0, 2, 0.0);
158 aTransform.set(1, 2, -aDistance.getY());
159 aRetval[6] = Primitive2DReference(new TransformPrimitive2D(aTransform, getChildren()));
161 aTransform.set(0, 2, aDiagonalDistance.getX());
162 aTransform.set(1, 2, -aDiagonalDistance.getY());
163 aRetval[7] = Primitive2DReference(new TransformPrimitive2D(aTransform, getChildren()));
165 // at last, place original over it, but force to white
166 const basegfx::BColorModifier aBColorModifierToWhite(basegfx::BColor(1.0, 1.0, 1.0));
167 aRetval[8] = Primitive2DReference(new ModifiedColorPrimitive2D(getChildren(), aBColorModifierToWhite));
169 break;
173 return aRetval;
176 TextEffectPrimitive2D::TextEffectPrimitive2D(
177 const Primitive2DSequence& rChildren,
178 const basegfx::B2DPoint& rRotationCenter,
179 double fDirection,
180 TextEffectStyle2D eTextEffectStyle2D)
181 : GroupPrimitive2D(rChildren),
182 maRotationCenter(rRotationCenter),
183 mfDirection(fDirection),
184 meTextEffectStyle2D(eTextEffectStyle2D)
188 bool TextEffectPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
190 if(GroupPrimitive2D::operator==(rPrimitive))
192 const TextEffectPrimitive2D& rCompare = (TextEffectPrimitive2D&)rPrimitive;
194 return (getRotationCenter() == rCompare.getRotationCenter()
195 && getDirection() == rCompare.getDirection()
196 && getTextEffectStyle2D() == rCompare.getTextEffectStyle2D());
199 return false;
202 basegfx::B2DRange TextEffectPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
204 // get range of content and grow by used fDiscreteSize. That way it is not necessary to ask
205 // the whole decomposition for it's ranges (which may be expensive with outline mode which
206 // then will ask 9 times at nearly the same content. This may even be refined here using the
207 // TextEffectStyle information, e.g. for TEXTEFFECTSTYLE2D_RELIEF the grow needs only to
208 // be in two directions
209 basegfx::B2DRange aRetval(getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation));
210 aRetval.grow(fDiscreteSize);
212 return aRetval;
215 Primitive2DSequence TextEffectPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
217 ::osl::MutexGuard aGuard( m_aMutex );
219 if(getLocalDecomposition().hasElements())
221 if(maLastObjectToViewTransformation != rViewInformation.getObjectToViewTransformation())
223 // conditions of last local decomposition have changed, delete
224 const_cast< TextEffectPrimitive2D* >(this)->setLocalDecomposition(Primitive2DSequence());
228 if(!getLocalDecomposition().hasElements())
230 // remember ViewRange and ViewTransformation
231 const_cast< TextEffectPrimitive2D* >(this)->maLastObjectToViewTransformation = rViewInformation.getObjectToViewTransformation();
234 // use parent implementation
235 return BasePrimitive2D::get2DDecomposition(rViewInformation);
238 // provide unique ID
239 ImplPrimitrive2DIDBlock(TextEffectPrimitive2D, PRIMITIVE2D_ID_TEXTEFFECTPRIMITIVE2D)
241 } // end of namespace primitive2d
242 } // end of namespace drawinglayer
244 //////////////////////////////////////////////////////////////////////////////
245 // eof