OutlinedText.vb
'' 完毕:
Imports System.IO
Imports System.Drawing
Imports System.Collections.Generic
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing
'' 此示例展示了如何使用描边字形轮廓渲染文本,
'' 并使用实心或渐变画笔填充字形。
Public Class OutlinedText
Sub CreatePDF(ByVal stream As Stream)
Dim doc = New GcPdfDocument()
Dim page = doc.NewPage()
Dim g = page.Graphics
Dim rc = Util.AddNote(
"此示例演示了如何使用描边字形轮廓绘制文本," +
"",
page)
Dim tl = g.CreateTextLayout()
'' 设置文本流和其他布局属性:
tl.MaxWidth = page.Size.Width
tl.MaxHeight = page.Size.Height
tl.MarginAll = 72
tl.MarginTop = rc.Bottom + 36
Dim rcBack = New RectangleF(tl.MarginLeft, tl.MarginTop, tl.MaxWidth.Value - tl.MarginLeft - tl.MarginRight, tl.MaxHeight.Value - tl.MarginTop - tl.MarginBottom)
g.DrawImage(GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "purples.jpg")), rcBack, Nothing, ImageAlign.StretchImage)
Dim tf0 = New TextFormat() With
{
.ForeColor = Color.LemonChiffon,
.Hollow = True,
.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "GOTHICB.TTF")),
.FontSize = 48
}
tl.AppendLine("Hollow Text", tf0)
Dim tf1 = New TextFormat() With
{
.StrokePen = Color.DarkMagenta,
.FillBrush = New GCDRAW.SolidBrush(Color.Yellow),
.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FoglihtenNo07.otf")),
.FontSize = 48
}
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 = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "cambriab.ttf")),
.FontSize = 48
}
tl.AppendLine("Gradient Fill", tf2)
Dim grad1 = New LinearGradientBrush(Color.Red, Color.Purple)
grad1.GradientStops = New List(Of GradientStop)()
grad1.GradientStops.Add(New GradientStop(Color.Orange, 1 / 6.0F))
grad1.GradientStops.Add(New GradientStop(Color.Yellow, 2 / 6.0F))
grad1.GradientStops.Add(New GradientStop(Color.Green, 3 / 6.0F))
grad1.GradientStops.Add(New GradientStop(Color.Cyan, 4 / 6.0F))
grad1.GradientStops.Add(New GradientStop(Color.Blue, 5 / 6.0F))
Dim tf3 = New TextFormat() With
{
.FillBrush = grad1,
.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "cambriab.ttf")),
.FontSize = 48
}
tl.AppendLine("Multi-stop gradient", tf3)
Dim tf4 = New TextFormat(tf3) With
{
.StrokePen = Color.GreenYellow
}
tl.AppendLine("Multi-stop gradient with outline", tf4)
Dim tf5 = New TextFormat(tf4)
tf5.Hollow = True
tf5.StrokePen = New GCDRAW.Pen(Color.DarkRed, 1)
tl.AppendLine("Text outlined with 1pt wide pen", tf5)
'' 没有必要为新创建的 TextLayout 调用 PerformLayout()
'' 或者在调用 TextLayout.Clear() 之后:
g.DrawTextLayout(tl, PointF.Empty)
'' 完毕:
doc.Save(stream)
End Sub
End Class