Return null if the file does not exist when opening a stream
This commit is contained in:
Родитель
5ac982c298
Коммит
88aa6ab08d
|
@ -92,7 +92,11 @@ namespace SkiaSharp
|
|||
throw new ArgumentException ("The filename cannot be empty.", nameof (filename));
|
||||
|
||||
using (var stream = SKFileStream.OpenStream (filename)) {
|
||||
return Create (stream);
|
||||
if (stream == null) {
|
||||
return null;
|
||||
} else {
|
||||
return Create (stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -216,6 +216,9 @@ namespace SkiaSharp
|
|||
|
||||
public static SKStreamAsset OpenStream (string path)
|
||||
{
|
||||
if (!File.Exists (path)) {
|
||||
return null;
|
||||
}
|
||||
if (!IsPathSupported (path)) {
|
||||
return new SKManagedStream (File.OpenRead (path), true);
|
||||
} else {
|
||||
|
|
|
@ -56,7 +56,11 @@ namespace SkiaSharp
|
|||
if (path == null)
|
||||
throw new ArgumentNullException (nameof (path));
|
||||
using (var stream = SKFileStream.OpenStream (path)) {
|
||||
return FromStream (stream, index);
|
||||
if (stream == null) {
|
||||
return null;
|
||||
} else {
|
||||
return FromStream (stream, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace SkiaSharp.Tests
|
|||
};
|
||||
|
||||
[SkippableFact]
|
||||
public void NullInWrongFileName()
|
||||
public void NullWithMissingFile()
|
||||
{
|
||||
Assert.Null(SKTypeface.FromFile(Path.Combine(PathToFonts, "font that doesn't exist.ttf")));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче