Line data Source code
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 :
20 : #include <sdr/primitive2d/sdrgrafprimitive2d.hxx>
21 : #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
22 : #include <basegfx/polygon/b2dpolygontools.hxx>
23 : #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
24 : #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
25 : #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
26 : #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
27 : #include <basegfx/polygon/b2dpolygon.hxx>
28 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
29 : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
30 :
31 : namespace drawinglayer
32 : {
33 : namespace primitive2d
34 : {
35 1134 : Primitive2DSequence SdrGrafPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
36 : {
37 1134 : Primitive2DSequence aRetval;
38 :
39 : // create unit outline polygon
40 2268 : basegfx::B2DPolygon aUnitOutline(basegfx::tools::createUnitPolygon());
41 :
42 : // add fill, but only when graphic ist transparent
43 1134 : if(!getSdrLFSTAttribute().getFill().isDefault() && isTransparent())
44 : {
45 4 : basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
46 :
47 4 : aTransformed.transform(getTransform());
48 : appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
49 : createPolyPolygonFillPrimitive(
50 : aTransformed,
51 4 : getSdrLFSTAttribute().getFill(),
52 8 : getSdrLFSTAttribute().getFillFloatTransGradient()));
53 : }
54 :
55 : // add graphic content
56 1134 : if(255L != getGraphicAttr().GetTransparency())
57 : {
58 : // standard graphic fill
59 : const Primitive2DReference xGraphicContentPrimitive(
60 : new GraphicPrimitive2D(
61 : getTransform(),
62 : getGraphicObject(),
63 1134 : getGraphicAttr()));
64 :
65 1134 : appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xGraphicContentPrimitive);
66 : }
67 :
68 : // add line
69 1134 : if(!getSdrLFSTAttribute().getLine().isDefault())
70 : {
71 : // if line width is given, polygon needs to be grown by half of it to make the
72 : // outline to be outside of the bitmap
73 0 : if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
74 : {
75 : // decompose to get scale
76 0 : basegfx::B2DVector aScale, aTranslate;
77 : double fRotate, fShearX;
78 0 : getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
79 :
80 : // create expanded range (add relative half line width to unit rectangle)
81 0 : double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
82 0 : double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
83 0 : double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
84 0 : const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY);
85 0 : basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange));
86 :
87 0 : aExpandedUnitOutline.transform(getTransform());
88 : appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
89 : createPolygonLinePrimitive(
90 : aExpandedUnitOutline,
91 0 : getSdrLFSTAttribute().getLine(),
92 0 : attribute::SdrLineStartEndAttribute()));
93 : }
94 : else
95 : {
96 0 : basegfx::B2DPolygon aTransformed(aUnitOutline);
97 :
98 0 : aTransformed.transform(getTransform());
99 : appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
100 : createPolygonLinePrimitive(
101 : aTransformed,
102 0 : getSdrLFSTAttribute().getLine(),
103 0 : attribute::SdrLineStartEndAttribute()));
104 : }
105 : }
106 :
107 : // add text
108 1134 : if(!getSdrLFSTAttribute().getText().isDefault())
109 : {
110 : appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
111 : createTextPrimitive(
112 : basegfx::B2DPolyPolygon(aUnitOutline),
113 0 : getTransform(),
114 0 : getSdrLFSTAttribute().getText(),
115 0 : getSdrLFSTAttribute().getLine(),
116 : false,
117 : false,
118 0 : false));
119 : }
120 :
121 : // add shadow
122 1134 : if(!getSdrLFSTAttribute().getShadow().isDefault())
123 : {
124 60 : aRetval = createEmbeddedShadowPrimitive(
125 : aRetval,
126 60 : getSdrLFSTAttribute().getShadow());
127 : }
128 :
129 2268 : return aRetval;
130 : }
131 :
132 2068 : SdrGrafPrimitive2D::SdrGrafPrimitive2D(
133 : const basegfx::B2DHomMatrix& rTransform,
134 : const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
135 : const GraphicObject& rGraphicObject,
136 : const GraphicAttr& rGraphicAttr)
137 : : BufferedDecompositionPrimitive2D(),
138 : maTransform(rTransform),
139 : maSdrLFSTAttribute(rSdrLFSTAttribute),
140 : maGraphicObject(rGraphicObject),
141 2068 : maGraphicAttr(rGraphicAttr)
142 : {
143 : // reset some values from GraphicAttr which are part of transformation already
144 2068 : maGraphicAttr.SetRotation(0L);
145 2068 : }
146 :
147 1416 : bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
148 : {
149 1416 : if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
150 : {
151 1416 : const SdrGrafPrimitive2D& rCompare = static_cast<const SdrGrafPrimitive2D&>(rPrimitive);
152 :
153 1416 : return (getTransform() == rCompare.getTransform()
154 1302 : && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
155 1302 : && getGraphicObject() == rCompare.getGraphicObject()
156 2718 : && getGraphicAttr() == rCompare.getGraphicAttr());
157 : }
158 :
159 0 : return false;
160 : }
161 :
162 4 : bool SdrGrafPrimitive2D::isTransparent() const
163 : {
164 4 : return ((0L != getGraphicAttr().GetTransparency())
165 4 : || (getGraphicObject().IsTransparent()));
166 : }
167 :
168 : // provide unique ID
169 3460 : ImplPrimitive2DIDBlock(SdrGrafPrimitive2D, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D)
170 :
171 : } // end of namespace primitive2d
172 651 : } // end of namespace drawinglayer
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|