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; }
//////////////////////////////////////////////////////////////////// // 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); }
//////////////////////////////////////////////////////////////////// // Draw Text for TextBox with web link //////////////////////////////////////////////////////////////////// /// <summary> /// Draw TextBox /// </summary> /// <param name="PosX">Position X</param> /// <param name="PosYTop">Position Y (by reference)</param> /// <param name="PosYBottom">Position Y bottom</param> /// <param name="LineNo">Start at line number</param> /// <param name="LineExtraSpace">Extra line spacing</param> /// <param name="ParagraphExtraSpace">Extra paragraph spacing</param> /// <param name="Justify">TextBox justify enumeration</param> /// <param name="TextBox">TextBox</param> /// <param name="Page">Page if TextBox contains web link segment</param> /// <returns>Next line number</returns> /// <remarks> /// Before calling this method you must add text to a TextBox object. /// <para> /// Set the PosX and PosYTop to the left top corner of the text area. /// Note PosYTop is by reference. This variable will be updated to /// the next vertical line position after the method was executed. /// </para> /// <para> /// Set the PosYBottom to the bottom of your page. The method will /// not print below this value. /// </para> /// <para> /// Set the LineNo to the first line to be printed. Initially /// this will be zero. After the method returns, PosYTop is set /// to next print line on the page and LineNo is set to next line /// within the box. /// </para> /// <para> /// If LineNo is equals to TextBox.LineCount the box was fully printed. /// </para> /// <para> /// If LineNo is less than TextBox.LineCount box printing was not /// done. Start a new PdfPage and associated PdfContents. Set /// PosYTop to desired start position. Set LineNo to the value /// returned by this method, and call the method again. /// </para> /// <para> /// If your TextBox contains WebLink segment you must supply /// Page argument and position X and Y must be relative to /// page bottom left corner. /// </para> /// <para> /// TextBoxJustify controls horizontal justification. FitToWidth /// will display a straight right edge. /// </para> /// </remarks> //////////////////////////////////////////////////////////////////// public Int32 DrawText( Double PosX, ref Double PosYTop, Double PosYBottom, Int32 LineNo, Double LineExtraSpace, Double ParagraphExtraSpace, TextBoxJustify Justify, TextBox TextBox, PdfPage Page = null ) { TextBox.Terminate(); for(; LineNo < TextBox.LineCount; LineNo++) { // short cut TextBoxLine Line = TextBox[LineNo]; // break out of the loop if printing below bottom line if(PosYTop - Line.LineHeight < PosYBottom) break; // adjust PosY to font base line PosYTop -= Line.Ascent; // text horizontal position Double X = PosX; Double W = TextBox.BoxWidth; // if we have first line indent, adjust text x position for first line of a paragraph if(TextBox.FirstLineIndent != 0 && (LineNo == 0 || TextBox[LineNo - 1].EndOfParagraph)) { X += TextBox.FirstLineIndent; W -= TextBox.FirstLineIndent; } // draw text to fit box width if(Justify == TextBoxJustify.FitToWidth && !Line.EndOfParagraph) { DrawText(X, PosYTop, W, Line, Page); } // draw text center or right justified else if(Justify == TextBoxJustify.Center || Justify == TextBoxJustify.Right) { DrawText(X, PosYTop, W, Justify, Line, Page); } // draw text normal else { DrawText(X, PosYTop, Line, Page); } // advance position y to next line PosYTop -= Line.Descent + LineExtraSpace; if(Line.EndOfParagraph) PosYTop -= ParagraphExtraSpace; } return(LineNo); }
//////////////////////////////////////////////////////////////////// // 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); }