OutlinedText.vb
''
'' This code is part of GrapeCity Documents for Imaging samples.
'' Copyright (c) GrapeCity, Inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports System.Collections.Generic
Imports System.Linq
Imports System.Numerics
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Imaging

'' Creating outlined text
Public Class OutlinedText
    Function GenerateImage(
                Optional pixelWidth As Integer = 1024,
                Optional pixelHeight As Integer = 1024,
                Optional opaque As Boolean = True,
                Optional dpiX As Single = 96,
                Optional dpiY As Single = 96) As GcBitmap
        Dim bmp = New GcBitmap(pixelWidth, pixelHeight, opaque, dpiX, dpiY)
        Using g = bmp.CreateGraphics(Color.White)
            Dim tl = g.CreateTextLayout()

            '' Set up text layout:
            tl.MaxWidth = g.Width
            tl.MaxHeight = g.Height
            tl.MarginAll = g.Resolution / 2
            Const fontSize = 64

            Dim rcBack = New RectangleF(0, 0, pixelWidth, pixelHeight)
            g.DrawImage(Image.FromFile(Path.Combine("Resources", "Images", "purples.jpg")), rcBack, Nothing, ImageAlign.StretchImage)

            Dim tf0 = New TextFormat() With
            {
                .ForeColor = Color.LemonChiffon,
                .Hollow = True,
                .Font = Font.FromFile(Path.Combine("Resources", "Fonts", "GOTHICB.TTF")),
                .FontSize = fontSize
            }
            tl.AppendLine("Hollow Text", tf0)

            Dim tf1 = New TextFormat() With
            {
                .StrokePen = Color.DarkMagenta,
                .FillBrush = New SolidBrush(Color.Yellow),
                .Font = Font.FromFile(Path.Combine("Resources", "Fonts", "FoglihtenNo07.otf")),
                .FontSize = fontSize
            }
            tl.AppendLine("Outlined Text", tf1)

            Dim grad0 = New LinearGradientBrush(Color.Red, New PointF(0, 0), Color.Blue, New PointF(1, 0))
            Dim tf2 = New TextFormat() With
            {
                .FillBrush = grad0,
                .Font = Font.FromFile(Path.Combine("Resources", "Fonts", "cambriab.ttf")),
                .FontSize = fontSize
            }
            tl.AppendLine("Gradient Fill", tf2)

            Dim grad1 = New LinearGradientBrush(Color.Red, Color.Purple)
            grad1.GradientStops = New List(Of GradientStop)() From
            {
                New GradientStop(Color.Orange, 1 / 6.0F),
                New GradientStop(Color.Yellow, 2 / 6.0F),
                New GradientStop(Color.Green, 3 / 6.0F),
                New GradientStop(Color.Cyan, 4 / 6.0F),
                New GradientStop(Color.Blue, 5 / 6.0F)
            }
            Dim tf3 = New TextFormat() With
            {
                .FillBrush = grad1,
                .Font = Font.FromFile(Path.Combine("Resources", "Fonts", "cambriab.ttf")),
                .FontSize = fontSize
            }
            tl.AppendLine("Multi-stop gradient", tf3)

            Dim tf4 = New TextFormat(tf3)
            tf4.StrokePen = Color.GreenYellow
            tl.AppendLine("Multi-stop gradient with outline", tf4)

            Dim tf5 = New TextFormat(tf4)
            tf5.Hollow = True
            tf5.StrokePen = New Pen(Color.DarkRed, g.Resolution / 72)
            tl.AppendLine("Text outlined with 1pt wide pen", tf5)

            '' It is not necessary to call PerformLayout() for a newly created TextLayout
            '' or after a call to TextLayout.Clear():
            g.DrawTextLayout(tl, PointF.Empty)
        End Using
        '' Done:
        Return bmp
    End Function
End Class