1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <vcl/GraphicObject.hxx>
25 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
26 #include <drawinglayer/geometry/viewinformation2d.hxx>
27 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
28 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
29 #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
32 namespace drawinglayer::primitive2d
34 void MediaPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& rViewInformation
) const
36 Primitive2DContainer xRetval
;
39 // create background object
40 basegfx::B2DPolygon
aBackgroundPolygon(basegfx::utils::createUnitPolygon());
41 aBackgroundPolygon
.transform(getTransform());
42 const Primitive2DReference
xRefBackground(
43 new PolyPolygonColorPrimitive2D(
44 basegfx::B2DPolyPolygon(aBackgroundPolygon
),
45 getBackgroundColor()));
46 xRetval
[0] = xRefBackground
;
48 if(GraphicType::Bitmap
== maSnapshot
.GetType() || GraphicType::GdiMetafile
== maSnapshot
.GetType())
50 const GraphicObject
aGraphicObject(maSnapshot
);
51 const GraphicAttr aGraphicAttr
;
53 xRetval
[1] = new GraphicPrimitive2D(getTransform(), aGraphicObject
, aGraphicAttr
);
56 if(getDiscreteBorder())
58 const basegfx::B2DVector
aDiscreteInLogic(rViewInformation
.getInverseObjectToViewTransformation() *
59 basegfx::B2DVector(static_cast<double>(getDiscreteBorder()), static_cast<double>(getDiscreteBorder())));
60 const double fDiscreteSize(aDiscreteInLogic
.getX() + aDiscreteInLogic
.getY());
62 basegfx::B2DRange
aSourceRange(0.0, 0.0, 1.0, 1.0);
63 aSourceRange
.transform(getTransform());
65 basegfx::B2DRange
aDestRange(aSourceRange
);
66 aDestRange
.grow(-0.5 * fDiscreteSize
);
68 if(basegfx::fTools::equalZero(aDestRange
.getWidth()) || basegfx::fTools::equalZero(aDestRange
.getHeight()))
70 // shrunk primitive has no content (zero size in X or Y), nothing to display. Still create
71 // invisible content for HitTest and BoundRect
72 const Primitive2DReference
xHiddenLines(new HiddenGeometryPrimitive2D(xRetval
));
74 xRetval
= Primitive2DContainer
{ xHiddenLines
, };
78 // create transformation matrix from original range to shrunk range
79 basegfx::B2DHomMatrix aTransform
;
80 aTransform
.translate(-aSourceRange
.getMinX(), -aSourceRange
.getMinY());
81 aTransform
.scale(aDestRange
.getWidth() / aSourceRange
.getWidth(), aDestRange
.getHeight() / aSourceRange
.getHeight());
82 aTransform
.translate(aDestRange
.getMinX(), aDestRange
.getMinY());
84 // add transform primitive
85 const Primitive2DReference
aScaled(new TransformPrimitive2D(aTransform
, xRetval
));
86 xRetval
= Primitive2DContainer
{ aScaled
};
90 rContainer
.insert(rContainer
.end(), xRetval
.begin(), xRetval
.end());
93 MediaPrimitive2D::MediaPrimitive2D(
94 const basegfx::B2DHomMatrix
& rTransform
,
96 const basegfx::BColor
& rBackgroundColor
,
97 sal_uInt32 nDiscreteBorder
,
98 const Graphic
&rSnapshot
)
99 : BufferedDecompositionPrimitive2D(),
100 maTransform(rTransform
),
102 maBackgroundColor(rBackgroundColor
),
103 mnDiscreteBorder(nDiscreteBorder
),
104 maSnapshot(rSnapshot
)
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());
123 basegfx::B2DRange
MediaPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const
125 basegfx::B2DRange
aRetval(0.0, 0.0, 1.0, 1.0);
126 aRetval
.transform(getTransform());
128 if(getDiscreteBorder())
130 const basegfx::B2DVector
aDiscreteInLogic(rViewInformation
.getInverseObjectToViewTransformation() *
131 basegfx::B2DVector(static_cast<double>(getDiscreteBorder()), static_cast<double>(getDiscreteBorder())));
132 const double fDiscreteSize(aDiscreteInLogic
.getX() + aDiscreteInLogic
.getY());
134 aRetval
.grow(-0.5 * fDiscreteSize
);
141 ImplPrimitive2DIDBlock(MediaPrimitive2D
, PRIMITIVE2D_ID_MEDIAPRIMITIVE2D
)
143 } // end of namespace
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */