Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Underline y-position wrong for baseline "alphabetic" #994

Open
GeorgeP39 opened this issue Jun 27, 2019 · 2 comments
Open

Underline y-position wrong for baseline "alphabetic" #994

GeorgeP39 opened this issue Jun 27, 2019 · 2 comments
Labels

Comments

@GeorgeP39
Copy link

Underline y-position wrong for baseline "alphabetic"

When setting the baseline to "alphabetic", underlines are drawn too far from the text

Code sample

// create a document and pipe to a blob
var doc = new PDFDocument();
var stream = doc.pipe(blobStream());

doc
  .font('Times-Roman', 13)
  .text(lorem, {
    width: 412,
    align: 'justify',
    indent: 30,
    columns: 2,
    height: 300,
    underline:true,
    baseline: "alphabetic"
  });

// end and display the document in the iframe to the right
doc.end();
stream.on('finish', function() {
  iframe.src = stream.toBlobURL('application/pdf');
});

underlineOffset

Your environment

  • pdfkit version: 0.10.0
  • Node version: N/A
  • Browser version (if applicable): N/A
  • Operating System: Windows 10
@blikblum blikblum added the bug label Jun 27, 2019
@ditiem
Copy link

ditiem commented Aug 16, 2019

Is there any estimated time to fix this or is there anyway to help (as in any idea where start looking at or what can be the reason)?

@GeorgeP39
Copy link
Author

I added a snippet to pdfkit_0,10.0.js which sorted it for my purposes (I'm not guaranteeing it for any other font, but it should get you started on a fix):

at around line 4016, there is

if (options.underline) {
  lineY -= lineWidth;
}

underneath that, I added

if(options.baseline && options.baseline === "alphabetic"){
	lineY -= ((this._font.ascender) / 1000) * this._fontSize;
}

Hope it helps!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants