LibreOffice Module drawinglayer (master) 1
metafileprimitive2d.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
21#include <utility>
22#include <wmfemfhelper.hxx>
23
28#include <vcl/canvastools.hxx>
29
30using namespace com::sun::star;
31
33{
35 {
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
39
40 if(!xRetval.empty())
41 {
42 // get target size
43 const ::tools::Rectangle aMtfTarget(getMetaFile().GetPrefMapMode().GetOrigin(), getMetaFile().GetPrefSize());
45
46 // tdf#113197 get content range and check if we have an overlap with
47 // defined target range (aMtfRange)
48 if (!aMtfRange.isEmpty())
49 {
50 const basegfx::B2DRange aContentRange(xRetval.getB2DRange(rViewInformation));
51
52 // also test equal since isInside gives also true for equal
53 if (!aMtfRange.equal(aContentRange) && !aMtfRange.isInside(aContentRange))
54 {
55 // contentRange is partly larger than aMtfRange (stuff sticks
56 // outside), clipping is needed
61 aMtfRange)),
62 std::move(xRetval)));
63
65 }
66 }
67
68 // create transformation
69 basegfx::B2DHomMatrix aAdaptedTransform;
70
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;
76
77 // embed to target transformation
78 const Primitive2DReference aEmbeddedTransform(
80 aAdaptedTransform,
81 std::move(xRetval)));
82
83 xRetval = Primitive2DContainer { aEmbeddedTransform };
84 }
85
86 rContainer.append(std::move(xRetval));
87 }
88
90 basegfx::B2DHomMatrix aMetaFileTransform,
91 const GDIMetaFile& rMetaFile)
92 : maMetaFileTransform(std::move(aMetaFileTransform)),
93 maMetaFile(rMetaFile)
94 {
95 }
96
98 {
99 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
100 {
101 const MetafilePrimitive2D& rCompare = static_cast<const MetafilePrimitive2D&>(rPrimitive);
102
103 return (getTransform() == rCompare.getTransform()
104 && getMetaFile() == rCompare.getMetaFile());
105 }
106
107 return false;
108 }
109
111 {
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());
118
119 return aRetval;
120 }
121
122 // from MetafileAccessor
124 {
125 rTargetMetafile = maMetaFile;
126 }
127
128 // provide unique ID
130 {
132 }
133
134} // end of namespace
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void translate(double fX, double fY)
void scale(double fX, double fY)
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
bool isInside(const Tuple2D< TYPE > &rTuple) const
bool isEmpty() const
bool equal(const Range2D &rRange) const
GDIMetaFile maMetaFile
the content definition
MetafilePrimitive2D(basegfx::B2DHomMatrix aMetaFileTransform, const GDIMetaFile &rMetaFile)
constructor
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &rViewInformation) const override
get range
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
const basegfx::B2DHomMatrix & getTransform() const
data read access
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &rViewInformation) const override
local decomposition.
virtual void accessMetafile(GDIMetaFile &rTargetMetafile) const override
from MetafileAccessor
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &aViewInformation) const
#define PRIMITIVE2D_ID_METAFILEPRIMITIVE2D
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
basegfx::B2DRange b2DRectangleFromRectangle(const ::tools::Rectangle &rRect)
drawinglayer::primitive2d::Primitive2DContainer interpretMetafile(const GDIMetaFile &rMetaFile, const drawinglayer::geometry::ViewInformation2D &rViewInformation)