diff --git a/binding/HarfBuzzSharp.Shared/Buffer.cs b/binding/HarfBuzzSharp.Shared/Buffer.cs index e78092eb2..a8cd8816b 100644 --- a/binding/HarfBuzzSharp.Shared/Buffer.cs +++ b/binding/HarfBuzzSharp.Shared/Buffer.cs @@ -85,6 +85,8 @@ namespace HarfBuzzSharp } } + public void Add (int codepoint, int cluster) => Add ((uint)codepoint, (uint)cluster); + public void Add (uint codepoint, uint cluster) { if (Length != 0 && ContentType != ContentType.Unicode) diff --git a/binding/HarfBuzzSharp.Shared/Script.cs b/binding/HarfBuzzSharp.Shared/Script.cs index d92e8a63f..3be6e24dd 100644 --- a/binding/HarfBuzzSharp.Shared/Script.cs +++ b/binding/HarfBuzzSharp.Shared/Script.cs @@ -17,6 +17,13 @@ namespace HarfBuzzSharp public static Script Parse (string str) => HarfBuzzApi.hb_script_from_string (str, -1); + public static bool TryParse (string str, out Script script) + { + script = Parse (str); + + return script != Unknown; + } + public override string ToString () => tag.ToString (); public static implicit operator uint (Script script) => script.tag; @@ -24,7 +31,7 @@ namespace HarfBuzzSharp public static implicit operator Script (uint tag) => new Script (tag); public override bool Equals (object obj) => - obj is Script script ? tag.Equals (script.tag) : false; + obj is Script script && tag.Equals (script.tag); public bool Equals (Script other) => tag.Equals (other.tag); diff --git a/binding/HarfBuzzSharp.Shared/UnicodeFunctions.cs b/binding/HarfBuzzSharp.Shared/UnicodeFunctions.cs index df8fe789b..620baaf62 100644 --- a/binding/HarfBuzzSharp.Shared/UnicodeFunctions.cs +++ b/binding/HarfBuzzSharp.Shared/UnicodeFunctions.cs @@ -36,18 +36,46 @@ namespace HarfBuzzSharp public void MakeImmutable () => HarfBuzzApi.hb_unicode_funcs_make_immutable (Handle); + public UnicodeCombiningClass GetCombiningClass (int unicode) => GetCombiningClass ((uint)unicode); + public UnicodeCombiningClass GetCombiningClass (uint unicode) => HarfBuzzApi.hb_unicode_combining_class (Handle, unicode); + public UnicodeGeneralCategory GetGeneralCategory (int unicode) => GetGeneralCategory ((uint)unicode); + public UnicodeGeneralCategory GetGeneralCategory (uint unicode) => HarfBuzzApi.hb_unicode_general_category (Handle, unicode); + public int GetMirroring (int unicode) => (int)GetMirroring ((uint)unicode); + public uint GetMirroring (uint unicode) => HarfBuzzApi.hb_unicode_mirroring (Handle, unicode); + public Script GetScript (int unicode) => GetScript ((uint)unicode); + public Script GetScript (uint unicode) => HarfBuzzApi.hb_unicode_script (Handle, unicode); + public bool TryCompose (int a, int b, out int ab) + { + var result = TryCompose ((uint)a, (uint)b, out var composed); + + ab = (int)composed; + + return result; + } + public bool TryCompose (uint a, uint b, out uint ab) => HarfBuzzApi.hb_unicode_compose (Handle, a, b, out ab); + public bool TryDecompose (int ab, out int a, out int b) + { + var result = TryDecompose ((uint)ab, out var decomposedA, out var decomposedB); + + a = (int)decomposedA; + + b = (int)decomposedB; + + return result; + } + public bool TryDecompose (uint ab, out uint a, out uint b) => HarfBuzzApi.hb_unicode_decompose (Handle, ab, out a, out b); public void SetCombiningClassDelegate (CombiningClassDelegate del, ReleaseDelegate destroy = null) diff --git a/tests/Tests/HBBufferTest.cs b/tests/Tests/HBBufferTest.cs index 1504c847a..95321cccf 100644 --- a/tests/Tests/HBBufferTest.cs +++ b/tests/Tests/HBBufferTest.cs @@ -60,6 +60,23 @@ namespace HarfBuzzSharp.Tests } } + [SkippableFact] + public void ShouldAdd() + { + using (var buffer = new Buffer()) + { + buffer.ContentType = ContentType.Unicode; + + buffer.Add(55, 1337); + + Assert.Equal(1, buffer.Length); + + Assert.Equal(55u, buffer.GlyphInfos[0].Codepoint); + + Assert.Equal(1337u, buffer.GlyphInfos[0].Cluster); + } + } + [SkippableFact] public void ShouldAddUtfByString() { diff --git a/tests/Tests/HBUnicodeFuncsTest.cs b/tests/Tests/HBUnicodeFuncsTest.cs index f5dcb2da7..225d442b3 100644 --- a/tests/Tests/HBUnicodeFuncsTest.cs +++ b/tests/Tests/HBUnicodeFuncsTest.cs @@ -107,7 +107,7 @@ namespace HarfBuzzSharp.Tests { unicodeFunctions.SetMirroringDelegate((f, u) => 1337); - Assert.Equal(1337u, unicodeFunctions.GetMirroring(0)); + Assert.Equal(1337, unicodeFunctions.GetMirroring(0)); } } @@ -124,7 +124,7 @@ namespace HarfBuzzSharp.Tests Assert.True(unicodeFunctions.TryCompose(1, 2, out var composed)); - Assert.Equal(1337u, composed); + Assert.Equal(1337, composed); } } @@ -142,8 +142,8 @@ namespace HarfBuzzSharp.Tests Assert.True(unicodeFunctions.TryDecompose(0, out var first, out var second)); - Assert.Equal(1337u, first); - Assert.Equal(7331u, second); + Assert.Equal(1337, first); + Assert.Equal(7331, second); } } }