forked from ststeiger/PdfSharpCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXGraphics.cs
More file actions
1973 lines (1652 loc) · 71.2 KB
/
Copy pathXGraphics.cs
File metadata and controls
1973 lines (1652 loc) · 71.2 KB
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region PDFsharp - A .NET library for processing PDF
//
// Authors:
// Stefan Lange
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.PdfSharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
using System;
using PdfSharpCore.Pdf;
using PdfSharpCore.Drawing.Pdf;
using PdfSharpCore.Pdf.Advanced;
#pragma warning disable 1587
// ReSharper disable UseNullPropagation
// ReSharper disable RedundantNameQualifier
// ReSharper disable UseNameofExpression
namespace PdfSharpCore.Drawing // #??? aufräumen
{
/// <summary>
/// Holds information about the current state of the XGraphics object.
/// </summary>
[Flags]
enum InternalGraphicsMode
{
DrawingGdiGraphics,
DrawingPdfContent,
DrawingBitmap,
}
/// <summary>
/// Represents a drawing surface for a fixed size page.
/// </summary>
public sealed class XGraphics : IDisposable
{
/// <summary>
/// Initializes a new instance of the XGraphics class for drawing on a PDF page.
/// </summary>
XGraphics(PdfPage page, XGraphicsPdfPageOptions options, XGraphicsUnit pageUnit, XPageDirection pageDirection)
{
if (page == null)
throw new ArgumentNullException("page");
if (page.Owner == null)
throw new ArgumentException("You cannot draw on a page that is not owned by a PdfDocument object.", "page");
if (page.RenderContent != null)
throw new InvalidOperationException("An XGraphics object already exists for this page and must be disposed before a new one can be created.");
if (page.Owner.IsReadOnly)
throw new InvalidOperationException("Cannot create XGraphics for a page of a document that cannot be modified. Use PdfDocumentOpenMode.Modify.");
_gsStack = new GraphicsStateStack(this);
PdfContent content = null;
switch (options)
{
case XGraphicsPdfPageOptions.Replace:
page.Contents.Elements.Clear();
goto case XGraphicsPdfPageOptions.Append;
case XGraphicsPdfPageOptions.Prepend:
content = page.Contents.PrependContent();
break;
case XGraphicsPdfPageOptions.Append:
content = page.Contents.AppendContent();
break;
}
page.RenderContent = content;
_renderer = new XGraphicsPdfRenderer(page, this, options);
_pageSizePoints = new XSize(page.Width, page.Height);
switch (pageUnit)
{
case XGraphicsUnit.Point:
_pageSize = new XSize(page.Width, page.Height);
break;
case XGraphicsUnit.Inch:
_pageSize = new XSize(XUnit.FromPoint(page.Width).Inch, XUnit.FromPoint(page.Height).Inch);
break;
case XGraphicsUnit.Millimeter:
_pageSize = new XSize(XUnit.FromPoint(page.Width).Millimeter, XUnit.FromPoint(page.Height).Millimeter);
break;
case XGraphicsUnit.Centimeter:
_pageSize = new XSize(XUnit.FromPoint(page.Width).Centimeter, XUnit.FromPoint(page.Height).Centimeter);
break;
case XGraphicsUnit.Presentation:
_pageSize = new XSize(XUnit.FromPoint(page.Width).Presentation, XUnit.FromPoint(page.Height).Presentation);
break;
default:
throw new NotImplementedException("unit");
}
_pageUnit = pageUnit;
_pageDirection = pageDirection;
Initialize();
}
XGraphics(XSize size, XGraphicsUnit pageUnit, XPageDirection pageDirection)
{
if (size == null)
throw new ArgumentNullException("size");
_gsStack = new GraphicsStateStack(this);
_pageSizePoints = new XSize(size.Width, size.Height);
switch (pageUnit)
{
case XGraphicsUnit.Point:
_pageSize = new XSize(size.Width, size.Height);
break;
case XGraphicsUnit.Inch:
_pageSize = new XSize(XUnit.FromPoint(size.Width).Inch, XUnit.FromPoint(size.Height).Inch);
break;
case XGraphicsUnit.Millimeter:
_pageSize = new XSize(XUnit.FromPoint(size.Width).Millimeter, XUnit.FromPoint(size.Height).Millimeter);
break;
case XGraphicsUnit.Centimeter:
_pageSize = new XSize(XUnit.FromPoint(size.Width).Centimeter, XUnit.FromPoint(size.Height).Centimeter);
break;
case XGraphicsUnit.Presentation:
_pageSize = new XSize(XUnit.FromPoint(size.Width).Presentation, XUnit.FromPoint(size.Height).Presentation);
break;
default:
throw new NotImplementedException("unit");
}
_pageUnit = pageUnit;
_pageDirection = pageDirection;
Initialize();
}
XGraphics(IXGraphicsRenderer renderer, XSize size, XGraphicsUnit pageUnit, XPageDirection pageDirection)
{
_renderer = renderer ?? throw new ArgumentNullException(nameof(renderer));
_gsStack = new GraphicsStateStack(this);
_pageSizePoints = new XSize(size.Width, size.Height);
switch (pageUnit)
{
case XGraphicsUnit.Point:
_pageSize = new XSize(size.Width, size.Height);
break;
case XGraphicsUnit.Inch:
_pageSize = new XSize(XUnit.FromPoint(size.Width).Inch, XUnit.FromPoint(size.Height).Inch);
break;
case XGraphicsUnit.Millimeter:
_pageSize = new XSize(XUnit.FromPoint(size.Width).Millimeter, XUnit.FromPoint(size.Height).Millimeter);
break;
case XGraphicsUnit.Centimeter:
_pageSize = new XSize(XUnit.FromPoint(size.Width).Centimeter, XUnit.FromPoint(size.Height).Centimeter);
break;
case XGraphicsUnit.Presentation:
_pageSize = new XSize(XUnit.FromPoint(size.Width).Presentation, XUnit.FromPoint(size.Height).Presentation);
break;
default:
throw new NotImplementedException($"{nameof(pageUnit)}: {pageUnit}");
}
_pageUnit = pageUnit;
_pageDirection = pageDirection;
Initialize();
}
/// <summary>
/// Initializes a new instance of the XGraphics class used for drawing on a form.
/// </summary>
XGraphics(XForm form)
{
if (form == null)
throw new ArgumentNullException("form");
_form = form;
form.AssociateGraphics(this);
_gsStack = new GraphicsStateStack(this);
_drawGraphics = false;
if (form.Owner != null)
_renderer = new XGraphicsPdfRenderer(form, this);
_pageSize = form.Size;
Initialize();
}
/// <summary>
/// Creates the measure context. This is a graphics context created only for querying measures of text.
/// Drawing on a measure context has no effect.
/// </summary>
public static XGraphics CreateMeasureContext(XSize size, XGraphicsUnit pageUnit, XPageDirection pageDirection)
{
return new XGraphics(size, pageUnit, pageDirection);
}
public static XGraphics FromRenderer(IXGraphicsRenderer renderer, XSize size, XGraphicsUnit pageUnit, XPageDirection pageDirection)
{
return new XGraphics(renderer, size, pageUnit, pageDirection);
}
/// <summary>
/// Creates a new instance of the XGraphics class from a PdfSharpCore.Pdf.PdfPage object.
/// </summary>
public static XGraphics FromPdfPage(PdfPage page)
{
return new XGraphics(page, XGraphicsPdfPageOptions.Append, XGraphicsUnit.Point, XPageDirection.Downwards);
}
/// <summary>
/// Creates a new instance of the XGraphics class from a PdfSharpCore.Pdf.PdfPage object.
/// </summary>
public static XGraphics FromPdfPage(PdfPage page, XGraphicsUnit unit)
{
return new XGraphics(page, XGraphicsPdfPageOptions.Append, unit, XPageDirection.Downwards);
}
/// <summary>
/// Creates a new instance of the XGraphics class from a PdfSharpCore.Pdf.PdfPage object.
/// </summary>
public static XGraphics FromPdfPage(PdfPage page, XPageDirection pageDirection)
{
return new XGraphics(page, XGraphicsPdfPageOptions.Append, XGraphicsUnit.Point, pageDirection);
}
/// <summary>
/// Creates a new instance of the XGraphics class from a PdfSharpCore.Pdf.PdfPage object.
/// </summary>
public static XGraphics FromPdfPage(PdfPage page, XGraphicsPdfPageOptions options)
{
return new XGraphics(page, options, XGraphicsUnit.Point, XPageDirection.Downwards);
}
/// <summary>
/// Creates a new instance of the XGraphics class from a PdfSharpCore.Pdf.PdfPage object.
/// </summary>
public static XGraphics FromPdfPage(PdfPage page, XGraphicsPdfPageOptions options, XPageDirection pageDirection)
{
return new XGraphics(page, options, XGraphicsUnit.Point, pageDirection);
}
/// <summary>
/// Creates a new instance of the XGraphics class from a PdfSharpCore.Pdf.PdfPage object.
/// </summary>
public static XGraphics FromPdfPage(PdfPage page, XGraphicsPdfPageOptions options, XGraphicsUnit unit)
{
return new XGraphics(page, options, unit, XPageDirection.Downwards);
}
/// <summary>
/// Creates a new instance of the XGraphics class from a PdfSharpCore.Pdf.PdfPage object.
/// </summary>
public static XGraphics FromPdfPage(PdfPage page, XGraphicsPdfPageOptions options, XGraphicsUnit unit, XPageDirection pageDirection)
{
return new XGraphics(page, options, unit, pageDirection);
}
/// <summary>
/// Creates a new instance of the XGraphics class from a PdfSharpCore.Drawing.XPdfForm object.
/// </summary>
public static XGraphics FromPdfForm(XPdfForm form)
{
if (form.Gfx != null)
return form.Gfx;
return new XGraphics(form);
}
/// <summary>
/// Creates a new instance of the XGraphics class from a PdfSharpCore.Drawing.XForm object.
/// </summary>
public static XGraphics FromForm(XForm form)
{
if (form.Gfx != null)
return form.Gfx;
return new XGraphics(form);
}
/// <summary>
/// Creates a new instance of the XGraphics class from a PdfSharpCore.Drawing.XForm object.
/// </summary>
public static XGraphics FromImage(XImage image)
{
return FromImage(image, XGraphicsUnit.Point);
}
/// <summary>
/// Creates a new instance of the XGraphics class from a PdfSharpCore.Drawing.XImage object.
/// </summary>
public static XGraphics FromImage(XImage image, XGraphicsUnit unit)
{
if (image == null)
throw new ArgumentNullException("image");
XBitmapImage bmImage = image as XBitmapImage;
if (bmImage != null)
{
}
return null;
}
/// <summary>
/// Internal setup.
/// </summary>
void Initialize()
{
_pageOrigin = new XPoint();
double pageHeight = _pageSize.Height;
PdfPage targetPage = PdfPage;
XPoint trimOffset = new XPoint();
if (targetPage != null && targetPage.TrimMargins.AreSet)
{
pageHeight += targetPage.TrimMargins.Top.Point + targetPage.TrimMargins.Bottom.Point;
trimOffset = new XPoint(targetPage.TrimMargins.Left.Point, targetPage.TrimMargins.Top.Point);
}
XMatrix matrix = new XMatrix();
if (_pageDirection != XPageDirection.Downwards)
matrix.Prepend(new XMatrix(1, 0, 0, -1, 0, pageHeight));
if (trimOffset != new XPoint())
matrix.TranslatePrepend(trimOffset.X, -trimOffset.Y);
DefaultViewMatrix = matrix;
_transform = new XMatrix();
}
/// <summary>
/// Releases all resources used by this object.
/// </summary>
public void Dispose()
{
Dispose(true);
}
void Dispose(bool disposing)
{
if (!_disposed)
{
_disposed = true;
if (disposing)
{
// Dispose managed resources.
if (_associatedImage != null)
{
_associatedImage.DisassociateWithGraphics(this);
_associatedImage = null;
}
}
if (_form != null)
_form.Finish();
_drawGraphics = false;
if (_renderer != null)
{
_renderer.Close();
_renderer = null;
}
}
}
bool _disposed;
/// <summary>
/// Internal hack for MigraDoc. Will be removed in further releases.
/// Unicode support requires a global refactoring of MigraDoc and will be done in further releases.
/// </summary>
// ReSharper disable once InconsistentNaming
// ReSharper disable once ConvertToAutoProperty
public PdfFontEncoding MUH // MigraDoc Unicode Hack...
{
get { return _muh; }
set { _muh = value; }
}
PdfFontEncoding _muh;
/// <summary>
/// Gets or sets the unit of measure used for page coordinates.
/// CURRENTLY ONLY POINT IS IMPLEMENTED.
/// </summary>
public XGraphicsUnit PageUnit
{
get { return _pageUnit; }
//set
//{
// // TODO: other page units
// if (value != XGraphicsUnit.Point)
// throw new NotImplementedException("PageUnit must be XGraphicsUnit.Point in current implementation.");
//}
}
readonly XGraphicsUnit _pageUnit;
/// <summary>
/// Gets or sets the a value indicating in which direction y-value grow.
/// </summary>
public XPageDirection PageDirection
{
get { return _pageDirection; }
set
{
// Is there really anybody who needes the concept of XPageDirection.Upwards?
if (value != XPageDirection.Downwards)
throw new NotImplementedException("PageDirection must be XPageDirection.Downwards in current implementation.");
}
}
readonly XPageDirection _pageDirection;
/// <summary>
/// Gets the current page origin. Setting the origin is not yet implemented.
/// </summary>
public XPoint PageOrigin
{
get { return _pageOrigin; }
set
{
// Is there really anybody who needes to set the page origin?
if (value != new XPoint())
throw new NotImplementedException("PageOrigin cannot be modified in current implementation.");
}
}
XPoint _pageOrigin;
/// <summary>
/// Gets the current size of the page.
/// </summary>
public XSize PageSize
{
get { return _pageSize; }
//set
//{
// //TODO
// throw new NotImplementedException("PageSize cannot be modified in current implementation.");
//}
}
XSize _pageSize;
XSize _pageSizePoints;
#region Drawing
// ----- DrawLine -----------------------------------------------------------------------------
/// <summary>
/// Draws a line connecting two XPoint structures.
/// </summary>
public void DrawLine(XPen pen, XPoint pt1, XPoint pt2)
{
DrawLine(pen, pt1.X, pt1.Y, pt2.X, pt2.Y);
}
/// <summary>
/// Draws a line connecting the two points specified by coordinate pairs.
/// </summary>
public void DrawLine(XPen pen, double x1, double y1, double x2, double y2)
{
if (pen == null)
throw new ArgumentNullException("pen");
if (_renderer != null)
_renderer.DrawLines(pen, new XPoint[] { new XPoint(x1, y1), new XPoint(x2, y2) });
}
// ----- DrawLines ----------------------------------------------------------------------------
/// <summary>
/// Draws a series of line segments that connect an array of points.
/// </summary>
public void DrawLines(XPen pen, XPoint[] points)
{
if (pen == null)
throw new ArgumentNullException("pen");
if (points == null)
throw new ArgumentNullException("points");
if (points.Length < 2)
throw new ArgumentException("points", PSSR.PointArrayAtLeast(2));
if (_renderer != null)
_renderer.DrawLines(pen, points);
}
/// <summary>
/// Draws a series of line segments that connect an array of x and y pairs.
/// </summary>
public void DrawLines(XPen pen, double x, double y, params double[] value)
{
if (pen == null)
throw new ArgumentNullException("pen");
if (value == null)
throw new ArgumentNullException("value");
int length = value.Length;
XPoint[] points = new XPoint[length / 2 + 1];
points[0].X = x;
points[0].Y = y;
for (int idx = 0; idx < length / 2; idx++)
{
points[idx + 1].X = value[2 * idx];
points[idx + 1].Y = value[2 * idx + 1];
}
DrawLines(pen, points);
}
// ----- DrawBezier ---------------------------------------------------------------------------
/// <summary>
/// Draws a Bézier spline defined by four points.
/// </summary>
public void DrawBezier(XPen pen, XPoint pt1, XPoint pt2, XPoint pt3, XPoint pt4)
{
DrawBezier(pen, pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
}
/// <summary>
/// Draws a Bézier spline defined by four points.
/// </summary>
public void DrawBezier(XPen pen, double x1, double y1, double x2, double y2,
double x3, double y3, double x4, double y4)
{
if (pen == null)
throw new ArgumentNullException("pen");
if (_renderer != null)
_renderer.DrawBeziers(pen,
new XPoint[] { new XPoint(x1, y1), new XPoint(x2, y2), new XPoint(x3, y3), new XPoint(x4, y4) });
}
// ----- DrawBeziers --------------------------------------------------------------------------
/// <summary>
/// Draws a series of Bézier splines from an array of points.
/// </summary>
public void DrawBeziers(XPen pen, XPoint[] points)
{
if (pen == null)
throw new ArgumentNullException("pen");
int count = points.Length;
if (count == 0)
return;
if ((count - 1) % 3 != 0)
throw new ArgumentException("Invalid number of points for bezier curves. Number must fulfil 4+3n.", "points");
if (_renderer != null)
_renderer.DrawBeziers(pen, points);
}
// ----- DrawCurve ----------------------------------------------------------------------------
/// <summary>
/// Draws a cardinal spline through a specified array of points.
/// </summary>
public void DrawCurve(XPen pen, XPoint[] points)
{
DrawCurve(pen, points, 0.5);
}
/// <summary>
/// Draws a cardinal spline through a specified array of point using a specified tension.
/// The drawing begins offset from the beginning of the array.
/// </summary>
public void DrawCurve(XPen pen, XPoint[] points, int offset, int numberOfSegments, double tension)
{
XPoint[] points2 = new XPoint[numberOfSegments];
Array.Copy(points, offset, points2, 0, numberOfSegments);
DrawCurve(pen, points2, tension);
}
/// <summary>
/// Draws a cardinal spline through a specified array of points using a specified tension.
/// </summary>
public void DrawCurve(XPen pen, XPoint[] points, double tension)
{
if (pen == null)
throw new ArgumentNullException("pen");
if (points == null)
throw new ArgumentNullException("points");
int count = points.Length;
if (count < 2)
throw new ArgumentException("DrawCurve requires two or more points.", "points");
if (_renderer != null)
_renderer.DrawCurve(pen, points, tension);
}
// ----- DrawArc ------------------------------------------------------------------------------
/// <summary>
/// Draws an arc representing a portion of an ellipse.
/// </summary>
public void DrawArc(XPen pen, XRect rect, double startAngle, double sweepAngle)
{
DrawArc(pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
}
/// <summary>
/// Draws an arc representing a portion of an ellipse.
/// </summary>
public void DrawArc(XPen pen, double x, double y, double width, double height, double startAngle, double sweepAngle)
{
if (pen == null)
throw new ArgumentNullException("pen");
if (Math.Abs(sweepAngle) >= 360)
{
DrawEllipse(pen, x, y, width, height);
}
else
{
if (_renderer != null)
_renderer.DrawArc(pen, x, y, width, height, startAngle, sweepAngle);
}
}
// ----- DrawRectangle ------------------------------------------------------------------------
// ----- stroke -----
/// <summary>
/// Draws a rectangle.
/// </summary>
public void DrawRectangle(XPen pen, XRect rect)
{
DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
}
/// <summary>
/// Draws a rectangle.
/// </summary>
public void DrawRectangle(XPen pen, double x, double y, double width, double height)
{
if (pen == null)
throw new ArgumentNullException("pen");
if (_drawGraphics)
{
}
if (_renderer != null)
_renderer.DrawRectangle(pen, null, x, y, width, height);
}
// ----- fill -----
/// <summary>
/// Draws a rectangle.
/// </summary>
public void DrawRectangle(XBrush brush, XRect rect)
{
DrawRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height);
}
/// <summary>
/// Draws a rectangle.
/// </summary>
public void DrawRectangle(XBrush brush, double x, double y, double width, double height)
{
if (brush == null)
throw new ArgumentNullException("brush");
if (_renderer != null)
_renderer.DrawRectangle(null, brush, x, y, width, height);
}
// ----- stroke and fill -----
/// <summary>
/// Draws a rectangle.
/// </summary>
public void DrawRectangle(XPen pen, XBrush brush, XRect rect)
{
DrawRectangle(pen, brush, rect.X, rect.Y, rect.Width, rect.Height);
}
/// <summary>
/// Draws a rectangle.
/// </summary>
public void DrawRectangle(XPen pen, XBrush brush, double x, double y, double width, double height)
{
if (pen == null && brush == null)
throw new ArgumentNullException("pen and brush", PSSR.NeedPenOrBrush);
if (_renderer != null)
_renderer.DrawRectangle(pen, brush, x, y, width, height);
}
// ----- DrawRectangles -----------------------------------------------------------------------
// ----- stroke -----
/// <summary>
/// Draws a series of rectangles.
/// </summary>
public void DrawRectangles(XPen pen, XRect[] rectangles)
{
if (pen == null)
throw new ArgumentNullException("pen");
if (rectangles == null)
throw new ArgumentNullException("rectangles");
DrawRectangles(pen, null, rectangles);
}
// ----- fill -----
/// <summary>
/// Draws a series of rectangles.
/// </summary>
public void DrawRectangles(XBrush brush, XRect[] rectangles)
{
if (brush == null)
throw new ArgumentNullException("brush");
if (rectangles == null)
throw new ArgumentNullException("rectangles");
DrawRectangles(null, brush, rectangles);
}
// ----- stroke and fill -----
/// <summary>
/// Draws a series of rectangles.
/// </summary>
public void DrawRectangles(XPen pen, XBrush brush, XRect[] rectangles)
{
if (pen == null && brush == null)
throw new ArgumentNullException("pen and brush", PSSR.NeedPenOrBrush);
if (rectangles == null)
throw new ArgumentNullException("rectangles");
int count = rectangles.Length;
if (_renderer != null)
{
for (int idx = 0; idx < count; idx++)
{
XRect rect = rectangles[idx];
_renderer.DrawRectangle(pen, brush, rect.X, rect.Y, rect.Width, rect.Height);
}
}
}
// ----- DrawRoundedRectangle -----------------------------------------------------------------
// ----- stroke -----
/// <summary>
/// Draws a rectangles with round corners.
/// </summary>
public void DrawRoundedRectangle(XPen pen, XRect rect, XSize ellipseSize)
{
DrawRoundedRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height, ellipseSize.Width, ellipseSize.Height);
}
/// <summary>
/// Draws a rectangles with round corners.
/// </summary>
public void DrawRoundedRectangle(XPen pen, double x, double y, double width, double height, double ellipseWidth, double ellipseHeight)
{
if (pen == null)
throw new ArgumentNullException("pen");
DrawRoundedRectangle(pen, null, x, y, width, height, ellipseWidth, ellipseHeight);
}
// ----- fill -----
/// <summary>
/// Draws a rectangles with round corners.
/// </summary>
public void DrawRoundedRectangle(XBrush brush, XRect rect, XSize ellipseSize)
{
DrawRoundedRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height, ellipseSize.Width, ellipseSize.Height);
}
/// <summary>
/// Draws a rectangles with round corners.
/// </summary>
public void DrawRoundedRectangle(XBrush brush, double x, double y, double width, double height, double ellipseWidth, double ellipseHeight)
{
if (brush == null)
throw new ArgumentNullException("brush");
DrawRoundedRectangle(null, brush, x, y, width, height, ellipseWidth, ellipseHeight);
}
// ----- stroke and fill -----
/// <summary>
/// Draws a rectangles with round corners.
/// </summary>
public void DrawRoundedRectangle(XPen pen, XBrush brush, XRect rect, XSize ellipseSize)
{
DrawRoundedRectangle(pen, brush, rect.X, rect.Y, rect.Width, rect.Height, ellipseSize.Width, ellipseSize.Height);
}
/// <summary>
/// Draws a rectangles with round corners.
/// </summary>
public void DrawRoundedRectangle(XPen pen, XBrush brush, double x, double y, double width, double height,
double ellipseWidth, double ellipseHeight)
{
if (pen == null && brush == null)
throw new ArgumentNullException("pen and brush", PSSR.NeedPenOrBrush);
if (_renderer != null)
_renderer.DrawRoundedRectangle(pen, brush, x, y, width, height, ellipseWidth, ellipseHeight);
}
// ----- DrawEllipse --------------------------------------------------------------------------
// ----- stroke -----
/// <summary>
/// Draws an ellipse defined by a bounding rectangle.
/// </summary>
public void DrawEllipse(XPen pen, XRect rect)
{
DrawEllipse(pen, rect.X, rect.Y, rect.Width, rect.Height);
}
/// <summary>
/// Draws an ellipse defined by a bounding rectangle.
/// </summary>
public void DrawEllipse(XPen pen, double x, double y, double width, double height)
{
if (pen == null)
throw new ArgumentNullException("pen");
// No DrawArc defined?
if (_drawGraphics)
{
}
if (_renderer != null)
_renderer.DrawEllipse(pen, null, x, y, width, height);
}
// ----- fill -----
/// <summary>
/// Draws an ellipse defined by a bounding rectangle.
/// </summary>
public void DrawEllipse(XBrush brush, XRect rect)
{
DrawEllipse(brush, rect.X, rect.Y, rect.Width, rect.Height);
}
/// <summary>
/// Draws an ellipse defined by a bounding rectangle.
/// </summary>
public void DrawEllipse(XBrush brush, double x, double y, double width, double height)
{
if (brush == null)
throw new ArgumentNullException("brush");
if (_drawGraphics)
{
}
if (_renderer != null)
_renderer.DrawEllipse(null, brush, x, y, width, height);
}
// ----- stroke and fill -----
/// <summary>
/// Draws an ellipse defined by a bounding rectangle.
/// </summary>
public void DrawEllipse(XPen pen, XBrush brush, XRect rect)
{
DrawEllipse(pen, brush, rect.X, rect.Y, rect.Width, rect.Height);
}
/// <summary>
/// Draws an ellipse defined by a bounding rectangle.
/// </summary>
public void DrawEllipse(XPen pen, XBrush brush, double x, double y, double width, double height)
{
if (pen == null && brush == null)
throw new ArgumentNullException("pen and brush", PSSR.NeedPenOrBrush);
if (_renderer != null)
_renderer.DrawEllipse(pen, brush, x, y, width, height);
}
/// <summary>
/// Draws a polygon defined by an array of points.
/// </summary>
public void DrawPolygon(XPen pen, XPoint[] points)
{
if (pen == null)
throw new ArgumentNullException("pen");
if (points == null)
throw new ArgumentNullException("points");
if (points.Length < 2)
throw new ArgumentException("points", PSSR.PointArrayAtLeast(2));
if (_renderer != null)
_renderer.DrawPolygon(pen, null, points, XFillMode.Alternate); // XFillMode is ignored
}
// ----- fill -----
/// <summary>
/// Draws a polygon defined by an array of points.
/// </summary>
public void DrawPolygon(XBrush brush, XPoint[] points, XFillMode fillmode)
{
if (brush == null)
throw new ArgumentNullException("brush");
if (points == null)
throw new ArgumentNullException("points");
if (points.Length < 2)
throw new ArgumentException("points", PSSR.PointArrayAtLeast(2));
if (_renderer != null)
_renderer.DrawPolygon(null, brush, points, fillmode);
}
// ----- stroke and fill -----
/// <summary>
/// Draws a polygon defined by an array of points.
/// </summary>
public void DrawPolygon(XPen pen, XBrush brush, XPoint[] points, XFillMode fillmode)
{
if (pen == null && brush == null)
throw new ArgumentNullException("pen and brush", PSSR.NeedPenOrBrush);
if (points == null)
throw new ArgumentNullException("points");
if (points.Length < 2)
throw new ArgumentException("points", PSSR.PointArrayAtLeast(2));
if (_renderer != null)
_renderer.DrawPolygon(pen, brush, points, fillmode);
}
// ----- DrawPie ------------------------------------------------------------------------------
// ----- stroke -----
/// <summary>
/// Draws a pie defined by an ellipse.
/// </summary>
public void DrawPie(XPen pen, XRect rect, double startAngle, double sweepAngle)
{
DrawPie(pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
}
/// <summary>
/// Draws a pie defined by an ellipse.
/// </summary>
public void DrawPie(XPen pen, double x, double y, double width, double height, double startAngle, double sweepAngle)
{
if (pen == null)
throw new ArgumentNullException("pen", PSSR.NeedPenOrBrush);
if (_renderer != null)
_renderer.DrawPie(pen, null, x, y, width, height, startAngle, sweepAngle);
}
// ----- fill -----
/// <summary>