/src/libreoffice/svx/source/sdr/primitive2d/sdrolecontentprimitive2d.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 <sdr/primitive2d/sdrolecontentprimitive2d.hxx> |
21 | | #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx> |
22 | | #include <svx/svdoole2.hxx> |
23 | | #include <utility> |
24 | | #include <vcl/svapp.hxx> |
25 | | #include <drawinglayer/primitive2d/graphicprimitive2d.hxx> |
26 | | #include <drawinglayer/primitive2d/groupprimitive2d.hxx> |
27 | | #include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx> |
28 | | #include <svtools/colorcfg.hxx> |
29 | | #include <basegfx/polygon/b2dpolygontools.hxx> |
30 | | #include <basegfx/polygon/b2dpolygon.hxx> |
31 | | #include <basegfx/matrix/b2dhommatrixtools.hxx> |
32 | | |
33 | | |
34 | | namespace drawinglayer::primitive2d |
35 | | { |
36 | | Primitive2DReference SdrOleContentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const |
37 | 0 | { |
38 | 0 | rtl::Reference<SdrOle2Obj> pSource = mpSdrOle2Obj.get(); |
39 | 0 | bool bScaleContent(false); |
40 | 0 | Graphic aGraphic; |
41 | |
|
42 | 0 | if(pSource) |
43 | 0 | { |
44 | 0 | const Graphic* pOLEGraphic = pSource->GetGraphic(); |
45 | |
|
46 | 0 | if(pOLEGraphic) |
47 | 0 | { |
48 | 0 | aGraphic = *pOLEGraphic; |
49 | 0 | bScaleContent = pSource->IsEmptyPresObj(); |
50 | 0 | } |
51 | 0 | } |
52 | | #ifdef _WIN32 // Little point in displaying the "broken OLE" graphic on OSes that don't have real OLE, maybe? |
53 | | if(GraphicType::NONE == aGraphic.GetType()) |
54 | | { |
55 | | // no source, use fallback resource empty OLE graphic |
56 | | aGraphic = SdrOle2Obj::GetEmptyOLEReplacementGraphic(); |
57 | | bScaleContent = true; |
58 | | } |
59 | | #endif |
60 | 0 | if(GraphicType::NONE == aGraphic.GetType()) |
61 | 0 | return nullptr; |
62 | | |
63 | 0 | const GraphicObject aGraphicObject(aGraphic); |
64 | 0 | const GraphicAttr aGraphicAttr; |
65 | 0 | Primitive2DContainer aContainer; |
66 | 0 | if(bScaleContent) |
67 | 0 | { |
68 | | // get transformation atoms |
69 | 0 | basegfx::B2DVector aScale, aTranslate; |
70 | 0 | double fRotate, fShearX; |
71 | 0 | getObjectTransform().decompose(aScale, aTranslate, fRotate, fShearX); |
72 | | |
73 | | // get PrefSize from the graphic in 100th mm |
74 | 0 | Size aPrefSize(aGraphic.GetPrefSize()); |
75 | |
|
76 | 0 | if(MapUnit::MapPixel == aGraphic.GetPrefMapMode().GetMapUnit()) |
77 | 0 | { |
78 | 0 | aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM)); |
79 | 0 | } |
80 | 0 | else |
81 | 0 | { |
82 | 0 | aPrefSize = OutputDevice::LogicToLogic(aPrefSize, aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM)); |
83 | 0 | } |
84 | |
|
85 | 0 | const double fOffsetX((aScale.getX() - aPrefSize.getWidth()) / 2.0); |
86 | 0 | const double fOffsetY((aScale.getY() - aPrefSize.getHeight()) / 2.0); |
87 | |
|
88 | 0 | if(fOffsetX >= 0.0 && fOffsetY >= 0.0) |
89 | 0 | { |
90 | | // if content fits into frame, create it |
91 | 0 | basegfx::B2DHomMatrix aInnerObjectMatrix(basegfx::utils::createScaleTranslateB2DHomMatrix( |
92 | 0 | aPrefSize.getWidth(), aPrefSize.getHeight(), fOffsetX, fOffsetY)); |
93 | 0 | aInnerObjectMatrix = basegfx::utils::createShearXRotateTranslateB2DHomMatrix(fShearX, fRotate, aTranslate) |
94 | 0 | * aInnerObjectMatrix; |
95 | |
|
96 | 0 | const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive( |
97 | 0 | new drawinglayer::primitive2d::GraphicPrimitive2D( |
98 | 0 | aInnerObjectMatrix, |
99 | 0 | aGraphicObject, |
100 | 0 | aGraphicAttr)); |
101 | 0 | aContainer.push_back(aGraphicPrimitive); |
102 | 0 | } |
103 | 0 | } |
104 | 0 | else |
105 | 0 | { |
106 | | // create graphic primitive for content |
107 | 0 | const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive( |
108 | 0 | new drawinglayer::primitive2d::GraphicPrimitive2D( |
109 | 0 | getObjectTransform(), |
110 | 0 | aGraphicObject, |
111 | 0 | aGraphicAttr)); |
112 | 0 | aContainer.push_back(aGraphicPrimitive); |
113 | 0 | } |
114 | | |
115 | | // a standard gray outline is created for scaled content |
116 | 0 | if(!bScaleContent) |
117 | 0 | return new GroupPrimitive2D(std::move(aContainer)); |
118 | | |
119 | 0 | const svtools::ColorConfig aColorConfig; |
120 | 0 | const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::DOCBOUNDARIES)); |
121 | |
|
122 | 0 | if(aColor.bIsVisible) |
123 | 0 | { |
124 | 0 | basegfx::B2DPolygon aOutline(basegfx::utils::createUnitPolygon()); |
125 | 0 | const Color aVclColor(aColor.nColor); |
126 | 0 | aOutline.transform(getObjectTransform()); |
127 | 0 | const drawinglayer::primitive2d::Primitive2DReference xOutline( |
128 | 0 | new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(std::move(aOutline), aVclColor.getBColor())); |
129 | 0 | aContainer.push_back(xOutline); |
130 | 0 | } |
131 | 0 | return new GroupPrimitive2D(std::move(aContainer)); |
132 | 0 | } |
133 | | |
134 | | SdrOleContentPrimitive2D::SdrOleContentPrimitive2D( |
135 | | const SdrOle2Obj& rSdrOle2Obj, |
136 | | basegfx::B2DHomMatrix aObjectTransform, |
137 | | sal_uInt32 nGraphicVersion |
138 | | ) |
139 | 0 | : mpSdrOle2Obj(const_cast< SdrOle2Obj* >(&rSdrOle2Obj)), |
140 | 0 | maObjectTransform(std::move(aObjectTransform)), |
141 | 0 | mnGraphicVersion(nGraphicVersion) |
142 | 0 | { |
143 | 0 | } |
144 | | |
145 | | bool SdrOleContentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const |
146 | 0 | { |
147 | 0 | if( BufferedDecompositionPrimitive2D::operator==(rPrimitive) ) |
148 | 0 | { |
149 | 0 | const SdrOleContentPrimitive2D& rCompare = static_cast<const SdrOleContentPrimitive2D&>(rPrimitive); |
150 | 0 | auto xSdrThis = mpSdrOle2Obj.get(); |
151 | 0 | auto xSdrThat = rCompare.mpSdrOle2Obj.get(); |
152 | 0 | const bool bBothNot(!xSdrThis && !xSdrThat); |
153 | 0 | const bool bBothAndEqual(xSdrThis && xSdrThat |
154 | 0 | && xSdrThis.get() == xSdrThat.get()); |
155 | |
|
156 | 0 | return ((bBothNot || bBothAndEqual) |
157 | 0 | && getObjectTransform() == rCompare.getObjectTransform() |
158 | | |
159 | | // #i104867# to find out if the Graphic content of the |
160 | | // OLE has changed, use GraphicVersion number |
161 | 0 | && mnGraphicVersion == rCompare.mnGraphicVersion |
162 | 0 | ); |
163 | 0 | } |
164 | | |
165 | 0 | return false; |
166 | 0 | } |
167 | | |
168 | | basegfx::B2DRange SdrOleContentPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const |
169 | 0 | { |
170 | 0 | basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0); |
171 | 0 | aRange.transform(getObjectTransform()); |
172 | |
|
173 | 0 | return aRange; |
174 | 0 | } |
175 | | |
176 | | // provide unique ID |
177 | | sal_uInt32 SdrOleContentPrimitive2D::getPrimitive2DID() const |
178 | 0 | { |
179 | 0 | return PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D; |
180 | 0 | } |
181 | | |
182 | | } // end of namespace |
183 | | |
184 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |