nfroidure/svgicons2svgfont

rx, ry, xrot is NaN

Closed this issue · 3 comments

tscpp commented

Issue

  • I've fully read the README recently
  • I've searched for existing issues
  • I've checked I'm up to date with the latest version of the project

Expected behavior

Actual behavior

The three numbers (rx, ry, xrot) after letter A after converting is always NaN.

rX, rY, xRot gets NaN @index.js#L476

...path.toAbs().matrix(...glyphPathTransform.toArray()).commands

Steps to reproduce the behavior

let result = ''

const stream = new SVGIcons2SVGFontStream()
	.on("data", (data) => {
		result += data
	})

const file = 'file.svg'
const glyph = fs.createReadStream(file)
glyph.metadata = await getMetadata(file)
stream.write(glyph)

stream.end()

// The generated SVG file
console.log(result)

file.svg
SVG is a minus, made with Inkscape and then compressed with SVGO. I have also tried using the original Inkscape file exported a plain SVG using this guide (by fontello).

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8.467 8.467" height="32" width="32"><rect ry=".952" rx="0" y="3.757" x="1.058" height=".952" width="6.35"/></svg>

Debugging informations

  • node -v result:
v14.15.0
  • npm -v result:
6.14.8

If the result is lower than 6.9.5, there is a poor chance I even have a look to it. Please, use the last NodeJS LTS version.

I tried to convert your path with:

// Shapes helpers (should also move elsewhere)
function svgShapesToPathRectToPath(attributes) {
const x = 'undefined' !== typeof attributes.x ? parseFloat(attributes.x) : 0;
const y = 'undefined' !== typeof attributes.y ? parseFloat(attributes.y) : 0;
const width =
'undefined' !== typeof attributes.width ? parseFloat(attributes.width) : 0;
const height =
'undefined' !== typeof attributes.height
? parseFloat(attributes.height)
: 0;
const rx =
'undefined' !== typeof attributes.rx
? parseFloat(attributes.rx)
: 'undefined' !== typeof attributes.ry ? parseFloat(attributes.ry) : 0;
const ry =
'undefined' !== typeof attributes.ry ? parseFloat(attributes.ry) : rx;
return (
'' +
// start at the left corner
'M' +
(x + rx) +
' ' +
y +
// top line
'h' +
(width - rx * 2) +
// upper right corner
(rx || ry ? 'a ' + rx + ' ' + ry + ' 0 0 1 ' + rx + ' ' + ry : '') +
// Draw right side
'v' +
(height - ry * 2) +
// Draw bottom right corner
(rx || ry ? 'a ' + rx + ' ' + ry + ' 0 0 1 ' + rx * -1 + ' ' + ry : '') +
// Down the down side
'h' +
(width - rx * 2) * -1 +
// Draw bottom right corner
(rx || ry
? 'a ' + rx + ' ' + ry + ' 0 0 1 ' + rx * -1 + ' ' + ry * -1
: '') +
// Down the left side
'v' +
(height - ry * 2) * -1 +
// Draw bottom right corner
(rx || ry ? 'a ' + rx + ' ' + ry + ' 0 0 1 ' + rx + ' ' + ry * -1 : '') +
// Close path
'z'
);
}

The result seems ok : M1.058 3.757h6.35a 0 0.952 0 0 1 0 0.952v-0.952a 0 0.952 0 0 1 0 0.952h-6.35a 0 0.952 0 0 1 0 -0.952v0.952a 0 0.952 0 0 1 0 -0.952z

Probably a problem with yOffset here :

And I guess it comes from the fact you did not setup any options to the SVGIcons2SVGFontStream'a constructor.

No activity so closing the issue.

tscpp commented

Sorry, I forgot the issue. I remember solving the issue, but not how I did it.