WordCharWrap.vb
'' 完毕:
Imports System
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing

'' 此示例演示了 WordWrap 和 CharWrap 之间的区别
'' 文本换行模式。
Public Class WordCharWrap
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim str =
            "Lose nothing in your documents! Document Solutions for PDF includes text and paragraph formatting, " +
            "special characters, multiple languages, RTL support, vertical and rotated text on all supported platforms."

        Dim doc = New GcPdfDocument()
        Dim page = doc.NewPage()
        Dim g = page.Graphics

        Dim tl = g.CreateTextLayout()
        tl.Append(str)
        tl.DefaultFormat.Font = StandardFonts.Times
        tl.DefaultFormat.FontSize = 12
        tl.MaxWidth = 72 * 3

        tl.WrapMode = WrapMode.WordWrap
        tl.PerformLayout(True)

        Dim dy = tl.Lines(0).Height + 72 / 16
        Dim rc = New RectangleF(72, 72 + dy, tl.MaxWidth, 72 * 1.4F)

        g.DrawString("WrapMode.WordWrap:", tl.DefaultFormat, New PointF(rc.Left, rc.Top - dy))
        g.DrawTextLayout(tl, rc.Location)
        g.DrawRectangle(rc, Color.CornflowerBlue)

        rc.Offset(0, 72 * 2)
        tl.WrapMode = WrapMode.CharWrap
        tl.PerformLayout(False)
        g.DrawString("WrapMode.CharWrap:", tl.DefaultFormat, New PointF(rc.Left, rc.Top - dy))
        g.DrawTextLayout(tl, rc.Location)
        g.DrawRectangle(rc, Color.CornflowerBlue)

        '' 完毕:
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class