LibreOffice Module svx (master)  1
sdrole2primitive2d.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 
27 
28 
29 using namespace com::sun::star;
30 
31 
32 namespace drawinglayer
33 {
34  namespace primitive2d
35  {
36  SdrOle2Primitive2D::SdrOle2Primitive2D(
37  const Primitive2DContainer& rOLEContent,
38  const basegfx::B2DHomMatrix& rTransform,
39  const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute)
40  : BasePrimitive2D(),
41  maOLEContent(rOLEContent),
42  maTransform(rTransform),
43  maSdrLFSTAttribute(rSdrLFSTAttribute)
44  {
45  }
46 
47  bool SdrOle2Primitive2D::operator==(const BasePrimitive2D& rPrimitive) const
48  {
49  if(BasePrimitive2D::operator==(rPrimitive))
50  {
51  const SdrOle2Primitive2D& rCompare = static_cast<const SdrOle2Primitive2D&>(rPrimitive);
52 
53  // #i108636# The standard operator== on two UNO sequences did not work as i
54  // would have expected; it just checks the .is() states and the data type
55  // of the sequence. What i need here is detection of equality of the whole
56  // sequence content, thus i need to use the arePrimitive2DSequencesEqual helper
57  // here instead of the operator== which lead to always returning false and thus
58  // always re-decompositions of the subcontent.
59  if(getOLEContent() == rCompare.getOLEContent()
60  && getTransform() == rCompare.getTransform()
61  && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute())
62  {
63  return true;
64  }
65  }
66 
67  return false;
68  }
69 
71  {
72  // to take care of getSdrLFSTAttribute() later, the same as in SdrGrafPrimitive2D::create2DDecomposition
73  // should happen. For the moment we only need the OLE itself
74  // Added complete primitive preparation using getSdrLFSTAttribute() now.
75  Primitive2DContainer aRetval;
76 
77  // create unit outline polygon
79 
80  // add fill
81  if(!getSdrLFSTAttribute().getFill().isDefault())
82  {
83  basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
84 
85  aTransformed.transform(getTransform());
86  aRetval.push_back(
88  aTransformed,
89  getSdrLFSTAttribute().getFill(),
90  getSdrLFSTAttribute().getFillFloatTransGradient()));
91  }
92 
93  // add line
94  // #i97981# condition was inverse to purpose. When being compatible to paint version,
95  // border needs to be suppressed
96  if(!getSdrLFSTAttribute().getLine().isDefault())
97  {
98  // if line width is given, polygon needs to be grown by half of it to make the
99  // outline to be outside of the bitmap
100  if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
101  {
102  // decompose to get scale
103  basegfx::B2DVector aScale, aTranslate;
104  double fRotate, fShearX;
105  getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
106 
107  // create expanded range (add relative half line width to unit rectangle)
108  double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
109  double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
110  double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
111  const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY);
112  basegfx::B2DPolygon aExpandedUnitOutline(basegfx::utils::createPolygonFromRect(aExpandedRange));
113 
114  aExpandedUnitOutline.transform(getTransform());
115  aRetval.push_back(
117  aExpandedUnitOutline,
118  getSdrLFSTAttribute().getLine(),
120  }
121  else
122  {
123  basegfx::B2DPolygon aTransformed(aUnitOutline);
124 
125  aTransformed.transform(getTransform());
126  aRetval.push_back(
128  aTransformed,
129  getSdrLFSTAttribute().getLine(),
131  }
132  }
133  else
134  {
135  // if initially no line is defined, create one for HitTest and BoundRect
136  aRetval.push_back(
138  false,
139  basegfx::B2DPolyPolygon(aUnitOutline),
140  getTransform()));
141  }
142 
143  // add graphic content
144  aRetval.append(getOLEContent());
145 
146  // add text, no need to suppress to stay compatible since text was
147  // always supported by the old paints, too
148  if(!getSdrLFSTAttribute().getText().isDefault())
149  {
150  aRetval.push_back(
152  basegfx::B2DPolyPolygon(aUnitOutline),
153  getTransform(),
154  getSdrLFSTAttribute().getText(),
155  getSdrLFSTAttribute().getLine(),
156  false,
157  false));
158  }
159 
160  // add shadow
161  if(!getSdrLFSTAttribute().getShadow().isDefault())
162  {
164  aRetval,
165  getSdrLFSTAttribute().getShadow());
166  }
167 
168  rVisitor.append(aRetval);
169  }
170 
171  // provide unique ID
173 
174  } // end of namespace primitive2d
175 } // end of namespace drawinglayer
176 
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define PRIMITIVE2D_ID_SDROLE2PRIMITIVE2D
ImplPrimitive2DIDBlock(BorderLinePrimitive2D, PRIMITIVE2D_ID_BORDERLINEPRIMITIVE2D) Primitive2DReference tryMergeBorderLinePrimitive2D(const Primitive2DReference &rCandidateA
B2DPolygon const & createUnitPolygon()
double getX() const
double getY() const
const attribute::SdrLineFillShadowTextAttribute & getSdrLFSTAttribute() const
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
Primitive2DReference createPolygonLinePrimitive(const basegfx::B2DPolygon &rPolygon, const attribute::SdrLineAttribute &rLine, const attribute::SdrLineStartEndAttribute &rStroke)
const basegfx::B2DHomMatrix & getTransform() const
Primitive2DReference createPolyPolygonFillPrimitive(const basegfx::B2DPolyPolygon &rPolyPolygon, const attribute::SdrFillAttribute &rFill, const attribute::FillGradientAttribute &rFillGradient)
bool decompose(B2DTuple &rScale, B2DTuple &rTranslate, double &rRotate, double &rShearX) const
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
Primitive2DReference createTextPrimitive(const basegfx::B2DPolyPolygon &rUnitPolyPolygon, const basegfx::B2DHomMatrix &rObjectTransform, const attribute::SdrTextAttribute &rText, const attribute::SdrLineAttribute &rStroke, bool bCellText, bool bWordWrap)
void transform(const basegfx::B2DHomMatrix &rMatrix)
virtual void append(const Primitive2DReference &) override
virtual void get2DDecomposition(Primitive2DDecompositionVisitor &rVisitor, const geometry::ViewInformation2D &aViewInformation) const override
void transform(const basegfx::B2DHomMatrix &rMatrix)
basegfx::B2DHomMatrix const maTransform
virtual void append(const Primitive2DReference &)=0
Primitive2DReference createHiddenGeometryPrimitives2D(const basegfx::B2DHomMatrix &rMatrix)
const Primitive2DContainer & getOLEContent() const
Primitive2DContainer createEmbeddedShadowPrimitive(const Primitive2DContainer &rContent, const attribute::SdrShadowAttribute &rShadow)