Skip to content

Commit f1b1587

Browse files
committed
1 parent 122e3d5 commit f1b1587

File tree

3 files changed

+219
-0
lines changed

3 files changed

+219
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2021.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
7+
package org.w3c.css.properties.css.fontface;
8+
9+
import org.w3c.css.parser.CssStyle;
10+
import org.w3c.css.properties.css.CssProperty;
11+
import org.w3c.css.properties.css3.Css3Style;
12+
import org.w3c.css.util.ApplContext;
13+
import org.w3c.css.util.InvalidParamException;
14+
import org.w3c.css.values.CssExpression;
15+
import org.w3c.css.values.CssValue;
16+
17+
/**
18+
* @since CSS3
19+
*/
20+
public class CssAscentOverride extends CssProperty {
21+
22+
public CssValue value;
23+
24+
/**
25+
* Create a new CssAscentOverride
26+
*/
27+
public CssAscentOverride() {
28+
}
29+
30+
/**
31+
* Creates a new CssAscentOverride
32+
*
33+
* @param expression The expression for this property
34+
* @throws InvalidParamException
35+
* Expressions are incorrect
36+
*/
37+
public CssAscentOverride(ApplContext ac, CssExpression expression, boolean check)
38+
throws InvalidParamException {
39+
throw new InvalidParamException("value",
40+
expression.getValue().toString(),
41+
getPropertyName(), ac);
42+
}
43+
44+
public CssAscentOverride(ApplContext ac, CssExpression expression)
45+
throws InvalidParamException {
46+
this(ac, expression, false);
47+
}
48+
49+
/**
50+
* Returns the value of this property
51+
*/
52+
public Object get() {
53+
return value;
54+
}
55+
56+
57+
/**
58+
* Returns the name of this property
59+
*/
60+
public final String getPropertyName() {
61+
return "ascent-override";
62+
}
63+
64+
/**
65+
* Returns true if this property is "softly" inherited
66+
* e.g. his value is equals to inherit
67+
*/
68+
public boolean isSoftlyInherited() {
69+
return value.equals(inherit);
70+
}
71+
72+
/**
73+
* Returns a string representation of the object.
74+
*/
75+
public String toString() {
76+
return value.toString();
77+
}
78+
79+
/**
80+
* Add this property to the CssStyle.
81+
*
82+
* @param style The CssStyle
83+
*/
84+
public void addToStyle(ApplContext ac, CssStyle style) {
85+
Css3Style s = (Css3Style) style;
86+
if (s.fontFaceCssAscentOverride != null) {
87+
style.addRedefinitionWarning(ac, this);
88+
}
89+
s.fontFaceCssAscentOverride = this;
90+
}
91+
92+
93+
/**
94+
* Compares two properties for equality.
95+
*
96+
* @param property The other property.
97+
*/
98+
public boolean equals(CssProperty property) {
99+
return (property instanceof CssAscentOverride &&
100+
value.equals(((CssAscentOverride) property).value));
101+
}
102+
103+
104+
/**
105+
* Get this property in the style.
106+
*
107+
* @param style The style where the property is
108+
* @param resolve if true, resolve the style to find this property
109+
*/
110+
public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) {
111+
if (resolve) {
112+
return ((Css3Style) style).getFontFaceCssAscentOverride();
113+
} else {
114+
return ((Css3Style) style).fontFaceCssAscentOverride;
115+
}
116+
}
117+
}
118+

org/w3c/css/properties/css3/Css3Style.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@
300300
import org.w3c.css.properties.css.counterstyle.CssSuffix;
301301
import org.w3c.css.properties.css.counterstyle.CssSymbols;
302302
import org.w3c.css.properties.css.counterstyle.CssSystem;
303+
import org.w3c.css.properties.css.fontface.CssAscentOverride;
303304
import org.w3c.css.properties.css.fontface.CssFontDisplay;
304305
import org.w3c.css.properties.css.fontface.CssFontNamedInstance;
305306
import org.w3c.css.properties.css.fontface.CssFontStretch;
@@ -586,6 +587,7 @@ public class Css3Style extends ATSCStyle {
586587
public CssFontStretch fontFaceCssFontStretch;
587588
public CssFontStyle fontFaceCssFontStyle;
588589
public CssFontNamedInstance fontFaceCssFontNamedInstance;
590+
public CssAscentOverride fontFaceCssAscentOverride;
589591

590592
public CssColorAdjust cssColorAdjust;
591593
public CssForcedColorAdjust cssForcedColorAdjust;
@@ -1288,6 +1290,15 @@ public org.w3c.css.properties.css.page.CssMarks getPageCssMarks() {
12881290
return pageCssMarks;
12891291
}
12901292

1293+
public CssAscentOverride getFontFaceCssAscentOverride() {
1294+
if (fontFaceCssAscentOverride == null) {
1295+
fontFaceCssAscentOverride =
1296+
(CssAscentOverride) style.CascadingOrder(new CssAscentOverride(),
1297+
style, selector);
1298+
}
1299+
return fontFaceCssAscentOverride;
1300+
}
1301+
12911302
public CssFontNamedInstance getFontFaceCssFontNamedInstance() {
12921303
if (fontFaceCssFontNamedInstance == null) {
12931304
fontFaceCssFontNamedInstance =
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2018.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
package org.w3c.css.properties.css3.fontface;
7+
8+
import org.w3c.css.util.ApplContext;
9+
import org.w3c.css.util.InvalidParamException;
10+
import org.w3c.css.values.CssExpression;
11+
import org.w3c.css.values.CssIdent;
12+
import org.w3c.css.values.CssTypes;
13+
import org.w3c.css.values.CssValue;
14+
15+
/**
16+
* @spec https://www.w3.org/TR/2021/WD-css-fonts-4-20210729/#descdef-font-face-ascent-override
17+
*/
18+
public class CssAscentOverride extends org.w3c.css.properties.css.fontface.CssAscentOverride {
19+
20+
public static final CssIdent[] allowed_values;
21+
22+
static {
23+
String[] _allowed_values = {"normal"};
24+
allowed_values = new CssIdent[_allowed_values.length];
25+
int i = 0;
26+
for (String s : _allowed_values) {
27+
allowed_values[i++] = CssIdent.getIdent(s);
28+
}
29+
}
30+
31+
public static CssIdent getAllowedIdent(CssIdent ident) {
32+
for (CssIdent id : allowed_values) {
33+
if (id.equals(ident)) {
34+
return id;
35+
}
36+
}
37+
return null;
38+
}
39+
40+
/**
41+
* Create a new CssAscentOverride
42+
*/
43+
public CssAscentOverride() {
44+
value = initial;
45+
}
46+
47+
/**
48+
* Creates a new CssAscentOverride
49+
*
50+
* @param expression The expression for this property
51+
* @throws InvalidParamException Expressions are incorrect
52+
*/
53+
public CssAscentOverride(ApplContext ac, CssExpression expression, boolean check)
54+
throws InvalidParamException {
55+
if (check && expression.getCount() > 1) {
56+
throw new InvalidParamException("unrecognize", ac);
57+
}
58+
59+
setByUser();
60+
61+
char op;
62+
CssValue val;
63+
64+
val = expression.getValue();
65+
op = expression.getOperator();
66+
67+
switch (val.getType()) {
68+
case CssTypes.CSS_PERCENTAGE:
69+
value = val;
70+
break;
71+
case CssTypes.CSS_IDENT:
72+
if (getAllowedIdent(val.getIdent()) != null) {
73+
value = val;
74+
break;
75+
}
76+
default:
77+
throw new InvalidParamException("value",
78+
val.toString(),
79+
getPropertyName(), ac);
80+
}
81+
expression.next();
82+
}
83+
84+
public CssAscentOverride(ApplContext ac, CssExpression expression)
85+
throws InvalidParamException {
86+
this(ac, expression, false);
87+
}
88+
89+
}
90+

0 commit comments

Comments
 (0)