calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / drawinglayer / source / primitive2d / mediaprimitive2d.cxx
blob124db4133cff8cde613d322257782ae27fc4dde3
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/mediaprimitive2d.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
24 #include <utility>
25 #include <vcl/GraphicObject.hxx>
26 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
27 #include <drawinglayer/geometry/viewinformation2d.hxx>
28 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
29 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
30 #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
33 namespace drawinglayer::primitive2d
35 void MediaPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& rViewInformation) const
37 Primitive2DContainer xRetval;
38 xRetval.resize(1);
40 // create background object
41 basegfx::B2DPolygon aBackgroundPolygon(basegfx::utils::createUnitPolygon());
42 aBackgroundPolygon.transform(getTransform());
43 const Primitive2DReference xRefBackground(
44 new PolyPolygonColorPrimitive2D(
45 basegfx::B2DPolyPolygon(aBackgroundPolygon),
46 getBackgroundColor()));
47 xRetval[0] = xRefBackground;
49 if(GraphicType::Bitmap == maSnapshot.GetType() || GraphicType::GdiMetafile == maSnapshot.GetType())
51 const GraphicObject aGraphicObject(maSnapshot);
52 const GraphicAttr aGraphicAttr;
53 xRetval.resize(2);
54 xRetval[1] = new GraphicPrimitive2D(getTransform(), aGraphicObject, aGraphicAttr);
57 if(getDiscreteBorder())
59 const basegfx::B2DVector aDiscreteInLogic(rViewInformation.getInverseObjectToViewTransformation() *
60 basegfx::B2DVector(static_cast<double>(getDiscreteBorder()), static_cast<double>(getDiscreteBorder())));
61 const double fDiscreteSize(aDiscreteInLogic.getX() + aDiscreteInLogic.getY());
63 basegfx::B2DRange aSourceRange(0.0, 0.0, 1.0, 1.0);
64 aSourceRange.transform(getTransform());
66 basegfx::B2DRange aDestRange(aSourceRange);
67 aDestRange.grow(-0.5 * fDiscreteSize);
69 if(basegfx::fTools::equalZero(aDestRange.getWidth()) || basegfx::fTools::equalZero(aDestRange.getHeight()))
71 // shrunk primitive has no content (zero size in X or Y), nothing to display. Still create
72 // invisible content for HitTest and BoundRect
73 const Primitive2DReference xHiddenLines(new HiddenGeometryPrimitive2D(std::move(xRetval)));
75 xRetval = Primitive2DContainer { xHiddenLines, };
77 else
79 // create transformation matrix from original range to shrunk range
80 basegfx::B2DHomMatrix aTransform;
81 aTransform.translate(-aSourceRange.getMinX(), -aSourceRange.getMinY());
82 aTransform.scale(aDestRange.getWidth() / aSourceRange.getWidth(), aDestRange.getHeight() / aSourceRange.getHeight());
83 aTransform.translate(aDestRange.getMinX(), aDestRange.getMinY());
85 // add transform primitive
86 Primitive2DReference aScaled(new TransformPrimitive2D(aTransform, std::move(xRetval)));
87 xRetval = Primitive2DContainer { aScaled };
91 rContainer.append(std::move(xRetval));
94 MediaPrimitive2D::MediaPrimitive2D(
95 basegfx::B2DHomMatrix aTransform,
96 OUString aURL,
97 const basegfx::BColor& rBackgroundColor,
98 sal_uInt32 nDiscreteBorder,
99 Graphic aSnapshot)
100 : maTransform(std::move(aTransform)),
101 maURL(std::move(aURL)),
102 maBackgroundColor(rBackgroundColor),
103 mnDiscreteBorder(nDiscreteBorder),
104 maSnapshot(std::move(aSnapshot))
108 bool MediaPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
110 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
112 const MediaPrimitive2D& rCompare = static_cast<const MediaPrimitive2D&>(rPrimitive);
114 return (getTransform() == rCompare.getTransform()
115 && maURL == rCompare.maURL
116 && getBackgroundColor() == rCompare.getBackgroundColor()
117 && getDiscreteBorder() == rCompare.getDiscreteBorder()
118 && maSnapshot.IsNone() == rCompare.maSnapshot.IsNone());
121 return false;
124 basegfx::B2DRange MediaPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
126 basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
127 aRetval.transform(getTransform());
129 if(getDiscreteBorder())
131 const basegfx::B2DVector aDiscreteInLogic(rViewInformation.getInverseObjectToViewTransformation() *
132 basegfx::B2DVector(static_cast<double>(getDiscreteBorder()), static_cast<double>(getDiscreteBorder())));
133 const double fDiscreteSize(aDiscreteInLogic.getX() + aDiscreteInLogic.getY());
135 aRetval.grow(-0.5 * fDiscreteSize);
138 return aRetval;
141 // provide unique ID
142 sal_uInt32 MediaPrimitive2D::getPrimitive2DID() const
144 return PRIMITIVE2D_ID_MEDIAPRIMITIVE2D;
147 } // end of namespace
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */