MaximumProfileClass.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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(FontStream stream)
  67. {
  68. stream.Position = this.Offset;
  69. max_profile.Version = stream.ReadUInt32(); // version number 0x00010000 for version 1.0.
  70. max_profile.numGlyphs = stream.ReadUInt16(); // The number of glyphs in the font.
  71. max_profile.maxPoints = stream.ReadUInt16(); // Maximum points in a non-composite glyph.
  72. max_profile.maxContours = stream.ReadUInt16(); // Maximum contours in a non-composite glyph.
  73. max_profile.maxCompositePoints = stream.ReadUInt16(); // Maximum points in a composite glyph.
  74. max_profile.maxCompositeContours = stream.ReadUInt16(); // Maximum contours in a composite glyph.
  75. max_profile.maxZones = stream.ReadUInt16(); // 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.
  76. max_profile.maxTwilightPoints = stream.ReadUInt16(); // Maximum points used in Z0.
  77. max_profile.maxStorage = stream.ReadUInt16(); // Number of Storage Area locations.
  78. max_profile.maxFunctionDefs = stream.ReadUInt16(); // Number of FDEFs.
  79. max_profile.maxInstructionDefs = stream.ReadUInt16(); // Number of IDEFs.
  80. max_profile.maxStackElements = stream.ReadUInt16(); // Maximum stack depth .
  81. max_profile.maxSizeOfInstructions = stream.ReadUInt16(); // Maximum byte count for glyph instructions.
  82. max_profile.maxComponentElements = stream.ReadUInt16(); // Maximum number of components referenced at “top level” for any composite glyph.
  83. max_profile.maxComponentDepth = stream.ReadUInt16(); // Maximum levels of recursion; 1 for simple components.
  84. }
  85. internal override uint Save(FontStream source_not_used, FontStream font, uint offset)
  86. {
  87. font.Position = offset;
  88. font.WriteUInt32(max_profile.Version); // public uint Version; // version number 0x00010000 for version 1.0.
  89. font.WriteUInt16(max_profile.numGlyphs); // public ushort numGlyphs; // The number of glyphs in the font.
  90. font.WriteUInt16(max_profile.numGlyphs); // public ushort maxPoints; // Maximum points in a non-composite glyph.
  91. font.WriteUInt16(max_profile.maxContours); // public ushort maxContours; // Maximum contours in a non-composite glyph.
  92. font.WriteUInt16(max_profile.maxCompositePoints); // public ushort maxCompositePoints; // Maximum points in a composite glyph.
  93. font.WriteUInt16(max_profile.maxCompositeContours); // public ushort maxCompositeContours; // Maximum contours in a composite glyph.
  94. font.WriteUInt16(max_profile.maxZones); // 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.
  95. font.WriteUInt16(max_profile.maxTwilightPoints); // public ushort maxTwilightPoints; // Maximum points used in Z0.
  96. font.WriteUInt16(max_profile.maxZones); // public ushort maxStorage; // Number of Storage Area locations.
  97. font.WriteUInt16(max_profile.maxFunctionDefs); // public ushort maxFunctionDefs; // Number of FDEFs.
  98. font.WriteUInt16(max_profile.maxInstructionDefs); // public ushort maxInstructionDefs; // Number of IDEFs.
  99. font.WriteUInt16(max_profile.maxStackElements); // public ushort maxStackElements; // Maximum stack depth .
  100. font.WriteUInt16(max_profile.maxSizeOfInstructions); // public ushort maxSizeOfInstructions; // Maximum byte count for glyph instructions.
  101. font.WriteUInt16(max_profile.maxComponentElements); // public ushort maxComponentElements; // Maximum number of components referenced at “top level” for any composite glyph.
  102. font.WriteUInt16(max_profile.maxComponentDepth); // public ushort maxComponentDepth; // Maximum levels of recursion; 1 for simple components.
  103. return offset + (uint)this.Length;
  104. }
  105. public MaximumProfileClass(TrueTypeTable src) : base(src)
  106. {
  107. if (src is MaximumProfileClass)
  108. this.max_profile = (src as MaximumProfileClass).max_profile;
  109. }
  110. public int GlyphsCount { get { return max_profile.numGlyphs; } set { max_profile.numGlyphs = (ushort)value; } }
  111. }
  112. }
  113. #pragma warning restore