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

Issue747: fix wrong layout of generating a table with alignment setting #749

Merged
merged 2 commits into from
Jul 9, 2022

Conversation

Brooklyn-0
Copy link
Contributor

@Brooklyn-0 Brooklyn-0 commented May 29, 2022

Description of the new Feature/Bugfix

The strange layout or endless loop is caused by wrong position of the first line in cell which sets alignment not as TOP. After searching the codes deeper, I find it forgets to change contentHeight after modifying line.height with adding correct alignment space. In this way, I just add the missing part on contentHeight for the first line and it works perfectly!

Related Issue: #747

Unit-Tests for the new Feature/Bugfix

public static void test() throws FileNotFoundException {
	Document document = new Document(PageSize.A4);
	PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
	Table table = new Table(2);
	Cell cell = new Cell("any text\nany text\nany text\nany text\nany text\nany text");
	cell.setVerticalAlignment(VerticalAlignment.BOTTOM);
	table.addCell(cell);
	StringBuilder largeStr = new StringBuilder();
	for (int i = 0; i < 45; i++) {
		largeStr.append(String.format("this is to test-> row %d\n", i));
	}
	Cell cell2 = new Cell(new Phrase(largeStr.toString()));
	table.addCell(cell2);
	document.open();
	document.add(table);
	document.close();
}

Before fixing:

image

After fixing:

Screen Shot 2022-05-29 at 11 39 02 AM

Compatibilities Issues

There are no compatibility problems with the new code so far.

Testing details

I create two Junit tests to examine.

@sonarcloud
Copy link

sonarcloud bot commented May 29, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@asturio asturio added this to the 1.3.30 milestone Jul 9, 2022
@asturio asturio linked an issue Jul 9, 2022 that may be closed by this pull request
@asturio asturio merged commit 9d021fe into LibrePDF:master Jul 9, 2022
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.

wrong layout of table with setVerticalAlignment as bottom
2 participants