~ubuntu-branches/ubuntu/trusty/pdfmod/trusty

« back to all changes in this revision

Viewing changes to lib/PdfSharp/PdfSharp.Drawing/XGraphicsPath.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-06-18 03:44:46 UTC
  • Revision ID: james.westby@ubuntu.com-20100618034446-bogifrsscpayp361
Tags: upstream-0.8.3
ImportĀ upstreamĀ versionĀ 0.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#region PDFsharp - A .NET library for processing PDF
 
2
//
 
3
// Authors:
 
4
//   Stefan Lange (mailto:Stefan.Lange@pdfsharp.com)
 
5
//
 
6
// Copyright (c) 2005-2008 empira Software GmbH, Cologne (Germany)
 
7
//
 
8
// http://www.pdfsharp.com
 
9
// http://sourceforge.net/projects/pdfsharp
 
10
//
 
11
// Permission is hereby granted, free of charge, to any person obtaining a
 
12
// copy of this software and associated documentation files (the "Software"),
 
13
// to deal in the Software without restriction, including without limitation
 
14
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
15
// and/or sell copies of the Software, and to permit persons to whom the
 
16
// Software is furnished to do so, subject to the following conditions:
 
17
//
 
18
// The above copyright notice and this permission notice shall be included
 
19
// in all copies or substantial portions of the Software.
 
20
//
 
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
24
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 
27
// DEALINGS IN THE SOFTWARE.
 
28
#endregion
 
29
 
 
30
using System;
 
31
using System.Diagnostics;
 
32
using System.Collections;
 
33
using System.Globalization;
 
34
using System.Text;
 
35
using System.IO;
 
36
#if GDI
 
37
using System.Drawing;
 
38
using System.Drawing.Drawing2D;
 
39
#endif
 
40
#if WPF
 
41
using System.Windows;
 
42
using System.Windows.Media;
 
43
#endif
 
44
using PdfSharp.Internal;
 
45
 
 
46
namespace PdfSharp.Drawing
 
47
{
 
48
  /// <summary>
 
49
  /// Represents a series of connected lines and curves.
 
50
  /// </summary>
 
51
  public sealed class XGraphicsPath
 
52
  {
 
53
    /// <summary>
 
54
    /// Initializes a new instance of the <see cref="XGraphicsPath"/> class.
 
55
    /// </summary>
 
56
    public XGraphicsPath()
 
57
    {
 
58
#if GDI
 
59
      this.gdipPath = new GraphicsPath();
 
60
#endif
 
61
#if WPF
 
62
      this.pathGeometry = new PathGeometry();
 
63
#endif
 
64
    }
 
65
 
 
66
#if GDI
 
67
    /// <summary>
 
68
    /// Initializes a new instance of the <see cref="XGraphicsPath"/> class.
 
69
    /// </summary>
 
70
    public XGraphicsPath(PointF[] points, byte[] types, XFillMode fillMode)
 
71
    {
 
72
#if GDI
 
73
      this.gdipPath = new GraphicsPath(points, types, (FillMode)fillMode);
 
74
#endif
 
75
#if WPF
 
76
      this.pathGeometry = new PathGeometry();
 
77
      this.pathGeometry.FillRule = FillRule.EvenOdd;
 
78
#endif
 
79
    }
 
80
#endif
 
81
 
 
82
#if GDI
 
83
    /// <summary>
 
84
    /// Gets access to underlying GDI+ path.
 
85
    /// </summary>
 
86
    internal GraphicsPath gdipPath;
 
87
#endif
 
88
 
 
89
#if WPF
 
90
    /// <summary>
 
91
    /// Gets access to underlying WPF path geometry.
 
92
    /// </summary>
 
93
    internal PathGeometry pathGeometry;
 
94
 
 
95
    ///// <summary>
 
96
    ///// The current path figure;
 
97
    ///// </summary>
 
98
    //PathFigure figure;
 
99
 
 
100
    /// <summary>
 
101
    /// Gets the current path figure.
 
102
    /// </summary>
 
103
    PathFigure CurrentPathFigure
 
104
    {
 
105
      get
 
106
      {
 
107
        int count = this.pathGeometry.Figures.Count;
 
108
        if (count == 0)
 
109
        {
 
110
          this.pathGeometry.Figures.Add(new PathFigure());
 
111
          count++;
 
112
        }
 
113
        else if (this.startNewFigure && this.pathGeometry.Figures[count - 1].Segments.Count == 0)
 
114
        {
 
115
          this.pathGeometry.Figures.Add(new PathFigure());
 
116
          count++;
 
117
        }
 
118
        return this.pathGeometry.Figures[count - 1];
 
119
 
 
120
        //if (this.figure == null)
 
121
        //{
 
122
        //  this.figure = new PathFigure();
 
123
        //  this.pathGeometry.Figures.Add(this.figure);
 
124
        //}
 
125
        //return this.figure;
 
126
      }
 
127
    }
 
128
    bool startNewFigure;
 
129
#endif
 
130
 
 
131
    /// <summary>
 
132
    /// Clones this instance.
 
133
    /// </summary>
 
134
    public XGraphicsPath Clone()
 
135
    {
 
136
      XGraphicsPath path = (XGraphicsPath)MemberwiseClone();
 
137
#if GDI
 
138
      path.gdipPath = this.gdipPath.Clone() as GraphicsPath;
 
139
#endif
 
140
#if WPF
 
141
      path.pathGeometry = this.pathGeometry.Clone();
 
142
#endif
 
143
      return path;
 
144
    }
 
145
 
 
146
    ///// <summary>
 
147
    ///// For internal use only.
 
148
    ///// </summary>
 
149
    //internal XGraphicsPathItem[] GetPathData()
 
150
    //{
 
151
    //  int count = this.items.Count;
 
152
    //  XGraphicsPathItem[] data = new XGraphicsPathItem[count];
 
153
    //  for (int idx = 0; idx < count; idx++)
 
154
    //    data[idx] = ((XGraphicsPathItem)this.items[idx]).Clone() as XGraphicsPathItem;
 
155
    //  return data;
 
156
    //}
 
157
 
 
158
    // ----- AddLine ------------------------------------------------------------------------------
 
159
 
 
160
#if GDI
 
161
    /// <summary>
 
162
    /// Adds a line segment to current figure.
 
163
    /// </summary>
 
164
    public void AddLine(System.Drawing.Point pt1, System.Drawing.Point pt2)
 
165
    {
 
166
      AddLine((double)pt1.X, (double)pt1.Y, (double)pt2.X, (double)pt2.Y);
 
167
    }
 
168
#endif
 
169
 
 
170
#if WPF
 
171
    /// <summary>
 
172
    /// Adds a line segment to current figure.
 
173
    /// </summary>
 
174
    public void AddLine(System.Windows.Point pt1, System.Windows.Point pt2)
 
175
    {
 
176
      AddLine(pt1.X, pt1.Y, pt2.X, pt2.Y);
 
177
    }
 
178
#endif
 
179
 
 
180
#if GDI
 
181
    /// <summary>
 
182
    /// Adds  a line segment to current figure.
 
183
    /// </summary>
 
184
    public void AddLine(PointF pt1, PointF pt2)
 
185
    {
 
186
      AddLine((double)pt1.X, (double)pt1.Y, (double)pt2.X, (double)pt2.Y);
 
187
    }
 
188
#endif
 
189
 
 
190
    /// <summary>
 
191
    /// Adds  a line segment to current figure.
 
192
    /// </summary>
 
193
    public void AddLine(XPoint pt1, XPoint pt2)
 
194
    {
 
195
      AddLine(pt1.X, pt1.Y, pt2.X, pt2.Y);
 
196
    }
 
197
 
 
198
    /// <summary>
 
199
    /// Adds  a line segment to current figure.
 
200
    /// </summary>
 
201
    public void AddLine(int x1, int y1, int x2, int y2)
 
202
    {
 
203
      AddLine((double)x1, (double)y1, (double)x2, (double)y2);
 
204
    }
 
205
 
 
206
    /// <summary>
 
207
    /// Adds  a line segment to current figure.
 
208
    /// </summary>
 
209
    public void AddLine(double x1, double y1, double x2, double y2)
 
210
    {
 
211
#if GDI
 
212
      this.gdipPath.AddLine((float)x1, (float)y1, (float)x2, (float)y2);
 
213
#endif
 
214
#if WPF
 
215
      PathFigure figure = CurrentPathFigure;
 
216
      if (figure.Segments.Count == 0)
 
217
      {
 
218
        figure.StartPoint = new System.Windows.Point(x1, y1);
 
219
        figure.Segments.Add(new LineSegment(new System.Windows.Point(x2, y2), true));
 
220
      }
 
221
      else
 
222
      {
 
223
        figure.Segments.Add(new LineSegment(new System.Windows.Point(x1, y1), true));
 
224
        figure.Segments.Add(new LineSegment(new System.Windows.Point(x2, y2), true));
 
225
      }
 
226
#endif
 
227
    }
 
228
 
 
229
    // ----- AddLines -----------------------------------------------------------------------------
 
230
 
 
231
#if GDI
 
232
    /// <summary>
 
233
    /// Adds a series of connected line segments to current figure.
 
234
    /// </summary>
 
235
    public void AddLines(System.Drawing.Point[] points)
 
236
    {
 
237
      AddLines(XGraphics.MakeXPointArray(points));
 
238
    }
 
239
#endif
 
240
 
 
241
#if WPF
 
242
    /// <summary>
 
243
    /// Adds a series of connected line segments to current figure.
 
244
    /// </summary>
 
245
    public void AddLines(System.Windows.Point[] points)
 
246
    {
 
247
      AddLines(XGraphics.MakeXPointArray(points));
 
248
    }
 
249
#endif
 
250
 
 
251
#if GDI
 
252
    /// <summary>
 
253
    /// Adds a series of connected line segments to current figure.
 
254
    /// </summary>
 
255
    public void AddLines(PointF[] points)
 
256
    {
 
257
      AddLines(XGraphics.MakeXPointArray(points));
 
258
    }
 
259
#endif
 
260
 
 
261
    /// <summary>
 
262
    /// Adds a series of connected line segments to current figure.
 
263
    /// </summary>
 
264
    public void AddLines(XPoint[] points)
 
265
    {
 
266
      if (points == null)
 
267
        throw new ArgumentNullException("points");
 
268
 
 
269
      int count = points.Length;
 
270
      if (count == 0)
 
271
        return;
 
272
 
 
273
#if GDI
 
274
      this.gdipPath.AddLines(XGraphics.MakePointFArray(points));
 
275
#endif
 
276
#if WPF
 
277
      PathFigure figure = CurrentPathFigure;
 
278
      if (figure.Segments.Count == 0)
 
279
      {
 
280
        figure.StartPoint = new System.Windows.Point(points[0].x, points[0].y);
 
281
        for (int idx = 1; idx < count; idx++)
 
282
          figure.Segments.Add(new LineSegment(new System.Windows.Point(points[idx].x, points[idx].y), true));
 
283
      }
 
284
      else
 
285
      {
 
286
        for (int idx = 0; idx < count; idx++)
 
287
          figure.Segments.Add(new LineSegment(new System.Windows.Point(points[idx].x, points[idx].y), true));
 
288
      }
 
289
#endif
 
290
    }
 
291
 
 
292
    // ----- AddBezier ----------------------------------------------------------------------------
 
293
 
 
294
#if GDI
 
295
    /// <summary>
 
296
    /// Adds a cubic Bļæ½zier curve to the current figure.
 
297
    /// </summary>
 
298
    public void AddBezier(System.Drawing.Point pt1, System.Drawing.Point pt2, System.Drawing.Point pt3, System.Drawing.Point pt4)
 
299
    {
 
300
      AddBezier((double)pt1.X, (double)pt1.Y, (double)pt2.X, (double)pt2.Y, (double)pt3.X, (double)pt3.Y, (double)pt4.X, (double)pt4.Y);
 
301
    }
 
302
#endif
 
303
 
 
304
#if WPF
 
305
    /// <summary>
 
306
    /// Adds a cubic Bļæ½zier curve to the current figure.
 
307
    /// </summary>
 
308
    public void AddBezier(System.Windows.Point pt1, System.Windows.Point pt2, System.Windows.Point pt3, System.Windows.Point pt4)
 
309
    {
 
310
      AddBezier(pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
 
311
    }
 
312
#endif
 
313
 
 
314
#if GDI
 
315
    /// <summary>
 
316
    /// Adds a cubic Bļæ½zier curve to the current figure.
 
317
    /// </summary>
 
318
    public void AddBezier(PointF pt1, PointF pt2, PointF pt3, PointF pt4)
 
319
    {
 
320
      AddBezier((double)pt1.X, (double)pt1.Y, (double)pt2.X, (double)pt2.Y, (double)pt3.X, (double)pt3.Y, (double)pt4.X, (double)pt4.Y);
 
321
    }
 
322
#endif
 
323
 
 
324
    /// <summary>
 
325
    /// Adds a cubic Bļæ½zier curve to the current figure.
 
326
    /// </summary>
 
327
    public void AddBezier(XPoint pt1, XPoint pt2, XPoint pt3, XPoint pt4)
 
328
    {
 
329
      AddBezier(pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
 
330
    }
 
331
 
 
332
    /// <summary>
 
333
    /// Adds a cubic Bļæ½zier curve to the current figure.
 
334
    /// </summary>
 
335
    public void AddBezier(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
 
336
    {
 
337
      AddBezier((double)x1, (double)y1, (double)x2, (double)y2, (double)x3, (double)y3, (double)x4, (double)y4);
 
338
    }
 
339
 
 
340
    /// <summary>
 
341
    /// Adds a cubic Bļæ½zier curve to the current figure.
 
342
    /// </summary>
 
343
    public void AddBezier(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
 
344
    {
 
345
#if GDI
 
346
      this.gdipPath.AddBezier((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4);
 
347
#endif
 
348
#if WPF
 
349
      PathFigure figure = CurrentPathFigure;
 
350
      if (figure.Segments.Count == 0)
 
351
        figure.StartPoint = new System.Windows.Point(x1, y1);
 
352
      else
 
353
        figure.Segments.Add(new LineSegment(new System.Windows.Point(x1, y1), true));
 
354
      figure.Segments.Add(new BezierSegment(
 
355
        new System.Windows.Point(x2, y2),
 
356
        new System.Windows.Point(x3, y3),
 
357
        new System.Windows.Point(x4, y4), true));
 
358
#endif
 
359
    }
 
360
 
 
361
    // ----- AddBeziers ---------------------------------------------------------------------------
 
362
 
 
363
#if GDI
 
364
    /// <summary>
 
365
    /// Adds a sequence of connected cubic Bļæ½zier curves to the current figure.
 
366
    /// </summary>
 
367
    public void AddBeziers(System.Drawing.Point[] points)
 
368
    {
 
369
      AddBeziers(XGraphics.MakeXPointArray(points));
 
370
    }
 
371
#endif
 
372
 
 
373
#if WPF
 
374
    /// <summary>
 
375
    /// Adds a sequence of connected cubic Bļæ½zier curves to the current figure.
 
376
    /// </summary>
 
377
    public void AddBeziers(System.Windows.Point[] points)
 
378
    {
 
379
      AddBeziers(XGraphics.MakeXPointArray(points));
 
380
    }
 
381
#endif
 
382
 
 
383
#if GDI
 
384
    /// <summary>
 
385
    /// Adds a sequence of connected cubic Bļæ½zier curves to the current figure.
 
386
    /// </summary>
 
387
    public void AddBeziers(PointF[] points)
 
388
    {
 
389
      AddBeziers(XGraphics.MakeXPointArray(points));
 
390
    }
 
391
#endif
 
392
 
 
393
    /// <summary>
 
394
    /// Adds a sequence of connected cubic Bļæ½zier curves to the current figure.
 
395
    /// </summary>
 
396
    public void AddBeziers(XPoint[] points)
 
397
    {
 
398
      if (points == null)
 
399
        new ArgumentNullException("points");
 
400
 
 
401
      int count = points.Length;
 
402
      if (points.Length < 4)
 
403
        throw new ArgumentException("At least four points required for bezier curve.", "points");
 
404
 
 
405
      if ((points.Length - 1) % 3 != 0)
 
406
        throw new ArgumentException("Invalid number of points for bezier curve. Number must fulfil 4+3n.", "points");
 
407
 
 
408
#if GDI
 
409
      this.gdipPath.AddBeziers(XGraphics.MakePointFArray(points));
 
410
#endif
 
411
#if WPF
 
412
      PathFigure figure = CurrentPathFigure;
 
413
      if (figure.Segments.Count == 0)
 
414
        figure.StartPoint = new System.Windows.Point(points[0].x, points[0].y);
 
415
      else
 
416
        figure.Segments.Add(new LineSegment(new System.Windows.Point(points[0].x, points[0].y), true));
 
417
 
 
418
      for (int idx = 1; idx < count; idx += 3)
 
419
        figure.Segments.Add(new BezierSegment(
 
420
          new System.Windows.Point(points[idx].x, points[idx].y),
 
421
          new System.Windows.Point(points[idx + 1].x, points[idx + 1].y),
 
422
          new System.Windows.Point(points[idx + 2].x, points[idx + 2].y), true));
 
423
#endif
 
424
    }
 
425
 
 
426
    // ----- AddCurve -----------------------------------------------------------------------
 
427
 
 
428
#if GDI
 
429
    /// <summary>
 
430
    /// Adds a spline curve to the current figure.
 
431
    /// </summary>
 
432
    public void AddCurve(System.Drawing.Point[] points)
 
433
    {
 
434
      AddCurve(XGraphics.MakeXPointArray(points));
 
435
    }
 
436
#endif
 
437
 
 
438
#if WPF
 
439
    /// <summary>
 
440
    /// Adds a spline curve to the current figure.
 
441
    /// </summary>
 
442
    public void AddCurve(System.Windows.Point[] points)
 
443
    {
 
444
      AddCurve(XGraphics.MakeXPointArray(points));
 
445
    }
 
446
#endif
 
447
 
 
448
#if GDI
 
449
    /// <summary>
 
450
    /// Adds a spline curve to the current figure.
 
451
    /// </summary>
 
452
    public void AddCurve(PointF[] points)
 
453
    {
 
454
      AddCurve(XGraphics.MakeXPointArray(points));
 
455
    }
 
456
#endif
 
457
 
 
458
    /// <summary>
 
459
    /// Adds a spline curve to the current figure.
 
460
    /// </summary>
 
461
    public void AddCurve(XPoint[] points)
 
462
    {
 
463
      AddCurve(points, 0.5);
 
464
    }
 
465
 
 
466
#if GDI
 
467
    /// <summary>
 
468
    /// Adds a spline curve to the current figure.
 
469
    /// </summary>
 
470
    public void AddCurve(System.Drawing.Point[] points, double tension)
 
471
    {
 
472
      AddCurve(XGraphics.MakeXPointArray(points), tension);
 
473
    }
 
474
#endif
 
475
 
 
476
#if WPF
 
477
    /// <summary>
 
478
    /// Adds a spline curve to the current figure.
 
479
    /// </summary>
 
480
    public void AddCurve(System.Windows.Point[] points, double tension)
 
481
    {
 
482
      AddCurve(XGraphics.MakeXPointArray(points), tension);
 
483
    }
 
484
#endif
 
485
 
 
486
#if GDI
 
487
    /// <summary>
 
488
    /// Adds a spline curve to the current figure.
 
489
    /// </summary>
 
490
    public void AddCurve(PointF[] points, double tension)
 
491
    {
 
492
      AddCurve(XGraphics.MakeXPointArray(points), tension);
 
493
    }
 
494
#endif
 
495
 
 
496
    /// <summary>
 
497
    /// Adds a spline curve to the current figure.
 
498
    /// </summary>
 
499
    public void AddCurve(XPoint[] points, double tension)
 
500
    {
 
501
      int count = points.Length;
 
502
      if (count < 2)
 
503
        throw new ArgumentException("AddCurve requires two or more points.", "points");
 
504
#if GDI
 
505
      this.gdipPath.AddCurve(XGraphics.MakePointFArray(points), (float)tension);
 
506
#endif
 
507
#if WPF
 
508
      tension /= 3;
 
509
 
 
510
      PathFigure figure = CurrentPathFigure;
 
511
      if (figure.Segments.Count == 0)
 
512
        figure.StartPoint = new System.Windows.Point(points[0].x, points[0].y);
 
513
      else
 
514
        figure.Segments.Add(new LineSegment(new System.Windows.Point(points[0].x, points[0].y), true));
 
515
 
 
516
      if (count == 2)
 
517
      {
 
518
        figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[0], points[0], points[1], points[1], tension));
 
519
      }
 
520
      else
 
521
      {
 
522
        figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[0], points[0], points[1], points[2], tension));
 
523
        for (int idx = 1; idx < count - 2; idx++)
 
524
          figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[idx - 1], points[idx], points[idx + 1], points[idx + 2], tension));
 
525
        figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[count - 3], points[count - 2], points[count - 1], points[count - 1], tension));
 
526
      }
 
527
#endif
 
528
    }
 
529
 
 
530
#if GDI
 
531
    /// <summary>
 
532
    /// Adds a spline curve to the current figure.
 
533
    /// </summary>
 
534
    public void AddCurve(System.Drawing.Point[] points, int offset, int numberOfSegments, float tension)
 
535
    {
 
536
      AddCurve(XGraphics.MakeXPointArray(points), offset, numberOfSegments, tension);
 
537
    }
 
538
#endif
 
539
 
 
540
#if WPF
 
541
    /// <summary>
 
542
    /// Adds a spline curve to the current figure.
 
543
    /// </summary>
 
544
    public void AddCurve(System.Windows.Point[] points, int offset, int numberOfSegments, float tension)
 
545
    {
 
546
      AddCurve(XGraphics.MakeXPointArray(points), offset, numberOfSegments, tension);
 
547
    }
 
548
#endif
 
549
 
 
550
#if GDI
 
551
    /// <summary>
 
552
    /// Adds a spline curve to the current figure.
 
553
    /// </summary>
 
554
    public void AddCurve(PointF[] points, int offset, int numberOfSegments, float tension)
 
555
    {
 
556
      AddCurve(XGraphics.MakeXPointArray(points), offset, numberOfSegments, tension);
 
557
    }
 
558
#endif
 
559
 
 
560
    /// <summary>
 
561
    /// Adds a spline curve to the current figure.
 
562
    /// </summary>
 
563
    public void AddCurve(XPoint[] points, int offset, int numberOfSegments, double tension)
 
564
    {
 
565
#if GDI
 
566
      this.gdipPath.AddCurve(XGraphics.MakePointFArray(points), offset, numberOfSegments, (float)tension);
 
567
#endif
 
568
#if WPF
 
569
      throw new NotImplementedException("AddCurve not yet implemented.");
 
570
#endif
 
571
    }
 
572
 
 
573
    // ----- AddArc -------------------------------------------------------------------------------
 
574
 
 
575
#if GDI
 
576
    /// <summary>
 
577
    /// Adds an elliptical arc to the current figure.
 
578
    /// </summary>
 
579
    public void AddArc(Rectangle rect, double startAngle, double sweepAngle)
 
580
    {
 
581
      AddArc((double)rect.X, (double)rect.Y, (double)rect.Width, (double)rect.Height, startAngle, sweepAngle);
 
582
    }
 
583
#endif
 
584
 
 
585
#if GDI
 
586
    /// <summary>
 
587
    /// Adds an elliptical arc to the current figure.
 
588
    /// </summary>
 
589
    public void AddArc(RectangleF rect, double startAngle, double sweepAngle)
 
590
    {
 
591
      AddArc((double)rect.X, (double)rect.Y, (double)rect.Width, (double)rect.Height, startAngle, sweepAngle);
 
592
    }
 
593
#endif
 
594
 
 
595
    /// <summary>
 
596
    /// Adds an elliptical arc to the current figure.
 
597
    /// </summary>
 
598
    public void AddArc(XRect rect, double startAngle, double sweepAngle)
 
599
    {
 
600
      AddArc((double)rect.X, (double)rect.Y, (double)rect.Width, (double)rect.Height, startAngle, sweepAngle);
 
601
    }
 
602
 
 
603
    /// <summary>
 
604
    /// Adds an elliptical arc to the current figure.
 
605
    /// </summary>
 
606
    public void AddArc(int x, int y, int width, int height, int startAngle, int sweepAngle)
 
607
    {
 
608
      AddArc((double)x, (double)y, (double)width, (double)height, (double)startAngle, (double)sweepAngle);
 
609
    }
 
610
 
 
611
    /// <summary>
 
612
    /// Adds an elliptical arc to the current figure.
 
613
    /// </summary>
 
614
    public void AddArc(double x, double y, double width, double height, double startAngle, double sweepAngle)
 
615
    {
 
616
#if GDI
 
617
      this.gdipPath.AddArc((float)x, (float)y, (float)width, (float)height, (float)startAngle, (float)sweepAngle);
 
618
#endif
 
619
#if WPF
 
620
      PathFigure figure = CurrentPathFigure;
 
621
      System.Windows.Point startPoint;
 
622
      ArcSegment seg = GeometryHelper.CreateArcSegment(x, y, width, height, startAngle, sweepAngle, out startPoint);
 
623
      if (figure.Segments.Count == 0)
 
624
        figure.StartPoint = startPoint;
 
625
      figure.Segments.Add(seg);
 
626
 
 
627
      //figure.Segments.Add(
 
628
      //if (figure.Segments.Count == 0)
 
629
      //  figure.StartPoint = new System.Windows.Point(points[0].x, points[0].y);
 
630
      //else
 
631
      //  figure.Segments.Add(new LineSegment(new System.Windows.Point(points[0].x, points[0].y), true));
 
632
 
 
633
      //for (int idx = 1; idx < 5555; idx += 3)
 
634
      //  figure.Segments.Add(new BezierSegment(
 
635
      //    new System.Windows.Point(points[idx].x, points[idx].y),
 
636
      //    new System.Windows.Point(points[idx + 1].x, points[idx + 1].y),
 
637
      //    new System.Windows.Point(points[idx + 2].x, points[idx + 2].y), true));
 
638
#endif
 
639
    }
 
640
 
 
641
#if WPF
 
642
    /// <summary>
 
643
    /// Adds an elliptical arc to the current figure. The arc is specified WPF like.
 
644
    /// </summary>
 
645
    public void AddArc(XPoint point1, XPoint point2, XSize size, double rotationAngle, bool isLargeArg, SweepDirection sweepDirection)
 
646
    {
 
647
      PathFigure figure = CurrentPathFigure;
 
648
      if (figure.Segments.Count == 0)
 
649
        figure.StartPoint = point1.ToPoint();
 
650
      else
 
651
        figure.Segments.Add(new LineSegment(point1.ToPoint(), true));
 
652
      figure.Segments.Add(new ArcSegment(point2.ToPoint(), size.ToSize(), rotationAngle, isLargeArg, sweepDirection, true));
 
653
    }
 
654
#endif
 
655
 
 
656
    // ----- AddRectangle -------------------------------------------------------------------------
 
657
 
 
658
#if GDI
 
659
    /// <summary>
 
660
    /// Adds a rectangle to this path.
 
661
    /// </summary>
 
662
    public void AddRectangle(Rectangle rect)
 
663
    {
 
664
      AddRectangle(new XRect(rect));
 
665
    }
 
666
#endif
 
667
 
 
668
#if GDI
 
669
    /// <summary>
 
670
    /// Adds a rectangle to this path.
 
671
    /// </summary>
 
672
    public void AddRectangle(RectangleF rect)
 
673
    {
 
674
      AddRectangle(new XRect(rect));
 
675
    }
 
676
#endif
 
677
 
 
678
    /// <summary>
 
679
    /// Adds a rectangle to this path.
 
680
    /// </summary>
 
681
    public void AddRectangle(XRect rect)
 
682
    {
 
683
#if GDI
 
684
      this.gdipPath.AddRectangle(rect.ToRectangleF());
 
685
#endif
 
686
#if WPF
 
687
      StartFigure();
 
688
      PathFigure figure = CurrentPathFigure;
 
689
      figure.StartPoint = new System.Windows.Point(rect.x, rect.y);
 
690
      figure.Segments.Add(new LineSegment(new System.Windows.Point(rect.x + rect.width, rect.y), true));
 
691
      figure.Segments.Add(new LineSegment(new System.Windows.Point(rect.x + rect.width, rect.y + rect.height), true));
 
692
      figure.Segments.Add(new LineSegment(new System.Windows.Point(rect.x, rect.y + rect.height), true));
 
693
      CloseFigure();
 
694
#endif
 
695
    }
 
696
 
 
697
    /// <summary>
 
698
    /// Adds a rectangle to this path.
 
699
    /// </summary>
 
700
    public void AddRectangle(int x, int y, int width, int height)
 
701
    {
 
702
      AddRectangle(new XRect(x, y, width, height));
 
703
    }
 
704
 
 
705
    /// <summary>
 
706
    /// Adds a rectangle to this path.
 
707
    /// </summary>
 
708
    public void AddRectangle(double x, double y, double width, double height)
 
709
    {
 
710
      AddRectangle(new XRect(x, y, width, height));
 
711
    }
 
712
 
 
713
    // ----- AddRectangles ------------------------------------------------------------------------
 
714
 
 
715
#if GDI
 
716
    /// <summary>
 
717
    /// Adds a series of rectangles to this path.
 
718
    /// </summary>
 
719
    public void AddRectangles(Rectangle[] rects)
 
720
    {
 
721
      int count = rects.Length;
 
722
      for (int idx = 0; idx < count; idx++)
 
723
        AddRectangle(rects[idx]);
 
724
      this.gdipPath.AddRectangles(rects);
 
725
    }
 
726
#endif
 
727
 
 
728
#if GDI
 
729
    /// <summary>
 
730
    /// Adds a series of rectangles to this path.
 
731
    /// </summary>
 
732
    public void AddRectangles(RectangleF[] rects)
 
733
    {
 
734
      int count = rects.Length;
 
735
      for (int idx = 0; idx < count; idx++)
 
736
        AddRectangle(rects[idx]);
 
737
      this.gdipPath.AddRectangles(rects);
 
738
    }
 
739
#endif
 
740
 
 
741
    /// <summary>
 
742
    /// Adds a series of rectangles to this path.
 
743
    /// </summary>
 
744
    public void AddRectangles(XRect[] rects)
 
745
    {
 
746
      int count = rects.Length;
 
747
      for (int idx = 0; idx < count; idx++)
 
748
      {
 
749
#if GDI
 
750
        this.gdipPath.AddRectangle(rects[idx].ToRectangleF());
 
751
#endif
 
752
#if WPF
 
753
        StartFigure();
 
754
        PathFigure figure = CurrentPathFigure;
 
755
        XRect rect = rects[idx];
 
756
        figure.StartPoint = new System.Windows.Point(rect.x, rect.y);
 
757
        figure.Segments.Add(new LineSegment(new System.Windows.Point(rect.x + rect.width, rect.y), true));
 
758
        figure.Segments.Add(new LineSegment(new System.Windows.Point(rect.x + rect.width, rect.y + rect.height), true));
 
759
        figure.Segments.Add(new LineSegment(new System.Windows.Point(rect.x, rect.y + rect.height), true));
 
760
        CloseFigure();
 
761
#endif
 
762
      }
 
763
    }
 
764
 
 
765
    // ----- AddRoundedRectangle ------------------------------------------------------------------
 
766
 
 
767
#if GDI
 
768
    /// <summary>
 
769
    /// Adds a rectangle with rounded cornes to this path.
 
770
    /// </summary>
 
771
    public void AddRoundedRectangle(Rectangle rect, System.Drawing.Size ellipseSize)
 
772
    {
 
773
      AddRoundedRectangle((double)rect.X, (double)rect.Y, (double)rect.Width, (double)rect.Height,
 
774
        (double)ellipseSize.Width, (double)ellipseSize.Height);
 
775
    }
 
776
#endif
 
777
 
 
778
#if WPF
 
779
    /// <summary>
 
780
    /// Adds a rectangle with rounded cornes to this path.
 
781
    /// </summary>
 
782
    public void AddRoundedRectangle(Rect rect, System.Windows.Size ellipseSize)
 
783
    {
 
784
      AddRoundedRectangle((double)rect.X, (double)rect.Y, (double)rect.Width, (double)rect.Height,
 
785
        (double)ellipseSize.Width, (double)ellipseSize.Height);
 
786
    }
 
787
#endif
 
788
 
 
789
#if GDI
 
790
    /// <summary>
 
791
    /// Adds a rectangle with rounded cornes to this path.
 
792
    /// </summary>
 
793
    public void AddRoundedRectangle(RectangleF rect, SizeF ellipseSize)
 
794
    {
 
795
      AddRoundedRectangle((double)rect.X, (double)rect.Y, (double)rect.Width, (double)rect.Height,
 
796
        (double)ellipseSize.Width, (double)ellipseSize.Height);
 
797
    }
 
798
#endif
 
799
 
 
800
#if GDI
 
801
    /// <summary>
 
802
    /// Adds a rectangle with rounded cornes to this path.
 
803
    /// </summary>
 
804
    public void AddRoundedRectangle(XRect rect, SizeF ellipseSize)
 
805
    {
 
806
      AddRoundedRectangle((double)rect.X, (double)rect.Y, (double)rect.Width, (double)rect.Height,
 
807
        (double)ellipseSize.Width, (double)ellipseSize.Height);
 
808
    }
 
809
#endif
 
810
 
 
811
    /// <summary>
 
812
    /// Adds a rectangle with rounded cornes to this path.
 
813
    /// </summary>
 
814
    public void AddRoundedRectangle(int x, int y, int width, int height, int ellipseWidth, int ellipseHeight)
 
815
    {
 
816
      AddRoundedRectangle((double)x, (double)y, (double)width, (double)height, (double)ellipseWidth, (double)ellipseHeight);
 
817
    }
 
818
 
 
819
    /// <summary>
 
820
    /// Adds a rectangle with rounded cornes to this path.
 
821
    /// </summary>
 
822
    public void AddRoundedRectangle(double x, double y, double width, double height, double ellipseWidth, double ellipseHeight)
 
823
    {
 
824
#if GDI
 
825
      this.gdipPath.AddArc((float)(x + width - ellipseWidth), (float)y, (float)ellipseWidth, (float)ellipseHeight, -90, 90);
 
826
      this.gdipPath.AddArc((float)(x + width - ellipseWidth), (float)(y + height - ellipseHeight), (float)ellipseWidth, (float)ellipseHeight, 0, 90);
 
827
      this.gdipPath.AddArc((float)x, (float)(y + height - ellipseHeight), (float)ellipseWidth, (float)ellipseHeight, 90, 90);
 
828
      this.gdipPath.AddArc((float)x, (float)y, (float)ellipseWidth, (float)ellipseHeight, 180, 90);
 
829
      this.gdipPath.CloseFigure();
 
830
#endif
 
831
#if WPF
 
832
      double ex = ellipseWidth / 2;
 
833
      double ey = ellipseHeight / 2;
 
834
      StartFigure();
 
835
      PathFigure figure = CurrentPathFigure;
 
836
      figure.StartPoint = new System.Windows.Point(x + ex, y);
 
837
      figure.Segments.Add(new LineSegment(new System.Windows.Point(x + width - ex, y), true));
 
838
      // TODOWPF
 
839
      figure.Segments.Add(new ArcSegment(new System.Windows.Point(x + width, y + ey), new System.Windows.Size(ex, ey), 0, false, SweepDirection.Clockwise, true));
 
840
      //figure.Segments.Add(new LineSegment(new System.Windows.Point(x + width, y + ey), true));
 
841
 
 
842
      figure.Segments.Add(new LineSegment(new System.Windows.Point(x + width, y + height - ey), true));
 
843
      // TODOWPF
 
844
      figure.Segments.Add(new ArcSegment(new System.Windows.Point(x + width - ex, y + height), new System.Windows.Size(ex, ey), 0, false, SweepDirection.Clockwise, true));
 
845
      //figure.Segments.Add(new LineSegment(new System.Windows.Point(x + width - ex, y + height), true));
 
846
 
 
847
      figure.Segments.Add(new LineSegment(new System.Windows.Point(x + ex, y + height), true));
 
848
      // TODOWPF
 
849
      figure.Segments.Add(new ArcSegment(new System.Windows.Point(x, y + height - ey), new System.Windows.Size(ex, ey), 0, false, SweepDirection.Clockwise, true));
 
850
      //figure.Segments.Add(new LineSegment(new System.Windows.Point(x, y + height - ey), true));
 
851
 
 
852
      figure.Segments.Add(new LineSegment(new System.Windows.Point(x, y + ey), true));
 
853
      // TODOWPF
 
854
      figure.Segments.Add(new ArcSegment(new System.Windows.Point(x + ex, y), new System.Windows.Size(ex, ey), 0, false, SweepDirection.Clockwise, true));
 
855
      //figure.Segments.Add(new LineSegment(new System.Windows.Point(x + ex, y), true));
 
856
 
 
857
      CloseFigure();
 
858
#endif
 
859
    }
 
860
 
 
861
    // ----- AddEllipse ---------------------------------------------------------------------------
 
862
 
 
863
#if GDI
 
864
    /// <summary>
 
865
    /// Adds an ellipse to the current path.
 
866
    /// </summary>
 
867
    public void AddEllipse(Rectangle rect)
 
868
    {
 
869
      AddEllipse(rect.X, rect.Y, rect.Width, rect.Height);
 
870
    }
 
871
#endif
 
872
 
 
873
#if GDI
 
874
    /// <summary>
 
875
    /// Adds an ellipse to the current path.
 
876
    /// </summary>
 
877
    public void AddEllipse(RectangleF rect)
 
878
    {
 
879
      AddEllipse(rect.X, rect.Y, rect.Width, rect.Height);
 
880
    }
 
881
#endif
 
882
 
 
883
    /// <summary>
 
884
    /// Adds an ellipse to the current path.
 
885
    /// </summary>
 
886
    public void AddEllipse(XRect rect)
 
887
    {
 
888
      AddEllipse(rect.x, rect.y, rect.width, rect.height);
 
889
    }
 
890
 
 
891
    /// <summary>
 
892
    /// Adds an ellipse to the current path.
 
893
    /// </summary>
 
894
    public void AddEllipse(int x, int y, int width, int height)
 
895
    {
 
896
      AddEllipse((double)x, (double)y, (double)width, (double)height);
 
897
    }
 
898
 
 
899
    /// <summary>
 
900
    /// Adds an ellipse to the current path.
 
901
    /// </summary>
 
902
    public void AddEllipse(double x, double y, double width, double height)
 
903
    {
 
904
#if GDI
 
905
      this.gdipPath.AddEllipse((float)x, (float)y, (float)width, (float)height);
 
906
#endif
 
907
#if WPF
 
908
      StartFigure();
 
909
      this.pathGeometry.AddGeometry(new EllipseGeometry(new Rect(x, y, width, height)));
 
910
#endif
 
911
    }
 
912
 
 
913
    // ----- AddPolygon ---------------------------------------------------------------------------
 
914
 
 
915
#if GDI
 
916
    /// <summary>
 
917
    /// Adds a polygon to this path.
 
918
    /// </summary>
 
919
    public void AddPolygon(System.Drawing.Point[] points)
 
920
    {
 
921
      this.gdipPath.AddPolygon(points);
 
922
    }
 
923
#endif
 
924
 
 
925
#if WPF
 
926
    /// <summary>
 
927
    /// Adds a polygon to this path.
 
928
    /// </summary>
 
929
    public void AddPolygon(System.Windows.Point[] points)
 
930
    {
 
931
      //  TODOWPF
 
932
    }
 
933
#endif
 
934
 
 
935
#if GDI
 
936
    /// <summary>
 
937
    /// Adds a polygon to this path.
 
938
    /// </summary>
 
939
    public void AddPolygon(PointF[] points)
 
940
    {
 
941
      this.gdipPath.AddPolygon(points);
 
942
    }
 
943
#endif
 
944
 
 
945
    /// <summary>
 
946
    /// Adds a polygon to this path.
 
947
    /// </summary>
 
948
    public void AddPolygon(XPoint[] points)
 
949
    {
 
950
#if GDI
 
951
      this.gdipPath.AddPolygon(XGraphics.MakePointFArray(points));
 
952
#endif
 
953
#if WPF
 
954
      StartFigure();
 
955
      this.pathGeometry.AddGeometry(GeometryHelper.CreatePolygonGeometry(XGraphics.MakePointArray(points), XFillMode.Alternate, false));
 
956
#endif
 
957
    }
 
958
 
 
959
    // ----- AddPie -------------------------------------------------------------------------------
 
960
 
 
961
#if GDI
 
962
    /// <summary>
 
963
    /// Adds the outline of a pie shape to this path.
 
964
    /// </summary>
 
965
    public void AddPie(Rectangle rect, double startAngle, double sweepAngle)
 
966
    {
 
967
      this.gdipPath.AddPie(rect, (float)startAngle, (float)sweepAngle);
 
968
    }
 
969
#endif
 
970
 
 
971
#if GDI
 
972
    /// <summary>
 
973
    /// Adds the outline of a pie shape to this path.
 
974
    /// </summary>
 
975
    public void AddPie(RectangleF rect, double startAngle, double sweepAngle)
 
976
    {
 
977
      AddPie((double)rect.X, (double)rect.Y, (double)rect.Width, (double)rect.Height, startAngle, sweepAngle);
 
978
    }
 
979
#endif
 
980
 
 
981
    /// <summary>
 
982
    /// Adds the outline of a pie shape to this path.
 
983
    /// </summary>
 
984
    public void AddPie(XRect rect, double startAngle, double sweepAngle)
 
985
    {
 
986
      AddPie(rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
 
987
    }
 
988
 
 
989
    /// <summary>
 
990
    /// Adds the outline of a pie shape to this path.
 
991
    /// </summary>
 
992
    public void AddPie(int x, int y, int width, int height, double startAngle, double sweepAngle)
 
993
    {
 
994
      AddPie((double)x, (double)y, (double)width, (double)height, startAngle, sweepAngle);
 
995
    }
 
996
 
 
997
    /// <summary>
 
998
    /// Adds the outline of a pie shape to this path.
 
999
    /// </summary>
 
1000
    public void AddPie(double x, double y, double width, double height, double startAngle, double sweepAngle)
 
1001
    {
 
1002
#if GDI
 
1003
      this.gdipPath.AddPie((float)x, (float)y, (float)width, (float)height, (float)startAngle, (float)sweepAngle);
 
1004
#endif
 
1005
#if WPF
 
1006
#endif
 
1007
    }
 
1008
 
 
1009
    // ----- AddClosedCurve ------------------------------------------------------------------------
 
1010
 
 
1011
#if GDI
 
1012
    /// <summary>
 
1013
    /// Adds a closed curve to this path.
 
1014
    /// </summary>
 
1015
    public void AddClosedCurve(System.Drawing.Point[] points)
 
1016
    {
 
1017
      AddClosedCurve(XGraphics.MakeXPointArray(points), 0.5);
 
1018
    }
 
1019
#endif
 
1020
 
 
1021
#if WPF
 
1022
    /// <summary>
 
1023
    /// Adds a closed curve to this path.
 
1024
    /// </summary>
 
1025
    public void AddClosedCurve(System.Windows.Point[] points)
 
1026
    {
 
1027
      AddClosedCurve(XGraphics.MakeXPointArray(points), 0.5);
 
1028
    }
 
1029
#endif
 
1030
 
 
1031
#if GDI
 
1032
    /// <summary>
 
1033
    /// Adds a closed curve to this path.
 
1034
    /// </summary>
 
1035
    public void AddClosedCurve(PointF[] points)
 
1036
    {
 
1037
      AddClosedCurve(XGraphics.MakeXPointArray(points), 0.5);
 
1038
    }
 
1039
#endif
 
1040
 
 
1041
    /// <summary>
 
1042
    /// Adds a closed curve to this path.
 
1043
    /// </summary>
 
1044
    public void AddClosedCurve(XPoint[] points)
 
1045
    {
 
1046
      AddClosedCurve(points, 0.5);
 
1047
    }
 
1048
 
 
1049
#if GDI
 
1050
    /// <summary>
 
1051
    /// Adds a closed curve to this path.
 
1052
    /// </summary>
 
1053
    public void AddClosedCurve(System.Drawing.Point[] points, double tension)
 
1054
    {
 
1055
      AddClosedCurve(XGraphics.MakeXPointArray(points), tension);
 
1056
    }
 
1057
#endif
 
1058
 
 
1059
#if WPF
 
1060
    /// <summary>
 
1061
    /// Adds a closed curve to this path.
 
1062
    /// </summary>
 
1063
    public void AddClosedCurve(System.Windows.Point[] points, double tension)
 
1064
    {
 
1065
      AddClosedCurve(XGraphics.MakeXPointArray(points), tension);
 
1066
    }
 
1067
#endif
 
1068
 
 
1069
#if GDI
 
1070
    /// <summary>
 
1071
    /// Adds a closed curve to this path.
 
1072
    /// </summary>
 
1073
    public void AddClosedCurve(PointF[] points, double tension)
 
1074
    {
 
1075
      AddClosedCurve(XGraphics.MakeXPointArray(points), tension);
 
1076
    }
 
1077
#endif
 
1078
 
 
1079
    /// <summary>
 
1080
    /// Adds a closed curve to this path.
 
1081
    /// </summary>
 
1082
    public void AddClosedCurve(XPoint[] points, double tension)
 
1083
    {
 
1084
      if (points == null)
 
1085
        throw new ArgumentNullException("points");
 
1086
      int count = points.Length;
 
1087
      if (count == 0)
 
1088
        return;
 
1089
      if (count < 2)
 
1090
        throw new ArgumentException("Not enough points.", "points");
 
1091
#if GDI
 
1092
      this.gdipPath.AddClosedCurve(XGraphics.MakePointFArray(points), (float)tension);
 
1093
#endif
 
1094
#if WPF
 
1095
      tension /= 3;
 
1096
 
 
1097
      StartFigure();
 
1098
      PathFigure figure = CurrentPathFigure;
 
1099
      figure.StartPoint = new System.Windows.Point(points[0].x, points[0].y);
 
1100
 
 
1101
      if (count == 2)
 
1102
      {
 
1103
        figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[0], points[0], points[1], points[1], tension));
 
1104
      }
 
1105
      else
 
1106
      {
 
1107
        figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[count - 1], points[0], points[1], points[2], tension));
 
1108
        for (int idx = 1; idx < count - 2; idx++)
 
1109
          figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[idx - 1], points[idx], points[idx + 1], points[idx + 2], tension));
 
1110
        figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[count - 3], points[count - 2], points[count - 1], points[0], tension));
 
1111
        figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[count - 2], points[count - 1], points[0], points[1], tension));
 
1112
      }
 
1113
#endif
 
1114
    }
 
1115
 
 
1116
    // ----- AddPath ------------------------------------------------------------------------------
 
1117
 
 
1118
    /// <summary>
 
1119
    /// Adds the specified path to this path.
 
1120
    /// </summary>
 
1121
    public void AddPath(XGraphicsPath path, bool connect)
 
1122
    {
 
1123
#if GDI
 
1124
      this.gdipPath.AddPath(path.gdipPath, connect);
 
1125
#endif
 
1126
#if WPF
 
1127
      this.pathGeometry.AddGeometry(path.pathGeometry);
 
1128
#endif
 
1129
    }
 
1130
 
 
1131
    // ----- AddString ----------------------------------------------------------------------------
 
1132
 
 
1133
#if GDI
 
1134
    /// <summary>
 
1135
    /// Adds a text string to this path.
 
1136
    /// </summary>
 
1137
    public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, System.Drawing.Point origin, XStringFormat format)
 
1138
    {
 
1139
      //this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, origin, format.RealizeGdiStringFormat());
 
1140
      // TODOWPF
 
1141
      AddString(s, family, style, emSize, origin, format);
 
1142
    }
 
1143
#endif
 
1144
 
 
1145
#if WPF
 
1146
    /// <summary>
 
1147
    /// Adds a text string to this path.
 
1148
    /// </summary>
 
1149
    public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, System.Windows.Point origin, XStringFormat format)
 
1150
    {
 
1151
      AddString(s, family, style, emSize, new XPoint(origin), format);
 
1152
      //// TODOWPF
 
1153
      //Typeface typeface = FontHelper.CreateTypeface(family, style);
 
1154
      //FormattedText formattedText = new FormattedText(s, null, FlowDirection.LeftToRight, typeface, emSize, System.Windows.Media.Brushes.Black);
 
1155
      //Geometry geo = formattedText.BuildGeometry(origin);
 
1156
      //this.pathGeometry.AddGeometry(geo);
 
1157
    }
 
1158
#endif
 
1159
 
 
1160
#if GDI
 
1161
    /// <summary>
 
1162
    /// Adds a text string to this path.
 
1163
    /// </summary>
 
1164
    public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, PointF origin, XStringFormat format)
 
1165
    {
 
1166
      //this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, origin, format.RealizeGdiStringFormat());
 
1167
      // TODOWPF
 
1168
      AddString(s, family, style, emSize, new XRect(origin.X, origin.Y, 0, 0), format);
 
1169
    }
 
1170
#endif
 
1171
 
 
1172
    /// <summary>
 
1173
    /// Adds a text string to this path.
 
1174
    /// </summary>
 
1175
    public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XPoint origin, XStringFormat format)
 
1176
    {
 
1177
      try
 
1178
      {
 
1179
#if GDI
 
1180
        // TODOWPF
 
1181
        this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, origin.ToPointF(), format.RealizeGdiStringFormat());
 
1182
#endif
 
1183
#if WPF
 
1184
        Typeface typeface = FontHelper.CreateTypeface(family, style);
 
1185
        FormattedText ft = new FormattedText(s, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, emSize,
 
1186
          System.Windows.Media.Brushes.Black);
 
1187
        Geometry geo = ft.BuildGeometry(origin);
 
1188
        this.pathGeometry.AddGeometry(geo);
 
1189
#endif
 
1190
      }
 
1191
      catch { }
 
1192
    }
 
1193
 
 
1194
#if GDI
 
1195
    /// <summary>
 
1196
    /// Adds a text string to this path.
 
1197
    /// </summary>
 
1198
    public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, Rectangle layoutRect, XStringFormat format)
 
1199
    {
 
1200
      // TODOWPF
 
1201
      this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, layoutRect, format.RealizeGdiStringFormat());
 
1202
    }
 
1203
#endif
 
1204
 
 
1205
#if GDI
 
1206
    /// <summary>
 
1207
    /// Adds a text string to this path.
 
1208
    /// </summary>
 
1209
    public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, RectangleF layoutRect, XStringFormat format)
 
1210
    {
 
1211
      // TODOWPF
 
1212
      this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, layoutRect, format.RealizeGdiStringFormat());
 
1213
    }
 
1214
#endif
 
1215
 
 
1216
#if WPF
 
1217
    /// <summary>
 
1218
    /// Adds a text string to this path.
 
1219
    /// </summary>
 
1220
    public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, Rect rect, XStringFormat format)
 
1221
    {
 
1222
      //this.gdip Path.AddString(s, family.gdiFamily, (int)style, (float)emSize, layoutRect, format.RealizeGdiStringFormat());
 
1223
      AddString(s, family, style, emSize, new XRect(rect), format);
 
1224
    }
 
1225
#endif
 
1226
 
 
1227
    /// <summary>
 
1228
    /// Adds a text string to this path.
 
1229
    /// </summary>
 
1230
    public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XRect layoutRect, XStringFormat format)
 
1231
    {
 
1232
      if (s == null)
 
1233
        throw new ArgumentNullException("s");
 
1234
      if (family == null)
 
1235
        throw new ArgumentNullException("family");
 
1236
 
 
1237
      if (format.LineAlignment == XLineAlignment.BaseLine && layoutRect.Height != 0)
 
1238
        throw new InvalidOperationException("DrawString: With XLineAlignment.BaseLine the height of the layout rectangle must be 0.");
 
1239
 
 
1240
      if (s.Length == 0)
 
1241
        return;
 
1242
 
 
1243
      if (format == null)
 
1244
        format = XStringFormats.Default;
 
1245
 
 
1246
      XFont font = new XFont(family.Name, emSize, style);
 
1247
#if GDI && !WPF
 
1248
          RectangleF rc = layoutRect.ToRectangleF();
 
1249
          if (format.LineAlignment == XLineAlignment.BaseLine)
 
1250
          {
 
1251
            double lineSpace = font.GetHeight();
 
1252
            int cellSpace = font.FontFamily.GetLineSpacing(font.Style);
 
1253
            int cellAscent = font.FontFamily.GetCellAscent(font.Style);
 
1254
            int cellDescent = font.FontFamily.GetCellDescent(font.Style);
 
1255
            double cyAscent = lineSpace * cellAscent / cellSpace;
 
1256
            cyAscent = lineSpace * font.cellAscent / font.cellSpace;
 
1257
            rc.Offset(0, (float)-cyAscent);
 
1258
          }
 
1259
          //this.gfx.DrawString(text, font.RealizeGdiFont(), brush.RealizeGdiBrush(), rect,
 
1260
          //  format != null ? format.RealizeGdiStringFormat() : null);
 
1261
      this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, rc, format.RealizeGdiStringFormat());
 
1262
#endif
 
1263
#if WPF && !GDI
 
1264
      // Just a first sketch, but currently we do not need it and there is enough to do...
 
1265
      double x = layoutRect.X;
 
1266
      double y = layoutRect.Y;
 
1267
 
 
1268
      //double lineSpace = font.GetHeight(this);
 
1269
      //double cyAscent = lineSpace * font.cellAscent / font.cellSpace;
 
1270
      //double cyDescent = lineSpace * font.cellDescent / font.cellSpace;
 
1271
 
 
1272
      //double cyAscent = family.GetCellAscent(style) * family.GetLineSpacing(style) / family.getl; //fontlineSpace * font.cellAscent / font.cellSpace;
 
1273
      //double cyDescent =family.GetCellDescent(style); // lineSpace * font.cellDescent / font.cellSpace;
 
1274
      double lineSpace = font.GetHeight();
 
1275
      double cyAscent = lineSpace * font.cellAscent / font.cellSpace;
 
1276
      double cyDescent = lineSpace * font.cellDescent / font.cellSpace;
 
1277
 
 
1278
      bool bold = (style & XFontStyle.Bold) != 0;
 
1279
      bool italic = (style & XFontStyle.Italic) != 0;
 
1280
      bool strikeout = (style & XFontStyle.Strikeout) != 0;
 
1281
      bool underline = (style & XFontStyle.Underline) != 0;
 
1282
 
 
1283
      Typeface typeface = FontHelper.CreateTypeface(family, style);
 
1284
      FormattedText formattedText = new FormattedText(s, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, emSize,
 
1285
        System.Windows.Media.Brushes.Black);
 
1286
 
 
1287
      switch (format.Alignment)
 
1288
      {
 
1289
        case XStringAlignment.Near:
 
1290
          // nothing to do, this is the default
 
1291
          //formattedText.TextAlignment = TextAlignment.Left;
 
1292
          break;
 
1293
 
 
1294
        case XStringAlignment.Center:
 
1295
          x += layoutRect.Width / 2;
 
1296
          formattedText.TextAlignment = TextAlignment.Center;
 
1297
          break;
 
1298
 
 
1299
        case XStringAlignment.Far:
 
1300
          x += layoutRect.Width;
 
1301
          formattedText.TextAlignment = TextAlignment.Right;
 
1302
          break;
 
1303
      }
 
1304
      //if (PageDirection == XPageDirection.Downwards)
 
1305
      //{
 
1306
      switch (format.LineAlignment)
 
1307
      {
 
1308
        case XLineAlignment.Near:
 
1309
          //y += cyAscent;
 
1310
          break;
 
1311
 
 
1312
        case XLineAlignment.Center:
 
1313
          // TODO use CapHeight. PDFlib also uses 3/4 of ascent
 
1314
          y += -formattedText.Baseline + (cyAscent * 2 / 4) + layoutRect.Height / 2;
 
1315
          break;
 
1316
 
 
1317
        case XLineAlignment.Far:
 
1318
          y += -formattedText.Baseline - cyDescent + layoutRect.Height;
 
1319
          break;
 
1320
 
 
1321
        case XLineAlignment.BaseLine:
 
1322
          y -= formattedText.Baseline;
 
1323
          break;
 
1324
      }
 
1325
      //}
 
1326
      //else
 
1327
      //{
 
1328
      //  // TODOWPF
 
1329
      //  switch (format.LineAlignment)
 
1330
      //  {
 
1331
      //    case XLineAlignment.Near:
 
1332
      //      //y += cyDescent;
 
1333
      //      break;
 
1334
 
 
1335
      //    case XLineAlignment.Center:
 
1336
      //      // TODO use CapHeight. PDFlib also uses 3/4 of ascent
 
1337
      //      //y += -(cyAscent * 3 / 4) / 2 + rect.Height / 2;
 
1338
      //      break;
 
1339
 
 
1340
      //    case XLineAlignment.Far:
 
1341
      //      //y += -cyAscent + rect.Height;
 
1342
      //      break;
 
1343
 
 
1344
      //    case XLineAlignment.BaseLine:
 
1345
      //      // nothing to do
 
1346
      //      break;
 
1347
      //  }
 
1348
      //}
 
1349
 
 
1350
      //if (bold && !descriptor.IsBoldFace)
 
1351
      //{
 
1352
      //  // TODO: emulate bold by thicker outline
 
1353
      //}
 
1354
 
 
1355
      //if (italic && !descriptor.IsBoldFace)
 
1356
      //{
 
1357
      //  // TODO: emulate italic by shearing transformation
 
1358
      //}
 
1359
 
 
1360
      if (underline)
 
1361
      {
 
1362
        //double underlinePosition = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlinePosition / font.cellSpace;
 
1363
        //double underlineThickness = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlineThickness / font.cellSpace;
 
1364
        //DrawRectangle(null, brush, x, y - underlinePosition, width, underlineThickness);
 
1365
      }
 
1366
 
 
1367
      if (strikeout)
 
1368
      {
 
1369
        //double strikeoutPosition = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutPosition / font.cellSpace;
 
1370
        //double strikeoutSize = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutSize / font.cellSpace;
 
1371
        //DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize);
 
1372
      }
 
1373
 
 
1374
      //this.dc.DrawText(formattedText, layoutRectangle.Location.ToPoint());
 
1375
      //this.dc.DrawText(formattedText, new System.Windows.Point(x, y));
 
1376
 
 
1377
      Geometry geo = formattedText.BuildGeometry(new Point(x, y));
 
1378
      this.pathGeometry.AddGeometry(geo);
 
1379
#endif
 
1380
    }
 
1381
 
 
1382
    // ----- CloseAllFigures ----------------------------------------------------------------------
 
1383
 
 
1384
    // TODO? CloseAllFigures
 
1385
    //public void CloseAllFigures();
 
1386
 
 
1387
    // --------------------------------------------------------------------------------------------
 
1388
 
 
1389
    /// <summary>
 
1390
    /// Closes the current figure and starts a new figure.
 
1391
    /// </summary>
 
1392
    public void CloseFigure()
 
1393
    {
 
1394
#if GDI
 
1395
      this.gdipPath.CloseFigure();
 
1396
#endif
 
1397
#if WPF
 
1398
      PathFigure figure = CurrentPathFigure;
 
1399
      if (figure.Segments.Count != 0)
 
1400
      {
 
1401
        figure.IsClosed = true;
 
1402
        //this.figure = null; // force start of new figure
 
1403
        this.startNewFigure = true;
 
1404
      }
 
1405
#endif
 
1406
    }
 
1407
 
 
1408
    /// <summary>
 
1409
    /// Starts a new figure without closing the current figure.
 
1410
    /// </summary>
 
1411
    public void StartFigure()
 
1412
    {
 
1413
#if GDI
 
1414
      this.gdipPath.StartFigure();
 
1415
#endif
 
1416
#if WPF
 
1417
      PathFigure figure = CurrentPathFigure;
 
1418
      if (figure.Segments.Count != 0)
 
1419
      {
 
1420
        figure = new PathFigure();
 
1421
        this.pathGeometry.Figures.Add(figure);
 
1422
      }
 
1423
#endif
 
1424
    }
 
1425
 
 
1426
    // --------------------------------------------------------------------------------------------
 
1427
 
 
1428
    /// <summary>
 
1429
    /// Gets or sets an XFillMode that determines how the interiors of shapes are filled.
 
1430
    /// </summary>
 
1431
    public XFillMode FillMode
 
1432
    {
 
1433
      get { return this.fillMode; }
 
1434
      set
 
1435
      {
 
1436
        this.fillMode = value;
 
1437
#if GDI
 
1438
        this.gdipPath.FillMode = (FillMode)value;
 
1439
#endif
 
1440
#if WPF
 
1441
        this.pathGeometry.FillRule = value == XFillMode.Winding ? FillRule.Nonzero : FillRule.EvenOdd;
 
1442
#endif
 
1443
      }
 
1444
    }
 
1445
    XFillMode fillMode;
 
1446
 
 
1447
    // --------------------------------------------------------------------------------------------
 
1448
 
 
1449
    /// <summary>
 
1450
    /// Converts each curve in this XGraphicsPath into a sequence of connected line segments. 
 
1451
    /// </summary>
 
1452
    public void Flatten()
 
1453
    {
 
1454
#if GDI
 
1455
      this.gdipPath.Flatten();
 
1456
#endif
 
1457
#if WPF
 
1458
      this.pathGeometry = this.pathGeometry.GetFlattenedPathGeometry();
 
1459
#endif
 
1460
    }
 
1461
 
 
1462
    /// <summary>
 
1463
    /// Converts each curve in this XGraphicsPath into a sequence of connected line segments. 
 
1464
    /// </summary>
 
1465
    public void Flatten(XMatrix matrix)
 
1466
    {
 
1467
#if GDI
 
1468
      this.gdipPath.Flatten(matrix.ToGdiMatrix());
 
1469
#endif
 
1470
#if WPF
 
1471
      this.pathGeometry = this.pathGeometry.GetFlattenedPathGeometry();
 
1472
      this.pathGeometry.Transform = new MatrixTransform(matrix.ToWpfMatrix());
 
1473
#endif
 
1474
    }
 
1475
 
 
1476
    /// <summary>
 
1477
    /// Converts each curve in this XGraphicsPath into a sequence of connected line segments. 
 
1478
    /// </summary>
 
1479
    public void Flatten(XMatrix matrix, double flatness)
 
1480
    {
 
1481
#if GDI
 
1482
      this.gdipPath.Flatten(matrix.ToGdiMatrix(), (float)flatness);
 
1483
#endif
 
1484
#if WPF
 
1485
      // TODOWPF: matrix
 
1486
      this.pathGeometry = this.pathGeometry.GetFlattenedPathGeometry();
 
1487
#endif
 
1488
    }
 
1489
 
 
1490
    // --------------------------------------------------------------------------------------------
 
1491
 
 
1492
    /// <summary>
 
1493
    /// Replaces this path with curves that enclose the area that is filled when this path is drawn 
 
1494
    /// by the specified pen.
 
1495
    /// </summary>
 
1496
    public void Widen(XPen pen)
 
1497
    {
 
1498
#if GDI
 
1499
      this.gdipPath.Widen(pen.RealizeGdiPen());
 
1500
#endif
 
1501
#if WPF
 
1502
      this.pathGeometry = this.pathGeometry.GetWidenedPathGeometry(pen.RealizeWpfPen());
 
1503
#endif
 
1504
    }
 
1505
 
 
1506
    /// <summary>
 
1507
    /// Replaces this path with curves that enclose the area that is filled when this path is drawn 
 
1508
    /// by the specified pen.
 
1509
    /// </summary>
 
1510
    public void Widen(XPen pen, XMatrix matrix)
 
1511
    {
 
1512
#if GDI
 
1513
      this.gdipPath.Widen(pen.RealizeGdiPen(), matrix.ToGdiMatrix());
 
1514
#endif
 
1515
#if WPF
 
1516
      this.pathGeometry = this.pathGeometry.GetWidenedPathGeometry(pen.RealizeWpfPen());
 
1517
#endif
 
1518
    }
 
1519
 
 
1520
    /// <summary>
 
1521
    /// Replaces this path with curves that enclose the area that is filled when this path is drawn 
 
1522
    /// by the specified pen.
 
1523
    /// </summary>
 
1524
    public void Widen(XPen pen, XMatrix matrix, double flatness)
 
1525
    {
 
1526
#if GDI
 
1527
      this.gdipPath.Widen(pen.RealizeGdiPen(), matrix.ToGdiMatrix(), (float)flatness);
 
1528
#endif
 
1529
#if WPF
 
1530
      this.pathGeometry = this.pathGeometry.GetWidenedPathGeometry(pen.RealizeWpfPen());
 
1531
#endif
 
1532
    }
 
1533
 
 
1534
    /// <summary>
 
1535
    /// Grants access to internal objects of this class.
 
1536
    /// </summary>
 
1537
    public XGraphicsPathInternals Internals
 
1538
    {
 
1539
      get { return new XGraphicsPathInternals(this); }
 
1540
    }
 
1541
  }
 
1542
}
 
 
b'\\ No newline at end of file'