OutlinedText.vb
  1. ''
  2. '' This code is part of Document Solutions for PDF demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports System.Collections.Generic
  8. Imports GrapeCity.Documents.Pdf
  9. Imports GrapeCity.Documents.Text
  10. Imports GrapeCity.Documents.Drawing
  11. Imports GCTEXT = GrapeCity.Documents.Text
  12. Imports GCDRAW = GrapeCity.Documents.Drawing
  13.  
  14. '' This sample shows how to render text with stroked glyph outlines,
  15. '' and with glyphs filled using solid or gradient brushes.
  16. Public Class OutlinedText
  17. Sub CreatePDF(ByVal stream As Stream)
  18. Dim doc = New GcPdfDocument()
  19. Dim page = doc.NewPage()
  20. Dim g = page.Graphics
  21.  
  22. Dim rc = Util.AddNote(
  23. "This sample shows how to draw text with stroked glyph outlines, " +
  24. "and how to fill glyphs with solid or gradient brushes.",
  25. page)
  26.  
  27. Dim tl = g.CreateTextLayout()
  28.  
  29. '' Set text flow and other layout properties:
  30. tl.MaxWidth = page.Size.Width
  31. tl.MaxHeight = page.Size.Height
  32. tl.MarginAll = 72
  33. tl.MarginTop = rc.Bottom + 36
  34.  
  35. Dim rcBack = New RectangleF(tl.MarginLeft, tl.MarginTop, tl.MaxWidth.Value - tl.MarginLeft - tl.MarginRight, tl.MaxHeight.Value - tl.MarginTop - tl.MarginBottom)
  36. g.DrawImage(GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "purples.jpg")), rcBack, Nothing, ImageAlign.StretchImage)
  37.  
  38. Dim tf0 = New TextFormat() With
  39. {
  40. .ForeColor = Color.LemonChiffon,
  41. .Hollow = True,
  42. .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "GOTHICB.TTF")),
  43. .FontSize = 48
  44. }
  45. tl.AppendLine("Hollow Text", tf0)
  46.  
  47. Dim tf1 = New TextFormat() With
  48. {
  49. .StrokePen = Color.DarkMagenta,
  50. .FillBrush = New GCDRAW.SolidBrush(Color.Yellow),
  51. .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FoglihtenNo07.otf")),
  52. .FontSize = 48
  53. }
  54. tl.AppendLine("Outlined Text", tf1)
  55.  
  56. Dim grad0 = New LinearGradientBrush(Color.Red, New PointF(0, 0), Color.Blue, New PointF(1, 0))
  57. Dim tf2 = New TextFormat() With
  58. {
  59. .FillBrush = grad0,
  60. .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "cambriab.ttf")),
  61. .FontSize = 48
  62. }
  63. tl.AppendLine("Gradient Fill", tf2)
  64.  
  65. Dim grad1 = New LinearGradientBrush(Color.Red, Color.Purple)
  66. grad1.GradientStops = New List(Of GradientStop)()
  67. grad1.GradientStops.Add(New GradientStop(Color.Orange, 1 / 6.0F))
  68. grad1.GradientStops.Add(New GradientStop(Color.Yellow, 2 / 6.0F))
  69. grad1.GradientStops.Add(New GradientStop(Color.Green, 3 / 6.0F))
  70. grad1.GradientStops.Add(New GradientStop(Color.Cyan, 4 / 6.0F))
  71. grad1.GradientStops.Add(New GradientStop(Color.Blue, 5 / 6.0F))
  72. Dim tf3 = New TextFormat() With
  73. {
  74. .FillBrush = grad1,
  75. .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "cambriab.ttf")),
  76. .FontSize = 48
  77. }
  78. tl.AppendLine("Multi-stop gradient", tf3)
  79.  
  80. Dim tf4 = New TextFormat(tf3) With
  81. {
  82. .StrokePen = Color.GreenYellow
  83. }
  84. tl.AppendLine("Multi-stop gradient with outline", tf4)
  85.  
  86. Dim tf5 = New TextFormat(tf4)
  87. tf5.Hollow = True
  88. tf5.StrokePen = New GCDRAW.Pen(Color.DarkRed, 1)
  89. tl.AppendLine("Text outlined with 1pt wide pen", tf5)
  90.  
  91. '' It is not necessary to call PerformLayout() for a newly created TextLayout
  92. '' or after a call to TextLayout.Clear():
  93. g.DrawTextLayout(tl, PointF.Empty)
  94.  
  95. '' Done
  96. doc.Save(stream)
  97. End Sub
  98. End Class
  99.