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
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
- Update jspdf.js (#2210) fix for #2011 not tested — committed to parallax/jsPDF by Uzlopak 6 years ago
- see #2011 - let getStringUnitWithds provide the sum of width of each individual character. — committed to bwl21/jsPDF_1.5 by deleted user 5 years ago
- Fix #2011 and some eslinting (#2379) Fix #2011 and some eslinting (#2379) — committed to parallax/jsPDF by Uzlopak 5 years ago
I played around with patching the kerning tables for helvetica.
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 13923var getStringUnitWidth = API.getStringUnitWidth = function (text, options) {
I could not find a proper place to fix it …