Surrogates.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 renders a variety of interesting Unicode characters
  14. // including surrogate pairs. It also implicitly uses the automatic
  15. // font fallback (font substitution) feature built into DsPdf.
  16. // Note that this sample may produce different results on different
  17. // systems, as it relies on system-provided fallback fonts.
  18. // For a platform- and system-independent version of this sample see SurrogatesPort.
  19. // See also FontFallbacks.
  20. public class Surrogates
  21. {
  22. public int CreatePDF(Stream stream)
  23. {
  24. var doc = new GcPdfDocument();
  25. var g = doc.NewPage().Graphics;
  26. // For most of the 'interesting' chars demoed in this sample,
  27. // fallback fonts (see FontFallbacks) will be automatically used,
  28. // so we can just use a standard font for the captions:
  29. var font = StandardFonts.Helvetica;
  30.  
  31. var tf = new TextFormat() { Font = font, FontSize = 12 };
  32. var tf1 = new TextFormat(tf) { FontSize = 14 };
  33.  
  34. g.DrawString("Some Interesting Unicode Characters (relies on system fallbacks)",
  35. new TextFormat(tf) { Underline = true, FontSize = tf.FontSize + 2 },
  36. new RectangleF(0, 36, doc.PageSize.Width, float.MaxValue),
  37. TextAlignment.Center);
  38.  
  39. // Set up text insertion point and its advance function:
  40. var ip = new PointF(72, 54);
  41. Func<bool, PointF> nextIp = (caption_) => { ip.Y += caption_ ? 30 : 20; return ip; };
  42.  
  43. // Draw the strings:
  44. g.DrawString("Surrogate Pairs:", tf, nextIp(true));
  45. g.DrawString("\uD867\uDEDB \uD840\uDC0B \uD834\uDD1E \uD834\uDD61 \uD83D\uDC04", tf1, nextIp(false));
  46.  
  47. g.DrawString("Currency Symbols:", tf, nextIp(true));
  48. g.DrawString("\u0024 \u20A0 \u20A1 \u20A2 \u20A3 \u20A4 \u20AC \u20B9 \x20BD", tf1, nextIp(false));
  49.  
  50. g.DrawString("Mathematical Operators:", tf, nextIp(true));
  51. g.DrawString("\u221A \u222B \u2211 \u2210 \u2264 \u2265 \u2202 \u2208", tf1, nextIp(false));
  52.  
  53. g.DrawString("CJK Ideographs Extension A:", tf, nextIp(true));
  54. g.DrawString("\u3400 \u3401 \u3402 \u3403 \u3404 \u3405 \u3406 \u3407", tf1, nextIp(false));
  55.  
  56. g.DrawString("Letterlike Symbols:", tf, nextIp(true));
  57. g.DrawString("\u2110 \u2111 \u2112 \u2113 \u2114 \u2115 \u211B \u211C", tf1, nextIp(false));
  58.  
  59. g.DrawString("Private Use Area:", tf, nextIp(true));
  60. g.DrawString("\uE000 \uE001 \uE010 \uE011 \uE012 \uE013 \uE014 \uE015", tf1, nextIp(false));
  61.  
  62. g.DrawString("Arrows:", tf, nextIp(true));
  63. g.DrawString("\u2190 \u2191 \u2192 \u2193 \u21B0 \u21E6 \u21CB \u21A9", tf1, nextIp(false));
  64.  
  65. g.DrawString("Dingbats:", tf, nextIp(true));
  66. g.DrawString("\u2714 \u2717 \u275B \u275C \u2706 \u2707 \u2708 \u2709", tf1, nextIp(false));
  67.  
  68. g.DrawString("Braille Patterns:", tf, nextIp(true));
  69. g.DrawString("\u2830 \u2831 \u2832 \u2833 \u2834 \u2835 \u2836 \u2837", tf1, nextIp(false));
  70.  
  71. g.DrawString("Geometric Shapes:", tf, nextIp(true));
  72. g.DrawString("\u25D0 \u25D1 \u25D2 \u25D3 \u25A4 \u25F0 \u25BC \u25CE", tf1, nextIp(false));
  73.  
  74. g.DrawString("Latin Extended A:", tf, nextIp(true));
  75. g.DrawString("\u0100 \u0101 \u0102 \u0103 \u0104 \u0105 \u0106 \u0107", tf1, nextIp(false));
  76.  
  77. g.DrawString("Miscellaneous Symbols:", tf, nextIp(true));
  78. g.DrawString("\u2600 \u2601 \u2602 \u2603 \u2604 \u2605 \u2606 \u2607 \u2608 \u2609 \u2614 \u2615 \u26F0", tf1, nextIp(false));
  79.  
  80. // Done:
  81. doc.Save(stream);
  82. return doc.Pages.Count;
  83. }
  84. }
  85. }
  86.