PostScriptClass.cs 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Runtime.InteropServices;
  3. #pragma warning disable CS3001, CS3002, CS3003, CS1591
  4. namespace FastReport.Fonts
  5. {
  6. /////////////////////////////////////////////////////////////////////////////////////////////////
  7. // PostScript table
  8. /////////////////////////////////////////////////////////////////////////////////////////////////
  9. public class PostScriptClass : TrueTypeTable
  10. {
  11. #region "Type definition"
  12. [StructLayout(LayoutKind.Explicit, Pack = 1)]
  13. public struct PostScript
  14. {
  15. [FieldOffset(0)]
  16. public uint Version; // version number 0x00010000 for version 1.0.
  17. [FieldOffset(4)]
  18. 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).
  19. [FieldOffset(8)]
  20. public short underlinePosition; // This is the suggested distance of the top of the underline from the baseline (negative values indicate below baseline).
  21. [FieldOffset(10)]
  22. public short underlineThickness; // Suggested values for the underline thickness.
  23. [FieldOffset(12)]
  24. public uint isFixedPitch; // Set to 0 if the font is proportionally spaced, non-zero if the font is not proportionally spaced (i.e. monospaced).
  25. [FieldOffset(16)]
  26. public uint minMemType42; // Minimum memory usage when an OpenType font is downloaded.
  27. [FieldOffset(20)]
  28. public uint maxMemType42; // Maximum memory usage when an OpenType font is downloaded.
  29. [FieldOffset(24)]
  30. public uint minMemType1; // Minimum memory usage when an OpenType font is downloaded as a Type 1 font.
  31. [FieldOffset(28)]
  32. public uint maxMemType1; // Maximum memory usage when an OpenType font is downloaded as a Type 1 font.
  33. }
  34. #endregion
  35. internal PostScript post_script;
  36. public bool IsItalic
  37. {
  38. get
  39. {
  40. return post_script.ItalicAngle != 0;
  41. }
  42. set
  43. {
  44. post_script.ItalicAngle = value ? post_script.ItalicAngle != 0 ? post_script.ItalicAngle : 1 : 0;
  45. }
  46. }
  47. public bool IsFixedPitch { get { return post_script.isFixedPitch != 0; } }
  48. private void ChangeEndian()
  49. {
  50. post_script.Version = SwapUInt32(post_script.Version);
  51. post_script.ItalicAngle = SwapInt32(post_script.ItalicAngle);
  52. post_script.underlinePosition = SwapInt16(post_script.underlinePosition);
  53. post_script.underlineThickness = SwapInt16(post_script.underlineThickness);
  54. post_script.isFixedPitch = SwapUInt32(post_script.isFixedPitch);
  55. post_script.minMemType42 = SwapUInt32(post_script.minMemType42);
  56. post_script.maxMemType42 = SwapUInt32(post_script.maxMemType42);
  57. post_script.minMemType1 = SwapUInt32(post_script.minMemType1);
  58. post_script.maxMemType1 = SwapUInt32(post_script.maxMemType1);
  59. }
  60. internal override void Load(IntPtr font)
  61. {
  62. IntPtr post_script_ptr = Increment(font, (int)this.Offset);
  63. post_script = (PostScript)Marshal.PtrToStructure(post_script_ptr, typeof(PostScript));
  64. ChangeEndian();
  65. }
  66. internal override uint Save(IntPtr font, uint offset)
  67. {
  68. this.Offset = offset;
  69. post_script.Version = 0x00030000;
  70. if (this.Length != (uint)Marshal.SizeOf(typeof(PostScript)))
  71. throw new Exception("Unexpected format of PostScript table ");
  72. ChangeEndian();
  73. IntPtr post_script_ptr = Increment(font, (int)offset);
  74. Marshal.StructureToPtr(post_script, post_script_ptr, false);
  75. ChangeEndian();
  76. return offset + (uint)this.Length;
  77. }
  78. public int ItalicAngle { get { return post_script.ItalicAngle; } }
  79. public PostScriptClass(TrueTypeTable src) : base(src) { }
  80. }
  81. }