SurrogatesPort.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. Imports GCTEXT = GrapeCity.Documents.Text
  10. Imports GCDRAW = GrapeCity.Documents.Drawing
  11.  
  12. '' This sample renders a variety of interesting Unicode characters
  13. '' including surrogate pairs, similar to the Surrogates sample.
  14. '' Unlike that sample though, it does not rely on any system-provided
  15. '' fallbacks. Instead, in this sample we purposefully restrict fallback
  16. '' font lookup to the program's own font collection, and provide
  17. '' our own set of fallback fonts.
  18. '' This makes the code platform and system independent, so it produces
  19. '' exactly the same result on Windows, Linux or Mac.
  20. Public Class SurrogatesPort
  21. Function CreatePDF(ByVal stream As Stream) As Integer
  22. Dim doc = New GcPdfDocument()
  23. Dim page = doc.NewPage()
  24. Dim g = page.Graphics
  25.  
  26. '' As in the Surrogates sample, we specify a standard font
  27. '' (which lacks many of the glyphs we will be rendering),
  28. '' and will rely on font fallback support provided by FontCollection:
  29. Dim font = StandardFonts.Helvetica
  30.  
  31. '' Set up text formats for captions, "interesting chars" and spacing:
  32. Dim tf = New TextFormat() With {.Font = font, .FontSize = 12}
  33. Dim tf1 = New TextFormat(tf) With {.FontSize = 14}
  34. Dim tfs = New TextFormat(tf) With {.FontSize = 6}
  35.  
  36. '' Create a font collection to use:
  37. Dim fc = New FontCollection()
  38. '' Add our own fallback fonts to use (note that order is important here,
  39. '' first come first found):
  40. fc.AppendFallbackFonts(
  41. GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "arialuni.ttf")),
  42. GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "l_10646.ttf")),
  43. GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "seguiemj.ttf")),
  44. GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "seguisym.ttf")),
  45. GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "simsun.ttc")),
  46. GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf")),
  47. GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "YuGothR.ttc"))
  48. )
  49.  
  50. '' Restricting default font lookup is done in the TextLayout, so unlike the
  51. '' {Surrogates} sample, here we cannot use DrawString, but must use
  52. '' TextLayout and DrawTextLayout directly.
  53. '' Notes:
  54. '' - Specify the font collection to use;
  55. '' - Restrict default fonts/fallbacks lookup to the specified collection only.
  56. Dim tl = New TextLayout(72) With {
  57. .FontCollection = fc,
  58. .RestrictedFontLookup = True,
  59. .FontFallbackScope = FontFallbackScope.FontCollectionOnly,
  60. .MaxWidth = page.Size.Width,
  61. .MaxHeight = page.Size.Height,
  62. .MarginLeft = 72,
  63. .MarginRight = 72,
  64. .MarginTop = 36,
  65. .MarginBottom = 36,
  66. .TextAlignment = TextAlignment.Center
  67. }
  68.  
  69. tl.Append("Some Interesting Unicode Characters (system-independent)",
  70. New TextFormat(tf) With {.Underline = True, .FontSize = tf.FontSize + 2})
  71. tl.PerformLayout(True)
  72. g.DrawTextLayout(tl, PointF.Empty)
  73.  
  74. tl.MarginTop = tl.ContentRectangle.Bottom + 20
  75. tl.Clear()
  76. tl.TextAlignment = TextAlignment.Leading
  77.  
  78. '' Draw the strings:
  79. tl.Append("Surrogate Pairs:" + vbCrLf, tf)
  80. tl.Append($"{ChrW(&HD867)}{ChrW(&HDEDB)} {ChrW(&HD840)}{ChrW(&HDC0B)} {ChrW(&HD834)}{ChrW(&HDD1E)} {ChrW(&HD834)}{ChrW(&HDD61)} {ChrW(&HD83D)}{ChrW(&HDC04)}{vbCrLf}", tf1)
  81. tl.Append(vbCrLf, tfs)
  82.  
  83. tl.Append("Currency Symbols:" + vbCrLf, tf)
  84. tl.Append($"{ChrW(&H24)} {ChrW(&H20A0)} {ChrW(&H20A1)} {ChrW(&H20A2)} {ChrW(&H20A3)} {ChrW(&H20A4)} {ChrW(&H20AC)} {ChrW(&H20B9)} {ChrW(&H20BD)}{vbCrLf}", tf1)
  85. tl.Append(vbCrLf, tfs)
  86.  
  87. tl.Append("Mathematical Operators:" + vbCrLf, tf)
  88. tl.Append($"{ChrW(&H221A)} {ChrW(&H222B)} {ChrW(&H2211)} {ChrW(&H2210)} {ChrW(&H2264)} {ChrW(&H2265)} {ChrW(&H2202)} {ChrW(&H2208)}{vbCrLf}", tf1)
  89. tl.Append(vbCrLf, tfs)
  90.  
  91. tl.Append("CJK Ideographs Extension A:" + vbCrLf, tf)
  92. tl.Append($"{ChrW(&H3400)} {ChrW(&H3401)} {ChrW(&H3402)} {ChrW(&H3403)} {ChrW(&H3404)} {ChrW(&H3405)} {ChrW(&H3406)} {ChrW(&H3407)}{vbCrLf}", tf1)
  93. tl.Append(vbCrLf, tfs)
  94.  
  95. tl.Append("Letterlike Symbols:" + vbCrLf, tf)
  96. tl.Append($"{ChrW(&H2110)} {ChrW(&H2111)} {ChrW(&H2112)} {ChrW(&H2113)} {ChrW(&H2114)} {ChrW(&H2115)} {ChrW(&H211B)} {ChrW(&H211C)}{vbCrLf}", tf1)
  97. tl.Append(vbCrLf, tfs)
  98.  
  99. tl.Append("Private Use Area:" + vbCrLf, tf)
  100. tl.Append($"{ChrW(&HE000)} {ChrW(&HE001)} {ChrW(&HE010)} {ChrW(&HE011)} {ChrW(&HE012)} {ChrW(&HE013)} {ChrW(&HE014)} {ChrW(&HE015)}{vbCrLf}", tf1)
  101. tl.Append(vbCrLf, tfs)
  102.  
  103. tl.Append("Arrows:" + vbCrLf, tf)
  104. tl.Append($"{ChrW(&H2190)} {ChrW(&H2191)} {ChrW(&H2192)} {ChrW(&H2193)} {ChrW(&H21B0)} {ChrW(&H21E6)} {ChrW(&H21CB)} {ChrW(&H21A9)}{vbCrLf}", tf1)
  105. tl.Append(vbCrLf, tfs)
  106.  
  107. tl.Append("Dingbats:" + vbCrLf, tf)
  108. tl.Append($"{ChrW(&H2714)} {ChrW(&H2717)} {ChrW(&H275B)} {ChrW(&H275C)} {ChrW(&H2706)} {ChrW(&H2707)} {ChrW(&H2708)} {ChrW(&H2709)}{vbCrLf}", tf1)
  109. tl.Append(vbCrLf, tfs)
  110.  
  111. tl.Append("Braille Patterns:" + vbCrLf, tf)
  112. tl.Append($"{ChrW(&H2830)} {ChrW(&H2831)} {ChrW(&H2832)} {ChrW(&H2833)} {ChrW(&H2834)} {ChrW(&H2835)} {ChrW(&H2836)} {ChrW(&H2837)}{vbCrLf}", tf1)
  113. tl.Append(vbCrLf, tfs)
  114.  
  115. tl.Append("Geometric Shapes:" + vbCrLf, tf)
  116. tl.Append($"{ChrW(&H25D0)} {ChrW(&H25D1)} {ChrW(&H25D2)} {ChrW(&H25D3)} {ChrW(&H25A4)} {ChrW(&H25F0)} {ChrW(&H25BC)} {ChrW(&H25CE)}{vbCrLf}", tf1)
  117. tl.Append(vbCrLf, tfs)
  118.  
  119. tl.Append("Latin Extended A:" + vbCrLf, tf)
  120. tl.Append($"{ChrW(&H100)} {ChrW(&H101)} {ChrW(&H102)} {ChrW(&H103)} {ChrW(&H104)} {ChrW(&H105)} {ChrW(&H106)} {ChrW(&H107)}{vbCrLf}", tf1)
  121. tl.Append(vbCrLf, tfs)
  122.  
  123. tl.Append("Miscellaneous Symbols:" + vbCrLf, tf)
  124. tl.Append($"{ChrW(&H2600)} {ChrW(&H2601)} {ChrW(&H2602)} {ChrW(&H2603)} {ChrW(&H2604)} {ChrW(&H2605)} {ChrW(&H2606)} " +
  125. $"{ChrW(&H2607)} {ChrW(&H2608)} {ChrW(&H2609)} {ChrW(&H2614)} {ChrW(&H2615)} {ChrW(&H26F0)}{vbCrLf}", tf1)
  126. tl.Append(vbCrLf, tfs)
  127.  
  128. tl.PerformLayout(True)
  129. g.DrawTextLayout(tl, PointF.Empty)
  130. ''
  131. '' Done:
  132. doc.Save(stream)
  133. Return doc.Pages.Count
  134. End Function
  135. End Class
  136.