Ligatures.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. '' Ligatures (joining two or more letters into a single glyph) are supported by DsPdf,
  13. '' provided the selected font supports them, and the corresponding font feature is on.
  14. '' For the complete list of font features see featurelist.htm.
  15. '' See also FontFeatures.
  16. Public Class Ligatures
  17. Function CreatePDF(ByVal stream As Stream) As Integer
  18. '' The list of common Latin ligatures:
  19. Const latinLigatures = "fi, fj, fl, ff, ffi, ffl."
  20. '' Set up ligature-related font features:
  21. '' All ON:
  22. Dim allOn As FontFeature() = {
  23. New FontFeature(FeatureTag.clig, True), '' Contextual Ligatures
  24. New FontFeature(FeatureTag.dlig, True), '' Discretionary Ligatures
  25. New FontFeature(FeatureTag.hlig, True), '' Historical Ligatures
  26. New FontFeature(FeatureTag.liga, True), '' Standard Ligatures
  27. New FontFeature(FeatureTag.rlig, True) '' Required Ligatures
  28. }
  29. '' All OFF:
  30. Dim allOff As FontFeature() = {
  31. New FontFeature(FeatureTag.clig, False),
  32. New FontFeature(FeatureTag.dlig, False),
  33. New FontFeature(FeatureTag.hlig, False),
  34. New FontFeature(FeatureTag.liga, False),
  35. New FontFeature(FeatureTag.rlig, False)
  36. }
  37. Dim doc = New GcPdfDocument()
  38. Dim g = doc.NewPage().Graphics
  39. '' Text insertion point:
  40. Dim ip = New PointF(72, 72)
  41. Dim tf = New TextFormat()
  42. tf.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf"))
  43. tf.FontSize = 20
  44. g.DrawString($"Common Latin ligatures, font {tf.Font.FontFamilyName}", tf, ip)
  45. ip.Y += 36
  46. '' Turn all ligature features OFF:
  47. tf.FontFeatures = allOff
  48. g.DrawString($"All ligature features OFF: {latinLigatures}", tf, ip)
  49. ip.Y += 36
  50. '' Turn all ligature features ON:
  51. tf.FontFeatures = allOn
  52. g.DrawString($"All ligature features ON: {latinLigatures}", tf, ip)
  53. ip.Y += 72
  54. '' Repeat with a different font:
  55. tf.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "Gabriola.ttf"))
  56. g.DrawString($"Common Latin ligatures, font {tf.Font.FontFamilyName}", tf, ip)
  57. ip.Y += 36
  58. '' Turn all ligature features OFF:
  59. tf.FontFeatures = allOff
  60. g.DrawString($"All ligature features OFF: {latinLigatures}", tf, ip)
  61. ip.Y += 36
  62. '' Turn all ligature features ON:
  63. tf.FontFeatures = allOn
  64. g.DrawString($"All ligature features ON: {latinLigatures}", tf, ip)
  65. ''
  66. '' Done:
  67. doc.Save(stream)
  68. Return doc.Pages.Count
  69. End Function
  70. End Class
  71.