An API method for TextNode.getAllFontNames would be much appreciated, so you wont have to loop over every char in a TextNode just to find out the fonts used. This seems hugely inefficient, and the solution feels hacky and verbose for such a simple task.
Maybe I’m missing something obvious?
This is my current solution to this problem:
`getFontNames = node => {
const getAllFontNames = node => {
const seen = new Set(), fonts = ;
for (const i of Array.from(node.characters).keys()) {
const
font = node.getRangeFontName(i, i + 1),
name = font.family + font.style; // concatenate property values into string
if (!seen.has(name)) { // if unseen
seen.add(name); // add the string to a set
fonts.push(font); // and output the object
}
}
return fonts;
}
return node.hasMissingFont ? ( figma.notify('Has missing font, replacing with Roboto Regular'), [defaultFont] )
: node.fontName === figma.mixed ? getAllFontNames(node)
: [node.fontName];
}`