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)
115  maTransform(rTransform),
116  maSdrLFSTAttribute(rSdrLFSTAttribute)
117  {
118  }
119 
121  {
122  if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
123  {
124  const SdrEllipsePrimitive2D& rCompare = static_cast<const SdrEllipsePrimitive2D&>(rPrimitive);
125 
126  return (getTransform() == rCompare.getTransform()
127  && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute());
128  }
129 
130  return false;
131  }
132 
133  // provide unique ID
135 
136 
137 
138  void SdrEllipseSegmentPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const
139  {
140  Primitive2DContainer aRetval;
141 
142  // create unit outline polygon
143  basegfx::B2DPolygon aUnitOutline(basegfx::utils::createPolygonFromUnitEllipseSegment(mfStartAngle, mfEndAngle));
144 
145  if(mbCloseSegment)
146  {
147  if(mbCloseUsingCenter)
148  {
149  // for compatibility, insert the center point at polygon start to get the same
150  // line stroking pattern as the old painting mechanisms.
151  aUnitOutline.insert(0, basegfx::B2DPoint(0.0, 0.0));
152  }
153 
154  aUnitOutline.setClosed(true);
155  }
156 
157  // move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
158  const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
160 
161  // apply to the geometry
162  aUnitOutline.transform(aUnitCorrectionMatrix);
163 
164  // add fill
165  if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline.isClosed())
166  {
167  basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
168 
169  aTransformed.transform(getTransform());
170  aRetval.push_back(
172  aTransformed,
173  getSdrLFSTAttribute().getFill(),
174  getSdrLFSTAttribute().getFillFloatTransGradient()));
175  }
176 
177  // add line
178  if(getSdrLFSTAttribute().getLine().isDefault())
179  {
180  // create invisible line for HitTest/BoundRect
181  aRetval.push_back(
183  false,
184  basegfx::B2DPolyPolygon(aUnitOutline),
185  getTransform()));
186  }
187  else
188  {
189  basegfx::B2DPolygon aTransformed(aUnitOutline);
190 
191  aTransformed.transform(getTransform());
192  aRetval.push_back(
194  aTransformed,
195  getSdrLFSTAttribute().getLine(),
196  getSdrLFSTAttribute().getLineStartEnd()));
197  }
198 
199  // add text
200  if(!getSdrLFSTAttribute().getText().isDefault())
201  {
202  aRetval.push_back(
204  basegfx::B2DPolyPolygon(aUnitOutline),
205  getTransform(),
206  getSdrLFSTAttribute().getText(),
207  getSdrLFSTAttribute().getLine(),
208  false,
209  false));
210  }
211 
212  // add shadow
213  if(!getSdrLFSTAttribute().getShadow().isDefault())
214  {
216  aRetval,
217  getSdrLFSTAttribute().getShadow());
218  }
219 
220  rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end());
221  }
222 
224  const basegfx::B2DHomMatrix& rTransform,
225  const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute,
226  double fStartAngle,
227  double fEndAngle,
228  bool bCloseSegment,
229  bool bCloseUsingCenter)
230  : SdrEllipsePrimitive2D(rTransform, rSdrLFSTAttribute),
231  mfStartAngle(fStartAngle),
232  mfEndAngle(fEndAngle),
233  mbCloseSegment(bCloseSegment),
234  mbCloseUsingCenter(bCloseUsingCenter)
235  {
236  }
237 
238  bool SdrEllipseSegmentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
239  {
240  if(SdrEllipsePrimitive2D::operator==(rPrimitive))
241  {
242  const SdrEllipseSegmentPrimitive2D& rCompare = static_cast<const SdrEllipseSegmentPrimitive2D&>(rPrimitive);
243 
244  if( mfStartAngle == rCompare.mfStartAngle
245  && mfEndAngle == rCompare.mfEndAngle
246  && mbCloseSegment == rCompare.mbCloseSegment
247  && mbCloseUsingCenter == rCompare.mbCloseUsingCenter)
248  {
249  return true;
250  }
251  }
252 
253  return false;
254  }
255 
256  // provide unique ID
258 
259 } // end of namespace
260 
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
B2DPolygon const & createPolygonFromUnitCircle(sal_uInt32 nStartQuadrant=0)
const ::basegfx::B2DHomMatrix & getTransform() const
#define PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D
B2DPolygon createPolygonFromUnitEllipseSegment(double fStart, double fEnd)
ImplPrimitive2DIDBlock(SdrEllipsePrimitive2D, PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D) void SdrEllipseSegmentPrimitive2D
const attribute::SdrLineFillEffectsTextAttribute & getSdrLFSTAttribute() const
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)
ImplPrimitive2DIDBlock(BorderLinePrimitive2D, PRIMITIVE2D_ID_BORDERLINEPRIMITIVE2D) Primitive2DReference tryMergeBorderLinePrimitive2D(const BorderLinePrimitive2D *pCandidateA
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)
Primitive2DContainer createEmbeddedShadowPrimitive(const Primitive2DContainer &rContent, const attribute::SdrShadowAttribute &rShadow, const basegfx::B2DHomMatrix &rObjectMatrix)
void setClosed(bool bNew)
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
Primitive2DReference createHiddenGeometryPrimitives2D(const basegfx::B2DHomMatrix &rMatrix)
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)