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 static org .w3c .css .values .CssOperator .SPACE ;
14
17
15
18
/**
16
- * @spec https://www.w3.org/TR/2021 /WD-css-fonts-4-20210729 /#propdef-font-size-adjust
19
+ * @spec https://www.w3.org/TR/2024 /WD-css-fonts-5-20240206 /#propdef-font-size-adjust
17
20
*/
18
21
public class CssFontSizeAdjust extends org .w3c .css .properties .css .CssFontSizeAdjust {
19
22
23
+ public static final CssIdent [] optionalIdentValues ;
24
+ public static final CssIdent from_font ;
25
+
26
+ static {
27
+ String [] _optionalIdentValues = {"ex-height" , "cap-height" , "ch-width" ,
28
+ "ic-width" , "ic-height" };
29
+ optionalIdentValues = new CssIdent [_optionalIdentValues .length ];
30
+ for (int i = 0 ; i < optionalIdentValues .length ; i ++) {
31
+ optionalIdentValues [i ] = CssIdent .getIdent (_optionalIdentValues [i ]);
32
+ }
33
+ from_font = CssIdent .getIdent ("from-font" );
34
+ }
35
+
36
+ public static final CssIdent getOptionalIdent (CssIdent ident ) {
37
+ for (CssIdent id : optionalIdentValues ) {
38
+ if (id .equals (ident )) {
39
+ return id ;
40
+ }
41
+ }
42
+ return null ;
43
+ }
44
+
20
45
public static final CssIdent getAllowedIdent (CssIdent ident ) {
21
- if (none .equals (ident )) {
22
- return none ;
46
+ if (from_font .equals (ident )) {
47
+ return from_font ;
23
48
}
24
49
return null ;
25
50
}
@@ -39,37 +64,74 @@ public CssFontSizeAdjust() {
39
64
*/
40
65
public CssFontSizeAdjust (ApplContext ac , CssExpression expression , boolean check )
41
66
throws InvalidParamException {
42
- if (check && expression .getCount () > 1 ) {
67
+ if (check && expression .getCount () > 2 ) {
43
68
throw new InvalidParamException ("unrecognize" , ac );
44
69
}
45
70
46
71
setByUser ();
47
72
48
73
CssValue val ;
74
+ CssValueList vl = null ;
49
75
char op ;
76
+ boolean got_option = false ;
77
+
78
+ while (!expression .end ()) {
79
+ val = expression .getValue ();
80
+ op = expression .getOperator ();
50
81
51
- val = expression .getValue ();
52
- op = expression .getOperator ();
53
-
54
- switch (val .getType ()) {
55
- case CssTypes .CSS_IDENT :
56
- CssIdent id = val .getIdent ();
57
- if (CssIdent .isCssWide (id ) || (getAllowedIdent (id ) != null )) {
58
- value = val ;
82
+ switch (val .getType ()) {
83
+ case CssTypes .CSS_IDENT :
84
+ CssIdent id = val .getIdent ();
85
+ if (expression .getCount () == 1 ) {
86
+ if (CssIdent .isCssWide (id ) || (getAllowedIdent (id ) != null ) || none .equals (id )) {
87
+ value = val ;
88
+ break ;
89
+ }
90
+ throw new InvalidParamException ("value" ,
91
+ val , getPropertyName (), ac );
92
+ } else {
93
+ if (!got_option ) {
94
+ got_option = (getOptionalIdent (id ) != null );
95
+ if (got_option ) {
96
+ vl = new CssValueList ();
97
+ vl .add (val );
98
+ } else {
99
+ throw new InvalidParamException ("value" ,
100
+ val , getPropertyName (), ac );
101
+ }
102
+ } else {
103
+ // got_option is true, so vl was created
104
+ if (getAllowedIdent (id ) != null ) {
105
+ vl .add (val );
106
+ } else {
107
+ throw new InvalidParamException ("value" ,
108
+ val , getPropertyName (), ac );
109
+ }
110
+ }
111
+ }
59
112
break ;
60
- }
61
- throw new InvalidParamException ("value" ,
62
- val , getPropertyName (), ac );
63
- case CssTypes .CSS_NUMBER :
64
- val .getCheckableValue ().checkPositiveness (ac , getPropertyName ());
65
- value = val ;
66
- break ;
67
- default :
68
- throw new InvalidParamException ("value" ,
69
- val , getPropertyName (), ac );
113
+ case CssTypes .CSS_NUMBER :
114
+ val .getCheckableValue ().checkPositiveness (ac , getPropertyName ());
115
+ if (got_option ) {
116
+ vl .add (val );
117
+ } else {
118
+ value = val ;
119
+ }
120
+ break ;
121
+ default :
122
+ throw new InvalidParamException ("value" ,
123
+ val , getPropertyName (), ac );
124
+ }
125
+ if (op != SPACE ) {
126
+ throw new InvalidParamException ("operator" , op ,
127
+ getPropertyName (), ac );
128
+ }
129
+ expression .next ();
130
+ }
131
+ // reassign if we got multiple values
132
+ if (got_option ) {
133
+ value = vl ;
70
134
}
71
- expression .next ();
72
-
73
135
}
74
136
75
137
public CssFontSizeAdjust (ApplContext ac , CssExpression expression )
0 commit comments