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