Skip to content

Commit

Permalink
#364 Very early proof-of-concept for footnotes.
Browse files Browse the repository at this point in the history
Still needs loads of work but sample is rendering something.
  • Loading branch information
danfickle committed May 26, 2021
1 parent 630842f commit 30e19b3
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 677 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,18 @@ public CascadedStyle getPECascadedStyle(Object e, String pseudoElement) {
}

public PageInfo getPageCascadedStyle(String pageName, String pseudoPage) {
List<PropertyDeclaration> props = new ArrayList<>();
List<PropertyDeclaration> props = new ArrayList<>();
Map<MarginBoxName, List<PropertyDeclaration>> marginBoxes = new HashMap<>();
List<PropertyDeclaration> footnote = new ArrayList<>();

for (PageRule pageRule : _pageRules) {
if (pageRule.applies(pageName, pseudoPage)) {
props.addAll(pageRule.getRuleset().getPropertyDeclarations());
marginBoxes.putAll(pageRule.getMarginBoxes());

if (pageRule.getFootnoteAreaProperties() != null) {
footnote.addAll(pageRule.getFootnoteAreaProperties());
}
}
}

Expand All @@ -128,7 +133,7 @@ public PageInfo getPageCascadedStyle(String pageName, String pseudoPage) {
style = new CascadedStyle(props.iterator());
}

return new PageInfo(props, style, marginBoxes);
return new PageInfo(props, style, marginBoxes, footnote);
}

public List<FontFaceRule> getFontFaceRules() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,36 @@
package com.openhtmltopdf.css.newmatch;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.openhtmltopdf.css.constants.CSSName;
import com.openhtmltopdf.css.constants.IdentValue;
import com.openhtmltopdf.css.constants.MarginBoxName;
import com.openhtmltopdf.css.parser.CSSPrimitiveValue;
import com.openhtmltopdf.css.parser.PropertyValue;
import com.openhtmltopdf.css.sheet.PropertyDeclaration;
import com.openhtmltopdf.css.sheet.StylesheetInfo;

public class PageInfo {
private final List<PropertyDeclaration> _properties;
private final CascadedStyle _pageStyle;
private final Map<MarginBoxName, List<PropertyDeclaration>> _marginBoxes;


private final List<PropertyDeclaration> _properties;
private final List<PropertyDeclaration> _xmpPropertyList;

public PageInfo(List<PropertyDeclaration> properties, CascadedStyle pageStyle, Map<MarginBoxName, List<PropertyDeclaration>> marginBoxes) {
private final List<PropertyDeclaration> _footnote;

public PageInfo(
List<PropertyDeclaration> properties,
CascadedStyle pageStyle,
Map<MarginBoxName, List<PropertyDeclaration>> marginBoxes,
List<PropertyDeclaration> footnote) {
_properties = properties;
_pageStyle = pageStyle;
_marginBoxes = marginBoxes;

_footnote = footnote;

_xmpPropertyList = marginBoxes.remove(MarginBoxName.FS_PDF_XMP_METADATA);
}

Expand All @@ -56,10 +64,25 @@ public CascadedStyle getPageStyle() {
public List<PropertyDeclaration> getProperties() {
return _properties;
}


public CascadedStyle createFootnoteAreaStyle() {
if (_footnote == null || _footnote.isEmpty()) {
return new CascadedStyle(Collections.singletonList(
CascadedStyle.createLayoutPropertyDeclaration(CSSName.DISPLAY, IdentValue.BLOCK)).iterator());
}

List<PropertyDeclaration> all = new ArrayList<>(2 + _footnote.size());

all.add(CascadedStyle.createLayoutPropertyDeclaration(CSSName.POSITION, IdentValue.ABSOLUTE));
all.add(CascadedStyle.createLayoutPropertyDeclaration(CSSName.DISPLAY, IdentValue.BLOCK));
all.addAll(this._footnote);

return new CascadedStyle(all.iterator());
}

public CascadedStyle createMarginBoxStyle(MarginBoxName marginBox, boolean alwaysCreate) {
List<PropertyDeclaration> marginProps = _marginBoxes.get(marginBox);

if ((marginProps == null || marginProps.size() == 0) && ! alwaysCreate) {
return null;
}
Expand Down Expand Up @@ -97,9 +120,8 @@ public boolean hasAny(MarginBoxName[] marginBoxes) {

return false;
}

public List<PropertyDeclaration> getXMPPropertyList()
{

public List<PropertyDeclaration> getXMPPropertyList() {
return _xmpPropertyList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,14 @@ private void margin(Stylesheet stylesheet, PageRule pageRule) throws IOException
}
String name = getTokenValue(t);
MarginBoxName marginBoxName = MarginBoxName.valueOf(name);
if (marginBoxName == null) {
if (marginBoxName == null && !"footnote".equals(name)) {
error(new CSSParseException(name + " is not a valid margin box name", getCurrentLine()), "at rule", true);
recover(true, false);
return;
}

boolean isFootnoteRule = "footnote".equals(name);

skip_whitespace();
try {
t = next();
Expand All @@ -590,7 +592,12 @@ private void margin(Stylesheet stylesheet, PageRule pageRule) throws IOException
push(t);
throw new CSSParseException(t, Token.TK_RBRACE, getCurrentLine());
}
pageRule.addMarginBoxProperties(marginBoxName, ruleset.getPropertyDeclarations());

if (isFootnoteRule) {
pageRule.addFootnoteAreaProperties(ruleset.getPropertyDeclarations());
} else {
pageRule.addMarginBoxProperties(marginBoxName, ruleset.getPropertyDeclarations());
}
} else {
push(t);
throw new CSSParseException(t, Token.TK_LBRACE, getCurrentLine());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.openhtmltopdf.css.sheet;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -32,7 +33,9 @@ public class PageRule implements RulesetContainer {
private int _origin;

private final Map<MarginBoxName,List<PropertyDeclaration>> _marginBoxes = new HashMap<>();


private List<PropertyDeclaration> _footnoteArea = null;

private int _pos;

private int _specificityF;
Expand Down Expand Up @@ -137,4 +140,12 @@ public int getPos() {
public void setPos(int pos) {
_pos = pos;
}

public void addFootnoteAreaProperties(List<PropertyDeclaration> propertyDeclarations) {
this._footnoteArea = propertyDeclarations;
}

public List<PropertyDeclaration> getFootnoteAreaProperties() {
return this._footnoteArea;
}
}
Loading

0 comments on commit 30e19b3

Please sign in to comment.