xref: /trunk/main/svx/source/sdr/primitive2d/sdrgrafprimitive2d.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "precompiled_svx.hxx"
29 #include <svx/sdr/primitive2d/sdrgrafprimitive2d.hxx>
30 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
31 #include <basegfx/polygon/b2dpolygontools.hxx>
32 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
33 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
34 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
35 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
36 #include <basegfx/polygon/b2dpolygon.hxx>
37 
38 //////////////////////////////////////////////////////////////////////////////
39 
40 namespace drawinglayer
41 {
42     namespace primitive2d
43     {
44         Primitive2DSequence SdrGrafPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
45         {
46             Primitive2DSequence  aRetval;
47 
48             // create unit outline polygon
49             basegfx::B2DPolygon aUnitOutline(basegfx::tools::createUnitPolygon());
50 
51             // add fill, but only when graphic ist transparent
52             if(!getSdrLFSTAttribute().getFill().isDefault() && isTransparent())
53             {
54                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
55                     createPolyPolygonFillPrimitive(
56                         basegfx::B2DPolyPolygon(aUnitOutline),
57                         getTransform(),
58                         getSdrLFSTAttribute().getFill(),
59                         getSdrLFSTAttribute().getFillFloatTransGradient()));
60             }
61 
62             // add line
63             if(!getSdrLFSTAttribute().getLine().isDefault())
64             {
65                 // if line width is given, polygon needs to be grown by half of it to make the
66                 // outline to be outside of the bitmap
67                 if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
68                 {
69                     // decompose to get scale
70                     basegfx::B2DVector aScale, aTranslate;
71                     double fRotate, fShearX;
72                     getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
73 
74                     // create expanded range (add relative half line width to unit rectangle)
75                     double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
76                     double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
77                     double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
78                     const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY);
79                     basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange));
80 
81                     appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
82                         createPolygonLinePrimitive(
83                             aExpandedUnitOutline,
84                             getTransform(),
85                             getSdrLFSTAttribute().getLine(),
86                             attribute::SdrLineStartEndAttribute()));
87                 }
88                 else
89                 {
90                     appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
91                         createPolygonLinePrimitive(
92                             aUnitOutline, getTransform(),
93                             getSdrLFSTAttribute().getLine(),
94                             attribute::SdrLineStartEndAttribute()));
95                 }
96             }
97 
98             // add graphic content
99             if(255L != getGraphicAttr().GetTransparency())
100             {
101                 const Primitive2DReference xGraphicContentPrimitive(
102                     new GraphicPrimitive2D(
103                         getTransform(),
104                         getGraphicObject(),
105                         getGraphicAttr()));
106 
107                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xGraphicContentPrimitive);
108             }
109 
110             // add text
111             if(!getSdrLFSTAttribute().getText().isDefault())
112             {
113                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
114                     createTextPrimitive(
115                         basegfx::B2DPolyPolygon(aUnitOutline),
116                         getTransform(),
117                         getSdrLFSTAttribute().getText(),
118                         getSdrLFSTAttribute().getLine(),
119                         false,
120                         false,
121                         false));
122             }
123 
124             // add shadow
125             if(!getSdrLFSTAttribute().getShadow().isDefault())
126             {
127                 aRetval = createEmbeddedShadowPrimitive(
128                     aRetval,
129                     getSdrLFSTAttribute().getShadow());
130             }
131 
132             return aRetval;
133         }
134 
135         SdrGrafPrimitive2D::SdrGrafPrimitive2D(
136             const basegfx::B2DHomMatrix& rTransform,
137             const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
138             const GraphicObject& rGraphicObject,
139             const GraphicAttr& rGraphicAttr)
140         :   BufferedDecompositionPrimitive2D(),
141             maTransform(rTransform),
142             maSdrLFSTAttribute(rSdrLFSTAttribute),
143             maGraphicObject(rGraphicObject),
144             maGraphicAttr(rGraphicAttr)
145         {
146             // reset some values from GraphicAttr which are part of transformation already
147             maGraphicAttr.SetRotation(0L);
148         }
149 
150         bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
151         {
152             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
153             {
154                 const SdrGrafPrimitive2D& rCompare = (SdrGrafPrimitive2D&)rPrimitive;
155 
156                 return (getTransform() == rCompare.getTransform()
157                     && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
158                     && getGraphicObject() == rCompare.getGraphicObject()
159                     && getGraphicAttr() == rCompare.getGraphicAttr());
160             }
161 
162             return false;
163         }
164 
165         bool SdrGrafPrimitive2D::isTransparent() const
166         {
167             return ((0L != getGraphicAttr().GetTransparency()) || (getGraphicObject().IsTransparent()));
168         }
169 
170         // provide unique ID
171         ImplPrimitrive2DIDBlock(SdrGrafPrimitive2D, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D)
172 
173     } // end of namespace primitive2d
174 } // end of namespace drawinglayer
175 
176 //////////////////////////////////////////////////////////////////////////////
177 // eof
178