danmarshall / google-font-to-svg-path

Create an SVG path from a Google font
https://danmarshall.github.io/google-font-to-svg-path
MIT License
754 stars 128 forks source link

SVG Should Not Have Dimensions #5

Closed villanus closed 7 years ago

villanus commented 7 years ago

So the SVG can properly scale it should not have width / height attributes. Instead it should have a preserveAspectRatio with the default value of xMidYMid meet.

https://jsfiddle.net/37Lsg3dk/6/

When the SVG has set dimensions it cannot scale within a container automatically. Only workaround is to set width to 100% and height to auto using css:

https://jsfiddle.net/37Lsg3dk/7/

danmarshall commented 7 years ago

Hi Frank, sorry this took so long, but you can already do this with the svgAttrs property which lets you override the defaults and add anything you need:

        var opts = {
            svgAttrs: {
                height: null,
                width: null,
                preserveAspectRatio: 'xMidYMid meet'
            }
        };

        var svg = makerjs.exporter.toSVG(model, opts);

This is in Maker.js but not exposed in this project. I'm assuming you're working off of a fork of this repo.