Skip to content

Commit

Permalink
Split long words
Browse files Browse the repository at this point in the history
  • Loading branch information
bombsimon committed Oct 13, 2023
1 parent df18a2d commit 088078c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion public/image.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
function splitLongWords(words, maxWidth) {
const result = [];

words.forEach((word) => {
if (word.length > maxWidth) {
for (let i = 0; i < word.length; i += maxWidth) {
result.push(
word.slice(i, i + maxWidth) + (i + maxWidth < word.length ? "-" : ""),
);
}
} else {
result.push(word);
}
});

return result;
}

// Helper function to split text into multiple lines
function splitToLines(ctx, text, maxWidth) {
const words = text.split(" ");
const maxCharsPerLine = 18;
const words = splitLongWords(text.split(" "), maxCharsPerLine);
const lines = [];
let currentLine = words[0];

Expand Down

0 comments on commit 088078c

Please sign in to comment.