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