PostScriptClass.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System.Runtime.InteropServices;
  2. #pragma warning disable CS3001, CS3002, CS3003, CS1591
  3. namespace FastReport.Fonts
  4. {
  5. /////////////////////////////////////////////////////////////////////////////////////////////////
  6. // PostScript table
  7. /////////////////////////////////////////////////////////////////////////////////////////////////
  8. public class PostScriptClass : TrueTypeTable
  9. {
  10. #region "Type definition"
  11. [StructLayout(LayoutKind.Explicit, Pack = 1)]
  12. public struct PostScript
  13. {
  14. [FieldOffset(0)]
  15. public uint Version; // version number 0x00010000 for version 1.0.
  16. [FieldOffset(4)]
  17. public int ItalicAngle; // Italic angle in counter-clockwise degrees from the vertical. Zero for upright text, negative for text that leans to the right (forward).
  18. [FieldOffset(8)]
  19. public short underlinePosition; // This is the suggested distance of the top of the underline from the baseline (negative values indicate below baseline).
  20. [FieldOffset(10)]
  21. public short underlineThickness; // Suggested values for the underline thickness.
  22. [FieldOffset(12)]
  23. public uint isFixedPitch; // Set to 0 if the font is proportionally spaced, non-zero if the font is not proportionally spaced (i.e. monospaced).
  24. [FieldOffset(16)]
  25. public uint minMemType42; // Minimum memory usage when an OpenType font is downloaded.
  26. [FieldOffset(20)]
  27. public uint maxMemType42; // Maximum memory usage when an OpenType font is downloaded.
  28. [FieldOffset(24)]
  29. public uint minMemType1; // Minimum memory usage when an OpenType font is downloaded as a Type 1 font.
  30. [FieldOffset(28)]
  31. public uint maxMemType1; // Maximum memory usage when an OpenType font is downloaded as a Type 1 font.
  32. }
  33. #endregion
  34. internal PostScript post_script;
  35. public bool IsItalic
  36. {
  37. get
  38. {
  39. return post_script.ItalicAngle != 0;
  40. }
  41. set
  42. {
  43. post_script.ItalicAngle = value ? post_script.ItalicAngle != 0 ? post_script.ItalicAngle : 1 : 0;
  44. }
  45. }
  46. public bool IsFixedPitch { get { return post_script.isFixedPitch != 0; } }
  47. private void ChangeEndian()
  48. {
  49. post_script.Version = SwapUInt32(post_script.Version);
  50. post_script.ItalicAngle = SwapInt32(post_script.ItalicAngle);
  51. post_script.underlinePosition = SwapInt16(post_script.underlinePosition);
  52. post_script.underlineThickness = SwapInt16(post_script.underlineThickness);
  53. post_script.isFixedPitch = SwapUInt32(post_script.isFixedPitch);
  54. post_script.minMemType42 = SwapUInt32(post_script.minMemType42);
  55. post_script.maxMemType42 = SwapUInt32(post_script.maxMemType42);
  56. post_script.minMemType1 = SwapUInt32(post_script.minMemType1);
  57. post_script.maxMemType1 = SwapUInt32(post_script.maxMemType1);
  58. }
  59. internal override void Load(FontStream stream)
  60. {
  61. stream.Seek(this.Offset, System.IO.SeekOrigin.Begin);
  62. post_script.Version = stream.ReadUInt32(); // version number 0x00010000 for version 1.0.
  63. post_script.ItalicAngle = stream.ReadInt32(); // Italic angle in counter-clockwise degrees from the vertical. Zero for upright text, negative for text that leans to the right (forward).
  64. post_script.underlinePosition = stream.ReadInt16(); // This is the suggested distance of the top of the underline from the baseline (negative values indicate below baseline).
  65. post_script.underlineThickness = stream.ReadInt16(); // Suggested values for the underline thickness.
  66. post_script.isFixedPitch = stream.ReadUInt32(); // Set to 0 if the font is proportionally spaced, non-zero if the font is not proportionally spaced (i.e. monospaced).
  67. post_script.minMemType42 = stream.ReadUInt32(); // Minimum memory usage when an OpenType font is downloaded.
  68. post_script.maxMemType42 = stream.ReadUInt32(); // Maximum memory usage when an OpenType font is downloaded.
  69. post_script.minMemType1 = stream.ReadUInt32(); // Minimum memory usage when an OpenType font is downloaded as a Type 1 font.
  70. post_script.maxMemType1 = stream.ReadUInt32(); // Maximum memory usage when an OpenType font is downloaded as a Type 1 font.
  71. }
  72. internal override uint Save(FontStream source_not_used, FontStream font, uint offset)
  73. {
  74. font.Position = offset;
  75. post_script.Version = 0x00030000;
  76. font.WriteUInt32(post_script.Version); // public uint Version; // version number 0x00010000 for version 1.0.
  77. font.WriteInt32(post_script.Version); // public int ItalicAngle; // Italic angle in counter-clockwise degrees from the vertical. Zero for upright text, negative for text that leans to the right (forward).
  78. font.WriteInt16(post_script.underlinePosition); // public short underlinePosition; // This is the suggested distance of the top of the underline from the baseline (negative values indicate below baseline).
  79. font.WriteInt16(post_script.underlineThickness); // public short underlineThickness; // Suggested values for the underline thickness.
  80. font.WriteUInt32(post_script.isFixedPitch); // public uint isFixedPitch; // Set to 0 if the font is proportionally spaced, non-zero if the font is not proportionally spaced (i.e. monospaced).
  81. font.WriteUInt32(post_script.minMemType42); // public uint minMemType42; // Minimum memory usage when an OpenType font is downloaded.
  82. font.WriteUInt32(post_script.maxMemType42); // public uint maxMemType42; // Maximum memory usage when an OpenType font is downloaded.
  83. font.WriteUInt32(post_script.minMemType1); // public uint minMemType1; // Minimum memory usage when an OpenType font is downloaded as a Type 1 font.
  84. font.WriteUInt32(post_script.maxMemType1); // public uint maxMemType1; // Maximum memory usage when an OpenType font is downloaded as a Type 1 font.
  85. return offset + (uint)this.Length;
  86. }
  87. public int ItalicAngle { get { return post_script.ItalicAngle; } }
  88. public PostScriptClass(TrueTypeTable src) : base(src) { }
  89. }
  90. }