Make sure we can create a typeface from non-seekable streams
This commit is contained in:
Родитель
cae3758edd
Коммит
6920c9390d
|
@ -62,6 +62,21 @@ namespace SkiaSharp
|
|||
{
|
||||
if (stream == null)
|
||||
throw new ArgumentNullException (nameof (stream));
|
||||
|
||||
if (!stream.CanSeek)
|
||||
{
|
||||
var fontStream = new MemoryStream ();
|
||||
stream.CopyTo (fontStream);
|
||||
fontStream.Flush ();
|
||||
fontStream.Position = 0;
|
||||
|
||||
stream.Dispose ();
|
||||
stream = null;
|
||||
|
||||
stream = fontStream;
|
||||
fontStream = null;
|
||||
}
|
||||
|
||||
return FromStream (new SKManagedStream (stream, true), index);
|
||||
}
|
||||
|
||||
|
@ -74,6 +89,11 @@ namespace SkiaSharp
|
|||
return typeface;
|
||||
}
|
||||
|
||||
public static SKTypeface FromData (SKData data, int index = 0)
|
||||
{
|
||||
return SKTypeface.FromStream (new SKMemoryStream (data), index);
|
||||
}
|
||||
|
||||
public int CountGlyphs (string str)
|
||||
{
|
||||
if (str == null)
|
||||
|
|
|
@ -142,5 +142,26 @@ namespace SkiaSharp.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanReadData()
|
||||
{
|
||||
var bytes = File.ReadAllBytes(Path.Combine(PathToFonts, "Distortable.ttf"));
|
||||
using (var data = SKData.CreateCopy(bytes))
|
||||
using (var typeface = SKTypeface.FromData(data))
|
||||
{
|
||||
Assert.IsNotNull(typeface);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanReadNonSeekableStream()
|
||||
{
|
||||
using (var stream = File.OpenRead(Path.Combine(PathToFonts, "Distortable.ttf")))
|
||||
using (var nonSeekable = new NonSeekableReadOnlyStream(stream))
|
||||
using (var typeface = SKTypeface.FromStream(nonSeekable))
|
||||
{
|
||||
Assert.IsNotNull(typeface);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче