Skip to content

Commit 32c1b99

Browse files
committed
1 parent 032af0c commit 32c1b99

4 files changed

Lines changed: 354 additions & 1 deletion

File tree

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ line-padding: org.w3c.css.properties.css3.CssLinePadding
206206
text-align: org.w3c.css.properties.css3.CssTextAlign
207207
text-align-all: org.w3c.css.properties.css3.CssTextAlignAll
208208
text-align-last: org.w3c.css.properties.css3.CssTextAlignLast
209+
text-autospace: org.w3c.css.properties.css3.CssTextAutospace
209210
text-indent: org.w3c.css.properties.css3.CssTextIndent
210211
text-justify: org.w3c.css.properties.css3.CssTextJustify
211212
text-transform: org.w3c.css.properties.css3.CssTextTransform
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 CssTextAutospace extends CssProperty {
18+
19+
/**
20+
* Create a new CssTextAutospace
21+
*/
22+
public CssTextAutospace() {
23+
}
24+
25+
/**
26+
* Creates a new CssTextAutospace
27+
*
28+
* @param expression The expression for this property
29+
* @throws InvalidParamException Expressions are incorrect
30+
*/
31+
public CssTextAutospace(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 CssTextAutospace(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-autospace";
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.cssTextAutospace != null) {
81+
style.addRedefinitionWarning(ac, this);
82+
}
83+
s.cssTextAutospace = 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 CssTextAutospace &&
94+
value.equals(((CssTextAutospace) 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).getTextAutospace();
107+
} else {
108+
return ((Css3Style) style).cssTextAutospace;
109+
}
110+
}
111+
}
112+

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@
262262
import org.w3c.css.properties.css.CssTabSize;
263263
import org.w3c.css.properties.css.CssTextAlignAll;
264264
import org.w3c.css.properties.css.CssTextAlignLast;
265+
import org.w3c.css.properties.css.CssTextAutospace;
265266
import org.w3c.css.properties.css.CssTextCombineUpright;
266267
import org.w3c.css.properties.css.CssTextDecorationColor;
267268
import org.w3c.css.properties.css.CssTextDecorationLine;
@@ -717,7 +718,17 @@ public class Css3Style extends ATSCStyle {
717718
public CssHyphenateLimitLast cssHyphenateLimitLast;
718719
public CssTextGroupAlign cssTextGroupAlign;
719720
public CssLinePadding cssLinePadding;
720-
721+
public CssTextAutospace cssTextAutospace;
722+
723+
public CssTextAutospace getTextAutospace() {
724+
if (cssTextAutospace == null) {
725+
cssTextAutospace =
726+
(CssTextAutospace) style.CascadingOrder(new CssTextAutospace(),
727+
style, selector);
728+
}
729+
return cssTextAutospace;
730+
}
731+
721732
public CssLinePadding getLinePadding() {
722733
if (cssLinePadding == null) {
723734
cssLinePadding =
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
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.properties.css.CssProperty;
9+
import org.w3c.css.util.ApplContext;
10+
import org.w3c.css.util.InvalidParamException;
11+
import org.w3c.css.values.CssExpression;
12+
import org.w3c.css.values.CssIdent;
13+
import org.w3c.css.values.CssTypes;
14+
import org.w3c.css.values.CssValue;
15+
import org.w3c.css.values.CssValueList;
16+
17+
import java.util.ArrayList;
18+
19+
import static org.w3c.css.values.CssOperator.SPACE;
20+
21+
/**
22+
* @spec https://www.w3.org/TR/2024/WD-css-text-4-20240219/#text-autospace-property
23+
*/
24+
public class CssTextAutospace extends org.w3c.css.properties.css.CssTextAutospace {
25+
26+
private static CssIdent[] allowed_values;
27+
private static CssIdent[] ideograph_axis, behaviour_axis;
28+
private static CssIdent single_val;
29+
30+
static {
31+
String[] id_values = {"normal", "auto", "no-autospace", "ideograph-alpha", "ideograph-numeric", "punctuation",
32+
"insert", "replace"};
33+
String[] id_axis = {"ideograph-alpha", "ideograph-numeric", "punctuation"};
34+
String[] be_axis = {"insert", "replace"};
35+
single_val = CssIdent.getIdent("no-autospace");
36+
allowed_values = new CssIdent[id_values.length];
37+
int i = 0;
38+
for (String s : id_values) {
39+
allowed_values[i++] = CssIdent.getIdent(s);
40+
}
41+
ideograph_axis = new CssIdent[id_axis.length];
42+
i = 0;
43+
for (String s : id_axis) {
44+
ideograph_axis[i++] = CssIdent.getIdent(s);
45+
}
46+
behaviour_axis = new CssIdent[be_axis.length];
47+
i = 0;
48+
for (String s : be_axis) {
49+
behaviour_axis[i++] = CssIdent.getIdent(s);
50+
}
51+
}
52+
53+
public static CssIdent getAllowedIdent(CssIdent ident) {
54+
for (CssIdent id : allowed_values) {
55+
if (id.equals(ident)) {
56+
return id;
57+
}
58+
}
59+
return null;
60+
}
61+
62+
public static CssIdent getAutospaceIdent(CssIdent ident) {
63+
if (single_val.equals(ident)) {
64+
return single_val;
65+
}
66+
for (CssIdent id : ideograph_axis) {
67+
if (id.equals(ident)) {
68+
return id;
69+
}
70+
}
71+
for (CssIdent id : behaviour_axis) {
72+
if (id.equals(ident)) {
73+
return id;
74+
}
75+
}
76+
return null;
77+
}
78+
79+
public static boolean isIdeographAxis(CssIdent ident) {
80+
for (CssIdent id : ideograph_axis) {
81+
if (id.equals(ident)) {
82+
return true;
83+
}
84+
}
85+
return false;
86+
}
87+
88+
public static boolean isBehaviourAxis(CssIdent ident) {
89+
for (CssIdent id : behaviour_axis) {
90+
if (id.equals(ident)) {
91+
return true;
92+
}
93+
}
94+
return false;
95+
}
96+
97+
/**
98+
* Create a new CssTextAutospace
99+
*/
100+
public CssTextAutospace() {
101+
value = initial;
102+
}
103+
104+
/**
105+
* Creates a new CssTextAutospace
106+
*
107+
* @param expression The expression for this property
108+
* @throws InvalidParamException Expressions are incorrect
109+
*/
110+
public CssTextAutospace(ApplContext ac, CssExpression expression, boolean check)
111+
throws InvalidParamException {
112+
CssIdent id;
113+
114+
setByUser();
115+
CssValue val = expression.getValue();
116+
117+
if (check && expression.getCount() > 4) {
118+
throw new InvalidParamException("unrecognize", ac);
119+
}
120+
121+
if (val.getType() != CssTypes.CSS_IDENT) {
122+
throw new InvalidParamException("value",
123+
expression.getValue(),
124+
getPropertyName(), ac);
125+
}
126+
id = val.getIdent();
127+
if (CssIdent.isCssWide(id)) {
128+
if (expression.getCount() > 1) {
129+
throw new InvalidParamException("value",
130+
expression.getValue(),
131+
getPropertyName(), ac);
132+
}
133+
value = val;
134+
expression.next();
135+
} else if (getAllowedIdent(id) != null) {
136+
// ident or <autospace>
137+
if (getAutospaceIdent(id) != null) {
138+
// <autospace>
139+
value = checkAutoSpace(ac, expression, this);
140+
} else {
141+
if (expression.getCount() > 1) {
142+
throw new InvalidParamException("value",
143+
expression.getValue(),
144+
getPropertyName(), ac);
145+
}
146+
value = val;
147+
expression.next();
148+
}
149+
} else {
150+
throw new InvalidParamException("value",
151+
expression.getValue(),
152+
getPropertyName(), ac);
153+
}
154+
155+
}
156+
157+
158+
public CssTextAutospace(ApplContext ac, CssExpression expression)
159+
throws InvalidParamException {
160+
this(ac, expression, false);
161+
}
162+
163+
// this function only check if the expression is an <autospace>
164+
public static CssValue checkAutoSpace(ApplContext ac, CssExpression expression, CssProperty caller)
165+
throws InvalidParamException {
166+
ArrayList<CssValue> values = new ArrayList<CssValue>();
167+
CssValue val;
168+
CssIdent id;
169+
char op;
170+
boolean got_behaviour = false;
171+
172+
if (expression.getCount() > 4) {
173+
throw new InvalidParamException("unrecognize", ac);
174+
}
175+
176+
while (!expression.end()) {
177+
val = expression.getValue();
178+
op = expression.getOperator();
179+
180+
if (val.getType() != CssTypes.CSS_IDENT) {
181+
throw new InvalidParamException("value",
182+
expression.getValue(),
183+
caller.getPropertyName(), ac);
184+
}
185+
id = val.getIdent();
186+
if (getAutospaceIdent(id) != null) {
187+
if (!isIdeographAxis(id) && !isBehaviourAxis(id)) {
188+
if (expression.getCount() > 1) {
189+
throw new InvalidParamException("value",
190+
expression.getValue(),
191+
caller.getPropertyName(), ac);
192+
}
193+
values.add(val);
194+
} else {
195+
// check we don't have two of those
196+
if (isBehaviourAxis(id)) {
197+
if (got_behaviour) {
198+
throw new InvalidParamException("value",
199+
expression.getValue(),
200+
caller.getPropertyName(), ac);
201+
} else {
202+
got_behaviour = true;
203+
}
204+
}
205+
// avoid duplicates. TODO is that a good enough check? See attr/var
206+
if (values.contains(id)) {
207+
throw new InvalidParamException("value",
208+
expression.getValue(),
209+
caller.getPropertyName(), ac);
210+
}
211+
values.add(val);
212+
}
213+
} else {
214+
throw new InvalidParamException("value",
215+
expression.getValue(),
216+
caller.getPropertyName(), ac);
217+
}
218+
if (op != SPACE) {
219+
throw new InvalidParamException("operator", op,
220+
caller.getPropertyName(), ac);
221+
}
222+
expression.next();
223+
}
224+
return (values.size() == 1) ? values.get(0) : new CssValueList(values);
225+
226+
}
227+
228+
}
229+

0 commit comments

Comments
 (0)