-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added font-face.font-display per https://www.w3.org/TR/2018/WD-css-fo…
- Loading branch information
Showing
6 changed files
with
227 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
org/w3c/css/properties/css/fontface/CssFontDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52af757
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #140