-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Word widths on justified line of text were calculated incorrectly. #3408
Word widths on justified line of text were calculated incorrectly. #3408
Conversation
…styles into account
@@ -500,7 +500,7 @@ | |||
// stretch the line | |||
var words = line.split(/\s+/), | |||
charOffset = 0, | |||
wordsWidth = this._getWidthOfWords(ctx, words.join(''), lineIndex, 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was wrong.
For line "lorem ipsum dolor"
a words
array would be equal to ["lorem", "ipsum", "dolor"]
then after applying words.join('')
a string "loremipsumdolor"
would be produced.
Passing that string to _getWidthOfWords
resulted in incorrect position of the characters relative to styles.
Moreover, _getWidthOfWords
is ready for that case - notice the if
statement in the method:
_getWidthOfWords: function (ctx, line, lineIndex, charOffset) {
var width = 0;
for (var charIndex = 0; charIndex < line.length; charIndex++) {
var _char = line[charIndex];
if (!_char.match(/\s/)) {
width += this._getWidthOfChar(ctx, _char, lineIndex, charIndex + charOffset);
}
}
return width;
}
@@ -500,7 +500,7 @@ | |||
// stretch the line | |||
var words = line.split(/\s+/), | |||
charOffset = 0, | |||
wordsWidth = this._getWidthOfWords(ctx, words.join(''), lineIndex, 0), | |||
wordsWidth = this._getWidthOfWords(ctx, words.join(' '), lineIndex, 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hence, the solution was to preserve the space characters.
can you correct the lint error? I m going to try this code, it looks good. itext needs a full rewrite in my opinion. |
…3408) * Calculation of word widths on justified line will now correctly take styles into account * fix lint
Thank you @asturur! I was about to fix the lint error this morning, but I saw that you already did that and merged the fix. Appreciate that! |
i wanted to ship in 1.6.7 |
The width of words was incorrectly calculated for justified line of text. Please see the comments to the code changes I committed.