Skip to content

Commit

Permalink
Merge pull request #711 from danfickle/issue_364_footnotes
Browse files Browse the repository at this point in the history
Fixes #364 - Implement footnotes at bottom of page
  • Loading branch information
danfickle authored Sep 6, 2021
2 parents c876b67 + 594b840 commit b87ef1f
Show file tree
Hide file tree
Showing 101 changed files with 5,312 additions and 3,848 deletions.
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

0 comments on commit b87ef1f

Please sign in to comment.