Break text into paths / create outlines

136 views
Skip to first unread message

Marlus Araujo

unread,
May 4, 2023, 8:16:48 AM5/4/23
to Paper.js
Hello everyone,

I'm wondering if there's a way to convert a PointText or TextItem into paths in Paper.js, so that when exporting the SVG, there's no need for the font file. This would be similar to the "Create Outlines" functionality in Adobe Illustrator, where the text is converted into vector shapes.

Any suggestions or solutions to achieve this would be greatly appreciated.

Thank you in advance for your help!

Best regards,

Marlus

Marlus Araujo

unread,
Aug 5, 2023, 2:12:37 PM8/5/23
to Paper.js
My solution was using opentype lib

import opentype, {Font} from 'opentype.js'
...
(async () => {
try {
const buffer = await fetch('/Degular-Regular.ttf').then(res => res.arrayBuffer());
font = opentype.parse(buffer);
generateSvgText(PARAMS.lettering.text)
} catch (err) {
console.error(err);
}
})();
...
const generateSvgText = (newText:string) => {
const text = newText.trim();
const letteringColor = getTextColor(PARAMS.colorBg, PARAMS.colorFg1);
if(text){
const lines = text.split("\n")
letteringGroup = new paper.Group()
lines.forEach((line,i)=>{
const path = font.getPath(line, 0, i*16, 20)
const svgString = path.toSVG(3)
const item = paper.project.importSVG(svgString, {
expandShapes: true
})
if(item && letteringGroup){
letteringGroup.addChild(item)
}
})
}
}

Reply all
Reply to author
Forward
0 new messages