calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / drawinglayer / source / primitive2d / unifiedtransparenceprimitive2d.cxx
blobc09401995dd1aee0699f355bb7824195519c2c69
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
30 using namespace com::sun::star;
33 namespace drawinglayer::primitive2d
35 UnifiedTransparencePrimitive2D::UnifiedTransparencePrimitive2D(
36 Primitive2DContainer&& aChildren,
37 double fTransparence)
38 : GroupPrimitive2D(std::move(aChildren)),
39 mfTransparence(fTransparence)
43 bool UnifiedTransparencePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
45 if(GroupPrimitive2D::operator==(rPrimitive))
47 const UnifiedTransparencePrimitive2D& rCompare = static_cast<const UnifiedTransparencePrimitive2D&>(rPrimitive);
49 return (getTransparence() == rCompare.getTransparence());
52 return false;
55 basegfx::B2DRange UnifiedTransparencePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
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);
62 void UnifiedTransparencePrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const
64 if(0.0 == getTransparence())
66 // no transparence used, so just use the content
67 getChildren(rVisitor);
69 else if(getTransparence() > 0.0 && getTransparence() < 1.0)
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:
76 // - Grow the used polygon range by one discrete unit in X and Y. This
77 // will make the decomposition view-dependent.
79 // - For all filled polygon renderings, draw the polygon outline extra. This
80 // would lead to unwanted side effects when using concatenated polygons.
82 // - At this decomposition, add a filled polygon and a hairline polygon. This
83 // solution stays view-independent.
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));
88 basegfx::B2DPolygon aPolygon(basegfx::utils::createPolygonFromRect(aPolygonRange));
89 const basegfx::BColor aGray(getTransparence(), getTransparence(), getTransparence());
90 Primitive2DContainer aTransparenceContent(2);
92 aTransparenceContent[0] = Primitive2DReference(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPolygon), aGray));
93 aTransparenceContent[1] = Primitive2DReference(new PolygonHairlinePrimitive2D(std::move(aPolygon), aGray));
95 // create sub-transparence group with a gray-colored rectangular fill polygon
96 rVisitor.visit(new TransparencePrimitive2D(Primitive2DContainer(getChildren()), std::move(aTransparenceContent)));
98 else
100 // completely transparent or invalid definition, add nothing
104 // provide unique ID
105 sal_uInt32 UnifiedTransparencePrimitive2D::getPrimitive2DID() const
107 return PRIMITIVE2D_ID_UNIFIEDTRANSPARENCEPRIMITIVE2D;
110 } // end of namespace
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */