Skip to content

Commit 6d481ca

Browse files
committed
1 parent 32c1b99 commit 6d481ca

4 files changed

Lines changed: 223 additions & 0 deletions

File tree

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-trim: org.w3c.css.properties.css3.CssTextSpacingTrim
230231
text-underline-offset: org.w3c.css.properties.css3.CssTextUnderlineOffset
231232
text-underline-position: org.w3c.css.properties.css3.CssTextUnderlinePosition
232233
text-wrap: org.w3c.css.properties.css3.CssTextWrap
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 CssTextSpacingTrim extends CssProperty {
18+
19+
/**
20+
* Create a new CssTextSpacingTrim
21+
*/
22+
public CssTextSpacingTrim() {
23+
}
24+
25+
/**
26+
* Creates a new CssTextSpacingTrim
27+
*
28+
* @param expression The expression for this property
29+
* @throws InvalidParamException Expressions are incorrect
30+
*/
31+
public CssTextSpacingTrim(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 CssTextSpacingTrim(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-trim";
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.cssTextSpacingTrim != null) {
81+
style.addRedefinitionWarning(ac, this);
82+
}
83+
s.cssTextSpacingTrim = 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 CssTextSpacingTrim &&
94+
value.equals(((CssTextSpacingTrim) 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).getTextSpacingTrim();
107+
} else {
108+
return ((Css3Style) style).cssTextSpacingTrim;
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.CssTextSpacingTrim;
286287
import org.w3c.css.properties.css.CssTextUnderlineOffset;
287288
import org.w3c.css.properties.css.CssTextUnderlinePosition;
288289
import org.w3c.css.properties.css.CssTextWrap;
@@ -719,6 +720,16 @@ public class Css3Style extends ATSCStyle {
719720
public CssTextGroupAlign cssTextGroupAlign;
720721
public CssLinePadding cssLinePadding;
721722
public CssTextAutospace cssTextAutospace;
723+
public CssTextSpacingTrim cssTextSpacingTrim;
724+
725+
public CssTextSpacingTrim getTextSpacingTrim() {
726+
if (cssTextSpacingTrim == null) {
727+
cssTextSpacingTrim =
728+
(CssTextSpacingTrim) style.CascadingOrder(new CssTextSpacingTrim(),
729+
style, selector);
730+
}
731+
return cssTextSpacingTrim;
732+
}
722733

723734
public CssTextAutospace getTextAutospace() {
724735
if (cssTextAutospace == null) {
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
15+
/**
16+
* @spec https://www.w3.org/TR/2024/WD-css-text-4-20240219/#propdef-text-spacing-trim
17+
*/
18+
public class CssTextSpacingTrim extends org.w3c.css.properties.css.CssTextSpacingTrim {
19+
20+
private static CssIdent[] allowed_values;
21+
private static CssIdent[] spacing_trim;
22+
23+
static {
24+
String[] id_values = {"space-all", "normal", "trim-auto", "trim-start", "space-first", "trim-all"};
25+
String[] other_values = {"auto"};
26+
allowed_values = new CssIdent[id_values.length + other_values.length];
27+
spacing_trim = new CssIdent[id_values.length];
28+
int i = 0;
29+
for (String s : id_values) {
30+
spacing_trim[i] = CssIdent.getIdent(s);
31+
allowed_values[i++] = CssIdent.getIdent(s);
32+
}
33+
for (String s : other_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+
public static CssIdent getSpacingTrimIdent(CssIdent ident) {
48+
for (CssIdent id : spacing_trim) {
49+
if (id.equals(ident)) {
50+
return id;
51+
}
52+
}
53+
return null;
54+
}
55+
56+
/**
57+
* Create a new CssTextSpacingTrim
58+
*/
59+
public CssTextSpacingTrim() {
60+
value = initial;
61+
}
62+
63+
/**
64+
* Creates a new CssTextSpacingTrim
65+
*
66+
* @param expression The expression for this property
67+
* @throws InvalidParamException Expressions are incorrect
68+
*/
69+
public CssTextSpacingTrim(ApplContext ac, CssExpression expression, boolean check)
70+
throws InvalidParamException {
71+
setByUser();
72+
CssValue val = expression.getValue();
73+
74+
if (check && expression.getCount() > 1) {
75+
throw new InvalidParamException("unrecognize", ac);
76+
}
77+
78+
if (val.getType() != CssTypes.CSS_IDENT) {
79+
throw new InvalidParamException("value",
80+
expression.getValue(),
81+
getPropertyName(), ac);
82+
}
83+
// ident, so inherit, or allowed value
84+
if (!CssIdent.isCssWide(val.getIdent()) && getAllowedIdent(val.getIdent()) == null) {
85+
throw new InvalidParamException("value",
86+
expression.getValue(),
87+
getPropertyName(), ac);
88+
}
89+
value = val;
90+
expression.next();
91+
}
92+
93+
public CssTextSpacingTrim(ApplContext ac, CssExpression expression)
94+
throws InvalidParamException {
95+
this(ac, expression, false);
96+
}
97+
98+
}
99+

0 commit comments

Comments
 (0)