Skip to content

Commit

Permalink
#493 Suppress warnings about SVG properties not being implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
danfickle committed Jul 19, 2020
1 parent 4a2cf8e commit 62ada2e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.openhtmltopdf.css.constants;

import java.util.Arrays;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;

/**
* This is a partial list of common SVG properties that are not present in
* the HTML renderer of this project. This list is here so we can suppress
* warnings for these properties.
*
* List from:
* https://css-tricks.com/svg-properties-and-css/
*/
public enum SVGProperty {
CLIP,
CLIP_PATH,
CLIP_RULE,
MASK,
FILTER,
STOP_COLOR,
STOP_OPACITY,
FILL,
FILL_RULE,
FILL_OPACITY,
MARKER,
MARKER_START,
MARKER_MID,
MARKER_END,
STROKE,
STROKE_DASHARRAY,
STROKE_DASHOFFSET,
STROKE_LINECAP,
STROKE_LINEJOIN,
STROKE_MITERLIMIT,
STROKE_OPACITY,
STROKE_WIDTH;

private static final Set<String> _set =
Arrays.stream(values())
.map(v -> v.name().toLowerCase(Locale.US).replace('_', '-'))
.collect(Collectors.toSet());

public static Set<String> properties() {
return _set;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.openhtmltopdf.css.constants.CSSName;
import com.openhtmltopdf.css.constants.MarginBoxName;
import com.openhtmltopdf.css.constants.SVGProperty;
import com.openhtmltopdf.css.extend.TreeResolver;
import com.openhtmltopdf.css.newmatch.Selector;
import com.openhtmltopdf.css.parser.property.PropertyBuilder;
Expand Down Expand Up @@ -1242,10 +1243,12 @@ private void pseudo(Selector selector) throws IOException {

private boolean checkCSSName(CSSName cssName, String propertyName) {
if (cssName == null) {
_errorHandler.error(
if (!SVGProperty.properties().contains(propertyName)) {
_errorHandler.error(
_URI,
propertyName + " is an unrecognized CSS property at line "
+ getCurrentLine() + ". Ignoring declaration.");
}
return false;
}

Expand Down

0 comments on commit 62ada2e

Please sign in to comment.