Skip to content

Commit

Permalink
added font-face.font-display per https://www.w3.org/TR/2018/WD-css-fo…
Browse files Browse the repository at this point in the history
  • Loading branch information
ylafon committed Aug 28, 2018
1 parent 01d024c commit 52af757
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 29 deletions.
1 change: 1 addition & 0 deletions org/w3c/css/properties/CSS3Properties.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions org/w3c/css/properties/CSS3SVGProperties.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
118 changes: 118 additions & 0 deletions org/w3c/css/properties/css/fontface/CssFontDisplay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//
// Author: Yves Lafon <[email protected]>
//
// (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;
}
}
}

26 changes: 19 additions & 7 deletions org/w3c/css/properties/css3/Css3Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -488,7 +500,7 @@ public CssPlaceItems getPlaceItems() {
}
return cssPlaceItems;
}

public CssJustifyItems getJustifyItems() {
if (cssJustifyItems == null) {
cssJustifyItems =
Expand All @@ -497,7 +509,7 @@ public CssJustifyItems getJustifyItems() {
}
return cssJustifyItems;
}

public CssPlaceContent getPlaceContent() {
if (cssPlaceContent == null) {
cssPlaceContent =
Expand All @@ -506,7 +518,7 @@ public CssPlaceContent getPlaceContent() {
}
return cssPlaceContent;
}

public CssPlaceSelf getPlaceSelf() {
if (cssPlaceSelf == null) {
cssPlaceSelf =
Expand All @@ -515,7 +527,7 @@ public CssPlaceSelf getPlaceSelf() {
}
return cssPlaceSelf;
}

public CssJustifySelf getJustifySelf() {
if (cssJustifySelf == null) {
cssJustifySelf =
Expand All @@ -524,7 +536,7 @@ public CssJustifySelf getJustifySelf() {
}
return cssJustifySelf;
}

public CssGap getGap() {
if (cssGap == null) {
cssGap =
Expand All @@ -533,7 +545,7 @@ public CssGap getGap() {
}
return cssGap;
}

public CssRowGap getRowGap() {
if (cssRowGap == null) {
cssRowGap =
Expand All @@ -542,7 +554,7 @@ public CssRowGap getRowGap() {
}
return cssRowGap;
}

public CssTextCombineUpright getTextCombineUpright() {
if (cssTextCombineUpright == null) {
cssTextCombineUpright =
Expand Down
88 changes: 88 additions & 0 deletions org/w3c/css/properties/css3/fontface/CssFontDisplay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// Author: Yves Lafon <[email protected]>
//
// (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);
}

}

22 changes: 0 additions & 22 deletions org/w3c/css/properties/css3/fontface/CssSrc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down

1 comment on commit 52af757

@ylafon
Copy link
Member Author

@ylafon ylafon commented on 52af757 Aug 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #140

Please sign in to comment.