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 15, 2024
1 parent 8c557ff commit 0cd9922
Show file tree
Hide file tree
Showing 151 changed files with 5,786 additions and 5,379 deletions.
11 changes: 7 additions & 4 deletions MIGRATING_FROM_BATIK.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Batik:

- Improved conformance to the SVG and CSS specifications.

- Better user experience (_e.g._ the `codec` classes that got merged into `transcoder`).
- Better user experience (_e.g._ the `codec` classes that got merged into
`transcoder`, or the cleaner module interdependencies).

- A circularity with Apache FOP. To render PDF images, Batik uses FOP which in
turn uses Batik, so depending on FOP would imply mixing EchoSVG and Batik. See
Expand All @@ -27,9 +28,8 @@ Batik:
2) Class names that included the name "Batik" now have "EchoSVG".

3) The `codec`-`transcoder` circular dependency was removed in the following way:
a few classes from the `codec` module were moved to two new packages in
`transcoder` (that aren't exported by that module). Now `transcoder` explicitly
depends on `codec` (but not the other way around).
a few classes from the `codec` module were moved to `transcoder`. Now
`transcoder` explicitly depends on `codec` (but not the other way around).

4) Tcl and Python 2.x scripting was removed (see issues [#12](https://github.com/css4j/echosvg/issues/12)
and [#13](https://github.com/css4j/echosvg/issues/13)). That scripting wasn't
Expand Down Expand Up @@ -65,3 +65,6 @@ Batik:

10) `SVGAnimationElementBridge.initializeAnimation()` gained a `BridgeContext`
argument and now returns a `boolean`.

11) The old and deprecated `CSSValue` API was replaced by an API close to W3C's
Typed OM.
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 Clinton Ingram, that are CC-licensed as
shown in the 'Compact-ICC-Profiles-license' 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
10 changes: 9 additions & 1 deletion echosvg-bridge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ dependencies {
api project(':echosvg-gvt')
api project(':echosvg-script')
api "io.sf.graphics:legacy-colors:${legacyColorsVersion}"
compileOnly "xml-apis:xml-apis:$xmlApisVersion" // Required by Java 8 compat
if (!project.getPluginManager().hasPlugin('eclipse')) {
compileOnly "xml-apis:xml-apis:$xmlApisVersion" // Required by Java 8 compat
}
testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

test {
useJUnitPlatform()
}

description = 'io.sf.carte:echosvg-bridge'
Expand Down
Loading

0 comments on commit 0cd9922

Please sign in to comment.