jsPDF: right align does not work properly if there is a "W" or a parenthesis in the text

Thank you for submitting an issue to jsPDF. Please read carefully.

Are you using the latest version of jsPDF?

using https://rawgit.com/MrRio/jsPDF/master/

Have you tried using jspdf.debug.js?

Steps to reproduce

Try with:

var doc = new jsPDF();

doc.text(10,10, "jspdf version " + jsPDF.version)

doc.setFont("helvetica");
doc.setFontType("bold");
doc.setFontSize(35)
doc.setFontStyle('bold')
doc.text(160,120, "aaaaa bbbbb cccc Wnnnnn\naaaa bbbb cccc nnnn", {align:'right'});
doc.text(160,150, "aaaaa bbbbb cccc wnnnnn\naaaa bbbb cccc nnnn", {align:'right'});
doc.text(160,180, "aaaaa bbbbb cccc wnnnnn\naaaa bbbb Wccc nnnn", {align:'right'});

doc.text(160, 40, ["...","III", "MMM", "M(M)M","M{i}M"],
{align:'right'})


doc.line(160, 0, 160, 190);

Ideally a link too. Try fork this http://jsbin.com/rilace/edit?html,js,output

What I saw

screenshot_1267

What I expected

In all cases the text lines should be right aligned properly. But it is only the case if there is no “W”.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 23 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I played around with patching the kerning tables for helvetica.

  kerning[111][87] = -0.8;
  kerning[87]={};
  kerning[87][111] = -0.8;

But of course this is a bad hack, and best would be indeed to have the right kerning information in src/modules/standard_fonts_metrics.js:317 But I could not find out how …

I dived a bit into the code and found, that somewhere ( in text is replaced by \(. The resulting string is used to compute the position in jspdf.debug.js line 13923

var getStringUnitWidth = API.getStringUnitWidth = function (text, options) {

I could not find a proper place to fix it …