Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
21 : #include <basegfx/polygon/b2dpolygon.hxx>
22 : #include <basegfx/polygon/b2dpolygontools.hxx>
23 : #include <basegfx/color/bcolor.hxx>
24 : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
25 : #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx>
26 : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
27 : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
28 :
29 :
30 :
31 : using namespace com::sun::star;
32 :
33 :
34 :
35 : namespace drawinglayer
36 : {
37 : namespace primitive2d
38 : {
39 0 : UnifiedTransparencePrimitive2D::UnifiedTransparencePrimitive2D(
40 : const Primitive2DSequence& rChildren,
41 : double fTransparence)
42 : : GroupPrimitive2D(rChildren),
43 0 : mfTransparence(fTransparence)
44 : {
45 0 : }
46 :
47 0 : bool UnifiedTransparencePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
48 : {
49 0 : if(GroupPrimitive2D::operator==(rPrimitive))
50 : {
51 0 : const UnifiedTransparencePrimitive2D& rCompare = (UnifiedTransparencePrimitive2D&)rPrimitive;
52 :
53 0 : return (getTransparence() == rCompare.getTransparence());
54 : }
55 :
56 0 : return false;
57 : }
58 :
59 0 : basegfx::B2DRange UnifiedTransparencePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
60 : {
61 : // do not use the fallback to decomposition here since for a correct BoundRect we also
62 : // need invisible (1.0 == getTransparence()) geometry; these would be deleted in the decomposition
63 0 : return getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation);
64 : }
65 :
66 0 : Primitive2DSequence UnifiedTransparencePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
67 : {
68 0 : if(0.0 == getTransparence())
69 : {
70 : // no transparence used, so just use the content
71 0 : return getChildren();
72 : }
73 0 : else if(getTransparence() > 0.0 && getTransparence() < 1.0)
74 : {
75 : // The idea is to create a TransparencePrimitive2D with transparent content using a fill color
76 : // corresponding to the transparence value. Problem is that in most systems, the right
77 : // and bottom pixel array is not filled when filling polygons, thus this would not
78 : // always produce a complete transparent bitmap. There are some solutions:
79 :
80 : // - Grow the used polygon range by one discrete unit in X and Y. This
81 : // will make the decomposition view-dependent.
82 :
83 : // - For all filled polygon renderings, dra wthe polygon outline extra. This
84 : // would lead to unwanted side effects when using concatenated polygons.
85 :
86 : // - At this decomposition, add a filled polygon and a hairline polygon. This
87 : // solution stays view-independent.
88 :
89 : // I will take the last one here. The small overhead of two primitives will only be
90 : // used when UnifiedTransparencePrimitive2D is not handled directly.
91 0 : const basegfx::B2DRange aPolygonRange(getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation));
92 0 : const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(aPolygonRange));
93 0 : const basegfx::BColor aGray(getTransparence(), getTransparence(), getTransparence());
94 0 : Primitive2DSequence aTransparenceContent(2);
95 :
96 0 : aTransparenceContent[0] = Primitive2DReference(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPolygon), aGray));
97 0 : aTransparenceContent[1] = Primitive2DReference(new PolygonHairlinePrimitive2D(aPolygon, aGray));
98 :
99 : // create sub-transparence group with a gray-colored rectangular fill polygon
100 0 : const Primitive2DReference xRefB(new TransparencePrimitive2D(getChildren(), aTransparenceContent));
101 0 : return Primitive2DSequence(&xRefB, 1L);
102 : }
103 : else
104 : {
105 : // completely transparent or invalid definition, add nothing
106 0 : return Primitive2DSequence();
107 : }
108 : }
109 :
110 : // provide unique ID
111 0 : ImplPrimitive2DIDBlock(UnifiedTransparencePrimitive2D, PRIMITIVE2D_ID_UNIFIEDTRANSPARENCEPRIMITIVE2D)
112 :
113 : } // end of namespace primitive2d
114 : } // end of namespace drawinglayer
115 :
116 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|