|
11 | 11 | import org.w3c.css.util.CssVersion; |
12 | 12 | import org.w3c.css.util.InvalidParamException; |
13 | 13 |
|
| 14 | +import java.math.BigDecimal; |
14 | 15 | import java.util.HashMap; |
15 | 16 |
|
16 | 17 | import static org.w3c.css.values.CssOperator.COMMA; |
@@ -913,6 +914,68 @@ public void setLABColor(CssExpression exp, ApplContext ac) |
913 | 914 | } |
914 | 915 | } |
915 | 916 |
|
| 917 | + public void setGrayColor(CssExpression exp, ApplContext ac) |
| 918 | + throws InvalidParamException { |
| 919 | + // HWB defined in CSSColor Level 4 and onward, currently used in the CSS level |
| 920 | + if (ac.getCssVersion().compareTo(CssVersion.CSS3) < 0) { |
| 921 | + StringBuilder sb = new StringBuilder(); |
| 922 | + sb.append("gray(").append(exp.toStringFromStart()).append(')'); |
| 923 | + throw new InvalidParamException("notversion", sb.toString(), |
| 924 | + ac.getCssVersionString(), ac); |
| 925 | + } |
| 926 | + |
| 927 | + color = null; |
| 928 | + lab = new LAB(); |
| 929 | + lab.setGray(true); |
| 930 | + CssValue val = exp.getValue(); |
| 931 | + char op = exp.getOperator(); |
| 932 | + // L |
| 933 | + if (val == null) { |
| 934 | + throw new InvalidParamException("invalid-color", ac); |
| 935 | + } |
| 936 | + switch (val.getType()) { |
| 937 | + case CssTypes.CSS_NUMBER: |
| 938 | + lab.setL(ac, val); |
| 939 | + break; |
| 940 | + default: |
| 941 | + throw new InvalidParamException("rgb", val, ac); // FIXME gray |
| 942 | + } |
| 943 | + |
| 944 | + // A |
| 945 | + CssNumber n = new CssNumber(); |
| 946 | + n.setValue(BigDecimal.ZERO); |
| 947 | + lab.setA(ac, n); |
| 948 | + // B |
| 949 | + lab.setB(ac, n); |
| 950 | + |
| 951 | + exp.next(); |
| 952 | + if (!exp.end()) { |
| 953 | + if (op != COMMA) { |
| 954 | + throw new InvalidParamException("operator", exp.toStringFromStart(), ac); |
| 955 | + } |
| 956 | + // Alpha |
| 957 | + val = exp.getValue(); |
| 958 | + if (val == null) { |
| 959 | + throw new InvalidParamException("invalid-color", exp.toStringFromStart(), ac); |
| 960 | + } |
| 961 | + switch (val.getType()) { |
| 962 | + case CssTypes.CSS_NUMBER: |
| 963 | + case CssTypes.CSS_PERCENTAGE: |
| 964 | + lab.setAlpha(ac, val); |
| 965 | + break; |
| 966 | + default: |
| 967 | + exp.starts(); |
| 968 | + throw new InvalidParamException("rgb", val, ac); // FIXME gray |
| 969 | + } |
| 970 | + exp.next(); |
| 971 | + } |
| 972 | + // extra values? |
| 973 | + if (!exp.end()) { |
| 974 | + exp.starts(); |
| 975 | + throw new InvalidParamException("rgb", exp.toStringFromStart(), ac); |
| 976 | + } |
| 977 | + } |
| 978 | + |
916 | 979 |
|
917 | 980 | public void setLCHColor(CssExpression exp, ApplContext ac) |
918 | 981 | throws InvalidParamException { |
@@ -997,5 +1060,6 @@ public void setLCHColor(CssExpression exp, ApplContext ac) |
997 | 1060 | } |
998 | 1061 | } |
999 | 1062 |
|
| 1063 | + |
1000 | 1064 | } |
1001 | 1065 |
|
0 commit comments