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