zhao
2021-07-09 0821715ebc11d3934d0594a1cc2c39686d808906
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
//============================================================================
//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>
    /// Cell of a PdfTable
    /// </summary>
    public class PdfCell
    {
        internal PdfDocument PdfDocument
        {
            get
            {
                return this.owner.PdfDocument;
            }
        }
        internal string stringFormat;
        internal double Height
        {
            get
            {
                return this.owner.Rows[row].Height;
            }
        }
        internal string text
        {
            get
            {
                string testo="";
                if (this.content!=null) testo=String.Format(this.stringFormat,this.content);
                return testo;
            }
        }
        internal double Width
        {
            get
            {
                return this.owner.Columns[column].CompensatedWidth;
            }
        }
        internal double cellPadding;
        internal int row,column;
        internal object content;
        /// <summary>
        /// gets the Content inside the Cell.
        /// </summary>
        public object Content
        {
            get
            {
                return this.content;
            }
        }
        internal int colSpan,rowSpan;
        /// <summary>
        /// gets or sets the Column Span of the Cell.
        /// </summary>
        public int ColSpan
        {
            get
            {
                return this.colSpan;
            }
            set
            {
                if (value<=0) throw new Exception("ColSpan must be grater than zero.");
                this.colSpan=value;
                    for (int r=this.row;r<row+rowSpan;r++)
                        for (int c=this.column+1;c<column+colSpan;c++)
                            this.owner.Cell(r,c).isSpanned=true;
            
            }
        }
        /// <summary>
        /// gets or sets the Row Span of the Cell.
        /// </summary>
        public int RowSpan
        {
            get
            {
                return this.rowSpan;
            }
            set
            {
                if (value<=0) throw new Exception("RowSpan must be grater than zero.");
                this.rowSpan=value;
                    for (int r=this.row+1;r<row+rowSpan;r++)
                        for (int c=this.column;c<column+colSpan;c++)
                            this.owner.Cell(r,c).isSpanned=true;
            
            }
        }
        internal PdfTable owner;
        internal Color foregroundColor;
        internal bool transparent;
        internal PdfArea area;
        private PdfArea _Area;
        internal PdfArea Area
        {
            get
            {
            //    if (_Area==null)
            //    {
            //        if ((this.rowSpan==1)&&(this.colSpan==1)) _Area=this.area;
                    _Area=this.area.Merge(this.owner.Cell(row+rowSpan-1,column+colSpan-1).area);
            //    }
                return this._Area;
            }
        }
        internal Color backgroundColor;
        internal ContentAlignment ContentAlignment;
        internal Font Font;
        internal PdfCell(PdfTable owner,int row,int column,ContentAlignment ContentAlignment,Color ForegroundColor,Font Font,double CellPadding)
        {
            this.colSpan=1;
            this.rowSpan=1;
            this.row=row;
            this.stringFormat="{0}";
            this.transparent=true;
            this.Font=Font;
            this.owner=owner;
            this.column=column;
            this.ContentAlignment=ContentAlignment;
            this.foregroundColor=ForegroundColor;
            this.cellPadding=CellPadding;
        }
        
        internal bool isSpanned;
        private double _neededHeight=0;
        internal double neededHeight
        {
            get
            {
                if (this._neededHeight==0)
                {
                    if (this.isSpanned) return 0;    
                    this._neededHeight=this.minimumLines*this.Font.Size+this.cellPadding*2;
                }
                return this._neededHeight;
            }
        }
        internal PdfTextArea pcatemp;
        internal int minimumLines
        {
            get
            {
                double W=Width;
                if (this.colSpan>1)
                {
                    for (int c=column;c<column+colSpan-1;c++)
                        W+=this.owner.Cell(row,c).Width;
                }
                PdfArea pa=new PdfArea(this.PdfDocument,0,0,W,1000);
                this.pcatemp= new PdfTextArea(Font,foregroundColor,pa.InnerArea(this.cellPadding*2)
                        ,ContentAlignment,text);
                return this.pcatemp.RenderLines().Count;
 
            }
        }
        /// <summary>
        /// sets the font to be used in the Cell.
        /// </summary>
        /// <param name="Font"></param>
        public void SetFont(Font Font)
        {
            this.Font=Font;
        }
        /// <summary>
        /// sets the background color of the Cell.
        /// </summary>
        /// <param name="BackgroundColor"></param>
        public void SetBackgroundColor(Color BackgroundColor)
        {
            this.backgroundColor=BackgroundColor;
            this.transparent=false;
        }
        /// <summary>
        /// sets the foreground color of the Cell.
        /// </summary>
        /// <param name="ForegroundColor"></param>
        public void SetForegroundColor(Color ForegroundColor)
        {
            this.foregroundColor=ForegroundColor;
        }
        /// <summary>
        /// sets the Content Alignment of the Cell.
        /// </summary>
        /// <param name="ContentAlignment"></param>
        public void SetContentAlignment(ContentAlignment ContentAlignment)
        {
            this.ContentAlignment=ContentAlignment;
        }
        /// <summary>
        /// sets the background and foreground colors of the Cell.
        /// </summary>
        /// <param name="ForegroundColor"></param>
        /// <param name="BackgroundColor"></param>
        public void SetColors(Color ForegroundColor,Color BackgroundColor)
        {
            this.SetForegroundColor(ForegroundColor);
            this.SetBackgroundColor(BackgroundColor);
        }
        /// <summary>
        /// makes the Cell background a transparent layer.
        /// </summary>
        public void SetTransparent()
        {
            this.transparent=true;
        }
        /// <summary>
        /// sets the Padding of the Cell.
        /// </summary>
        /// <param name="CellPadding"></param>
        public void SetCellPadding(double CellPadding)
        {
            if (CellPadding<0) throw new Exception("CellPadding must be non-negative.");
            this.cellPadding=CellPadding;
        }
        /// <summary>
        /// Sets the content of the cell. 
        /// </summary>
        /// <param name="Content"></param>
        public void SetContent(object Content)
        {
            this.content=Content;
        }
        /// <summary>
        /// Sets the string Format of the Cell
        /// </summary>
        /// <param name="Format"></param>
        public void SetContentFormat(string Format)
        {
            this.stringFormat=Format;
        }
    }
}