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  Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const
31 {
32  Primitive2DContainer aRetval;
33 
34  // create unit outline polygon
36 
37  // add fill, but only when graphic is transparent
38  if (!getSdrLFSTAttribute().getFill().isDefault() && isTransparent())
39  {
40  basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
41 
42  aTransformed.transform(getTransform());
43  aRetval.push_back(
44  createPolyPolygonFillPrimitive(aTransformed, getSdrLFSTAttribute().getFill(),
45  getSdrLFSTAttribute().getFillFloatTransGradient()));
46  }
47 
48  // add graphic content
49  if (0 != getGraphicAttr().GetAlpha())
50  {
51  // standard graphic fill
52  const Primitive2DReference xGraphicContentPrimitive(
54  aRetval.push_back(xGraphicContentPrimitive);
55  }
56 
57  // add line
58  if (!getSdrLFSTAttribute().getLine().isDefault())
59  {
60  // if line width is given, polygon needs to be grown by half of it to make the
61  // outline to be outside of the bitmap
62  if (0.0 != getSdrLFSTAttribute().getLine().getWidth())
63  {
64  // decompose to get scale
65  basegfx::B2DVector aScale, aTranslate;
66  double fRotate, fShearX;
67  getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
68 
69  // create expanded range (add relative half line width to unit rectangle)
70  double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
71  double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
72  double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
73  const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX,
74  1.0 + fScaleY);
75  basegfx::B2DPolygon aExpandedUnitOutline(
77 
78  aExpandedUnitOutline.transform(getTransform());
79  aRetval.push_back(createPolygonLinePrimitive(aExpandedUnitOutline,
80  getSdrLFSTAttribute().getLine(),
82  }
83  else
84  {
85  basegfx::B2DPolygon aTransformed(aUnitOutline);
86 
87  aTransformed.transform(getTransform());
88  aRetval.push_back(createPolygonLinePrimitive(aTransformed,
89  getSdrLFSTAttribute().getLine(),
91  }
92  }
93 
94  // Soft edges should be before text, since text is not affected by soft edges
95  if (!aRetval.empty() && getSdrLFSTAttribute().getSoftEdgeRadius())
96  {
97  aRetval = createEmbeddedSoftEdgePrimitive(std::move(aRetval),
98  getSdrLFSTAttribute().getSoftEdgeRadius());
99  }
100 
101  // add text
102  if (!getSdrLFSTAttribute().getText().isDefault())
103  {
104  aRetval.push_back(createTextPrimitive(basegfx::B2DPolyPolygon(aUnitOutline), getTransform(),
105  getSdrLFSTAttribute().getText(),
106  getSdrLFSTAttribute().getLine(), false, false));
107  }
108 
109  // tdf#132199: put glow before shadow, to have shadow of the glow, not the opposite
110  if (!aRetval.empty() && !getSdrLFSTAttribute().getGlow().isDefault())
111  {
112  // glow
113  aRetval = createEmbeddedGlowPrimitive(aRetval, getSdrLFSTAttribute().getGlow());
114  }
115 
116  // add shadow
117  if (!getSdrLFSTAttribute().getShadow().isDefault())
118  {
119  aRetval = createEmbeddedShadowPrimitive(aRetval, getSdrLFSTAttribute().getShadow(),
120  getTransform());
121  }
122 
123  rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end());
124 }
125 
127  const basegfx::B2DHomMatrix& rTransform,
128  const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute,
129  const GraphicObject& rGraphicObject, const GraphicAttr& rGraphicAttr)
130  : maTransform(rTransform)
131  , maSdrLFSTAttribute(rSdrLFSTAttribute)
132  , maGraphicObject(rGraphicObject)
133  , maGraphicAttr(rGraphicAttr)
134 {
135  // reset some values from GraphicAttr which are part of transformation already
136  maGraphicAttr.SetRotation(0_deg10);
137 }
138 
139 bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
140 {
141  if (BufferedDecompositionPrimitive2D::operator==(rPrimitive))
142  {
143  const SdrGrafPrimitive2D& rCompare = static_cast<const SdrGrafPrimitive2D&>(rPrimitive);
144 
145  return (getTransform() == rCompare.getTransform()
146  && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
147  && getGraphicObject() == rCompare.getGraphicObject()
148  && getGraphicAttr() == rCompare.getGraphicAttr());
149  }
150 
151  return false;
152 }
153 
155 {
156  return ((255 != getGraphicAttr().GetAlpha()) || (getGraphicObject().IsTransparent()));
157 }
158 
159 // provide unique ID
161 {
163 }
164 
165 } // end of namespace
166 
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double getY() const
Primitive2DContainer createEmbeddedGlowPrimitive(const Primitive2DContainer &rContent, const attribute::SdrGlowAttribute &rGlow)
B2DPolygon const & createUnitPolygon()
SdrGrafPrimitive2D(const ::basegfx::B2DHomMatrix &rTransform, const attribute::SdrLineFillEffectsTextAttribute &rSdrLFSTAttribute, const GraphicObject &rGraphicObject, const GraphicAttr &rGraphicAttr)
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &aViewInformation) const override
Primitive2DContainer createEmbeddedShadowPrimitive(const 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
virtual sal_uInt32 getPrimitive2DID() const override
void SetRotation(Degree10 nRotate10)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
void transform(const basegfx::B2DHomMatrix &rMatrix)
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)
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
Primitive2DContainer createEmbeddedSoftEdgePrimitive(Primitive2DContainer &&aContent, sal_Int32 nRadius)
const attribute::SdrLineFillEffectsTextAttribute & getSdrLFSTAttribute() 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)
const ::basegfx::B2DHomMatrix & getTransform() const