xref: /AOO41X/main/drawinglayer/source/primitive2d/unifiedtransparenceprimitive2d.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  *  OpenOffice.org - a multi-platform office productivity suite
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  *  $RCSfile: UnifiedTransparencePrimitive2D.cxx,v $
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  *  $Revision: 1.5 $
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  *  last change: $Author: aw $ $Date: 2008-05-27 14:11:20 $
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  *  The Contents of this file are made available subject to
12*cdf0e10cSrcweir  *  the terms of GNU Lesser General Public License Version 2.1.
13*cdf0e10cSrcweir  *
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  *    GNU Lesser General Public License Version 2.1
16*cdf0e10cSrcweir  *    =============================================
17*cdf0e10cSrcweir  *    Copyright 2005 by Sun Microsystems, Inc.
18*cdf0e10cSrcweir  *    901 San Antonio Road, Palo Alto, CA 94303, USA
19*cdf0e10cSrcweir  *
20*cdf0e10cSrcweir  *    This library is free software; you can redistribute it and/or
21*cdf0e10cSrcweir  *    modify it under the terms of the GNU Lesser General Public
22*cdf0e10cSrcweir  *    License version 2.1, as published by the Free Software Foundation.
23*cdf0e10cSrcweir  *
24*cdf0e10cSrcweir  *    This library is distributed in the hope that it will be useful,
25*cdf0e10cSrcweir  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
26*cdf0e10cSrcweir  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27*cdf0e10cSrcweir  *    Lesser General Public License for more details.
28*cdf0e10cSrcweir  *
29*cdf0e10cSrcweir  *    You should have received a copy of the GNU Lesser General Public
30*cdf0e10cSrcweir  *    License along with this library; if not, write to the Free Software
31*cdf0e10cSrcweir  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32*cdf0e10cSrcweir  *    MA  02111-1307  USA
33*cdf0e10cSrcweir  *
34*cdf0e10cSrcweir  ************************************************************************/
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
37*cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
40*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
41*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
42*cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx>
43*cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
44*cdf0e10cSrcweir #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx>
45*cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
46*cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir using namespace com::sun::star;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir namespace drawinglayer
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir 	namespace primitive2d
57*cdf0e10cSrcweir 	{
58*cdf0e10cSrcweir 		UnifiedTransparencePrimitive2D::UnifiedTransparencePrimitive2D(
59*cdf0e10cSrcweir 			const Primitive2DSequence& rChildren,
60*cdf0e10cSrcweir 			double fTransparence)
61*cdf0e10cSrcweir 		:	GroupPrimitive2D(rChildren),
62*cdf0e10cSrcweir 			mfTransparence(fTransparence)
63*cdf0e10cSrcweir 		{
64*cdf0e10cSrcweir 		}
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 		bool UnifiedTransparencePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
67*cdf0e10cSrcweir 		{
68*cdf0e10cSrcweir 			if(GroupPrimitive2D::operator==(rPrimitive))
69*cdf0e10cSrcweir 			{
70*cdf0e10cSrcweir 				const UnifiedTransparencePrimitive2D& rCompare = (UnifiedTransparencePrimitive2D&)rPrimitive;
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 				return (getTransparence() == rCompare.getTransparence());
73*cdf0e10cSrcweir 			}
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 			return false;
76*cdf0e10cSrcweir 		}
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 		basegfx::B2DRange UnifiedTransparencePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
79*cdf0e10cSrcweir         {
80*cdf0e10cSrcweir             // do not use the fallback to decomposition here since for a correct BoundRect we also
81*cdf0e10cSrcweir             // need invisible (1.0 == getTransparence()) geometry; these would be deleted in the decomposition
82*cdf0e10cSrcweir 			return getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation);
83*cdf0e10cSrcweir         }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 		Primitive2DSequence UnifiedTransparencePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
86*cdf0e10cSrcweir 		{
87*cdf0e10cSrcweir 			if(0.0 == getTransparence())
88*cdf0e10cSrcweir 			{
89*cdf0e10cSrcweir 				// no transparence used, so just use the content
90*cdf0e10cSrcweir 				return getChildren();
91*cdf0e10cSrcweir 			}
92*cdf0e10cSrcweir 			else if(getTransparence() > 0.0 && getTransparence() < 1.0)
93*cdf0e10cSrcweir 			{
94*cdf0e10cSrcweir                 // The idea is to create a TransparencePrimitive2D with transparent content using a fill color
95*cdf0e10cSrcweir                 // corresponding to the transparence value. Problem is that in most systems, the right
96*cdf0e10cSrcweir                 // and bottom pixel array is not filled when filling polygons, thus this would not
97*cdf0e10cSrcweir                 // always produce a complete transparent bitmap. There are some solutions:
98*cdf0e10cSrcweir                 //
99*cdf0e10cSrcweir                 // - Grow the used polygon range by one discrete unit in X and Y. This
100*cdf0e10cSrcweir                 // will make the decomposition view-dependent.
101*cdf0e10cSrcweir                 //
102*cdf0e10cSrcweir                 // - For all filled polygon renderings, dra wthe polygon outline extra. This
103*cdf0e10cSrcweir                 // would lead to unwanted side effects when using concatenated polygons.
104*cdf0e10cSrcweir                 //
105*cdf0e10cSrcweir                 // - At this decomposition, add a filled polygon and a hairline polygon. This
106*cdf0e10cSrcweir                 // solution stays view-independent.
107*cdf0e10cSrcweir                 //
108*cdf0e10cSrcweir                 // I will take the last one here. The small overhead of two primitives will only be
109*cdf0e10cSrcweir                 // used when UnifiedTransparencePrimitive2D is not handled directly.
110*cdf0e10cSrcweir 				const basegfx::B2DRange aPolygonRange(getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation));
111*cdf0e10cSrcweir 				const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(aPolygonRange));
112*cdf0e10cSrcweir 				const basegfx::BColor aGray(getTransparence(), getTransparence(), getTransparence());
113*cdf0e10cSrcweir 				Primitive2DSequence aTransparenceContent(2);
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir                 aTransparenceContent[0] = Primitive2DReference(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPolygon), aGray));
116*cdf0e10cSrcweir                 aTransparenceContent[1] = Primitive2DReference(new PolygonHairlinePrimitive2D(aPolygon, aGray));
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 				// create sub-transparence group with a gray-colored rectangular fill polygon
119*cdf0e10cSrcweir 				const Primitive2DReference xRefB(new TransparencePrimitive2D(getChildren(), aTransparenceContent));
120*cdf0e10cSrcweir 				return Primitive2DSequence(&xRefB, 1L);
121*cdf0e10cSrcweir 			}
122*cdf0e10cSrcweir 			else
123*cdf0e10cSrcweir 			{
124*cdf0e10cSrcweir 				// completely transparent or invalid definition, add nothing
125*cdf0e10cSrcweir 				return Primitive2DSequence();
126*cdf0e10cSrcweir 			}
127*cdf0e10cSrcweir 		}
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 		// provide unique ID
130*cdf0e10cSrcweir 		ImplPrimitrive2DIDBlock(UnifiedTransparencePrimitive2D, PRIMITIVE2D_ID_UNIFIEDTRANSPARENCEPRIMITIVE2D)
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 	} // end of namespace primitive2d
133*cdf0e10cSrcweir } // end of namespace drawinglayer
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
136*cdf0e10cSrcweir // eof
137