Skip to content

Commit 3084572

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

File tree

8 files changed

+177
-18
lines changed

8 files changed

+177
-18
lines changed

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

Lines changed: 33 additions & 1 deletion
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,31 @@ 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+
* Gives the legacy object representation of the value of a CSS property if it
89+
* has been explicitly set within this declaration block.
90+
* <p>
91+
* This method returns <code>null</code> if the property is a shorthand
92+
* property. Shorthand property values can only be accessed and modified as
93+
* strings, using the <code>getPropertyValue</code> and <code>setProperty</code>
94+
* methods.
95+
* </p>
96+
*
97+
* @param propertyName The name of the CSS property.
98+
* @return the value of the property if it has been explicitly set for this
99+
* declaration block. Returns <code>null</code> if the property has not
100+
* been set, or the implementation does not support legacy object
101+
* values.
102+
*/
103+
@SuppressWarnings("exports")
104+
@Override
105+
default CSSValue getPropertyCSSValue(String propertyName) {
106+
return null;
107+
}
108+
79109
/**
80110
* Gets the object representation of the value of a CSS property if it has been
81111
* explicitly set for this declaration block.
@@ -109,6 +139,7 @@ default CSSStyleValue getCSSStyleValue(String propertyName) {
109139
* block, or the empty string if the property has not been set or is a shorthand
110140
* that could not be serialized.
111141
*/
142+
@Override
112143
String getPropertyValue(String propertyName);
113144

114145
/**
@@ -117,6 +148,7 @@ default CSSStyleValue getCSSStyleValue(String propertyName) {
117148
* @return the CSS rule that contains this declaration block or <code>null</code> if this
118149
* <code>CSSStyleDeclaration</code> is not attached to a <code>CSSRule</code>.
119150
*/
151+
@Override
120152
CSSRule getParentRule();
121153

122154
}

svgom-api/build.gradle

Lines changed: 1 addition & 0 deletions
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

Lines changed: 7 additions & 4 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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/SVGRect.java

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,82 @@
1414

1515
import org.w3c.dom.DOMException;
1616

17+
/**
18+
* Represents rectangular geometry.
19+
* <p>
20+
* Rectangles are defined as consisting of a (x,y) coordinate pair identifying a
21+
* minimum X value, a minimum Y value, and a width and height, which are usually
22+
* constrained to be non-negative.
23+
* </p>
24+
*/
1725
public interface SVGRect {
18-
public float getX();
1926

20-
public void setX(float x) throws DOMException;
27+
/**
28+
* The minimum X value.
29+
*
30+
* @return the minimum X value in user units.
31+
*/
32+
float getX();
33+
34+
/**
35+
* Sets the minimum X value.
36+
*
37+
* @param x the minimum X value in user units.
38+
* @throws DOMException NO_MODIFICATION_ALLOWED_ERR if the rectangle corresponds
39+
* to a read only attribute or when the object itself is
40+
* read only.
41+
*/
42+
void setX(float x) throws DOMException;
43+
44+
/**
45+
* The minimum Y value.
46+
*
47+
* @return the minimum Y value in user units.
48+
*/
49+
float getY();
2150

22-
public float getY();
51+
/**
52+
* Sets the minimum Y value.
53+
*
54+
* @param y the minimum Y value in user units.
55+
* @throws DOMException NO_MODIFICATION_ALLOWED_ERR if the rectangle corresponds
56+
* to a read only attribute or when the object itself is
57+
* read only.
58+
*/
59+
void setY(float y) throws DOMException;
2360

24-
public void setY(float y) throws DOMException;
61+
/**
62+
* The width.
63+
*
64+
* @return the width in user units.
65+
*/
66+
float getWidth();
2567

26-
public float getWidth();
68+
/**
69+
* Sets the width of the rectangle.
70+
*
71+
* @param width the width in user units.
72+
* @throws DOMException NO_MODIFICATION_ALLOWED_ERR if the rectangle corresponds
73+
* to a read only attribute or when the object itself is
74+
* read only.
75+
*/
76+
void setWidth(float width) throws DOMException;
2777

28-
public void setWidth(float width) throws DOMException;
78+
/**
79+
* The height.
80+
*
81+
* @return the height in user units.
82+
*/
83+
float getHeight();
2984

30-
public float getHeight();
85+
/**
86+
* Sets the height of the rectangle.
87+
*
88+
* @param height the height in user units.
89+
* @throws DOMException NO_MODIFICATION_ALLOWED_ERR if the rectangle corresponds
90+
* to a read only attribute or when the object itself is
91+
* read only.
92+
*/
93+
void setHeight(float height) throws DOMException;
3194

32-
public void setHeight(float height) throws DOMException;
3395
}

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

Lines changed: 16 additions & 5 deletions
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
}
Lines changed: 48 additions & 0 deletions
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)