added TryGetTableData to avoid Exceptions when a table doesn't exist
This commit is contained in:
Родитель
9ada7e6349
Коммит
641282f412
|
@ -140,13 +140,24 @@ namespace SkiaSharp
|
|||
IntPtr dataSize = SkiaApi.sk_typeface_get_table_size(Handle, tag);
|
||||
byte[] result = new byte[(int)dataSize];
|
||||
IntPtr r = SkiaApi.sk_typeface_get_table_data(Handle, tag, IntPtr.Zero, dataSize, result);
|
||||
if (r == IntPtr.Zero)
|
||||
{
|
||||
if (r == IntPtr.Zero) {
|
||||
throw new Exception("Unable to read the data table.");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool TryGetTableData(UInt32 tag, out byte[] tableData)
|
||||
{
|
||||
IntPtr dataSize = SkiaApi.sk_typeface_get_table_size(Handle, tag);
|
||||
tableData = new byte[(int)dataSize];
|
||||
IntPtr r = SkiaApi.sk_typeface_get_table_data(Handle, tag, IntPtr.Zero, dataSize, tableData);
|
||||
if (r == IntPtr.Zero) {
|
||||
tableData = null;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
2
skia
2
skia
|
@ -1 +1 @@
|
|||
Subproject commit ee4bd198dfe298511d0d07cec4109654ad68ce78
|
||||
Subproject commit 23031d670d5c62325f31f6fb3dcd5091b12f5777
|
|
@ -99,5 +99,34 @@ namespace SkiaSharp.Tests
|
|||
Assert.Throws<System.Exception>(() => typeface.GetTableData(8));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTryGetTableData()
|
||||
{
|
||||
using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "ReallyBigA.ttf")))
|
||||
{
|
||||
var tables = typeface.GetTableTags();
|
||||
for (int i = 0; i < tables.Length; i++) {
|
||||
byte[] tableData;
|
||||
Assert.IsTrue(typeface.TryGetTableData(tables[i], out tableData));
|
||||
Assert.AreEqual(ExpectedTableLengthsReallyBigAFont[i], tableData.Length, "Unexpected length for table: " + GetReadableTag(tables[i]));
|
||||
}
|
||||
|
||||
Assert.AreEqual(ExpectedTableDataPostReallyBigAFont, typeface.GetTableData(GetIntTag("post")));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InvalidTryGetTableData()
|
||||
{
|
||||
using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "Distortable.ttf")))
|
||||
{
|
||||
byte[] tableData;
|
||||
Assert.IsFalse(typeface.TryGetTableData(8, out tableData));
|
||||
Assert.IsNull(tableData);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче