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

Text baseline option is not working as expected. #3808

Open
kgeronim opened this issue Jan 1, 2025 · 1 comment
Open

Text baseline option is not working as expected. #3808

kgeronim opened this issue Jan 1, 2025 · 1 comment

Comments

@kgeronim
Copy link

kgeronim commented Jan 1, 2025

Happy new year :)
Anyways uh just wanted to point something out.

Starting on line: 3627

Code behaves as expected with "alphabetic" or "ideographic".

Issue:
Code behaves as expected with "top", "bottom", "hanging" and "middle" only if you keep the default lineHeightFactor.
Changing the global lineHeightFactor or the lineHeightFactor from the doc.text(...) function will produce an unexpected output.

const doc = new jsPDF({ unit: 'pt' });

doc.setFont('times');
doc.setFontSize(18);
doc.text('Test 1', 72, 72, { baseline: 'hanging' });
doc.setLineHeightFactor(2); // this

// or this
doc.text('Test 1', 72, 72, { baseline: 'hanging', lineHeightFactor: 2 });

Expected output:
Text should hang by the 72pt line.
image

Unexpected output:
Text does not do what the baseline claims to do. If we continue with the "hanging" baseline for example, it breaks if the scale factor is anything but 1.15.
image

For now, the work around is to calculate the baseline manually. The issue is that in the source code the descent is dependent on the lineHeightFactor when in reality it should probably be a fixed percentage.

Thank you.

Copy link

github-actions bot commented Apr 7, 2025

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant