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/wrongspellprimitive2d.hxx>
32 #include <basegfx/polygon/b2dpolygon.hxx>
33 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
34 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
35 #include <drawinglayer/geometry/viewinformation2d.hxx>
36 
37 //////////////////////////////////////////////////////////////////////////////
38 
39 namespace drawinglayer
40 {
41 	namespace primitive2d
42 	{
43 		Primitive2DSequence WrongSpellPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
44 		{
45             // ATM this decompose is view-independent, what the original VCL-Display is not. To mimic
46             // the old behaviour here if wanted it is necessary to add get2DDecomposition and implement
47             // it similar to the usage in e.g. HelplinePrimitive2D. Remembering the ViewTransformation
48             // should be enough then.
49             // The view-independent wavelines work well (if You ask me). Maybe the old VCL-Behaviour is only
50             // in place because it was not possible/too expensive at that time to scale the wavelines with the
51             // view...
52             // With the VCL-PixelRenderer this will not even be used since it implements WrongSpellPrimitive2D
53             // directly and mimics the old VCL-Display there. If You implemented a new renderer without
54             // direct WrongSpellPrimitive2D support, You may want to do the described change here.
55 
56             // get the font height (part of scale), so decompose the matrix
57 		    basegfx::B2DVector aScale, aTranslate;
58 		    double fRotate, fShearX;
59 		    getTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
60 
61             // calculate distances based on a static default (to allow testing in debugger)
62             static double fDefaultDistance(0.03);
63             const double fFontHeight(aScale.getY());
64             const double fUnderlineDistance(fFontHeight * fDefaultDistance);
65 		    const double fWaveWidth(2.0 * fUnderlineDistance);
66 
67             // the Y-distance needs to be relativated to FontHeight since the points get
68             // transformed with the transformation containing that scale already.
69             const double fRelativeUnderlineDistance(basegfx::fTools::equalZero(aScale.getY()) ? 0.0 : fUnderlineDistance / aScale.getY());
70             basegfx::B2DPoint aStart(getStart(), fRelativeUnderlineDistance);
71             basegfx::B2DPoint aStop(getStop(), fRelativeUnderlineDistance);
72             basegfx::B2DPolygon aPolygon;
73 
74             aPolygon.append(getTransformation() * aStart);
75             aPolygon.append(getTransformation() * aStop);
76 
77 			// prepare line attribute
78 			const attribute::LineAttribute aLineAttribute(getColor());
79 
80             // create the waveline primitive
81             Primitive2DReference xPrimitive(new PolygonWavePrimitive2D(aPolygon, aLineAttribute, fWaveWidth, 0.5 * fWaveWidth));
82             Primitive2DSequence xRetval(&xPrimitive, 1);
83 
84             return xRetval;
85 		}
86 
87 		WrongSpellPrimitive2D::WrongSpellPrimitive2D(
88 		    const basegfx::B2DHomMatrix& rTransformation,
89             double fStart,
90             double fStop,
91 		    const basegfx::BColor& rColor)
92 		:	BufferedDecompositionPrimitive2D(),
93 			maTransformation(rTransformation),
94             mfStart(fStart),
95             mfStop(fStop),
96 			maColor(rColor)
97 		{
98 		}
99 
100 		bool WrongSpellPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
101 		{
102 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
103 			{
104 				const WrongSpellPrimitive2D& rCompare = (WrongSpellPrimitive2D&)rPrimitive;
105 
106 				return (getTransformation() == rCompare.getTransformation()
107 					&& getStart() == rCompare.getStart()
108 					&& getStop() == rCompare.getStop()
109 					&& getColor() == rCompare.getColor());
110 			}
111 
112 			return false;
113 		}
114 
115         // provide unique ID
116 		ImplPrimitrive2DIDBlock(WrongSpellPrimitive2D, PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D)
117 
118 	} // end of namespace primitive2d
119 } // end of namespace drawinglayer
120 
121 //////////////////////////////////////////////////////////////////////////////
122 // eof
123