/src/libreoffice/drawinglayer/source/primitive2d/mediaprimitive2d.cxx
Line | Count | Source |
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 | | |
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 <utility> |
25 | | #include <vcl/GraphicObject.hxx> |
26 | | #include <drawinglayer/primitive2d/graphicprimitive2d.hxx> |
27 | | #include <drawinglayer/geometry/viewinformation2d.hxx> |
28 | | #include <drawinglayer/primitive2d/transformprimitive2d.hxx> |
29 | | #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> |
30 | | #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx> |
31 | | |
32 | | |
33 | | namespace drawinglayer::primitive2d |
34 | | { |
35 | | Primitive2DReference MediaPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const |
36 | 0 | { |
37 | 0 | Primitive2DContainer xRetval; |
38 | 0 | xRetval.resize(1); |
39 | | |
40 | | // create background object |
41 | 0 | basegfx::B2DPolygon aBackgroundPolygon(basegfx::utils::createUnitPolygon()); |
42 | 0 | aBackgroundPolygon.transform(getTransform()); |
43 | 0 | const Primitive2DReference xRefBackground( |
44 | 0 | new PolyPolygonColorPrimitive2D( |
45 | 0 | basegfx::B2DPolyPolygon(aBackgroundPolygon), |
46 | 0 | getBackgroundColor())); |
47 | 0 | xRetval[0] = xRefBackground; |
48 | |
|
49 | 0 | if(GraphicType::Bitmap == maSnapshot.GetType() || GraphicType::GdiMetafile == maSnapshot.GetType()) |
50 | 0 | { |
51 | 0 | const GraphicObject aGraphicObject(maSnapshot); |
52 | 0 | const GraphicAttr aGraphicAttr; |
53 | 0 | xRetval.resize(2); |
54 | 0 | xRetval[1] = new GraphicPrimitive2D(getTransform(), aGraphicObject, aGraphicAttr); |
55 | 0 | } |
56 | |
|
57 | 0 | if(getDiscreteBorder()) |
58 | 0 | { |
59 | 0 | const basegfx::B2DVector aDiscreteInLogic(rViewInformation.getInverseObjectToViewTransformation() * |
60 | 0 | basegfx::B2DVector(static_cast<double>(getDiscreteBorder()), static_cast<double>(getDiscreteBorder()))); |
61 | 0 | const double fDiscreteSize(aDiscreteInLogic.getX() + aDiscreteInLogic.getY()); |
62 | |
|
63 | 0 | basegfx::B2DRange aSourceRange(0.0, 0.0, 1.0, 1.0); |
64 | 0 | aSourceRange.transform(getTransform()); |
65 | |
|
66 | 0 | basegfx::B2DRange aDestRange(aSourceRange); |
67 | 0 | aDestRange.grow(-0.5 * fDiscreteSize); |
68 | |
|
69 | 0 | if(basegfx::fTools::equalZero(aDestRange.getWidth()) || basegfx::fTools::equalZero(aDestRange.getHeight())) |
70 | 0 | { |
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 | 0 | const Primitive2DReference xHiddenLines(new HiddenGeometryPrimitive2D(std::move(xRetval))); |
74 | |
|
75 | 0 | xRetval = Primitive2DContainer { xHiddenLines, }; |
76 | 0 | } |
77 | 0 | else |
78 | 0 | { |
79 | | // create transformation matrix from original range to shrunk range |
80 | 0 | basegfx::B2DHomMatrix aTransform; |
81 | 0 | aTransform.translate(-aSourceRange.getMinX(), -aSourceRange.getMinY()); |
82 | 0 | aTransform.scale(aDestRange.getWidth() / aSourceRange.getWidth(), aDestRange.getHeight() / aSourceRange.getHeight()); |
83 | 0 | aTransform.translate(aDestRange.getMinX(), aDestRange.getMinY()); |
84 | | |
85 | | // add transform primitive |
86 | 0 | xRetval = Primitive2DContainer { |
87 | 0 | new TransformPrimitive2D(aTransform, std::move(xRetval)) // Scaled |
88 | 0 | }; |
89 | 0 | } |
90 | 0 | } |
91 | |
|
92 | 0 | return new GroupPrimitive2D(std::move(xRetval)); |
93 | 0 | } |
94 | | |
95 | | MediaPrimitive2D::MediaPrimitive2D( |
96 | | basegfx::B2DHomMatrix aTransform, |
97 | | OUString aURL, |
98 | | const basegfx::BColor& rBackgroundColor, |
99 | | sal_uInt32 nDiscreteBorder, |
100 | | Graphic aSnapshot) |
101 | 0 | : maTransform(std::move(aTransform)), |
102 | 0 | maURL(std::move(aURL)), |
103 | 0 | maBackgroundColor(rBackgroundColor), |
104 | 0 | mnDiscreteBorder(nDiscreteBorder), |
105 | 0 | maSnapshot(std::move(aSnapshot)) |
106 | 0 | { |
107 | 0 | } |
108 | | |
109 | | bool MediaPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const |
110 | 0 | { |
111 | 0 | if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) |
112 | 0 | { |
113 | 0 | const MediaPrimitive2D& rCompare = static_cast<const MediaPrimitive2D&>(rPrimitive); |
114 | |
|
115 | 0 | return (getTransform() == rCompare.getTransform() |
116 | 0 | && maURL == rCompare.maURL |
117 | 0 | && getBackgroundColor() == rCompare.getBackgroundColor() |
118 | 0 | && getDiscreteBorder() == rCompare.getDiscreteBorder() |
119 | 0 | && maSnapshot.IsNone() == rCompare.maSnapshot.IsNone()); |
120 | 0 | } |
121 | | |
122 | 0 | return false; |
123 | 0 | } |
124 | | |
125 | | basegfx::B2DRange MediaPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const |
126 | 0 | { |
127 | 0 | basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0); |
128 | 0 | aRetval.transform(getTransform()); |
129 | |
|
130 | 0 | if(getDiscreteBorder()) |
131 | 0 | { |
132 | 0 | const basegfx::B2DVector aDiscreteInLogic(rViewInformation.getInverseObjectToViewTransformation() * |
133 | 0 | basegfx::B2DVector(static_cast<double>(getDiscreteBorder()), static_cast<double>(getDiscreteBorder()))); |
134 | 0 | const double fDiscreteSize(aDiscreteInLogic.getX() + aDiscreteInLogic.getY()); |
135 | |
|
136 | 0 | aRetval.grow(-0.5 * fDiscreteSize); |
137 | 0 | } |
138 | |
|
139 | 0 | return aRetval; |
140 | 0 | } |
141 | | |
142 | | // provide unique ID |
143 | | sal_uInt32 MediaPrimitive2D::getPrimitive2DID() const |
144 | 0 | { |
145 | 0 | return PRIMITIVE2D_ID_MEDIAPRIMITIVE2D; |
146 | 0 | } |
147 | | |
148 | | } // end of namespace |
149 | | |
150 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |