Skip to content

Commit

Permalink
#364 Ban footnotes inside page margins.
Browse files Browse the repository at this point in the history
  • Loading branch information
danfickle committed Sep 5, 2021
1 parent 055c0b3 commit edc438a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static void createChildren(LayoutContext c, BlockBox parent) {
CalculatedStyle parentStyle = parent.getStyle();

boolean oldAllowFootnotes = c.isFootnoteAllowed();
if (parentStyle.isFixed()) {
if (parentStyle.isFixed() || parentStyle.isRunning()) {
c.setFootnoteAllowed(false);
}

Expand Down Expand Up @@ -1309,6 +1309,7 @@ private static boolean isValidFootnote(
return c.isPrint() &&
(style.isInline() || style.isSpecifiedAsBlock()) &&
!style.isPostionedOrFloated() &&
!style.isRunning() &&
!c.getSharedContext().getReplacedElementFactory().isReplacedElement(element);
}

Expand All @@ -1322,8 +1323,8 @@ private static void logInvalidFootnoteStyle(
cause = "The footnote element must not be floated";
} else if (c.getSharedContext().getReplacedElementFactory().isReplacedElement(element)) {
cause = "The footnote element must not be replaced (such as <img>)";
} else if (style.isPositioned()) {
cause = "The footnote element must have position: static (not absolute, relative or fixed)";
} else if (style.isPositioned() || style.isRunning()) {
cause = "The footnote element must have position: static (not absolute, relative, running or fixed)";
}

XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.GENERAL_FOOTNOTE_INVALID, cause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ private void retrievePageMetadata(LayoutContext c) {
}

private void layoutMarginAreas(LayoutContext c) {
c.setFootnoteAllowed(false);
RectPropertySet margin = getMargin(c);
for (int i = 0; i < MARGIN_AREA_DEFS.length; i++) {
MarginArea area = MARGIN_AREA_DEFS[i];
Expand Down Expand Up @@ -598,6 +599,7 @@ private void layoutMarginAreas(LayoutContext c) {
_marginAreas[i] = new MarginAreaContainer(area, table);
}
}
c.setFootnoteAllowed(true);
}

public boolean isLeftPage() {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<html>
<head>
<style>
@page {
size: 300px 300px;
margin: 40px;

@top-center {
float: footnote;
content: "Invalid 1";
}
@bottom-center {
content: element(footer);
}
}
</style>
</head>
<body>
<div style="position: running(footer); float: footnote;">
Invalid 2
<div style="float: footnote;">
Invalid 3
</div>
</div>

Page 1 in-flow content.

<div style="page-break-before: always;">
Page 2 content
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,17 @@ public void testIssue364CalledFromPositioned() throws IOException {
assertTrue(vt.runTest("issue-364-called-from-positioned"));
}

/**
* Tests that footnotes inside page margins are treated as normal
* content (and warning is logged).
*/
@Test
public void testIssue364FootnotesInsidePageMargins() throws IOException {
TestSupport.withLog((log, builder) -> {
assertTrue(vt.runTest("issue-364-page-margins", builder));
assertThat(log, hasItem(LogMessageId.LogMessageId0Param.GENERAL_NO_FOOTNOTES_INSIDE_FOOTNOTES));
assertThat(log, hasItem(LogMessageId.LogMessageId1Param.GENERAL_FOOTNOTE_INVALID));
});
}

}

0 comments on commit edc438a

Please sign in to comment.