Update ooo320-m1
[ooovba.git] / drawinglayer / source / primitive2d / unifiedalphaprimitive2d.cxx
blob9005067b8af6065cd59c7f80c32f8e5c2a0612ab
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: unifiedalphaprimitive2d.cxx,v $
7 * $Revision: 1.5 $
9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:20 $
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/unifiedalphaprimitive2d.hxx>
40 #include <basegfx/polygon/b2dpolygon.hxx>
41 #include <basegfx/polygon/b2dpolygontools.hxx>
42 #include <basegfx/color/bcolor.hxx>
43 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
44 #include <drawinglayer/primitive2d/alphaprimitive2d.hxx>
45 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
46 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
48 //////////////////////////////////////////////////////////////////////////////
50 using namespace com::sun::star;
52 //////////////////////////////////////////////////////////////////////////////
54 namespace drawinglayer
56 namespace primitive2d
58 Primitive2DSequence UnifiedAlphaPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& rViewInformation) const
60 if(0.0 == getAlpha())
62 // no transparence used, so just use the content
63 return getChildren();
65 else if(getAlpha() > 0.0 && getAlpha() < 1.0)
67 // The idea is to create a AlphaPrimitive2D with alpha content using a fill color
68 // corresponding to the alpha value. Problem is that in most systems, the right
69 // and bottom pixel array is not filled when filling polygons, thus this would not
70 // always produce a complete alpha bitmap. There are some solutions:
72 // - Grow the used polygon range by one discrete unit in X and Y. This
73 // will make the decomposition view-dependent.
75 // - For all filled polygon renderings, dra wthe polygon outline extra. This
76 // would lead to unwanted side effects when using concatenated polygons.
78 // - At this decomposition, add a filled polygon and a hairline polygon. This
79 // solution stays view-independent.
81 // I will take the last one here. The small overhead of two primitives will only be
82 // used when UnifiedAlphaPrimitive2D is not handled directly.
83 const basegfx::B2DRange aPolygonRange(getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation));
84 const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(aPolygonRange));
85 const basegfx::BColor aGray(getAlpha(), getAlpha(), getAlpha());
86 Primitive2DSequence aAlphaContent(2);
88 aAlphaContent[0] = Primitive2DReference(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPolygon), aGray));
89 aAlphaContent[1] = Primitive2DReference(new PolygonHairlinePrimitive2D(aPolygon, aGray));
91 // create sub-transparence group with a gray-colored rectangular fill polygon
92 const Primitive2DReference xRefB(new AlphaPrimitive2D(getChildren(), aAlphaContent));
93 return Primitive2DSequence(&xRefB, 1L);
95 else
97 // completely transparent or invalid definition, add nothing
98 return Primitive2DSequence();
102 UnifiedAlphaPrimitive2D::UnifiedAlphaPrimitive2D(
103 const Primitive2DSequence& rChildren,
104 double fAlpha)
105 : GroupPrimitive2D(rChildren),
106 mfAlpha(fAlpha)
110 bool UnifiedAlphaPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
112 if(GroupPrimitive2D::operator==(rPrimitive))
114 const UnifiedAlphaPrimitive2D& rCompare = (UnifiedAlphaPrimitive2D&)rPrimitive;
116 return (getAlpha() == rCompare.getAlpha());
119 return false;
122 // provide unique ID
123 ImplPrimitrive2DIDBlock(UnifiedAlphaPrimitive2D, PRIMITIVE2D_ID_UNIFIEDALPHAPRIMITIVE2D)
125 } // end of namespace primitive2d
126 } // end of namespace drawinglayer
128 //////////////////////////////////////////////////////////////////////////////
129 // eof