Open mmghv opened 1 year ago
Hi Mohamed, I am really interested in solving this issue, could you please assign this to me?
Thanks
Sorry guys, I'm not associated with jspdf, just reporting an issue.
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
Still relevant.
Hello,
I want to resolve this number, please assign me
Hello, I've tried to work on this issue by adding a '-' character for word splitting in the splitLongWord()
function :
var splitLongWord = function(word, widths_array, firstLineMaxLen, maxLen) {
var answer = [];
var hyphen = '-'; // Hyphen character for word splitting
// Calculate the width of a hyphen using the current font and size
var hyphenWidth = this.getStringUnitWidth(hyphen, { font: this.getFont().fontName, fontSize: this.internal.getFontSize() });
// Chop the word to fit the remaining space on the line
var i = 0,
l = word.length,
workingLen = 0;
while (i < l && workingLen + widths_array[i] < firstLineMaxLen) {
workingLen += widths_array[i];
i++;
}
// If the word is being split and there's room, add a hyphen
if (i < l && workingLen + hyphenWidth <= firstLineMaxLen) {
answer.push(word.slice(0, i) + hyphen);
} else {
answer.push(word.slice(0, i));
}
// Split the rest of the word to fit the max line length
var startOfLine = i;
workingLen = 0;
while (i < l) {
// When exceeding max length, split and add to the answer
if (workingLen + widths_array[i] > maxLen) {
answer.push(word.slice(startOfLine, i));
startOfLine = i;
workingLen = 0;
}
workingLen += widths_array[i];
i++;
}
// Add the last piece if there's any
if (startOfLine < l) {
answer.push(word.slice(startOfLine));
}
return answer;
};
What do you think ?
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
Still relevant.
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
Still relevant.
Hi is the issue is still open , I would love to contribute in this .
When splitting a long text that has no spaces using
splitTextToSize()
on a predefined width, it splits at the wrong length causing the text to get out of bounds.The issue gets worse the more width the rectangle has (with longer text)
Exaggerated example :
jspdf v2.5.1 codepen : https://codepen.io/mmghv/pen/eYbjRdX?editors=0011