parallax/jsPDF

charSpace and maxWidth in doc.text() : charSpace > 0 and maxWidth is not respected

オープン

#3,299 opened on 2021/10/16

 (5 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (4,596 件のフォーク)batch import
Bugdifficulty:mediumhacktoberfesthelp wanted

Repository metrics

Stars
 (28,280 個のスター)
PR merge metrics
 (PR metrics pending)

説明

I have read and understood the contribution guidelines.

Basically, charSpace and maxWidth don't play nicely together.

Code tested using your live demo at http://raw.githack.com/MrRio/jsPDF/master/

The following works fine ...

var doc = new jsPDF();
doc.setFontSize(22);
doc.text("This is a title", 20, 20);

const maxWidth = 100;
const charSpace = 0;

// Drawing a box to show maxWidth clearly
doc.rect(20, 20, maxWidth, 100, 'S')

// Using 'justify' to show things clearly but also happens with 'left'
const options = {
    maxWidth: maxWidth,
    charSpace: charSpace,
    align: 'justify'
}
const str = "Mary had a little lamb she also had a duck. She put them on the mantlepiece to see if they would fall off."

doc.setFontSize(16);
doc.text(str, 20, 30, options);

However, if you change charSpace to 1 then maxWidth is not correctly applied and then text extends beyond the maxWidth boundary.

I can then adjust maxWidth to try and compensate for this, but the formula is not leaping off the page at me!

コントリビューターガイド