Skip to content

Commit 6fff5be

Browse files
committed
Fix resolving display:none css style not correctly for flex children
DEVSIX-6547
1 parent 2f98eed commit 6fff5be

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

src/main/java/com/itextpdf/html2pdf/css/resolve/DefaultCssResolver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,12 @@ private Map<String, String> resolveStyles(INode element, CssContext context) {
202202
CommonCssConstants.FONT_SIZE), inheritanceRules);
203203

204204
// If the parent has display: flex, the flex item is blockified
205-
// no matter what display value is set for it.
205+
// no matter what display value is set for it (except 'none' value).
206206
// See CSS Flexible Box Layout Module Level 1,
207207
// W3C Candidate Recommendation, 19 November 2018: 4. Flex Items.
208-
if (isFlexItem(entry, elementStyles.get(CssConstants.DISPLAY))) {
208+
final String currentElementDisplay = elementStyles.get(CssConstants.DISPLAY);
209+
if (isFlexItem(entry, currentElementDisplay) &&
210+
!CommonCssConstants.NONE.equals(currentElementDisplay)) {
209211
elementStyles.put(CssConstants.DISPLAY, CssConstants.BLOCK);
210212
}
211213
}

src/test/java/com/itextpdf/html2pdf/css/DisplayFlexTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ public void marginsCollapseInsideFlexItemTest() throws IOException, InterruptedE
485485
convertToPdfAndCompare("marginsCollapseInsideFlexItem", SOURCE_FOLDER, DESTINATION_FOLDER);
486486
}
487487

488+
@Test
489+
public void resolveStylesIfParentHasDisplayFlexStyleTest() throws IOException, InterruptedException {
490+
convertToPdfAndCompare("displayNoneTest", SOURCE_FOLDER, DESTINATION_FOLDER);
491+
}
492+
488493
private static void assertDiv(IElement element, String text) {
489494
Assert.assertTrue(element instanceof Div);
490495
Assert.assertEquals(1, ((Div) element).getChildren().size());
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<style>
5+
*[parent]:not([parent~="z"]) {
6+
display: flex;
7+
}
8+
*[child1]:not([child1~="z"]) {
9+
display: none;
10+
}
11+
*[child2]:not([child2~="z"]) {
12+
display: block;
13+
}
14+
</style>
15+
<meta charset="UTF-8">
16+
<title>Title</title>
17+
</head>
18+
<body>
19+
<div class="fieldLabel" parent="v"> FlexParent
20+
<div class="fieldLabe2" child1="w"> , NoneChild </div>
21+
<div class="fieldLabe2" child2="x"> , BlockChild </div>
22+
</div>
23+
<div class="fieldLabe3"> NoneChild should be unvisible </div>
24+
</body>
25+
</html>

0 commit comments

Comments
 (0)