zhao
2021-06-04 c7ec496f9e41c2227103b3ef776e4a3f91bce6b2
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
//============================================================================
//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;
using System.Text;
 
namespace HH.WMS.Utils.Gios.Pdf
{
    /// <summary>
    /// a generic Line for a PdfPage
    /// </summary>
    public class PdfLine : PdfObject
    {
        internal PointF start,end;
        internal Color color;
        internal double strokeWidth;
        /// <summary>
        /// gets or sets the Color of the line
        /// </summary>
        public Color Color
        {
            set
            {
                this.color=value;
            }
            get
            {
                return this.color;
            }
        }
        /// <summary>
        /// gets or sets the width of the stroke
        /// </summary>
        public double StrokeWidth
        {
            set
            {
                if (value<=0) throw new Exception("StrokeWidth must be greater than zero.");
                this.strokeWidth=value;
            }
            get
            {
                return this.strokeWidth;
            }
        }
        /// <summary>
        /// gets or sets the starting point of the line
        /// </summary>
        public PointF Start
        {
            get
            {
                return this.start;
            }
            set
            {
                this.start=value;
            }
        }
        /// <summary>
        /// gets or sets the ending point of the line
        /// </summary>
        public PointF End
        {
            get
            {
                return this.end;
            }
            set
            {
                this.end=value;
            }
        }
        /// <summary>
        /// created a new line to put inside a PdfPage
        /// </summary>
        /// <param name="Start">the starting point of the line</param>
        /// <param name="End">the ending point of the line</param>
        /// <param name="Color">the Color of the line</param>
        /// <param name="StrokeWidth">the width of the stroke</param>
        public PdfLine(PdfDocument PdfDocument,PointF Start,PointF End,Color Color,double StrokeWidth)
        {
            this.PdfDocument=PdfDocument;
            if (StrokeWidth<=0) throw new Exception("StrokeWidth must be greater than zero.");
            this.start=Start;
            this.end=End;
            this.color=Color;
            this.strokeWidth=StrokeWidth;
        }
        
        internal string ToLineStream()
        {
            System.Text.StringBuilder sb=new StringBuilder();
            
            sb.Append(this.start.X.ToString("0.##").Replace(",",".")+" ");
            sb.Append((this.PdfDocument.PH-this.start.Y).ToString("0.##").Replace(",",".")+" ");
            sb.Append("m ");
            
            sb.Append(this.end.X.ToString("0.##").Replace(",",".")+" ");
            sb.Append((this.PdfDocument.PH-this.end.Y).ToString("0.##").Replace(",",".")+" ");
            sb.Append("l ");
 
            sb.Append("S\n");
            return sb.ToString();
            
        }
        internal string ToLineStreamWithColorAndWidth()
        {
            System.Text.StringBuilder sb=new StringBuilder();
            sb.Append(Utility.ColorRGLine(this.color));
            sb.Append(this.strokeWidth.ToString("0.##").Replace(",",".")+" ");
            sb.Append("w\n");
            sb.Append(this.ToLineStream());
            return sb.ToString();
        }
        
        internal override int StreamWrite(System.IO.Stream stream)
        {
            int num=this.id;
            string text="";
            text+=this.ToLineStreamWithColorAndWidth();        
            System.Text.StringBuilder sb=new StringBuilder();
            sb.Append(num.ToString()+" 0 obj\n");
            sb.Append("<< /Lenght "+text.Length+" >>\n");
            sb.Append("stream\n");
            sb.Append(text);
            sb.Append("endstream\n");
            sb.Append("endobj\n");
            Byte[] b=ASCIIEncoding.ASCII.GetBytes(sb.ToString());
            stream.Write(b,0,b.Length);
            return b.Length;
        }
 
    }
}