コード例 #1
0
        ////////////////////////////////////////////////////////////////////
        // Draw text within text box center or right justified
        ////////////////////////////////////////////////////////////////////
        private Double DrawText(
			Double			PosX,
			Double			PosY,
			Double			Width,
			TextBoxJustify	Justify,
			TextBoxLine		Line,
			PdfPage			Page
			)
        {
            Double LineWidth = 0;
            foreach(TextBoxSeg Seg in Line.SegArray) LineWidth += Seg.SegWidth;

            Double SegPosX = PosX;
            if(Justify == TextBoxJustify.Right) SegPosX += Width - LineWidth;
            else SegPosX += 0.5 * (Width - LineWidth);
            foreach(TextBoxSeg Seg in Line.SegArray)
            {
            Double SegWidth = DrawText(Seg.Font, Seg.FontSize, SegPosX, PosY, TextJustify.Left, Seg.DrawStyle, Seg.FontColor, Seg.Text);
            if(Seg.WebLink != null)
                {
                if(Page == null) throw new ApplicationException("TextBox with WebLink. You must call DrawText with PdfPage");
                Page.AddWebLink(SegPosX, PosY - Seg.Font.DescentPlusLeading(Seg.FontSize), SegPosX + SegWidth, PosY + Seg.Font.AscentPlusLeading(Seg.FontSize), Seg.WebLink);
                }

            SegPosX += SegWidth;
            }

            return(SegPosX - PosX);
        }
コード例 #2
0
        ////////////////////////////////////////////////////////////////////
        // 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);
        }