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 · 0 comments
Open

Text baseline option is not working as expected. #3808

kgeronim opened this issue Jan 1, 2025 · 0 comments

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.

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