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 
32 namespace drawinglayer
33 {
34  namespace primitive2d
35  {
37  {
38  const SdrOle2Obj* pSource = mpSdrOle2Obj.get();
39  bool bScaleContent(false);
40  Graphic aGraphic;
41 
42  if(pSource)
43  {
44  const Graphic* pOLEGraphic = pSource->GetGraphic();
45 
46  if(pOLEGraphic)
47  {
48  aGraphic = *pOLEGraphic;
49  bScaleContent = pSource->IsEmptyPresObj();
50  }
51  }
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
57  bScaleContent = true;
58  }
59 #endif
60  if(GraphicType::NONE != aGraphic.GetType())
61  {
62  const GraphicObject aGraphicObject(aGraphic);
63  const GraphicAttr aGraphicAttr;
64 
65  if(bScaleContent)
66  {
67  // get transformation atoms
68  basegfx::B2DVector aScale, aTranslate;
69  double fRotate, fShearX;
70  getObjectTransform().decompose(aScale, aTranslate, fRotate, fShearX);
71 
72  // get PrefSize from the graphic in 100th mm
73  Size aPrefSize(aGraphic.GetPrefSize());
74 
75  if(MapUnit::MapPixel == aGraphic.GetPrefMapMode().GetMapUnit())
76  {
77  aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM));
78  }
79  else
80  {
81  aPrefSize = OutputDevice::LogicToLogic(aPrefSize, aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM));
82  }
83 
84  const double fOffsetX((aScale.getX() - aPrefSize.getWidth()) / 2.0);
85  const double fOffsetY((aScale.getY() - aPrefSize.getHeight()) / 2.0);
86 
87  if(basegfx::fTools::moreOrEqual(fOffsetX, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY, 0.0))
88  {
89  // if content fits into frame, create it
91  aPrefSize.getWidth(), aPrefSize.getHeight(), fOffsetX, fOffsetY));
92  aInnerObjectMatrix = basegfx::utils::createShearXRotateTranslateB2DHomMatrix(fShearX, fRotate, aTranslate)
93  * aInnerObjectMatrix;
94 
97  aInnerObjectMatrix,
98  aGraphicObject,
99  aGraphicAttr));
100  rContainer.push_back(aGraphicPrimitive);
101  }
102  }
103  else
104  {
105  // create graphic primitive for content
106  const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive(
109  aGraphicObject,
110  aGraphicAttr));
111  rContainer.push_back(aGraphicPrimitive);
112  }
113 
114  // a standard gray outline is created for scaled content
115  if(bScaleContent)
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  }
131  }
132 
134  const SdrOle2Obj& rSdrOle2Obj,
135  const basegfx::B2DHomMatrix& rObjectTransform,
136  sal_uInt32 nGraphicVersion
137  )
139  mpSdrOle2Obj(const_cast< SdrOle2Obj* >(&rSdrOle2Obj)),
140  maObjectTransform(rObjectTransform),
141  mnGraphicVersion(nGraphicVersion)
142  {
143  }
144 
146  {
147  if( BufferedDecompositionPrimitive2D::operator==(rPrimitive) )
148  {
149  const SdrOleContentPrimitive2D& rCompare = static_cast<const SdrOleContentPrimitive2D&>(rPrimitive);
150  const bool bBothNot(!mpSdrOle2Obj.is() && !rCompare.mpSdrOle2Obj.is());
151  const bool bBothAndEqual(mpSdrOle2Obj.is() && rCompare.mpSdrOle2Obj.is()
152  && mpSdrOle2Obj.get() == rCompare.mpSdrOle2Obj.get());
153 
154  return ((bBothNot || bBothAndEqual)
155  && getObjectTransform() == rCompare.getObjectTransform()
156 
157  // #i104867# to find out if the Graphic content of the
158  // OLE has changed, use GraphicVersion number
159  && mnGraphicVersion == rCompare.mnGraphicVersion
160  );
161  }
162 
163  return false;
164  }
165 
167  {
168  basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0);
169  aRange.transform(getObjectTransform());
170 
171  return aRange;
172  }
173 
174  // provide unique ID
176 
177  } // end of namespace primitive2d
178 } // end of namespace drawinglayer
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool moreOrEqual(const double &rfValA, const double &rfValB)
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &aViewInformation) const override
ImplPrimitive2DIDBlock(BorderLinePrimitive2D, PRIMITIVE2D_ID_BORDERLINEPRIMITIVE2D) Primitive2DReference tryMergeBorderLinePrimitive2D(const Primitive2DReference &rCandidateA
B2DPolygon const & createUnitPolygon()
const basegfx::B2DHomMatrix & getObjectTransform() const
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
double getX() const
double getY() 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:1944
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
Point PixelToLogic(const Point &rDevicePt) const
Size GetPrefSize() const
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart=true) const
MapMode GetPrefMapMode() const
reference_type * get() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
basegfx::BColor getBColor() const
B2DHomMatrix createShearXRotateTranslateB2DHomMatrix(double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
const Graphic * GetGraphic() const
Definition: svdoole2.cxx:1660
bool IsEmptyPresObj() const
Definition: svdobj.hxx:880