- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Sat, 04 Aug 2012 21:17:08 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/properties/css21
In directory hutz:/tmp/cvs-serv31218/w3c/css/properties/css21
Added Files:
CssFont.java CssFontFamily.java CssFontSize.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
--- 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.css21;
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/REC-CSS2-20110607/fonts.html#propdef-font
*/
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() {
}
/**
* 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 = CssFontStyle.allowed_values.indexOf(ident);
if (pos >= 0) {
if (fontStyle != null) {
throw new InvalidParamException("value",
val.toString(),
getPropertyName(), ac);
}
fontStyle = new 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: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.css21;
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/REC-CSS2-20110607/fonts.html#propdef-font-variant
*/
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");
public static final CssIdent getAllowedFontVariant(CssIdent ident) {
if (smallCaps.equals(ident)) {
return smallCaps;
}
if (normal.equals(ident)) {
return normal;
}
return null;
}
/**
* 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();
if (val.getType() == CssTypes.CSS_IDENT) {
CssIdent ident = (CssIdent) val;
if (inherit.equals(ident)) {
value = inherit;
} else {
value = 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() {
}
}
--- NEW FILE: CssFontStyle.java ---
// $Id: CssFontStyle.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.css21;
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/REC-CSS2-20110607/fonts.html#propdef-font-style
*/
public class CssFontStyle extends org.w3c.css.properties.css.CssFontStyle {
static final String[] _allowed_values = {"italic", "normal", "oblique"};
public 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() {
}
/**
* 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: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.css21;
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/2011/REC-CSS2-20110607/visudet.html#propdef-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 {
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: 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.css21;
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/REC-CSS2-20110607/fonts.html#font-size-props
*/
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() {
}
/**
* 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: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.css21;
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/REC-CSS2-20110607/fonts.html#propdef-font-weight
* @version $Revision: 1.1 $
*/
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() {
}
/**
* 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.css21;
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/REC-CSS2-20110607/fonts.html#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);
}
}
Received on Saturday, 4 August 2012 21:17:10 UTC