From 80e75612541f66ec9bd4230bf44ff33ef64b0f62 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 6 Jul 2016 08:49:59 +0100 Subject: [PATCH 1/4] Implement Library.PropertySet on int type. Specifically, this is for making _lib.PropertySet("truetype", "interpreter-version", 35); _lib.PropertySet("truetype", "interpreter-version", 40); work. https://github.com/Robmaister/SharpFont/issues/82 --- Source/SharpFont/Library.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/SharpFont/Library.cs b/Source/SharpFont/Library.cs index 561cdfb..98affdc 100644 --- a/Source/SharpFont/Library.cs +++ b/Source/SharpFont/Library.cs @@ -435,6 +435,28 @@ public void PropertySet(string moduleName, string propertyName, IntPtr value) throw new FreeTypeException(err); } + /// + /// Set a property for a given module. + /// + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection + /// of the module's documentation. + /// + /// Note that only a few modules have properties. + /// A generic pointer to a variable or structure which gives the new value of the property. + /// The exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's + /// documentation. + public unsafe void PropertySet(string moduleName, string propertyName, int value) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + Error err = FT.FT_Property_Set(Reference, moduleName, propertyName, (IntPtr)(&value)); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + /// /// Set a property for a given module. /// From 32ca7b34b2e68dc593689a6264b993fa90d8ab23 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 7 Jul 2016 10:02:46 +0100 Subject: [PATCH 2/4] New additional FT_Property_Get() prototype which takes a ref int as parameter. I believe the original code [1] for PropertyGet with a "out IntPtr" last argument is wrong for value types like int. Whereas pointer types get the IntPtr filled in with by having the pointer to a pre-existing structure within Freetype, when FT_property_get() is called with &int as a final argument, the caller is expected to provide the storage which the pointer is pointed to. Hence "out IntPtr" will never work when FT_Property_Get expects int* , as the storage pointed to by the pointer never existed. This enhancement fixes: https://github.com/Robmaister/SharpFont/issues/82 (I tested this - it works for my purpose - doing: int b; _lib.PropertyGet("truetype", "interpreter-version", ref b); // b is 35 _lib.PropertySet("truetype", "interpreter-version", 40); _lib.PropertyGet("truetype", "interpreter-version", ref b); // b is now 40 ) Also note that [1] said "untested" - do not know if it is still true: [1] commit 0ad176fc9bbfe0ebe50722d4a16388c1dae964e1 Author: Robert Rouhani Date: Fri Jan 25 21:46:15 2013 -0500 Updated to FreeType 2.4.11, untested. --- Source/SharpFont/FT.Internal.cs | 3 +++ Source/SharpFont/Library.cs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Source/SharpFont/FT.Internal.cs b/Source/SharpFont/FT.Internal.cs index db755e8..84436ab 100644 --- a/Source/SharpFont/FT.Internal.cs +++ b/Source/SharpFont/FT.Internal.cs @@ -621,6 +621,9 @@ public static partial class FT [DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] internal static extern Error FT_Property_Get(IntPtr library, string module_name, string property_name, out IntPtr value); + [DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] + internal static extern Error FT_Property_Get(IntPtr library, string module_name, string property_name, ref int value); + [DllImport(FreetypeDll, CallingConvention = CallConvention)] internal static extern Error FT_Reference_Library(IntPtr library); diff --git a/Source/SharpFont/Library.cs b/Source/SharpFont/Library.cs index 98affdc..a38cdd5 100644 --- a/Source/SharpFont/Library.cs +++ b/Source/SharpFont/Library.cs @@ -547,6 +547,26 @@ public void PropertyGet(string moduleName, string propertyName, out IntPtr value throw new FreeTypeException(err); } + /// + /// Get a module's property value. + /// + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection of the + /// module's documentation. + /// A generic pointer to a variable or structure which gives the value of the property. The + /// exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's + /// documentation. + public void PropertyGet(string moduleName, string propertyName, ref int value) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + Error err = FT.FT_Property_Get(Reference, moduleName, propertyName, ref value); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + /// /// Get a module's property value. /// From b9ee15cdd07aa92720f4163c212b248cd0ee547e Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Sat, 9 Jul 2016 08:20:04 +0100 Subject: [PATCH 3/4] New FTMatrix constructor with a "FTMatrix(Fixed16Dot16 xx, Fixed16Dot16 xy, Fixed16Dot16 yx, Fixed16Dot16 yy)" signature https://github.com/Robmaister/SharpFont/issues/87 --- Source/SharpFont/FTMatrix.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Source/SharpFont/FTMatrix.cs b/Source/SharpFont/FTMatrix.cs index f724f95..85523ad 100644 --- a/Source/SharpFont/FTMatrix.cs +++ b/Source/SharpFont/FTMatrix.cs @@ -65,6 +65,22 @@ public FTMatrix(int xx, int xy, int yx, int yy) this.yy = (IntPtr)yy; } + /// + /// Initializes a new instance of the struct. + /// + /// Matrix coefficient XX. + /// Matrix coefficient XY. + /// Matrix coefficient YX. + /// Matrix coefficient YY. + public FTMatrix(Fixed16Dot16 xx, Fixed16Dot16 xy, Fixed16Dot16 yx, Fixed16Dot16 yy) + : this() + { + this.XX = xx; + this.XY = xy; + this.YX = yx; + this.YY = yy; + } + /// /// Initializes a new instance of the struct. /// From f671523be920850ad663ae8bf69a797658f06b4c Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 14 Jul 2016 13:55:40 +0100 Subject: [PATCH 4/4] passes FTMatrix by reference to the multiplication method. This fixes the problem, where passing by value does not update the source object: https://github.com/Robmaister/SharpFont/issues/88 --- Source/SharpFont/FTMatrix.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/SharpFont/FTMatrix.cs b/Source/SharpFont/FTMatrix.cs index 85523ad..c0b0a50 100644 --- a/Source/SharpFont/FTMatrix.cs +++ b/Source/SharpFont/FTMatrix.cs @@ -197,7 +197,7 @@ public Fixed16Dot16 YY /// /// A pointer to matrix ‘a’. /// A pointer to matrix ‘b’. - public static void Multiply(FTMatrix a, FTMatrix b) + public static void Multiply(ref FTMatrix a, ref FTMatrix b) { FT.FT_Matrix_Multiply(ref a, ref b); } @@ -209,7 +209,7 @@ public static void Multiply(FTMatrix a, FTMatrix b) /// The result is undefined if either ‘a’ or ‘b’ is zero. /// /// A pointer to matrix ‘b’. - public void Multiply(FTMatrix b) + public void Multiply(ref FTMatrix b) { FT.FT_Matrix_Multiply(ref this, ref b); }