CharsAndFonts.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 how to draw text using different fonts (.ttf, .otf, .woff)
  15. '' and characters with codes greater than 0xFFFF.
  16. Public Class CharsAndFonts
  17. Function GenerateImage(
  18. ByVal pixelSize As Size,
  19. ByVal dpi As Single,
  20. ByVal opaque As Boolean,
  21. Optional ByVal sampleParams As String() = Nothing) As GcBitmap
  22.  
  23. Dim garlicFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "Woff", "Garlicembrace.woff"))
  24. Dim foglihtenFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FoglihtenNo07.otf"))
  25. Dim pericFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "peric.ttf"))
  26. Dim emojiFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "seguiemj.ttf"))
  27. Dim timesFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf"))
  28. Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi)
  29. Using g = bmp.CreateGraphics(Color.White)
  30. Dim tf = New TextFormat With
  31. {
  32. .Font = garlicFont,
  33. .FontSize = 40
  34. }
  35. g.DrawString("Garlicembrace.woff", tf, New RectangleF(4, 4, 500, 50))
  36.  
  37. tf = New TextFormat With
  38. {
  39. .Font = timesFont,
  40. .FontSize = 40
  41. }
  42. g.DrawString("Times New Roman", tf, New RectangleF(4, 64, 580, 50))
  43.  
  44. Dim tl = g.CreateTextLayout()
  45. tf = New TextFormat With
  46. {
  47. .Font = foglihtenFont,
  48. .FontSize = 40
  49. }
  50. tl.Append("FoglihtenNo07.otf", tf)
  51. g.DrawTextLayout(tl, New PointF(4, 139))
  52.  
  53. tf = New TextFormat With
  54. {
  55. .Font = pericFont,
  56. .FontSize = 40
  57. }
  58. g.DrawString("peric.ttf", tf, New RectangleF(4, 190, 500, 50))
  59.  
  60. Dim pals = emojiFont.CreateFontTables(TableTag.CpalDraw).GetPalettes()
  61. tf = New TextFormat With
  62. {
  63. .Font = emojiFont,
  64. .FontSize = 40,
  65. .Palette = pals(0)
  66. }
  67. Dim s1 As String = Char.ConvertFromUtf32(&H1F433)
  68. Dim s2 As String = Char.ConvertFromUtf32(&H1F349)
  69. Dim s3 As String = Char.ConvertFromUtf32(&H1F367)
  70. g.DrawString($"seguiemj.ttf {s1}{s2}{s3}", tf, New RectangleF(4, 240, 550, 50))
  71. End Using
  72. Return bmp
  73. End Function
  74. End Class
  75.