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