(textContent, width)
| 2371 | }; |
| 2372 | // Function to break text into lines based on when user go next line on press enter button |
| 2373 | const breakTextIntoLines = (textContent, width) => { |
| 2374 | const finalLines = []; |
| 2375 | const paragraphs = textContent.split("\n"); // preserve user order |
| 2376 | for (const para of paragraphs) { |
| 2377 | const lineWidth = font.widthOfTextAtSize(para, fontSize); |
| 2378 | //checking string length to container width |
| 2379 | //if string length is less then container width it means user press enter button |
| 2380 | if (lineWidth <= width) { |
| 2381 | // user forced newline |
| 2382 | finalLines.push(para); |
| 2383 | } else { |
| 2384 | // auto wrap paragraph |
| 2385 | finalLines.push(...NewbreakTextIntoLines(para, width)); |
| 2386 | } |
| 2387 | } |
| 2388 | |
| 2389 | return finalLines; |
| 2390 | }; |
| 2391 | //check if text content have `\n` string it means user press enter to go next line and handle condition |
| 2392 | //else auto adjust text content according to container width |
| 2393 | const lines = isNewOnEnterLineExist |
no test coverage detected