jaywcjlove / svgtofont

Read a set of SVG icons and ouput a TTF/EOT/WOFF/WOFF2/SVG font.
https://jaywcjlove.github.io/svgtofont
MIT License
515 stars 81 forks source link

Unexpected Result while converting an svg to font #180

Closed alapanbagchi closed 1 year ago

alapanbagchi commented 1 year ago

I was trying to convert a bunch of svgs to font using this code but it has led to some weird results

const uploadPath = path.join(__dirname, `../temp/svg/${userid}`)
const fontPath = path.join(__dirname, `../temp/fonts/${userid}`)

const options: SvgToFontOptions = {
            src: uploadPath,
            dist: fontPath,
            fontName: name,
            useNameAsUnicode: true,
        }
        await createSVG(options)
        const ttf = await createTTF(options)
        await createWOFF(options, ttf)
        await createWOFF2(options, ttf)
        await createEOT(options, ttf)

Ths is the original svg used

dog1

This is the result obtained image

jaywcjlove commented 1 year ago

@alapanbagchi If you convert to fonts, you can only use <path>, many tags of svg cannot be used.

alapanbagchi commented 1 year ago

Hi, thanks for clearing that up I managed to fix that issue by converting it into one long single <path> which fixed the above mentioned issue. However I encountered a new problem.

So, here is the new svg test

and this is the resulting font image

As you can see it has lost its transparency. I dont know how to fix that Thanks

jaywcjlove commented 1 year ago

In fonts, fill-rule="evenodd" for svg is also not supported.

alapanbagchi commented 1 year ago

That makes sense, thanks for your help

schmidt-oliver commented 1 year ago

Hi @alapanbagchi, please try using SVGFixer to outline the icons before converting them to font. It worked like a charm in my case.

Opty1712 commented 3 months ago

Hi @alapanbagchi, please try using SVGFixer to outline the icons before converting them to font. It worked like a charm in my case.

confirm it works!

await SVGFixer(resolve(process.cwd(), 'svg'), resolve(process.cwd(), 'tmp'), {
  showProgressBar: true,
  throwIfDestinationDoesNotExist: false,
}).fix();