LibreOffice Module drawinglayer (master) 1
mediaprimitive2d.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
24#include <utility>
25#include <vcl/GraphicObject.hxx>
31
32
34{
36 {
38 xRetval.resize(1);
39
40 // create background object
42 aBackgroundPolygon.transform(getTransform());
43 const Primitive2DReference xRefBackground(
45 basegfx::B2DPolyPolygon(aBackgroundPolygon),
47 xRetval[0] = xRefBackground;
48
49 if(GraphicType::Bitmap == maSnapshot.GetType() || GraphicType::GdiMetafile == maSnapshot.GetType())
50 {
51 const GraphicObject aGraphicObject(maSnapshot);
52 const GraphicAttr aGraphicAttr;
53 xRetval.resize(2);
54 xRetval[1] = new GraphicPrimitive2D(getTransform(), aGraphicObject, aGraphicAttr);
55 }
56
58 {
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());
62
63 basegfx::B2DRange aSourceRange(0.0, 0.0, 1.0, 1.0);
64 aSourceRange.transform(getTransform());
65
66 basegfx::B2DRange aDestRange(aSourceRange);
67 aDestRange.grow(-0.5 * fDiscreteSize);
68
70 {
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)));
74
75 xRetval = Primitive2DContainer { xHiddenLines, };
76 }
77 else
78 {
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());
84
85 // add transform primitive
86 Primitive2DReference aScaled(new TransformPrimitive2D(aTransform, std::move(xRetval)));
87 xRetval = Primitive2DContainer { aScaled };
88 }
89 }
90
91 rContainer.append(std::move(xRetval));
92 }
93
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))
105 {
106 }
107
108 bool MediaPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
109 {
110 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
111 {
112 const MediaPrimitive2D& rCompare = static_cast<const MediaPrimitive2D&>(rPrimitive);
113
114 return (getTransform() == rCompare.getTransform()
115 && maURL == rCompare.maURL
116 && getBackgroundColor() == rCompare.getBackgroundColor()
117 && getDiscreteBorder() == rCompare.getDiscreteBorder()
118 && maSnapshot.IsNone() == rCompare.maSnapshot.IsNone());
119 }
120
121 return false;
122 }
123
125 {
126 basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
127 aRetval.transform(getTransform());
128
130 {
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());
134
135 aRetval.grow(-0.5 * fDiscreteSize);
136 }
137
138 return aRetval;
139 }
140
141 // provide unique ID
143 {
145 }
146
147} // end of namespace
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Color maBackgroundColor
GraphicType GetType() const
bool IsNone() const
void translate(double fX, double fY)
void scale(double fX, double fY)
void transform(const basegfx::B2DHomMatrix &rMatrix)
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
void grow(TYPE fValue)
TYPE getWidth() const
TYPE getMinX() const
TYPE getMinY() const
TYPE getHeight() const
TYPE getX() const
TYPE getY() const
const basegfx::B2DHomMatrix & getInverseObjectToViewTransformation() const
const basegfx::BColor & getBackgroundColor() const
MediaPrimitive2D(basegfx::B2DHomMatrix aTransform, OUString aURL, const basegfx::BColor &rBackgroundColor, sal_uInt32 nDiscreteBorder, Graphic aSnapshot)
constructor
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &rViewInformation) const override
local decomposition
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &rViewInformation) const override
get range
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
const basegfx::B2DHomMatrix & getTransform() const
data read access
URL aURL
#define PRIMITIVE2D_ID_MEDIAPRIMITIVE2D
basegfx::B2DHomMatrix maTransform
the geometric definition
bool equalZero(const T &rfVal)
B2DPolygon const & createUnitPolygon()
const double fDiscreteSize(1.1)
const URL maURL