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. GCTEXT.Font font;
  26. var fpath = Path.Combine("Resources", "Fonts", "Gabriola.ttf");
  27. if (File.Exists(fpath))
  28. font = GCTEXT.Font.FromFile(fpath);
  29. else
  30. font = FontCollection.SystemFonts.FindFamilyName("Gabriola");
  31. var tf = new TextFormat() { Font = font, FontSize = 20 };
  32. //
  33. var tl = g.CreateTextLayout();
  34. tl.AppendLine("Line with no custom font features.", tf);
  35. //
  36. tf.FontFeatures = [new FontFeature(FeatureTag.ss03)];
  37. tl.AppendLine("Line with font feature ss03 enabled.", tf);
  38. //
  39. tf.FontFeatures = [new FontFeature(FeatureTag.ss05)];
  40. tl.AppendLine("Line with font feature ss05 enabled.", tf);
  41. //
  42. tf.FontFeatures = [new FontFeature(FeatureTag.ss07)];
  43. tl.AppendLine("Line with font feature ss07 enabled.", tf);
  44. //
  45. tl.PerformLayout(true);
  46. g.DrawTextLayout(tl, new PointF(72, 72));
  47. // Done:
  48. doc.Save(stream);
  49. return doc.Pages.Count;
  50. }
  51. }
  52. }
  53.