|
11 | 11 | import org.w3c.css.values.CssIdent;
|
12 | 12 | import org.w3c.css.values.CssTypes;
|
13 | 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; |
14 | 19 |
|
15 | 20 | /**
|
16 |
| - * @spec https://www.w3.org/TR/2021/CRD-css-text-3-20210422/#propdef-text-justify |
| 21 | + * @spec https://www.w3.org/TR/2024/WD-css-text-4-20240219/#text-justify-property |
17 | 22 | */
|
18 | 23 | public class CssTextJustify extends org.w3c.css.properties.css.CssTextJustify {
|
19 | 24 |
|
20 | 25 | private static CssIdent[] allowed_values;
|
| 26 | + private static CssIdent no_compress, distribute; |
21 | 27 |
|
22 | 28 | static {
|
23 |
| - String id_values[] = {"auto", "none", "inter-word", "inter-character"}; |
| 29 | + no_compress = CssIdent.getIdent("no-compress"); |
| 30 | + distribute = CssIdent.getIdent("distribute"); |
| 31 | + String id_values[] = {"auto", "none", "inter-word", "inter-character", "ruby", "distribute"}; |
24 | 32 | allowed_values = new CssIdent[id_values.length];
|
25 | 33 | int i = 0;
|
26 | 34 | for (String s : id_values) {
|
@@ -52,28 +60,66 @@ public CssTextJustify() {
|
52 | 60 | */
|
53 | 61 | public CssTextJustify(ApplContext ac, CssExpression expression, boolean check)
|
54 | 62 | throws InvalidParamException {
|
| 63 | + ArrayList<CssValue> values = new ArrayList<CssValue>(); |
| 64 | + CssValue val; |
| 65 | + CssExpression trimexp = null; |
| 66 | + CssIdent id; |
| 67 | + boolean got_no_compress = false; |
| 68 | + char op; |
| 69 | + |
55 | 70 | setByUser();
|
56 |
| - CssValue val = expression.getValue(); |
57 | 71 |
|
58 |
| - if (check && expression.getCount() > 1) { |
| 72 | + if (check && expression.getCount() > 2) { |
59 | 73 | throw new InvalidParamException("unrecognize", ac);
|
60 | 74 | }
|
61 | 75 |
|
62 |
| - if (val.getType() != CssTypes.CSS_IDENT) { |
63 |
| - throw new InvalidParamException("value", |
64 |
| - expression.getValue(), |
65 |
| - getPropertyName(), ac); |
66 |
| - } |
67 |
| - // ident, so inherit, or allowed value |
68 |
| - CssIdent id = val.getIdent(); |
| 76 | + while (!expression.end()) { |
| 77 | + val = expression.getValue(); |
| 78 | + op = expression.getOperator(); |
69 | 79 |
|
70 |
| - if (!CssIdent.isCssWide(id) && (getMatchingIdent(id) == null)) { |
71 |
| - throw new InvalidParamException("value", |
72 |
| - expression.getValue(), |
73 |
| - getPropertyName(), ac); |
| 80 | + if (val.getType() != CssTypes.CSS_IDENT) { |
| 81 | + throw new InvalidParamException("value", |
| 82 | + expression.getValue(), |
| 83 | + getPropertyName(), ac); |
| 84 | + } |
| 85 | + id = val.getIdent(); |
| 86 | + if (CssIdent.isCssWide(id)) { |
| 87 | + if (expression.getCount() > 1) { |
| 88 | + throw new InvalidParamException("value", |
| 89 | + expression.getValue(), |
| 90 | + getPropertyName(), ac); |
| 91 | + } |
| 92 | + values.add(val); |
| 93 | + } else if (id.equals(no_compress)) { |
| 94 | + if (got_no_compress) { |
| 95 | + throw new InvalidParamException("value", |
| 96 | + expression.getValue(), |
| 97 | + getPropertyName(), ac); |
| 98 | + } |
| 99 | + got_no_compress = true; |
| 100 | + values.add(val); |
| 101 | + } else if (getMatchingIdent(id) != null) { |
| 102 | + if (!got_no_compress && !values.isEmpty()) { |
| 103 | + throw new InvalidParamException("value", |
| 104 | + expression.getValue(), |
| 105 | + getPropertyName(), ac); |
| 106 | + } |
| 107 | + values.add(val); |
| 108 | + if (distribute.equals(id)) { |
| 109 | + ac.getFrame().addWarning("deprecated", distribute.toString()); |
| 110 | + } |
| 111 | + } else { |
| 112 | + throw new InvalidParamException("value", |
| 113 | + expression.getValue(), |
| 114 | + getPropertyName(), ac); |
| 115 | + } |
| 116 | + if (op != SPACE) { |
| 117 | + throw new InvalidParamException("operator", op, |
| 118 | + getPropertyName(), ac); |
| 119 | + } |
| 120 | + expression.next(); |
74 | 121 | }
|
75 |
| - value = val; |
76 |
| - expression.next(); |
| 122 | + value = (values.size() == 1) ? values.get(0) : new CssValueList(values); |
77 | 123 | }
|
78 | 124 |
|
79 | 125 | public CssTextJustify(ApplContext ac, CssExpression expression)
|
|
0 commit comments