Skip to content

Commit

Permalink
Fix missing text where value has multiple '-'
Browse files Browse the repository at this point in the history
  • Loading branch information
yaojiu19 committed Aug 12, 2021
1 parent cc0f84c commit 542114c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,10 @@ export default function (self) {
elWidth = self.ctx.measureText(' ' + et).width;
for (x = 0; x < words.length; x += 1) {
word = words[x];
var measure = self.ctx.measureText(word + splitChar);
var curSplitChar = word[word.length - 1] === '-' ? '' : splitChar;
var measure = self.ctx.measureText(word + curSplitChar);
if (line.width + measure.width + elWidth < cell.paddedWidth) {
line.value += word + splitChar;
line.value += word + curSplitChar;
line.width += measure.width;
continue;
}
Expand All @@ -373,13 +374,17 @@ export default function (self) {
// then back up and re-read new split set
// this behavior seems right, it might not be
if (/\w-\w/.test(word) && cell.paddedWidth < measure.width) {
words.splice(x, 1, word.split('-')[0] + '-', word.split('-')[1]);
var arr = word.split('-');
arr = arr.map((item, index) => {
return index === arr.length - 1 ? item : item + '-';
});
words.splice(x, 1, ...arr);
x -= 1;
continue;
}
line = {
width: measure.width,
value: word + splitChar,
value: word + curSplitChar,
};
if (x === 0) {
lines = [];
Expand Down

0 comments on commit 542114c

Please sign in to comment.