MCPcopy Index your code
hub / github.com/OpenSignLabs/OpenSign / NewbreakTextIntoLines

Function NewbreakTextIntoLines

apps/OpenSign/src/constant/Utils.js:2333–2371  ·  view source on GitHub ↗
(textContent, width)

Source from the content-addressed store, hash-verified

2331
2332 // Function to break text into lines based on the fixed width
2333 const NewbreakTextIntoLines = (textContent, width) => {
2334 const lines = [];
2335 let currentLine = "";
2336
2337 const words = textContent?.split(" ");
2338 for (let word of words) {
2339 const testLine = currentLine ? currentLine + " " + word : word;
2340 const testWidth = font.widthOfTextAtSize(testLine, fontSize);
2341
2342 if (testWidth <= width) {
2343 currentLine = testLine;
2344 } else {
2345 // If single long word
2346 if (font.widthOfTextAtSize(word, fontSize) > width) {
2347 // Break a long word into smaller parts character-by-character
2348 const brokenParts = forceBreakLongWord(
2349 word,
2350 width,
2351 font,
2352 fontSize
2353 );
2354
2355 // push currentLine before breaking word
2356 if (currentLine.trim()) lines.push(currentLine.trim());
2357
2358 // push ALL broken parts in order
2359 brokenParts.forEach((p) => lines.push(p));
2360
2361 currentLine = "";
2362 } else {
2363 // push current line and start new
2364 if (currentLine.trim()) lines.push(currentLine.trim());
2365 currentLine = word;
2366 }
2367 }
2368 }
2369 if (currentLine.trim()) lines.push(currentLine.trim());
2370 return lines;
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 = [];

Callers 2

breakTextIntoLinesFunction · 0.85
embedWidgetsToDocFunction · 0.85

Calls 1

forceBreakLongWordFunction · 0.85

Tested by

no test coverage detected