summaryrefslogtreecommitdiff
path: root/drawinglayer/source/primitive3d/polygonprimitive3d.cxx
blob: 435ccca60716ad66bfbc0711f59291bc002e42e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: polygonprimitive3d.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: aw $ $Date: 2006-08-09 16:51:15 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _DRAWINGLAYER_PRIMITIVE3D_POLYGONPRIMITIVE3D_HXX
#include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
#endif

#ifndef _BGFX_POLYGON_B3DPOLYGONTOOLS_HXX
#include <basegfx/polygon/b3dpolygontools.hxx>
#endif

#ifndef _BGFX_POLYPOLYGON_B3DPOLYGONTOOLS_HXX
#include <basegfx/polygon/b3dpolypolygontools.hxx>
#endif

#ifndef _DRAWINGLAYER_PRIMITIVE3D_POLYGONTUBEPRIMITIVE3D_HXX
#include <drawinglayer/primitive3d/polygontubeprimitive3d.hxx>
#endif

//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
    namespace primitive3d
    {
        polygonHairlinePrimitive3D::polygonHairlinePrimitive3D(const basegfx::B3DPolygon& rPolygon, const basegfx::BColor& rBColor)
        :   basePrimitive3D(),
            maPolygon(rPolygon),
            maBColor(rBColor)
        {
        }

        polygonHairlinePrimitive3D::~polygonHairlinePrimitive3D()
        {
        }

        bool polygonHairlinePrimitive3D::operator==(const basePrimitive3D& rPrimitive) const
        {
            if(getID() == rPrimitive.getID())
            {
                const polygonHairlinePrimitive3D& rCompare = (polygonHairlinePrimitive3D&)rPrimitive;

                return (maPolygon == rCompare.maPolygon
                    && maBColor == rCompare.maBColor);
            }

            return false;
        }

        PrimitiveID polygonHairlinePrimitive3D::getID() const
        {
            return CreatePrimitiveID('P', 'O', 'H', '3');
        }

        basegfx::B3DRange polygonHairlinePrimitive3D::get3DRange() const
        {
            return basegfx::tools::getRange(maPolygon);
        }
    } // end of namespace primitive3d
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
    namespace primitive3d
    {
        void polygonStrokePrimitive3D::decompose(primitiveVector3D& rTarget)
        {
            if(maPolygon.count())
            {
                basegfx::B3DPolyPolygon aHairLinePolyPolygon(maPolygon);

                if(0.0 != maStrokeAttribute.getFullDotDashLen())
                {
                    // apply LineStyle
                    aHairLinePolyPolygon = basegfx::tools::applyLineDashing(aHairLinePolyPolygon, maStrokeAttribute.getDotDashArray(), maStrokeAttribute.getFullDotDashLen());

                    // merge LineStyle polygons to bigger parts
                    aHairLinePolyPolygon = basegfx::tools::mergeDashedLines(aHairLinePolyPolygon);
                }

                if(maStrokeAttribute.getWidth())
                {
                    // create fat line data
                    const double fRadius(maStrokeAttribute.getWidth() / 2.0);
                    const basegfx::tools::B2DLineJoin aLineJoin(maStrokeAttribute.getLineJoin());

                    for(sal_uInt32 a(0L); a < aHairLinePolyPolygon.count(); a++)
                    {
                        // create tube primitives
                        polygonTubePrimitive3D* pNew = new polygonTubePrimitive3D(aHairLinePolyPolygon.getB3DPolygon(a),
                            maStrokeAttribute.getColor(),
                            fRadius, aLineJoin);
                        rTarget.push_back(referencedPrimitive3D(*pNew));
                    }
                }
                else
                {
                    // create hair line data for all sub polygons
                    for(sal_uInt32 a(0L); a < aHairLinePolyPolygon.count(); a++)
                    {
                        const basegfx::B3DPolygon aCandidate = aHairLinePolyPolygon.getB3DPolygon(a);
                        basePrimitive3D* pNew = new polygonHairlinePrimitive3D(aCandidate, maStrokeAttribute.getColor());
                        rTarget.push_back(referencedPrimitive3D(*pNew));
                    }
                }
            }
        }

        polygonStrokePrimitive3D::polygonStrokePrimitive3D(
            const basegfx::B3DPolygon& rPolygon,
            const attribute::strokeAttribute& rStrokeAttribute)
        :   basePrimitive3D(),
            maPolygon(rPolygon),
            maStrokeAttribute(rStrokeAttribute)
        {
        }

        polygonStrokePrimitive3D::~polygonStrokePrimitive3D()
        {
        }

        bool polygonStrokePrimitive3D::operator==(const basePrimitive3D& rPrimitive) const
        {
            if(getID() == rPrimitive.getID())
            {
                const polygonStrokePrimitive3D& rCompare = (polygonStrokePrimitive3D&)rPrimitive;

                return (maPolygon == rCompare.maPolygon
                    && maStrokeAttribute == rCompare.maStrokeAttribute);
            }

            return false;
        }

        PrimitiveID polygonStrokePrimitive3D::getID() const
        {
            return CreatePrimitiveID('P', 'L', 'S', '3');
        }
    } // end of namespace primitive3d
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////
// eof