Skip to content

Commit 5534c15

Browse files
committed
1 parent 7c94d60 commit 5534c15

File tree

4 files changed

+224
-1
lines changed

4 files changed

+224
-1
lines changed

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ lighting-color: org.w3c.css.properties.css3.CssLightingC
521521
@font-face.font-weight: org.w3c.css.properties.css3.fontface.CssFontWeight
522522
@font-face.font-size: org.w3c.css.properties.css2.font.FontSize
523523
@font-face.font-family: org.w3c.css.properties.css2.font.FontFamily
524-
@font-face.font-stretch: org.w3c.css.properties.css2.font.FontStretch
524+
@font-face.font-stretch: org.w3c.css.properties.css3.fontface.CssFontStretch\
525525
@font-face.font-display: org.w3c.css.properties.css3.fontface.CssFontDisplay
526526

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

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@
301301
import org.w3c.css.properties.css.counterstyle.CssSymbols;
302302
import org.w3c.css.properties.css.counterstyle.CssSystem;
303303
import org.w3c.css.properties.css.fontface.CssFontDisplay;
304+
import org.w3c.css.properties.css.fontface.CssFontStretch;
304305
import org.w3c.css.properties.css.fontface.CssFontWeight;
305306
import org.w3c.css.properties.css.viewport.CssMaxZoom;
306307
import org.w3c.css.properties.css.viewport.CssMinZoom;
@@ -580,6 +581,7 @@ public class Css3Style extends ATSCStyle {
580581

581582
public CssFontDisplay fontFaceCssFontDisplay;
582583
public CssFontWeight fontFaceCssFontWeight;
584+
public CssFontStretch fontFaceCssFontStretch;
583585

584586
public CssColorAdjust cssColorAdjust;
585587
public CssForcedColorAdjust cssForcedColorAdjust;
@@ -1291,6 +1293,15 @@ public CssFontDisplay getFontFaceCssFontDisplay() {
12911293
return fontFaceCssFontDisplay;
12921294
}
12931295

1296+
public CssFontStretch getFontFaceCssFontStretch() {
1297+
if (fontFaceCssFontStretch == null) {
1298+
fontFaceCssFontStretch =
1299+
(CssFontStretch) style.CascadingOrder(new CssFontStretch(),
1300+
style, selector);
1301+
}
1302+
return fontFaceCssFontStretch;
1303+
}
1304+
12941305
public CssFontWeight getFontFaceCssFontWeight() {
12951306
if (fontFaceCssFontWeight == null) {
12961307
fontFaceCssFontWeight =
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
import org.w3c.css.values.CssValueList;
15+
16+
import java.util.ArrayList;
17+
18+
import static org.w3c.css.properties.css3.CssFontStretch.getAllowedValue;
19+
import static org.w3c.css.values.CssOperator.SPACE;
20+
21+
/**
22+
* @spec https://www.w3.org/TR/2021/WD-css-fonts-4-20210729/#descdef-font-face-font-stretch
23+
* @see org.w3c.css.properties.css3.CssFontStretch
24+
*/
25+
public class CssFontStretch extends org.w3c.css.properties.css.fontface.CssFontStretch {
26+
27+
public static final CssIdent auto = CssIdent.getIdent("auto");
28+
29+
/**
30+
* Create a new CssFontStretch
31+
*/
32+
public CssFontStretch() {
33+
value = initial;
34+
}
35+
36+
/**
37+
* Creates a new CssFontStretch
38+
*
39+
* @param expression The expression for this property
40+
* @throws InvalidParamException Expressions are incorrect
41+
*/
42+
public CssFontStretch(ApplContext ac, CssExpression expression, boolean check)
43+
throws InvalidParamException {
44+
if (check && expression.getCount() > 2) {
45+
throw new InvalidParamException("unrecognize", ac);
46+
}
47+
48+
setByUser();
49+
50+
char op;
51+
CssValue val;
52+
ArrayList<CssValue> values = new ArrayList<>();
53+
54+
while (!expression.end()) {
55+
val = expression.getValue();
56+
op = expression.getOperator();
57+
58+
switch (val.getType()) {
59+
case CssTypes.CSS_PERCENTAGE:
60+
val.getCheckableValue().checkPositiveness(ac, getPropertyName());
61+
values.add(val);
62+
break;
63+
case CssTypes.CSS_IDENT:
64+
CssIdent id = val.getIdent();
65+
if (auto.equals(id)) {
66+
if (expression.getCount() > 1) {
67+
throw new InvalidParamException("unrecognize", ac);
68+
}
69+
values.add(val);
70+
break;
71+
}
72+
if (getAllowedValue(id) != null) {
73+
values.add(val);
74+
break;
75+
}
76+
default:
77+
throw new InvalidParamException("value",
78+
val.toString(),
79+
getPropertyName(), ac);
80+
}
81+
if (op != SPACE) {
82+
throw new InvalidParamException("operator",
83+
Character.toString(op), ac);
84+
}
85+
expression.next();
86+
}
87+
if (values.isEmpty()) {
88+
throw new InvalidParamException("few-value", getPropertyName(), ac);
89+
}
90+
value = (values.size() == 1) ? values.get(0) : new CssValueList(values);
91+
}
92+
93+
public CssFontStretch(ApplContext ac, CssExpression expression)
94+
throws InvalidParamException {
95+
this(ac, expression, false);
96+
}
97+
98+
}
99+

0 commit comments

Comments
 (0)