From a79bbbaa6aa1ae4fe14f0617adb64478673956ea Mon Sep 17 00:00:00 2001 From: "H. Utku Maden" Date: Sat, 29 Jun 2024 14:27:29 +0300 Subject: [PATCH] Explicitly set some structure layouts. --- Structures.cs | 113 ++++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 55 deletions(-) diff --git a/Structures.cs b/Structures.cs index 0dcc1f3..2f2594a 100644 --- a/Structures.cs +++ b/Structures.cs @@ -40,32 +40,33 @@ namespace ReFuel.FreeType public long YMax; } + [StructLayout(LayoutKind.Explicit, Size = 248)] internal struct FTFaceInternal { - public long NumberOfFaces; - public long FaceIndex; - public long FaceFlags; - public long StyleFlags; - public long NumberOfGlyphs; - public IntPtr FamilyName; - public IntPtr StyleName; - public int NumberOfFixedSizes; - public IntPtr AvailableSizes; - public int NumberOfCharMaps; - public IntPtr Charmaps; - public FTGeneric Generic; - public FTBox BoundingBox; - public ushort UnitsPerEm; - public short Ascender; - public short Descender; - public short Height; - public short MaxAdvanceWidth; - public short MaxAdvanceHeight; - public short UnderlinePosition; - public short UnderlineThickness; - public FTGlyphSlot Glyph; - public IntPtr Size; - public IntPtr Charmap; + [FieldOffset(0)] public long NumberOfFaces; + [FieldOffset(8)] public long FaceIndex; + [FieldOffset(16)] public long FaceFlags; + [FieldOffset(24)] public long StyleFlags; + [FieldOffset(32)] public long NumberOfGlyphs; + [FieldOffset(40)] public IntPtr FamilyName; + [FieldOffset(48)] public IntPtr StyleName; + [FieldOffset(56)] public int NumberOfFixedSizes; + [FieldOffset(64)] public IntPtr AvailableSizes; + [FieldOffset(72)] public int NumberOfCharMaps; + [FieldOffset(80)] public IntPtr Charmaps; + [FieldOffset(88)] public FTGeneric Generic; + [FieldOffset(104)] public FTBox BoundingBox; + [FieldOffset(136)] public ushort UnitsPerEm; + [FieldOffset(138)] public short Ascender; + [FieldOffset(140)] public short Descender; + [FieldOffset(142)] public short Height; + [FieldOffset(144)] public short MaxAdvanceWidth; + [FieldOffset(146)] public short MaxAdvanceHeight; + [FieldOffset(148)] public short UnderlinePosition; + [FieldOffset(150)] public short UnderlineThickness; + [FieldOffset(152)] public FTGlyphSlot Glyph; + [FieldOffset(160)] public IntPtr Size; + [FieldOffset(168)] public IntPtr Charmap; // Rest of the struct is private to implementation. } @@ -82,52 +83,54 @@ namespace ReFuel.FreeType public long Y; } + [StructLayout(LayoutKind.Explicit)] public struct FTBitmap { - public uint Rows; - public uint Width; - public int Pitch; - public IntPtr Buffer; - public ushort NumberOfGrays; - public byte PixelMode; - public byte PaletteMode; - public IntPtr Palette; + [FieldOffset(0)] public uint Rows; + [FieldOffset(4)] public uint Width; + [FieldOffset(8)] public int Pitch; + [FieldOffset(16)] public IntPtr Buffer; + [FieldOffset(24)] public ushort NumberOfGrays; + [FieldOffset(26)] public byte PixelMode; + [FieldOffset(27)] public byte PaletteMode; + [FieldOffset(32)] public IntPtr Palette; } public struct FTOutline { public short NumberOfContours; - public short NumberOfPoints; + public short NumberOfPoints; public IntPtr Points; public IntPtr Tags; public IntPtr Contours; public int Flags; } + [StructLayout(LayoutKind.Explicit, Size = 296)] internal struct FTGlyphSlotInternal { - public FTLibrary Library; - public FTFace Face; - public FTGlyphSlot Next; - public uint GlyphIndex; - public FTGeneric Generic; - public FTGlyphMetrics Metrics; - public int LinearHorizontalAdvance; - public int LinearVerticalAdvance; - public FTVector Advance; - public int Format; - public FTBitmap Bitmap; - public int BitmapLeft; - public int BitmapTop; - public FTOutline Outline; - public uint NumberOfSubGlyphs; - public IntPtr SubGlyphs; - public IntPtr ControlData; - public long ControlLength; - public long LsbDelta; - public long RsbDelta; - public IntPtr Other; - public IntPtr Internal; + [FieldOffset(0)] public FTLibrary Library; + [FieldOffset(8)] public FTFace Face; + [FieldOffset(16)] public FTGlyphSlot Next; + [FieldOffset(24)] public uint GlyphIndex; + [FieldOffset(32)] public FTGeneric Generic; + [FieldOffset(48)] public FTGlyphMetrics Metrics; + [FieldOffset(112)] public int LinearHorizontalAdvance; + [FieldOffset(116)] public int LinearVerticalAdvance; + [FieldOffset(120)] public FTVector Advance; + [FieldOffset(136)] public int Format; + [FieldOffset(144)] public FTBitmap Bitmap; + [FieldOffset(184)] public int BitmapLeft; + [FieldOffset(188)] public int BitmapTop; + [FieldOffset(192)] public FTOutline Outline; + [FieldOffset(232)] public uint NumberOfSubGlyphs; + [FieldOffset(240)] public IntPtr SubGlyphs; + [FieldOffset(248)] public IntPtr ControlData; + [FieldOffset(256)] public long ControlLength; + [FieldOffset(264)] public long LsbDelta; + [FieldOffset(272)] public long RsbDelta; + [FieldOffset(280)] public IntPtr Other; + [FieldOffset(288)] public IntPtr Internal; } public unsafe struct FTGlyphSlot