Skip to content

Commit

Permalink
#79 - Solved the ordering problem for complex inline nesting (with te…
Browse files Browse the repository at this point in the history
…stcase).
  • Loading branch information
danfickle committed Feb 6, 2019
1 parent 85fc5f1 commit d46f4d4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum StructureType {
FLOAT,
BLOCK,
INLINE,
INLINE_CHILD_BOX,
LIST_MARKER,
REPLACED;
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,19 @@ public void paintInline(RenderingContext c) {
}

c.getOutputDevice().endStructure(token1);
Object token2 = c.getOutputDevice().startStructure(StructureType.TEXT, this);

for (int i = 0; i < getInlineChildCount(); i++) {
Object child = getInlineChild(i);
if (child instanceof InlineText) {
Object tokenText = c.getOutputDevice().startStructure(StructureType.TEXT, this);
((InlineText)child).paint(c);
c.getOutputDevice().endStructure(tokenText);
} else if (child instanceof Box) {
Object tokenChildBox = c.getOutputDevice().startStructure(StructureType.INLINE_CHILD_BOX, (Box) child);
c.getOutputDevice().endStructure(tokenChildBox);
}
}

c.getOutputDevice().endStructure(token2);
Object token3 = c.getOutputDevice().startStructure(StructureType.BACKGROUND, this);

for (TextDecoration tD : textDecorations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ public static void main(String... args) throws Exception {
run("tables");
run("bookmarks");
run("links");
run("ordering");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<html>
<head>
<title>Complex PDF/UA Ordering Testcase</title>
<meta name="description" content="A complex ordering example"/>
<style>
@page {
size: 200px 200px;
margin: 0;
}
body {
margin: 0;
width: 200px;
}
</style>
</head>
<body style="font-family: 'TestFont'; font-size: 14px;">
<p>Please check carefully the reading order of below paragraphs!</p>
<p>Some <span>very <span>very <span>deeply</span> nested</span> text</span>!</p>
<p>Some inlines <div>and blocks (with <span>inline</span>)</div> <span>mixed</span> <div>in</div> the same container.</p>
<p>Some <span>inlines</span>, <div>blocks</div> and <span style="display: inline-block;">inline blocks (with <span>nested</span>)</span>!</p>
<p>This is a link to <a title="Go to Google!" href="https://google.com">Google (external)</a>. This text should be read after the <span>link</span>.</p>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,30 @@ public void finishNumberTree() {
_od.getWriter().getDocumentCatalog().getStructureTreeRoot().setParentTree(numberTreeNode);
}

private static String guessBoxTag(Box box) {
if (box instanceof BlockBox) {
BlockBox block = (BlockBox) box;

if (block.isInline()) {
return StandardStructureTypes.SPAN;
} else {
return StandardStructureTypes.DIV;
}
} else {
return StandardStructureTypes.SPAN;
}
}

/**
* Choose a tag for a {@link GenericStructualElement}.
*/
private static String chooseTag(Box box) {
if (box != null) {
if (box.getLayer() != null) {
return StandardStructureTypes.SECT;
} else if (box.getElement() != null) {
} else if (box.isAnonymous()) {
return guessBoxTag(box);
} if (box.getElement() != null) {
String htmlTag = box.getElement().getTagName();

if (htmlTag.equals("p")) {
Expand All @@ -400,17 +416,7 @@ private static String chooseTag(Box box) {
}
}

if (box instanceof BlockBox) {
BlockBox block = (BlockBox) box;

if (block.isInline()) {
return StandardStructureTypes.SPAN;
} else {
return StandardStructureTypes.DIV;
}
} else {
return StandardStructureTypes.SPAN;
}
return guessBoxTag(box);
}

return StandardStructureTypes.SPAN;
Expand Down Expand Up @@ -851,6 +857,14 @@ public Token startStructure(StructureType type, Box box) {
}
return FALSE_TOKEN;
}
case INLINE_CHILD_BOX: {
AbstractStructualElement struct = (AbstractStructualElement) box.getAccessibilityObject();
if (struct == null) {
struct = createStructureItem(type, box);
setupStructureElement(struct, box);
}
return FALSE_TOKEN;
}
case BACKGROUND: {
if (box.hasNonTextContent(_ctx)) {
COSDictionary current = createBackgroundArtifact(type, box);
Expand Down

0 comments on commit d46f4d4

Please sign in to comment.