summaryrefslogtreecommitdiff
path: root/svx/source/svdraw/svdoimp.cxx
blob: 069bbc13709f0daf5eaa8d07297155c478629ec3 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: svdoimp.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: ihi $ $Date: 2006-11-14 13:45:53 $
 *
 *  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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"

#ifndef _SVX_SVDOIMP_HXX
#include <svdoimp.hxx>
#endif

#ifndef _SFXITEMSET_HXX
#include <svtools/itemset.hxx>
#endif

#ifndef _SVX_XLNSTIT_HXX
#include <xlnstit.hxx>
#endif

#ifndef _SVX_XLNEDIT_HXX
#include "xlnedit.hxx"
#endif

#ifndef _SVX_XLNWTIT_HXX
#include <xlnwtit.hxx>
#endif

#ifndef _SVX_XLINEIT0_HXX
#include <xlineit0.hxx>
#endif

#ifndef _SVX_XLNSTWIT_HXX
#include <xlnstwit.hxx>
#endif

#ifndef _SVX_XLNEDWIT_HXX
#include <xlnedwit.hxx>
#endif

#ifndef _SVX_XLNSTCIT_HXX
#include <xlnstcit.hxx>
#endif

#ifndef _SVX_XLNEDCIT_HXX
#include <xlnedcit.hxx>
#endif

#ifndef _SVX_XLINJOIT_HXX
#include <xlinjoit.hxx>
#endif

#ifndef _SVX_XLNDSIT_HXX
#include <xlndsit.hxx>
#endif

#ifndef _BGFX_POLYGON_B2DPOLYGON_HXX
#include <basegfx/polygon/b2dpolygon.hxx>
#endif

#ifndef _BGFX_POINT_B2DPOINT_HXX
#include <basegfx/point/b2dpoint.hxx>
#endif

#ifndef _BGFX_VECTOR_B2DVECTOR_HXX
#include <basegfx/vector/b2dvector.hxx>
#endif

#ifndef _BGFX_RANGE_B2DRANGE_HXX
#include <basegfx/range/b2drange.hxx>
#endif

#ifndef _BGFX_POLYGON_B2DPOLYGONTOOLS_HXX
#include <basegfx/polygon/b2dpolygontools.hxx>
#endif

#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX
#include <basegfx/matrix/b2dhommatrix.hxx>
#endif

#ifndef _BGFX_POLYPOLYGON_B2DPOLYGONTOOLS_HXX
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#endif

#ifndef _BGFX_POLYGON_B2DLINEGEOMETRY_HXX
#include <basegfx/polygon/b2dlinegeometry.hxx>
#endif

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

ImpLineStyleParameterPack::ImpLineStyleParameterPack(
    const SfxItemSet& rSet,
    bool _bForceHair)
:   mbForceNoArrowsLeft(false),
    mbForceNoArrowsRight(false),
    mbForceHair(_bForceHair)
{
    maStartPolyPolygon = ((const XLineStartItem&)(rSet.Get(XATTR_LINESTART))).GetLineStartValue();

    if(maStartPolyPolygon.count())
    {
        if(maStartPolyPolygon.areControlPointsUsed())
        {
            maStartPolyPolygon = basegfx::tools::adaptiveSubdivideByAngle(maStartPolyPolygon);
        }

        if(basegfx::ORIENTATION_NEGATIVE == basegfx::tools::getOrientation(maStartPolyPolygon.getB2DPolygon(0L)))
        {
            maStartPolyPolygon.flip();
        }
    }

    maEndPolyPolygon = ((const XLineEndItem&)(rSet.Get(XATTR_LINEEND))).GetLineEndValue();

    if(maEndPolyPolygon.count())
    {
        if(maEndPolyPolygon.areControlPointsUsed())
        {
            maEndPolyPolygon = basegfx::tools::adaptiveSubdivideByAngle(maEndPolyPolygon);
        }

        if(basegfx::ORIENTATION_NEGATIVE == basegfx::tools::getOrientation(maEndPolyPolygon.getB2DPolygon(0L)))
        {
            maEndPolyPolygon.flip();
        }
    }

    mnLineWidth = ((const XLineWidthItem&)(rSet.Get(XATTR_LINEWIDTH))).GetValue();
    mbLineStyleSolid = (XLINE_SOLID == (XLineStyle)((const XLineStyleItem&)rSet.Get(XATTR_LINESTYLE)).GetValue());

    mnStartWidth = ((const XLineStartWidthItem&)(rSet.Get(XATTR_LINESTARTWIDTH))).GetValue();
    if(mnStartWidth < 0)
        mnStartWidth = -mnLineWidth * mnStartWidth / 100L;

    mnEndWidth = ((const XLineEndWidthItem&)(rSet.Get(XATTR_LINEENDWIDTH))).GetValue();
    if(mnEndWidth < 0)
        mnEndWidth = -mnLineWidth * mnEndWidth / 100L;

    mbStartCentered = ((const XLineStartCenterItem&)(rSet.Get(XATTR_LINESTARTCENTER))).GetValue();
    mbEndCentered = ((const XLineEndCenterItem&)(rSet.Get(XATTR_LINEENDCENTER))).GetValue();

    mfDegreeStepWidth = 10.0;
    meLineJoint = ((const XLineJointItem&)(rSet.Get(XATTR_LINEJOINT))).GetValue();

    XDash aDash = ((const XLineDashItem&)(rSet.Get(XATTR_LINEDASH))).GetDashValue();

    // fill local dash info
    mfFullDotDashLen = aDash.CreateDotDashArray(maDotDashArray, (double)GetDisplayLineWidth());
}

ImpLineStyleParameterPack::~ImpLineStyleParameterPack()
{
}

bool ImpLineStyleParameterPack::IsStartActive() const
{
    if(!mbForceNoArrowsLeft && maStartPolyPolygon.count() && GetStartWidth())
    {
        return (0L != maStartPolyPolygon.getB2DPolygon(0L).count());
    }

    return false;
}

bool ImpLineStyleParameterPack::IsEndActive() const
{
    if(!mbForceNoArrowsRight && maEndPolyPolygon.count() && GetEndWidth())
    {
        return (0L != maEndPolyPolygon.getB2DPolygon(0L).count());
    }

    return false;
}

void ImpLineGeometryCreator::ImpCreateLineGeometry(const basegfx::B2DPolygon& rSourcePoly)
{
    if(rSourcePoly.count() > 1L)
    {
        basegfx::B2DPolygon aSourceLineGeometry(rSourcePoly);

        if(aSourceLineGeometry.areControlPointsUsed())
        {
            aSourceLineGeometry = basegfx::tools::adaptiveSubdivideByAngle(aSourceLineGeometry);
        }

        sal_uInt32 nCount(aSourceLineGeometry.count());

        if(!aSourceLineGeometry.isClosed())
        {
            nCount--;
            const double fPolyLength(basegfx::tools::getLength(aSourceLineGeometry));
            double fStart(0.0);
            double fEnd(0.0);

            if(mrLineAttr.IsStartActive())
            {
                // create line start polygon and move line end
                basegfx::B2DPolyPolygon aArrowPolyPolygon;
                aArrowPolyPolygon.append(mrLineAttr.GetStartPolyPolygon());

                basegfx::B2DPolyPolygon aArrow = basegfx::tools::createAreaGeometryForLineStartEnd(
                    aSourceLineGeometry,
                    aArrowPolyPolygon,
                    true,
                    (double)mrLineAttr.GetStartWidth(),
                    mrLineAttr.IsStartCentered() ? 0.5 : 0.0,
                    &fStart);

                maAreaPolyPolygon.append(aArrow);
                fStart *= 0.8;
            }

            if(mrLineAttr.IsEndActive())
            {
                // create line end polygon and move line end
                basegfx::B2DPolyPolygon aArrowPolyPolygon;
                aArrowPolyPolygon.append(mrLineAttr.GetEndPolyPolygon());

                basegfx::B2DPolyPolygon aArrow = basegfx::tools::createAreaGeometryForLineStartEnd(
                    aSourceLineGeometry,
                    aArrowPolyPolygon,
                    false,
                    (double)mrLineAttr.GetEndWidth(),
                    mrLineAttr.IsEndCentered() ? 0.5 : 0.0,
                    &fEnd);

                maAreaPolyPolygon.append(aArrow);
                fEnd *= 0.8;
            }

            if(fStart != 0.0 || fEnd != 0.0)
            {
                // build new poly, consume something from old poly
                aSourceLineGeometry = basegfx::tools::getSnippetAbsolute(
                    aSourceLineGeometry, fStart, fPolyLength - fEnd, fPolyLength);
                nCount = aSourceLineGeometry.count() - 1L;
            }
        }

        if(nCount)
        {
            basegfx::B2DPolyPolygon aHairLinePolyPolygon;

            if(mbLineDraft || mrLineAttr.IsLineStyleSolid())
            {
                // no LineStyle
                aHairLinePolyPolygon.append(aSourceLineGeometry);
            }
            else
            {
                // apply LineStyle
                aHairLinePolyPolygon = basegfx::tools::applyLineDashing(aSourceLineGeometry, mrLineAttr.GetDotDash(), mrLineAttr.GetFullDotDashLen());

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

            if(!mrLineAttr.GetDisplayLineWidth())
            {
                // LineWidth zero, add directly to linePoly
                maLinePolyPolygon.append(aHairLinePolyPolygon);
            }
            else
            {
                basegfx::tools::B2DLineJoin aB2DLineJoin(basegfx::tools::B2DLINEJOIN_NONE);

                switch(mrLineAttr.GetLineJoint())
                {
                case XLINEJOINT_NONE    : aB2DLineJoin = basegfx::tools::B2DLINEJOIN_NONE;  break;
                case XLINEJOINT_MIDDLE  : aB2DLineJoin = basegfx::tools::B2DLINEJOIN_MIDDLE;    break;
                case XLINEJOINT_BEVEL   : aB2DLineJoin = basegfx::tools::B2DLINEJOIN_BEVEL; break;
                case XLINEJOINT_MITER   : aB2DLineJoin = basegfx::tools::B2DLINEJOIN_MITER; break;
                case XLINEJOINT_ROUND   : aB2DLineJoin = basegfx::tools::B2DLINEJOIN_ROUND; break;
                }

                for(sal_uInt32 a(0L); a < aHairLinePolyPolygon.count(); a++)
                {
                    basegfx::B2DPolygon aCandidate = aHairLinePolyPolygon.getB2DPolygon(a);
                    basegfx::B2DPolyPolygon aAreaPolyPolygon = basegfx::tools::createAreaGeometryForPolygon(
                        aCandidate,
                        (double)mrLineAttr.GetDisplayLineWidth() / 2.0,
                        aB2DLineJoin,
                        (double)mrLineAttr.GetDegreeStepWidth() * F_PI180,
                        (double)mrLineAttr.GetLinejointMiterMinimumAngle() * F_PI180);
                    maAreaPolyPolygon.append(aAreaPolyPolygon);
                }
            }
        }
    }
}

// eof