lottie-web icon indicating copy to clipboard operation
lottie-web copied to clipboard

custom text failed while no current char in chars of output

Open zhounan354 opened this issue 9 months ago • 0 comments

当我想替换lottie的文字的时候,如果shape中没有对应的字符,就不绘制这个字符了,这回引起极大的困扰,建议应该做一个保底方案,找不到对应字符的shape时,就通过默认字体绘制,只需要改一处简单的代码就行。 这是源代码: if (fontManager.chars) { charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily); cLength = newLineFlag ? 0 : charData.w * documentData.finalSize / 100; } else { // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize); // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily; cLength = fontManager.measureText(val, documentData.f, documentData.finalSize); } // 希望可以对getCharData的返回值做一个判断,如果找不到,就执行下方的else中的代码。 辛苦大佬们google翻译一下看看吧哈哈哈哈,感谢!

PS: 我现在用了一个方法规避,就是拿到lootie的json后,删除chars这个数组,如此,就会全部走入else的默认字体绘制了。

zhounan354 avatar May 09 '24 03:05 zhounan354