W3C home > Mailing lists > Public > www-validator-cvs@w3.org > August 2012

2002/css-validator/org/w3c/css/properties/css3 CssFontFeatureSettings.java,NONE,1.1 Css3Style.java,1.29,1.30

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Mon, 13 Aug 2012 05:38:58 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1T0nMg-0001zS-NK@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/properties/css3
In directory hutz:/tmp/cvs-serv7312/w3c/css/properties/css3

Modified Files:
	Css3Style.java 
Added Files:
	CssFontFeatureSettings.java 
Log Message:
font-feature-settings per w3c/css/properties/css/CssFontFeatureSettings.java

--- NEW FILE: CssFontFeatureSettings.java ---
// $Id: CssFontFeatureSettings.java,v 1.1 2012/08/13 05:38:56 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 org.w3c.css.values.CssValueList;

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/#propdef-font-feature-settings
 */
public class CssFontFeatureSettings extends org.w3c.css.properties.css.CssFontFeatureSettings {

	public static final CssIdent on, off;

	static {
		on = CssIdent.getIdent("on");
		off = CssIdent.getIdent("off");

	}

	public Object value;

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

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

		setByUser();
		CssValue val;
		ArrayList<CssValue> values;
		CssExpression singleExpr = null;
		CssValue b_val = null;
		char op;

		values = new ArrayList<CssValue>();
		// we just accumulate values and check at validation
		while (!expression.end()) {
			val = expression.getValue();
			op = expression.getOperator();

			if (inherit.equals(val)) {
				if (expression.getCount() > 1) {
					throw new InvalidParamException("value", val,
							getPropertyName(), ac);
				}
				value = inherit;
				expression.next();
				return;
			}
			if (singleExpr == null) {
				singleExpr = new CssExpression();
			}
			// we will check later
			singleExpr.addValue(val);
			singleExpr.setOperator(op);
			expression.next();

			if (!expression.end()) {
				// incomplete value followed by a comma... it's complete!
				if (op == COMMA) {
					singleExpr.setOperator(SPACE);
					b_val = check(ac, singleExpr);
					values.add(b_val);
					singleExpr = null;
				} else if ((op != SPACE)) {
					throw new InvalidParamException("operator",
							((new Character(op)).toString()), ac);
				}
			}
		}
		// if we reach the end in a value that can come in pair
		if (singleExpr != null) {
			b_val = check(ac, singleExpr);
			values.add(b_val);
		}
		if (values.size() == 1) {
			value = values.get(0);
		} else {
			value = values;
		}
	}

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

	public CssValue check(ApplContext ac, CssExpression exp)
			throws InvalidParamException {
		CssValue val;
		if (exp.getCount() > 2) {
			throw new InvalidParamException("unrecognize", ac);
		}
		val = exp.getValue();
		if (val.getType() == CssTypes.CSS_STRING) {
			String s = val.toString();
			// limit of 4 characters + two surrounding quotes
			if (s.length() != 6) {
				throw new InvalidParamException("value",
						s, getPropertyName(), ac);
			}
		} else {
			throw new InvalidParamException("value",
					val.toString(),
					getPropertyName(), ac);
		}
		if (exp.getCount() == 1) {
			return val;
		}
		ArrayList<CssValue> v = new ArrayList<CssValue>(2);
		v.add(val);
		// now check the second value
		exp.next();
		val = exp.getValue();
		switch (val.getType()) {
			case CssTypes.CSS_NUMBER:
				CssNumber n = (CssNumber) val;
				if (!n.isPositive()) {
					throw new InvalidParamException("negative-value",
							val.toString(),
							getPropertyName(), ac);
				}
				v.add(n);
				break;
			case CssTypes.CSS_IDENT:
				if (on.equals(val)) {
					v.add(on);
					break;
				}
				if (off.equals(val)) {
					v.add(off);
					break;
				}
				// let it fail
			default:
				throw new InvalidParamException("value",
						val.toString(),
						getPropertyName(), ac);
		}
		return new CssValueList(v);
	}

	/**
	 * Returns a string representation of the object.
	 */
	public String toString() {
		if (value instanceof ArrayList) {
			StringBuilder sb = new StringBuilder();
			boolean addComa = false;
			for (Object v : (ArrayList) value) {
				if (addComa) {
					sb.append(", ");
				} else {
					addComa = true;
				}
				sb.append(v);
			}
			return sb.toString();
		}
		return value.toString();
	}
}


Index: Css3Style.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css3/Css3Style.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- Css3Style.java	10 Aug 2012 05:02:13 -0000	1.29
+++ Css3Style.java	13 Aug 2012 05:38:56 -0000	1.30
@@ -28,6 +28,7 @@
 import org.w3c.css.properties.css.CssColumnSpan;
 import org.w3c.css.properties.css.CssColumnWidth;
 import org.w3c.css.properties.css.CssColumns;
+import org.w3c.css.properties.css.CssFontFeatureSettings;
 import org.w3c.css.properties.css.CssFontKerning;
 import org.w3c.css.properties.css.CssFontLanguageOverride;
 import org.w3c.css.properties.css.CssFontSynthesis;
@@ -155,6 +156,7 @@
 	public CssFontVariantEastAsian cssFontVariantEastAsian;
 	public CssFontVariantLigatures cssFontVariantLigatures;
 	public CssFontVariantNumeric cssFontVariantNumeric;
+	public CssFontFeatureSettings cssFontFeatureSettings;
 
 	CssDropInitialAfterAdjust cssDropInitialAfterAdjust;
 	CssDropInitialAfterAlign cssDropInitialAfterAlign;
@@ -1638,6 +1640,15 @@
 		return cssFontVariantNumeric;
 	}
 
+	public CssFontFeatureSettings getFontFeatureSettings() {
+		if (cssFontFeatureSettings == null) {
+			cssFontFeatureSettings =
+					(CssFontFeatureSettings) style.CascadingOrder(
+							new CssFontFeatureSettings(), style, selector);
+		}
+		return cssFontFeatureSettings;
+	}
+
 	///
 
 	public CssTextIndentCSS3 getTextIndentCSS3() {
Received on Monday, 13 August 2012 05:39:02 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:50 UTC