@@ -32,6 +32,27 @@ public final int getType() {
3232 return computed_type ;
3333 }
3434
35+ public static final CssIdent [] rounding_values ;
36+
37+ static {
38+ String [] _allowed_rounding_values = {"nearest" , "up" , "down" ,
39+ "to-zero" };
40+ int i = 0 ;
41+ rounding_values = new CssIdent [_allowed_rounding_values .length ];
42+ for (String s : _allowed_rounding_values ) {
43+ rounding_values [i ++] = CssIdent .getIdent (s );
44+ }
45+ }
46+
47+ public static final boolean isAllowedRounding (CssIdent ident ) {
48+ for (CssIdent id : rounding_values ) {
49+ if (id .equals (ident )) {
50+ return true ;
51+ }
52+ }
53+ return false ;
54+ }
55+
3556 ApplContext ac ;
3657 int computed_type = CssTypes .CSS_UNKNOWN ;
3758 ArrayList <CssValue > values = null ;
@@ -121,30 +142,196 @@ private int _checkAcceptableType(int type)
121142 return type ;
122143 }
123144
124- private void _computeResultingType (boolean first )
145+ private void _computeResultingType (boolean is_final )
125146 throws InvalidParamException {
126147 switch (prefix ) {
127148 case "clamp(" :
128149 case "min(" :
129150 case "max(" :
130151 case "hypot(" :
131- _computeResultingTypeList (first );
152+ _computeResultingTypeList (is_final );
132153 break ;
133154 case "sin(" :
134155 case "cos(" :
135156 case "tan(" :
136157 case "asin(" :
137158 case "acos(" :
138159 case "atan(" :
139- _computeResultingTypeTrig (first );
160+ if (is_final ) {
161+ _computeResultingTypeTrig (is_final );
162+ }
163+ break ;
164+ case "exp(" :
165+ case "sqrt(" :
166+ _computeResultingTypeOneNum (is_final );
167+ break ;
168+ case "pow(" :
169+ if (is_final ) {
170+ _computeResultingTypeTwoNum (is_final );
171+ }
172+ break ;
173+ case "log(" :
174+ if (is_final ) {
175+ _computeResultingTypeTwoNumOpt (is_final );
176+ }
177+ break ;
178+ case "mod(" :
179+ case "rem(" :
180+ if (is_final ) {
181+ _computeResultingTypeTwoAny (is_final );
182+ }
183+ break ;
184+ case "abs(" :
185+ _computeResultingTypeOneAny (is_final );
186+ break ;
187+ case "atan2(" :
188+ if (is_final ) {
189+ _computeResultingTypeAtan2 (is_final );
190+ }
191+ break ;
192+ case "sign(" :
193+ if (is_final ) {
194+ _computeResultingTypeSign (is_final );
195+ }
196+ break ;
197+ case "round(" :
198+ if (is_final ) {
199+ _computeResultingTypeRound (is_final );
200+ }
140201 break ;
141202 default :
142203 throw new InvalidParamException ("unrecognize" , ac );
143204 }
144205
145206 }
146207
147- private void _computeResultingTypeTrig (boolean first )
208+ private void _computeResultingTypeOneNum (boolean is_final )
209+ throws InvalidParamException {
210+ int valtype ;
211+ if (values .size () > 1 ) {
212+ throw new InvalidParamException ("unrecognize" , ac );
213+ }
214+ valtype = values .get (0 ).getType ();
215+ if (valtype == CssTypes .CSS_NUMBER ) {
216+ computed_type = CssTypes .CSS_NUMBER ;
217+ } else {
218+ throw new InvalidParamException ("incompatibletypes" , toString (), ac );
219+ }
220+ }
221+
222+ private void _computeResultingTypeTwoNum (boolean is_final )
223+ throws InvalidParamException {
224+ int valtype1 , valtype2 ;
225+ if (values .size () != 2 ) {
226+ throw new InvalidParamException ("unrecognize" , ac );
227+ }
228+ valtype1 = values .get (0 ).getType ();
229+ valtype2 = values .get (1 ).getType ();
230+ if ((valtype1 == CssTypes .CSS_NUMBER ) && (valtype2 == CssTypes .CSS_NUMBER )) {
231+ computed_type = CssTypes .CSS_NUMBER ;
232+ } else {
233+ throw new InvalidParamException ("incompatibletypes" , toString (), ac );
234+ }
235+ }
236+
237+ // used for log(A, B?)
238+ private void _computeResultingTypeTwoNumOpt (boolean is_final )
239+ throws InvalidParamException {
240+ int valtype ;
241+ if (values .size () > 2 ) {
242+ throw new InvalidParamException ("unrecognize" , ac );
243+ }
244+ valtype = values .get (0 ).getType ();
245+ if (valtype != CssTypes .CSS_NUMBER ) {
246+ throw new InvalidParamException ("incompatibletypes" , toString (), ac );
247+ }
248+ if (values .size () > 1 ) {
249+ valtype = values .get (1 ).getType ();
250+ if (valtype != CssTypes .CSS_NUMBER ) {
251+ throw new InvalidParamException ("incompatibletypes" , toString (), ac );
252+ }
253+ }
254+ computed_type = CssTypes .CSS_NUMBER ;
255+ }
256+
257+ private void _computeResultingTypeAtan2 (boolean is_final )
258+ throws InvalidParamException {
259+ int valtype1 , valtype2 ;
260+ if (values .size () != 2 ) {
261+ throw new InvalidParamException ("unrecognize" , ac );
262+ }
263+ valtype1 = values .get (0 ).getType ();
264+ valtype2 = values .get (1 ).getType ();
265+ if (valtype1 == valtype2 ) {
266+ computed_type = CssTypes .CSS_ANGLE ;
267+ } else {
268+ throw new InvalidParamException ("incompatibletypes" , toString (), ac );
269+ }
270+ }
271+
272+ private void _computeResultingTypeRound (boolean is_final )
273+ throws InvalidParamException {
274+ int valtype1 , valtype2 ;
275+ int vsize = values .size ();
276+ if ((vsize < 2 ) || (vsize > 3 )) {
277+ throw new InvalidParamException ("unrecognize" , ac );
278+ }
279+ if (vsize == 2 ) {
280+ valtype1 = values .get (0 ).getType ();
281+ valtype2 = values .get (1 ).getType ();
282+ } else { // 3 values
283+ CssValue v = values .get (0 );
284+ if (v .getType () != CssTypes .CSS_IDENT ) {
285+ throw new InvalidParamException ("incompatibletypes" , toString (), ac );
286+ }
287+ if (!isAllowedRounding (v .getIdent ())) {
288+ throw new InvalidParamException ("incompatibletypes" , toString (), ac );
289+ }
290+ valtype1 = values .get (1 ).getType ();
291+ valtype2 = values .get (2 ).getType ();
292+ }
293+ if (valtype1 == valtype2 ) {
294+ computed_type = valtype1 ;
295+ } else {
296+ throw new InvalidParamException ("incompatibletypes" , toString (), ac );
297+ }
298+
299+ }
300+
301+ private void _computeResultingTypeSign (boolean is_final )
302+ throws InvalidParamException {
303+ if (values .size () > 1 ) {
304+ throw new InvalidParamException ("unrecognize" , ac );
305+ }
306+ computed_type = CssTypes .CSS_NUMBER ;
307+ }
308+
309+ private void _computeResultingTypeOneAny (boolean is_final )
310+ throws InvalidParamException {
311+ int valtype ;
312+ if (values .size () > 1 ) {
313+ throw new InvalidParamException ("unrecognize" , ac );
314+ }
315+ valtype = values .get (0 ).getType ();
316+ computed_type = valtype ;
317+ }
318+
319+ private void _computeResultingTypeTwoAny (boolean is_final )
320+ throws InvalidParamException {
321+ int valtype1 , valtype2 ;
322+ if (values .size () != 2 ) {
323+ throw new InvalidParamException ("unrecognize" , ac );
324+ }
325+ valtype1 = values .get (0 ).getType ();
326+ valtype2 = values .get (1 ).getType ();
327+ if (valtype1 == valtype2 ) {
328+ computed_type = valtype1 ;
329+ } else {
330+ throw new InvalidParamException ("incompatibletypes" , toString (), ac );
331+ }
332+ }
333+
334+ private void _computeResultingTypeTrig (boolean is_final )
148335 throws InvalidParamException {
149336 int valtype ;
150337 if (values .size () > 1 ) {
@@ -162,7 +349,7 @@ private void _computeResultingTypeTrig(boolean first)
162349 }
163350 }
164351
165- private void _computeResultingTypeList (boolean first )
352+ private void _computeResultingTypeList (boolean is_final )
166353 throws InvalidParamException {
167354 int valtype = CssTypes .CSS_MATH_FUNCTION ;
168355 boolean firstVal = true ;
0 commit comments