Skip to content

Commit a78ad94

Browse files
committed
1 parent 374fa6e commit a78ad94

File tree

5 files changed

+354
-2
lines changed

5 files changed

+354
-2
lines changed

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ lighting-color: org.w3c.css.properties.css3.CssLightingC
444444

445445
@font-face.unicode-range: org.w3c.css.properties.css2.font.UnicodeRange
446446
@font-face.units-per-em: org.w3c.css.properties.css2.font.UnitsPerEm
447-
@font-face.src: org.w3c.css.properties.css2.font.Src
447+
@font-face.src: org.w3c.css.properties.css3.fontface.CssSrc
448448
@font-face.panose-1: org.w3c.css.properties.css2.font.Panose1
449449
@font-face.stemv: org.w3c.css.properties.css2.font.Stemv
450450
@font-face.stemh: org.w3c.css.properties.css2.font.Stemh

org/w3c/css/properties/CSS3SVGProperties.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ lighting-color: org.w3c.css.properties.css3.CssLightingC
487487

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

org/w3c/css/properties/css2/Css2Style.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.w3c.css.properties.css.CssVoiceFamily;
6565
import org.w3c.css.properties.css.CssVolume;
6666
import org.w3c.css.properties.css.CssWidows;
67+
import org.w3c.css.properties.css.fontface.CssSrc;
6768
import org.w3c.css.properties.css1.Css1Style;
6869
import org.w3c.css.util.ApplContext;
6970
import org.w3c.css.util.Warning;
@@ -76,6 +77,11 @@
7677
public class Css2Style extends Css1Style {
7778

7879
static final CssIdent marker = CssIdent.getIdent("marker");
80+
/**
81+
* font-face
82+
*/
83+
public CssSrc fontFaceCssSrc;
84+
7985
/**
8086
* aural properties
8187
*/
@@ -156,6 +162,14 @@ public class Css2Style extends Css1Style {
156162
public CssOrphans cssOrphans;
157163
public CssWidows cssWidows;
158164

165+
166+
public CssSrc getFontFaceCssSrc() {
167+
if (fontFaceCssSrc == null) {
168+
fontFaceCssSrc = (CssSrc) style.CascadingOrder(new CssSrc(),
169+
style, selector);
170+
}
171+
return fontFaceCssSrc;
172+
}
159173
/**
160174
* Get the azimuth
161175
*/
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2017.
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.CssFunction;
12+
import org.w3c.css.values.CssIdent;
13+
import org.w3c.css.values.CssLayerList;
14+
import org.w3c.css.values.CssTypes;
15+
import org.w3c.css.values.CssValue;
16+
import org.w3c.css.values.CssValueList;
17+
18+
import java.util.ArrayList;
19+
20+
import static org.w3c.css.values.CssOperator.COMMA;
21+
import static org.w3c.css.values.CssOperator.SPACE;
22+
23+
/**
24+
* @spec https://www.w3.org/TR/2013/CR-css-fonts-3-20131003/#descdef-src
25+
*/
26+
public class CssSrc extends org.w3c.css.properties.css.fontface.CssSrc {
27+
28+
public static final CssIdent[] allowed_values;
29+
30+
static {
31+
String[] _allowed_values = {"flex-start", "flex-end", "center", "space-between",
32+
"space-around", "stretch"};
33+
allowed_values = new CssIdent[_allowed_values.length];
34+
int i = 0;
35+
for (String s : _allowed_values) {
36+
allowed_values[i++] = CssIdent.getIdent(s);
37+
}
38+
}
39+
40+
public static CssIdent getAllowedIdent(CssIdent ident) {
41+
for (CssIdent id : allowed_values) {
42+
if (id.equals(ident)) {
43+
return id;
44+
}
45+
}
46+
return null;
47+
}
48+
49+
/**
50+
* Create a new CssSrc
51+
*/
52+
public CssSrc() {
53+
value = initial;
54+
}
55+
56+
/**
57+
* Creates a new CssSrc
58+
*
59+
* @param expression The expression for this property
60+
* @throws org.w3c.css.util.InvalidParamException
61+
* Expressions are incorrect
62+
*/
63+
public CssSrc(ApplContext ac, CssExpression expression, boolean check)
64+
throws InvalidParamException {
65+
66+
setByUser();
67+
68+
char op;
69+
70+
CssExpression nex;
71+
ArrayList<CssValue> values = new ArrayList<>();
72+
73+
while (!expression.end()) {
74+
nex = new CssExpression();
75+
76+
while (!expression.end() && expression.getOperator() == SPACE) {
77+
nex.addValue(expression.getValue());
78+
expression.next();
79+
}
80+
// the weird ending case
81+
if (!expression.end()) {
82+
nex.addValue(expression.getValue());
83+
}
84+
values.add(parseSrcLayer(ac, nex, check));
85+
if (!expression.end()) {
86+
op = expression.getOperator();
87+
if (op != COMMA) {
88+
throw new InvalidParamException("operator", op,
89+
getPropertyName(), ac);
90+
}
91+
expression.next();
92+
}
93+
}
94+
value = (values.size() == 1) ? values.get(0) : new CssLayerList(values);
95+
}
96+
97+
protected CssValue parseSrcLayer(ApplContext ac, CssExpression expression, boolean check)
98+
throws InvalidParamException {
99+
100+
if (check && expression.getCount() > 2) {
101+
throw new InvalidParamException("unrecognize", ac);
102+
}
103+
104+
ArrayList<CssValue> values = new ArrayList<>();
105+
boolean gotUrl = false;
106+
boolean gotFormat = false;
107+
CssValue val;
108+
109+
while (!expression.end()) {
110+
val = expression.getValue();
111+
switch (val.getType()) {
112+
case CssTypes.CSS_URL:
113+
if (gotUrl) {
114+
throw new InvalidParamException("value",
115+
val.toString(),
116+
getPropertyName(), ac);
117+
}
118+
gotUrl = true;
119+
values.add(val);
120+
break;
121+
case CssTypes.CSS_FUNCTION:
122+
CssFunction f = (CssFunction) val;
123+
String funcName = f.getName().toLowerCase();
124+
switch (funcName) {
125+
case "local":
126+
if (expression.getCount() > 1) {
127+
throw new InvalidParamException("unrecognize", ac);
128+
}
129+
parseLocalFunction(ac, f);
130+
values.add(f);
131+
break;
132+
case "format":
133+
if (gotFormat) {
134+
throw new InvalidParamException("value",
135+
val.toString(),
136+
getPropertyName(), ac);
137+
}
138+
parseFormatFunction(ac, f);
139+
gotFormat = true;
140+
values.add(val);
141+
break;
142+
default:
143+
throw new InvalidParamException("value",
144+
val.toString(),
145+
getPropertyName(), ac);
146+
}
147+
break;
148+
default:
149+
throw new InvalidParamException("value",
150+
val.toString(),
151+
getPropertyName(), ac);
152+
}
153+
expression.next();
154+
}
155+
return (values.size() == 1) ? values.get(0) : new CssValueList(values);
156+
}
157+
158+
protected void parseFormatFunction(ApplContext ac, CssFunction f)
159+
throws InvalidParamException {
160+
CssExpression exp = f.getParameters();
161+
char op;
162+
CssValue val;
163+
164+
while (!exp.end()) {
165+
val = exp.getValue();
166+
op = exp.getOperator();
167+
168+
if (val.getType() != CssTypes.CSS_STRING) {
169+
throw new InvalidParamException("value",
170+
val.toString(),
171+
f.getName(), ac);
172+
}
173+
if (op != COMMA && exp.getRemainingCount() > 1) {
174+
throw new InvalidParamException("operator", op,
175+
f.getName(), ac);
176+
}
177+
exp.next();
178+
}
179+
}
180+
181+
protected void parseLocalFunction(ApplContext ac, CssFunction f)
182+
throws InvalidParamException {
183+
CssExpression exp = f.getParameters();
184+
char op;
185+
CssValue val;
186+
187+
while (!exp.end()) {
188+
val = exp.getValue();
189+
op = exp.getOperator();
190+
191+
switch (val.getType()) {
192+
case CssTypes.CSS_STRING:
193+
// quoted string must be unique
194+
if (exp.getCount() > 1) {
195+
throw new InvalidParamException("unrecognize", ac);
196+
}
197+
break;
198+
case CssTypes.CSS_IDENT:
199+
break;
200+
default:
201+
throw new InvalidParamException("value",
202+
val.toString(),
203+
f.getName(), ac);
204+
}
205+
// idents must be separated by spaces
206+
if (op != SPACE && exp.getRemainingCount() > 1) {
207+
throw new InvalidParamException("operator", op,
208+
f.getName(), ac);
209+
}
210+
exp.next();
211+
}
212+
}
213+
214+
215+
public CssSrc(ApplContext ac, CssExpression expression)
216+
throws InvalidParamException {
217+
this(ac, expression, false);
218+
}
219+
220+
}
221+

0 commit comments

Comments
 (0)