LibreOffice Module svx (master)  1
sdrolecontentprimitive2d.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 
22 #include <svx/svdoole2.hxx>
23 #include <vcl/svapp.hxx>
25 #include <svtools/colorcfg.hxx>
30 
31 
33 {
35  {
36  const SdrOle2Obj* pSource = mpSdrOle2Obj.get();
37  bool bScaleContent(false);
38  Graphic aGraphic;
39 
40  if(pSource)
41  {
42  const Graphic* pOLEGraphic = pSource->GetGraphic();
43 
44  if(pOLEGraphic)
45  {
46  aGraphic = *pOLEGraphic;
47  bScaleContent = pSource->IsEmptyPresObj();
48  }
49  }
50 #ifdef _WIN32 // Little point in displaying the "broken OLE" graphic on OSes that don't have real OLE, maybe?
51  if(GraphicType::NONE == aGraphic.GetType())
52  {
53  // no source, use fallback resource empty OLE graphic
55  bScaleContent = true;
56  }
57 #endif
58  if(GraphicType::NONE == aGraphic.GetType())
59  return;
60 
61  const GraphicObject aGraphicObject(aGraphic);
62  const GraphicAttr aGraphicAttr;
63 
64  if(bScaleContent)
65  {
66  // get transformation atoms
67  basegfx::B2DVector aScale, aTranslate;
68  double fRotate, fShearX;
69  getObjectTransform().decompose(aScale, aTranslate, fRotate, fShearX);
70 
71  // get PrefSize from the graphic in 100th mm
72  Size aPrefSize(aGraphic.GetPrefSize());
73 
74  if(MapUnit::MapPixel == aGraphic.GetPrefMapMode().GetMapUnit())
75  {
76  aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM));
77  }
78  else
79  {
80  aPrefSize = OutputDevice::LogicToLogic(aPrefSize, aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM));
81  }
82 
83  const double fOffsetX((aScale.getX() - aPrefSize.getWidth()) / 2.0);
84  const double fOffsetY((aScale.getY() - aPrefSize.getHeight()) / 2.0);
85 
86  if(basegfx::fTools::moreOrEqual(fOffsetX, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY, 0.0))
87  {
88  // if content fits into frame, create it
90  aPrefSize.getWidth(), aPrefSize.getHeight(), fOffsetX, fOffsetY));
91  aInnerObjectMatrix = basegfx::utils::createShearXRotateTranslateB2DHomMatrix(fShearX, fRotate, aTranslate)
92  * aInnerObjectMatrix;
93 
96  aInnerObjectMatrix,
97  aGraphicObject,
98  aGraphicAttr));
99  rContainer.push_back(aGraphicPrimitive);
100  }
101  }
102  else
103  {
104  // create graphic primitive for content
105  const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive(
108  aGraphicObject,
109  aGraphicAttr));
110  rContainer.push_back(aGraphicPrimitive);
111  }
112 
113  // a standard gray outline is created for scaled content
114  if(!bScaleContent)
115  return;
116 
117  const svtools::ColorConfig aColorConfig;
119 
120  if(aColor.bIsVisible)
121  {
123  const Color aVclColor(aColor.nColor);
124  aOutline.transform(getObjectTransform());
127  rContainer.push_back(xOutline);
128  }
129  }
130 
132  const SdrOle2Obj& rSdrOle2Obj,
133  const basegfx::B2DHomMatrix& rObjectTransform,
134  sal_uInt32 nGraphicVersion
135  )
136  : mpSdrOle2Obj(const_cast< SdrOle2Obj* >(&rSdrOle2Obj)),
137  maObjectTransform(rObjectTransform),
138  mnGraphicVersion(nGraphicVersion)
139  {
140  }
141 
143  {
144  if( BufferedDecompositionPrimitive2D::operator==(rPrimitive) )
145  {
146  const SdrOleContentPrimitive2D& rCompare = static_cast<const SdrOleContentPrimitive2D&>(rPrimitive);
147  const bool bBothNot(!mpSdrOle2Obj.is() && !rCompare.mpSdrOle2Obj.is());
148  const bool bBothAndEqual(mpSdrOle2Obj.is() && rCompare.mpSdrOle2Obj.is()
149  && mpSdrOle2Obj.get() == rCompare.mpSdrOle2Obj.get());
150 
151  return ((bBothNot || bBothAndEqual)
152  && getObjectTransform() == rCompare.getObjectTransform()
153 
154  // #i104867# to find out if the Graphic content of the
155  // OLE has changed, use GraphicVersion number
156  && mnGraphicVersion == rCompare.mnGraphicVersion
157  );
158  }
159 
160  return false;
161  }
162 
164  {
165  basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0);
166  aRange.transform(getObjectTransform());
167 
168  return aRange;
169  }
170 
171  // provide unique ID
173  {
175  }
176 
177 } // end of namespace
178 
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double getY() const
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &aViewInformation) const override
bool moreOrEqual(const T &rfValA, const T &rfValB)
B2DPolygon const & createUnitPolygon()
const basegfx::B2DHomMatrix & getObjectTransform() const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
SdrOleContentPrimitive2D(const SdrOle2Obj &rSdrOle2Obj, const basegfx::B2DHomMatrix &rObjectTransform, sal_uInt32 nGraphicVersion)
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
static OutputDevice * GetDefaultDevice()
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &rViewInformation) const override
GraphicType GetType() const
static Graphic GetEmptyOLEReplacementGraphic()
Definition: svdoole2.cxx:1907
bool decompose(B2DTuple &rScale, B2DTuple &rTranslate, double &rRotate, double &rShearX) const
#define PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D
MapUnit GetMapUnit() const
void transform(const basegfx::B2DHomMatrix &rMatrix)
bool is() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
Size GetPrefSize() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart=true) const
MapMode GetPrefMapMode() const
reference_type * get() const
basegfx::BColor getBColor() const
double getX() const
B2DHomMatrix createShearXRotateTranslateB2DHomMatrix(double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
const Graphic * GetGraphic() const
Definition: svdoole2.cxx:1631
bool IsEmptyPresObj() const
Definition: svdobj.hxx:831