1*4bfbcde8SAndrew Rist /**************************************************************
2*4bfbcde8SAndrew Rist  *
3*4bfbcde8SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*4bfbcde8SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*4bfbcde8SAndrew Rist  * distributed with this work for additional information
6*4bfbcde8SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*4bfbcde8SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*4bfbcde8SAndrew Rist  * "License"); you may not use this file except in compliance
9*4bfbcde8SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*4bfbcde8SAndrew Rist  *
11*4bfbcde8SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*4bfbcde8SAndrew Rist  *
13*4bfbcde8SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*4bfbcde8SAndrew Rist  * software distributed under the License is distributed on an
15*4bfbcde8SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*4bfbcde8SAndrew Rist  * KIND, either express or implied.  See the License for the
17*4bfbcde8SAndrew Rist  * specific language governing permissions and limitations
18*4bfbcde8SAndrew Rist  * under the License.
19*4bfbcde8SAndrew Rist  *
20*4bfbcde8SAndrew Rist  *************************************************************/
21cdf0e10cSrcweir 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
26cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
27cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
28cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
30cdf0e10cSrcweir #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx>
31cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
32cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
35cdf0e10cSrcweir 
36cdf0e10cSrcweir using namespace com::sun::star;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace drawinglayer
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 	namespace primitive2d
43cdf0e10cSrcweir 	{
UnifiedTransparencePrimitive2D(const Primitive2DSequence & rChildren,double fTransparence)44cdf0e10cSrcweir 		UnifiedTransparencePrimitive2D::UnifiedTransparencePrimitive2D(
45cdf0e10cSrcweir 			const Primitive2DSequence& rChildren,
46cdf0e10cSrcweir 			double fTransparence)
47cdf0e10cSrcweir 		:	GroupPrimitive2D(rChildren),
48cdf0e10cSrcweir 			mfTransparence(fTransparence)
49cdf0e10cSrcweir 		{
50cdf0e10cSrcweir 		}
51cdf0e10cSrcweir 
operator ==(const BasePrimitive2D & rPrimitive) const52cdf0e10cSrcweir 		bool UnifiedTransparencePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
53cdf0e10cSrcweir 		{
54cdf0e10cSrcweir 			if(GroupPrimitive2D::operator==(rPrimitive))
55cdf0e10cSrcweir 			{
56cdf0e10cSrcweir 				const UnifiedTransparencePrimitive2D& rCompare = (UnifiedTransparencePrimitive2D&)rPrimitive;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 				return (getTransparence() == rCompare.getTransparence());
59cdf0e10cSrcweir 			}
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 			return false;
62cdf0e10cSrcweir 		}
63cdf0e10cSrcweir 
getB2DRange(const geometry::ViewInformation2D & rViewInformation) const64cdf0e10cSrcweir 		basegfx::B2DRange UnifiedTransparencePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir             // do not use the fallback to decomposition here since for a correct BoundRect we also
67cdf0e10cSrcweir             // need invisible (1.0 == getTransparence()) geometry; these would be deleted in the decomposition
68cdf0e10cSrcweir 			return getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation);
69cdf0e10cSrcweir         }
70cdf0e10cSrcweir 
get2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const71cdf0e10cSrcweir 		Primitive2DSequence UnifiedTransparencePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
72cdf0e10cSrcweir 		{
73cdf0e10cSrcweir 			if(0.0 == getTransparence())
74cdf0e10cSrcweir 			{
75cdf0e10cSrcweir 				// no transparence used, so just use the content
76cdf0e10cSrcweir 				return getChildren();
77cdf0e10cSrcweir 			}
78cdf0e10cSrcweir 			else if(getTransparence() > 0.0 && getTransparence() < 1.0)
79cdf0e10cSrcweir 			{
80cdf0e10cSrcweir                 // The idea is to create a TransparencePrimitive2D with transparent content using a fill color
81cdf0e10cSrcweir                 // corresponding to the transparence value. Problem is that in most systems, the right
82cdf0e10cSrcweir                 // and bottom pixel array is not filled when filling polygons, thus this would not
83cdf0e10cSrcweir                 // always produce a complete transparent bitmap. There are some solutions:
84cdf0e10cSrcweir                 //
85cdf0e10cSrcweir                 // - Grow the used polygon range by one discrete unit in X and Y. This
86cdf0e10cSrcweir                 // will make the decomposition view-dependent.
87cdf0e10cSrcweir                 //
88cdf0e10cSrcweir                 // - For all filled polygon renderings, dra wthe polygon outline extra. This
89cdf0e10cSrcweir                 // would lead to unwanted side effects when using concatenated polygons.
90cdf0e10cSrcweir                 //
91cdf0e10cSrcweir                 // - At this decomposition, add a filled polygon and a hairline polygon. This
92cdf0e10cSrcweir                 // solution stays view-independent.
93cdf0e10cSrcweir                 //
94cdf0e10cSrcweir                 // I will take the last one here. The small overhead of two primitives will only be
95cdf0e10cSrcweir                 // used when UnifiedTransparencePrimitive2D is not handled directly.
96cdf0e10cSrcweir 				const basegfx::B2DRange aPolygonRange(getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation));
97cdf0e10cSrcweir 				const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(aPolygonRange));
98cdf0e10cSrcweir 				const basegfx::BColor aGray(getTransparence(), getTransparence(), getTransparence());
99cdf0e10cSrcweir 				Primitive2DSequence aTransparenceContent(2);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir                 aTransparenceContent[0] = Primitive2DReference(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPolygon), aGray));
102cdf0e10cSrcweir                 aTransparenceContent[1] = Primitive2DReference(new PolygonHairlinePrimitive2D(aPolygon, aGray));
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 				// create sub-transparence group with a gray-colored rectangular fill polygon
105cdf0e10cSrcweir 				const Primitive2DReference xRefB(new TransparencePrimitive2D(getChildren(), aTransparenceContent));
106cdf0e10cSrcweir 				return Primitive2DSequence(&xRefB, 1L);
107cdf0e10cSrcweir 			}
108cdf0e10cSrcweir 			else
109cdf0e10cSrcweir 			{
110cdf0e10cSrcweir 				// completely transparent or invalid definition, add nothing
111cdf0e10cSrcweir 				return Primitive2DSequence();
112cdf0e10cSrcweir 			}
113cdf0e10cSrcweir 		}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 		// provide unique ID
116cdf0e10cSrcweir 		ImplPrimitrive2DIDBlock(UnifiedTransparencePrimitive2D, PRIMITIVE2D_ID_UNIFIEDTRANSPARENCEPRIMITIVE2D)
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	} // end of namespace primitive2d
119cdf0e10cSrcweir } // end of namespace drawinglayer
120cdf0e10cSrcweir 
121cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
122cdf0e10cSrcweir // eof
123