Skip to content

Conversation

RadekWikturna
Copy link
Contributor

@RadekWikturna RadekWikturna commented Sep 12, 2025

Description of the new Feature/Bugfix

When parsing HTML with a span styled with line-height (e.g., <span "line-height:115%">), the generated Paragraph in OpenPDF 1.3.x computed the multiplied leading incorrectly, resulting in overlapping lines (see attached PDF file).

paragraph.getLeading()           = 0.0
paragraph.getMultipliedLeading() = 0.138  // much too small
paragraph.getTotalLeading()      ≈ 1.656  // causes overlapping lines in the PDF

Expected behavior:

For font size 12pt and line-height:115%, the total leading should be ≈ 13.8pt (12 × 1.15).

Cause:

FactoryProperties.insertStyle, line 383 handles line-height in percentage (by dividing by 100) although the percentage handling is done already in Markup.parseLength(String string, float actualFontSize), line 553.
The problem was most likely introduced by: #1059 When converting HTML to PDF, font size specified in % is interpreted as pixels

Solution:

Adjusted FactoryProperties.insertStyle - removed handling line-height in percentage.

Added a JUnit test (testLineHeightPercentage) that parses a small HTML snippet with line-height:115% and asserts that Paragraph.getTotalLeading() matches the expected value.

Unit-Tests for the Bugfix

  • [x ] Unit-Tests added to reproduce the bug

Compatibilities Issues

None

Your real name

Radek Wikturna

Testing details

Any other details about how to test the new feature or bugfix?

Line Height Percentage.pdf

@RadekWikturna RadekWikturna changed the base branch from master to 1.3-java8 September 12, 2025 12:54
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
47 Security Hotspots
B Maintainability Rating on New Code (required ≥ A)
D Security Rating on New Code (required ≥ A)
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@RadekWikturna
Copy link
Contributor Author

I wonder if anyone can have a look, so that the pull request could be accepted.

I've described the issue in detail, including the cause.
I've fixed the problem (basically removed a few lines)
I've written a JUnit test covering this problem

All tests pass.

Note: Some SonarCloud Code Analysis and Codacy Code Analysis report some problem - but NOT in the new code but elsewhere.

@RadekWikturna
Copy link
Contributor Author

I'm rather disappointed that there's no activity towards merging this fix. My previous 3 pull requests were merged pretty fast and this one is just waiting. Can I do anything to make it happen? @asturio, can you help?

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

Successfully merging this pull request may close these issues.

1 participant