Antialiasing.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.Numerics
  8. Imports GrapeCity.Documents.Drawing
  9. Imports GrapeCity.Documents.Text
  10. Imports GrapeCity.Documents.Imaging
  11. Imports GCTEXT = GrapeCity.Documents.Text
  12. Imports GCDRAW = GrapeCity.Documents.Drawing
  13.  
  14. '' This sample shows the different (anti)aliasing modes of rendering text:
  15. '' - No anti-aliasing, very fast but poor quality (not recommended).
  16. '' - Fast anti-aliasing. This is the default that provides good quality and fast rendering.
  17. '' - Slow anti-aliasing. Highest quality but slower than the default.
  18. Public Class Antialiasing
  19. Function GenerateImage(
  20. ByVal pixelSize As Size,
  21. ByVal dpi As Single,
  22. ByVal opaque As Boolean,
  23. Optional ByVal sampleParams As String() = Nothing) As GcBitmap
  24.  
  25. Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi)
  26. Using g = bmp.CreateGraphics(Color.FromArgb(&HFFCCF2FF))
  27. g.Renderer.Multithreaded = True
  28.  
  29. Dim text = Util.LoremIpsum()
  30. Dim tsize = New SizeF(bmp.Width / 2, bmp.Height / 2)
  31. Dim pad = 96.0F / 4
  32.  
  33. Dim tfcap = New TextFormat() With
  34. {
  35. .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "timesbd.ttf")),
  36. .FontSize = 16
  37. }
  38.  
  39. Dim tl = g.CreateTextLayout()
  40. tl.DefaultFormat.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf"))
  41. tl.DefaultFormat.FontSize = 14
  42. tl.TextAlignment = TextAlignment.Justified
  43. tl.FirstLineIndent = 96 / 2
  44. tl.ParagraphSpacing = 96 / 8
  45. tl.MaxWidth = tsize.Width
  46. tl.MaxHeight = tsize.Height
  47. tl.MarginAll = pad
  48.  
  49. Dim tloc = PointF.Empty
  50. Using g.PushClip(New RectangleF(tloc, tsize))
  51. bmp.Renderer.Aliased = True
  52. tl.AppendLine("No anti-aliasing (worst quality)", tfcap)
  53. tl.Append(text)
  54. tl.PerformLayout(True)
  55. g.DrawTextLayout(tl, tloc)
  56. End Using
  57. tloc.X += tsize.Width
  58. Using g.PushClip(New RectangleF(tloc, tsize))
  59. bmp.Renderer.Aliased = False
  60. bmp.Renderer.SlowAntialiasing = False
  61. tl.Clear()
  62. tl.AppendLine("Fast anti-aliasing (default quality)", tfcap)
  63. tl.Append(text)
  64. tl.PerformLayout(True)
  65. g.DrawTextLayout(tl, tloc)
  66. End Using
  67. tloc.X = 0
  68. tloc.Y += tsize.Height
  69. Using g.PushClip(New RectangleF(tloc, tsize))
  70. bmp.Renderer.Aliased = False
  71. bmp.Renderer.SlowAntialiasing = True
  72. tl.Clear()
  73. tl.AppendLine("Slow anti-aliasing (highest quality)", tfcap)
  74. tl.Append(text)
  75. tl.PerformLayout(True)
  76. g.DrawTextLayout(tl, tloc)
  77. End Using
  78. End Using
  79. Return bmp
  80. End Function
  81. End Class
  82.