Add int unicode overloads to be more consistent (#972)

This commit is contained in:
Benedikt Stebner 2019-10-24 20:57:48 +02:00 коммит произвёл Matthew Leibowitz
Родитель af74a6c5f8
Коммит 8a7e913dcc
5 изменённых файлов: 59 добавлений и 5 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -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);

Просмотреть файл

@ -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)

Просмотреть файл

@ -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()
{

Просмотреть файл

@ -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);
}
}
}