MaximumProfileClass.cs 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Runtime.InteropServices;
  3. #pragma warning disable CS3001, CS3002, CS3003, CS1591
  4. namespace FastReport.Fonts
  5. {
  6. /// <summary>
  7. /// MaximumProfile table
  8. /// </summary>
  9. public class MaximumProfileClass : TrueTypeTable
  10. {
  11. #region "Structure definition"
  12. [StructLayout(LayoutKind.Explicit, Pack = 1)]
  13. public struct MaximumProfile
  14. {
  15. [FieldOffset(0)]
  16. public uint Version; // version number 0x00010000 for version 1.0.
  17. [FieldOffset(4)]
  18. public ushort numGlyphs; // The number of glyphs in the font.
  19. [FieldOffset(6)]
  20. public ushort maxPoints; // Maximum points in a non-composite glyph.
  21. [FieldOffset(8)]
  22. public ushort maxContours; // Maximum contours in a non-composite glyph.
  23. [FieldOffset(10)]
  24. public ushort maxCompositePoints; // Maximum points in a composite glyph.
  25. [FieldOffset(12)]
  26. public ushort maxCompositeContours; // Maximum contours in a composite glyph.
  27. [FieldOffset(14)]
  28. public ushort maxZones; // 1 if instructions do not use the twilight zone (Z0), or 2 if instructions do use Z0; should be set to 2 in most cases.
  29. [FieldOffset(16)]
  30. public ushort maxTwilightPoints; // Maximum points used in Z0.
  31. [FieldOffset(18)]
  32. public ushort maxStorage; // Number of Storage Area locations.
  33. [FieldOffset(20)]
  34. public ushort maxFunctionDefs; // Number of FDEFs.
  35. [FieldOffset(22)]
  36. public ushort maxInstructionDefs; // Number of IDEFs.
  37. [FieldOffset(24)]
  38. public ushort maxStackElements; // Maximum stack depth .
  39. [FieldOffset(26)]
  40. public ushort maxSizeOfInstructions; // Maximum byte count for glyph instructions.
  41. [FieldOffset(28)]
  42. public ushort maxComponentElements; // Maximum number of components referenced at “top level” for any composite glyph.
  43. [FieldOffset(30)]
  44. public ushort maxComponentDepth; // Maximum levels of recursion; 1 for simple components.
  45. }
  46. #endregion
  47. private MaximumProfile max_profile;
  48. private void ChangeEndian()
  49. {
  50. max_profile.Version = SwapUInt32(max_profile.Version);
  51. max_profile.numGlyphs = SwapUInt16(max_profile.numGlyphs);
  52. max_profile.maxPoints = SwapUInt16(max_profile.maxPoints);
  53. max_profile.maxContours = SwapUInt16(max_profile.maxContours);
  54. max_profile.maxCompositePoints = SwapUInt16(max_profile.maxCompositePoints);
  55. max_profile.maxCompositeContours = SwapUInt16(max_profile.maxCompositeContours);
  56. max_profile.maxZones = SwapUInt16(max_profile.maxZones);
  57. max_profile.maxTwilightPoints = SwapUInt16(max_profile.maxTwilightPoints);
  58. max_profile.maxStorage = SwapUInt16(max_profile.maxStorage);
  59. max_profile.maxFunctionDefs = SwapUInt16(max_profile.maxFunctionDefs);
  60. max_profile.maxInstructionDefs = SwapUInt16(max_profile.maxInstructionDefs);
  61. max_profile.maxStackElements = SwapUInt16(max_profile.maxStackElements);
  62. max_profile.maxSizeOfInstructions = SwapUInt16(max_profile.maxSizeOfInstructions);
  63. max_profile.maxComponentElements = SwapUInt16(max_profile.maxComponentElements);
  64. max_profile.maxComponentDepth = SwapUInt16(max_profile.maxComponentDepth);
  65. }
  66. internal override void Load(IntPtr font)
  67. {
  68. IntPtr mprofile_ptr = Increment(font, (int)this.Offset);
  69. max_profile = (MaximumProfile)Marshal.PtrToStructure(mprofile_ptr, typeof(MaximumProfile));
  70. ChangeEndian();
  71. }
  72. internal override uint Save(IntPtr font, uint offset)
  73. {
  74. this.Offset = offset;
  75. ChangeEndian();
  76. IntPtr profile_ptr = Increment(font, (int)offset);
  77. Marshal.StructureToPtr(max_profile, profile_ptr, false);
  78. ChangeEndian();
  79. return offset + (uint)this.Length;
  80. }
  81. public MaximumProfileClass(TrueTypeTable src) : base(src) { }
  82. public int GlyphsCount { get { return max_profile.numGlyphs; } set { max_profile.numGlyphs = (ushort)value; } }
  83. }
  84. }
  85. #pragma warning restore