Skip to content

Commit 014b202

Browse files
AnhelinaMiText-CI
authored andcommitted
Fix resolving display:none css style not correctly for flex children
DEVSIX-6547 Autoported commit. Original commit hash: [6fff5bea6]
1 parent 1ecc4dc commit 014b202

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

itext.tests/itext.html2pdf.tests/itext/html2pdf/css/DisplayFlexTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ public virtual void MarginsCollapseInsideFlexItemTest() {
419419
ConvertToPdfAndCompare("marginsCollapseInsideFlexItem", SOURCE_FOLDER, DESTINATION_FOLDER);
420420
}
421421

422+
[NUnit.Framework.Test]
423+
public virtual void ResolveStylesIfParentHasDisplayFlexStyleTest() {
424+
ConvertToPdfAndCompare("displayNoneTest", SOURCE_FOLDER, DESTINATION_FOLDER);
425+
}
426+
422427
private static void AssertDiv(IElement element, String text) {
423428
NUnit.Framework.Assert.IsTrue(element is Div);
424429
NUnit.Framework.Assert.AreEqual(1, ((Div)element).GetChildren().Count);
1.06 KB
Binary file not shown.
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>

itext/itext.html2pdf/itext/html2pdf/css/resolve/DefaultCssResolver.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,11 @@ private IDictionary<String, String> ResolveStyles(INode element, CssContext cont
163163
elementStyles = StyleUtil.MergeParentStyleDeclaration(elementStyles, entry.Key, entry.Value, parentStyles.
164164
Get(CommonCssConstants.FONT_SIZE), inheritanceRules);
165165
// If the parent has display: flex, the flex item is blockified
166-
// no matter what display value is set for it.
166+
// no matter what display value is set for it (except 'none' value).
167167
// See CSS Flexible Box Layout Module Level 1,
168168
// W3C Candidate Recommendation, 19 November 2018: 4. Flex Items.
169-
if (IsFlexItem(entry, elementStyles.Get(CssConstants.DISPLAY))) {
169+
String currentElementDisplay = elementStyles.Get(CssConstants.DISPLAY);
170+
if (IsFlexItem(entry, currentElementDisplay) && !CommonCssConstants.NONE.Equals(currentElementDisplay)) {
170171
elementStyles.Put(CssConstants.DISPLAY, CssConstants.BLOCK);
171172
}
172173
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2f98eedd3d5fe0f906b628657badbddb7ce3e0b5
1+
6fff5bea6e841e6ad359986f736185145e48f141

0 commit comments

Comments
 (0)