parallax/jsPDF

Text centers incorrectly with nonzero charSpace

Open

#3406 aperta il 7 apr 2022

Vedi su GitHub
 (3 commenti) (0 reazioni) (0 assegnatari)JavaScript (4596 fork)batch import
Bugdifficulty:mediumhelp wanted

Metriche repository

Star
 (28.280 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

let pdf = new jspdf.jsPDF();
let page_height = pdf.internal.pageSize.getHeight();
let page_width = pdf.internal.pageSize.getWidth(); 
let x_center = page_width / 2;
let y1 = page_height / 3;
let y2 = y1 + 12;
let y3 = y1 + 24;
let txt = "The quick brown fox jumps over the lazy dog."; 

pdf.text(txt, x_center, y1, { align: 'center', charSpace: 0 });
pdf.text(txt, x_center, y2, { align: 'center', charSpace: -1 });
pdf.text(txt, x_center, y3, { align: 'center', charSpace: 1 });

pdf.save('charspace_bug.pdf');

Expectation: All lines are centered around x_center.

Result: Only the { charSpace: 0 } line is centered. Other lines are left-aligned to that line's left edge.

Hypothesis: jsPDF calculates the starting coordinate before the charSpace transformation is applied?

Guida contributor