Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,6 @@ public static void insertStyle(Map<String, String> h, ChainedProperties cprops)
actualFontSize = Markup.DEFAULT_FONT_SIZE;
}
float v = parseLength(prop.getProperty(key), actualFontSize);
if (ss.endsWith("%")) {
h.put("leading", "0," + (v / 100));
return;
}
if ("normal".equalsIgnoreCase(ss)) {
h.put("leading", "0,1.5");
return;
Expand Down
40 changes: 40 additions & 0 deletions openpdf/src/test/java/com/lowagie/text/html/StylesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.html.simpleparser.HTMLWorker;
import com.lowagie.text.html.simpleparser.StyleSheet;
Expand Down Expand Up @@ -126,4 +127,43 @@ void testNamedFontSize() throws Exception {
Chunk chunk10 = (Chunk) paragraph.get(18);
Assertions.assertEquals(FontSize.LARGER.getScale() * 20f, chunk10.getFont().getSize());
}

@Test
void testLineHeightPercentage() throws Exception {
List<Element> elements = htmlToPdf("stylesTest/lineHeightPercentage.html", "target/Line Height Percentage.pdf");
Paragraph paragraph = (Paragraph) elements.get(0);
Chunk chunk = (Chunk) paragraph.get(0);
float fontSize;
if (chunk.getFont() != null) {
fontSize = chunk.getFont().getSize();
} else {
fontSize = Font.DEFAULTSIZE;
}
float expectedMultiplier = 1.15f; // derived from <span style="line-height:115%"> in lineHeightPercentage.html
float expectedTotalLeading = fontSize * expectedMultiplier;
float totalLeading = paragraph.getTotalLeading();

Assertions.assertEquals(expectedTotalLeading, totalLeading, 0.1f,
"Total leading should be ~fontSize * " + expectedMultiplier);
}

@Test
void testDefaultLineHeight() throws Exception {
List<Element> elements = htmlToPdf("stylesTest/lineHeightDefault.html", "target/Line Height Default.pdf");
Paragraph paragraph = (Paragraph) elements.get(0);
Chunk chunk = (Chunk) paragraph.get(0);
float fontSize;
if (chunk.getFont() != null) {
fontSize = chunk.getFont().getSize();
} else {
fontSize = Font.DEFAULTSIZE;
}
float expectedMultiplier = 1.5f;
float expectedTotalLeading = fontSize * expectedMultiplier;
float totalLeading = paragraph.getTotalLeading();

Assertions.assertEquals(expectedTotalLeading, totalLeading, 0.1f,
"Total leading should be ~fontSize * " + expectedMultiplier);
}

}
15 changes: 15 additions & 0 deletions openpdf/src/test/resources/stylesTest/lineHeightDefault.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eget hendrerit nulla.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae.
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat.
</span>
</body>
</html>
15 changes: 15 additions & 0 deletions openpdf/src/test/resources/stylesTest/lineHeightPercentage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<span style="line-height:115%">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eget hendrerit nulla.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae.
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat.
</span>
</body>
</html>