UnicodeRanges.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.  
  11. namespace DsPdfWeb.Demos.Basics
  12. {
  13. // This sample lists Unicode ranges available in each system font.
  14. public class UnicodeRanges
  15. {
  16. public int CreatePDF(Stream stream)
  17. {
  18. // Setup:
  19. var doc = new GcPdfDocument();
  20. var tl = new TextLayout(72)
  21. {
  22. MaxWidth = doc.PageSize.Width,
  23. MaxHeight = doc.PageSize.Height,
  24. MarginAll = 72,
  25. };
  26. tl.DefaultFormat.FontSize = 7;
  27. var tfH = new TextFormat() { Font = StandardFonts.TimesBold, FontSize = 12 };
  28. var tfP = new TextFormat() { Font = StandardFonts.Times, FontSize = 11 };
  29.  
  30. // Loop through all system fonts,
  31. // list Unicode ranges provided by each font:
  32. foreach (var font in FontCollection.SystemFonts)
  33. {
  34. tl.AppendLine($"{font.FontFileName} [{font.FullFontName}] [{font.FontFamilyName}]", tfH);
  35. var shot = font.CreateFontTables(TableTag.OS2);
  36. tl.AppendLine(shot.GetUnicodeRanges(), tfP);
  37. tl.AppendLine();
  38. }
  39.  
  40. // Split and render TextLayout as shown in the PaginatedText sample:
  41. var to = new TextSplitOptions(tl)
  42. {
  43. MinLinesInFirstParagraph = 2,
  44. MinLinesInLastParagraph = 2
  45. };
  46. tl.PerformLayout(true);
  47. while (true)
  48. {
  49. var splitResult = tl.Split(to, out TextLayout rest);
  50. doc.Pages.Add().Graphics.DrawTextLayout(tl, PointF.Empty);
  51. if (splitResult != SplitResult.Split)
  52. break;
  53. tl = rest;
  54. }
  55.  
  56. // Done:
  57. doc.Save(stream);
  58. return doc.Pages.Count;
  59. }
  60. }
  61. }
  62.