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  {
60  const GraphicObject aGraphicObject(aGraphic);
61  const GraphicAttr aGraphicAttr;
62 
63  if(bScaleContent)
64  {
65  // get transformation atoms
66  basegfx::B2DVector aScale, aTranslate;
67  double fRotate, fShearX;
68  getObjectTransform().decompose(aScale, aTranslate, fRotate, fShearX);
69 
70  // get PrefSize from the graphic in 100th mm
71  Size aPrefSize(aGraphic.GetPrefSize());
72 
73  if(MapUnit::MapPixel == aGraphic.GetPrefMapMode().GetMapUnit())
74  {
75  aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM));
76  }
77  else
78  {
79  aPrefSize = OutputDevice::LogicToLogic(aPrefSize, aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM));
80  }
81 
82  const double fOffsetX((aScale.getX() - aPrefSize.getWidth()) / 2.0);
83  const double fOffsetY((aScale.getY() - aPrefSize.getHeight()) / 2.0);
84 
85  if(basegfx::fTools::moreOrEqual(fOffsetX, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY, 0.0))
86  {
87  // if content fits into frame, create it
89  aPrefSize.getWidth(), aPrefSize.getHeight(), fOffsetX, fOffsetY));
90  aInnerObjectMatrix = basegfx::utils::createShearXRotateTranslateB2DHomMatrix(fShearX, fRotate, aTranslate)
91  * aInnerObjectMatrix;
92 
95  aInnerObjectMatrix,
96  aGraphicObject,
97  aGraphicAttr));
98  rContainer.push_back(aGraphicPrimitive);
99  }
100  }
101  else
102  {
103  // create graphic primitive for content
104  const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive(
107  aGraphicObject,
108  aGraphicAttr));
109  rContainer.push_back(aGraphicPrimitive);
110  }
111 
112  // a standard gray outline is created for scaled content
113  if(bScaleContent)
114  {
115  const svtools::ColorConfig aColorConfig;
117 
118  if(aColor.bIsVisible)
119  {
121  const Color aVclColor(aColor.nColor);
122  aOutline.transform(getObjectTransform());
125  rContainer.push_back(xOutline);
126  }
127  }
128  }
129  }
130 
132  const SdrOle2Obj& rSdrOle2Obj,
133  const basegfx::B2DHomMatrix& rObjectTransform,
134  sal_uInt32 nGraphicVersion
135  )
137  mpSdrOle2Obj(const_cast< SdrOle2Obj* >(&rSdrOle2Obj)),
138  maObjectTransform(rObjectTransform),
139  mnGraphicVersion(nGraphicVersion)
140  {
141  }
142 
144  {
145  if( BufferedDecompositionPrimitive2D::operator==(rPrimitive) )
146  {
147  const SdrOleContentPrimitive2D& rCompare = static_cast<const SdrOleContentPrimitive2D&>(rPrimitive);
148  const bool bBothNot(!mpSdrOle2Obj.is() && !rCompare.mpSdrOle2Obj.is());
149  const bool bBothAndEqual(mpSdrOle2Obj.is() && rCompare.mpSdrOle2Obj.is()
150  && mpSdrOle2Obj.get() == rCompare.mpSdrOle2Obj.get());
151 
152  return ((bBothNot || bBothAndEqual)
153  && getObjectTransform() == rCompare.getObjectTransform()
154 
155  // #i104867# to find out if the Graphic content of the
156  // OLE has changed, use GraphicVersion number
157  && mnGraphicVersion == rCompare.mnGraphicVersion
158  );
159  }
160 
161  return false;
162  }
163 
165  {
166  basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0);
167  aRange.transform(getObjectTransform());
168 
169  return aRange;
170  }
171 
172  // provide unique ID
174 
175 } // end of namespace
176 
177 /* 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:1932
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
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
B2DHomMatrix createShearXRotateTranslateB2DHomMatrix(double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
const Graphic * GetGraphic() const
Definition: svdoole2.cxx:1648
bool IsEmptyPresObj() const
Definition: svdobj.hxx:880