Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrgrafprimitive2d.cxx
blob18bef098575a5359016b9dee38d95f7f4b203e83
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sdr/primitive2d/sdrgrafprimitive2d.hxx>
21 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <sdr/primitive2d/sdrdecompositiontools.hxx>
24 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
25 #include <basegfx/polygon/b2dpolygon.hxx>
26 #include <utility>
28 namespace drawinglayer::primitive2d
30 void SdrGrafPrimitive2D::create2DDecomposition(
31 Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const
33 Primitive2DContainer aRetval;
35 // create unit outline polygon
36 const basegfx::B2DPolygon& aUnitOutline(basegfx::utils::createUnitPolygon());
38 // add fill, but only when graphic is transparent
39 if (!getSdrLFSTAttribute().getFill().isDefault() && isTransparent())
41 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
43 aTransformed.transform(getTransform());
44 aRetval.push_back(
45 createPolyPolygonFillPrimitive(aTransformed, getSdrLFSTAttribute().getFill(),
46 getSdrLFSTAttribute().getFillFloatTransGradient()));
49 // add graphic content
50 if (0 != getGraphicAttr().GetAlpha())
52 // standard graphic fill
53 const Primitive2DReference xGraphicContentPrimitive(
54 new GraphicPrimitive2D(getTransform(), getGraphicObject(), getGraphicAttr()));
55 aRetval.push_back(xGraphicContentPrimitive);
58 // add line
59 if (!getSdrLFSTAttribute().getLine().isDefault())
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())
65 // decompose to get scale
66 basegfx::B2DVector aScale, aTranslate;
67 double fRotate, fShearX;
68 getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
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(
77 basegfx::utils::createPolygonFromRect(aExpandedRange));
79 aExpandedUnitOutline.transform(getTransform());
80 aRetval.push_back(createPolygonLinePrimitive(aExpandedUnitOutline,
81 getSdrLFSTAttribute().getLine(),
82 attribute::SdrLineStartEndAttribute()));
84 else
86 basegfx::B2DPolygon aTransformed(aUnitOutline);
88 aTransformed.transform(getTransform());
89 aRetval.push_back(createPolygonLinePrimitive(aTransformed,
90 getSdrLFSTAttribute().getLine(),
91 attribute::SdrLineStartEndAttribute()));
95 // Soft edges should be before text, since text is not affected by soft edges
96 if (!aRetval.empty() && getSdrLFSTAttribute().getSoftEdgeRadius())
98 aRetval = createEmbeddedSoftEdgePrimitive(std::move(aRetval),
99 getSdrLFSTAttribute().getSoftEdgeRadius());
102 // add text
103 if (!getSdrLFSTAttribute().getText().isDefault())
105 aRetval.push_back(createTextPrimitive(basegfx::B2DPolyPolygon(aUnitOutline), getTransform(),
106 getSdrLFSTAttribute().getText(),
107 getSdrLFSTAttribute().getLine(), false, false));
110 // tdf#132199: put glow before shadow, to have shadow of the glow, not the opposite
111 if (!aRetval.empty() && !getSdrLFSTAttribute().getGlow().isDefault())
113 // glow
114 aRetval = createEmbeddedGlowPrimitive(std::move(aRetval), getSdrLFSTAttribute().getGlow());
117 // add shadow
118 if (!getSdrLFSTAttribute().getShadow().isDefault())
120 aRetval = createEmbeddedShadowPrimitive(std::move(aRetval),
121 getSdrLFSTAttribute().getShadow(), getTransform());
124 rContainer.append(std::move(aRetval));
127 SdrGrafPrimitive2D::SdrGrafPrimitive2D(
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)
136 // reset some values from GraphicAttr which are part of transformation already
137 maGraphicAttr.SetRotation(0_deg10);
140 bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
142 if (BufferedDecompositionPrimitive2D::operator==(rPrimitive))
144 const SdrGrafPrimitive2D& rCompare = static_cast<const SdrGrafPrimitive2D&>(rPrimitive);
146 return (getTransform() == rCompare.getTransform()
147 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
148 && getGraphicObject() == rCompare.getGraphicObject()
149 && getGraphicAttr() == rCompare.getGraphicAttr());
152 return false;
155 bool SdrGrafPrimitive2D::isTransparent() const
157 return ((255 != getGraphicAttr().GetAlpha()) || (getGraphicObject().IsTransparent()));
160 // provide unique ID
161 sal_uInt32 SdrGrafPrimitive2D::getPrimitive2DID() const
163 return PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D;
166 } // end of namespace
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */