Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load Svg from String #56

Closed
GW-FUB opened this issue May 11, 2020 · 2 comments
Closed

Load Svg from String #56

GW-FUB opened this issue May 11, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@GW-FUB
Copy link

GW-FUB commented May 11, 2020

I'm trying to load a generated svg image. Unfortunately Forms9Patch doesn't allow this; it just taskes ImageSources from local files.

So my workaround is to create a local temporary image and load from this. This works but I would like to read directly from a string.

Is there a possibility to load my SVG directly from memory?

@baskren baskren added the enhancement New feature or request label Jun 24, 2020
@baskren
Copy link
Owner

baskren commented Jun 24, 2020

@GW-FUB -

I've just added Forms9Patch.ImageSource.FromSvgText(string svgText) to the dev branch and it is passing all of the tests. Usage example:

           var svgString = $@"
<svg xmlns=""http://www.w3.org/2000/svg"" viewBox=""0 0 96 105"">
  <g fill=""#97C024"" stroke=""#97C024"" stroke-linejoin=""round"" stroke-linecap=""round"">
    <path d=""M14,40v24M81,40v24M38,68v24M57,68v24M28,42v31h39v-31z"" stroke-width=""12""/>
    <path d=""M32,5l5,10M64,5l-6,10"" stroke-width=""2""/>
  </g>
  <path d=""M22,35h51v10h-51zM22,33c0-31,51-31,51,0"" fill=""#97C024""/>
  <g fill=""#FFF"">
    <circle cx=""36"" cy=""22"" r=""2""/>
    <circle cx=""59"" cy=""22"" r=""2""/>
  </g>
</svg>
";

            var image = new Forms9Patch.Image
            {
                Source = Forms9Patch.ImageSource.FromSvgText(svgString),
                HeightRequest = 200,
                WidthRequest = 200,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center
            };

            Content = new StackLayout
            {
                Children = {
                    image,
                }
            };

gives the following results:

image

image

Note that Forms9Patch is using SkiaSharp.SVG for SVG rendering. It appears that SkiaSharp.SVG is not handling stroke-linecap correctly.

I'll be updating the NuGet in a day or two.

@baskren
Copy link
Owner

baskren commented Jun 29, 2020

Version 2.3 has been released. Please let me know if this does not fix this issue.

@baskren baskren closed this as completed Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants