Comments (7)
@JonathanDDuncan It is doable (for my application, I have done it). But it's not simple.
Essentially you'll need to create a separate utility class that parses the SVG file (or whatever other file contains your in-line styles), finds places where "@font-face { whatever}" appears in it, and where it finds src: url('...') it reads that source data and constructs an SKTypeFace from it, and adds it to a Dictionary<string,SKTypeFace>, that lets you obtain the typeface you want, based on its font-family name.
Then you define a 'provider' class that implements ITypeFaceProvider, and in your code you construct an instance of your provider class., and register it by calling SKSvgSettings.s_typefaceProviders.Insert(0, myProviderInstance).
Your provider class has to implement a method FromFamilyName(string name, SKFontStyleWeight wt, SKFontStyleWidth dw, SKFontStyleSlant sl) which will use 'name' to do a look up the SKTypeface in your Dictionary<string,SKTypeFace>, and will then do whatever messing about is necessary to apply weight, width and slant, and will then finally return the SKTypeFace that it found in the dictionary.
I hope that makes sense, and is helpful. I can't quickly post a working implementation, because my implementation of this logic has to achieve a bunch of other things on the side, and is rather entangled with several thousand lines of code for doing other things. But if I can help more, please let me know,
from svg.skia.
I did not run into this problem. We can come up with some solution together. No need for making forked version. I just have to figure out how to make the library plug-able.
from svg.skia.
@jrc14 I will add interface in next release:
public interface ITypefaceProvider
{
SKTypeface? FromFamilyName(string fontFamily, SKFontStyleWeight fontWeight, SKFontStyleWidth fontWidth, SKFontStyleSlant fontStyle);
}
You can implement your own typeface provider and add to SvgTextExtensions.s_typefaceProviders
.
Change is already in master
branch cb51079
from svg.skia.
Thank you - that looks good!
from svg.skia.
@wieslawsoltes
For the following example, how would I use ITypefaceProvider
public void SVGtoPNG(string id, string svg) { using (var skSVG = new SKSvg()) { if (skSVG.FromSvg(svg) != null) { using (var stream = File.OpenWrite(@"image.png"))) { skSVG.Picture.ToImage(stream, SKColors.Empty, SKEncodedImageFormat.Png, 100, 1f, 1f, SKColorType.Rgba8888, SKAlphaType.Premul); } } } }
We are using embeded fonts in our SVGs like this.
`
<style>
@font-face {
font-family: Fontania;
src: url('data:application/font-woff;base64,d09GRgABAAAA....ysKzC/wZ21h')
}
</style>
`
from svg.skia.
@wieslawsoltes
For the following example, how would I use ITypefaceProvider
public void SVGtoPNG(string id, string svg) { using (var skSVG = new SKSvg()) { if (skSVG.FromSvg(svg) != null) { using (var stream = File.OpenWrite(@"image.png"))) { skSVG.Picture.ToImage(stream, SKColors.Empty, SKEncodedImageFormat.Png, 100, 1f, 1f, SKColorType.Rgba8888, SKAlphaType.Premul); } } } }
We are using embeded fonts in our SVGs like this.
<style> ``` @font-face { font-family: Fontania; src: url('data:application/font-woff;base64,d09GRgABAAAA....ysKzC/wZ21h') } </style>
``
This is not supported.
from svg.skia.
@wieslawsoltes Thanks for your prompt response
from svg.skia.
Related Issues (20)
- Cannot render text SVG which is one of W3C samples HOT 1
- SvgImage markupextension cannot support nested binding extension HOT 2
- Styling support for SVG HOT 8
- SVG with some pathes are not drawn HOT 2
- Compile error after update - There is no argument given that corresponds to the required parameter 'skiaModel' of 'SKSvg.ToPicture(SvgFragment, SkiaModel, IAssetLoader)' HOT 1
- Why isn't this SVG image showing? HOT 1
- SvgExtensions.Transforms.GetDimensions rounding causes loss of precision HOT 1
- Publish a new version of Svg.Skia.Converter HOT 2
- Opacity bug HOT 1
- Vector-effect attribute is not supported HOT 1
- Strong signing the assembly HOT 2
- Colors are wrong on Quest Pro (Android + Unity) HOT 3
- Broken link
- Load image through a string binding HOT 1
- Svg.Skia produces more-complex-than-necessary SKPaths which result in rasterisation if rendered back out via e.g. Skia's PDF backend HOT 5
- SVG not applying blur filter in .NET MAUI HOT 2
- Svg Images not rendered after upgrading to Avalonia.Svg, Version=11.0.0.10 HOT 2
- The Fifth Element isn't shown in sliding menu (Avalonia.Skia.Svg) HOT 1
- SvgImage creation outside uithread HOT 2
- EXEC conversion error on UWP build HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svg.skia.