Example #1
0
        internal void TextBoxInitialization()
        {
            // terminate TextBox
            TextBox.Terminate();

            // calculate overall TextBox height
            TextBoxHeight = TextBox.BoxHeightExtra(Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace);
            double TextBoxHeightPageBreak = TextBoxHeight;

            // textbox minimum height for page break calculations
            if (!Header && (Style.TextBoxPageBreakLines != 0 && Style.TextBoxPageBreakLines < TextBox.LineCount))
            {
                // calculate TextBox height and add to cell height
                TextBoxHeightPageBreak = TextBox.BoxHeightExtra(Style.TextBoxPageBreakLines, Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace);
            }

            // required cell height for page break calculations and for full textbox height
            TextBoxCellHeight = CellHeight + TextBoxHeightPageBreak;
            CellHeight       += TextBoxHeight;

            // reset textbox line number
            TextBoxLineNo = 0;

            // set type to text box
            Type = CellType.TextBox;
            return;
        }
Example #2
0
        ////////////////////////////////////////////////////////////////////
        // Draw Cell
        ////////////////////////////////////////////////////////////////////

        internal void DrawCell()
        {
            // draw background color
            if (Style.BackgroundColor != Color.Empty)
            {
                Parent.Contents.SaveGraphicsState();
                Parent.Contents.SetColorNonStroking(Style.BackgroundColor);
                Parent.Contents.DrawRectangle(Parent._ColumnPosition[Index], Parent.RowBottomPosition,
                                              Parent._ColumnWidth[Index], Header ? Parent.HeaderHeight : Parent.RowHeight, PaintOp.Fill);
                Parent.Contents.RestoreGraphicsState();
            }

            // switch based on cell type
            switch (Type)
            {
            // one line of text
            case CellType.Text:
                TextJustify TextJustify;
                Parent.Contents.DrawText(Style.Font, Style.FontSize, TextHorPos(out TextJustify), TextVerPos(),
                                         TextJustify, Style.TextDrawStyle, Style.ForegroundColor, FormattedText);
                break;

            // text box
            case CellType.TextBox:
                // calculate textbox size and position
                int LineEnd;
                if (TextBoxLineNo != 0 || TextBoxHeight > ClientTop - ClientBottom + Parent.Epsilon)
                {
                    TextBoxHeight = TextBox.BoxHeightExtra(ref TextBoxLineNo, out LineEnd,
                                                           ClientTop - ClientBottom + Parent.Epsilon, Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace);
                }
                double YPos = TopPos(TextBoxHeight);

                // draw textbox
                Parent.Contents.SaveGraphicsState();
                LineEnd = Parent.Contents.DrawText(LeftPos(TextBox.BoxWidth), ref YPos, ClientBottom - Parent.Epsilon, TextBoxLineNo,
                                                   Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace, Style.TextBoxTextJustify, TextBox);
                Parent.Contents.RestoreGraphicsState();

                // textbox did not fit in current page
                if (LineEnd < TextBox.LineCount)
                {
                    TextBoxLineNo          = LineEnd;
                    Parent.TextBoxContinue = true;
                }
                // textbox drawing is done
                else
                {
                    TextBoxLineNo = 0;
                }
                break;

            // image
            case CellType.Image:
                Parent.Contents.DrawImage(Image, LeftPos(ImageWidth), TopPos(ImageHeight) - ImageHeight, ImageWidth, ImageHeight);
                break;

            // barcode
            case CellType.Barcode:
                Parent.Contents.DrawBarcode(LeftPos(BarcodeBox.TotalWidth) + BarcodeBox.OriginX,
                                            TopPos(BarcodeBox.TotalHeight) - BarcodeBox.TotalHeight + BarcodeBox.OriginY,
                                            TextJustify.Left, Style.BarcodeBarWidth, Style.BarcodeHeight, Style.ForegroundColor, Barcode, Style.Font, Style.FontSize);;
                break;
            }

            // cell has a web link
            if (AnnotAction != null)
            {
                Parent.Page.AddAnnotation(new PdfRectangle(ClientLeft, ClientBottom, ClientRight, ClientTop), AnnotAction);
            }
            return;
        }
        ////////////////////////////////////////////////////////////////////
        // Draw Cell Initialization
        ////////////////////////////////////////////////////////////////////
        internal void DrawCellInitialization()
        {
            // calculate left and right client space
            ClientLeft  = FrameLeft + Style.Margin.Left;
            ClientRight = FrameLeft + FrameWidth - Style.Margin.Right;

            // initialize cell height to top and bottom margins
            CellHeight = Style.Margin.Top + Style.Margin.Bottom;

            // we have something to draw
            if (Value != null)
            {
                // assume cell type to be text
                Type = CellType.Text;

                // get object type
                Type ValueType = Value.GetType();

                // value is string
                if (ValueType == typeof(String))
                {
                    // multi line text
                    if (Style.MultiLineText)
                    {
                        // convert string to TextBox
                        TextBox = new TextBox(ClientRight - ClientLeft, Style.TextBoxFirstLineIndent, Style.TextBoxLineBreakFactor);
                        TextBox.AddText(Style.Font, Style.FontSize, Style.ForegroundColor, (String)Value);

                        // textbox initialization
                        TextBoxInitialization();
                    }

                    // single line text
                    else
                    {
                        // save value as string
                        FormattedText = (String)Value;

                        // add line spacing
                        CellHeight += Style.FontLineSpacing;
                    }
                }

                // value is text box
                else if (ValueType == typeof(TextBox))
                {
                    // set TextBox
                    TextBox = (TextBox)Value;

                    // test width
                    if (TextBox.BoxWidth - (ClientRight - ClientLeft) > Parent.Epsilon)
                    {
                        throw new ApplicationException("PdfTableCell: TextBox width is greater than column width");
                    }

                    // textbox initialization
                    TextBoxInitialization();
                }

                // value is PdfImage
                else if (ValueType == typeof(PdfImage))
                {
                    // set image
                    Image = (PdfImage)Value;

                    // calculate client width
                    Double Width = ClientWidth;

                    // calculate image width and height
                    if (ImageWidth == 0.0)
                    {
                        if (ImageHeight == 0.0)
                        {
                            ImageWidth  = Width;
                            ImageHeight = ImageWidth * (Double)Image.HeightPix / (Double)Image.WidthPix;
                        }
                        else
                        {
                            ImageWidth = ImageHeight * (Double)Image.WidthPix / (Double)Image.HeightPix;
                        }
                    }
                    else if (ImageHeight == 0.0)
                    {
                        ImageHeight = ImageWidth * (Double)Image.HeightPix / (Double)Image.WidthPix;
                    }

                    // image width is too wide
                    if (ImageWidth > Width)
                    {
                        ImageHeight = Width * ImageHeight / ImageWidth;
                        ImageWidth  = Width;
                    }

                    // adjust cell's height
                    CellHeight += ImageHeight;

                    // set type to image
                    Type = CellType.Image;
                }

                // value is PdfQRCode
                else if (ValueType == typeof(PdfQRCode))
                {
                    // set QR Code
                    QRCode = (PdfQRCode)Value;

                    // calculate client width
                    Double Width = ClientWidth;

                    // calculate QR Code width
                    if (QRCodeWidth == 0.0 || QRCodeWidth > Width)
                    {
                        QRCodeWidth = Width;
                    }

                    // adjust cell's height
                    CellHeight += QRCodeWidth;

                    // set type to QR Code
                    Type = CellType.QRCode;
                }

                // value is a derived class of barcode
                else if (ValueType.BaseType == typeof(Barcode))
                {
                    // set barcode
                    Barcode = (Barcode)Value;

                    // test barcode height
                    if (Style.BarcodeHeight <= 0.0)
                    {
                        throw new ApplicationException("PdfTableStyle: BarcodeHeight must be defined.");
                    }

                    // calculate total barcode height
                    BarcodeBox = Barcode.GetBarcodeBox(Style.BarcodeBarWidth, Style.BarcodeHeight, Style.Font, Style.FontSize);

                    // adjust cell's height
                    CellHeight += BarcodeBox.TotalHeight;

                    // set type to barcode
                    Type = CellType.Barcode;
                }

                // value is basic mostly numeric object
                else
                {
                    String           Format       = Style.Format;
                    NumberFormatInfo NumberFormat = Style.NumberFormatInfo;
                    if (ValueType == typeof(Int32))
                    {
                        FormattedText = ((Int32)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(Single))
                    {
                        FormattedText = ((Single)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(Double))
                    {
                        FormattedText = ((Double)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(Boolean))
                    {
                        FormattedText = ((Boolean)Value).ToString();
                    }
                    else if (ValueType == typeof(Char))
                    {
                        FormattedText = ((Char)Value).ToString();
                    }
                    else if (ValueType == typeof(Byte))
                    {
                        FormattedText = ((Byte)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(SByte))
                    {
                        FormattedText = ((SByte)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(Int16))
                    {
                        FormattedText = ((Int16)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(UInt16))
                    {
                        FormattedText = ((UInt16)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(UInt32))
                    {
                        FormattedText = ((UInt32)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(Int64))
                    {
                        FormattedText = ((Int64)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(UInt64))
                    {
                        FormattedText = ((UInt64)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(Decimal))
                    {
                        FormattedText = ((Decimal)Value).ToString(Format, NumberFormat);
                    }
                    else
                    {
                        throw new ApplicationException("PdfTableCell: Unknown object type");
                    }

                    // add line spacing
                    CellHeight += Style.FontLineSpacing;
                }
            }

            // value is null and textbox continuation is required
            else if (Type == CellType.TextBox && TextBoxLineNo != 0)
            {
                Int32 LineEnd;
                CellHeight += TextBox.BoxHeightExtra(ref TextBoxLineNo, out LineEnd,
                                                     Parent._RowTopPosition - Parent.TableBottomLimit - (Style.Margin.Top + Style.Margin.Bottom), Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace);
                TextBoxCellHeight = CellHeight;
            }
            else
            {
                // reset cell type
                Type = CellType.Empty;
            }

            // test for minimum height requirement
            if (CellHeight < Style.MinHeight)
            {
                CellHeight = Style.MinHeight;
            }

            // cell minimum height for all types but textbox
            if (Type != CellType.TextBox)
            {
                TextBoxCellHeight = CellHeight;
            }

            // return result
            return;
        }
        ////////////////////////////////////////////////////////////////////
        // Draw Cell Initialization
        ////////////////////////////////////////////////////////////////////
        internal Double DrawCellInitialization()
        {
            // calculate left and right client space
            ClientLeft = FrameLeft + Style.Margin.Left;
            ClientRight = FrameLeft + FrameWidth - Style.Margin.Right;

            // initialize cell height to top and bottom margins
            Double CellHeight = Style.Margin.Top + Style.Margin.Bottom;

            // reset cell type
            Type = CellType.Empty;

            // we have something to draw
            if(Value != null)
            {
            // assume cell type to be text
            Type = CellType.Text;

            // get object type
            Type ValueType = Value.GetType();

            // value is string
            if(ValueType == typeof(String))
                {
                // multi line text
                if(Style.MultiLineText)
                    {
                    // convert string to TextBox
                    TextBox = new TextBox(ClientRight - ClientLeft, Style.TextBoxFirstLineIndent, Style.TextBoxLineBreakFactor);
                    TextBox.AddText(Style.Font, Style.FontSize, (String) Value);
                    TextBox.Terminate();
                    TextBoxHeight = TextBox.BoxHeightExtra(Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace);
                    CellHeight += TextBoxHeight;
                    Type = CellType.TextBox;
                    }

                // single line text
                else
                    {
                    // save value as string
                    FormattedText = (String) Value;

                    // add line spacing
                    CellHeight += Style.FontLineSpacing;
                    }
                }

            // value is text box
            else if(ValueType == typeof(TextBox))
                {
                // set TextBox
                TextBox = (TextBox) Value;

                // test width
                if(TextBox.BoxWidth - (ClientRight - ClientLeft) > Parent.Epsilon) throw new ApplicationException("PdfTableCell: TextBox width is greater than column width");

                // terminate TextBox
                TextBox.Terminate();

                // calculate TextBox height and add to cell height
                TextBoxHeight = TextBox.BoxHeightExtra(Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace);
                CellHeight += TextBoxHeight;

                // set type to text box
                Type = CellType.TextBox;
                }

            // value is PdfImage
            else if(ValueType == typeof(PdfImage))
                {
                // set image
                Image = (PdfImage) Value;

                // calculate client width
                Double Width = ClientWidth;

                // calculate image width and height
                if(ImageWidth == 0.0)
                    {
                    if(ImageHeight == 0.0)
                        {
                        ImageWidth = Width;
                        ImageHeight = ImageWidth * (Double) Image.HeightPix / (Double) Image.WidthPix;
                        }
                    else
                        {
                        ImageWidth = ImageHeight * (Double) Image.WidthPix / (Double) Image.HeightPix;
                        }
                    }
                else if(ImageHeight == 0.0)
                    {
                    ImageHeight = ImageWidth * (Double) Image.HeightPix / (Double) Image.WidthPix;
                    }

                // image width is too wide
                if(ImageWidth > Width)
                    {
                    ImageHeight = Width * ImageHeight / ImageWidth;
                    ImageWidth = Width;
                    }

                // adjust cell's height
                CellHeight += ImageHeight;

                // set type to image
                Type = CellType.Image;
                }

            // value is PdfQRCode
            else if(ValueType == typeof(PdfQRCode))
                {
                // set QR Code
                QRCode = (PdfQRCode) Value;

                // calculate client width
                Double Width = ClientWidth;

                // calculate QR Code width
                if(QRCodeWidth == 0.0 || QRCodeWidth > Width) QRCodeWidth = Width;

                // adjust cell's height
                CellHeight += QRCodeWidth;

                // set type to QR Code
                Type = CellType.QRCode;
                }

            // value is a derived class of barcode
            else if(ValueType.BaseType == typeof(Barcode))
                {
                // set barcode
                Barcode = (Barcode) Value;

                // test barcode height
                if(Style.BarcodeHeight <= 0.0) throw new ApplicationException("PdfTableStyle: BarcodeHeight must be defined.");

                // calculate total barcode height
                BarcodeBox = Barcode.GetBarcodeBox(Style.BarcodeBarWidth, Style.BarcodeHeight, Style.Font, Style.FontSize);

                // adjust cell's height
                CellHeight += BarcodeBox.TotalHeight;

                // set type to barcode
                Type = CellType.Barcode;
                }

            // value is basic mostly numeric object
            else
                {
                String Format = Style.Format;
                NumberFormatInfo NumberFormat = Style.NumberFormatInfo;
                if(ValueType == typeof(Int32)) FormattedText = ((Int32) Value).ToString(Format, NumberFormat);
                else if(ValueType == typeof(Single)) FormattedText = ((Single) Value).ToString(Format, NumberFormat);
                else if(ValueType == typeof(Double)) FormattedText = ((Double) Value).ToString(Format, NumberFormat);
                else if(ValueType == typeof(Boolean)) FormattedText = ((Boolean) Value).ToString();
                else if(ValueType == typeof(Char)) FormattedText = ((Char) Value).ToString();
                else if(ValueType == typeof(Byte)) FormattedText = ((Byte) Value).ToString(Format, NumberFormat);
                else if(ValueType == typeof(SByte)) FormattedText = ((SByte) Value).ToString(Format, NumberFormat);
                else if(ValueType == typeof(Int16)) FormattedText = ((Int16) Value).ToString(Format, NumberFormat);
                else if(ValueType == typeof(UInt16)) FormattedText = ((UInt16) Value).ToString(Format, NumberFormat);
                else if(ValueType == typeof(UInt32)) FormattedText = ((UInt32) Value).ToString(Format, NumberFormat);
                else if(ValueType == typeof(Int64)) FormattedText = ((Int64) Value).ToString(Format, NumberFormat);
                else if(ValueType == typeof(UInt64)) FormattedText = ((UInt64) Value).ToString(Format, NumberFormat);
                else if(ValueType == typeof(Decimal)) FormattedText = ((Decimal) Value).ToString(Format, NumberFormat);
                else throw new ApplicationException("PdfTableCell: Unknown object type");

                // add line spacing
                CellHeight += Style.FontLineSpacing;
                }
            }

            // test for minimum height requirement
            if(CellHeight < Style.MinHeight) CellHeight = Style.MinHeight;

            // return result
            return(CellHeight);
        }