Skip to content

Commit e302a50

Browse files
committed
1 parent 53f265a commit e302a50

4 files changed

Lines changed: 241 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
@@ -196,6 +196,7 @@ word-wrap: org.w3c.css.properties.css3.CssOverflowW
196196
word-break: org.w3c.css.properties.css3.CssWordBreak
197197
hanging-punctuation: org.w3c.css.properties.css3.CssHangingPunctuation
198198
hyphenate-character: org.w3c.css.properties.css3.CssHyphenateCharacter
199+
hyphenate-limit-chars: org.w3c.css.properties.css3.CssHyphenateLimitChars
199200
hyphenate-limit-zone: org.w3c.css.properties.css3.CssHyphenateLimitZone
200201
hyphens: org.w3c.css.properties.css3.CssHyphens
201202
line-break: org.w3c.css.properties.css3.CssLineBreak
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 MIT, ERCIM, Keio, Beihang, 2022.
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 CssHyphenateLimitChars extends CssProperty {
18+
19+
/**
20+
* Create a new CssHyphenateLimitChars
21+
*/
22+
public CssHyphenateLimitChars() {
23+
}
24+
25+
/**
26+
* Creates a new CssHyphenateLimitChars
27+
*
28+
* @param expression The expression for this property
29+
* @throws InvalidParamException Expressions are incorrect
30+
*/
31+
public CssHyphenateLimitChars(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 CssHyphenateLimitChars(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 "hyphenate-limit-chars";
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.cssHyphenateLimitChars != null) {
81+
style.addRedefinitionWarning(ac, this);
82+
}
83+
s.cssHyphenateLimitChars = 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 CssHyphenateLimitChars &&
94+
value.equals(((CssHyphenateLimitChars) 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).getHyphenateLimitChars();
107+
} else {
108+
return ((Css3Style) style).cssHyphenateLimitChars;
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
@@ -53,6 +53,7 @@
5353
import org.w3c.css.properties.css.CssBorderEndEndRadius;
5454
import org.w3c.css.properties.css.CssBorderEndStartRadius;
5555
import org.w3c.css.properties.css.CssHyphenateCharacter;
56+
import org.w3c.css.properties.css.CssHyphenateLimitChars;
5657
import org.w3c.css.properties.css.CssHyphenateLimitZone;
5758
import org.w3c.css.properties.css.CssImageRendering;
5859
import org.w3c.css.properties.css.CssBorderImageSource;
@@ -707,7 +708,17 @@ public class Css3Style extends ATSCStyle {
707708
public CssWhiteSpaceTrim cssWhiteSpaceTrim;
708709
public CssHyphenateCharacter cssHyphenateCharacter;
709710
public CssHyphenateLimitZone cssHyphenateLimitZone;
711+
public CssHyphenateLimitChars cssHyphenateLimitChars;
710712

713+
public CssHyphenateLimitChars getHyphenateLimitChars() {
714+
if (cssHyphenateLimitChars == null) {
715+
cssHyphenateLimitChars =
716+
(CssHyphenateLimitChars) style.CascadingOrder(new CssHyphenateLimitChars(),
717+
style, selector);
718+
}
719+
return cssHyphenateLimitChars;
720+
}
721+
711722
public CssHyphenateLimitZone getHyphenateLimitZone() {
712723
if (cssHyphenateLimitZone == null) {
713724
cssHyphenateLimitZone =
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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.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-hyphenate-limit-chars
22+
*/
23+
public class CssHyphenateLimitChars extends org.w3c.css.properties.css.CssHyphenateLimitChars {
24+
25+
private final static CssIdent[] allowed_values;
26+
27+
static {
28+
String[] id_values = {"auto"};
29+
allowed_values = new CssIdent[id_values.length];
30+
int i = 0;
31+
for (String s : id_values) {
32+
allowed_values[i++] = CssIdent.getIdent(s);
33+
}
34+
}
35+
36+
public static CssIdent getAllowedIdent(CssIdent ident) {
37+
for (CssIdent id : allowed_values) {
38+
if (id.equals(ident)) {
39+
return id;
40+
}
41+
}
42+
return null;
43+
}
44+
45+
/**
46+
* Create a new CssHyphenateLimitChars
47+
*/
48+
public CssHyphenateLimitChars() {
49+
value = initial;
50+
}
51+
52+
/**
53+
* Creates a new CssHyphenateLimitChars
54+
*
55+
* @param expression The expression for this property
56+
* @throws InvalidParamException Expressions are incorrect
57+
*/
58+
public CssHyphenateLimitChars(ApplContext ac, CssExpression expression, boolean check)
59+
throws InvalidParamException {
60+
ArrayList<CssValue> values = new ArrayList<CssValue>();
61+
CssValue val;
62+
CssIdent id;
63+
char op;
64+
65+
setByUser();
66+
67+
if (check && expression.getCount() > 3) {
68+
throw new InvalidParamException("unrecognize", ac);
69+
}
70+
71+
while (!expression.end()) {
72+
val = expression.getValue();
73+
op = expression.getOperator();
74+
75+
switch (val.getType()) {
76+
case CssTypes.CSS_IDENT:
77+
if (CssIdent.isCssWide(val.getIdent())) {
78+
if (expression.getCount() > 1) {
79+
throw new InvalidParamException("value",
80+
expression.getValue(),
81+
getPropertyName(), ac);
82+
}
83+
values.add(val);
84+
break;
85+
}
86+
if (getAllowedIdent(val.getIdent()) != null) {
87+
values.add(val);
88+
break;
89+
}
90+
throw new InvalidParamException("value",
91+
expression.getValue(),
92+
getPropertyName(), ac);
93+
case CssTypes.CSS_NUMBER:
94+
val.getCheckableValue().checkInteger(ac, this);
95+
values.add(val);
96+
break;
97+
default:
98+
throw new InvalidParamException("value",
99+
expression.getValue(),
100+
getPropertyName(), ac);
101+
}
102+
if (op != SPACE) {
103+
throw new InvalidParamException("operator", op,
104+
getPropertyName(), ac);
105+
}
106+
expression.next();
107+
}
108+
value = (values.size() == 1) ? values.get(0) : new CssValueList(values);
109+
}
110+
111+
public CssHyphenateLimitChars(ApplContext ac, CssExpression expression)
112+
throws InvalidParamException {
113+
this(ac, expression, false);
114+
}
115+
116+
}
117+

0 commit comments

Comments
 (0)