1212import org .w3c .css .util .InvalidParamException ;
1313
1414import java .math .BigDecimal ;
15- import java .util .HashMap ;
1615
1716import static org .w3c .css .values .CssOperator .COMMA ;
1817import static org .w3c .css .values .CssOperator .SPACE ;
@@ -36,6 +35,7 @@ public final int getType() {
3635 HWB hwb = null ;
3736 LAB lab = null ;
3837 LCH lch = null ;
38+ DeviceCMYK cmyk = null ;
3939
4040 /**
4141 * Create a new CssColor.
@@ -98,6 +98,8 @@ public String toString() {
9898 return lab .toString ();
9999 } else if (lch != null ) {
100100 return lch .toString ();
101+ } else if (cmyk != null ) {
102+ return cmyk .toString ();
101103 }
102104 return "*invalid*" ;
103105 }
@@ -529,24 +531,6 @@ public void setShortRGBColor(ApplContext ac, String s)
529531 }
530532 }
531533
532- protected boolean computeIdentColor (HashMap <String , Object > definitions ,
533- String s ) {
534- Object obj = definitions .get (s );
535- if (obj != null ) {
536- if (obj instanceof RGB ) {
537- color = s ;
538- rgb = (RGB ) obj ;
539- } else if (obj instanceof RGBA ) {
540- color = s ;
541- rgba = (RGBA ) obj ;
542- } else if (obj instanceof String ) {
543- color = (String ) obj ;
544- }
545- return true ;
546- }
547- return false ;
548- }
549-
550534 /**
551535 * Parse an ident color.
552536 */
@@ -633,6 +617,14 @@ public boolean equals(Object cssColor) {
633617 return rgba .equals (otherColor .rgba );
634618 } else if ((hsl != null ) && (otherColor .hsl != null )) {
635619 return hsl .equals (otherColor .hsl );
620+ } else if ((hwb != null ) && (otherColor .hwb != null )) {
621+ return hwb .equals (otherColor .hwb );
622+ } else if ((lab != null ) && (otherColor .lab != null )) {
623+ return lab .equals (otherColor .lab );
624+ } else if ((lch != null ) && (otherColor .lch != null )) {
625+ return lch .equals (otherColor .lch );
626+ } else if ((cmyk != null ) && (otherColor .cmyk != null )) {
627+ return cmyk .equals (otherColor .cmyk );
636628 }
637629 return false ;
638630 }
@@ -1123,5 +1115,129 @@ public void setLCHColor(ApplContext ac, CssExpression exp)
11231115 }
11241116
11251117
1118+ public void setDeviceCMYKColor (ApplContext ac , CssExpression exp )
1119+ throws InvalidParamException {
1120+ // HWB defined in CSSColor Level 4 and onward, currently used in the CSS level
1121+ if (ac .getCssVersion ().compareTo (CssVersion .CSS3 ) < 0 ) {
1122+ StringBuilder sb = new StringBuilder ();
1123+ sb .append ("device-cmyk(" ).append (exp .toStringFromStart ()).append (')' );
1124+ throw new InvalidParamException ("notversion" , sb .toString (),
1125+ ac .getCssVersionString (), ac );
1126+ }
1127+
1128+ color = null ;
1129+ cmyk = new DeviceCMYK ();
1130+ CssValue val = exp .getValue ();
1131+ char op = exp .getOperator ();
1132+ boolean gotFallback = false ;
1133+
1134+ // C
1135+ if (val == null || op != SPACE ) {
1136+ throw new InvalidParamException ("invalid-color" , ac );
1137+ }
1138+ switch (val .getType ()) {
1139+ case CssTypes .CSS_NUMBER :
1140+ case CssTypes .CSS_PERCENTAGE :
1141+ cmyk .setC (ac , val );
1142+ break ;
1143+ default :
1144+ throw new InvalidParamException ("rgb" , val , ac ); // FIXME device-cmyk
1145+ }
1146+
1147+ // M
1148+ exp .next ();
1149+ val = exp .getValue ();
1150+ op = exp .getOperator ();
1151+ if (val == null || op != SPACE ) {
1152+ exp .starts ();
1153+ throw new InvalidParamException ("invalid-color" , ac );
1154+ }
1155+ switch (val .getType ()) {
1156+ case CssTypes .CSS_NUMBER :
1157+ case CssTypes .CSS_PERCENTAGE :
1158+ cmyk .setM (ac , val );
1159+ break ;
1160+ default :
1161+ throw new InvalidParamException ("rgb" , val , ac ); // FIXME device-cmyk
1162+ }
1163+
1164+ // Y
1165+ exp .next ();
1166+ val = exp .getValue ();
1167+ op = exp .getOperator ();
1168+ if (val == null ) {
1169+ throw new InvalidParamException ("invalid-color" , exp .toStringFromStart (), ac );
1170+ }
1171+ switch (val .getType ()) {
1172+ case CssTypes .CSS_NUMBER :
1173+ case CssTypes .CSS_PERCENTAGE :
1174+ cmyk .setY (ac , val );
1175+ break ;
1176+ default :
1177+ throw new InvalidParamException ("rgb" , val , ac ); // FIXME device-cmyk
1178+ }
1179+ // K
1180+ exp .next ();
1181+ val = exp .getValue ();
1182+ op = exp .getOperator ();
1183+ if (val == null ) {
1184+ throw new InvalidParamException ("invalid-color" , exp .toStringFromStart (), ac );
1185+ }
1186+ switch (val .getType ()) {
1187+ case CssTypes .CSS_NUMBER :
1188+ case CssTypes .CSS_PERCENTAGE :
1189+ cmyk .setK (ac , val );
1190+ break ;
1191+ default :
1192+ throw new InvalidParamException ("rgb" , val , ac ); // FIXME device-cmyk
1193+ }
1194+
1195+ exp .next ();
1196+ if (!exp .end ()) {
1197+ if (op == SPACE ) {
1198+ // now we need an alpha.
1199+ val = exp .getValue ();
1200+ op = exp .getOperator ();
1201+
1202+ if (val .getType () != CssTypes .CSS_SWITCH ) {
1203+ throw new InvalidParamException ("rgb" , val , ac );
1204+ }
1205+ if (op != SPACE ) {
1206+ throw new InvalidParamException ("invalid-color" , ac );
1207+ }
1208+ exp .next ();
1209+ // now we get the alpha value
1210+ val = exp .getValue ();
1211+ if (val == null ) {
1212+ throw new InvalidParamException ("invalid-color" , exp .toStringFromStart (), ac );
1213+ }
1214+ switch (val .getType ()) {
1215+ case CssTypes .CSS_NUMBER :
1216+ case CssTypes .CSS_PERCENTAGE :
1217+ cmyk .setAlpha (ac , val );
1218+ break ;
1219+ default :
1220+ exp .starts ();
1221+ throw new InvalidParamException ("rgb" , val , ac ); // FIXME lch
1222+ }
1223+ exp .next ();
1224+ }
1225+ if (op == COMMA ) {
1226+ //the optional fallback
1227+ if (exp .end ()) {
1228+ throw new InvalidParamException ("rgb" , exp .toStringFromStart (), ac );
1229+ }
1230+ val = exp .getValue ();
1231+ cmyk .setFallbackColor (ac , val );
1232+ exp .next ();
1233+ }
1234+ }
1235+ // extra values?
1236+ if (!exp .end ()) {
1237+ exp .starts ();
1238+ throw new InvalidParamException ("rgb" , exp .toStringFromStart (), ac );
1239+ }
1240+ }
1241+
11261242}
11271243
0 commit comments