question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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”.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:23 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
bwl21commented, Mar 27, 2019

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 …

1reaction
bwl21commented, Dec 28, 2018

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 …

Read more comments on GitHub >

github_iconTop Results From Across the Web

right align does not work properly if there is a "W" or a ... - GitHub
In all cases the text lines should be right aligned properly. But it is only the case if there is no "W".
Read more >
html - How to properly align numbers enclosed in parentheses?
One simple solution using html would be to use a table, and align the left most column to the right and the right...
Read more >
Aligning Positive and Negative Whole Numbers in a Column
One solution, if you don't have many negative numbers, is to add a right parenthesis to the positive numbers and then simply format...
Read more >
siunitx: Alignment Problems with numbers in parenthesis - TeX
The option table-align-text-post = false shifts the *** next to the numbers. In your example the *** and the minus in the column...
Read more >
Easily insert a right aligned caption next to an equation in word
Manually insert a right aligned caption next to an equation with Tab · 1. Put the cursor right to the equation, and click...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found