Surrogates.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 GrapeCity.Documents.Pdf
  8. Imports GrapeCity.Documents.Text
  9.  
  10. '' This sample renders a variety of interesting Unicode characters
  11. '' including surrogate pairs. It also implicitly uses the automatic
  12. '' font fallback (font substitution) feature built into DsPdf.
  13. '' Note that this sample may produce different results on different
  14. '' systems, as it relies on system-provided fallback fonts.
  15. '' For a platform- and system-independent version of this sample see SurrogatesPort.
  16. '' See also FontFallbacks.
  17. Public Class Surrogates
  18. Function CreatePDF(ByVal stream As Stream) As Integer
  19. Dim doc = New GcPdfDocument()
  20. Dim g = doc.NewPage().Graphics
  21. '' For most of the 'interesting' chars demoed in this sample,
  22. '' fallback fonts (see FontFallbacks) will be automatically used,
  23. '' so we can just use a standard font for the captions:
  24. Dim font = StandardFonts.Helvetica
  25. Dim tf = New TextFormat() With {.Font = font, .FontSize = 12}
  26. Dim tf1 = New TextFormat(tf) With {.FontSize = 14}
  27.  
  28. g.DrawString("Some Interesting Unicode Characters (relies on system fallbacks)",
  29. New TextFormat(tf) With {.Underline = True, .FontSize = tf.FontSize + 2},
  30. New RectangleF(0, 36, doc.PageSize.Width, Single.MaxValue),
  31. TextAlignment.Center)
  32.  
  33. '' Set up text insertion point and its advance function:
  34. Dim ip = New PointF(72, 54)
  35. Dim nextIp As Func(Of Boolean, PointF) =
  36. Function(caption_ As Boolean)
  37. ip.Y += If(caption_, 30, 20)
  38. Return ip
  39. End Function
  40.  
  41. '' Draw the strings:
  42. g.DrawString("Surrogate Pairs:", tf, nextIp(True))
  43. g.DrawString($"{ChrW(&HD867)}{ChrW(&HDEDB)} {ChrW(&HD840)}{ChrW(&HDC0B)} {ChrW(&HD834)}{ChrW(&HDD1E)} {ChrW(&HD834)}{ChrW(&HDD61)} {ChrW(&HD83D)}{ChrW(&HDC04)}", tf1, nextIp(False))
  44.  
  45. g.DrawString("Currency Symbols:", tf, nextIp(True))
  46. g.DrawString($"{ChrW(&H24)} {ChrW(&H20A0)} {ChrW(&H20A1)} {ChrW(&H20A2)} {ChrW(&H20A3)} {ChrW(&H20A4)} {ChrW(&H20AC)} {ChrW(&H20B9)} {ChrW(&H20BD)}", tf1, nextIp(False))
  47.  
  48. g.DrawString("Mathematical Operators:", tf, nextIp(True))
  49. g.DrawString($"{ChrW(&H221A)} {ChrW(&H222B)} {ChrW(&H2211)} {ChrW(&H2210)} {ChrW(&H2264)} {ChrW(&H2265)} {ChrW(&H2202)} {ChrW(&H2208)}", tf1, nextIp(False))
  50.  
  51. g.DrawString("CJK Ideographs Extension A:", tf, nextIp(True))
  52. g.DrawString($"{ChrW(&H3400)} {ChrW(&H3401)} {ChrW(&H3402)} {ChrW(&H3403)} {ChrW(&H3404)} {ChrW(&H3405)} {ChrW(&H3406)} {ChrW(&H3407)}", tf1, nextIp(False))
  53.  
  54. g.DrawString("Letterlike Symbols:", tf, nextIp(True))
  55. g.DrawString($"{ChrW(&H2110)} {ChrW(&H2111)} {ChrW(&H2112)} {ChrW(&H2113)} {ChrW(&H2114)} {ChrW(&H2115)} {ChrW(&H211B)} {ChrW(&H211C)}", tf1, nextIp(False))
  56.  
  57. g.DrawString("Private Use Area:", tf, nextIp(True))
  58. g.DrawString($"{ChrW(&HE000)} {ChrW(&HE001)} {ChrW(&HE010)} {ChrW(&HE011)} {ChrW(&HE012)} {ChrW(&HE013)} {ChrW(&HE014)} {ChrW(&HE015)}", tf1, nextIp(False))
  59.  
  60. g.DrawString("Arrows:", tf, nextIp(True))
  61. g.DrawString($"{ChrW(&H2190)} {ChrW(&H2191)} {ChrW(&H2192)} {ChrW(&H2193)} {ChrW(&H21B0)} {ChrW(&H21E6)} {ChrW(&H21CB)} {ChrW(&H21A9)}", tf1, nextIp(False))
  62.  
  63. g.DrawString("Dingbats:", tf, nextIp(True))
  64. g.DrawString($"{ChrW(&H2714)} {ChrW(&H2717)} {ChrW(&H275B)} {ChrW(&H275C)} {ChrW(&H2706)} {ChrW(&H2707)} {ChrW(&H2708)} {ChrW(&H2709)}", tf1, nextIp(False))
  65.  
  66. g.DrawString("Braille Patterns:", tf, nextIp(True))
  67. g.DrawString($"{ChrW(&H2830)} {ChrW(&H2831)} {ChrW(&H2832)} {ChrW(&H2833)} {ChrW(&H2834)} {ChrW(&H2835)} {ChrW(&H2836)} {ChrW(&H2837)}", tf1, nextIp(False))
  68.  
  69. g.DrawString($"Geometric Shapes:", tf, nextIp(True))
  70. g.DrawString($"{ChrW(&H25D0)} {ChrW(&H25D1)} {ChrW(&H25D2)} {ChrW(&H25D3)} {ChrW(&H25A4)} {ChrW(&H25F0)} {ChrW(&H25BC)} {ChrW(&H25CE)}", tf1, nextIp(False))
  71.  
  72. g.DrawString("Latin Extended A:", tf, nextIp(True))
  73. g.DrawString($"{ChrW(&H100)} {ChrW(&H101)} {ChrW(&H102)} {ChrW(&H103)} {ChrW(&H104)} {ChrW(&H105)} {ChrW(&H106)} {ChrW(&H107)}", tf1, nextIp(False))
  74.  
  75. g.DrawString("Miscellaneous Symbols:", tf, nextIp(True))
  76. g.DrawString($"{ChrW(&H2600)} {ChrW(&H2601)} {ChrW(&H2602)} {ChrW(&H2603)} {ChrW(&H2604)} {ChrW(&H2605)} {ChrW(&H2606)} " +
  77. $"{ChrW(&H2607)} {ChrW(&H2608)} {ChrW(&H2609)} {ChrW(&H2614)} {ChrW(&H2615)} {ChrW(&H26F0)}", tf1, nextIp(False))
  78. ''
  79. '' Done:
  80. doc.Save(stream)
  81. Return doc.Pages.Count
  82. End Function
  83. End Class
  84.