Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

widthOfString/heightOfString not accurate? #1460

Open
altano opened this issue Aug 27, 2023 · 0 comments
Open

widthOfString/heightOfString not accurate? #1460

altano opened this issue Aug 27, 2023 · 0 comments

Comments

@altano
Copy link

altano commented Aug 27, 2023

Bug Report

Description of the problem

If I call height/widthOfString and draw a rect+stroke with the dimensions returned, I would expect the rect to encompass the text. But that isn't the behavior I'm seeing.

Here are the issues I'm seeing:

  1. With Helvetica, the box is too wide (wider than the pdf) and too tall:
image
  1. With Inter SemiBold, the height looks just about right:
image
  1. But as soon as I give the Inter text a negative line gap, the height is wrong:
image

My goal is to measure the size of text and choose the largest font size that will fill a given area. If I can't compute that area the task is impossible.

Is there a better way of getting the area of the rendered text?

Code sample

code that demonstrates these issues: https://github.com/altano/pdfkit-bugs/tree/main

Just clone, npm install && npm start

Your environment

  • pdfkit version: v0.13.0
  • Node version: v18.16.0
  • Browser version (if applicable): n/a
  • Operating System: macOS 13.4.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant