Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #364 Implement footnotes at bottom of page #711

Merged
merged 56 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
4509837
#364 Basic test for footnotes (failing).
danfickle May 25, 2021
2bc0a97
#364 Add footnote and bottom as allowed values for float.
danfickle May 25, 2021
d28dc9b
#364 Progress on pseudo classes plus cleanup of BoxBuilder.
danfickle May 25, 2021
630842f
#364 counter-increment support for footnotes.
danfickle May 25, 2021
30e19b3
#364 Very early proof-of-concept for footnotes.
danfickle May 26, 2021
f8b3cb0
#364 Create a box for footnote at-rule and place footnotes in it.
danfickle May 26, 2021
ab2e563
#364 Footnotes positioned correctly on multiple pages.
danfickle May 28, 2021
885af09
Output footnote-call before footnote-marker to correct counters.
danfickle May 28, 2021
0edc576
Better box building, at least when footnote is inline.
danfickle May 28, 2021
46b796d
#364 Start the work of the meeting of in-flow content with footnotes.
danfickle May 29, 2021
5372cb5
#364 Fix for double-adding footnotes when satisfying widows/orphans.
danfickle Jun 2, 2021
4a99a8c
#364 Implement links from footnote-call to footnote-marker.
danfickle Jun 4, 2021
2f8f28a
#364 Passing test for footnote-call links.
danfickle Jun 4, 2021
b706ddf
#364 Fix double painting of footnotes by making sure not linked to an…
danfickle Jun 5, 2021
e027b47
#364 Multi-page footnotes.
danfickle Jun 5, 2021
1070277
#364 Moved footnote management from PageBox to dedicated manager.
danfickle Jun 7, 2021
04ff372
#364 Cleanup and documentation.
danfickle Jun 7, 2021
9775a74
#364 Implement max-height support in footnote at-rule.
danfickle Jun 7, 2021
889069d
#364 Prevent lines in multi-page footnote area from splitting across …
danfickle Jun 8, 2021
b923763
#364 Test for footnotes with a line-height greater than page height.
danfickle Jun 8, 2021
541545e
#364 Failing test for blocks in footnotes.
danfickle Jun 10, 2021
c1af88d
#364 Fix logic error and build in BlockBoxing.
danfickle Jun 10, 2021
f6d67fe
#364 Finally got boxing correct including for block content in footno…
danfickle Jun 14, 2021
312e7a1
#364 Move footnote tests to their own class and folder.
danfickle Jun 20, 2021
d1a814e
#364 Failing test for paginated table with footnotes.
danfickle Jun 20, 2021
7393704
#364 Implement footnotes called from paginated tables.
danfickle Jun 27, 2021
290b97b
Merge branch 'open-dev-v1' into issue_364_footnotes
danfickle Jun 27, 2021
003b242
#364 Fix footnote link test again.
danfickle Jun 27, 2021
240b77d
Merge branch 'open-dev-v1' into issue_364_footnotes
danfickle Jul 17, 2021
d894be8
Fixes #551 - Fix layout explosion with deeply nested avoid page-break…
danfickle Jul 20, 2021
2686570
Try to solve disagreement about number of pages in PDF.
danfickle Jul 20, 2021
f92575b
Take 3 in getting agreement on page count.
danfickle Jul 20, 2021
d33008f
#364 Failing test for position: fixed content.
danfickle Aug 1, 2021
c134383
#364 When positioning fixed elements exclude footnote area.
danfickle Aug 1, 2021
0e26149
#364 Successful test for absolute/fixed inside footnote elements.
danfickle Aug 1, 2021
53e7c8b
#364 Tests floats in footnotes, floated footnote calls and floats int…
danfickle Aug 9, 2021
25a3b34
#364 - Images with footnotes.
danfickle Aug 19, 2021
b6e6d2f
#364 Yet more work on correct boxing.
danfickle Aug 22, 2021
c581ae0
#364 Non-paginated tables with footnotes test with proof.
danfickle Aug 22, 2021
f10ab03
#364 Two link tests with footnotes (one failing).
danfickle Aug 22, 2021
22222f0
#364 Fix linking to the wrong location when an InlineContentBox is mo…
danfickle Aug 23, 2021
f329721
#364 Treat footnotes inside footnotes gracefully.
danfickle Aug 25, 2021
228744a
#364 Warn if an invalid element is being used as a footnote.
danfickle Aug 25, 2021
efa3310
#364 Tests unsupported paginated table inside a footnote.
danfickle Aug 25, 2021
ac0f7ed
#364 More warnings and filtering around invalid footnote styles.
danfickle Aug 27, 2021
7e9e766
#364 Passing test for footnotes with inline-block elements.
danfickle Aug 27, 2021
ceaa17a
#364 Passing test for footnotes with transforms.
danfickle Aug 27, 2021
7a5124d
#364 Make footnote-body inherit styles from footnote element.
danfickle Aug 27, 2021
443a076
#364 Test proof for multi-page footnotes test.
danfickle Aug 27, 2021
8f1d6c7
#364 Proofs for positioned content outside and inside footnotes.
danfickle Aug 28, 2021
a815eb1
#364 Test for calling footnotes from positioned content.
danfickle Aug 28, 2021
055c0b3
#364 Proofs for several footnote tests.
danfickle Sep 5, 2021
edc438a
#364 Ban footnotes inside page margins.
danfickle Sep 5, 2021
33bcce1
#364 Rough performance tests for footnotes.
danfickle Sep 6, 2021
3c5fe74
#364 Java2D manual test for footnotes.
danfickle Sep 6, 2021
594b840
#364 Due to a stack overflow on GitHub actions we will try a smaller …
danfickle Sep 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
package com.openhtmltopdf.context;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.w3c.dom.Element;

import com.openhtmltopdf.css.constants.IdentValue;
import com.openhtmltopdf.css.extend.ContentFunction;
import com.openhtmltopdf.css.parser.CSSPrimitiveValue;
Expand Down Expand Up @@ -188,7 +189,15 @@ public boolean isStatic() {

@Override
public String calculate(RenderingContext c, FSFunction function, InlineText text) {
String uri = text.getParent().getElement().getAttribute("href");
// Due to how BoxBuilder::wrapGeneratedContent works, it is likely the immediate
// parent of text is an anonymous InlineLayoutBox so we have to go up another
// level to the wrapper box which contains the element.
Element hrefElement = text.getParent().getElement() == null ?
text.getParent().getParent().getElement() :
text.getParent().getElement();

String uri = hrefElement.getAttribute("href");

if (uri != null && uri.startsWith("#")) {
String anchor = uri.substring(1);
Box target = c.getBoxById(anchor);
Expand Down Expand Up @@ -242,7 +251,15 @@ public boolean isStatic() {

@Override
public String calculate(RenderingContext c, FSFunction function, InlineText text) {
String uri = text.getParent().getElement().getAttribute("href");
// Due to how BoxBuilder::wrapGeneratedContent works, it is likely the immediate
// parent of text is an anonymous InlineLayoutBox so we have to go up another
// level to the wrapper box which contains the element.
Element hrefElement = text.getParent().getElement() == null ?
text.getParent().getParent().getElement() :
text.getParent().getElement();

String uri = hrefElement.getAttribute("href");

if (uri != null && uri.startsWith("#")) {
String anchor = uri.substring(1);
Box target = c.getBoxById(anchor);
Expand Down Expand Up @@ -302,16 +319,46 @@ public String calculate(RenderingContext c, FSFunction function, InlineText text
// Because the leader should fill up the line, we need the correct
// width and must first compute the target-counter function.
boolean dynamic = false;
Iterator<Box> childIterator = lineBox.getChildIterator();
while (childIterator.hasNext()) {
Box child = childIterator.next();
boolean dynamic2 = false;
Box wrapperBox = iB.getParent();
List<? extends Object> children = null;

// The type of wrapperBox will depend on the CSS display property
// of the pseudo element where the content property using this function exists.
// See BoxBuilder#wrapGeneratedContent.
if (wrapperBox instanceof InlineLayoutBox) {
children = ((InlineLayoutBox) wrapperBox).getInlineChildren();
} else {
children = wrapperBox.getChildren();
}

for (Object child : children) {
if (child == iB) {
// Don't call InlineLayoutBox::lookForDynamicFunctions on this box
// as we will arrive back here and end up as a stack overflow.
// Instead set the dynamic flag so we resolve subsequent dynamic functions.
dynamic = true;
} else if (dynamic && child instanceof InlineLayoutBox) {
} else if (child instanceof InlineLayoutBox) {
// This forces the computation of dynamic functions.
((InlineLayoutBox)child).lookForDynamicFunctions(c);
}
}

// We also have to evaluate subsequent dynamic functions at the line level
// in the case that we are in the ::before and subsequent functions are in ::after.
if (dynamic) {
for (Box child : lineBox.getChildren()) {
if (wrapperBox == child) {
dynamic2 = true;
} else if (dynamic2 && child instanceof InlineLayoutBox) {
((InlineLayoutBox)child).lookForDynamicFunctions(c);
}
}
}

if (dynamic) {
// Re-calculate the width of the line after subsequent dynamic functions
// have been calculated.
int totalLineWidth = InlineBoxing.positionHorizontally(c, lineBox, 0);
lineBox.setContentWidth(totalLineWidth);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,192 +268,3 @@ public void setSupportCMYKColors(boolean b) {
_stylesheetFactory.setSupportCMYKColors(b);
}
}

/*
* $Id$
*
* $Log$
* Revision 1.22 2008/07/27 00:21:46 peterbrant
* Implement CMYK color support for PDF output, starting with patch from Mykola Gurov / Banish java.awt.Color from FS core layout classes
*
* Revision 1.21 2008/04/04 13:32:38 peterbrant
* Fix method name
*
* Revision 1.20 2008/04/04 13:28:38 peterbrant
* Make sure user agent is provided to StyleReference when it's modified / Light cleanup
*
* Revision 1.19 2008/01/22 00:29:23 peterbrant
* Need to propagate changes to user agent in SharedContext to containing StyleReference
*
* Revision 1.18 2007/10/31 23:14:42 peterbrant
* Add rudimentary support for @font-face rules
*
* Revision 1.17 2007/08/19 22:22:52 peterbrant
* Merge R8pbrant changes to HEAD
*
* Revision 1.16.2.1 2007/07/09 22:18:04 peterbrant
* Begin work on running headers and footers and named pages
*
* Revision 1.16 2007/05/26 19:04:13 peterbrant
* Implement support for removing all references to a particular Element (in order to support limited dynamic DOM changes)
*
* Revision 1.15 2007/05/20 23:25:34 peterbrant
* Various code cleanups (e.g. remove unused imports)
*
* Patch from Sean Bright
*
* Revision 1.14 2007/05/16 22:27:14 peterbrant
* Only load default stylesheet once
*
* Revision 1.13 2007/02/20 23:44:51 peterbrant
* Minor formatting change
*
* Revision 1.12 2007/02/20 01:17:10 peterbrant
* Start CSS parser cleanup
*
* Revision 1.11 2007/02/19 14:53:42 peterbrant
* Integrate new CSS parser
*
* Revision 1.10 2006/09/11 19:23:29 peterbrant
* Parse element styles all at once
*
* Revision 1.9 2006/08/27 00:36:14 peterbrant
* Initial commit of (initial) R7 work
*
* Revision 1.8 2006/01/03 23:02:37 peterbrant
* Remove unused variable
*
* Revision 1.7 2005/12/30 01:32:43 peterbrant
* First merge of parts of pagination work
*
* Revision 1.6 2005/11/11 01:33:15 peterbrant
* Add ability to clear all cached stylesheets
*
* Revision 1.5 2005/10/27 00:08:51 tobega
* Sorted out Context into RenderingContext and LayoutContext
*
* Revision 1.4 2005/06/26 15:48:10 tobega
* Converted to almost standard html4 default css, which shook out a bug: position should not inherit
*
* Revision 1.3 2005/06/25 19:27:46 tobega
* UAC now supplies Resources
*
* Revision 1.2 2005/06/23 17:03:40 tobega
* css now independent of DOM
*
* Revision 1.1 2005/06/22 23:48:40 tobega
* Refactored the css package to allow a clean separation from the core.
*
* Revision 1.34 2005/06/16 12:59:23 pdoubleya
* Cleaned up support for reloading documents.
*
* Revision 1.33 2005/06/16 11:29:12 pdoubleya
* First cut support for reload page, flushes inline stylesheets.
*
* Revision 1.32 2005/06/16 07:24:48 tobega
* Fixed background image bug.
* Caching images in browser.
* Enhanced LinkListener.
* Some house-cleaning, playing with Idea's code inspection utility.
*
* Revision 1.31 2005/06/15 11:53:45 tobega
* Changed UserAgentCallback to getInputStream instead of getReader. Fixed up some consequences of previous change.
*
* Revision 1.30 2005/06/01 21:36:37 tobega
* Got image scaling working, and did some refactoring along the way
*
* Revision 1.29 2005/05/17 06:56:23 tobega
* Inline backgrounds now work correctly, as does mixing of inlines and blocks for style inheritance
*
* Revision 1.28 2005/05/08 15:37:29 tobega
* Fixed up style caching so it really works (internalize CascadedStyles and let each CalculatedStyle keep track of its derived children)
*
* Revision 1.27 2005/05/08 14:51:22 tobega
* Removed the need for the Styler
*
* Revision 1.26 2005/05/08 14:36:54 tobega
* Refactored away the need for having a context in a CalculatedStyle
*
* Revision 1.25 2005/03/24 23:18:38 pdoubleya
* Added use of SharedContext (Kevin).
*
* Revision 1.24 2005/01/29 20:19:22 pdoubleya
* Clean/reformat code. Removed commented blocks, checked copyright.
*
* Revision 1.23 2005/01/29 12:49:24 pdoubleya
* Fixed cast on get...PropertiesMap().
*
* Revision 1.22 2005/01/24 19:01:09 pdoubleya
* Mass checkin. Changed to use references to CSSName, which now has a Singleton instance for each property, everywhere property names were being used before. Removed commented code. Cascaded and Calculated style now store properties in arrays rather than maps, for optimization.
*
* Revision 1.21 2005/01/24 14:36:30 pdoubleya
* Mass commit, includes: updated for changes to property declaration instantiation, and new use of DerivedValue. Removed any references to older XR... classes (e.g. XRProperty). Cleaned imports.
*
* Revision 1.20 2005/01/16 18:50:03 tobega
* Re-introduced caching of styles, which make hamlet and alice scroll nicely again. Background painting still slow though.
*
* Revision 1.19 2005/01/08 15:56:54 tobega
* Further work on extensibility interfaces. Documented it - see website.
*
* Revision 1.18 2005/01/08 11:55:16 tobega
* Started massaging the extension interfaces
*
* Revision 1.17 2005/01/04 10:19:11 tobega
* resolve selectors to styles direcly on match, should reduce memory footprint and not affect speed very much.
*
* Revision 1.16 2005/01/03 23:40:40 tobega
* Cleaned out unnecessary styling/matching code. styling/matching is now called during boxing/rendering rather than as a separate stage.
*
* Revision 1.15 2004/12/29 10:39:27 tobega
* Separated current state Context into LayoutContext and the rest into SharedContext.
*
* Revision 1.14 2004/12/28 01:48:22 tobega
* More cleaning. Magically, the financial report demo is starting to look reasonable, without any effort being put on it.
*
* Revision 1.13 2004/12/11 18:18:08 tobega
* Still broken, won't even compile at the moment. Working hard to fix it, though. Replace the StyleReference interface with our only concrete implementation, it was a bother changing in two places all the time.
*
* Revision 1.22 2004/12/05 18:11:36 tobega
* Now uses style cache for pseudo-element styles. Also started preparing to replace inline node handling with inline content handling.
*
* Revision 1.21 2004/12/05 14:35:38 tobega
* Cleaned up some usages of Node (and removed unused stuff) in layout code. The goal is to pass "better" objects than Node wherever possible in an attempt to shake out the bugs in tree-traversal (probably often unnecessary tree-traversal)
*
* Revision 1.20 2004/12/05 00:48:53 tobega
* Cleaned up so that now all property-lookups use the CalculatedStyle. Also added support for relative values of top, left, width, etc.
*
* Revision 1.19 2004/12/02 19:46:35 tobega
* Refactored handling of inline styles to fit with StylesheetInfo and media handling (is also now correct if there should be more than one style element)
*
* Revision 1.18 2004/12/01 14:02:51 joshy
* modified media to use the value from the rendering context
* added the inline-block box
* - j
*
* Revision 1.17 2004/11/30 23:47:56 tobega
* At-media rules should now work (not tested). Also fixed at-import rules, which got broken at previous modification.
*
* Revision 1.16 2004/11/29 23:25:37 tobega
* Had to redo thinking about Stylesheets and StylesheetInfos. Now StylesheetInfos are passed around instead of Stylesheets because any Stylesheet should only be linked to its URI. Bonus: the external sheets get lazy-loaded only if needed for the medium.
*
* Revision 1.15 2004/11/28 23:29:00 tobega
* Now handles media on Stylesheets, still need to handle at-media-rules. The media-type should be set in Context.media (set by default to "screen") before calling setContext on StyleReference.
*
* Revision 1.14 2004/11/15 22:22:08 tobega
* Now handles @import stylesheets
*
* Revision 1.13 2004/11/15 19:46:13 tobega
* Refactoring in preparation for handling @import stylesheets
*
* Revision 1.12 2004/11/15 12:42:22 pdoubleya
* Across this checkin (all may not apply to this particular file)
* Changed default/package-access members to private.
* Changed to use XRRuntimeException where appropriate.
* Began move from System.err.println to std logging.
* Standard code reformat.
* Removed some unnecessary SAC member variables that were only used in initialization.
* CVS log section.
*
*
*/

Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ public class IdentValue implements FSDerivedValue {
*/
public static final IdentValue COLUMN = addValue("column");

/**
* CSS footnotes for use in float: footnote
*/
public static final IdentValue FOOTNOTE = addValue("footnote");
public static final IdentValue FS_FOOTNOTE_BODY = addValue("-fs-footnote-body");

/**
* Constructor for the IdentValue object
*
Expand Down
Loading