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

[#712] Optional Content (aka PDF Layers) implementation #819

Open
wants to merge 7 commits into
base: open-dev-v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -36,6 +36,7 @@
import com.openhtmltopdf.css.extend.lib.DOMTreeResolver;
import com.openhtmltopdf.css.newmatch.CascadedStyle;
import com.openhtmltopdf.css.newmatch.PageInfo;
import com.openhtmltopdf.css.newmatch.Selector;
import com.openhtmltopdf.css.parser.CSSPrimitiveValue;
import com.openhtmltopdf.css.sheet.PropertyDeclaration;
import com.openhtmltopdf.css.sheet.Stylesheet;
Expand Down Expand Up @@ -85,6 +86,10 @@ public CalculatedStyle getRootElementStyle() {
}
}

public List<Selector> getSelectors() {
return _matcher.getSelectors();
}

/**
* Sets the documentContext attribute of the StyleReference object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,87 @@ public final class CSSName implements Comparable<CSSName> {
new PrimitivePropertyBuilders.FSKeepWithInline()
);

/**
* Layer identifier (document-scoped).
*/
public final static CSSName FS_OCG_ID =
addProperty(
"-fs-ocg-id",
PRIMITIVE,
IdentValue.NONE.asString(),
NOT_INHERITED,
new PrimitivePropertyBuilders.FSOcId()
);
/**
* Layer name, suitable for UI presentation (see {@code Name} entry in optional content group
* dictionary [ISO:32000-1:8.11.2.1]).
*/
public final static CSSName FS_OCG_LABEL =
addProperty(
"-fs-ocg-label",
PRIMITIVE,
IdentValue.NONE.asString(),
NOT_INHERITED,
new PrimitivePropertyBuilders.FSOcgLabel()
);
/**
* Layer parent {@link #FS_OCG_ID reference}.
*/
public final static CSSName FS_OCG_PARENT =
addProperty(
"-fs-ocg-parent",
PRIMITIVE,
IdentValue.NONE.asString(),
NOT_INHERITED,
new PrimitivePropertyBuilders.FSOcId()
);
/**
* Layer visibility.
*/
public final static CSSName FS_OCG_VISIBILITY =
addProperty(
"-fs-ocg-visibility",
PRIMITIVE,
IdentValue.VISIBLE.asString(),
NOT_INHERITED,
new PrimitivePropertyBuilders.FSOcgVisibility()
);
/**
* Layer membership identifier (document-scoped).
*/
public final static CSSName FS_OCM_ID =
addProperty(
"-fs-ocm-id",
PRIMITIVE,
IdentValue.NONE.asString(),
NOT_INHERITED,
new PrimitivePropertyBuilders.FSOcId()
);
/**
* Layer visibility policy (see {@code BaseState}, {@code ON}, {@code OFF} entries in {@code D}
* entry in optional content configuration dictionary [ISO:32000-1:8.11.4.3]).
*/
public final static CSSName FS_OCM_VISIBLE =
addProperty(
"-fs-ocm-visible",
PRIMITIVE,
IdentValue.ANY_VISIBLE.asString(),
NOT_INHERITED,
new PrimitivePropertyBuilders.FSOcmVisible()
);
/**
* Layers belonging to the membership.
*
* <p>Value: list of {@link #FS_OCG_ID layer references}.</p>
*/
public final static CSSName FS_OCM_OCGS =
addProperty(
"-fs-ocm-ocgs",
PRIMITIVE,
IdentValue.NONE.asString(),
NOT_INHERITED,
new PrimitivePropertyBuilders.FSOcIds());

/**
* Unique CSSName instance for CSS2 property.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ public class IdentValue implements FSDerivedValue {
public final int FS_ID;

public final static IdentValue ABSOLUTE = addValue("absolute");
public final static IdentValue ALL_HIDDEN = addValue("all-hidden");
public final static IdentValue ALL_VISIBLE = addValue("all-visible");
public final static IdentValue ALWAYS = addValue("always");
public final static IdentValue ANY_HIDDEN = addValue("any-hidden");
public final static IdentValue ANY_VISIBLE = addValue("any-visible");
public final static IdentValue ARMENIAN = addValue("armenian");
public final static IdentValue AUTO = addValue("auto");
public final static IdentValue AVOID = addValue("avoid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ public PageInfo getPageCascadedStyle(String pageName, String pseudoPage) {
public List<FontFaceRule> getFontFaceRules() {
return _fontFaceRules;
}

public List<Selector> getSelectors() {
return docMapper.axes;
}

public boolean isVisitedStyled(Object e) {
return _visitElements.contains(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,51 @@ protected BitSet getAllowed() {
return BORDER_STYLES;
}
}


private static class GenericString extends AbstractPropertyBuilder {
private static final BitSet ALLOWED = setFor(
new IdentValue[] { IdentValue.NONE });

@Override
public List<PropertyDeclaration> buildDeclarations(
CSSName cssName, List<PropertyValue> values, int origin, boolean important, boolean inheritAllowed) {
checkValueCount(cssName, 1, values.size());
return Collections.singletonList(
checkDeclaration(cssName, values.get(0), origin, important, inheritAllowed));
}

protected PropertyDeclaration checkDeclaration(
CSSName cssName, CSSPrimitiveValue value, int origin, boolean important, boolean inheritAllowed) {
checkInheritAllowed(value, inheritAllowed);
if (value.getCssValueType() != CSSValue.CSS_INHERIT) {
switch (value.getPrimitiveType()) {
case CSSPrimitiveValue.CSS_STRING:
/* NOOP: Any custom string value accepted. */
break;
case CSSPrimitiveValue.CSS_IDENT:
IdentValue ident = checkIdent(cssName, value);
checkValidity(cssName, ALLOWED, ident);
break;
default:
throw new CSSParseException("Value '" + value + "' is invalid for " + cssName, -1);
}
}
return new PropertyDeclaration(cssName, value, important, origin);
}
}

private static class GenericStrings extends GenericString {
@Override
public List<PropertyDeclaration> buildDeclarations(
CSSName cssName, List<PropertyValue> values, int origin, boolean important, boolean inheritAllowed) {
List<PropertyDeclaration> declarations = new ArrayList<>();
for (PropertyValue value : values) {
declarations.add(checkDeclaration(cssName, value, origin, important, inheritAllowed));
}
return Collections.unmodifiableList(declarations);
}
}

public static class Direction extends SingleIdent {
@Override
protected BitSet getAllowed() {
Expand Down Expand Up @@ -1014,6 +1058,38 @@ protected BitSet getAllowed() {
}
}

public static class FSOcgLabel extends GenericString {
}

public static class FSOcgVisibility extends SingleIdent {
private static final BitSet ALLOWED = setFor(
new IdentValue[] {
IdentValue.VISIBLE, IdentValue.HIDDEN });

@Override
protected BitSet getAllowed() {
return ALLOWED;
}
}

public static class FSOcId extends GenericString {
}

public static class FSOcIds extends GenericStrings {
};

public static class FSOcmVisible extends SingleIdent {
private static final BitSet ALLOWED = setFor(
new IdentValue[] {
IdentValue.ALL_HIDDEN, IdentValue.ALL_VISIBLE, IdentValue.ANY_HIDDEN,
IdentValue.ANY_VISIBLE });

@Override
protected BitSet getAllowed() {
return ALLOWED;
}
}

public static class Left extends LengthLikeWithAuto {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,11 @@ public void addInvalidProperty(InvalidPropertyDeclaration invalidPropertyDeclara
public List<InvalidPropertyDeclaration> getInvalidPropertyDeclarations() {
return _invalidProperties == null ? Collections.emptyList() : _invalidProperties;
}

@Override
public String toString() {
StringBuilder b=new StringBuilder();
toCSS(b);
return b.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ public void paintBackground(RenderingContext c, Box box) {
paintBackground0(c, box.getStyle(), backgroundBounds, backgroundBounds, border);
}

protected void onBackgroundPaint(RenderingContext c, CalculatedStyle style,
Rectangle backgroundBounds, Rectangle bgImageContainer,
BorderPropertySet border) {
}

private void paintBackground0(
RenderingContext c, CalculatedStyle style,
Rectangle backgroundBounds, Rectangle bgImageContainer,
Expand All @@ -240,6 +245,8 @@ private void paintBackground0(
return;
}

onBackgroundPaint(c, style, backgroundBounds, bgImageContainer, border);

FSColor backgroundColor = style.getBackgroundColor();
List<BackgroundContainer> bgImages = style.getBackgroundImages();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ private void paintBackgroundAndBorders(RenderingContext c, List<DisplayListItem>
box.paintBackground(c);
box.paintBorder(c);

c.getOutputDevice().endStructure(innerToken);
c.getOutputDevice().endStructure(outerToken);

if (collapsedTableBorders != null && box instanceof TableCellBox) {
TableCellBox cell = (TableCellBox) box;

Expand All @@ -88,9 +91,6 @@ private void paintBackgroundAndBorders(RenderingContext c, List<DisplayListItem>
}
}
}

c.getOutputDevice().endStructure(innerToken);
c.getOutputDevice().endStructure(outerToken);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ enum LogMessageId1Param implements LogMessageId {
GENERAL_PDF_ACCESSIBILITY_NO_TITLE_TEXT_PROVIDED_FOR(XRLog.GENERAL, "PDF/UA - No title text provided for {}."),
GENERAL_PDF_COULD_NOT_FIND_VALID_TARGET_FOR_BOOKMARK(XRLog.GENERAL, "Could not find valid target for bookmark. Bookmark href = {}"),
GENERAL_PDF_COULD_NOT_FIND_VALID_TARGET_FOR_LINK(XRLog.GENERAL, "Could not find valid target for link. Link href = {}"),
GENERAL_PDF_LAYER_END(XRLog.GENERAL, "OC: {} END"),
GENERAL_PDF_URI_IN_HREF_IS_NOT_A_VALID_URI(XRLog.GENERAL, "'{}' in href is not a valid URI, will be skipped"),
GENERAL_PDF_FOUND_FORM_CONTROL_WITH_NO_ENCLOSING_FORM(XRLog.GENERAL, "Found form control ({}) with no enclosing form. Ignoring."),
GENERAL_PDF_A_ELEMENT_DOES_NOT_HAVE_OPTION_CHILDREN(XRLog.GENERAL, "A <{}> element does not have <option> children"),
Expand Down Expand Up @@ -278,6 +279,12 @@ enum LogMessageId3Param implements LogMessageId {
", parent type={}" +
", expected child type={}" +
". Document will not be PDF/UA compliant."),
GENERAL_PDF_LAYER_BEGIN(XRLog.GENERAL, "OC: {} BEGIN (" +
"box type={}" +
", element={})"),
GENERAL_PDF_LAYER_CONTINUE(XRLog.GENERAL, "OC: {} CONTINUE (" +
"box type={}" +
", element={})"),

EXCEPTION_URI_WITH_BASE_URI_INVALID(XRLog.EXCEPTION, "When trying to load uri({}) with base {} URI({}), one or both were invalid URIs."),
EXCEPTION_SVG_SCRIPT_NOT_ALLOWED(XRLog.EXCEPTION, "Tried to run script inside SVG. Refusing. Details: {}, {}, {}");
Expand Down
Loading