Skip to content

Commit

Permalink
Switch from the legacy CSSValue API to Typed OM
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosame committed Aug 12, 2024
1 parent 2499876 commit 921b8bb
Show file tree
Hide file tree
Showing 139 changed files with 5,577 additions and 4,949 deletions.
12 changes: 11 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ This product includes software developed at The Apache Software Foundation
(https://www.apache.org/) under the 'Apache Batik' project.

This software contains code from the World Wide Web Consortium (W3C) for the
Document Object Model API (DOM API) and SVG Document Type Definition (DTD).
Document Object Model API (DOM API).

This software contains code from the International Organisation for
Standardization for the definition of character entities used in the software's
documentation.

This software contains color profiles by Elle Stone, that are licensed as shown
in the 'ElleStone-legalcode.txt' file under the color profiles directory (bridge
module).

This product contains a Display P3 color profile that was made by Apple and was
obtained from color.org (ICC).

This product contains the ITU-R Recommendation BT.2020 color profile that was
also obtained from color.org (ICC).

This product includes images from the Tango Desktop Project
(Former website http://tango.freedesktop.org/ archived at
https://web.archive.org/web/20201024165718/http://tango-project.org/).
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/allowed-licenses.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
{
"moduleLicense": "Mozilla Public License, Version 2.0"
},
{
"moduleLicense": "W3C Software and Document Notice and License"
},
{
"moduleLicense": "MIT License"
}
Expand Down
8 changes: 7 additions & 1 deletion buildSrc/src/main/groovy/echosvg.java-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ repositories {
content {
includeGroup 'io.sf.carte'
includeGroup 'io.sf.graphics'
includeGroup 'io.sf.w3'
includeGroup 'io.sf.jclf'
}
}
Expand Down Expand Up @@ -121,7 +122,7 @@ tasks.register("${project.name}-jar-with-deps", Jar) {
// Provided by Java SE
exclude 'javax/**'
// Not used by EchoSVG
exclude 'org/w3c/css/**'
exclude 'org/w3c/css/sac/**'
// The next ones are provided by java.xml module
exclude 'org/w3c/dom/*'
exclude 'org/w3c/dom/bootstrap/**'
Expand All @@ -131,6 +132,11 @@ tasks.register("${project.name}-jar-with-deps", Jar) {
exclude 'org/w3c/dom/traversal/**'
exclude 'org/w3c/dom/views/**'
exclude 'org/xml/**'
// Provided by jdk.xml.dom module
exclude 'org/w3c/dom/css/**'
exclude 'org/w3c/dom/html/**'
exclude 'org/w3c/dom/stylesheets/**'
exclude 'org/w3c/dom/xpath/**'
// Modularity does not apply here
exclude 'module-info.class'
}
Expand Down
26 changes: 25 additions & 1 deletion echosvg-all/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ tasks.register('cloneRepos') {
refToCheckout: "v${svgomVersion}")
gitWebAPIs?.close()

def gitCSSAPIs = grgit.clone(dir: "$buildDir/repos/cssom-apis",
uri: 'https://github.com/css4j/cssom-apis.git',
refToCheckout: "v0.1")
gitCSSAPIs?.close()

def gitLegacyColors = grgit.clone(dir: "$buildDir/repos/legacy-colors",
uri: 'https://github.com/css4j/legacy-colors.git',
refToCheckout: "v${legacyColorsVersion}")
Expand Down Expand Up @@ -208,6 +213,18 @@ tasks.register('prepareModularSources') {
include(name: '**/*')
}
}

// CSSOM and DOM View APIs
ant.copy(todir: "$buildDir/src/org.w3c.css.om") {
fileset(dir: "$buildDir/repos/cssom-apis/cssom-api/src/main/java") {
include(name: '**/*')
}
}
ant.copy(todir: "$buildDir/src/org.w3c.dom.view") {
fileset(dir: "$buildDir/repos/cssom-apis/domview-api/src/main/java") {
include(name: '**/*')
}
}
}
}

Expand Down Expand Up @@ -243,6 +260,8 @@ tasks.register('modularJavadoc', Javadoc) {
"$buildDir/src/io.sf.carte.echosvg.util.gui",
"$buildDir/src/io.sf.carte.echosvg.xml",
"$buildDir/src/io.sf.graphics.legacy.colors",
"$buildDir/src/org.w3c.css.om",
"$buildDir/src/org.w3c.dom.view",
"$buildDir/src/org.w3c.dom.smil",
"$buildDir/src/org.w3c.dom.svg" ]
includes += '**/*.java'
Expand Down Expand Up @@ -282,7 +301,7 @@ tasks.register('uberjar', Jar) {
// Provided by Java SE
exclude 'javax/**'
// Not used by EchoSVG
exclude 'org/w3c/css/**'
exclude 'org/w3c/css/sac/**'
// The next ones are provided by java.xml module
exclude 'org/w3c/dom/*'
exclude 'org/w3c/dom/bootstrap/**'
Expand All @@ -292,6 +311,11 @@ tasks.register('uberjar', Jar) {
exclude 'org/w3c/dom/traversal/**'
exclude 'org/w3c/dom/views/**'
exclude 'org/xml/**'
// Provided by jdk.xml.dom module
exclude 'org/w3c/dom/css/**'
exclude 'org/w3c/dom/html/**'
exclude 'org/w3c/dom/stylesheets/**'
exclude 'org/w3c/dom/xpath/**'
// Modularity does not apply here
exclude 'module-info.class'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
import java.nio.charset.StandardCharsets;
import java.util.HashMap;

import org.w3c.css.om.CSSStyleDeclaration;
import org.w3c.css.om.CSSStyleSheet;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.CSSStyleSheet;
import org.w3c.dom.css.ViewCSS;
import org.w3c.dom.events.Event;
import org.w3c.dom.stylesheets.StyleSheet;
import org.w3c.dom.view.ViewCSS;

import io.sf.carte.doc.style.css.nsac.InputSource;
import io.sf.carte.doc.style.css.nsac.Parser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Locale;
import java.util.MissingResourceException;

import org.w3c.css.om.CSSStyleDeclaration;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Comment;
Expand All @@ -40,8 +41,6 @@
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.DocumentCSS;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.MutationEvent;
Expand Down Expand Up @@ -687,9 +686,9 @@ public void otherAnimationChanged(Element e, String type) {
// DocumentCSS ////////////////////////////////////////////////////////////

/**
* <b>DOM</b>: Implements {@link DocumentCSS#getOverrideStyle(Element,String)}.
* This does not implement {@code DocumentCSS#getOverrideStyle(Element,String)}
* anymore, as it does not support Typed OM.
*/
@Override
public CSSStyleDeclaration getOverrideStyle(Element elt, String pseudoElt) {
if (elt instanceof SVGStylableElement && pseudoElt == null) {
return ((SVGStylableElement) elt).getOverrideStyle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
import java.awt.geom.AffineTransform;
import java.util.List;

import org.w3c.css.om.CSSStyleDeclaration;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.DocumentCSS;
import org.w3c.dom.css.ViewCSS;
import org.w3c.dom.events.DocumentEvent;
import org.w3c.dom.events.Event;
import org.w3c.dom.stylesheets.DocumentStyle;
Expand All @@ -48,6 +46,8 @@
import org.w3c.dom.svg.SVGStringList;
import org.w3c.dom.svg.SVGTransform;
import org.w3c.dom.svg.SVGViewSpec;
import org.w3c.dom.view.DocumentCSS;
import org.w3c.dom.view.ViewCSS;
import org.w3c.dom.views.AbstractView;
import org.w3c.dom.views.DocumentView;

Expand Down Expand Up @@ -716,10 +716,6 @@ public DocumentView getDocument() {
return (DocumentView) getOwnerDocument();
}

/**
* <b>DOM</b>: Implements
* {@link org.w3c.dom.css.ViewCSS#getComputedStyle(Element,String)}.
*/
@Override
public CSSStyleDeclaration getComputedStyle(Element elt, String pseudoElt) {
AbstractView av = ((DocumentView) getOwnerDocument()).getDefaultView();
Expand Down Expand Up @@ -748,19 +744,11 @@ public boolean canDispatch(String namespaceURI, String type) throws DOMException

// DocumentCSS ////////////////////////////////////////////////////////////

/**
* <b>DOM</b>: Implements
* {@link org.w3c.dom.stylesheets.DocumentStyle#getStyleSheets()}.
*/
@Override
public StyleSheetList getStyleSheets() {
return ((DocumentStyle) getOwnerDocument()).getStyleSheets();
}

/**
* <b>DOM</b>: Implements
* {@link org.w3c.dom.css.DocumentCSS#getOverrideStyle(Element,String)}.
*/
@Override
public CSSStyleDeclaration getOverrideStyle(Element elt, String pseudoElt) {
return ((DocumentCSS) getOwnerDocument()).getOverrideStyle(elt, pseudoElt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
*/
package io.sf.carte.echosvg.anim.dom;

import org.w3c.css.om.CSSStyleDeclaration;
import org.w3c.css.om.typed.CSSStyleValue;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.CSSValue;
import org.w3c.dom.svg.SVGAnimatedString;

import io.sf.carte.echosvg.anim.values.AnimatableValue;
Expand All @@ -35,6 +35,7 @@
import io.sf.carte.echosvg.css.engine.SVGCSSEngine;
import io.sf.carte.echosvg.css.engine.StyleDeclarationProvider;
import io.sf.carte.echosvg.css.engine.StyleMap;
import io.sf.carte.echosvg.css.engine.value.AbstractValueModificationHandler;
import io.sf.carte.echosvg.css.engine.value.Value;
import io.sf.carte.echosvg.css.engine.value.svg.SVGColorManager;
import io.sf.carte.echosvg.css.engine.value.svg.SVGPaintManager;
Expand All @@ -48,8 +49,10 @@
* This class provides a common superclass for elements which implement
* SVGStylable.
*
* @author <a href="mailto:[email protected]">Stephane Hillion</a>
* @author For later modifications, see Git history.
* <p>
* Original author: <a href="mailto:[email protected]">Stephane Hillion</a>.
* For later modifications, see Git history.
* </p>
* @version $Id$
*/
public abstract class SVGStylableElement extends SVGOMElement implements CSSStylableElement {
Expand Down Expand Up @@ -227,7 +230,7 @@ public void updatePropertyValue(String pn, AnimatableValue val) {
public boolean useLinearRGBColorInterpolation() {
CSSEngine eng = ((SVGOMDocument) getOwnerDocument()).getCSSEngine();
Value v = eng.getComputedStyle(this, null, SVGCSSEngine.COLOR_INTERPOLATION_INDEX);
return v.getStringValue().charAt(0) == 'l';
return v.getIdentifierValue().charAt(0) == 'l';
}

/**
Expand Down Expand Up @@ -262,9 +265,6 @@ public void removeTargetListener(String ns, String an, boolean isCSS, AnimationT

// SVGStylable support ///////////////////////////////////////////////////

/**
* <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGStylable#getStyle()}.
*/
public CSSStyleDeclaration getStyle() {
if (style == null) {
CSSEngine eng = ((SVGOMDocument) getOwnerDocument()).getCSSEngine();
Expand All @@ -274,12 +274,8 @@ public CSSStyleDeclaration getStyle() {
return style;
}

/**
* <b>DOM</b>: Implements
* {@link org.w3c.dom.svg.SVGStylable#getPresentationAttribute(String)}.
*/
public CSSValue getPresentationAttribute(String name) {
CSSValue result = (CSSValue) getLiveAttributeValue(null, name);
public CSSStyleValue getPresentationAttributeValue(String name) {
CSSStyleValue result = (CSSStyleValue) getLiveAttributeValue(null, name);
if (result != null)
return result;

Expand Down Expand Up @@ -365,14 +361,14 @@ public class PresentationAttributeValue extends CSSOMValue implements LiveAttrib
public PresentationAttributeValue(CSSEngine eng, String prop) {
super(null);
valueProvider = this;
setModificationHandler(new AbstractModificationHandler() {
setModificationHandler(new AbstractValueModificationHandler() {
@Override
protected Value getValue() {
return PresentationAttributeValue.this.getValue();
}

@Override
public void textChanged(String text) throws DOMException {
protected void setPropertyText(String text) throws DOMException {
value = cssEngine.parsePropertyValue(SVGStylableElement.this, property, text);
mutate = true;
setAttributeNS(null, property, text);
Expand Down Expand Up @@ -468,14 +464,14 @@ public class PresentationAttributeColorValue extends CSSOMSVGColor
public PresentationAttributeColorValue(CSSEngine eng, String prop) {
super(null);
valueProvider = this;
setModificationHandler(new AbstractModificationHandler() {
setModificationHandler(new AbstractValueModificationHandler() {
@Override
protected Value getValue() {
return PresentationAttributeColorValue.this.getValue();
}

@Override
public void textChanged(String text) throws DOMException {
protected void setPropertyText(String text) throws DOMException {
value = cssEngine.parsePropertyValue(SVGStylableElement.this, property, text);
mutate = true;
setAttributeNS(null, property, text);
Expand Down Expand Up @@ -578,7 +574,7 @@ protected Value getValue() {
}

@Override
public void textChanged(String text) throws DOMException {
protected void setPropertyText(String text) throws DOMException {
value = cssEngine.parsePropertyValue(SVGStylableElement.this, property, text);
mutate = true;
setAttributeNS(null, property, text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,13 @@ public Stop createStop(BridgeContext ctx, Element gradientElement, Element stopE
// use default value
offset = 0f;
}
Color color = CSSUtilities.convertStopColor(stopElement, opacity, ctx);
Color color;
try {
color = CSSUtilities.convertStopColor(stopElement, opacity, ctx);
} catch (Exception ex) {
throw new BridgeException(ctx, stopElement, ex, ERR_CSS_VALUE_ERROR,
new Object[] { ex });
}

return new Stop(color, offset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ public Element getReferencedElement(Element e, String uri) {
*
* @param e the element interested in its viewport
*/
@Override
public Viewport getViewport(Element e) {
if (viewportStack != null) {
// building time
Expand Down Expand Up @@ -1896,11 +1897,9 @@ public boolean checkInteractiveElement(SVGDocument doc, Element e) {
*
* // Check if cursor property is set to something other than 'auto'. Value
* cursorValue = CSSUtilities.getComputedStyle (e, SVGCSSEngine.CURSOR_INDEX);
* if ((cursorValue != null) && (cursorValue.getCssValueType() ==
* CSSValue.CSS_PRIMITIVE_VALUE) && (cursorValue.getPrimitiveType() ==
* CSSPrimitiveValue.CSS_IDENT) &&
* (SVGConstants.SVG_AUTO_VALUE.equals(cursorValue.getStringValue()))) return
* true;
* if ((cursorValue != null) && (cursorValue.getPrimitiveType() == Type.IDENT)
* && (SVGConstants.SVG_AUTO_VALUE.equals(cursorValue.getIdentifierValue())))
* return true;
*/

// Check all the child elements for any of the above.
Expand Down
Loading

0 comments on commit 921b8bb

Please sign in to comment.