Skip to content

Commit b11e994

Browse files
committed
1 parent 3615cac commit b11e994

File tree

3 files changed

+260
-0
lines changed

3 files changed

+260
-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 CssFontLanguageOverride extends CssProperty {
21+
22+
public CssValue value;
23+
24+
/**
25+
* Create a new CssFontLanguageOverride
26+
*/
27+
public CssFontLanguageOverride() {
28+
}
29+
30+
/**
31+
* Creates a new CssFontLanguageOverride
32+
*
33+
* @param expression The expression for this property
34+
* @throws InvalidParamException
35+
* Expressions are incorrect
36+
*/
37+
public CssFontLanguageOverride(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 CssFontLanguageOverride(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 "font-language-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.fontFaceCssFontLanguageOverride != null) {
87+
style.addRedefinitionWarning(ac, this);
88+
}
89+
s.fontFaceCssFontLanguageOverride = 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 CssFontLanguageOverride &&
100+
value.equals(((CssFontLanguageOverride) 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).getFontFaceCssFontLanguageOverride();
113+
} else {
114+
return ((Css3Style) style).fontFaceCssFontLanguageOverride;
115+
}
116+
}
117+
}
118+

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ public class Css3Style extends ATSCStyle {
589589
public CssFontWeight fontFaceCssFontWeight;
590590
public CssFontStretch fontFaceCssFontStretch;
591591
public CssFontStyle fontFaceCssFontStyle;
592+
public org.w3c.css.properties.css.fontface.CssFontLanguageOverride fontFaceCssFontLanguageOverride;
592593
public CssFontNamedInstance fontFaceCssFontNamedInstance;
593594
public CssAscentOverride fontFaceCssAscentOverride;
594595
public CssDescentOverride fontFaceCssDescentOverride;
@@ -1304,6 +1305,15 @@ public CssUnicodeRange getFontFaceCssUnicodeRange() {
13041305
}
13051306
return fontFaceCssUnicodeRange;
13061307
}
1308+
1309+
public org.w3c.css.properties.css.fontface.CssFontLanguageOverride getFontFaceCssFontLanguageOverride() {
1310+
if (fontFaceCssFontLanguageOverride == null) {
1311+
fontFaceCssFontLanguageOverride =
1312+
(org.w3c.css.properties.css.fontface.CssFontLanguageOverride) style.CascadingOrder(new org.w3c.css.properties.css.fontface.CssFontLanguageOverride(),
1313+
style, selector);
1314+
}
1315+
return fontFaceCssFontLanguageOverride;
1316+
}
13071317

13081318
public CssAscentOverride getFontFaceCssAscentOverride() {
13091319
if (fontFaceCssAscentOverride == null) {
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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.CssString;
13+
import org.w3c.css.values.CssTypes;
14+
import org.w3c.css.values.CssValue;
15+
import org.w3c.css.values.external.OpenTypeLanguageSystemTag;
16+
17+
import java.util.Arrays;
18+
19+
/**
20+
* @spec https://www.w3.org/TR/2021/WD-css-fonts-4-20210729/#descdef-font-face-font-language-override
21+
* @see org.w3c.css.properties.css3.CssFontLanguageOverride
22+
* @see org.w3c.css.values.external.OpenTypeLanguageSystemTag
23+
*/
24+
public class CssFontLanguageOverride extends org.w3c.css.properties.css.fontface.CssFontLanguageOverride {
25+
26+
public static final CssIdent[] allowed_values;
27+
28+
static {
29+
String[] _allowed_values = {"normal"};
30+
allowed_values = new CssIdent[_allowed_values.length];
31+
int i = 0;
32+
for (String s : _allowed_values) {
33+
allowed_values[i++] = CssIdent.getIdent(s);
34+
}
35+
}
36+
37+
public static CssIdent getAllowedIdent(CssIdent ident) {
38+
for (CssIdent id : allowed_values) {
39+
if (id.equals(ident)) {
40+
return id;
41+
}
42+
}
43+
return null;
44+
}
45+
46+
/**
47+
* Create a new CssFontLanguageOverride
48+
*/
49+
public CssFontLanguageOverride() {
50+
value = initial;
51+
}
52+
53+
/**
54+
* Creates a new CssFontLanguageOverride
55+
*
56+
* @param expression The expression for this property
57+
* @throws InvalidParamException Expressions are incorrect
58+
*/
59+
public CssFontLanguageOverride(ApplContext ac, CssExpression expression, boolean check)
60+
throws InvalidParamException {
61+
if (check && expression.getCount() > 1) {
62+
throw new InvalidParamException("unrecognize", ac);
63+
}
64+
65+
setByUser();
66+
67+
char op;
68+
CssValue val;
69+
70+
val = expression.getValue();
71+
op = expression.getOperator();
72+
73+
switch (val.getType()) {
74+
case CssTypes.CSS_STRING:
75+
CssString s = val.getString();
76+
int l = s.toString().length();
77+
// limit of 4characters + two surrounding quotes
78+
if ((l < 4) || (l > 6)) {
79+
throw new InvalidParamException("value",
80+
expression.getValue().toString(),
81+
getPropertyName(), ac);
82+
}
83+
// we extract the 2, 3 or 4 letters from the quotes...
84+
String tag = s.toString().substring(1, l - 1).toUpperCase();
85+
// align to 4
86+
switch (tag.length()) {
87+
case 1:
88+
tag = tag.concat(" ");
89+
break;
90+
case 2:
91+
tag = tag.concat(" ");
92+
break;
93+
case 3:
94+
tag = tag.concat(" ");
95+
break;
96+
default:
97+
}
98+
// valid values are specified here.
99+
int idx = Arrays.binarySearch(OpenTypeLanguageSystemTag.tags, tag);
100+
if (idx < 0) {
101+
// TODO specific error code
102+
throw new InvalidParamException("value",
103+
expression.getValue().toString(),
104+
getPropertyName(), ac);
105+
}
106+
// check if deprecated
107+
idx = Arrays.binarySearch(OpenTypeLanguageSystemTag.deprecated_tags, tag);
108+
if (idx >= 0) {
109+
ac.getFrame().addWarning("deprecated", tag);
110+
}
111+
value = val;
112+
break;
113+
case CssTypes.CSS_IDENT:
114+
if (getAllowedIdent(val.getIdent()) != null) {
115+
value = val;
116+
break;
117+
}
118+
default:
119+
throw new InvalidParamException("value",
120+
val.toString(),
121+
getPropertyName(), ac);
122+
}
123+
expression.next();
124+
}
125+
126+
public CssFontLanguageOverride(ApplContext ac, CssExpression expression)
127+
throws InvalidParamException {
128+
this(ac, expression, false);
129+
}
130+
131+
}
132+

0 commit comments

Comments
 (0)