1464702f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3464702f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4464702f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5464702f4SAndrew Rist  * distributed with this work for additional information
6464702f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7464702f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8464702f4SAndrew Rist  * "License"); you may not use this file except in compliance
9464702f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10464702f4SAndrew Rist  *
11464702f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12464702f4SAndrew Rist  *
13464702f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14464702f4SAndrew Rist  * software distributed under the License is distributed on an
15464702f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16464702f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17464702f4SAndrew Rist  * specific language governing permissions and limitations
18464702f4SAndrew Rist  * under the License.
19464702f4SAndrew Rist  *
20464702f4SAndrew Rist  *************************************************************/
21464702f4SAndrew Rist 
22464702f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <drawinglayer/primitive2d/texteffectprimitive2d.hxx>
28cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation2d.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
30cdf0e10cSrcweir #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
31cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
32cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace drawinglayer
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	namespace primitive2d
39cdf0e10cSrcweir 	{
40cdf0e10cSrcweir 		static double fDiscreteSize(1.1);
41cdf0e10cSrcweir 
create2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const42cdf0e10cSrcweir 		Primitive2DSequence TextEffectPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
43cdf0e10cSrcweir 		{
44cdf0e10cSrcweir 			Primitive2DSequence aRetval;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 			// get the distance of one discrete units from target display. Use between 1.0 and sqrt(2) to
47cdf0e10cSrcweir 			// have good results on rotated objects, too
48cdf0e10cSrcweir 			const basegfx::B2DVector aDistance(rViewInformation.getInverseObjectToViewTransformation() *
49cdf0e10cSrcweir                 basegfx::B2DVector(fDiscreteSize, fDiscreteSize));
50cdf0e10cSrcweir 			const basegfx::B2DVector aDiagonalDistance(aDistance * (1.0 / 1.44));
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 			switch(getTextEffectStyle2D())
53cdf0e10cSrcweir 			{
54cdf0e10cSrcweir 				case TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED:
55cdf0e10cSrcweir 				case TEXTEFFECTSTYLE2D_RELIEF_ENGRAVED:
56cdf0e10cSrcweir 				case TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED_DEFAULT:
57cdf0e10cSrcweir 				case TEXTEFFECTSTYLE2D_RELIEF_ENGRAVED_DEFAULT:
58cdf0e10cSrcweir 				{
59cdf0e10cSrcweir 					// prepare transform of sub-group back to (0,0) and align to X-Axis
60cdf0e10cSrcweir                     basegfx::B2DHomMatrix aBackTransform(basegfx::tools::createTranslateB2DHomMatrix(
61cdf0e10cSrcweir                         -getRotationCenter().getX(), -getRotationCenter().getY()));
62cdf0e10cSrcweir 					aBackTransform.rotate(-getDirection());
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 					// prepare transform of sub-group back to it's position and rotation
65cdf0e10cSrcweir                     basegfx::B2DHomMatrix aForwardTransform(basegfx::tools::createRotateB2DHomMatrix(getDirection()));
66cdf0e10cSrcweir 					aForwardTransform.translate(getRotationCenter().getX(), getRotationCenter().getY());
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 					// create transformation for one discrete unit
69cdf0e10cSrcweir 					const bool bEmbossed(
70cdf0e10cSrcweir 						TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED  == getTextEffectStyle2D()
71cdf0e10cSrcweir 						|| TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED_DEFAULT == getTextEffectStyle2D());
72cdf0e10cSrcweir 					const bool bDefaultTextColor(
73cdf0e10cSrcweir 						TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED_DEFAULT == getTextEffectStyle2D()
74cdf0e10cSrcweir 						|| TEXTEFFECTSTYLE2D_RELIEF_ENGRAVED_DEFAULT == getTextEffectStyle2D());
75cdf0e10cSrcweir 					basegfx::B2DHomMatrix aTransform(aBackTransform);
76cdf0e10cSrcweir 					aRetval.realloc(2);
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 					if(bEmbossed)
79cdf0e10cSrcweir 					{
80cdf0e10cSrcweir 						// to bottom-right
81cdf0e10cSrcweir 						aTransform.translate(aDiagonalDistance.getX(), aDiagonalDistance.getY());
82cdf0e10cSrcweir 					}
83cdf0e10cSrcweir 					else
84cdf0e10cSrcweir 					{
85cdf0e10cSrcweir 						// to top-left
86cdf0e10cSrcweir 						aTransform.translate(-aDiagonalDistance.getX(), -aDiagonalDistance.getY());
87cdf0e10cSrcweir 					}
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 					aTransform *= aForwardTransform;
90cdf0e10cSrcweir 
91*49c58f9bSArmin Le Grand                     if(bDefaultTextColor)
92*49c58f9bSArmin Le Grand                     {
93*49c58f9bSArmin Le Grand                         // emboss/engrave in black, original forced to white
94*49c58f9bSArmin Le Grand                         const basegfx::BColorModifierSharedPtr aBColorModifierToGray(
95*49c58f9bSArmin Le Grand                             new basegfx::BColorModifier_replace(
96*49c58f9bSArmin Le Grand                                 basegfx::BColor(0.0)));
97*49c58f9bSArmin Le Grand                         const Primitive2DReference xModifiedColor(
98*49c58f9bSArmin Le Grand                             new ModifiedColorPrimitive2D(
99*49c58f9bSArmin Le Grand                                 getTextContent(),
100*49c58f9bSArmin Le Grand                                 aBColorModifierToGray));
101*49c58f9bSArmin Le Grand 
102*49c58f9bSArmin Le Grand                         aRetval[0] = Primitive2DReference(
103*49c58f9bSArmin Le Grand                             new TransformPrimitive2D(
104*49c58f9bSArmin Le Grand                                 aTransform,
105*49c58f9bSArmin Le Grand                                 Primitive2DSequence(&xModifiedColor, 1)));
106*49c58f9bSArmin Le Grand 
107*49c58f9bSArmin Le Grand                         // add original, too
108*49c58f9bSArmin Le Grand                         const basegfx::BColorModifierSharedPtr aBColorModifierToWhite(
109*49c58f9bSArmin Le Grand                             new basegfx::BColorModifier_replace(
110*49c58f9bSArmin Le Grand                                 basegfx::BColor(1.0)));
111*49c58f9bSArmin Le Grand 
112*49c58f9bSArmin Le Grand                         aRetval[1] = Primitive2DReference(
113*49c58f9bSArmin Le Grand                             new ModifiedColorPrimitive2D(
114*49c58f9bSArmin Le Grand                                 getTextContent(),
115*49c58f9bSArmin Le Grand                                 aBColorModifierToWhite));
116*49c58f9bSArmin Le Grand                     }
117*49c58f9bSArmin Le Grand                     else
118*49c58f9bSArmin Le Grand                     {
119*49c58f9bSArmin Le Grand                         // emboss/engrave in gray, keep original's color
120*49c58f9bSArmin Le Grand                         const basegfx::BColorModifierSharedPtr aBColorModifierToGray(
121*49c58f9bSArmin Le Grand                             new basegfx::BColorModifier_replace(
122*49c58f9bSArmin Le Grand                                 basegfx::BColor(0.75))); // 192
123*49c58f9bSArmin Le Grand                         const Primitive2DReference xModifiedColor(
124*49c58f9bSArmin Le Grand                             new ModifiedColorPrimitive2D(
125*49c58f9bSArmin Le Grand                                 getTextContent(),
126*49c58f9bSArmin Le Grand                                 aBColorModifierToGray));
127*49c58f9bSArmin Le Grand 
128*49c58f9bSArmin Le Grand                         aRetval[0] = Primitive2DReference(
129*49c58f9bSArmin Le Grand                             new TransformPrimitive2D(
130*49c58f9bSArmin Le Grand                                 aTransform,
131*49c58f9bSArmin Le Grand                                 Primitive2DSequence(&xModifiedColor, 1)));
132*49c58f9bSArmin Le Grand 
133*49c58f9bSArmin Le Grand                         // add original, too
134*49c58f9bSArmin Le Grand                         aRetval[1] = Primitive2DReference(new GroupPrimitive2D(getTextContent()));
135*49c58f9bSArmin Le Grand                     }
136*49c58f9bSArmin Le Grand 
137*49c58f9bSArmin Le Grand                     break;
138cdf0e10cSrcweir 				}
139cdf0e10cSrcweir 				case TEXTEFFECTSTYLE2D_OUTLINE:
140cdf0e10cSrcweir 				{
141cdf0e10cSrcweir 					// create transform primitives in all directions
142cdf0e10cSrcweir 					basegfx::B2DHomMatrix aTransform;
143cdf0e10cSrcweir 					aRetval.realloc(9);
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 					aTransform.set(0, 2, aDistance.getX());
146cdf0e10cSrcweir 					aTransform.set(1, 2, 0.0);
147cdf0e10cSrcweir 					aRetval[0] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent()));
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 					aTransform.set(0, 2, aDiagonalDistance.getX());
150cdf0e10cSrcweir 					aTransform.set(1, 2, aDiagonalDistance.getY());
151cdf0e10cSrcweir 					aRetval[1] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent()));
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 					aTransform.set(0, 2, 0.0);
154cdf0e10cSrcweir 					aTransform.set(1, 2, aDistance.getY());
155cdf0e10cSrcweir 					aRetval[2] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent()));
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 					aTransform.set(0, 2, -aDiagonalDistance.getX());
158cdf0e10cSrcweir 					aTransform.set(1, 2, aDiagonalDistance.getY());
159cdf0e10cSrcweir 					aRetval[3] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent()));
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 					aTransform.set(0, 2, -aDistance.getX());
162cdf0e10cSrcweir 					aTransform.set(1, 2, 0.0);
163cdf0e10cSrcweir 					aRetval[4] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent()));
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 					aTransform.set(0, 2, -aDiagonalDistance.getX());
166cdf0e10cSrcweir 					aTransform.set(1, 2, -aDiagonalDistance.getY());
167cdf0e10cSrcweir 					aRetval[5] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent()));
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 					aTransform.set(0, 2, 0.0);
170cdf0e10cSrcweir 					aTransform.set(1, 2, -aDistance.getY());
171cdf0e10cSrcweir 					aRetval[6] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent()));
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 					aTransform.set(0, 2, aDiagonalDistance.getX());
174cdf0e10cSrcweir 					aTransform.set(1, 2, -aDiagonalDistance.getY());
175cdf0e10cSrcweir 					aRetval[7] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent()));
176cdf0e10cSrcweir 
177*49c58f9bSArmin Le Grand                     // at last, place original over it, but force to white
178*49c58f9bSArmin Le Grand                     const basegfx::BColorModifierSharedPtr aBColorModifierToWhite(
179*49c58f9bSArmin Le Grand                         new basegfx::BColorModifier_replace(
180*49c58f9bSArmin Le Grand                             basegfx::BColor(1.0, 1.0, 1.0)));
181*49c58f9bSArmin Le Grand                     aRetval[8] = Primitive2DReference(
182*49c58f9bSArmin Le Grand                         new ModifiedColorPrimitive2D(
183*49c58f9bSArmin Le Grand                             getTextContent(),
184*49c58f9bSArmin Le Grand                             aBColorModifierToWhite));
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 					break;
187cdf0e10cSrcweir 				}
188cdf0e10cSrcweir 			}
189cdf0e10cSrcweir 
190cdf0e10cSrcweir             return aRetval;
191cdf0e10cSrcweir 		}
192cdf0e10cSrcweir 
TextEffectPrimitive2D(const Primitive2DSequence & rTextContent,const basegfx::B2DPoint & rRotationCenter,double fDirection,TextEffectStyle2D eTextEffectStyle2D)193cdf0e10cSrcweir 		TextEffectPrimitive2D::TextEffectPrimitive2D(
194cdf0e10cSrcweir             const Primitive2DSequence& rTextContent,
195cdf0e10cSrcweir 			const basegfx::B2DPoint& rRotationCenter,
196cdf0e10cSrcweir 			double fDirection,
197cdf0e10cSrcweir             TextEffectStyle2D eTextEffectStyle2D)
198cdf0e10cSrcweir 		:	BufferedDecompositionPrimitive2D(),
199cdf0e10cSrcweir             maTextContent(rTextContent),
200cdf0e10cSrcweir 			maRotationCenter(rRotationCenter),
201cdf0e10cSrcweir 			mfDirection(fDirection),
202cdf0e10cSrcweir             meTextEffectStyle2D(eTextEffectStyle2D)
203cdf0e10cSrcweir 		{
204cdf0e10cSrcweir 		}
205cdf0e10cSrcweir 
operator ==(const BasePrimitive2D & rPrimitive) const206cdf0e10cSrcweir 		bool TextEffectPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
207cdf0e10cSrcweir 		{
208cdf0e10cSrcweir 			if(BasePrimitive2D::operator==(rPrimitive))
209cdf0e10cSrcweir 			{
210cdf0e10cSrcweir 				const TextEffectPrimitive2D& rCompare = (TextEffectPrimitive2D&)rPrimitive;
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 				return (getTextContent() == rCompare.getTextContent()
213cdf0e10cSrcweir                     && getRotationCenter() == rCompare.getRotationCenter()
214cdf0e10cSrcweir 					&& getDirection() == rCompare.getDirection()
215cdf0e10cSrcweir 					&& getTextEffectStyle2D() == rCompare.getTextEffectStyle2D());
216cdf0e10cSrcweir 			}
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 			return false;
219cdf0e10cSrcweir 		}
220cdf0e10cSrcweir 
getB2DRange(const geometry::ViewInformation2D & rViewInformation) const221cdf0e10cSrcweir 		basegfx::B2DRange TextEffectPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
222cdf0e10cSrcweir 		{
223cdf0e10cSrcweir 			// get range of content and grow by used fDiscreteSize. That way it is not necessary to ask
224cdf0e10cSrcweir 			// the whole decomposition for it's ranges (which may be expensive with outline mode which
225cdf0e10cSrcweir 			// then will ask 9 times at nearly the same content. This may even be refined here using the
226cdf0e10cSrcweir 			// TextEffectStyle information, e.g. for TEXTEFFECTSTYLE2D_RELIEF the grow needs only to
227cdf0e10cSrcweir 			// be in two directions
228cdf0e10cSrcweir 			basegfx::B2DRange aRetval(getB2DRangeFromPrimitive2DSequence(getTextContent(), rViewInformation));
229cdf0e10cSrcweir 			aRetval.grow(fDiscreteSize);
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 			return aRetval;
232cdf0e10cSrcweir 		}
233cdf0e10cSrcweir 
get2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const234cdf0e10cSrcweir 		Primitive2DSequence TextEffectPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
235cdf0e10cSrcweir 		{
236cdf0e10cSrcweir 			::osl::MutexGuard aGuard( m_aMutex );
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 			if(getBuffered2DDecomposition().hasElements())
239cdf0e10cSrcweir 			{
240cdf0e10cSrcweir 				if(maLastObjectToViewTransformation != rViewInformation.getObjectToViewTransformation())
241cdf0e10cSrcweir 				{
242cdf0e10cSrcweir 					// conditions of last local decomposition have changed, delete
243cdf0e10cSrcweir 					const_cast< TextEffectPrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DSequence());
244cdf0e10cSrcweir 				}
245cdf0e10cSrcweir 			}
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 			if(!getBuffered2DDecomposition().hasElements())
248cdf0e10cSrcweir 			{
249cdf0e10cSrcweir 				// remember ViewRange and ViewTransformation
250cdf0e10cSrcweir 				const_cast< TextEffectPrimitive2D* >(this)->maLastObjectToViewTransformation = rViewInformation.getObjectToViewTransformation();
251cdf0e10cSrcweir 			}
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 			// use parent implementation
254cdf0e10cSrcweir 			return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation);
255cdf0e10cSrcweir 		}
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 		// provide unique ID
258cdf0e10cSrcweir 		ImplPrimitrive2DIDBlock(TextEffectPrimitive2D, PRIMITIVE2D_ID_TEXTEFFECTPRIMITIVE2D)
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 	} // end of namespace primitive2d
261cdf0e10cSrcweir } // end of namespace drawinglayer
262cdf0e10cSrcweir 
263cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
264cdf0e10cSrcweir // eof
265