D3js : How to convert svg text to path?

前端 未结 2 1444
攒了一身酷
攒了一身酷 2021-02-14 10:23

Is there a D3.js way to convert a text element into a path element?

So when I grasp the generated svg, I could keep my the texts shapes.

2条回答
  •  渐次进展
    2021-02-14 11:12

    There is a node module called text-to-svg that claimed to do so:

    Convert text to SVG path without native dependencies.

    Example

    const TextToSVG = require('text-to-svg');
    const textToSVG = TextToSVG.loadSync();
    
    const attributes = {fill: 'red', stroke: 'black'};
    const options = {x: 0, y: 0, fontSize: 72, anchor: 'top', attributes: attributes};
    
    const svg = textToSVG.getSVG('hello', options);
    
    console.log(svg);
    

提交回复
热议问题