How to use the svg2ttf/lib/svg.toSfntCoutours function in svg2ttf

To help you get started, we’ve selected a few svg2ttf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github noppa / text-security / build.js View on Github external
function svgToContours({width, height, d}) {
	const accuracy = Math.max(width, height) * 0.0006
	const svgPath = new SvgPath(d)
		.abs()
		.unshort()
		.unarc()
		.iterate((segment, index, x, y) => svg.cubicToQuad(segment, index, x, y, accuracy))

	const sfntContours = svg.toSfntCoutours(svgPath)

	return sfntContours.map(sfntContour => {
		const contour = new sfnt.Contour()

		contour.points = sfntContour.map(sfntPoint => {
			const point = new sfnt.Point()

			point.x = sfntPoint.x
			point.y = sfntPoint.y
			point.onCurve = sfntPoint.onCurve
			return point
		})

		return contour
	})
}

svg2ttf

Converts SVG font to TTF font

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis