From 52af7570bba4196b1468fd6df04c8df31686a159 Mon Sep 17 00:00:00 2001 From: Yves Lafon Date: Tue, 28 Aug 2018 12:00:24 +0200 Subject: [PATCH] added font-face.font-display per https://www.w3.org/TR/2018/WD-css-fonts-4-20180410/#font-display-desc --- .../css/properties/CSS3Properties.properties | 1 + .../properties/CSS3SVGProperties.properties | 1 + .../css/fontface/CssFontDisplay.java | 118 ++++++++++++++++++ org/w3c/css/properties/css3/Css3Style.java | 26 ++-- .../css3/fontface/CssFontDisplay.java | 88 +++++++++++++ .../css/properties/css3/fontface/CssSrc.java | 22 ---- 6 files changed, 227 insertions(+), 29 deletions(-) create mode 100644 org/w3c/css/properties/css/fontface/CssFontDisplay.java create mode 100644 org/w3c/css/properties/css3/fontface/CssFontDisplay.java diff --git a/org/w3c/css/properties/CSS3Properties.properties b/org/w3c/css/properties/CSS3Properties.properties index eb7157fd2..b25972812 100644 --- a/org/w3c/css/properties/CSS3Properties.properties +++ b/org/w3c/css/properties/CSS3Properties.properties @@ -484,6 +484,7 @@ lighting-color: org.w3c.css.properties.css3.CssLightingC @font-face.font-size: org.w3c.css.properties.css2.font.FontSize @font-face.font-family: org.w3c.css.properties.css2.font.FontFamily @font-face.font-stretch: org.w3c.css.properties.css2.font.FontStretch +@font-face.font-display: org.w3c.css.properties.css3.fontface.CssFontDisplay mediafeature.width: org.w3c.css.atrules.css3.media.MediaWidth mediafeature.height: org.w3c.css.atrules.css3.media.MediaHeight diff --git a/org/w3c/css/properties/CSS3SVGProperties.properties b/org/w3c/css/properties/CSS3SVGProperties.properties index b4e8ca36e..c8f6fec1a 100644 --- a/org/w3c/css/properties/CSS3SVGProperties.properties +++ b/org/w3c/css/properties/CSS3SVGProperties.properties @@ -541,6 +541,7 @@ lighting-color: org.w3c.css.properties.css3.CssLightingC @font-face.font-size: org.w3c.css.properties.css2.font.FontSize @font-face.font-family: org.w3c.css.properties.css2.font.FontFamily @font-face.font-stretch: org.w3c.css.properties.css2.font.FontStretch +@font-face.font-display: org.w3c.css.properties.css3.fontface.CssFontDisplay mediafeature.width: org.w3c.css.atrules.css3.media.MediaWidth mediafeature.height: org.w3c.css.atrules.css3.media.MediaHeight diff --git a/org/w3c/css/properties/css/fontface/CssFontDisplay.java b/org/w3c/css/properties/css/fontface/CssFontDisplay.java new file mode 100644 index 000000000..92b7ece53 --- /dev/null +++ b/org/w3c/css/properties/css/fontface/CssFontDisplay.java @@ -0,0 +1,118 @@ +// +// Author: Yves Lafon +// +// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2018. +// Please first read the full copyright statement in file COPYRIGHT.html + +package org.w3c.css.properties.css.fontface; + +import org.w3c.css.parser.CssStyle; +import org.w3c.css.properties.css.CssProperty; +import org.w3c.css.properties.css3.Css3Style; +import org.w3c.css.util.ApplContext; +import org.w3c.css.util.InvalidParamException; +import org.w3c.css.values.CssExpression; +import org.w3c.css.values.CssValue; + +/** + * @since CSS3 + */ +public class CssFontDisplay extends CssProperty { + + public CssValue value; + + /** + * Create a new CssFontDisplay + */ + public CssFontDisplay() { + } + + /** + * Creates a new CssFontDisplay + * + * @param expression The expression for this property + * @throws org.w3c.css.util.InvalidParamException + * Expressions are incorrect + */ + public CssFontDisplay(ApplContext ac, CssExpression expression, boolean check) + throws InvalidParamException { + throw new InvalidParamException("value", + expression.getValue().toString(), + getPropertyName(), ac); + } + + public CssFontDisplay(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } + + /** + * Returns the value of this property + */ + public Object get() { + return value; + } + + + /** + * Returns the name of this property + */ + public final String getPropertyName() { + return "font-display"; + } + + /** + * Returns true if this property is "softly" inherited + * e.g. his value is equals to inherit + */ + public boolean isSoftlyInherited() { + return value.equals(inherit); + } + + /** + * Returns a string representation of the object. + */ + public String toString() { + return value.toString(); + } + + /** + * Add this property to the CssStyle. + * + * @param style The CssStyle + */ + public void addToStyle(ApplContext ac, CssStyle style) { + Css3Style s = (Css3Style) style; + if (s.fontFaceCssFontDisplay != null) { + style.addRedefinitionWarning(ac, this); + } + s.fontFaceCssFontDisplay = this; + } + + + /** + * Compares two properties for equality. + * + * @param property The other property. + */ + public boolean equals(CssProperty property) { + return (property instanceof CssFontDisplay && + value.equals(((CssFontDisplay) property).value)); + } + + + /** + * Get this property in the style. + * + * @param style The style where the property is + * @param resolve if true, resolve the style to find this property + */ + public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) { + if (resolve) { + return ((Css3Style) style).getFontFaceCssFontDisplay(); + } else { + return ((Css3Style) style).fontFaceCssFontDisplay; + } + } +} + diff --git a/org/w3c/css/properties/css3/Css3Style.java b/org/w3c/css/properties/css3/Css3Style.java index 25044ac39..085e902cd 100644 --- a/org/w3c/css/properties/css3/Css3Style.java +++ b/org/w3c/css/properties/css3/Css3Style.java @@ -218,6 +218,7 @@ import org.w3c.css.properties.css.counterstyle.CssSuffix; import org.w3c.css.properties.css.counterstyle.CssSymbols; import org.w3c.css.properties.css.counterstyle.CssSystem; +import org.w3c.css.properties.css.fontface.CssFontDisplay; import org.w3c.css.properties.css.viewport.CssMaxZoom; import org.w3c.css.properties.css.viewport.CssMinZoom; import org.w3c.css.properties.css.viewport.CssOrientation; @@ -479,6 +480,17 @@ public class Css3Style extends ATSCStyle { public CssJustifyItems cssJustifyItems; public CssPlaceItems cssPlaceItems; + public CssFontDisplay fontFaceCssFontDisplay; + + + public CssFontDisplay getFontFaceCssFontDisplay() { + if (fontFaceCssFontDisplay == null) { + fontFaceCssFontDisplay = + (CssFontDisplay) style.CascadingOrder(new CssFontDisplay(), + style, selector); + } + return fontFaceCssFontDisplay; + } public CssPlaceItems getPlaceItems() { if (cssPlaceItems == null) { @@ -488,7 +500,7 @@ public CssPlaceItems getPlaceItems() { } return cssPlaceItems; } - + public CssJustifyItems getJustifyItems() { if (cssJustifyItems == null) { cssJustifyItems = @@ -497,7 +509,7 @@ public CssJustifyItems getJustifyItems() { } return cssJustifyItems; } - + public CssPlaceContent getPlaceContent() { if (cssPlaceContent == null) { cssPlaceContent = @@ -506,7 +518,7 @@ public CssPlaceContent getPlaceContent() { } return cssPlaceContent; } - + public CssPlaceSelf getPlaceSelf() { if (cssPlaceSelf == null) { cssPlaceSelf = @@ -515,7 +527,7 @@ public CssPlaceSelf getPlaceSelf() { } return cssPlaceSelf; } - + public CssJustifySelf getJustifySelf() { if (cssJustifySelf == null) { cssJustifySelf = @@ -524,7 +536,7 @@ public CssJustifySelf getJustifySelf() { } return cssJustifySelf; } - + public CssGap getGap() { if (cssGap == null) { cssGap = @@ -533,7 +545,7 @@ public CssGap getGap() { } return cssGap; } - + public CssRowGap getRowGap() { if (cssRowGap == null) { cssRowGap = @@ -542,7 +554,7 @@ public CssRowGap getRowGap() { } return cssRowGap; } - + public CssTextCombineUpright getTextCombineUpright() { if (cssTextCombineUpright == null) { cssTextCombineUpright = diff --git a/org/w3c/css/properties/css3/fontface/CssFontDisplay.java b/org/w3c/css/properties/css3/fontface/CssFontDisplay.java new file mode 100644 index 000000000..f9f4b1fe1 --- /dev/null +++ b/org/w3c/css/properties/css3/fontface/CssFontDisplay.java @@ -0,0 +1,88 @@ +// +// Author: Yves Lafon +// +// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2018. +// Please first read the full copyright statement in file COPYRIGHT.html +package org.w3c.css.properties.css3.fontface; + +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 https://www.w3.org/TR/2018/WD-css-fonts-4-20180410/#font-display-desc + */ +public class CssFontDisplay extends org.w3c.css.properties.css.fontface.CssFontDisplay { + + public static final CssIdent[] allowed_values; + + static { + String[] _allowed_values = {"auto", "block", "swap", "fallback", "optional"}; + allowed_values = new CssIdent[_allowed_values.length]; + int i = 0; + for (String s : _allowed_values) { + allowed_values[i++] = CssIdent.getIdent(s); + } + } + + public static CssIdent getAllowedIdent(CssIdent ident) { + for (CssIdent id : allowed_values) { + if (id.equals(ident)) { + return id; + } + } + return null; + } + + /** + * Create a new CssFontDisplay + */ + public CssFontDisplay() { + value = initial; + } + + /** + * Creates a new CssFontDisplay + * + * @param expression The expression for this property + * @throws org.w3c.css.util.InvalidParamException + * Expressions are incorrect + */ + public CssFontDisplay(ApplContext ac, CssExpression expression, boolean check) + throws InvalidParamException { + if (check && expression.getCount() > 1) { + throw new InvalidParamException("unrecognize", ac); + } + + setByUser(); + + char op; + CssValue val; + + val = expression.getValue(); + op = expression.getOperator(); + + switch (val.getType()) { + case CssTypes.CSS_IDENT: + value = getAllowedIdent((CssIdent) val); + if (value != null) { + break; + } + default: + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } + expression.next(); + } + + public CssFontDisplay(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } + +} + diff --git a/org/w3c/css/properties/css3/fontface/CssSrc.java b/org/w3c/css/properties/css3/fontface/CssSrc.java index e837d07fe..197e4f1ba 100644 --- a/org/w3c/css/properties/css3/fontface/CssSrc.java +++ b/org/w3c/css/properties/css3/fontface/CssSrc.java @@ -9,7 +9,6 @@ import org.w3c.css.util.InvalidParamException; import org.w3c.css.values.CssExpression; import org.w3c.css.values.CssFunction; -import org.w3c.css.values.CssIdent; import org.w3c.css.values.CssLayerList; import org.w3c.css.values.CssTypes; import org.w3c.css.values.CssValue; @@ -25,27 +24,6 @@ */ public class CssSrc extends org.w3c.css.properties.css.fontface.CssSrc { - public static final CssIdent[] allowed_values; - - static { - String[] _allowed_values = {"flex-start", "flex-end", "center", "space-between", - "space-around", "stretch"}; - allowed_values = new CssIdent[_allowed_values.length]; - int i = 0; - for (String s : _allowed_values) { - allowed_values[i++] = CssIdent.getIdent(s); - } - } - - public static CssIdent getAllowedIdent(CssIdent ident) { - for (CssIdent id : allowed_values) { - if (id.equals(ident)) { - return id; - } - } - return null; - } - /** * Create a new CssSrc */