2002/css-validator/org/w3c/css/properties/css3 CssFont.java,NONE,1.1 CssFontFamily.java,NONE,1.1 CssFontSize.java,NONE,1.1 CssFontSizeAdjust.java,NONE,1.1 CssFontStretch.java,NONE,1.1 CssFontStyle.java,NONE,1.1 CssFontVariant.java,NONE,1.1 CssFontWeight.java,NONE,1.1 CssLineHeight.java,NONE,1.1 Css3Style.java,1.20,1.21

Update of /sources/public/2002/css-validator/org/w3c/css/properties/css3
In directory hutz:/tmp/cvs-serv31218/w3c/css/properties/css3

Modified Files:
	Css3Style.java 
Added Files:
	CssFont.java CssFontFamily.java CssFontSize.java 
	CssFontSizeAdjust.java CssFontStretch.java CssFontStyle.java 
	CssFontVariant.java CssFontWeight.java CssLineHeight.java 
Log Message:
font revamp, still some missing properties for CSS3 and @font-face for CSS2 and CSS3

Index: Css3Style.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css3/Css3Style.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- Css3Style.java	26 Apr 2012 18:33:30 -0000	1.20
+++ Css3Style.java	4 Aug 2012 21:17:06 -0000	1.21
@@ -38,11 +38,6 @@
 
     CssColorProfile cssColorProfile;
     CssRenderIntent cssRenderIntent;
-    CssFontEffect cssFontEffect;
-    CssFontSmooth cssFontSmooth;
-    CssFontEmphasizeStyle cssFontEmphasizeStyle;
-    CssFontEmphasizePos cssFontEmphasizePos;
-    CssFontEmphasize cssFontEmphasize;
     CssRubyPosition cssRubyPosition;
     CssRubyAlign cssRubyAlign;
     CssRubyOverhang cssRubyOverhang;
@@ -231,51 +226,6 @@
         return cssRenderIntent;
     }
 
-    public CssFontEffect getFontEffect() {
-        if (cssFontEffect == null) {
-            cssFontEffect =
-                    (CssFontEffect) style.CascadingOrder(new CssFontEffect(),
-                            style, selector);
-        }
-        return cssFontEffect;
-    }
-
-    public CssFontSmooth getFontSmooth() {
-        if (cssFontSmooth == null) {
-            cssFontSmooth =
-                    (CssFontSmooth) style.CascadingOrder(new CssFontSmooth(),
-                            style, selector);
-        }
-        return cssFontSmooth;
-    }
-
-    public CssFontEmphasizeStyle getFontEmphasizeStyle() {
-        if (cssFontEmphasizeStyle == null) {
-            cssFontEmphasizeStyle =
-                    (CssFontEmphasizeStyle) style.CascadingOrder(
-                            new CssFontEmphasizeStyle(), style, selector);
-        }
-        return cssFontEmphasizeStyle;
-    }
-
-    public CssFontEmphasizePos getFontEmphasizePos() {
-        if (cssFontEmphasizePos == null) {
-            cssFontEmphasizePos =
-                    (CssFontEmphasizePos) style.CascadingOrder(
-                            new CssFontEmphasizePos(), style, selector);
-        }
-        return cssFontEmphasizePos;
-    }
-
-    public CssFontEmphasize getFontEmphasize() {
-        if (cssFontEmphasize == null) {
-            cssFontEmphasize =
-                    (CssFontEmphasize) style.CascadingOrder(
-                            new CssFontEmphasizePos(), style, selector);
-        }
-        return cssFontEmphasize;
-    }
-
     public CssRubyPosition getRubyPosition() {
         if (cssRubyPosition == null) {
             cssRubyPosition =

--- NEW FILE: CssFontStretch.java ---
// $Id: CssFontStretch.java,v 1.1 2012/08/04 21:17:07 ylafon Exp $
// Author: Yves Lafon <ylafon@w3.org>
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.css3;

import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

import java.util.HashMap;

/**
 * @spec http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-stretch-prop
 */
public class CssFontStretch extends org.w3c.css.properties.css.CssFontStretch {

	static final String[] _allowed_values = {"normal", "ultra-condensed",
			"extra-condensed", "condensed", "semi-condensed", "semi-expanded",
			"expanded", "extra-expanded", "ultra-expanded"};
	static final HashMap<String, CssIdent> allowed_values;

	static {
		allowed_values = new HashMap<String, CssIdent>();
		for (String s : _allowed_values) {
			allowed_values.put(s, CssIdent.getIdent(s));
		}
	}

	/**
	 * Create a new CssFontStretch
	 */
	public CssFontStretch() {
		value = initial;
	}

	/**
	 * Creates a new CssFontStretch
	 *
	 * @param expression The expression for this property
	 * @throws org.w3c.css.util.InvalidParamException
	 *          Expressions are incorrect
	 */
	public CssFontStretch(ApplContext ac, CssExpression expression, boolean check)
			throws InvalidParamException {
		if (check && expression.getCount() > 1) {
			throw new InvalidParamException("unrecognize", ac);
		}
		setByUser();

		CssValue val;
		char op;

		val = expression.getValue();
		op = expression.getOperator();

		if (val.getType() == CssTypes.CSS_IDENT) {
			CssIdent ident = (CssIdent) val;
			if (inherit.equals(ident)) {
				value = inherit;
			} else {
				value = allowed_values.get(val.toString());
				if (value == null) {
					throw new InvalidParamException("value",
							val.toString(),
							getPropertyName(), ac);
				}
			}
		} else {
			throw new InvalidParamException("value",
					val.toString(),
					getPropertyName(), ac);
		}
		expression.next();
	}

	public CssFontStretch(ApplContext ac, CssExpression expression)
			throws InvalidParamException {
		this(ac, expression, false);
	}


}


--- NEW FILE: CssFont.java ---
// $Id: CssFont.java,v 1.1 2012/08/04 21:17:06 ylafon Exp $
// Author: Yves Lafon <ylafon@w3.org>
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.css3;

import org.w3c.css.properties.css21.CssFontFamily;
import org.w3c.css.properties.css21.CssFontSize;
import org.w3c.css.properties.css21.CssFontStyle;
import org.w3c.css.properties.css21.CssFontVariant;
import org.w3c.css.properties.css21.CssFontWeight;
import org.w3c.css.properties.css21.CssLineHeight;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

import java.util.HashMap;

import static org.w3c.css.values.CssOperator.SPACE;

/**
 * @spec http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-prop
 */
public class CssFont extends org.w3c.css.properties.css.CssFont {

	public static final CssIdent normal;
	public static final HashMap<String, CssIdent> systemFonts;
	static final String[] _systemFonts = {"caption", "icon", "menu",
			"message-box", "small-caption", "status-bar"};

	static {
		normal = CssIdent.getIdent("normal");
		systemFonts = new HashMap<String, CssIdent>();
		for (String s : _systemFonts) {
			systemFonts.put(s, CssIdent.getIdent(s));
		}
	}

	/**
	 * Create a new CssFontSize
	 */
	public CssFont() {
		value = initial;
	}

	/**
	 * Creates a new CssFontSize
	 *
	 * @param expression The expression for this property
	 * @throws org.w3c.css.util.InvalidParamException
	 *          Expressions are incorrect
	 */
	public CssFont(ApplContext ac, CssExpression expression, boolean check)
			throws InvalidParamException {

		setByUser();

		CssValue val;
		char op;

		boolean gotNormal = false;
		int state = 0;

		while (!expression.end()) {
			val = expression.getValue();
			op = expression.getOperator();
			switch (val.getType()) {
				case CssTypes.CSS_IDENT:
					if (inherit.equals(val)) {
						if (expression.getCount() != 1) {
							throw new InvalidParamException("value",
									val.toString(),
									getPropertyName(), ac);
						}
						value = inherit;
						break;
					}
					CssIdent ident;
					ident = systemFonts.get(val.toString());
					if (ident != null) {
						if (expression.getCount() != 1) {
							throw new InvalidParamException("value",
									val.toString(),
									getPropertyName(), ac);
						}
						value = ident;
						break;
					}

					// first font-style
					ident = (CssIdent) val;
					if (state == 0) {
						// now check for possible font values
						// first the strange case of 'normal'
						// which sets up to three values...
						// we keep it around for the final check
						if (normal.equals((CssIdent) val)) {
							gotNormal = true;
							break;
						}
						int pos = org.w3c.css.properties.css21.CssFontStyle.allowed_values.indexOf(ident);
						if (pos >= 0) {
							if (fontStyle != null) {
								throw new InvalidParamException("value",
										val.toString(),
										getPropertyName(), ac);
							}
							fontStyle = new org.w3c.css.properties.css21.CssFontStyle();
							fontStyle.value = CssFontStyle.allowed_values.get(pos);
							break;
						}
						// font-variant
						CssIdent v = CssFontVariant.getAllowedFontVariant(ident);
						if (v != null) {
							if (fontVariant != null) {
								throw new InvalidParamException("value",
										val.toString(),
										getPropertyName(), ac);
							}
							fontVariant = new CssFontVariant();
							fontVariant.value = v;
							break;
						}
						// font-weight
						v = CssFontWeight.allowed_values.get(ident.toString());
						if (v != null) {
							if (fontWeight != null) {
								throw new InvalidParamException("value",
										val.toString(),
										getPropertyName(), ac);
							}
							fontWeight = new CssFontWeight();
							fontWeight.value = v;
							break;
						}
					}

					// check if we moved past and we now got
					// a font-size
					if (state == 0) {
						CssIdent v = CssFontSize.allowed_values.get(ident.toString());
						if (v != null) {
							// we got a FontSize, so no more style/variant/weight
							state = 1;
							if (fontSize != null) {
								throw new InvalidParamException("value",
										val.toString(),
										getPropertyName(), ac);
							}
							fontSize = new CssFontSize();
							fontSize.value = v;
							break;
						}
					}
					// still nothing? It must be a font-family then...
					// let the fun begin ;)
					fontFamily = new CssFontFamily(ac, expression, check);
					state = 2;
					// expression.next is called, so continue instead
					// of next
					continue;
				case CssTypes.CSS_SWITCH:
					// sanity check, it must happen only after a fontSize
					if (fontSize == null || state != 1) {
						throw new InvalidParamException("value",
								val.toString(),
								getPropertyName(), ac);
					}
					expression.next();
					if (expression.end()) {
						throw new InvalidParamException("value",
								expression.toString(),
								getPropertyName(), ac);
					}
					// let's parse a line-height
					lineHeight = new CssLineHeight(ac, expression, false);
					state = 1;
					// expression.next is called, so continue instead
					// of next
					continue;

				case CssTypes.CSS_NUMBER:
					// must be a font-weight
					if (state == 0 && fontWeight == null) {
						fontWeight = new CssFontWeight(ac, expression, false);
						// expression.next is called, so continue instead
						// of next
						continue;
					}
					throw new InvalidParamException("value",
							val.toString(),
							getPropertyName(), ac);

				case CssTypes.CSS_PERCENTAGE:
				case CssTypes.CSS_LENGTH:
					if (state == 0 && fontSize == null) {
						fontSize = new CssFontSize(ac, expression, false);
						state = 1;
						// expression.next is called, so continue instead
						// of next
						continue;
					}
					throw new InvalidParamException("value",
							val.toString(),
							getPropertyName(), ac);
				default:
					throw new InvalidParamException("value",
							val.toString(),
							getPropertyName(), ac);
			}
			if (op != SPACE) {
				throw new InvalidParamException("operator",
						Character.toString(op),
						ac);
			}
			expression.next();
		}
		if (gotNormal) {
			if (fontSize == null) {
				fontSize = new CssFontSize();
				fontSize.value = normal;
			}
			if (fontVariant == null) {
				fontVariant = new CssFontVariant();
				fontVariant.value = normal;
			}
			if (fontWeight == null) {
				fontWeight = new CssFontWeight();
				fontWeight.value = normal;

			}
		}
	}

	public CssFont(ApplContext ac, CssExpression expression)
			throws InvalidParamException {
		this(ac, expression, false);
	}

}


--- NEW FILE: CssFontVariant.java ---
// $Id: CssFontVariant.java,v 1.1 2012/08/04 21:17:07 ylafon Exp $
// Author: Yves Lafon <ylafon@w3.org>
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.css3;

import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * //spec http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-variant-prop
 * // TODO UNFINISHED
 */
public class CssFontVariant extends org.w3c.css.properties.css.CssFontVariant {

	public static final CssIdent normal = CssIdent.getIdent("normal");
	public static final CssIdent smallCaps = CssIdent.getIdent("small-caps");

	/**
	 * Creates a new CssFontVariant
	 *
	 * @param expression The expression for this property
	 * @throws org.w3c.css.util.InvalidParamException
	 *          Expressions are incorrect
	 */
	public CssFontVariant(ApplContext ac, CssExpression expression, boolean check)
			throws InvalidParamException {
		if (check && expression.getCount() > 1) {
			throw new InvalidParamException("unrecognize", ac);
		}
		setByUser();

		CssValue val;
		char op;

		val = expression.getValue();
		op = expression.getOperator();

		// TODO FIXME this is a shorthand!
		if (val.getType() == CssTypes.CSS_IDENT) {
			CssIdent ident = (CssIdent) val;
			if (inherit.equals(ident)) {
				value = inherit;
			} else {
				value = org.w3c.css.properties.css21.CssFontVariant.getAllowedFontVariant(ident);
				if (value == null) {
					throw new InvalidParamException("value",
							val.toString(),
							getPropertyName(), ac);
				}
			}
		} else {
			throw new InvalidParamException("value",
					val.toString(),
					getPropertyName(), ac);
		}
		expression.next();
	}

	public CssFontVariant(ApplContext ac, CssExpression expression)
			throws InvalidParamException {
		this(ac, expression, false);
	}

	public CssFontVariant() {
		value = initial;
	}
}


--- NEW FILE: CssFontStyle.java ---
// $Id: CssFontStyle.java,v 1.1 2012/08/04 21:17:07 ylafon Exp $
// Author: Yves Lafon <ylafon@w3.org>
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.css3;

import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

import java.util.ArrayList;

/**
 * @spec http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-style-prop
 */
public class CssFontStyle extends org.w3c.css.properties.css.CssFontStyle {

	static final String[] _allowed_values = {"italic", "normal", "oblique"};
	static final ArrayList<CssIdent> allowed_values;

	static {
		allowed_values = new ArrayList<CssIdent>(3);
		for (String s : _allowed_values) {
			allowed_values.add(CssIdent.getIdent(s));
		}
	}

	/**
	 * Create a new CssFontStyle
	 */
	public CssFontStyle() {
		value = initial;
	}

	/**
	 * Creates a new CssFontStyle
	 *
	 * @param expression The expression for this property
	 * @throws org.w3c.css.util.InvalidParamException
	 *          Expressions are incorrect
	 */
	public CssFontStyle(ApplContext ac, CssExpression expression, boolean check)
			throws InvalidParamException {
		if (check && expression.getCount() > 1) {
			throw new InvalidParamException("unrecognize", ac);
		}
		setByUser();

		CssValue val;
		char op;

		val = expression.getValue();
		op = expression.getOperator();

		if (val.getType() == CssTypes.CSS_IDENT) {
			CssIdent ident = (CssIdent) val;
			if (inherit.equals(ident)) {
				value = inherit;
			} else {
				int pos = allowed_values.indexOf(ident);
				if (pos < 0) {
					throw new InvalidParamException("value",
							val.toString(),
							getPropertyName(), ac);
				}
				value = allowed_values.get(pos);
			}
		} else {
			throw new InvalidParamException("value",
					val.toString(),
					getPropertyName(), ac);
		}
		expression.next();
	}

	public CssFontStyle(ApplContext ac, CssExpression expression)
			throws InvalidParamException {
		this(ac, expression, false);
	}

}


--- NEW FILE: CssLineHeight.java ---
// $Id: CssLineHeight.java,v 1.1 2012/08/04 21:17:07 ylafon Exp $
// Author: Yves Lafon <ylafon@w3.org>
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.css3;

import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssLength;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssPercentage;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2002/WD-css3-linebox-20020515/#line-height
 * @version $Revision: 1.1 $
 */
public class CssLineHeight extends org.w3c.css.properties.css.CssLineHeight {

	public static final CssIdent normal = CssIdent.getIdent("normal");

    /**
     * Create a new CssLineHeight
     */
    public CssLineHeight() {
    }

    /**
     * Creates a new CssLineHeight
     *
     * @param expression The expression for this property
     * @throws org.w3c.css.util.InvalidParamException
     *          Expressions are incorrect
     */
    public CssLineHeight(ApplContext ac, CssExpression expression, boolean check)
            throws InvalidParamException {
		if (check && expression.getCount() > 1) {
			throw new InvalidParamException("unrecognize", ac);
		}
		setByUser();
		CssValue val = expression.getValue();

		switch (val.getType()) {
			case CssTypes.CSS_IDENT:
				if (inherit.equals(val)) {
					value = inherit;
				} else if (normal.equals(val)) {
					value = normal;
				} else if (none.equals(val)) {
					value = none;
				} else {
					throw new InvalidParamException("value", val.toString(),
							getPropertyName(), ac);
				}
				break;
			case CssTypes.CSS_LENGTH:
				CssLength length = (CssLength) val;
				if (!length.isPositive()) {
					throw new InvalidParamException("negative-value",
							val.toString(), ac);
				}
				value = val;
				break;
			case CssTypes.CSS_NUMBER:
				CssNumber number = (CssNumber) val;
				if (!number.isPositive()) {
					throw new InvalidParamException("negative-value",
							val.toString(), ac);
				}
				value = val;
				break;
			case CssTypes.CSS_PERCENTAGE:
				CssPercentage percent = (CssPercentage) val;
				if (!percent.isPositive()) {
					throw new InvalidParamException("negative-value",
							val.toString(), ac);
				}
				value = val;
				break;
			default:
				throw new InvalidParamException("value", val.toString(),
						getPropertyName(), ac);
		}
		expression.next();
    }

    public CssLineHeight(ApplContext ac, CssExpression expression)
            throws InvalidParamException {
        this(ac, expression, false);
    }


}


--- NEW FILE: CssFontSizeAdjust.java ---
// $Id: CssFontSizeAdjust.java,v 1.1 2012/08/04 21:17:06 ylafon Exp $
// Author: Yves Lafon <ylafon@w3.org>
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.css3;

import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-size-adjust-prop
 */
public class CssFontSizeAdjust extends org.w3c.css.properties.css.CssFontSizeAdjust {

	/**
	 * Create a new CssFontSizeAdjust
	 */
	public CssFontSizeAdjust() {
		value = initial;
	}

	/**
	 * Creates a new CssFontSizeAdjust
	 *
	 * @param expression The expression for this property
	 * @throws org.w3c.css.util.InvalidParamException
	 *          Expressions are incorrect
	 */
	public CssFontSizeAdjust(ApplContext ac, CssExpression expression, boolean check)
			throws InvalidParamException {
		if (check && expression.getCount() > 1) {
			throw new InvalidParamException("unrecognize", ac);
		}

		setByUser();

		CssValue val;
		char op;

		val = expression.getValue();
		op = expression.getOperator();

		switch (val.getType()) {
			case CssTypes.CSS_IDENT:
				CssIdent id = (CssIdent) val;
				if (inherit.equals(id)) {
					value = inherit;
				} else if (none.equals(id)) {
					value = none;
				} else {
					throw new InvalidParamException("value",
							val.toString(),
							getPropertyName(), ac);
				}
				break;
			case CssTypes.CSS_NUMBER:
				value = val;
				break;
			default:
				throw new InvalidParamException("value",
						val.toString(),
						getPropertyName(), ac);
		}
		expression.next();

	}

	public CssFontSizeAdjust(ApplContext ac, CssExpression expression)
			throws InvalidParamException {
		this(ac, expression, false);
	}

}


--- NEW FILE: CssFontSize.java ---
// $Id: CssFontSize.java,v 1.1 2012/08/04 21:17:06 ylafon Exp $
// Author: Yves Lafon <ylafon@w3.org>
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.css3;

import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssLength;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssPercentage;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

import java.util.HashMap;

/**
 * @spec http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-size-prop
 */
public class CssFontSize extends org.w3c.css.properties.css.CssFontSize {

	public static final HashMap<String,CssIdent> allowed_values;
	static final String[] absolute_values = {"xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"};
	static final String[] relative_values = {"smaller", "larger"};

	static {
		allowed_values = new HashMap<String, CssIdent>();
		for (String s : absolute_values) {
			allowed_values.put(s, CssIdent.getIdent(s));
		}
		for (String s : relative_values) {
			allowed_values.put(s, CssIdent.getIdent(s));
		}
	}
	/**
	 * Create a new CssFontSize
	 */
	public CssFontSize() {
		value = initial;
	}

	/**
	 * Creates a new CssFontSize
	 *
	 * @param expression The expression for this property
	 * @throws org.w3c.css.util.InvalidParamException
	 *          Expressions are incorrect
	 */
	public CssFontSize(ApplContext ac, CssExpression expression, boolean check)
			throws InvalidParamException {
		if (check && expression.getCount() > 1) {
			throw new InvalidParamException("unrecognize", ac);
		}
		setByUser();

		CssValue val;
		char op;

		val = expression.getValue();
		op = expression.getOperator();

		switch (val.getType()) {
			case CssTypes.CSS_NUMBER:
				val = ((CssNumber)val).getLength();
			case CssTypes.CSS_LENGTH:
				CssLength l = (CssLength) val;
				if (!l.isPositive()) {
					throw new InvalidParamException("negative-value",
							val.toString(), ac);
				}
				value = l;
				break;
			case CssTypes.CSS_PERCENTAGE:
				CssPercentage p = (CssPercentage) val;
				if (!p.isPositive()) {
					throw new InvalidParamException("negative-value",
							val.toString(), ac);
				}
				value = p;
				break;
			case CssTypes.CSS_IDENT:
				CssIdent ident = (CssIdent) val;
				if (inherit.equals(ident)) {
					value = inherit;
					break;
				}
				value = allowed_values.get(val.toString());
				if (value == null) {
					throw new InvalidParamException("value",
							expression.getValue().toString(),
							getPropertyName(), ac);
				}
				 break;
			default:
				throw new InvalidParamException("value",
						expression.getValue().toString(),
						getPropertyName(), ac);
		}
		expression.next();
	}

	public CssFontSize(ApplContext ac, CssExpression expression)
			throws InvalidParamException {
		this(ac, expression, false);
	}


}


--- NEW FILE: CssFontWeight.java ---
// $Id: CssFontWeight.java,v 1.1 2012/08/04 21:17:07 ylafon Exp $
// Author: Yves Lafon <ylafon@w3.org>
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.css3;

import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

import java.util.HashMap;

/**
 * @spec http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-weight-prop
 */
public class CssFontWeight extends org.w3c.css.properties.css.CssFontWeight {

	public static final HashMap<String,CssIdent> allowed_values;
	static final String[] _allowed_values = {"normal", "bold", "bolder", "lighter"};

	static {
		allowed_values = new HashMap<String, CssIdent>(_allowed_values.length);
		for (String s : _allowed_values) {
			allowed_values.put(s, CssIdent.getIdent(s));
		}
	}
    /**
     * Create a new CssFontWeight
     */
    public CssFontWeight() {
		value = initial;
    }

    /**
     * Creates a new CssFontWeight
     *
     * @param expression The expression for this property
     * @throws org.w3c.css.util.InvalidParamException
     *          Expressions are incorrect
     */
    public CssFontWeight(ApplContext ac, CssExpression expression, boolean check)
            throws InvalidParamException {
		if (check && expression.getCount() > 1) {
			throw new InvalidParamException("unrecognize", ac);
		}
		setByUser();

		CssValue val;
		char op;

		val = expression.getValue();
		op = expression.getOperator();

		switch (val.getType()) {
			case CssTypes.CSS_NUMBER:
				CssNumber num = (CssNumber) val;
				switch(num.getInt()) {
					case 100:
					case 200:
					case 300:
					case 400:
					case 500:
					case 600:
					case 700:
					case 800:
					case 900:
					   value = num;
						break;
					default:
						throw new InvalidParamException("value",
								val.toString(),
								getPropertyName(), ac);
				}
				break;
			case CssTypes.CSS_IDENT:
				CssIdent ident = (CssIdent) val;
				if (inherit.equals(ident)) {
					value = inherit;
					break;
				}
				value = allowed_values.get(val.toString());
				if (value == null) {
					throw new InvalidParamException("value",
							val.toString(),
							getPropertyName(), ac);
				}
				break;
			default:
				throw new InvalidParamException("value",
						expression.getValue().toString(),
						getPropertyName(), ac);
		}
		expression.next();
    }

    public CssFontWeight(ApplContext ac, CssExpression expression)
            throws InvalidParamException {
        this(ac, expression, false);
    }

}


--- NEW FILE: CssFontFamily.java ---
// $Id: CssFontFamily.java,v 1.1 2012/08/04 21:17:06 ylafon Exp $
// Author: Yves Lafon <ylafon@w3.org>
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.css3;

import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

import java.util.ArrayList;

import static org.w3c.css.values.CssOperator.COMMA;
import static org.w3c.css.values.CssOperator.SPACE;

/**
 * @spec http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-family-prop
 */
public class CssFontFamily extends org.w3c.css.properties.css.CssFontFamily {

	public static final ArrayList<CssIdent> genericNames;
	public static final ArrayList<CssIdent> reservedNames;

	public static final String[] _genericNames = {
			"serif",
			"sans-serif",
			"cursive",
			"fantasy",
			"monospace"};

	public static final String[] _reservedNames = {"inherit",
			"initial", "default"
	};

	static {
		genericNames = new ArrayList<CssIdent>();
		for (String s : _genericNames) {
			genericNames.add(CssIdent.getIdent(s));
		}
		reservedNames = new ArrayList<CssIdent>();
		for (String s : _reservedNames) {
			reservedNames.add(CssIdent.getIdent(s));
		}
	}

	static CssIdent getGenericFontName(CssIdent ident) {
		int pos = genericNames.indexOf(ident);
		if (pos >= 0) {
			return genericNames.get(pos);
		}
		return null;
	}

	static CssIdent getReservedFontName(CssIdent ident) {
		int pos = reservedNames.indexOf(ident);
		if (pos >= 0) {
			return reservedNames.get(pos);
		}
		return null;
	}

	private void checkExpression(ApplContext ac, ArrayList<CssValue> curval,
								 ArrayList<CssIdent> values, boolean check) {
		CssIdent val;
		if (values.size() > 1) {
			// create a value out of that. We could even create
			// a CssString for the output (TODO ?)
			StringBuilder sb = new StringBuilder();
			boolean addSpace = false;
			for (CssIdent id : values) {
				if (addSpace) {
					sb.append(' ');
				} else {
					addSpace = true;
				}
				sb.append(id);
			}
			ac.getFrame().addWarning("with-space", 1);
			val = new CssIdent(sb.toString());
		} else {
			val = values.get(0);
			// could be done in the consistency check, but...
			if (null != getGenericFontName(val)) {
				hasGenericFontFamily = true;
			}
			if (inherit.equals(val)) {
				val = inherit;
			}
		}
		curval.add(val);
	}

	// final consistency check
	private void checkValues(ApplContext ac, ArrayList<CssValue> values)
			throws InvalidParamException {
		// we need to check that we don't have 'inherit' in multiple values
		if (values.size() > 1) {
			for (CssValue val : values) {
				if (inherit.equals(val)) {
					throw new InvalidParamException("unrecognize", ac);
				}
			}
		}
	}

	/**
	 * Creates a new CssFontFamily
	 *
	 * @param expression The expression for this property
	 * @throws org.w3c.css.util.InvalidParamException
	 *          Expressions are incorrect
	 */
	public CssFontFamily(ApplContext ac, CssExpression expression, boolean check)
			throws InvalidParamException {

		ArrayList<CssValue> values = new ArrayList<CssValue>();

		while (!expression.end()) {
			char op = expression.getOperator();
			CssValue val = expression.getValue();
			switch (val.getType()) {
				case CssTypes.CSS_STRING:
					// check it's not a quoted reserved keyword
					String s = val.toString();
					if (s.length() > 2) {
						// we remove quotes and check it's not reserved.
						CssIdent id = new CssIdent(s.substring(1, s.length() - 1));
						if (getGenericFontName(id) != null) {
							ac.getFrame().addWarning("generic-family.quote", 2);
						}
					}
					values.add(val);
					break;
				case CssTypes.CSS_IDENT:
					ArrayList<CssIdent> idval = new ArrayList<CssIdent>();
					idval.add((CssIdent) val);
					// we add idents if separated by spaces...
					expression.next();
					while (op == SPACE && !expression.end()) {
						op = expression.getOperator();
						val = expression.getValue();
						if (val.getType() == CssTypes.CSS_IDENT) {
							idval.add((CssIdent) val);
						} else {
							throw new InvalidParamException("value", val,
									getPropertyName(), ac);
						}
						expression.next();
					}
					checkExpression(ac, values, idval, check);
					break;
				default:
					throw new InvalidParamException("value", val,
							getPropertyName(), ac);
			}
			expression.next();
			if (!expression.end() && (op != COMMA)) {
				throw new InvalidParamException("operator",
						((new Character(op)).toString()), ac);
			}
		}
		checkValues(ac, values);
		value = (values.size() > 1) ? values : values.get(0);
	}

	public CssFontFamily(ApplContext ac, CssExpression expression)
			throws InvalidParamException {
		this(ac, expression, false);
	}

	public CssFontFamily() {
		value = initial;
	}
}

Received on Saturday, 4 August 2012 21:17:11 UTC