-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
105 changed files
with
3,302 additions
and
3,396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Reader Copilot. All rights reserved. | ||
// <auto-generated /> | ||
|
||
using Microsoft.UI.Xaml.Media.Imaging; | ||
|
||
namespace Bili.Copilot.App.Controls.Markdown; | ||
|
||
internal class DefaultSVGRenderer : ISVGRenderer | ||
{ | ||
public async Task<Image> SvgToImage(string svgString) | ||
{ | ||
var svgImageSource = new SvgImageSource(); | ||
var image = new Image(); | ||
|
||
// Create a MemoryStream object and write the SVG string to it | ||
using (var memoryStream = new MemoryStream()) | ||
using (var streamWriter = new StreamWriter(memoryStream)) | ||
{ | ||
await streamWriter.WriteAsync(svgString); | ||
await streamWriter.FlushAsync(); | ||
|
||
// Rewind the MemoryStream | ||
memoryStream.Position = 0; | ||
|
||
// Load the SVG from the MemoryStream | ||
await svgImageSource.SetSourceAsync(memoryStream.AsRandomAccessStream()); | ||
} | ||
|
||
// Set the Source property of the Image control to the SvgImageSource object | ||
image.Source = svgImageSource; | ||
var size = Extensions.GetSvgSize(svgString); | ||
if (size.Width != 0) | ||
{ | ||
image.Width = size.Width; | ||
} | ||
|
||
if (size.Height != 0) | ||
{ | ||
image.Height = size.Height; | ||
} | ||
|
||
return image; | ||
} | ||
} |
Oops, something went wrong.