HorizontalHeaderClass.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace FastReport.Fonts
  4. {
  5. /////////////////////////////////////////////////////////////////////////////////////////////////
  6. // HorizontalHeader table
  7. /////////////////////////////////////////////////////////////////////////////////////////////////
  8. class HorizontalHeaderClass : TrueTypeTable
  9. {
  10. #region "Type definition"
  11. [StructLayout(LayoutKind.Explicit, Pack = 1)]
  12. public struct HorizontalHeader
  13. {
  14. [FieldOffset(0)]
  15. public uint Version; // version number 0x00010000 for version 1.0.
  16. [FieldOffset(4)]
  17. public short Ascender; // Typographic ascent.
  18. [FieldOffset(6)]
  19. public short Descender; // Typographic descent.
  20. [FieldOffset(8)]
  21. public short LineGap; // Typographic line gap. Negative LineGap values are treated as zero in Windows 3.1, System 6, and System 7.
  22. [FieldOffset(10)]
  23. public ushort advanceWidthMax; // Maximum advance width value in ‘hmtx’ table.
  24. [FieldOffset(12)]
  25. public short minLeftSideBearing; // Minimum left sidebearing value in ‘hmtx’ table.
  26. [FieldOffset(14)]
  27. public short minRightSideBearing; // Minimum right sidebearing value; calculated as Min(aw - lsb - (xMax - xMin)).
  28. [FieldOffset(16)]
  29. public short xMaxExtent; // Max(lsb + (xMax - xMin)).
  30. [FieldOffset(18)]
  31. public short caretSlopeRise; // Used to calculate the slope of the cursor (rise/run); 1 for vertical.
  32. [FieldOffset(20)]
  33. public short caretSlopeRun; // 0 for vertical.
  34. [FieldOffset(22)]
  35. public short reserved1; // set to 0
  36. [FieldOffset(24)]
  37. public short reserved2; // set to 0
  38. [FieldOffset(26)]
  39. public short reserved3; // set to 0
  40. [FieldOffset(28)]
  41. public short reserved4; // set to 0
  42. [FieldOffset(30)]
  43. public short reserved5; // set to 0
  44. [FieldOffset(32)]
  45. public short metricDataFormat; // 0 for current format.
  46. [FieldOffset(34)]
  47. public ushort numberOfHMetrics; // Number of hMetric entries in ‘hmtx’ table; may be smaller than the total number of glyphs in the font.
  48. }
  49. #endregion
  50. private HorizontalHeader horizontal_header;
  51. internal override void Load(FontStream stream)
  52. {
  53. stream.Position = this.Offset;
  54. horizontal_header.Version = stream.ReadUInt32(); // version number 0x00010000 for version 1.0.
  55. horizontal_header.Ascender = stream.ReadInt16(); // Typographic ascent.
  56. horizontal_header.Descender = stream.ReadInt16(); // Typographic descent.
  57. horizontal_header.LineGap = stream.ReadInt16(); // Typographic line gap. Negative LineGap values are treated as zero in Windows 3.1, System 6, and System 7.
  58. horizontal_header.advanceWidthMax = stream.ReadUInt16(); // Maximum advance width value in ‘hmtx’ table.
  59. horizontal_header.minLeftSideBearing = stream.ReadInt16(); // Minimum left sidebearing value in ‘hmtx’ table.
  60. horizontal_header.minRightSideBearing = stream.ReadInt16(); // Minimum right sidebearing value; calculated as Min(aw - lsb - (xMax - xMin)).
  61. horizontal_header.xMaxExtent = stream.ReadInt16(); // Max(lsb + (xMax - xMin)).
  62. horizontal_header.caretSlopeRise = stream.ReadInt16(); // Used to calculate the slope of the cursor (rise/run); 1 for vertical.
  63. horizontal_header.caretSlopeRun = stream.ReadInt16(); // 0 for vertical.
  64. horizontal_header.reserved1 = stream.ReadInt16(); // set to 0
  65. horizontal_header.reserved2 = stream.ReadInt16(); // set to 0
  66. horizontal_header.reserved3 = stream.ReadInt16(); // set to 0
  67. horizontal_header.reserved4 = stream.ReadInt16(); // set to 0
  68. horizontal_header.reserved5 = stream.ReadInt16(); // set to 0
  69. horizontal_header.metricDataFormat = stream.ReadInt16(); // 0 for current format.
  70. horizontal_header.numberOfHMetrics = stream.ReadUInt16(); // Number of hMetric entries in ‘hmtx’ table; may be smaller than the total number of glyphs in the font.
  71. }
  72. internal override uint Save(FontStream source_not_used, FontStream stream, uint offset)
  73. {
  74. stream.Position = offset;
  75. stream.WriteUInt32(horizontal_header.Version); // version number 0x00010000 for version 1.0.
  76. stream.WriteInt16(horizontal_header.Ascender); // Typographic ascent.
  77. stream.WriteInt16(horizontal_header.Descender); // Typographic descent.
  78. stream.WriteInt16(horizontal_header.LineGap); // Typographic line gap. Negative LineGap values are treated as zero in Windows 3.1, System 6, and System 7.
  79. stream.WriteUInt16(horizontal_header.advanceWidthMax); // Maximum advance width value in ‘hmtx’ table.
  80. stream.WriteInt16(horizontal_header.minLeftSideBearing);// Minimum left sidebearing value in ‘hmtx’ table.
  81. stream.WriteInt16(horizontal_header.minRightSideBearing);// Minimum right sidebearing value; calculated as Min(aw - lsb - (xMax - xMin)).
  82. stream.WriteInt16(horizontal_header.xMaxExtent); // Max(lsb + (xMax - xMin)).
  83. stream.WriteInt16(horizontal_header.caretSlopeRise); // Used to calculate the slope of the cursor (rise/run); 1 for vertical.
  84. stream.WriteInt16(horizontal_header.caretSlopeRun); // 0 for vertical.
  85. stream.WriteInt16(horizontal_header.reserved1); // set to 0
  86. stream.WriteInt16(horizontal_header.reserved2); // set to 0
  87. stream.WriteInt16(horizontal_header.reserved3); // set to 0
  88. stream.WriteInt16(horizontal_header.reserved4); // set to 0
  89. stream.WriteInt16(horizontal_header.reserved5); // set to 0
  90. stream.WriteInt16(horizontal_header.metricDataFormat); // 0 for current format.
  91. stream.WriteUInt16(horizontal_header.numberOfHMetrics); // Number of hMetric entries in ‘hmtx’ table; may be smaller than the total number of glyphs in the font.
  92. return offset + (uint)this.Length;
  93. }
  94. public short Ascender { get { return horizontal_header.Ascender; } }
  95. public short Descender { get { return horizontal_header.Descender; } }
  96. public short LineGap { get { return horizontal_header.LineGap; } }
  97. public ushort MaxWidth { get { return horizontal_header.advanceWidthMax; } }
  98. public short MinLeftSideBearing { get { return horizontal_header.minLeftSideBearing; } }
  99. public ushort NumberOfHMetrics { get { return horizontal_header.numberOfHMetrics; } set { horizontal_header.numberOfHMetrics = value; } }
  100. public HorizontalHeaderClass(TrueTypeTable src) : base(src)
  101. {
  102. }
  103. }
  104. }