WordCharWrap.vb
''
'' This code is part of Document Solutions for PDF demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing

'' This sample demonstrates the difference between WordWrap And CharWrap
'' text wrapping modes.
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)

        '' Done
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class