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/polypolygonprimitive2d.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
36 void MediaPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& rViewInformation
) const
38 Primitive2DContainer xRetval
;
41 // create background object
42 basegfx::B2DPolygon
aBackgroundPolygon(basegfx::utils::createUnitPolygon());
43 aBackgroundPolygon
.transform(getTransform());
44 const Primitive2DReference
xRefBackground(
45 new PolyPolygonColorPrimitive2D(
46 basegfx::B2DPolyPolygon(aBackgroundPolygon
),
47 getBackgroundColor()));
48 xRetval
[0] = xRefBackground
;
50 if(GraphicType::Bitmap
== maSnapshot
.GetType() || GraphicType::GdiMetafile
== maSnapshot
.GetType())
52 const GraphicObject
aGraphicObject(maSnapshot
);
53 const GraphicAttr aGraphicAttr
;
55 xRetval
[1] = new GraphicPrimitive2D(getTransform(), aGraphicObject
, aGraphicAttr
);
58 if(getDiscreteBorder())
60 const basegfx::B2DVector
aDiscreteInLogic(rViewInformation
.getInverseObjectToViewTransformation() *
61 basegfx::B2DVector(static_cast<double>(getDiscreteBorder()), static_cast<double>(getDiscreteBorder())));
62 const double fDiscreteSize(aDiscreteInLogic
.getX() + aDiscreteInLogic
.getY());
64 basegfx::B2DRange
aSourceRange(0.0, 0.0, 1.0, 1.0);
65 aSourceRange
.transform(getTransform());
67 basegfx::B2DRange
aDestRange(aSourceRange
);
68 aDestRange
.grow(-0.5 * fDiscreteSize
);
70 if(basegfx::fTools::equalZero(aDestRange
.getWidth()) || basegfx::fTools::equalZero(aDestRange
.getHeight()))
72 // shrunk primitive has no content (zero size in X or Y), nothing to display. Still create
73 // invisible content for HitTest and BoundRect
74 const Primitive2DReference
xHiddenLines(new HiddenGeometryPrimitive2D(xRetval
));
76 xRetval
= Primitive2DContainer
{ xHiddenLines
, };
80 // create transformation matrix from original range to shrunk range
81 basegfx::B2DHomMatrix aTransform
;
82 aTransform
.translate(-aSourceRange
.getMinX(), -aSourceRange
.getMinY());
83 aTransform
.scale(aDestRange
.getWidth() / aSourceRange
.getWidth(), aDestRange
.getHeight() / aSourceRange
.getHeight());
84 aTransform
.translate(aDestRange
.getMinX(), aDestRange
.getMinY());
86 // add transform primitive
87 const Primitive2DReference
aScaled(new TransformPrimitive2D(aTransform
, xRetval
));
88 xRetval
= Primitive2DContainer
{ aScaled
};
92 rContainer
.insert(rContainer
.end(), xRetval
.begin(), xRetval
.end());
95 MediaPrimitive2D::MediaPrimitive2D(
96 const basegfx::B2DHomMatrix
& rTransform
,
98 const basegfx::BColor
& rBackgroundColor
,
99 sal_uInt32 nDiscreteBorder
,
100 const Graphic
&rSnapshot
)
101 : BufferedDecompositionPrimitive2D(),
102 maTransform(rTransform
),
104 maBackgroundColor(rBackgroundColor
),
105 mnDiscreteBorder(nDiscreteBorder
),
106 maSnapshot(rSnapshot
)
110 bool MediaPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
112 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
114 const MediaPrimitive2D
& rCompare
= static_cast<const MediaPrimitive2D
&>(rPrimitive
);
116 return (getTransform() == rCompare
.getTransform()
117 && maURL
== rCompare
.maURL
118 && getBackgroundColor() == rCompare
.getBackgroundColor()
119 && getDiscreteBorder() == rCompare
.getDiscreteBorder());
125 basegfx::B2DRange
MediaPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const
127 basegfx::B2DRange
aRetval(0.0, 0.0, 1.0, 1.0);
128 aRetval
.transform(getTransform());
130 if(getDiscreteBorder())
132 const basegfx::B2DVector
aDiscreteInLogic(rViewInformation
.getInverseObjectToViewTransformation() *
133 basegfx::B2DVector(static_cast<double>(getDiscreteBorder()), static_cast<double>(getDiscreteBorder())));
134 const double fDiscreteSize(aDiscreteInLogic
.getX() + aDiscreteInLogic
.getY());
136 aRetval
.grow(-0.5 * fDiscreteSize
);
143 ImplPrimitive2DIDBlock(MediaPrimitive2D
, PRIMITIVE2D_ID_MEDIAPRIMITIVE2D
)
145 } // end of namespace primitive2d
146 } // end of namespace drawinglayer
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */