/src/libreoffice/drawinglayer/source/primitive2d/unifiedtransparenceprimitive2d.cxx
Line | Count | Source |
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/PolygonHairlinePrimitive2D.hxx> |
25 | | #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx> |
26 | | #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx> |
27 | | #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> |
28 | | |
29 | | |
30 | | namespace drawinglayer::primitive2d |
31 | | { |
32 | | UnifiedTransparencePrimitive2D::UnifiedTransparencePrimitive2D( |
33 | | Primitive2DContainer&& aChildren, |
34 | | double fTransparence) |
35 | 0 | : GroupPrimitive2D(std::move(aChildren)), |
36 | 0 | mfTransparence(fTransparence) |
37 | 0 | { |
38 | 0 | } |
39 | | |
40 | | bool UnifiedTransparencePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const |
41 | 0 | { |
42 | 0 | if(GroupPrimitive2D::operator==(rPrimitive)) |
43 | 0 | { |
44 | 0 | const UnifiedTransparencePrimitive2D& rCompare = static_cast<const UnifiedTransparencePrimitive2D&>(rPrimitive); |
45 | |
|
46 | 0 | return (getTransparence() == rCompare.getTransparence()); |
47 | 0 | } |
48 | | |
49 | 0 | return false; |
50 | 0 | } |
51 | | |
52 | | basegfx::B2DRange UnifiedTransparencePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const |
53 | 0 | { |
54 | | // do not use the fallback to decomposition here since for a correct BoundRect we also |
55 | | // need invisible (1.0 == getTransparence()) geometry; these would be deleted in the decomposition |
56 | 0 | return getChildren().getB2DRange( rViewInformation); |
57 | 0 | } |
58 | | |
59 | | void UnifiedTransparencePrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const |
60 | 0 | { |
61 | 0 | if(0.0 == getTransparence()) |
62 | 0 | { |
63 | | // no transparence used, so just use the content |
64 | 0 | getChildren(rVisitor); |
65 | 0 | } |
66 | 0 | else if(getTransparence() > 0.0 && getTransparence() < 1.0) |
67 | 0 | { |
68 | | // The idea is to create a TransparencePrimitive2D with transparent content using a fill color |
69 | | // corresponding to the transparence value. Problem is that in most systems, the right |
70 | | // and bottom pixel array is not filled when filling polygons, thus this would not |
71 | | // always produce a complete transparent bitmap. There are some solutions: |
72 | | |
73 | | // - Grow the used polygon range by one discrete unit in X and Y. This |
74 | | // will make the decomposition view-dependent. |
75 | | |
76 | | // - For all filled polygon renderings, draw the polygon outline extra. This |
77 | | // would lead to unwanted side effects when using concatenated polygons. |
78 | | |
79 | | // - At this decomposition, add a filled polygon and a hairline polygon. This |
80 | | // solution stays view-independent. |
81 | | |
82 | | // I will take the last one here. The small overhead of two primitives will only be |
83 | | // used when UnifiedTransparencePrimitive2D is not handled directly. |
84 | 0 | const basegfx::B2DRange aPolygonRange(getChildren().getB2DRange(rViewInformation)); |
85 | 0 | basegfx::B2DPolygon aPolygon(basegfx::utils::createPolygonFromRect(aPolygonRange)); |
86 | 0 | const basegfx::BColor aGray(getTransparence(), getTransparence(), getTransparence()); |
87 | 0 | Primitive2DContainer aTransparenceContent(2); |
88 | |
|
89 | 0 | aTransparenceContent[0] = new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPolygon), aGray); |
90 | 0 | aTransparenceContent[1] = new PolygonHairlinePrimitive2D(std::move(aPolygon), aGray); |
91 | | |
92 | | // create sub-transparence group with a gray-colored rectangular fill polygon |
93 | 0 | rVisitor.visit(new TransparencePrimitive2D(Primitive2DContainer(getChildren()), std::move(aTransparenceContent))); |
94 | 0 | } |
95 | 0 | else |
96 | 0 | { |
97 | | // completely transparent or invalid definition, add nothing |
98 | 0 | } |
99 | 0 | } |
100 | | |
101 | | // provide unique ID |
102 | | sal_uInt32 UnifiedTransparencePrimitive2D::getPrimitive2DID() const |
103 | 0 | { |
104 | 0 | return PRIMITIVE2D_ID_UNIFIEDTRANSPARENCEPRIMITIVE2D; |
105 | 0 | } |
106 | | |
107 | | } // end of namespace |
108 | | |
109 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |