OutlinedText.vb
  1. ''
  2. '' This code is part of Document Solutions for Imaging 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 System.Linq
  9. Imports System.Numerics
  10. Imports GrapeCity.Documents.Drawing
  11. Imports GrapeCity.Documents.Text
  12. Imports GrapeCity.Documents.Imaging
  13. Imports GCTEXT = GrapeCity.Documents.Text
  14. Imports GCDRAW = GrapeCity.Documents.Drawing
  15.  
  16. '' Creating outlined text
  17. Public Class OutlinedText
  18. Function GenerateImage(
  19. ByVal pixelSize As Size,
  20. ByVal dpi As Single,
  21. ByVal opaque As Boolean,
  22. Optional ByVal sampleParams As String() = Nothing) As GcBitmap
  23.  
  24. Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)
  25. Using g = bmp.CreateGraphics(Color.White)
  26. Dim tl = g.CreateTextLayout()
  27.  
  28. '' Set up text layout:
  29. tl.MaxWidth = g.Width
  30. tl.MaxHeight = g.Height
  31. tl.MarginAll = g.Resolution / 2
  32. Const fontSize = 64
  33.  
  34. Dim rcBack = New RectangleF(0, 0, pixelSize.Width, pixelSize.Height)
  35. g.DrawImage(GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "purples.jpg")), rcBack, Nothing, ImageAlign.StretchImage)
  36.  
  37. Dim tf0 = New TextFormat() With
  38. {
  39. .ForeColor = Color.LemonChiffon,
  40. .Hollow = True,
  41. .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "GOTHICB.TTF")),
  42. .FontSize = fontSize
  43. }
  44. tl.AppendLine("Hollow Text", tf0)
  45.  
  46. Dim tf1 = New TextFormat() With
  47. {
  48. .StrokePen = Color.DarkMagenta,
  49. .FillBrush = New GCDRAW.SolidBrush(Color.Yellow),
  50. .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FoglihtenNo07.otf")),
  51. .FontSize = fontSize
  52. }
  53. tl.AppendLine("Outlined Text", tf1)
  54.  
  55. Dim grad0 = New LinearGradientBrush(Color.Red, New PointF(0, 0), Color.Blue, New PointF(1, 0))
  56. Dim tf2 = New TextFormat() With
  57. {
  58. .FillBrush = grad0,
  59. .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "cambriab.ttf")),
  60. .FontSize = fontSize
  61. }
  62. tl.AppendLine("Gradient Fill", tf2)
  63.  
  64. Dim grad1 = New LinearGradientBrush(Color.Red, Color.Purple)
  65. grad1.GradientStops = New List(Of GradientStop)() From
  66. {
  67. New GradientStop(Color.Orange, 1 / 6.0F),
  68. New GradientStop(Color.Yellow, 2 / 6.0F),
  69. New GradientStop(Color.Green, 3 / 6.0F),
  70. New GradientStop(Color.Cyan, 4 / 6.0F),
  71. New GradientStop(Color.Blue, 5 / 6.0F)
  72. }
  73. Dim tf3 = New TextFormat() With
  74. {
  75. .FillBrush = grad1,
  76. .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "cambriab.ttf")),
  77. .FontSize = fontSize
  78. }
  79. tl.AppendLine("Multi-stop gradient", tf3)
  80.  
  81. Dim tf4 = New TextFormat(tf3)
  82. tf4.StrokePen = Color.GreenYellow
  83. tl.AppendLine("Multi-stop gradient with outline", tf4)
  84.  
  85. Dim tf5 = New TextFormat(tf4)
  86. tf5.Hollow = True
  87. tf5.StrokePen = New GCDRAW.Pen(Color.DarkRed, g.Resolution / 72)
  88. tl.AppendLine("Text outlined with 1pt wide pen", tf5)
  89.  
  90. '' It is not necessary to call PerformLayout() for a newly created TextLayout
  91. '' or after a call to TextLayout.Clear():
  92. g.DrawTextLayout(tl, PointF.Empty)
  93. End Using
  94. '' Done:
  95. Return bmp
  96. End Function
  97. End Class
  98.  
  99.