123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Runtime.InteropServices;
- namespace FastReport.Fonts
- {
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // HorizontalHeader table
- /////////////////////////////////////////////////////////////////////////////////////////////////
- class HorizontalHeaderClass : TrueTypeTable
- {
- #region "Type definition"
- [StructLayout(LayoutKind.Explicit, Pack = 1)]
- public struct HorizontalHeader
- {
- [FieldOffset(0)]
- public uint Version; // version number 0x00010000 for version 1.0.
- [FieldOffset(4)]
- public short Ascender; // Typographic ascent.
- [FieldOffset(6)]
- public short Descender; // Typographic descent.
- [FieldOffset(8)]
- public short LineGap; // Typographic line gap. Negative LineGap values are treated as zero in Windows 3.1, System 6, and System 7.
- [FieldOffset(10)]
- public ushort advanceWidthMax; // Maximum advance width value in ‘hmtx’ table.
- [FieldOffset(12)]
- public short minLeftSideBearing; // Minimum left sidebearing value in ‘hmtx’ table.
- [FieldOffset(14)]
- public short minRightSideBearing; // Minimum right sidebearing value; calculated as Min(aw - lsb - (xMax - xMin)).
- [FieldOffset(16)]
- public short xMaxExtent; // Max(lsb + (xMax - xMin)).
- [FieldOffset(18)]
- public short caretSlopeRise; // Used to calculate the slope of the cursor (rise/run); 1 for vertical.
- [FieldOffset(20)]
- public short caretSlopeRun; // 0 for vertical.
- [FieldOffset(22)]
- public short reserved1; // set to 0
- [FieldOffset(24)]
- public short reserved2; // set to 0
- [FieldOffset(26)]
- public short reserved3; // set to 0
- [FieldOffset(28)]
- public short reserved4; // set to 0
- [FieldOffset(30)]
- public short reserved5; // set to 0
- [FieldOffset(32)]
- public short metricDataFormat; // 0 for current format.
- [FieldOffset(34)]
- public ushort numberOfHMetrics; // Number of hMetric entries in ‘hmtx’ table; may be smaller than the total number of glyphs in the font.
- }
- #endregion
- private HorizontalHeader horizontal_header;
- internal override void Load(FontStream stream)
- {
- stream.Position = this.Offset;
- horizontal_header.Version = stream.ReadUInt32(); // version number 0x00010000 for version 1.0.
- horizontal_header.Ascender = stream.ReadInt16(); // Typographic ascent.
- horizontal_header.Descender = stream.ReadInt16(); // Typographic descent.
- horizontal_header.LineGap = stream.ReadInt16(); // Typographic line gap. Negative LineGap values are treated as zero in Windows 3.1, System 6, and System 7.
- horizontal_header.advanceWidthMax = stream.ReadUInt16(); // Maximum advance width value in ‘hmtx’ table.
- horizontal_header.minLeftSideBearing = stream.ReadInt16(); // Minimum left sidebearing value in ‘hmtx’ table.
- horizontal_header.minRightSideBearing = stream.ReadInt16(); // Minimum right sidebearing value; calculated as Min(aw - lsb - (xMax - xMin)).
- horizontal_header.xMaxExtent = stream.ReadInt16(); // Max(lsb + (xMax - xMin)).
- horizontal_header.caretSlopeRise = stream.ReadInt16(); // Used to calculate the slope of the cursor (rise/run); 1 for vertical.
- horizontal_header.caretSlopeRun = stream.ReadInt16(); // 0 for vertical.
- horizontal_header.reserved1 = stream.ReadInt16(); // set to 0
- horizontal_header.reserved2 = stream.ReadInt16(); // set to 0
- horizontal_header.reserved3 = stream.ReadInt16(); // set to 0
- horizontal_header.reserved4 = stream.ReadInt16(); // set to 0
- horizontal_header.reserved5 = stream.ReadInt16(); // set to 0
- horizontal_header.metricDataFormat = stream.ReadInt16(); // 0 for current format.
- horizontal_header.numberOfHMetrics = stream.ReadUInt16(); // Number of hMetric entries in ‘hmtx’ table; may be smaller than the total number of glyphs in the font.
- }
- internal override uint Save(FontStream source_not_used, FontStream stream, uint offset)
- {
- stream.Position = offset;
- stream.WriteUInt32(horizontal_header.Version); // version number 0x00010000 for version 1.0.
- stream.WriteInt16(horizontal_header.Ascender); // Typographic ascent.
- stream.WriteInt16(horizontal_header.Descender); // Typographic descent.
- stream.WriteInt16(horizontal_header.LineGap); // Typographic line gap. Negative LineGap values are treated as zero in Windows 3.1, System 6, and System 7.
- stream.WriteUInt16(horizontal_header.advanceWidthMax); // Maximum advance width value in ‘hmtx’ table.
- stream.WriteInt16(horizontal_header.minLeftSideBearing);// Minimum left sidebearing value in ‘hmtx’ table.
- stream.WriteInt16(horizontal_header.minRightSideBearing);// Minimum right sidebearing value; calculated as Min(aw - lsb - (xMax - xMin)).
- stream.WriteInt16(horizontal_header.xMaxExtent); // Max(lsb + (xMax - xMin)).
- stream.WriteInt16(horizontal_header.caretSlopeRise); // Used to calculate the slope of the cursor (rise/run); 1 for vertical.
- stream.WriteInt16(horizontal_header.caretSlopeRun); // 0 for vertical.
- stream.WriteInt16(horizontal_header.reserved1); // set to 0
- stream.WriteInt16(horizontal_header.reserved2); // set to 0
- stream.WriteInt16(horizontal_header.reserved3); // set to 0
- stream.WriteInt16(horizontal_header.reserved4); // set to 0
- stream.WriteInt16(horizontal_header.reserved5); // set to 0
- stream.WriteInt16(horizontal_header.metricDataFormat); // 0 for current format.
- stream.WriteUInt16(horizontal_header.numberOfHMetrics); // Number of hMetric entries in ‘hmtx’ table; may be smaller than the total number of glyphs in the font.
- return offset + (uint)this.Length;
- }
- public short Ascender { get { return horizontal_header.Ascender; } }
- public short Descender { get { return horizontal_header.Descender; } }
- public short LineGap { get { return horizontal_header.LineGap; } }
- public ushort MaxWidth { get { return horizontal_header.advanceWidthMax; } }
- public short MinLeftSideBearing { get { return horizontal_header.minLeftSideBearing; } }
- public ushort NumberOfHMetrics { get { return horizontal_header.numberOfHMetrics; } set { horizontal_header.numberOfHMetrics = value; } }
- public HorizontalHeaderClass(TrueTypeTable src) : base(src)
- {
- }
- }
- }
|