LibreOffice Module svx (master)  1
sdrellipseprimitive2d.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 
28 
29 
30 using namespace com::sun::star;
31 
32 
34 {
35  void SdrEllipsePrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const
36  {
37  Primitive2DContainer aRetval;
38 
39  // create unit outline polygon
40  // Do use createPolygonFromUnitCircle, but let create from first quadrant to mimic old geometry creation.
41  // This is needed to have the same look when stroke is used since the polygon start point defines the
42  // stroke start, too.
44 
45  // scale and move UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
46  const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
48 
49  // apply to the geometry
50  aUnitOutline.transform(aUnitCorrectionMatrix);
51 
52  // add fill
53  if(!getSdrLFSTAttribute().getFill().isDefault())
54  {
55  basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
56 
57  aTransformed.transform(getTransform());
58  aRetval.push_back(
60  aTransformed,
61  getSdrLFSTAttribute().getFill(),
62  getSdrLFSTAttribute().getFillFloatTransGradient()));
63  }
64 
65  // add line
66  if(getSdrLFSTAttribute().getLine().isDefault())
67  {
68  // create invisible line for HitTest/BoundRect
69  aRetval.push_back(
71  false,
72  basegfx::B2DPolyPolygon(aUnitOutline),
73  getTransform()));
74  }
75  else
76  {
77  basegfx::B2DPolygon aTransformed(aUnitOutline);
78 
79  aTransformed.transform(getTransform());
80  aRetval.push_back(
82  aTransformed,
83  getSdrLFSTAttribute().getLine(),
85  }
86 
87  // add text
88  if(!getSdrLFSTAttribute().getText().isDefault())
89  {
90  aRetval.push_back(
92  basegfx::B2DPolyPolygon(aUnitOutline),
93  getTransform(),
94  getSdrLFSTAttribute().getText(),
95  getSdrLFSTAttribute().getLine(),
96  false,
97  false));
98  }
99 
100  // add shadow
101  if(!getSdrLFSTAttribute().getShadow().isDefault())
102  {
104  aRetval,
105  getSdrLFSTAttribute().getShadow());
106  }
107 
108  rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end());
109  }
110 
111  SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
112  const basegfx::B2DHomMatrix& rTransform,
113  const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute)
114  : maTransform(rTransform),
115  maSdrLFSTAttribute(rSdrLFSTAttribute)
116  {
117  }
118 
120  {
121  if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
122  {
123  const SdrEllipsePrimitive2D& rCompare = static_cast<const SdrEllipsePrimitive2D&>(rPrimitive);
124 
125  return (getTransform() == rCompare.getTransform()
126  && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute());
127  }
128 
129  return false;
130  }
131 
132  // provide unique ID
134  {
136  }
137 
138 
139 
141  {
142  Primitive2DContainer aRetval;
143 
144  // create unit outline polygon
146 
147  if(mbCloseSegment)
148  {
150  {
151  // for compatibility, insert the center point at polygon start to get the same
152  // line stroking pattern as the old painting mechanisms.
153  aUnitOutline.insert(0, basegfx::B2DPoint(0.0, 0.0));
154  }
155 
156  aUnitOutline.setClosed(true);
157  }
158 
159  // move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
160  const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
162 
163  // apply to the geometry
164  aUnitOutline.transform(aUnitCorrectionMatrix);
165 
166  // add fill
167  if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline.isClosed())
168  {
169  basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
170 
171  aTransformed.transform(getTransform());
172  aRetval.push_back(
174  aTransformed,
175  getSdrLFSTAttribute().getFill(),
176  getSdrLFSTAttribute().getFillFloatTransGradient()));
177  }
178 
179  // add line
180  if(getSdrLFSTAttribute().getLine().isDefault())
181  {
182  // create invisible line for HitTest/BoundRect
183  aRetval.push_back(
185  false,
186  basegfx::B2DPolyPolygon(aUnitOutline),
187  getTransform()));
188  }
189  else
190  {
191  basegfx::B2DPolygon aTransformed(aUnitOutline);
192 
193  aTransformed.transform(getTransform());
194  aRetval.push_back(
196  aTransformed,
197  getSdrLFSTAttribute().getLine(),
198  getSdrLFSTAttribute().getLineStartEnd()));
199  }
200 
201  // add text
202  if(!getSdrLFSTAttribute().getText().isDefault())
203  {
204  aRetval.push_back(
206  basegfx::B2DPolyPolygon(aUnitOutline),
207  getTransform(),
208  getSdrLFSTAttribute().getText(),
209  getSdrLFSTAttribute().getLine(),
210  false,
211  false));
212  }
213 
214  // add shadow
215  if(!getSdrLFSTAttribute().getShadow().isDefault())
216  {
218  aRetval,
219  getSdrLFSTAttribute().getShadow());
220  }
221 
222  rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end());
223  }
224 
226  const basegfx::B2DHomMatrix& rTransform,
227  const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute,
228  double fStartAngle,
229  double fEndAngle,
230  bool bCloseSegment,
231  bool bCloseUsingCenter)
232  : SdrEllipsePrimitive2D(rTransform, rSdrLFSTAttribute),
233  mfStartAngle(fStartAngle),
234  mfEndAngle(fEndAngle),
235  mbCloseSegment(bCloseSegment),
236  mbCloseUsingCenter(bCloseUsingCenter)
237  {
238  }
239 
241  {
242  if(SdrEllipsePrimitive2D::operator==(rPrimitive))
243  {
244  const SdrEllipseSegmentPrimitive2D& rCompare = static_cast<const SdrEllipseSegmentPrimitive2D&>(rPrimitive);
245 
246  if( mfStartAngle == rCompare.mfStartAngle
247  && mfEndAngle == rCompare.mfEndAngle
248  && mbCloseSegment == rCompare.mbCloseSegment
249  && mbCloseUsingCenter == rCompare.mbCloseUsingCenter)
250  {
251  return true;
252  }
253  }
254 
255  return false;
256  }
257 
258  // provide unique ID
260  {
262  }
263 
264 } // end of namespace
265 
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
B2DPolygon const & createPolygonFromUnitCircle(sal_uInt32 nStartQuadrant=0)
const ::basegfx::B2DHomMatrix & getTransform() const
#define PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
B2DPolygon createPolygonFromUnitEllipseSegment(double fStart, double fEnd)
Primitive2DContainer createEmbeddedShadowPrimitive(const Primitive2DContainer &rContent, const attribute::SdrShadowAttribute &rShadow, const basegfx::B2DHomMatrix &rObjectMatrix, const Primitive2DContainer *pContentForShadow)
const attribute::SdrLineFillEffectsTextAttribute & getSdrLFSTAttribute() const
virtual sal_uInt32 getPrimitive2DID() const override
void insert(sal_uInt32 nIndex, const basegfx::B2DPoint &rPoint, sal_uInt32 nCount=1)
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
#define PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D
bool isClosed() const
basegfx::B2DHomMatrix maTransform
void transform(const basegfx::B2DHomMatrix &rMatrix)
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)
SdrEllipseSegmentPrimitive2D(const ::basegfx::B2DHomMatrix &rTransform, const attribute::SdrLineFillEffectsTextAttribute &rSdrLFSTAttribute, double fStartAngle, double fEndAngle, bool bCloseSegment, bool bCloseUsingCenter)
void setClosed(bool bNew)
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
Primitive2DReference createHiddenGeometryPrimitives2D(const basegfx::B2DHomMatrix &rMatrix)
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &aViewInformation) const override
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)