1234567891011121314 |
- export const getWrapText = (ctx, text = "", maxWidth = 200) => {
- let txtList = [];
- let str = "";
- for (let i = 0, len = text.length; i < len; i++) {
- str += text.charAt(i);
- if (ctx.measureText(str).width > maxWidth) {
- txtList.push(str.substring(0, str.length - 1));
- str = "";
- i--;
- }
- }
- txtList.push(str);
- return txtList;
- };
|