From a4c8f83e5c27647731a3d7db25b1f5a59d796911 Mon Sep 17 00:00:00 2001 From: Levent Dag Date: Tue, 23 Jun 2026 10:22:59 +0200 Subject: [PATCH] UPDATE: font-stretch restored, font-width is still a draft and shouldn't replace font-stretch --- .../css/properties/CSS3Properties.properties | 4 +- .../css/fontface/CSSFontStretch.java | 100 ++++++++++++++++++ org/w3c/css/properties/css3/Css3Style.java | 8 ++ .../css3/fontface/CSSFontStretch.java | 88 +++++++++++++++ 4 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 org/w3c/css/properties/css/fontface/CSSFontStretch.java create mode 100644 org/w3c/css/properties/css3/fontface/CSSFontStretch.java diff --git a/org/w3c/css/properties/CSS3Properties.properties b/org/w3c/css/properties/CSS3Properties.properties index eb95401d0..32832b4e6 100644 --- a/org/w3c/css/properties/CSS3Properties.properties +++ b/org/w3c/css/properties/CSS3Properties.properties @@ -555,8 +555,8 @@ zoom: org.w3c.css.properties.css3.CssZoom @font-face.font-feature-settings: org.w3c.css.properties.css3.fontface.CssFontFeatureSettings @font-face.font-language-override: org.w3c.css.properties.css3.fontface.CssFontLanguageOverride @font-face.font-named-instance org.w3c.css.properties.css3.fontface.CssFontNamedInstance -@font-face.font-stretch: org.w3c.css.properties.css3.fontface.CssFontWidth -@font-face.font-width: org.w3c.css.properties.css3.fontface.CssFontWidth +@font-face.font-stretch: org.w3c.css.properties.css3.fontface.CSSFontStretch +@font-face.font-width: org.w3c.css.properties.css3.fontface.CssFontWidth @font-face.font-style: org.w3c.css.properties.css3.fontface.CssFontStyle @font-face.font-variation-settings: org.w3c.css.properties.css3.fontface.CssFontVariationSettings @font-face.font-weight: org.w3c.css.properties.css3.fontface.CssFontWeight diff --git a/org/w3c/css/properties/css/fontface/CSSFontStretch.java b/org/w3c/css/properties/css/fontface/CSSFontStretch.java new file mode 100644 index 000000000..aeee4974b --- /dev/null +++ b/org/w3c/css/properties/css/fontface/CSSFontStretch.java @@ -0,0 +1,100 @@ +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; + +/** + * @version $Revision$ + * @since CSS2 + */ +public class CSSFontStretch extends CssProperty { + + /** + * Create a new CSSFontStretch + */ + public CSSFontStretch() { + } + + /** + * Creates a new CSSFontStretch + * + * @param expression The expression for this property + * @throws InvalidParamException Expressions are incorrect + */ + public CSSFontStretch(ApplContext ac, CssExpression expression, boolean check) throws InvalidParamException { + throw new InvalidParamException("value", expression.getValue().toString(), getPropertyName(), ac); + } + + public CSSFontStretch(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-stretch"; + } + + /** + * 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.fontFaceCssFontStretch != null) { + style.addRedefinitionWarning(ac, this); + } + s.fontFaceCssFontStretch = this; + } + + /** + * Compares two properties for equality. + * + * @param property The other property. + */ + public boolean equals(CssProperty property) { + return (property instanceof CSSFontStretch && value.equals(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).getFontFaceCssFontStretch(); + } else { + return ((Css3Style) style).fontFaceCssFontStretch; + } + } +} diff --git a/org/w3c/css/properties/css3/Css3Style.java b/org/w3c/css/properties/css3/Css3Style.java index 4fd5e2a70..7512b30da 100644 --- a/org/w3c/css/properties/css3/Css3Style.java +++ b/org/w3c/css/properties/css3/Css3Style.java @@ -648,6 +648,7 @@ public class Css3Style extends ATSCStyle { public CssFontDisplay fontFaceCssFontDisplay; public CssFontWeight fontFaceCssFontWeight; public org.w3c.css.properties.css.fontface.CssFontWidth fontFaceCssFontWidth; + public org.w3c.css.properties.css.fontface.CSSFontStretch fontFaceCssFontStretch; public CssFontStyle fontFaceCssFontStyle; public org.w3c.css.properties.css.fontface.CssFontLanguageOverride fontFaceCssFontLanguageOverride; public CssFontNamedInstance fontFaceCssFontNamedInstance; @@ -1831,6 +1832,13 @@ public CssFontDisplay getFontFaceCssFontDisplay() { return fontFaceCssFontDisplay; } + public org.w3c.css.properties.css.fontface.CSSFontStretch getFontFaceCssFontStretch() { + if (fontFaceCssFontStretch == null) { + fontFaceCssFontStretch = (org.w3c.css.properties.css.fontface.CSSFontStretch) style.CascadingOrder(new org.w3c.css.properties.css.fontface.CSSFontStretch(), style, selector); + } + return fontFaceCssFontStretch; + } + public org.w3c.css.properties.css.fontface.CssFontWidth getFontFaceCssFontWidth() { if (fontFaceCssFontWidth == null) { fontFaceCssFontWidth = diff --git a/org/w3c/css/properties/css3/fontface/CSSFontStretch.java b/org/w3c/css/properties/css3/fontface/CSSFontStretch.java new file mode 100644 index 000000000..e74b8bef2 --- /dev/null +++ b/org/w3c/css/properties/css3/fontface/CSSFontStretch.java @@ -0,0 +1,88 @@ +package org.w3c.css.properties.css3.fontface; + +import static org.w3c.css.properties.css3.CssFontWidth.getAllowedValue; +import static org.w3c.css.values.CssOperator.SPACE; + +import java.util.ArrayList; + +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; +import org.w3c.css.values.CssValueList; + +/** + * @spec http://www.w3.org/TR/2008/REC-CSS2-20080411/fonts.html#propdef-font-stretch + */ +public class CSSFontStretch extends org.w3c.css.properties.css.fontface.CSSFontStretch { + + public static final CssIdent auto = CssIdent.getIdent("auto"); + + /** + * Create a new CSSFontStretch + */ + public CSSFontStretch() { + value = initial; + } + + /** + * Creates a new CSSFontStretch + * + * @param expression The expression for this property + * @throws InvalidParamException Expressions are incorrect + */ + public CSSFontStretch(ApplContext ac, CssExpression expression, boolean check) + throws InvalidParamException { + if (check && expression.getCount() > 2) { + throw new InvalidParamException("unrecognize", ac); + } + + setByUser(); + + char op; + CssValue val; + ArrayList values = new ArrayList<>(); + + while (!expression.end()) { + val = expression.getValue(); + op = expression.getOperator(); + + switch (val.getType()) { + case CssTypes.CSS_IDENT: + CssIdent id = val.getIdent(); + if (auto.equals(id)) { + if (expression.getCount() > 1) { + throw new InvalidParamException("unrecognize", ac); + } + values.add(val); + break; + } + if (getAllowedValue(id) != null) { + values.add(val); + break; + } + default: + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } + if (op != SPACE) { + throw new InvalidParamException("operator", + Character.toString(op), ac); + } + expression.next(); + } + if (values.isEmpty()) { + throw new InvalidParamException("few-value", getPropertyName(), ac); + } + value = (values.size() == 1) ? values.get(0) : new CssValueList(values); + } + + public CSSFontStretch(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } + +} \ No newline at end of file