xref: /AOO42X/main/svx/source/sdr/primitive2d/sdrgrafprimitive2d.cxx (revision b1c5455db1639c48e26c568e4fa7ee78ca5d60ee)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22cdf0e10cSrcweir #include "precompiled_svx.hxx"
23cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrgrafprimitive2d.hxx>
24cdf0e10cSrcweir #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
25cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
26cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
27cdf0e10cSrcweir #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
28cdf0e10cSrcweir #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
30cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
31ddde725dSArmin Le Grand #include <basegfx/matrix/b2dhommatrixtools.hxx>
32ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace drawinglayer
37cdf0e10cSrcweir {
38cdf0e10cSrcweir     namespace primitive2d
39cdf0e10cSrcweir     {
create2DDecomposition(const geometry::ViewInformation2D &) const40cdf0e10cSrcweir         Primitive2DSequence SdrGrafPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
41cdf0e10cSrcweir         {
42cdf0e10cSrcweir             Primitive2DSequence  aRetval;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir             // create unit outline polygon
45cdf0e10cSrcweir             basegfx::B2DPolygon aUnitOutline(basegfx::tools::createUnitPolygon());
46cdf0e10cSrcweir 
47cdf0e10cSrcweir             // add fill, but only when graphic ist transparent
48cdf0e10cSrcweir             if(!getSdrLFSTAttribute().getFill().isDefault() && isTransparent())
49cdf0e10cSrcweir             {
50*64b14621SArmin Le Grand                 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
51*64b14621SArmin Le Grand 
52*64b14621SArmin Le Grand                 aTransformed.transform(getTransform());
53cdf0e10cSrcweir                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
54cdf0e10cSrcweir                     createPolyPolygonFillPrimitive(
55*64b14621SArmin Le Grand                         aTransformed,
56cdf0e10cSrcweir                         getSdrLFSTAttribute().getFill(),
57cdf0e10cSrcweir                         getSdrLFSTAttribute().getFillFloatTransGradient()));
58cdf0e10cSrcweir             }
59cdf0e10cSrcweir 
60025b0597SArmin Le Grand             // add graphic content
61025b0597SArmin Le Grand             if(255L != getGraphicAttr().GetTransparency())
62025b0597SArmin Le Grand             {
63025b0597SArmin Le Grand                 // standard graphic fill
64025b0597SArmin Le Grand                 const Primitive2DReference xGraphicContentPrimitive(
65025b0597SArmin Le Grand                     new GraphicPrimitive2D(
66025b0597SArmin Le Grand                         getTransform(),
67025b0597SArmin Le Grand                         getGraphicObject(),
68025b0597SArmin Le Grand                         getGraphicAttr()));
69025b0597SArmin Le Grand 
70025b0597SArmin Le Grand                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xGraphicContentPrimitive);
71025b0597SArmin Le Grand             }
72025b0597SArmin Le Grand 
73cdf0e10cSrcweir             // add line
74cdf0e10cSrcweir             if(!getSdrLFSTAttribute().getLine().isDefault())
75cdf0e10cSrcweir             {
76cdf0e10cSrcweir                 // if line width is given, polygon needs to be grown by half of it to make the
77cdf0e10cSrcweir                 // outline to be outside of the bitmap
78cdf0e10cSrcweir                 if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
79cdf0e10cSrcweir                 {
80cdf0e10cSrcweir                     // decompose to get scale
81cdf0e10cSrcweir                     basegfx::B2DVector aScale, aTranslate;
82cdf0e10cSrcweir                     double fRotate, fShearX;
83cdf0e10cSrcweir                     getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
84cdf0e10cSrcweir 
85cdf0e10cSrcweir                     // create expanded range (add relative half line width to unit rectangle)
86cdf0e10cSrcweir                     double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
87cdf0e10cSrcweir                     double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
88cdf0e10cSrcweir                     double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
89cdf0e10cSrcweir                     const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY);
90cdf0e10cSrcweir                     basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange));
91cdf0e10cSrcweir 
92*64b14621SArmin Le Grand                     aExpandedUnitOutline.transform(getTransform());
93cdf0e10cSrcweir                     appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
94cdf0e10cSrcweir                         createPolygonLinePrimitive(
95cdf0e10cSrcweir                             aExpandedUnitOutline,
96cdf0e10cSrcweir                             getSdrLFSTAttribute().getLine(),
97cdf0e10cSrcweir                             attribute::SdrLineStartEndAttribute()));
98cdf0e10cSrcweir                 }
99cdf0e10cSrcweir                 else
100cdf0e10cSrcweir                 {
101*64b14621SArmin Le Grand                     basegfx::B2DPolygon aTransformed(aUnitOutline);
102*64b14621SArmin Le Grand 
103*64b14621SArmin Le Grand                     aTransformed.transform(getTransform());
104cdf0e10cSrcweir                     appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
105cdf0e10cSrcweir                         createPolygonLinePrimitive(
106*64b14621SArmin Le Grand                             aTransformed,
107cdf0e10cSrcweir                             getSdrLFSTAttribute().getLine(),
108cdf0e10cSrcweir                             attribute::SdrLineStartEndAttribute()));
109cdf0e10cSrcweir                 }
110cdf0e10cSrcweir             }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir             // add text
113cdf0e10cSrcweir             if(!getSdrLFSTAttribute().getText().isDefault())
114cdf0e10cSrcweir             {
115cdf0e10cSrcweir                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
116cdf0e10cSrcweir                     createTextPrimitive(
117cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aUnitOutline),
118cdf0e10cSrcweir                         getTransform(),
119cdf0e10cSrcweir                         getSdrLFSTAttribute().getText(),
120cdf0e10cSrcweir                         getSdrLFSTAttribute().getLine(),
121cdf0e10cSrcweir                         false,
122cdf0e10cSrcweir                         false,
123cdf0e10cSrcweir                         false));
124cdf0e10cSrcweir             }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir             // add shadow
127cdf0e10cSrcweir             if(!getSdrLFSTAttribute().getShadow().isDefault())
128cdf0e10cSrcweir             {
129cdf0e10cSrcweir                 aRetval = createEmbeddedShadowPrimitive(
130cdf0e10cSrcweir                     aRetval,
131cdf0e10cSrcweir                     getSdrLFSTAttribute().getShadow());
132cdf0e10cSrcweir             }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir             return aRetval;
135cdf0e10cSrcweir         }
136cdf0e10cSrcweir 
SdrGrafPrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute,const GraphicObject & rGraphicObject,const GraphicAttr & rGraphicAttr)137cdf0e10cSrcweir         SdrGrafPrimitive2D::SdrGrafPrimitive2D(
138cdf0e10cSrcweir             const basegfx::B2DHomMatrix& rTransform,
139cdf0e10cSrcweir             const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
140cdf0e10cSrcweir             const GraphicObject& rGraphicObject,
141cdf0e10cSrcweir             const GraphicAttr& rGraphicAttr)
142cdf0e10cSrcweir         :   BufferedDecompositionPrimitive2D(),
143cdf0e10cSrcweir             maTransform(rTransform),
144cdf0e10cSrcweir             maSdrLFSTAttribute(rSdrLFSTAttribute),
145cdf0e10cSrcweir             maGraphicObject(rGraphicObject),
146cdf0e10cSrcweir             maGraphicAttr(rGraphicAttr)
147cdf0e10cSrcweir         {
148cdf0e10cSrcweir             // reset some values from GraphicAttr which are part of transformation already
149cdf0e10cSrcweir             maGraphicAttr.SetRotation(0L);
150cdf0e10cSrcweir         }
151cdf0e10cSrcweir 
operator ==(const BasePrimitive2D & rPrimitive) const152cdf0e10cSrcweir         bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
153cdf0e10cSrcweir         {
154cdf0e10cSrcweir             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
155cdf0e10cSrcweir             {
156cdf0e10cSrcweir                 const SdrGrafPrimitive2D& rCompare = (SdrGrafPrimitive2D&)rPrimitive;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir                 return (getTransform() == rCompare.getTransform()
159cdf0e10cSrcweir                     && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
160cdf0e10cSrcweir                     && getGraphicObject() == rCompare.getGraphicObject()
161cdf0e10cSrcweir                     && getGraphicAttr() == rCompare.getGraphicAttr());
162cdf0e10cSrcweir             }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir             return false;
165cdf0e10cSrcweir         }
166cdf0e10cSrcweir 
isTransparent() const167cdf0e10cSrcweir         bool SdrGrafPrimitive2D::isTransparent() const
168cdf0e10cSrcweir         {
169ddde725dSArmin Le Grand             return ((0L != getGraphicAttr().GetTransparency())
170ddde725dSArmin Le Grand                 || (getGraphicObject().IsTransparent()));
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         // provide unique ID
174cdf0e10cSrcweir         ImplPrimitrive2DIDBlock(SdrGrafPrimitive2D, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D)
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     } // end of namespace primitive2d
177cdf0e10cSrcweir } // end of namespace drawinglayer
178cdf0e10cSrcweir 
179cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
180cdf0e10cSrcweir // eof
181