LibreOffice Module svx (master)  1
sdrgrafprimitive2d.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 
26 
28 {
30  {
31  Primitive2DContainer aRetval;
32 
33  // create unit outline polygon
35 
36  // add fill, but only when graphic is transparent
37  if(!getSdrLFSTAttribute().getFill().isDefault() && isTransparent())
38  {
39  basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
40 
41  aTransformed.transform(getTransform());
42  aRetval.push_back(
44  aTransformed,
45  getSdrLFSTAttribute().getFill(),
46  getSdrLFSTAttribute().getFillFloatTransGradient()));
47  }
48 
49  // add graphic content
50  if(255 != getGraphicAttr().GetTransparency())
51  {
52  // standard graphic fill
53  const Primitive2DReference xGraphicContentPrimitive(
55  getTransform(),
57  getGraphicAttr()));
58  aRetval.push_back(xGraphicContentPrimitive);
59  }
60 
61  // add line
62  if(!getSdrLFSTAttribute().getLine().isDefault())
63  {
64  // if line width is given, polygon needs to be grown by half of it to make the
65  // outline to be outside of the bitmap
66  if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
67  {
68  // decompose to get scale
69  basegfx::B2DVector aScale, aTranslate;
70  double fRotate, fShearX;
71  getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
72 
73  // create expanded range (add relative half line width to unit rectangle)
74  double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
75  double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
76  double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
77  const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY);
78  basegfx::B2DPolygon aExpandedUnitOutline(basegfx::utils::createPolygonFromRect(aExpandedRange));
79 
80  aExpandedUnitOutline.transform(getTransform());
81  aRetval.push_back(
83  aExpandedUnitOutline,
84  getSdrLFSTAttribute().getLine(),
86  }
87  else
88  {
89  basegfx::B2DPolygon aTransformed(aUnitOutline);
90 
91  aTransformed.transform(getTransform());
92  aRetval.push_back(
94  aTransformed,
95  getSdrLFSTAttribute().getLine(),
97  }
98  }
99 
100  // Soft edges should be before text, since text is not affected by soft edges
101  if (!aRetval.empty() && getSdrLFSTAttribute().getSoftEdgeRadius())
102  {
104  aRetval, getSdrLFSTAttribute().getSoftEdgeRadius());
105  }
106 
107  // add text
108  if(!getSdrLFSTAttribute().getText().isDefault())
109  {
110  aRetval.push_back(
112  basegfx::B2DPolyPolygon(aUnitOutline),
113  getTransform(),
114  getSdrLFSTAttribute().getText(),
115  getSdrLFSTAttribute().getLine(),
116  false,
117  false));
118  }
119 
120  // tdf#132199: put glow before shadow, to have shadow of the glow, not the opposite
121  if (!aRetval.empty() && !getSdrLFSTAttribute().getGlow().isDefault())
122  {
123  // glow
124  aRetval = createEmbeddedGlowPrimitive(aRetval, getSdrLFSTAttribute().getGlow());
125  }
126 
127  // add shadow
128  if(!getSdrLFSTAttribute().getShadow().isDefault())
129  {
131  aRetval,
132  getSdrLFSTAttribute().getShadow(),
133  getTransform());
134  }
135 
136  rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end());
137  }
138 
140  const basegfx::B2DHomMatrix& rTransform,
141  const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute,
142  const GraphicObject& rGraphicObject,
143  const GraphicAttr& rGraphicAttr)
145  maTransform(rTransform),
146  maSdrLFSTAttribute(rSdrLFSTAttribute),
147  maGraphicObject(rGraphicObject),
148  maGraphicAttr(rGraphicAttr)
149  {
150  // reset some values from GraphicAttr which are part of transformation already
152  }
153 
154  bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
155  {
156  if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
157  {
158  const SdrGrafPrimitive2D& rCompare = static_cast<const SdrGrafPrimitive2D&>(rPrimitive);
159 
160  return (getTransform() == rCompare.getTransform()
161  && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
162  && getGraphicObject() == rCompare.getGraphicObject()
163  && getGraphicAttr() == rCompare.getGraphicAttr());
164  }
165 
166  return false;
167  }
168 
170  {
171  return ((0 != getGraphicAttr().GetTransparency())
172  || (getGraphicObject().IsTransparent()));
173  }
174 
175  // provide unique ID
177 
178 } // end of namespace
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Primitive2DContainer createEmbeddedGlowPrimitive(const Primitive2DContainer &rContent, const attribute::SdrGlowAttribute &rGlow)
B2DPolygon const & createUnitPolygon()
double getX() const
SdrGrafPrimitive2D(const ::basegfx::B2DHomMatrix &rTransform, const attribute::SdrLineFillEffectsTextAttribute &rSdrLFSTAttribute, const GraphicObject &rGraphicObject, const GraphicAttr &rGraphicAttr)
double getY() const
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &aViewInformation) const override
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)
ImplPrimitive2DIDBlock(BorderLinePrimitive2D, PRIMITIVE2D_ID_BORDERLINEPRIMITIVE2D) Primitive2DReference tryMergeBorderLinePrimitive2D(const BorderLinePrimitive2D *pCandidateA
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
Primitive2DReference createTextPrimitive(const basegfx::B2DPolyPolygon &rUnitPolyPolygon, const basegfx::B2DHomMatrix &rObjectTransform, const attribute::SdrTextAttribute &rText, const attribute::SdrLineAttribute &rStroke, bool bCellText, bool bWordWrap)
#define PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D
const GraphicObject & getGraphicObject() const
void transform(const basegfx::B2DHomMatrix &rMatrix)
Primitive2DContainer createEmbeddedShadowPrimitive(const Primitive2DContainer &rContent, const attribute::SdrShadowAttribute &rShadow, const basegfx::B2DHomMatrix &rObjectMatrix)
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
Primitive2DContainer createEmbeddedSoftEdgePrimitive(const Primitive2DContainer &rContent, sal_Int32 nRadius)
const attribute::SdrLineFillEffectsTextAttribute & getSdrLFSTAttribute() const
Primitive2DReference createPolygonLinePrimitive(const basegfx::B2DPolygon &rPolygon, const attribute::SdrLineAttribute &rLine, const attribute::SdrLineStartEndAttribute &rStroke)
void SetRotation(sal_uInt16 nRotate10)
Primitive2DReference createPolyPolygonFillPrimitive(const basegfx::B2DPolyPolygon &rPolyPolygon, const attribute::SdrFillAttribute &rFill, const attribute::FillGradientAttribute &rFillGradient)
const ::basegfx::B2DHomMatrix & getTransform() const