- From: CVS User ylafon <cvsmail@w3.org>
- Date: Mon, 18 May 2015 08:52:39 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/values In directory roscoe:/var/tmp/cvs-serv20487/org/w3c/css/values Modified Files: CssColor.java CssPercentage.java CssUnitsCSS3.java Log Message: added q unit (absolute length) per css3-values edcopy http://dev.w3.org/csswg/css-values-3/ added calc() parsing, more to be done on type checking... --- /sources/public/2002/css-validator/org/w3c/css/values/CssColor.java 2012/11/07 15:46:38 1.25 +++ /sources/public/2002/css-validator/org/w3c/css/values/CssColor.java 2015/05/18 08:52:38 1.26 @@ -1,5 +1,5 @@ // -// $Id: CssColor.java,v 1.25 2012/11/07 15:46:38 ylafon Exp $ +// $Id: CssColor.java,v 1.26 2015/05/18 08:52:38 ylafon Exp $ // From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr) // // (c) COPYRIGHT MIT and INRIA, 1997. @@ -17,349 +17,371 @@ import static org.w3c.css.values.CssOperator.COMMA; /** - * @version $Revision: 1.25 $ + * @version $Revision: 1.26 $ */ public class CssColor extends CssValue { - public static final int type = CssTypes.CSS_COLOR; + public static final int type = CssTypes.CSS_COLOR; + + public final int getType() { + return type; + } + + Object color = null; + RGB rgb = null; + RGBA rgba = null; + HSL hsl = null; + HSLA hsla = null; + HWB hwb = null; + + /** + * Create a new CssColor. + */ + public CssColor() { + } + + /** + * Create a new CssColor with a color name. + * + * @param s The name color. + * @throws InvalidParamException the color is incorrect + */ + public CssColor(ApplContext ac, String s) throws InvalidParamException { + // setIdentColor(s.toLowerCase(), ac); + setIdentColor(s, ac); + } + + /** + * Set the value from a defined color RBG. + * + * @param s the string representation of the color. + * @throws InvalidParamException the color is incorrect. + */ + public void set(String s, ApplContext ac) throws InvalidParamException { + if (s.charAt(0) == '#') { + setShortRGBColor(s.toLowerCase(), ac); + } else { + setIdentColor(s, ac); + } + } + + /** + * Return the internal value. + */ + public Object get() { + if (color != null) { + return color; + } else { + return rgb; + } + } + + + /** + * Returns a string representation of the object. + */ + public String toString() { + if (color != null) { + return color.toString(); + } else if (rgb != null) { + return rgb.toString(); + } else if (rgba != null) { + return rgba.toString(); + } else if (hsl != null) { + return hsl.toString(); + } else if (hsla != null) { + return hsla.toString(); + } else { + return hwb.toString(); + } + } + + /** + * Parse a RGB color. + * format rgb(<num>%?, <num>%?, <num>%?) + */ + public void setRGBColor(CssExpression exp, ApplContext ac) + throws InvalidParamException { + CssValue val = exp.getValue(); + char op = exp.getOperator(); + color = null; + rgb = new RGB(); + + if (val == null || op != COMMA) { + throw new InvalidParamException("invalid-color", ac); + } + + switch (val.getType()) { + case CssTypes.CSS_NUMBER: + CssNumber number = (CssNumber) val; + rgb.setRed(clippedIntValue(number.getInt(), ac)); + rgb.setPercent(false); + break; + case CssTypes.CSS_PERCENTAGE: + CssPercentage percent = (CssPercentage) val; + rgb.setRed(clippedPercentValue(percent.floatValue(), ac)); + rgb.setPercent(true); + break; + default: + throw new InvalidParamException("rgb", val, ac); + } + + exp.next(); + val = exp.getValue(); + op = exp.getOperator(); + + if (val == null || op != COMMA) { + throw new InvalidParamException("invalid-color", ac); + } + + switch (val.getType()) { + case CssTypes.CSS_NUMBER: + if (rgb.isPercent()) { + throw new InvalidParamException("percent", val, ac); + } + CssNumber number = (CssNumber) val; + rgb.setGreen(clippedIntValue(number.getInt(), ac)); + break; + case CssTypes.CSS_PERCENTAGE: + if (!rgb.isPercent()) { + throw new InvalidParamException("integer", val, ac); + } + CssPercentage percent = (CssPercentage) val; + rgb.setGreen(clippedPercentValue(percent.floatValue(), ac)); + break; + default: + throw new InvalidParamException("rgb", val, ac); + } + + exp.next(); + val = exp.getValue(); + op = exp.getOperator(); + + if (val == null) { + throw new InvalidParamException("invalid-color", ac); + } + + switch (val.getType()) { + case CssTypes.CSS_NUMBER: + if (rgb.isPercent()) { + throw new InvalidParamException("percent", val, ac); + } + CssNumber number = (CssNumber) val; + rgb.setBlue(clippedIntValue(number.getInt(), ac)); + break; + case CssTypes.CSS_PERCENTAGE: + if (!rgb.isPercent()) { + throw new InvalidParamException("integer", val, ac); + } + CssPercentage percent = (CssPercentage) val; + rgb.setBlue(clippedPercentValue(percent.floatValue(), ac)); + break; + default: + throw new InvalidParamException("rgb", val, ac); + } + + exp.next(); + if (exp.getValue() != null) { + throw new InvalidParamException("rgb", exp.getValue(), ac); + } + } + + /** + * Parse a RGB color. + * format #(3-6)<hexnum> + */ + public void setShortRGBColor(String s, ApplContext ac) + throws InvalidParamException { + int r; + int g; + int b; + int v; + int idx; + boolean islong; + + v = s.length(); + islong = (v == 7); + if (v != 4 && !islong) { + throw new InvalidParamException("rgb", s, ac); + } + idx = 1; + r = Character.digit(s.charAt(idx++), 16); + if (r < 0) { + throw new InvalidParamException("rgb", s, ac); + } + if (islong) { + v = Character.digit(s.charAt(idx++), 16); + if (v < 0) { + throw new InvalidParamException("rgb", s, ac); + } + r = (r << 4) + v; + } else { + r |= (r << 4); + } + g = Character.digit(s.charAt(idx++), 16); + if (g < 0) { + throw new InvalidParamException("rgb", s, ac); + } + if (islong) { + v = Character.digit(s.charAt(idx++), 16); + if (v < 0) { + throw new InvalidParamException("rgb", s, ac); + } + g = (g << 4) + v; + } else { + g |= (g << 4); + } + b = Character.digit(s.charAt(idx), 16); + if (b < 0) { + throw new InvalidParamException("rgb", s, ac); + } + if (islong) { + v = Character.digit(s.charAt(++idx), 16); + if (v < 0) { + throw new InvalidParamException("rgb", s, ac); + } + b = (b << 4) + v; + } else { + b |= (b << 4); + } - public final int getType() { - return type; - } - - Object color = null; - RGB rgb = null; - RGBA rgba = null; - HSL hsl = null; - HSLA hsla = null; - - /** - * Create a new CssColor. - */ - public CssColor() { - } - - /** - * Create a new CssColor with a color name. - * - * @param s The name color. - * @throws InvalidParamException the color is incorrect - */ - public CssColor(ApplContext ac, String s) throws InvalidParamException { - // setIdentColor(s.toLowerCase(), ac); - setIdentColor(s, ac); - } - - /** - * Set the value from a defined color RBG. - * - * @param s the string representation of the color. - * @throws InvalidParamException the color is incorrect. - */ - public void set(String s, ApplContext ac) throws InvalidParamException { - if (s.charAt(0) == '#') { - setShortRGBColor(s.toLowerCase(), ac); - } else { - setIdentColor(s, ac); - } - } - - /** - * Return the internal value. - */ - public Object get() { - if (color != null) { - return color; - } else { - return rgb; - } - } - - - /** - * Returns a string representation of the object. - */ - public String toString() { - if (color != null) { - return color.toString(); - } else if (rgba != null) { - return rgba.toString(); - } else if (hsl != null) { - return hsl.toString(); - } else if (hsla != null) { - return hsla.toString(); - } else { - return rgb.toString(); - } - } - - /** - * Parse a RGB color. - * format rgb(<num>%?, <num>%?, <num>%?) - */ - public void setRGBColor(CssExpression exp, ApplContext ac) - throws InvalidParamException { - CssValue val = exp.getValue(); - char op = exp.getOperator(); - color = null; - rgb = new RGB(); - - if (val == null || op != COMMA) { - throw new InvalidParamException("invalid-color", ac); - } - - switch (val.getType()) { - case CssTypes.CSS_NUMBER: - CssNumber number = (CssNumber) val; - rgb.setRed(clippedIntValue(number.getInt(), ac)); - rgb.setPercent(false); - break; - case CssTypes.CSS_PERCENTAGE: - CssPercentage percent = (CssPercentage) val; - rgb.setRed(clippedPercentValue(percent.floatValue(), ac)); - rgb.setPercent(true); - break; - default: - throw new InvalidParamException("rgb", val, ac); - } - - exp.next(); - val = exp.getValue(); - op = exp.getOperator(); - - if (val == null || op != COMMA) { - throw new InvalidParamException("invalid-color", ac); - } - - switch (val.getType()) { - case CssTypes.CSS_NUMBER: - if (rgb.isPercent()) { - throw new InvalidParamException("percent", val, ac); - } - CssNumber number = (CssNumber) val; - rgb.setGreen(clippedIntValue(number.getInt(), ac)); - break; - case CssTypes.CSS_PERCENTAGE: - if (!rgb.isPercent()) { - throw new InvalidParamException("integer", val, ac); - } - CssPercentage percent = (CssPercentage) val; - rgb.setGreen(clippedPercentValue(percent.floatValue(), ac)); - break; - default: - throw new InvalidParamException("rgb", val, ac); - } - - exp.next(); - val = exp.getValue(); - op = exp.getOperator(); - - if (val == null) { - throw new InvalidParamException("invalid-color", ac); - } - - switch (val.getType()) { - case CssTypes.CSS_NUMBER: - if (rgb.isPercent()) { - throw new InvalidParamException("percent", val, ac); - } - CssNumber number = (CssNumber) val; - rgb.setBlue(clippedIntValue(number.getInt(), ac)); - break; - case CssTypes.CSS_PERCENTAGE: - if (!rgb.isPercent()) { - throw new InvalidParamException("integer", val, ac); - } - CssPercentage percent = (CssPercentage) val; - rgb.setBlue(clippedPercentValue(percent.floatValue(), ac)); - break; - default: - throw new InvalidParamException("rgb", val, ac); - } - - exp.next(); - if (exp.getValue() != null) { - throw new InvalidParamException("rgb", exp.getValue(), ac); [963 lines skipped] --- /sources/public/2002/css-validator/org/w3c/css/values/CssPercentage.java 2012/12/17 15:26:59 1.18 +++ /sources/public/2002/css-validator/org/w3c/css/values/CssPercentage.java 2015/05/18 08:52:38 1.19 @@ -1,5 +1,5 @@ // -// $Id: CssPercentage.java,v 1.18 2012/12/17 15:26:59 ylafon Exp $ +// $Id: CssPercentage.java,v 1.19 2015/05/18 08:52:38 ylafon Exp $ // From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr) // // (c) COPYRIGHT MIT, ERCIM and Keio University, 2010. @@ -33,7 +33,7 @@ * In all inherited CSS1 properties, if the value is specified as a percentage, * child elements inherit the resultant value, not the percentage value. * - * @version $Revision: 1.18 $ + * @version $Revision: 1.19 $ */ public class CssPercentage extends CssCheckableValue { @@ -113,6 +113,13 @@ } /** + * Returns the real value + */ + public BigDecimal getValue() { + return value; + } + + /** * Returns true is the value is positive of null * * @return a boolean --- /sources/public/2002/css-validator/org/w3c/css/values/CssUnitsCSS3.java 2013/06/12 09:51:00 1.8 +++ /sources/public/2002/css-validator/org/w3c/css/values/CssUnitsCSS3.java 2015/05/18 08:52:39 1.9 @@ -1,4 +1,4 @@ -// $Id: CssUnitsCSS3.java,v 1.8 2013/06/12 09:51:00 ylafon Exp $ +// $Id: CssUnitsCSS3.java,v 1.9 2015/05/18 08:52:39 ylafon Exp $ // Author: Yves Lafon <ylafon@w3.org> // // (c) COPYRIGHT MIT, ERCIM and Keio University, 2012. @@ -20,7 +20,7 @@ }; private static final String[] absolute_length_units = { - "in", "cm", "mm", "pt", "pc", "px" + "in", "cm", "mm", "pt", "pc", "px", "q" }; public static final String[] angle_units = {
Received on Monday, 18 May 2015 08:52:41 UTC