jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
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
//============================================================================
//Gios Pdf.NET - A library for exporting Pdf Documents in C#
//Copyright (C) 2005  Paolo Gios - www.paologios.com
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.
//
//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
//=============================================================================
 
using System;
using System.Drawing;
 
namespace HH.WMS.Utils.Gios.Pdf
{
    /// <summary>
    /// A generic sized Area.
    /// </summary>
    public class PdfArea
    {
        /// <summary>
        /// 
        /// </summary>
        internal PdfDocument PdfDocument;
        internal double posx,posy,width,height;
        /// <summary>
        /// gets or sets the X positioning of the Area
        /// </summary>
        public double PosX
        {
            get
            {
                return this.posx;
            }
            set
            {
                this.posx=value;
            }
        }
        /// <summary>
        /// gets or sets the Y positioning of the Area
        /// </summary>
        public double PosY
        {
            get
            {
                return this.posy;
                }
            set
            {
                this.posy=value;
            }
        }
        /// <summary>
        /// gets the X-coordinate of the center of the Area.
        /// </summary>
        public double CenterX
        {
            get
            {
                return this.posx+(this.BottomRightCornerX-this.posx)/2;
            }
            
        }
        /// <summary>
        /// gets the Y-coordinate of the center of the Area.
        /// </summary>
        public double CenterY
        {
            get
            {
                return this.posy+(this.BottomRightCornerY-this.posy)/2;
            }
            
        }
        /// <summary>
        /// gets or sets the Width of the Area.
        /// </summary>
        public double Width
        {
            get
            {
                return this.width;
            }
            set
            {
                if (value<=0) throw new Exception("Width must be grater than zero.");
                this.width=value;
            }
        }
        /// <summary>
        /// gets or sets the Height of the Area.
        /// </summary>
        public double Height
        {
            get
            {
                return this.height;
            }
            set
            {
                if (value<=0) throw new Exception("Height must be grater than zero.");
                this.height=value;
            }
        }
        /// <summary>
        /// gets the coordinates struct of the Top Left Vertex of the Area
        /// </summary>
        public PointF TopLeftVertex
        {
            get
            {
                return new System.Drawing.PointF((float)this.posx,(float)this.posy);
            }
        }
        /// <summary>
        /// gets the coordinates struct of the Bottom Right Vertex of the Area
        /// </summary>
        public PointF BottomRightVertex
        {
            get
            {
                return new PointF((float)this.BottomRightCornerX,(float)this.BottomRightCornerY);
            }
        }
        /// <summary>
        /// gets the coordinates struct of the Bottom Left Vertex of the Area
        /// </summary>
        public PointF BottomLeftVertex
        {
            get
            {
                return new PointF((float)this.posx,(float)this.BottomRightCornerY);
            }
        }
        /// <summary>
        /// gets the coordinates struct of the Top Right Vertex of the Area
        /// </summary>
        public PointF TopRightVertex
        {
            get
            {
                return new PointF((float)this.BottomRightCornerX,(float)this.posy);
            }
        }
        internal string Key
        {
            get
            {
                return this.posx.ToString()+" "+this.posy.ToString()+" "+
                    this.width.ToString()+" "+this.height.ToString();
            }
        }
        /// <summary>
        /// Creates a new Area for correctly placing objects into Pdf Pages
        /// </summary>
        /// <param name="posx">Top-Left Vertex X-coordinate</param>
        /// <param name="posy">Top-Left Vertex Y-coordinate</param>
        /// <param name="width">Width of the Area</param>
        /// <param name="height">Height of the Area</param>
        public PdfArea (PdfDocument PdfDocument,double posx,double posy,double width,double height)
        {
            this.PdfDocument=PdfDocument;
            if (width<=0) throw new Exception("Width must be grater than zero.");
            if (height<=0) throw new Exception("Height must be grater than zero.");
            this.PosX=(double)posx;
            this.PosY=(double)posy;
            this.Width=(double)width;
            this.Height=(double)height;
            
        }
        internal PdfArea (PdfDocument PdfDocument){this.PdfDocument=PdfDocument;}
        /// <summary>
        /// Generates a new Area inside the base one specifing the width difference.
        /// </summary>
        /// <param name="Difference">the Width difference of the inner Area</param>
        /// <returns></returns>
        public PdfArea InnerArea(double Difference)
        {
            this.PdfDocument=PdfDocument;
            if (Difference<0) throw new Exception("Difference must be non negative.");
            PdfArea pa=this.MemberwiseClone() as PdfArea;
            pa.width-=(double)Difference;
            pa.Height-=(double)Difference;
            pa.posx+=(double)Difference/2;
            pa.posy+=(double)Difference/2;
            return pa;
        }
        /// <summary>
        /// Generates a new Area inside the base one specifing the width difference.
        /// </summary>
        /// <param name="WidthDifference">the Width difference of the inner Area</param>
        /// <param name="HeightDifference">the Height difference of the inner Area</param>
        /// <returns></returns>
        public PdfArea InnerArea(double WidthDifference,double HeightDifference)
        {
            if (WidthDifference<0) throw new Exception("WidthDifference must be non negative.");
            if (HeightDifference<0) throw new Exception("HeightDifference must be non negative.");
            PdfArea pa=this.MemberwiseClone() as PdfArea;
            pa.width-=(double)WidthDifference;
            pa.Height-=(double)HeightDifference;
            pa.posx+=(double)WidthDifference/2;
            pa.posy+=(double)HeightDifference/2;
            return pa;
        }
        /// <summary>
        /// Generates a new Area outside the base one specifing the width difference
        /// </summary>
        /// <param name="Difference">the Width difference of the inner Area</param>
        /// <returns></returns>
        public PdfArea OuterArea(double Difference)
        {
            if (Difference<0) throw new Exception("Difference must be non negative.");
            PdfArea pa=this.MemberwiseClone() as PdfArea;
            pa.width+=(double)Difference;
            pa.Height+=(double)Difference;
            pa.posx-=(double)Difference/2;
            pa.posy-=(double)Difference/2;
            return pa;
        }
        /// <summary>
        /// Generates a new Area outside the base one specifing the width difference.
        /// </summary>
        /// <param name="WidthDifference">the Width difference of the inner Area</param>
        /// <param name="HeightDifference">the Height difference of the inner Area</param>
        /// <returns></returns>
        public PdfArea OuterArea(double WidthDifference,double HeightDifference)
        {
            if (WidthDifference<0) throw new Exception("WidthDifference must be non negative.");
            if (HeightDifference<0) throw new Exception("HeightDifference must be non negative.");
            PdfArea pa=this.MemberwiseClone() as PdfArea;
            pa.width+=(double)WidthDifference;
            pa.Height+=(double)HeightDifference;
            pa.posx-=(double)WidthDifference/2;
            pa.posy-=(double)HeightDifference/2;
            return pa;
        }
        /// <summary>
        /// Extends the area to the bounds of another area
        /// </summary>
        /// <param name="Area"></param>
        /// <returns></returns>
        public PdfArea Merge(PdfArea Area)
        {
            PdfArea res=this.MemberwiseClone() as PdfArea;
 
            if (this.PosX>Area.PosX) 
            {
                res.PosX=Area.PosX;
                res.Width=Area.Width;
            }
            if (this.PosY>Area.PosY) 
            {
                res.PosY=Area.PosY;
                res.Height=Area.Height;
            }
 
            if (this.BottomRightCornerX<Area.BottomRightCornerX)
            {
                res.BottomRightCornerX=Area.BottomRightCornerX;
            }
            if (this.BottomRightCornerY<Area.BottomRightCornerY)
            {
                res.BottomRightCornerY=Area.BottomRightCornerY;
            }
            return res;
        }
        /// <summary>
        /// get or sets the bottom-right bound X-coordinate
        /// </summary>
        public double BottomRightCornerX
        {
            get
            {
                return this.PosX+this.Width;
            }
            set
            {
                this.width=value-this.posx;
                if (width<=0) throw new Exception("Width must be grater than zero.");
            
            }
        }
        /// <summary>
        /// get or sets the bottom-right boud Y-coordinate
        /// </summary>
        public double BottomRightCornerY
        {
            get
            {
                return this.PosY+this.Height;
            }
            set
            {
                this.height=value-this.posy;
                if (height<=0) throw new Exception("Height must be grater than zero.");
            
            }
        }
        /// <summary>
        /// Creates a Circle inside the Area
        /// </summary>
        /// <param name="BorderColor"></param>
        /// <returns></returns>
        public PdfCircle InnerCircle(System.Drawing.Color BorderColor)
        {
            PdfCircle pc=new PdfCircle();
            pc.AxesArea=this;
            pc.BorderColor=BorderColor;
            return pc;
        }
        /// <summary>
        /// Creates a Circle outside the Area
        /// </summary>
        /// <param name="BorderColor"></param>
        /// <returns></returns>
        public PdfCircle OuterCircle(System.Drawing.Color BorderColor)
        {
            PdfCircle pc=new PdfCircle();
            pc.AxesArea=this.OuterArea(this.width*(double)0.40,this.height*(double)0.40);
            pc.BorderColor=BorderColor;
            return pc;
        }
        /// <summary>
        /// Creates a Circle inside the Area
        /// </summary>
        /// <param name="BorderColor"></param>
        /// <param name="StrokeWidth"></param>
        /// <returns></returns>
        public PdfCircle InnerCircle(System.Drawing.Color BorderColor,double StrokeWidth)
        {
            if (StrokeWidth<=0) throw new Exception("StrokeWidth must be grater than zero.");
            PdfCircle pc=new PdfCircle();
            pc.AxesArea=this;
            pc.BorderColor=BorderColor;
            pc.strokeWidth=StrokeWidth;
            return pc;
        }
        /// <summary>
        /// Creates a Circle outside the Area
        /// </summary>
        /// <param name="BorderColor"></param>
        /// <param name="StrokeWidth"></param>
        /// <returns></returns>
        public PdfCircle OuterCircle(System.Drawing.Color BorderColor,double StrokeWidth)
        {
            if (StrokeWidth<=0) throw new Exception("StrokeWidth must be grater than zero.");
            PdfCircle pc=new PdfCircle();
            pc.AxesArea=this.OuterArea(this.width*(double)0.40,this.height*(double)0.40);
            pc.BorderColor=BorderColor;
            pc.strokeWidth=StrokeWidth;
            return pc;
        }
        /// <summary>
        /// Creates a line which crosses the Area from the bottom-left to the top-right corner
        /// </summary>
        /// <param name="Color"></param>
        /// <returns></returns>
        public PdfLine SlashLine(Color Color)
        {
            return new PdfLine(this.PdfDocument,this.BottomLeftVertex,this.TopRightVertex,Color,1);
        }
        /// <summary>
        /// Creates a line which crosses the Area from the top-left to the bottom-right corner
        /// </summary>
        /// <param name="Color"></param>
        /// <returns></returns>
        public PdfLine BackSlashLine(Color Color)
        {
            return new PdfLine(this.PdfDocument,this.TopLeftVertex,this.BottomRightVertex,Color,1);
        }
        /// <summary>
        /// Creates a line which crosses the Area from the bottom-left to the top-right corner
        /// </summary>
        /// <param name="Color"></param>
        /// <param name="StrokeWidth"></param>
        /// <returns></returns>
        public PdfLine SlashLine(Color Color,double StrokeWidth)
        {
            if (StrokeWidth<=0) throw new Exception("StrokeWidth must be grater than zero.");
            return new PdfLine(this.PdfDocument,this.BottomLeftVertex,this.TopRightVertex,Color,(double)StrokeWidth);
        }
        /// <summary>
        /// Creates a line which crosses the Area from the top-left to the bottom-right corner
        /// </summary>
        /// <param name="Color"></param>
        /// <param name="StrokeWidth"></param>
        /// <returns></returns>
        public PdfLine BackSlashLine(Color Color,double StrokeWidth)
        {
            if (StrokeWidth<=0) throw new Exception("StrokeWidth must be grater than zero.");
            return new PdfLine(this.PdfDocument,this.TopLeftVertex,this.BottomRightVertex,Color,(double)StrokeWidth);
        }
        /// <summary>
        /// Creates a line corresponding to the Upper Bound of the Area
        /// </summary>
        /// <param name="Color"></param>
        /// <param name="StrokeWidth"></param>
        /// <returns></returns>
        public PdfLine UpperBound(Color Color,double StrokeWidth)
        {
            if (StrokeWidth<=0) throw new Exception("StrokeWidth must be grater than zero.");
            return new PdfLine(this.PdfDocument,this.TopLeftVertex,this.TopRightVertex,Color,StrokeWidth);
        }
        /// <summary>
        /// Creates a line corresponding to the lower bound of the Area
        /// </summary>
        /// <param name="Color"></param>
        /// <param name="StrokeWidth"></param>
        /// <returns></returns>
        public PdfLine LowerBound(Color Color,double StrokeWidth)
        {
            if (StrokeWidth<=0) throw new Exception("StrokeWidth must be grater than zero.");
            return new PdfLine(this.PdfDocument,this.BottomLeftVertex,this.BottomRightVertex,Color,StrokeWidth);
        }
        /// <summary>
        /// Creates a line corresponding to the left bound of the Area
        /// </summary>
        /// <param name="Color"></param>
        /// <param name="StrokeWidth"></param>
        /// <returns></returns>
    
        public PdfLine LeftBound(Color Color,double StrokeWidth)
        {
            if (StrokeWidth<=0) throw new Exception("StrokeWidth must be grater than zero.");
            return new PdfLine(this.PdfDocument,this.TopLeftVertex,this.BottomLeftVertex,Color,StrokeWidth);
        }
        /// <summary>
        /// Creates a line corresponding to the Horizontal Axe of the Area
        /// </summary>
        /// <param name="Color"></param>
        /// <param name="StrokeWidth"></param>
        /// <returns></returns>
        public PdfLine HorizontalAxe(Color Color,double StrokeWidth)
        {
            if (StrokeWidth<=0) throw new Exception("StrokeWidth must be grater than zero.");
            System.Drawing.PointF p1=this.TopLeftVertex;
            System.Drawing.PointF p2=this.TopRightVertex;
            p1.Y+=(float)this.height/2;
            p2.Y+=(float)this.height/2;
            return new PdfLine(this.PdfDocument,p1,p2,Color,StrokeWidth);
        }
        /// <summary>
        /// Creates a line corresponding to the Vertical Axe of the Area
        /// </summary>
        /// <param name="Color"></param>
        /// <param name="StrokeWidth"></param>
        /// <returns></returns>
    
        public PdfLine VerticalAxe(Color Color,double StrokeWidth)
        {
            if (StrokeWidth<=0) throw new Exception("StrokeWidth must be grater than zero.");
            System.Drawing.PointF p1=this.TopLeftVertex;
            System.Drawing.PointF p2=this.BottomLeftVertex;
            p1.X+=(float)this.width/2;
            p2.X+=(float)this.width/2;
            return new PdfLine(this.PdfDocument,p1,p2,Color,StrokeWidth);
        }
        /// <summary>
        /// Creates a line corresponding to the right bound of the Area.
        /// </summary>
        /// <param name="Color"></param>
        /// <param name="StrokeWidth"></param>
        /// <returns></returns>
        public PdfLine RightBound(Color Color,double StrokeWidth)
        {
            if (StrokeWidth<=0) throw new Exception("StrokeWidth must be grater than zero.");
            return new PdfLine(this.PdfDocument,this.TopRightVertex,this.BottomRightVertex,Color,StrokeWidth);
        }
        /// <summary>
        /// Creates a simple void rectangle delimited by this Area.
        /// </summary>
        /// <param name="BorderColor"></param>
        /// <returns></returns>
        public PdfRectangle ToRectangle(Color BorderColor)
        {
            PdfRectangle pr=new PdfRectangle(this.PdfDocument,this,BorderColor);
            return pr;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="BorderColor"></param>
        /// <param name="BorderWidth"></param>
        /// <returns></returns>
        public PdfRectangle ToRectangle(Color BorderColor,double BorderWidth)
        {
            if (BorderWidth<=0) throw new Exception("BorderWidth must be grater than zero.");
            PdfRectangle pr=new PdfRectangle(this.PdfDocument,this,BorderColor,BorderWidth);
            return pr;
        }
        /// <summary>
        /// Creates a simple void rectangle delimited by this Area.
        /// </summary>
        /// <param name="BorderColor"></param>
        /// <param name="FillingColor"></param>
        /// <returns></returns>
        public PdfRectangle ToRectangle(Color BorderColor,Color FillingColor)
        {
            PdfRectangle pr=new PdfRectangle(this.PdfDocument,this,BorderColor,FillingColor);
            return pr;
        }
        /// <summary>
        /// Creates a filled rectangle delimited by this Area.
        /// </summary>
        /// <param name="BorderColor"></param>
        /// <param name="BorderWidth"></param>
        /// <param name="FillingColor"></param>
        /// <returns></returns>
        public PdfRectangle ToRectangle(Color BorderColor,double BorderWidth,Color FillingColor)
        {
            if (BorderWidth<=0) throw new Exception("BorderWidth must be grater than zero.");
            PdfRectangle pr=new PdfRectangle(this.PdfDocument,this,BorderColor,BorderWidth,FillingColor);
            return pr;
        }
        internal PdfArea Clone()
        {
            return this.MemberwiseClone() as PdfArea;
        }
        
    }
 
}