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