FontFeatures.cs
  1. //
  2. // This code is part of Document Solutions for PDF demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using GrapeCity.Documents.Pdf;
  9. using GrapeCity.Documents.Text;
  10. using GCTEXT = GrapeCity.Documents.Text;
  11. using GCDRAW = GrapeCity.Documents.Drawing;
  12.  
  13. namespace DsPdfWeb.Demos.Basics
  14. {
  15. // A simple demonstration of some interesting font features in action.
  16. // For the complete list of font features see featurelist.htm.
  17. // See also Ligatures.
  18. public class FontFeatures
  19. {
  20. public int CreatePDF(Stream stream)
  21. {
  22. var doc = new GcPdfDocument();
  23. var g = doc.NewPage().Graphics;
  24. //
  25. var font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "Gabriola.ttf"));
  26. var tf = new TextFormat() { Font = font, FontSize = 20 };
  27. //
  28. var tl = g.CreateTextLayout();
  29. tl.AppendLine("Line with no custom font features.", tf);
  30. //
  31. tf.FontFeatures = new FontFeature[] { new FontFeature(FeatureTag.ss03) };
  32. tl.AppendLine("Line with font feature ss03 enabled.", tf);
  33. //
  34. tf.FontFeatures = new FontFeature[] { new FontFeature(FeatureTag.ss05) };
  35. tl.AppendLine("Line with font feature ss05 enabled.", tf);
  36. //
  37. tf.FontFeatures = new FontFeature[] { new FontFeature(FeatureTag.ss07) };
  38. tl.AppendLine("Line with font feature ss07 enabled.", tf);
  39. //
  40. tl.PerformLayout(true);
  41. g.DrawTextLayout(tl, new PointF(72, 72));
  42. // Done:
  43. doc.Save(stream);
  44. return doc.Pages.Count;
  45. }
  46. }
  47. }
  48.