Skip to content

Commit de4c3dc

Browse files
committed
svgom: make SVGStylable compatible with modern CSSOM and Typed OM
1 parent 172fe27 commit de4c3dc

File tree

7 files changed

+103
-10
lines changed

7 files changed

+103
-10
lines changed

cssom-api/src/main/java/org/w3c/css/om/CSSStyleDeclaration.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@
1212

1313
import org.w3c.css.om.typed.CSSStyleValue;
1414
import org.w3c.dom.DOMException;
15+
import org.w3c.dom.css.CSSValue;
1516

1617
/**
1718
* CSS style declaration.
1819
*/
19-
public interface CSSStyleDeclaration {
20+
public interface CSSStyleDeclaration extends org.w3c.dom.css.CSSStyleDeclaration {
2021

2122
/**
2223
* A parsable serialization of the declaration.
2324
*
2425
* @return the textual representation of the declaration.
2526
*/
27+
@Override
2628
String getCssText();
2729

2830
/**
@@ -31,6 +33,7 @@ public interface CSSStyleDeclaration {
3133
*
3234
* @param cssText the serialized style declaration.
3335
*/
36+
@Override
3437
void setCssText(String cssText) throws DOMException;
3538

3639
/**
@@ -40,6 +43,7 @@ public interface CSSStyleDeclaration {
4043
* @return the value of the removed property, or the empty string if that
4144
* property was not explicitly set in this declaration.
4245
*/
46+
@Override
4347
String removeProperty(String propertyName) throws DOMException;
4448

4549
/**
@@ -48,6 +52,7 @@ public interface CSSStyleDeclaration {
4852
* @param propertyName the name of the property.
4953
* @return the priority string, or the empty string if no priority was set.
5054
*/
55+
@Override
5156
String getPropertyPriority(String propertyName);
5257

5358
/**
@@ -57,13 +62,15 @@ public interface CSSStyleDeclaration {
5762
* @param value the property value.
5863
* @param priority the priority.
5964
*/
65+
@Override
6066
void setProperty(String propertyName, String value, String priority) throws DOMException;
6167

6268
/**
6369
* The number of properties in this declaration.
6470
*
6571
* @return the number of properties in this declaration.
6672
*/
73+
@Override
6774
int getLength();
6875

6976
/**
@@ -74,8 +81,27 @@ public interface CSSStyleDeclaration {
7481
* less than zero, or greater or equal to the length of this
7582
* declaration.
7683
*/
84+
@Override
7785
String item(int index);
7886

87+
/**
88+
* Used to retrieve the object representation of the value of a CSS property if
89+
* it has been explicitly set within this declaration block. This method returns
90+
* <code>null</code> if the property is a shorthand property. Shorthand property
91+
* values can only be accessed and modified as strings, using the
92+
* <code>getPropertyValue</code> and <code>setProperty</code> methods.
93+
*
94+
* @param propertyName The name of the CSS property. See the CSS property index.
95+
* @return Returns the value of the property if it has been explicitly set for
96+
* this declaration block. Returns <code>null</code> if the property has
97+
* not been set.
98+
*/
99+
@SuppressWarnings("exports")
100+
@Override
101+
default CSSValue getPropertyCSSValue(String propertyName) {
102+
return null;
103+
}
104+
79105
/**
80106
* Gets the object representation of the value of a CSS property if it has been
81107
* explicitly set for this declaration block.
@@ -109,6 +135,7 @@ default CSSStyleValue getCSSStyleValue(String propertyName) {
109135
* block, or the empty string if the property has not been set or is a shorthand
110136
* that could not be serialized.
111137
*/
138+
@Override
112139
String getPropertyValue(String propertyName);
113140

114141
/**
@@ -117,6 +144,7 @@ default CSSStyleValue getCSSStyleValue(String propertyName) {
117144
* @return the CSS rule that contains this declaration block or <code>null</code> if this
118145
* <code>CSSStyleDeclaration</code> is not attached to a <code>CSSRule</code>.
119146
*/
147+
@Override
120148
CSSRule getParentRule();
121149

122150
}

svgom-api/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44

55
dependencies {
66
api project(':smil-api')
7+
api project(':cssom-api')
78
}
89

910
description = 'io.sf.carte:svgom-api'

svgom-api/src/main/java/module-info.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
* [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
1111
*
1212
* Later modifications:
13-
* Copyright (c) 2020-2021 Carlos Amengual
13+
* Copyright (c) 2020-2024 Carlos Amengual
1414
*/
1515

1616
/**
1717
* Scalable Vector Graphics (SVG) Java binding.
1818
* <p>
1919
* This is a Java binding for an old version of the SVG DOM API (SVGOM). It is
20-
* compatible with the SVGOM API used by Apache Batik (which uses the SVGOM
21-
* packages at the <a href=
20+
* compatible with modern Typed OM but also with the legacy SVGOM API used by
21+
* Apache Batik (which uses the SVGOM packages at the <a href=
2222
* "http://archive.apache.org/dist/xml/commons/xml-commons-external-1.3.04-src.zip">{@code xml-apis-ext-1.3.04}</a>
2323
* package), that seem to be a mixture of the
2424
* <a href="http://www.w3.org/TR/2000/CR-SVG-20000802/java-binding.zip">SVG
@@ -28,12 +28,15 @@
2828
* </p>
2929
* <p>
3030
* Some method signatures were modified so they match the implementations in
31-
* Apache Batik/EchoSVG.
31+
* Apache Batik.
3232
* </p>
3333
*/
3434
module org.w3c.dom.svg {
35+
3536
exports org.w3c.dom.svg;
3637

3738
requires transitive jdk.xml.dom;
3839
requires transitive org.w3c.dom.smil;
40+
requires transitive org.w3c.css.om;
41+
3942
}

svgom-api/src/main/java/org/w3c/dom/svg/SVGColor.java

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ default RGBColor getRGBColor() {
3434
return null;
3535
}
3636

37+
@SuppressWarnings("removal")
3738
default SVGICCColor getICCColor() {
3839
return null;
3940
}

svgom-api/src/main/java/org/w3c/dom/svg/SVGPaint.java

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* ‘fill’ and ‘stroke’.
1818
*/
1919
@Deprecated
20+
@SuppressWarnings("removal")
2021
public interface SVGPaint extends SVGColor {
2122
// Paint Types
2223
public static final short SVG_PAINTTYPE_UNKNOWN = 0;

svgom-api/src/main/java/org/w3c/dom/svg/SVGStylable.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,24 @@
1212

1313
package org.w3c.dom.svg;
1414

15-
import org.w3c.dom.css.CSSStyleDeclaration;
1615
import org.w3c.dom.css.CSSValue;
1716

18-
public interface SVGStylable {
19-
public SVGAnimatedString getClassName();
17+
/**
18+
* This interface is implemented on all objects corresponding to SVG elements
19+
* that can have <code>style</code>, <code>class</code> and presentation
20+
* attributes specified on them.
21+
*/
22+
public interface SVGStylable extends SVGStylableP<CSSValue> {
2023

21-
public CSSStyleDeclaration getStyle();
24+
/**
25+
* Returns the base value of a given presentation attribute as an object.
26+
*
27+
* @param name the presentation attribute.
28+
* @return the given presentation attribute as an object.
29+
*/
30+
@Deprecated
31+
default CSSValue getPresentationAttribute(String name) {
32+
return null;
33+
}
2234

23-
public CSSValue getPresentationAttribute(String name);
2435
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2010 World Wide Web Consortium,
3+
*
4+
* (Massachusetts Institute of Technology, European Research Consortium for
5+
* Informatics and Mathematics, Keio University). All Rights Reserved. This
6+
* work is distributed under the W3C(r) Software License [1] in the hope that
7+
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
8+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9+
*
10+
* [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
11+
*/
12+
13+
package org.w3c.dom.svg;
14+
15+
import org.w3c.css.om.CSSStyleDeclaration;
16+
17+
/**
18+
* This interface is implemented on all objects corresponding to SVG elements
19+
* that can have <code>style</code>, <code>class</code> and presentation
20+
* attributes specified on them.
21+
*/
22+
public interface SVGStylableP<V> {
23+
24+
/**
25+
* Gets the attribute {@code class} on this element.
26+
*
27+
* @return the attribute {@code class}.
28+
*/
29+
SVGAnimatedString getClassName();
30+
31+
/**
32+
* Gets the inline style of this element.
33+
*
34+
* @return the inline style.
35+
*/
36+
CSSStyleDeclaration getStyle();
37+
38+
/**
39+
* Returns the base value of a given presentation attribute as an object of type
40+
* {@code V}.
41+
*
42+
* @param name the presentation attribute.
43+
* @return the given presentation attribute as an object.
44+
*/
45+
@Deprecated
46+
V getPresentationAttribute(String name);
47+
48+
}

0 commit comments

Comments
 (0)