Code Monkey home page Code Monkey logo

Comments (7)

jrc14 avatar jrc14 commented on May 12, 2024 1

@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.

wieslawsoltes avatar wieslawsoltes commented on May 12, 2024

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.

wieslawsoltes avatar wieslawsoltes commented on May 12, 2024

@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.

jrc14 avatar jrc14 commented on May 12, 2024

Thank you - that looks good!

from svg.skia.

JonathanDDuncan avatar JonathanDDuncan commented on May 12, 2024

@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 avatar wieslawsoltes commented on May 12, 2024

@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.

JonathanDDuncan avatar JonathanDDuncan commented on May 12, 2024

@wieslawsoltes Thanks for your prompt response

from svg.skia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.