Skip to content

Commit 91abbe6

Browse files
committed
Use tag repairing mechanism
DEVSIX-8862
1 parent 573a853 commit 91abbe6

File tree

132 files changed

+1855
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+1855
-132
lines changed

src/main/java/com/itextpdf/html2pdf/attach/impl/tags/UlOlTagWorker.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This file is part of the iText (R) project.
2929
import com.itextpdf.html2pdf.css.CssConstants;
3030
import com.itextpdf.html2pdf.html.AttributeConstants;
3131
import com.itextpdf.layout.IPropertyContainer;
32-
import com.itextpdf.layout.element.AnonymousBox;
32+
import com.itextpdf.layout.element.AnonymousInlineBox;
3333
import com.itextpdf.layout.element.IBlockElement;
3434
import com.itextpdf.layout.element.ILeafElement;
3535
import com.itextpdf.layout.element.List;
@@ -139,11 +139,12 @@ public IPropertyContainer getElementResult() {
139139
* Processes an unlabeled list item.
140140
*/
141141
private void processUnlabeledListItem() {
142-
AnonymousBox ab = new AnonymousBox();
142+
AnonymousInlineBox ab = new AnonymousInlineBox();
143143
inlineHelper.flushHangingLeaves(ab);
144-
if (ab.getChildren().size() > 0) {
145-
addUnlabeledListItem(ab);
144+
if (ab.getChildren().isEmpty()) {
145+
return;
146146
}
147+
addUnlabeledListItem(ab);
147148
}
148149

149150
/**

src/main/java/com/itextpdf/html2pdf/attach/util/WaitingInlineElementsHelper.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This file is part of the iText (R) project.
2929
import com.itextpdf.kernel.pdf.tagging.StandardRoles;
3030
import com.itextpdf.layout.Document;
3131
import com.itextpdf.layout.IPropertyContainer;
32-
import com.itextpdf.layout.element.AnonymousBox;
32+
import com.itextpdf.layout.element.AnonymousInlineBox;
3333
import com.itextpdf.layout.element.Cell;
3434
import com.itextpdf.layout.element.Div;
3535
import com.itextpdf.layout.element.IBlockElement;
@@ -135,7 +135,7 @@ public void addAll(Collection<ILeafElement> collection) {
135135
* @param container a container element
136136
*/
137137
public void flushHangingLeaves(IPropertyContainer container) {
138-
AnonymousBox ab = createLeavesContainer();
138+
AnonymousInlineBox ab = createLeavesContainer();
139139
if (ab != null) {
140140
Map<String, String> map = new HashMap<>();
141141
map.put(CssConstants.OVERFLOW, CommonCssConstants.VISIBLE);
@@ -173,34 +173,34 @@ public void flushHangingLeaves(IPropertyContainer container) {
173173
/**
174174
* Creates the leaves container.
175175
*
176-
* @return an {@link AnonymousBox}
176+
* @return an {@link AnonymousInlineBox}
177177
*/
178-
private AnonymousBox createLeavesContainer() {
178+
private AnonymousInlineBox createLeavesContainer() {
179179
if (collapseSpaces) {
180180
waitingLeaves = TrimUtil.trimLeafElementsAndSanitize(waitingLeaves);
181181
}
182182
capitalize(waitingLeaves);
183183

184-
if (waitingLeaves.size() > 0) {
185-
AnonymousBox ab = new AnonymousBox();
186-
boolean runningElementsOnly = true;
187-
for (IElement leaf : waitingLeaves) {
188-
if (leaf instanceof ILeafElement) {
189-
runningElementsOnly = false;
190-
ab.add((ILeafElement) leaf);
191-
} else if (leaf instanceof IBlockElement) {
192-
runningElementsOnly = runningElementsOnly && leaf instanceof RunningElement;
193-
ab.add((IBlockElement) leaf);
194-
}
195-
}
196-
if (runningElementsOnly) {
197-
// TODO DEVSIX-7008 Remove completely empty tags from logical structure of resultant PDF documents
198-
ab.getAccessibilityProperties().setRole(StandardRoles.ARTIFACT);
199-
}
200-
return ab;
201-
} else {
184+
if (waitingLeaves.isEmpty()) {
202185
return null;
203186
}
187+
AnonymousInlineBox ab = new AnonymousInlineBox();
188+
ab.getAccessibilityProperties().setRole(StandardRoles.P);
189+
boolean runningElementsOnly = true;
190+
for (IElement leaf : waitingLeaves) {
191+
if (leaf instanceof ILeafElement) {
192+
runningElementsOnly = false;
193+
ab.add((ILeafElement) leaf);
194+
} else if (leaf instanceof IBlockElement) {
195+
runningElementsOnly = runningElementsOnly && leaf instanceof RunningElement;
196+
ab.add((IBlockElement) leaf);
197+
}
198+
}
199+
if (runningElementsOnly) {
200+
// TODO DEVSIX-7008 Remove completely empty tags from logical structure of resultant PDF documents
201+
ab.getAccessibilityProperties().setRole(StandardRoles.ARTIFACT);
202+
}
203+
return ab;
204204
}
205205

206206
/**

src/test/java/com/itextpdf/html2pdf/HtmlConverterPdfUA1UA2Test.java

Lines changed: 120 additions & 99 deletions
Large diffs are not rendered by default.

src/test/java/com/itextpdf/html2pdf/attribute/LangAttributeTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,26 +129,26 @@ public void langAttrEmptyTagTest() throws IOException {
129129
.moveToRoot()
130130
.moveToKid(1)
131131
.moveToKid(0)
132-
.moveToKid(StandardRoles.P);
132+
.moveToKid(StandardRoles.LBL);
133133
Assertions.assertEquals("", tagPointer.getProperties().getLanguage());
134134

135135
tagPointer
136136
.moveToRoot()
137-
.moveToKid(3)
138-
.moveToKid(0)
139-
.moveToKid(StandardRoles.P);
137+
.moveToKid(1)
138+
.moveToKid(2)
139+
.moveToKid(StandardRoles.LBL);
140140
Assertions.assertEquals("", tagPointer.getProperties().getLanguage());
141141

142142
tagPointer
143143
.moveToRoot()
144-
.moveToKid(4)
144+
.moveToKid(2)
145145
.moveToKid(0)
146146
.moveToKid(StandardRoles.TD);
147147
Assertions.assertEquals("", tagPointer.getProperties().getLanguage());
148148

149149
tagPointer
150150
.moveToRoot()
151-
.moveToKid(4)
151+
.moveToKid(2)
152152
.moveToKid(1)
153153
.moveToKid(StandardRoles.TD);
154154
Assertions.assertEquals("", tagPointer.getProperties().getLanguage());
@@ -254,7 +254,7 @@ public void langAttrInSvgForTaggedPdfTest() throws IOException {
254254

255255
tagPointer
256256
.moveToRoot()
257-
.moveToKid(2, StandardRoles.P)
257+
.moveToKid(3, StandardRoles.P)
258258
.moveToKid(StandardRoles.FIGURE);
259259
Assertions.assertEquals("ru", tagPointer.getProperties().getLanguage());
260260

@@ -324,6 +324,7 @@ public void langAttrInListWithBeforeStyleForTaggedPdfTest() throws IOException {
324324
.moveToKid(0, StandardRoles.LBODY);
325325
Assertions.assertEquals("de", tagPointer.getProperties().getLanguage());
326326

327+
tagPointer.moveToKid(0, StandardRoles.P);
327328
List<String> kidsRoles = tagPointer.getKidsRoles();
328329
Assertions.assertTrue(StandardRoles.SPAN.equals(kidsRoles.get(0))
329330
&& StandardRoles.SPAN.equals(kidsRoles.get(1)));
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)