calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / drawinglayer / source / primitive2d / metafileprimitive2d.cxx
blobf229aed520a4a8eec05fa494b6ebc595b7567fac
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/metafileprimitive2d.hxx>
21 #include <utility>
22 #include <wmfemfhelper.hxx>
24 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
25 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
26 #include <basegfx/polygon/b2dpolygontools.hxx>
27 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
28 #include <vcl/canvastools.hxx>
30 using namespace com::sun::star;
32 namespace drawinglayer::primitive2d
34 void MetafilePrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& rViewInformation) const
36 // Interpret the Metafile and get the content. There should be only one target, as in the start condition,
37 // but iterating will be the right thing to do when some push/pop is not closed
38 Primitive2DContainer xRetval(wmfemfhelper::interpretMetafile(getMetaFile(), rViewInformation));
40 if(!xRetval.empty())
42 // get target size
43 const ::tools::Rectangle aMtfTarget(getMetaFile().GetPrefMapMode().GetOrigin(), getMetaFile().GetPrefSize());
44 const basegfx::B2DRange aMtfRange(vcl::unotools::b2DRectangleFromRectangle(aMtfTarget));
46 // tdf#113197 get content range and check if we have an overlap with
47 // defined target range (aMtfRange)
48 if (!aMtfRange.isEmpty())
50 const basegfx::B2DRange aContentRange(xRetval.getB2DRange(rViewInformation));
52 // also test equal since isInside gives also true for equal
53 if (!aMtfRange.equal(aContentRange) && !aMtfRange.isInside(aContentRange))
55 // contentRange is partly larger than aMtfRange (stuff sticks
56 // outside), clipping is needed
57 const drawinglayer::primitive2d::Primitive2DReference xMask(
58 new drawinglayer::primitive2d::MaskPrimitive2D(
59 basegfx::B2DPolyPolygon(
60 basegfx::utils::createPolygonFromRect(
61 aMtfRange)),
62 std::move(xRetval)));
64 xRetval = drawinglayer::primitive2d::Primitive2DContainer{ xMask };
68 // create transformation
69 basegfx::B2DHomMatrix aAdaptedTransform;
71 aAdaptedTransform.translate(-aMtfTarget.Left(), -aMtfTarget.Top());
72 aAdaptedTransform.scale(
73 aMtfTarget.getOpenWidth() ? 1.0 / aMtfTarget.getOpenWidth() : 1.0,
74 aMtfTarget.getOpenHeight() ? 1.0 / aMtfTarget.getOpenHeight() : 1.0);
75 aAdaptedTransform = getTransform() * aAdaptedTransform;
77 // embed to target transformation
78 const Primitive2DReference aEmbeddedTransform(
79 new TransformPrimitive2D(
80 aAdaptedTransform,
81 std::move(xRetval)));
83 xRetval = Primitive2DContainer { aEmbeddedTransform };
86 rContainer.append(std::move(xRetval));
89 MetafilePrimitive2D::MetafilePrimitive2D(
90 basegfx::B2DHomMatrix aMetaFileTransform,
91 const GDIMetaFile& rMetaFile)
92 : maMetaFileTransform(std::move(aMetaFileTransform)),
93 maMetaFile(rMetaFile)
97 bool MetafilePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
99 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
101 const MetafilePrimitive2D& rCompare = static_cast<const MetafilePrimitive2D&>(rPrimitive);
103 return (getTransform() == rCompare.getTransform()
104 && getMetaFile() == rCompare.getMetaFile());
107 return false;
110 basegfx::B2DRange MetafilePrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
112 // use own implementation to quickly answer the getB2DRange question. The
113 // MetafilePrimitive2D assumes that all geometry is inside of the shape. If
114 // this is not the case (i have already seen some wrong Metafiles) it should
115 // be embedded to a MaskPrimitive2D
116 basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
117 aRetval.transform(getTransform());
119 return aRetval;
122 // from MetafileAccessor
123 void MetafilePrimitive2D::accessMetafile(GDIMetaFile& rTargetMetafile) const
125 rTargetMetafile = maMetaFile;
128 // provide unique ID
129 sal_uInt32 MetafilePrimitive2D::getPrimitive2DID() const
131 return PRIMITIVE2D_ID_METAFILEPRIMITIVE2D;
134 } // end of namespace
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */