Skip to content

Commit 16eed8c

Browse files
committed
1 parent e95180c commit 16eed8c

File tree

4 files changed

+261
-0
lines changed

4 files changed

+261
-0
lines changed

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ text-emphasis-position: org.w3c.css.properties.css3.CssTextEmpha
227227
text-emphasis-style: org.w3c.css.properties.css3.CssTextEmphasisStyle
228228
text-group-align: org.w3c.css.properties.css3.CssTextGroupAlign
229229
text-size-adjust: org.w3c.css.properties.css3.CssTextSizeAdjust
230+
text-spacing: org.w3c.css.properties.css3.CssTextSpacing
230231
text-spacing-trim: org.w3c.css.properties.css3.CssTextSpacingTrim
231232
text-underline-offset: org.w3c.css.properties.css3.CssTextUnderlineOffset
232233
text-underline-position: org.w3c.css.properties.css3.CssTextUnderlinePosition
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT World Wide Web Consortium, 2024.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
package org.w3c.css.properties.css;
7+
8+
import org.w3c.css.parser.CssStyle;
9+
import org.w3c.css.properties.css3.Css3Style;
10+
import org.w3c.css.util.ApplContext;
11+
import org.w3c.css.util.InvalidParamException;
12+
import org.w3c.css.values.CssExpression;
13+
14+
/**
15+
* @since CSS3
16+
*/
17+
public class CssTextSpacing extends CssProperty {
18+
19+
/**
20+
* Create a new CssTextSpacing
21+
*/
22+
public CssTextSpacing() {
23+
}
24+
25+
/**
26+
* Creates a new CssTextSpacing
27+
*
28+
* @param expression The expression for this property
29+
* @throws InvalidParamException Expressions are incorrect
30+
*/
31+
public CssTextSpacing(ApplContext ac, CssExpression expression, boolean check)
32+
throws InvalidParamException {
33+
throw new InvalidParamException("value",
34+
expression.getValue().toString(),
35+
getPropertyName(), ac);
36+
}
37+
38+
public CssTextSpacing(ApplContext ac, CssExpression expression)
39+
throws InvalidParamException {
40+
this(ac, expression, false);
41+
}
42+
43+
/**
44+
* Returns the value of this property
45+
*/
46+
public Object get() {
47+
return value;
48+
}
49+
50+
51+
/**
52+
* Returns the name of this property
53+
*/
54+
public final String getPropertyName() {
55+
return "text-spacing";
56+
}
57+
58+
/**
59+
* Returns true if this property is "softly" inherited
60+
* e.g. his value is equals to inherit
61+
*/
62+
public boolean isSoftlyInherited() {
63+
return value.equals(inherit);
64+
}
65+
66+
/**
67+
* Returns a string representation of the object.
68+
*/
69+
public String toString() {
70+
return value.toString();
71+
}
72+
73+
/**
74+
* Add this property to the CssStyle.
75+
*
76+
* @param style The CssStyle
77+
*/
78+
public void addToStyle(ApplContext ac, CssStyle style) {
79+
Css3Style s = (Css3Style) style;
80+
if (s.cssTextSpacing != null) {
81+
style.addRedefinitionWarning(ac, this);
82+
}
83+
s.cssTextSpacing = this;
84+
}
85+
86+
87+
/**
88+
* Compares two properties for equality.
89+
*
90+
* @param property The other property.
91+
*/
92+
public boolean equals(CssProperty property) {
93+
return (property instanceof CssTextSpacing &&
94+
value.equals(((CssTextSpacing) property).value));
95+
}
96+
97+
98+
/**
99+
* Get this property in the style.
100+
*
101+
* @param style The style where the property is
102+
* @param resolve if true, resolve the style to find this property
103+
*/
104+
public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) {
105+
if (resolve) {
106+
return ((Css3Style) style).getTextSpacing();
107+
} else {
108+
return ((Css3Style) style).cssTextSpacing;
109+
}
110+
}
111+
}
112+

org/w3c/css/properties/css3/Css3Style.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@
283283
import org.w3c.css.properties.css.CssTextOrientation;
284284
import org.w3c.css.properties.css.CssTextOverflow;
285285
import org.w3c.css.properties.css.CssTextSizeAdjust;
286+
import org.w3c.css.properties.css.CssTextSpacing;
286287
import org.w3c.css.properties.css.CssTextSpacingTrim;
287288
import org.w3c.css.properties.css.CssTextUnderlineOffset;
288289
import org.w3c.css.properties.css.CssTextUnderlinePosition;
@@ -721,6 +722,16 @@ public class Css3Style extends ATSCStyle {
721722
public CssLinePadding cssLinePadding;
722723
public CssTextAutospace cssTextAutospace;
723724
public CssTextSpacingTrim cssTextSpacingTrim;
725+
public CssTextSpacing cssTextSpacing;
726+
727+
public CssTextSpacing getTextSpacing() {
728+
if (cssTextSpacing == null) {
729+
cssTextSpacing =
730+
(CssTextSpacing) style.CascadingOrder(new CssTextSpacing(),
731+
style, selector);
732+
}
733+
return cssTextSpacing;
734+
}
724735

725736
public CssTextSpacingTrim getTextSpacingTrim() {
726737
if (cssTextSpacingTrim == null) {
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT MIT, ERCIM, Keio University, Beihang, 2012.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
package org.w3c.css.properties.css3;
7+
8+
import org.w3c.css.util.ApplContext;
9+
import org.w3c.css.util.InvalidParamException;
10+
import org.w3c.css.values.CssExpression;
11+
import org.w3c.css.values.CssIdent;
12+
import org.w3c.css.values.CssTypes;
13+
import org.w3c.css.values.CssValue;
14+
import org.w3c.css.values.CssValueList;
15+
16+
import java.util.ArrayList;
17+
18+
import static org.w3c.css.values.CssOperator.SPACE;
19+
20+
/**
21+
* @spec https://www.w3.org/TR/2024/WD-css-text-4-20240219/#propdef-text-spacing
22+
* @see CssTextAutospace
23+
* @see CssTextSpacingTrim
24+
*/
25+
public class CssTextSpacing extends org.w3c.css.properties.css.CssTextSpacing {
26+
27+
private static CssIdent[] allowed_values;
28+
29+
static {
30+
String[] id_values = {"none", "auto"};
31+
allowed_values = new CssIdent[id_values.length];
32+
int i = 0;
33+
for (String s : id_values) {
34+
allowed_values[i++] = CssIdent.getIdent(s);
35+
}
36+
}
37+
38+
public static CssIdent getAllowedIdent(CssIdent ident) {
39+
for (CssIdent id : allowed_values) {
40+
if (id.equals(ident)) {
41+
return id;
42+
}
43+
}
44+
return null;
45+
}
46+
47+
48+
/**
49+
* Create a new CssTextSpacing
50+
*/
51+
public CssTextSpacing() {
52+
value = initial;
53+
}
54+
55+
/**
56+
* Creates a new CssTextSpacing
57+
*
58+
* @param expression The expression for this property
59+
* @throws InvalidParamException Expressions are incorrect
60+
*/
61+
public CssTextSpacing(ApplContext ac, CssExpression expression, boolean check)
62+
throws InvalidParamException {
63+
ArrayList<CssValue> values = new ArrayList<CssValue>();
64+
CssValue val;
65+
CssExpression spacexp = null;
66+
boolean has_trim = false;
67+
CssIdent id;
68+
char op;
69+
70+
setByUser();
71+
72+
while (!expression.end()) {
73+
val = expression.getValue();
74+
op = expression.getOperator();
75+
76+
if (val.getType() != CssTypes.CSS_IDENT) {
77+
throw new InvalidParamException("value",
78+
expression.getValue(),
79+
getPropertyName(), ac);
80+
}
81+
id = val.getIdent();
82+
if (CssIdent.isCssWide(id)) {
83+
if (expression.getCount() > 1) {
84+
throw new InvalidParamException("value",
85+
expression.getValue(),
86+
getPropertyName(), ac);
87+
}
88+
values.add(val);
89+
} else if (getAllowedIdent(id) != null) {
90+
// the single values
91+
if (expression.getCount() > 1) {
92+
throw new InvalidParamException("value",
93+
expression.getValue(),
94+
getPropertyName(), ac);
95+
}
96+
values.add(val);
97+
} else if (CssTextSpacingTrim.getSpacingTrimIdent(id) != null) {
98+
if (has_trim) {
99+
throw new InvalidParamException("value",
100+
expression.getValue(),
101+
getPropertyName(), ac);
102+
}
103+
has_trim = true;
104+
values.add(val);
105+
} else if (CssTextAutospace.getAutospaceIdent(id) != null) {
106+
if (spacexp == null) {
107+
spacexp = new CssExpression();
108+
}
109+
// FIXME one way would be to add _all_ the matching idents
110+
// FIXME then refuse new ones (as avoid values being mixed between
111+
// FIXME autospace and spacing-trim)
112+
spacexp.addValue(val);
113+
spacexp.setOperator(op);
114+
} else {
115+
throw new InvalidParamException("value",
116+
expression.getValue(),
117+
getPropertyName(), ac);
118+
}
119+
if (op != SPACE) {
120+
throw new InvalidParamException("operator", op,
121+
getPropertyName(), ac);
122+
}
123+
expression.next();
124+
}
125+
if (spacexp != null) {
126+
values.add(CssTextAutospace.checkAutoSpace(ac, spacexp, this));
127+
}
128+
value = (values.size() == 1) ? values.get(0) : new CssValueList(values);
129+
}
130+
131+
public CssTextSpacing(ApplContext ac, CssExpression expression)
132+
throws InvalidParamException {
133+
this(ac, expression, false);
134+
}
135+
136+
}
137+

0 commit comments

Comments
 (0)