diff --git a/MIGRATING_FROM_BATIK.md b/MIGRATING_FROM_BATIK.md index bc9ac8604..557a493fb 100644 --- a/MIGRATING_FROM_BATIK.md +++ b/MIGRATING_FROM_BATIK.md @@ -7,7 +7,8 @@ Batik: - Improved conformance to the SVG and CSS specifications. -- Better user experience (_e.g._ the `codec` classes that got merged into `transcoder`). +- Better user experience (_e.g._ the `codec` classes that got merged into + `transcoder`, or the cleaner module interdependencies). - A circularity with Apache FOP. To render PDF images, Batik uses FOP which in turn uses Batik, so depending on FOP would imply mixing EchoSVG and Batik. See @@ -27,9 +28,8 @@ Batik: 2) Class names that included the name "Batik" now have "EchoSVG". 3) The `codec`-`transcoder` circular dependency was removed in the following way: - a few classes from the `codec` module were moved to two new packages in - `transcoder` (that aren't exported by that module). Now `transcoder` explicitly - depends on `codec` (but not the other way around). + a few classes from the `codec` module were moved to `transcoder`. Now + `transcoder` explicitly depends on `codec` (but not the other way around). 4) Tcl and Python 2.x scripting was removed (see issues [#12](https://github.com/css4j/echosvg/issues/12) and [#13](https://github.com/css4j/echosvg/issues/13)). That scripting wasn't @@ -65,3 +65,6 @@ Batik: 10) `SVGAnimationElementBridge.initializeAnimation()` gained a `BridgeContext` argument and now returns a `boolean`. + +11) The old and deprecated `CSSValue` API was replaced by an API close to W3C's + Typed OM. diff --git a/NOTICE b/NOTICE index fe6e2dcb1..3d5018e75 100644 --- a/NOTICE +++ b/NOTICE @@ -7,12 +7,22 @@ This product includes software developed at The Apache Software Foundation (https://www.apache.org/) under the 'Apache Batik' project. This software contains code from the World Wide Web Consortium (W3C) for the -Document Object Model API (DOM API) and SVG Document Type Definition (DTD). +Document Object Model API (DOM API). This software contains code from the International Organisation for Standardization for the definition of character entities used in the software's documentation. +This software contains color profiles by Clinton Ingram, that are CC-licensed as +shown in the 'Compact-ICC-Profiles-license' file under the color profiles +directory (bridge module). + +This product contains a Display P3 color profile that was made by Apple and was +obtained from color.org (ICC). + +This product contains the ITU-R Recommendation BT.2020 color profile that was +also obtained from color.org (ICC). + This product includes images from the Tango Desktop Project (Former website http://tango.freedesktop.org/ archived at https://web.archive.org/web/20201024165718/http://tango-project.org/). diff --git a/buildSrc/allowed-licenses.json b/buildSrc/allowed-licenses.json index 22670b189..b1d0906af 100644 --- a/buildSrc/allowed-licenses.json +++ b/buildSrc/allowed-licenses.json @@ -15,6 +15,9 @@ { "moduleLicense": "Mozilla Public License, Version 2.0" }, + { + "moduleLicense": "W3C Software and Document Notice and License" + }, { "moduleLicense": "MIT License" } diff --git a/buildSrc/src/main/groovy/echosvg.java-conventions.gradle b/buildSrc/src/main/groovy/echosvg.java-conventions.gradle index bf2351ec0..3f5ea25b3 100644 --- a/buildSrc/src/main/groovy/echosvg.java-conventions.gradle +++ b/buildSrc/src/main/groovy/echosvg.java-conventions.gradle @@ -18,6 +18,7 @@ repositories { content { includeGroup 'io.sf.carte' includeGroup 'io.sf.graphics' + includeGroup 'io.sf.w3' includeGroup 'io.sf.jclf' } } @@ -121,7 +122,7 @@ tasks.register("${project.name}-jar-with-deps", Jar) { // Provided by Java SE exclude 'javax/**' // Not used by EchoSVG - exclude 'org/w3c/css/**' + exclude 'org/w3c/css/sac/**' // The next ones are provided by java.xml module exclude 'org/w3c/dom/*' exclude 'org/w3c/dom/bootstrap/**' @@ -131,6 +132,11 @@ tasks.register("${project.name}-jar-with-deps", Jar) { exclude 'org/w3c/dom/traversal/**' exclude 'org/w3c/dom/views/**' exclude 'org/xml/**' + // Provided by jdk.xml.dom module + exclude 'org/w3c/dom/css/**' + exclude 'org/w3c/dom/html/**' + exclude 'org/w3c/dom/stylesheets/**' + exclude 'org/w3c/dom/xpath/**' // Modularity does not apply here exclude 'module-info.class' } diff --git a/echosvg-all/build.gradle b/echosvg-all/build.gradle index b2a2717a3..d781a1285 100644 --- a/echosvg-all/build.gradle +++ b/echosvg-all/build.gradle @@ -61,6 +61,11 @@ tasks.register('cloneRepos') { refToCheckout: "v${svgomVersion}") gitWebAPIs?.close() + def gitCSSAPIs = grgit.clone(dir: "$buildDir/repos/cssom-apis", + uri: 'https://github.com/css4j/cssom-apis.git', + refToCheckout: "v0.1") + gitCSSAPIs?.close() + def gitLegacyColors = grgit.clone(dir: "$buildDir/repos/legacy-colors", uri: 'https://github.com/css4j/legacy-colors.git', refToCheckout: "v${legacyColorsVersion}") @@ -208,6 +213,18 @@ tasks.register('prepareModularSources') { include(name: '**/*') } } + + // CSSOM and DOM View APIs + ant.copy(todir: "$buildDir/src/org.w3c.css.om") { + fileset(dir: "$buildDir/repos/cssom-apis/cssom-api/src/main/java") { + include(name: '**/*') + } + } + ant.copy(todir: "$buildDir/src/org.w3c.dom.view") { + fileset(dir: "$buildDir/repos/cssom-apis/domview-api/src/main/java") { + include(name: '**/*') + } + } } } @@ -243,6 +260,8 @@ tasks.register('modularJavadoc', Javadoc) { "$buildDir/src/io.sf.carte.echosvg.util.gui", "$buildDir/src/io.sf.carte.echosvg.xml", "$buildDir/src/io.sf.graphics.legacy.colors", + "$buildDir/src/org.w3c.css.om", + "$buildDir/src/org.w3c.dom.view", "$buildDir/src/org.w3c.dom.smil", "$buildDir/src/org.w3c.dom.svg" ] includes += '**/*.java' @@ -282,7 +301,7 @@ tasks.register('uberjar', Jar) { // Provided by Java SE exclude 'javax/**' // Not used by EchoSVG - exclude 'org/w3c/css/**' + exclude 'org/w3c/css/sac/**' // The next ones are provided by java.xml module exclude 'org/w3c/dom/*' exclude 'org/w3c/dom/bootstrap/**' @@ -292,6 +311,11 @@ tasks.register('uberjar', Jar) { exclude 'org/w3c/dom/traversal/**' exclude 'org/w3c/dom/views/**' exclude 'org/xml/**' + // Provided by jdk.xml.dom module + exclude 'org/w3c/dom/css/**' + exclude 'org/w3c/dom/html/**' + exclude 'org/w3c/dom/stylesheets/**' + exclude 'org/w3c/dom/xpath/**' // Modularity does not apply here exclude 'module-info.class' diff --git a/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGDOMImplementation.java b/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGDOMImplementation.java index e473c6e75..0faca4948 100644 --- a/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGDOMImplementation.java +++ b/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGDOMImplementation.java @@ -25,17 +25,17 @@ import java.nio.charset.StandardCharsets; import java.util.HashMap; +import org.w3c.css.om.CSSStyleDeclaration; +import org.w3c.css.om.CSSStyleSheet; import org.w3c.dom.DOMException; import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.Node; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleSheet; -import org.w3c.dom.css.ViewCSS; import org.w3c.dom.events.Event; import org.w3c.dom.stylesheets.StyleSheet; +import org.w3c.dom.view.ViewCSS; import io.sf.carte.doc.style.css.nsac.InputSource; import io.sf.carte.doc.style.css.nsac.Parser; diff --git a/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGOMDocument.java b/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGOMDocument.java index e2209668e..2e39d7111 100644 --- a/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGOMDocument.java +++ b/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGOMDocument.java @@ -27,6 +27,7 @@ import java.util.Locale; import java.util.MissingResourceException; +import org.w3c.css.om.CSSStyleDeclaration; import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; import org.w3c.dom.Comment; @@ -40,8 +41,6 @@ import org.w3c.dom.Node; import org.w3c.dom.ProcessingInstruction; import org.w3c.dom.Text; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.DocumentCSS; import org.w3c.dom.events.Event; import org.w3c.dom.events.EventListener; import org.w3c.dom.events.MutationEvent; @@ -687,9 +686,9 @@ public void otherAnimationChanged(Element e, String type) { // DocumentCSS //////////////////////////////////////////////////////////// /** - * DOM: Implements {@link DocumentCSS#getOverrideStyle(Element,String)}. + * This does not implement {@code DocumentCSS#getOverrideStyle(Element,String)} + * anymore, as it does not support Typed OM. */ - @Override public CSSStyleDeclaration getOverrideStyle(Element elt, String pseudoElt) { if (elt instanceof SVGStylableElement && pseudoElt == null) { return ((SVGStylableElement) elt).getOverrideStyle(); diff --git a/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGOMSVGElement.java b/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGOMSVGElement.java index b2bdfb52a..8d99179fa 100644 --- a/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGOMSVGElement.java +++ b/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGOMSVGElement.java @@ -21,13 +21,11 @@ import java.awt.geom.AffineTransform; import java.util.List; +import org.w3c.css.om.CSSStyleDeclaration; import org.w3c.dom.DOMException; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.DocumentCSS; -import org.w3c.dom.css.ViewCSS; import org.w3c.dom.events.DocumentEvent; import org.w3c.dom.events.Event; import org.w3c.dom.stylesheets.DocumentStyle; @@ -48,6 +46,8 @@ import org.w3c.dom.svg.SVGStringList; import org.w3c.dom.svg.SVGTransform; import org.w3c.dom.svg.SVGViewSpec; +import org.w3c.dom.view.DocumentCSS; +import org.w3c.dom.view.ViewCSS; import org.w3c.dom.views.AbstractView; import org.w3c.dom.views.DocumentView; @@ -716,10 +716,6 @@ public DocumentView getDocument() { return (DocumentView) getOwnerDocument(); } - /** - * DOM: Implements - * {@link org.w3c.dom.css.ViewCSS#getComputedStyle(Element,String)}. - */ @Override public CSSStyleDeclaration getComputedStyle(Element elt, String pseudoElt) { AbstractView av = ((DocumentView) getOwnerDocument()).getDefaultView(); @@ -748,19 +744,11 @@ public boolean canDispatch(String namespaceURI, String type) throws DOMException // DocumentCSS //////////////////////////////////////////////////////////// - /** - * DOM: Implements - * {@link org.w3c.dom.stylesheets.DocumentStyle#getStyleSheets()}. - */ @Override public StyleSheetList getStyleSheets() { return ((DocumentStyle) getOwnerDocument()).getStyleSheets(); } - /** - * DOM: Implements - * {@link org.w3c.dom.css.DocumentCSS#getOverrideStyle(Element,String)}. - */ @Override public CSSStyleDeclaration getOverrideStyle(Element elt, String pseudoElt) { return ((DocumentCSS) getOwnerDocument()).getOverrideStyle(elt, pseudoElt); diff --git a/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGStylableElement.java b/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGStylableElement.java index c1fed720a..88a086323 100644 --- a/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGStylableElement.java +++ b/echosvg-anim/src/main/java/io/sf/carte/echosvg/anim/dom/SVGStylableElement.java @@ -18,11 +18,11 @@ */ package io.sf.carte.echosvg.anim.dom; +import org.w3c.css.om.CSSStyleDeclaration; +import org.w3c.css.om.typed.CSSStyleValue; import org.w3c.dom.Attr; import org.w3c.dom.DOMException; import org.w3c.dom.Node; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSValue; import org.w3c.dom.svg.SVGAnimatedString; import io.sf.carte.echosvg.anim.values.AnimatableValue; @@ -35,6 +35,7 @@ import io.sf.carte.echosvg.css.engine.SVGCSSEngine; import io.sf.carte.echosvg.css.engine.StyleDeclarationProvider; import io.sf.carte.echosvg.css.engine.StyleMap; +import io.sf.carte.echosvg.css.engine.value.AbstractValueModificationHandler; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.css.engine.value.svg.SVGColorManager; import io.sf.carte.echosvg.css.engine.value.svg.SVGPaintManager; @@ -48,8 +49,10 @@ * This class provides a common superclass for elements which implement * SVGStylable. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public abstract class SVGStylableElement extends SVGOMElement implements CSSStylableElement { @@ -227,7 +230,7 @@ public void updatePropertyValue(String pn, AnimatableValue val) { public boolean useLinearRGBColorInterpolation() { CSSEngine eng = ((SVGOMDocument) getOwnerDocument()).getCSSEngine(); Value v = eng.getComputedStyle(this, null, SVGCSSEngine.COLOR_INTERPOLATION_INDEX); - return v.getStringValue().charAt(0) == 'l'; + return v.getIdentifierValue().charAt(0) == 'l'; } /** @@ -262,9 +265,6 @@ public void removeTargetListener(String ns, String an, boolean isCSS, AnimationT // SVGStylable support /////////////////////////////////////////////////// - /** - * DOM: Implements {@link org.w3c.dom.svg.SVGStylable#getStyle()}. - */ public CSSStyleDeclaration getStyle() { if (style == null) { CSSEngine eng = ((SVGOMDocument) getOwnerDocument()).getCSSEngine(); @@ -274,12 +274,8 @@ public CSSStyleDeclaration getStyle() { return style; } - /** - * DOM: Implements - * {@link org.w3c.dom.svg.SVGStylable#getPresentationAttribute(String)}. - */ - public CSSValue getPresentationAttribute(String name) { - CSSValue result = (CSSValue) getLiveAttributeValue(null, name); + public CSSStyleValue getPresentationAttributeValue(String name) { + CSSStyleValue result = (CSSStyleValue) getLiveAttributeValue(null, name); if (result != null) return result; @@ -365,14 +361,14 @@ public class PresentationAttributeValue extends CSSOMValue implements LiveAttrib public PresentationAttributeValue(CSSEngine eng, String prop) { super(null); valueProvider = this; - setModificationHandler(new AbstractModificationHandler() { + setModificationHandler(new AbstractValueModificationHandler() { @Override protected Value getValue() { return PresentationAttributeValue.this.getValue(); } @Override - public void textChanged(String text) throws DOMException { + protected void setPropertyText(String text) throws DOMException { value = cssEngine.parsePropertyValue(SVGStylableElement.this, property, text); mutate = true; setAttributeNS(null, property, text); @@ -468,14 +464,14 @@ public class PresentationAttributeColorValue extends CSSOMSVGColor public PresentationAttributeColorValue(CSSEngine eng, String prop) { super(null); valueProvider = this; - setModificationHandler(new AbstractModificationHandler() { + setModificationHandler(new AbstractValueModificationHandler() { @Override protected Value getValue() { return PresentationAttributeColorValue.this.getValue(); } @Override - public void textChanged(String text) throws DOMException { + protected void setPropertyText(String text) throws DOMException { value = cssEngine.parsePropertyValue(SVGStylableElement.this, property, text); mutate = true; setAttributeNS(null, property, text); @@ -578,7 +574,7 @@ protected Value getValue() { } @Override - public void textChanged(String text) throws DOMException { + protected void setPropertyText(String text) throws DOMException { value = cssEngine.parsePropertyValue(SVGStylableElement.this, property, text); mutate = true; setAttributeNS(null, property, text); diff --git a/echosvg-bridge/build.gradle b/echosvg-bridge/build.gradle index 9a3113cf3..c1de05ff6 100644 --- a/echosvg-bridge/build.gradle +++ b/echosvg-bridge/build.gradle @@ -7,7 +7,15 @@ dependencies { api project(':echosvg-gvt') api project(':echosvg-script') api "io.sf.graphics:legacy-colors:${legacyColorsVersion}" - compileOnly "xml-apis:xml-apis:$xmlApisVersion" // Required by Java 8 compat + if (!project.getPluginManager().hasPlugin('eclipse')) { + compileOnly "xml-apis:xml-apis:$xmlApisVersion" // Required by Java 8 compat + } + testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}" + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +test { + useJUnitPlatform() } description = 'io.sf.carte:echosvg-bridge' diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/AbstractSVGGradientElementBridge.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/AbstractSVGGradientElementBridge.java index e5b48fd52..7e49e64f2 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/AbstractSVGGradientElementBridge.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/AbstractSVGGradientElementBridge.java @@ -296,7 +296,13 @@ public Stop createStop(BridgeContext ctx, Element gradientElement, Element stopE // use default value offset = 0f; } - Color color = CSSUtilities.convertStopColor(stopElement, opacity, ctx); + Color color; + try { + color = CSSUtilities.convertStopColor(stopElement, opacity, ctx); + } catch (Exception ex) { + throw new BridgeException(ctx, stopElement, ex, ERR_CSS_VALUE_ERROR, + new Object[] { ex }); + } return new Stop(color, offset); } diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/BridgeContext.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/BridgeContext.java index def8d791b..546cec4bc 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/BridgeContext.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/BridgeContext.java @@ -18,7 +18,9 @@ */ package io.sf.carte.echosvg.bridge; +import java.awt.Color; import java.awt.Cursor; +import java.awt.color.ColorSpace; import java.awt.geom.Dimension2D; import java.io.Closeable; import java.io.IOException; @@ -195,6 +197,11 @@ public class BridgeContext implements ErrorConstants, CSSContext, Closeable { */ protected TextPainter textPainter; + /** + * The recommended color space. + */ + private ColorSpace colorSpace = null; + /** * Indicates that no DOM listeners should be registered. In this case the * generated GVT tree should be totally independent of the DOM tree (in practice @@ -390,6 +397,33 @@ public CSSEngine getCSSEngineForElement(Element e) { return doc.getCSSEngine(); } + /** + * Update the color space recommendations for this context. + *

+ * Should be called whenever a non-sRGB color is created. The information shall + * be used to determine the recommended color profile for a destination image. + *

+ * + * @param color the color that the bridge must be able to paint. + * @param csRGB the color space in the RGB color model that is able to represent + * the color. + */ + public void updateColorSpace(Color color, ColorSpace csRGB) { + if (colorSpace != csRGB) { + colorSpace = CSSColorSpaces.mergeColorSpace(colorSpace, csRGB, color); + } + } + + /** + * Get the recommended color space for this context. + * + * @return the recommended color space, or {@code null} if the color space is + * the default sRGB. + */ + public ColorSpace getColorSpace() { + return colorSpace; + } + // properties //////////////////////////////////////////////////////////// /** @@ -798,35 +832,6 @@ public Element getReferencedElement(Element e, String uri) { // Viewport ////////////////////////////////////////////////////////////// - /** - * Returns the viewport of the specified element. - * - * @param e the element interested in its viewport - */ - public Viewport getViewport(Element e) { - if (viewportStack != null) { - // building time - if (viewportStack.size() == 0) { - // outermost svg element - return viewportMap.get(userAgent); - } else { - // current viewport - return viewportStack.get(0); - } - } else { - // search the first parent which has defined a viewport - e = SVGUtilities.getParentElement(e); - while (e != null) { - Viewport viewport = viewportMap.get(e); - if (viewport != null) { - return viewport; - } - e = SVGUtilities.getParentElement(e); - } - return viewportMap.get(userAgent); - } - } - /** * Starts a new viewport from the specified element. * @@ -841,6 +846,8 @@ public void openViewport(Element e, Viewport viewport) { viewportStack.add(0, viewport); } + // Viewport ////////////////////////////////////////////////////////////// + public void removeViewport(Element e) { viewportMap.remove(e); } @@ -1746,6 +1753,36 @@ public void otherAnimationChanged(Element e, String type) { // CSS context //////////////////////////////////////////////////////////// + /** + * Returns the viewport of the specified element. + * + * @param e the element interested in its viewport + */ + @Override + public Viewport getViewport(Element e) { + if (viewportStack != null) { + // building time + if (viewportStack.size() == 0) { + // outermost svg element + return viewportMap.get(userAgent); + } else { + // current viewport + return viewportStack.get(0); + } + } else { + // search the first parent which has defined a viewport + e = SVGUtilities.getParentElement(e); + while (e != null) { + Viewport viewport = viewportMap.get(e); + if (viewport != null) { + return viewport; + } + e = SVGUtilities.getParentElement(e); + } + return viewportMap.get(userAgent); + } + } + /** * Returns the Value corresponding to the given system color. */ @@ -1896,11 +1933,9 @@ public boolean checkInteractiveElement(SVGDocument doc, Element e) { * * // Check if cursor property is set to something other than 'auto'. Value * cursorValue = CSSUtilities.getComputedStyle (e, SVGCSSEngine.CURSOR_INDEX); - * if ((cursorValue != null) && (cursorValue.getCssValueType() == - * CSSValue.CSS_PRIMITIVE_VALUE) && (cursorValue.getPrimitiveType() == - * CSSPrimitiveValue.CSS_IDENT) && - * (SVGConstants.SVG_AUTO_VALUE.equals(cursorValue.getStringValue()))) return - * true; + * if ((cursorValue != null) && (cursorValue.getPrimitiveType() == Type.IDENT) + * && (SVGConstants.SVG_AUTO_VALUE.equals(cursorValue.getIdentifierValue()))) + * return true; */ // Check all the child elements for any of the above. diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CSSColorSpaces.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CSSColorSpaces.java new file mode 100644 index 000000000..5795ccafa --- /dev/null +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CSSColorSpaces.java @@ -0,0 +1,210 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.bridge; + +import java.awt.Color; +import java.awt.color.ColorSpace; +import java.awt.color.ICC_ColorSpace; +import java.awt.color.ICC_Profile; +import java.io.IOException; +import java.io.InputStream; + +/** + * Predefined ICC color spaces. + */ +class CSSColorSpaces { + + private static ICC_ColorSpace a98rgb; + + private static ICC_ColorSpace prophotoRGB; + + private static ICC_ColorSpace displayP3; + + private static ICC_ColorSpace rec2020; + + CSSColorSpaces() { + super(); + } + + public static ICC_ColorSpace getA98RGB() { + ICC_Profile prof; + if (a98rgb == null) { + try (InputStream is = CSSColorSpaces.class.getResourceAsStream( + "color/profiles/A98RGBCompat-v4.icc")) { + prof = ICC_Profile.getInstance(is); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + a98rgb = new ICC_ColorSpace(prof); + } + return a98rgb; + } + + public static ICC_ColorSpace getProphotoRGB() { + ICC_Profile prof; + if (prophotoRGB == null) { + try (InputStream is = CSSColorSpaces.class.getResourceAsStream( + "color/profiles/WideGamutPhoto-v4.icc")) { + prof = ICC_Profile.getInstance(is); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + prophotoRGB = new ICC_ColorSpace(prof); + } + return prophotoRGB; + } + + public static ICC_ColorSpace getDisplayP3() { + ICC_Profile prof; + if (displayP3 == null) { + try (InputStream is = CSSColorSpaces.class.getResourceAsStream( + "color/profiles/Display P3.icc")) { + prof = ICC_Profile.getInstance(is); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + displayP3 = new ICC_ColorSpace(prof); + } + return displayP3; + } + + public static ICC_ColorSpace getRec2020() { + ICC_Profile prof; + if (rec2020 == null) { + try (InputStream is = CSSColorSpaces.class.getResourceAsStream( + "color/profiles/ITU-R_BT2020.icc")) { + prof = ICC_Profile.getInstance(is); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + rec2020 = new ICC_ColorSpace(prof); + } + return rec2020; + } + + /** + * Merge the two color spaces. + * + * @param colorSpace1 the first color space, or {@code null}. + * @param colorSpace2 the second color space. Cannot be equal to colorSpace1 + * (check that before calling). + * @param color the color that needs to be represented by the merged + * space. + * @return the recommended merged color space. + */ + static ColorSpace mergeColorSpace(ColorSpace colorSpace1, ColorSpace colorSpace2, Color color) { + // For a reasoning, you may want to look at + // https://upload.wikimedia.org/wikipedia/commons/b/b3/CIE1931xy_gamut_comparison_of_sRGB_P3_Rec2020.svg + if (colorSpace1 == null || colorSpace2 == getProphotoRGB()) { + return colorSpace2; + } + + // Prophoto contains nearly all of the other gamuts, first check for it. + if (colorSpace1 == getProphotoRGB() || isInGamut(color, colorSpace1)) { + return colorSpace1; + } + + // colorSpace1 is either rec2020, A98RGB or P3. + // colorSpace2 must be rec2020, A98RGB or P3. + // rec2020 is the best, smallest merge. + ICC_ColorSpace rec = getRec2020(); + if (colorSpace1 != rec) { + if (isInGamut(color, rec)) { + return rec; + } + } + + return getProphotoRGB(); + } + + /** + * Determine which color space is the most adequate to represent the given + * color, starting with sRGB and then giving precedence to the supplied color + * space over others. + * + * @param xyz the color to check, often in the XYZ color space. + * @param colorSpace the suggested color space. + * @return the recommended color space, or {@code null} if it is sRGB. + */ + static ColorSpace containerRGBSpace(Color xyz, ColorSpace colorSpace) { + // Verify whether xyz is in sRGB gamut, otherwise check P3, A98, rec2020, prophoto. + ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); + if (isInGamut(xyz, cs)) { + return null; + } + if (colorSpace != null) { + if (isInGamut(xyz, colorSpace)) { + return colorSpace; + } + } + // Check P3 + cs = getDisplayP3(); + if (colorSpace != cs) { + if (isInGamut(xyz, cs)) { + return cs; + } + } + // Check A98 + cs = getA98RGB(); + if (colorSpace != cs) { + if (isInGamut(xyz, cs)) { + return cs; + } + } + // Check rec2020 + cs = getRec2020(); + if (colorSpace != cs) { + if (isInGamut(xyz, cs)) { + return cs; + } + } + return getProphotoRGB(); + } + + /** + * Check whether the color is in the gamut of the given color space. + *

+ * This method is only approximate. + *

+ * + * @param color the color to check. + * @param space the color space. Cannot be {@code null}. + * @return {@code false} if the color may not be representable in the given + * color space. + */ + private static boolean isInGamut(Color color, ColorSpace space) { + float[] comps = color.getColorComponents(space, null); + float min = space.getMinValue(0); + float max = space.getMaxValue(0); + + for (float comp : comps) { + if (comp <= min || comp >= max) { + // Symptom that the color is at the edge of the gamut + return false; + } + } + + return true; + } + +} diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CSSFontFace.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CSSFontFace.java index 3fece4672..705c0a68a 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CSSFontFace.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CSSFontFace.java @@ -21,9 +21,8 @@ import java.util.LinkedList; import java.util.List; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; - +import io.sf.carte.echosvg.css.dom.CSSValue.CssType; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.FontFaceRule; import io.sf.carte.echosvg.css.engine.SVGCSSEngine; @@ -85,10 +84,10 @@ public static CSSFontFace createCSSFontFace(CSSEngine eng, FontFaceRule ffr) { ParsedURL base = ffr.getURL(); if ((v != null) && (v != ValueConstants.NONE_VALUE)) { - if (v.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (v.getCssValueType() == CssType.TYPED) { ret.srcs = new LinkedList<>(); ret.srcs.add(getSrcValue(v, base)); - } else if (v.getCssValueType() == CSSValue.CSS_VALUE_LIST) { + } else if (v.getCssValueType() == CssType.LIST) { ret.srcs = new LinkedList<>(); for (int i = 0; i < v.getLength(); i++) { ret.srcs.add(getSrcValue(v.item(i), base)); @@ -115,14 +114,12 @@ public static CSSFontFace createCSSFontFace(CSSEngine eng, FontFaceRule ffr) { } public static Object getSrcValue(Value v, ParsedURL base) { - if (v.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) - return null; - if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_URI) { + if (v.getPrimitiveType() == Type.URI) { if (base != null) - return new ParsedURL(base, v.getStringValue()); - return new ParsedURL(v.getStringValue()); + return new ParsedURL(base, v.getURIValue()); + return new ParsedURL(v.getURIValue()); } - if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_STRING) + if (v.getPrimitiveType() == Type.STRING) return v.getStringValue(); return null; } @@ -134,7 +131,7 @@ public static String getStringProp(StyleMap sm, CSSEngine eng, int pidx) { ValueManager vm = vms[pidx]; v = vm.getDefaultValue(); } - while (v.getCssValueType() == CSSValue.CSS_VALUE_LIST) { + while (v.getCssValueType() == CssType.LIST) { v = v.item(0); } return v.getStringValue(); @@ -147,7 +144,7 @@ public static float getFloatProp(StyleMap sm, CSSEngine eng, int pidx) { ValueManager vm = vms[pidx]; v = vm.getDefaultValue(); } - while (v.getCssValueType() == CSSValue.CSS_VALUE_LIST) { + while (v.getCssValueType() == CssType.LIST) { v = v.item(0); } return v.getFloatValue(); diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CSSUtilities.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CSSUtilities.java index 07c2b5360..73b926d71 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CSSUtilities.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CSSUtilities.java @@ -27,15 +27,15 @@ import java.awt.geom.Rectangle2D; import org.w3c.dom.Element; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; import io.sf.carte.echosvg.anim.dom.SVGOMDocument; import io.sf.carte.echosvg.constants.XMLConstants; +import io.sf.carte.echosvg.css.dom.CSSValue.CssType; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.SVGCSSEngine; -import io.sf.carte.echosvg.css.engine.value.ListValue; +import io.sf.carte.echosvg.css.engine.value.RectValue; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.ext.awt.MultipleGradientPaint; import io.sf.carte.echosvg.ext.awt.image.renderable.ClipRable; @@ -99,7 +99,7 @@ public static Value getComputedStyle(Element e, int property) { */ public static int convertPointerEvents(Element e) { Value v = getComputedStyle(e, SVGCSSEngine.POINTER_EVENTS_INDEX); - String s = v.getStringValue(); + String s = v.getIdentifierValue(); switch (s.charAt(0)) { case 'v': if (s.length() == 7) { @@ -146,11 +146,10 @@ public static int convertPointerEvents(Element e) { public static Rectangle2D convertEnableBackground(Element e /* * , UnitProcessor.Context uctx */) { - Value v = getComputedStyle(e, SVGCSSEngine.ENABLE_BACKGROUND_INDEX); - if (v.getCssValueType() != CSSValue.CSS_VALUE_LIST) { + Value lv = getComputedStyle(e, SVGCSSEngine.ENABLE_BACKGROUND_INDEX); + if (lv.getCssValueType() != CssType.LIST) { return null; // accumulate } - ListValue lv = (ListValue) v; int length = lv.getLength(); switch (length) { case 1: @@ -180,7 +179,7 @@ public static Rectangle2D convertEnableBackground(Element e /* */ public static boolean convertColorInterpolationFilters(Element e) { Value v = getComputedStyle(e, SVGCSSEngine.COLOR_INTERPOLATION_FILTERS_INDEX); - return CSS_LINEARRGB_VALUE == v.getStringValue(); + return CSS_LINEARRGB_VALUE == v.getIdentifierValue(); } ///////////////////////////////////////////////////////////////////////// @@ -195,7 +194,7 @@ public static boolean convertColorInterpolationFilters(Element e) { */ public static MultipleGradientPaint.ColorSpaceEnum convertColorInterpolation(Element e) { Value v = getComputedStyle(e, SVGCSSEngine.COLOR_INTERPOLATION_INDEX); - return (CSS_LINEARRGB_VALUE == v.getStringValue()) ? MultipleGradientPaint.LINEAR_RGB + return (CSS_LINEARRGB_VALUE == v.getIdentifierValue()) ? MultipleGradientPaint.LINEAR_RGB : MultipleGradientPaint.SRGB; } @@ -211,15 +210,13 @@ public static boolean isAutoCursor(Element e) { boolean isAuto = false; if (cursorValue != null) { - if (cursorValue.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE - && cursorValue.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT - && cursorValue.getStringValue().charAt(0) == 'a') { + if (cursorValue.getPrimitiveType() == Type.IDENT + && cursorValue.getIdentifierValue().charAt(0) == 'a') { isAuto = true; - } else if (cursorValue.getCssValueType() == CSSValue.CSS_VALUE_LIST && cursorValue.getLength() == 1) { + } else if (cursorValue.getCssValueType() == CssType.LIST && cursorValue.getLength() == 1) { Value lValue = cursorValue.item(0); - if (lValue != null && lValue.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE - && lValue.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT - && lValue.getStringValue().charAt(0) == 'a') { + if (lValue != null && lValue.getPrimitiveType() == Type.IDENT + && lValue.getIdentifierValue().charAt(0) == 'a') { isAuto = true; } } @@ -281,7 +278,7 @@ public static Cursor convertCursor(Element e, BridgeContext ctx) { */ public static RenderingHints convertShapeRendering(Element e, RenderingHints hints) { Value v = getComputedStyle(e, SVGCSSEngine.SHAPE_RENDERING_INDEX); - String s = v.getStringValue(); + String s = v.getIdentifierValue(); int len = s.length(); if ((len == 4) && (s.charAt(0) == 'a')) // auto return hints; @@ -360,7 +357,7 @@ public static RenderingHints convertShapeRendering(Element e, RenderingHints hin */ public static RenderingHints convertTextRendering(Element e, RenderingHints hints) { Value v = getComputedStyle(e, SVGCSSEngine.TEXT_RENDERING_INDEX); - String s = v.getStringValue(); + String s = v.getIdentifierValue(); int len = s.length(); if ((len == 4) && (s.charAt(0) == 'a')) // auto return hints; @@ -428,7 +425,7 @@ public static RenderingHints convertTextRendering(Element e, RenderingHints hint */ public static RenderingHints convertImageRendering(Element e, RenderingHints hints) { Value v = getComputedStyle(e, SVGCSSEngine.IMAGE_RENDERING_INDEX); - String s = v.getStringValue(); + String s = v.getIdentifierValue(); int len = s.length(); if ((len == 4) && (s.charAt(0) == 'a')) // auto return hints; @@ -483,7 +480,7 @@ public static RenderingHints convertImageRendering(Element e, RenderingHints hin */ public static RenderingHints convertColorRendering(Element e, RenderingHints hints) { Value v = getComputedStyle(e, SVGCSSEngine.COLOR_RENDERING_INDEX); - String s = v.getStringValue(); + String s = v.getIdentifierValue(); int len = s.length(); if ((len == 4) && (s.charAt(0) == 'a')) // auto return hints; @@ -521,7 +518,7 @@ public static boolean convertDisplay(Element e) { return true; } Value v = getComputedStyle(e, SVGCSSEngine.DISPLAY_INDEX); - return v.getStringValue().charAt(0) != 'n'; + return v.getIdentifierValue().charAt(0) != 'n'; } ///////////////////////////////////////////////////////////////////////// @@ -536,7 +533,7 @@ public static boolean convertDisplay(Element e) { */ public static boolean convertVisibility(Element e) { Value v = getComputedStyle(e, SVGCSSEngine.VISIBILITY_INDEX); - return v.getStringValue().charAt(0) == 'v'; + return v.getIdentifierValue().charAt(0) == 'v'; } ///////////////////////////////////////////////////////////////////////// @@ -576,7 +573,7 @@ public static Composite convertOpacity(Element e) { */ public static boolean convertOverflow(Element e) { Value v = getComputedStyle(e, SVGCSSEngine.OVERFLOW_INDEX); - String s = v.getStringValue(); + String s = v.getIdentifierValue(); return (s.charAt(0) == 'h') || (s.charAt(0) == 's'); } @@ -588,20 +585,20 @@ public static boolean convertOverflow(Element e) { */ public static float[] convertClip(Element e) { Value v = getComputedStyle(e, SVGCSSEngine.CLIP_INDEX); - int primitiveType = v.getPrimitiveType(); - switch (primitiveType) { - case CSSPrimitiveValue.CSS_RECT: + switch (v.getPrimitiveType()) { + case RECT: float[] off = new float[4]; - off[0] = v.getTop().getFloatValue(); - off[1] = v.getRight().getFloatValue(); - off[2] = v.getBottom().getFloatValue(); - off[3] = v.getLeft().getFloatValue(); + RectValue rect = v.getRectValue(); + off[0] = rect.getTop().getFloatValue(); + off[1] = rect.getRight().getFloatValue(); + off[2] = rect.getBottom().getFloatValue(); + off[3] = rect.getLeft().getFloatValue(); return off; - case CSSPrimitiveValue.CSS_IDENT: + case IDENT: return null; // 'auto' means no offsets default: // can't be reached - throw new IllegalStateException("Unexpected primitiveType:" + primitiveType); + throw new IllegalStateException("Unexpected primitiveType: " + v.getPrimitiveType()); } } @@ -619,13 +616,13 @@ public static float[] convertClip(Element e) { */ public static Filter convertFilter(Element filteredElement, GraphicsNode filteredNode, BridgeContext ctx) { Value v = getComputedStyle(filteredElement, SVGCSSEngine.FILTER_INDEX); - int primitiveType = v.getPrimitiveType(); + Type primitiveType = v.getPrimitiveType(); switch (primitiveType) { - case CSSPrimitiveValue.CSS_IDENT: + case IDENT: return null; // 'filter:none' - case CSSPrimitiveValue.CSS_URI: - String uri = v.getStringValue(); + case URI: + String uri = v.getURIValue(); Element filter = ctx.getReferencedElement(filteredElement, uri); if (filter == null) { return null; // Missing reference @@ -666,13 +663,13 @@ public static Filter convertFilter(Element filteredElement, GraphicsNode filtere */ public static ClipRable convertClipPath(Element clippedElement, GraphicsNode clippedNode, BridgeContext ctx) { Value v = getComputedStyle(clippedElement, SVGCSSEngine.CLIP_PATH_INDEX); - int primitiveType = v.getPrimitiveType(); + Type primitiveType = v.getPrimitiveType(); switch (primitiveType) { - case CSSPrimitiveValue.CSS_IDENT: + case IDENT: return null; // 'clip-path:none' - case CSSPrimitiveValue.CSS_URI: - String uri = v.getStringValue(); + case URI: + String uri = v.getURIValue(); Element cp = ctx.getReferencedElement(clippedElement, uri); if (cp == null) { return null; // Missing reference @@ -706,7 +703,7 @@ public static ClipRable convertClipPath(Element clippedElement, GraphicsNode cli */ public static int convertClipRule(Element e) { Value v = getComputedStyle(e, SVGCSSEngine.CLIP_RULE_INDEX); - return (v.getStringValue().charAt(0) == 'n') ? Path2D.WIND_NON_ZERO : Path2D.WIND_EVEN_ODD; + return (v.getIdentifierValue().charAt(0) == 'n') ? Path2D.WIND_NON_ZERO : Path2D.WIND_EVEN_ODD; } ///////////////////////////////////////////////////////////////////////// @@ -723,13 +720,13 @@ public static int convertClipRule(Element e) { */ public static Mask convertMask(Element maskedElement, GraphicsNode maskedNode, BridgeContext ctx) { Value v = getComputedStyle(maskedElement, SVGCSSEngine.MASK_INDEX); - int primitiveType = v.getPrimitiveType(); + Type primitiveType = v.getPrimitiveType(); switch (primitiveType) { - case CSSPrimitiveValue.CSS_IDENT: + case IDENT: return null; // 'mask:none' - case CSSPrimitiveValue.CSS_URI: - String uri = v.getStringValue(); + case URI: + String uri = v.getURIValue(); Element m = ctx.getReferencedElement(maskedElement, uri); if (m == null) { return null; // Missing reference @@ -763,7 +760,7 @@ public static Mask convertMask(Element maskedElement, GraphicsNode maskedNode, B */ public static int convertFillRule(Element e) { Value v = getComputedStyle(e, SVGCSSEngine.FILL_RULE_INDEX); - return (v.getStringValue().charAt(0) == 'n') ? Path2D.WIND_NON_ZERO : Path2D.WIND_EVEN_ODD; + return (v.getIdentifierValue().charAt(0) == 'n') ? Path2D.WIND_NON_ZERO : Path2D.WIND_EVEN_ODD; } ///////////////////////////////////////////////////////////////////////// @@ -779,8 +776,8 @@ public static int convertFillRule(Element e) { */ public static Color convertLightingColor(Element e, BridgeContext ctx) { Value v = getComputedStyle(e, SVGCSSEngine.LIGHTING_COLOR_INDEX); - if (v.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - return PaintServer.convertColor(v, 1); + if (v.getCssValueType() != CssType.LIST) { + return PaintServer.convertColor(v.getColorValue(), 1, ctx); } else { return PaintServer.convertRGBICCColor(e, v.item(0), v.item(1), 1, ctx); } @@ -801,8 +798,8 @@ public static Color convertFloodColor(Element e, BridgeContext ctx) { Value v = getComputedStyle(e, SVGCSSEngine.FLOOD_COLOR_INDEX); Value o = getComputedStyle(e, SVGCSSEngine.FLOOD_OPACITY_INDEX); float f = PaintServer.convertOpacity(o); - if (v.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - return PaintServer.convertColor(v, f); + if (v.getCssValueType() != CssType.LIST) { + return PaintServer.convertColor(v.getColorValue(), f, ctx); } else { return PaintServer.convertRGBICCColor(e, v.item(0), v.item(1), f, ctx); } @@ -824,8 +821,8 @@ public static Color convertStopColor(Element e, float opacity, BridgeContext ctx Value v = getComputedStyle(e, SVGCSSEngine.STOP_COLOR_INDEX); Value o = getComputedStyle(e, SVGCSSEngine.STOP_OPACITY_INDEX); opacity *= PaintServer.convertOpacity(o); - if (v.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - return PaintServer.convertColor(v, opacity); + if (v.getCssValueType() != CssType.LIST) { + return PaintServer.convertColor(v.getColorValue(), opacity, ctx); } else { return PaintServer.convertRGBICCColor(e, v.item(0), v.item(1), opacity, ctx); } @@ -865,13 +862,13 @@ public static void computeStyleAndURIs(Element refElement, Element localRefEleme ///////////////////////////////////////////////////////////////////////// /** - * Returns the winding rule represented by the specified CSSValue. + * Returns the winding rule represented by the specified Value. * * @param v the value that represents the rule * @return GeneralPath.WIND_NON_ZERO | GeneralPath.WIND_EVEN_ODD */ - protected static int rule(CSSValue v) { - return (((CSSPrimitiveValue) v).getStringValue().charAt(0) == 'n') ? Path2D.WIND_NON_ZERO + protected static int rule(Value v) { + return v.getIdentifierValue().charAt(0) == 'n' ? Path2D.WIND_NON_ZERO : Path2D.WIND_EVEN_ODD; } diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CursorManager.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CursorManager.java index 125bd59bb..89114b1b7 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CursorManager.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/CursorManager.java @@ -37,11 +37,11 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; import org.w3c.dom.svg.SVGDocument; import org.w3c.dom.svg.SVGPreserveAspectRatio; +import io.sf.carte.echosvg.css.dom.CSSValue.CssType; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.SVGCSSEngine; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.dom.AbstractNode; @@ -174,18 +174,17 @@ public Cursor convertCursor(Element e) { String cursorStr = SVGConstants.SVG_AUTO_VALUE; if (cursorValue != null) { - if (cursorValue.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE - && cursorValue.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { + if (cursorValue.getPrimitiveType() == Type.IDENT) { // Single Value : should be one of the predefined cursors or // 'inherit' - cursorStr = cursorValue.getStringValue(); + cursorStr = cursorValue.getIdentifierValue(); return convertBuiltInCursor(e, cursorStr); - } else if (cursorValue.getCssValueType() == CSSValue.CSS_VALUE_LIST) { + } else if (cursorValue.getCssValueType() == CssType.LIST) { int nValues = cursorValue.getLength(); if (nValues == 1) { cursorValue = cursorValue.item(0); - if (cursorValue.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { - cursorStr = cursorValue.getStringValue(); + if (cursorValue.getPrimitiveType() == Type.IDENT) { + cursorStr = cursorValue.getIdentifierValue(); return convertBuiltInCursor(e, cursorStr); } } else if (nValues > 1) { @@ -273,8 +272,8 @@ public Cursor convertSVGCursor(Element e, Value l) { Element cursorElement = null; for (int i = 0; i < nValues - 1; i++) { Value cursorValue = l.item(i); - if (cursorValue.getPrimitiveType() == CSSPrimitiveValue.CSS_URI) { - String uri = cursorValue.getStringValue(); + if (cursorValue.getPrimitiveType() == Type.URI) { + String uri = cursorValue.getURIValue(); // If the uri does not resolve to a cursor element, // then, this is not a type of cursor uri we can handle: @@ -310,8 +309,8 @@ public Cursor convertSVGCursor(Element e, Value l) { // Fallback on the built in cursor property. Value cursorValue = l.item(nValues - 1); String cursorStr = SVGConstants.SVG_AUTO_VALUE; - if (cursorValue.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { - cursorStr = cursorValue.getStringValue(); + if (cursorValue.getPrimitiveType() == Type.IDENT) { + cursorStr = cursorValue.getIdentifierValue(); } return convertBuiltInCursor(e, cursorStr); diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/ErrorConstants.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/ErrorConstants.java index ba8a534ba..0a0415691 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/ErrorConstants.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/ErrorConstants.java @@ -74,6 +74,19 @@ public interface ErrorConstants { */ String ERR_CSS_URI_BAD_TARGET = "css.uri.badTarget"; + /** + * The error code when a URI specified in a CSS property referenced a bad + * element. + * + *
+	 * {0} = the uri
+	 * {1} = the line
+	 * {2} = the local name
+	 * {3} = the exception
+	 * 
+ */ + String ERR_CSS_VALUE_ERROR = "css.badValue"; + /** * The error code when a specified URI references a bad element. * diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/PaintServer.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/PaintServer.java index 1d758d341..12080bd7d 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/PaintServer.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/PaintServer.java @@ -23,25 +23,24 @@ import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; +import java.awt.color.ColorSpace; +import java.awt.color.ICC_ColorSpace; import java.awt.color.ICC_Profile; import java.io.IOException; -import io.sf.graphics.java2d.color.CIELabColorSpace; -import io.sf.graphics.java2d.color.ColorSpaces; -import io.sf.graphics.java2d.color.ColorWithAlternatives; -import io.sf.graphics.java2d.color.DeviceCMYKColorSpace; -import io.sf.graphics.java2d.color.ICCColorSpaceWithIntent; -import io.sf.graphics.java2d.color.NamedColorSpace; -import io.sf.graphics.java2d.color.profile.NamedColorProfile; -import io.sf.graphics.java2d.color.profile.NamedColorProfileParser; +import org.w3c.css.om.typed.CSSStyleValueList; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.Element; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; +import io.sf.carte.echosvg.css.dom.CSSValue.CssType; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.SVGCSSEngine; +import io.sf.carte.echosvg.css.engine.value.ColorFunction; +import io.sf.carte.echosvg.css.engine.value.ColorValue; +import io.sf.carte.echosvg.css.engine.value.NumericValue; +import io.sf.carte.echosvg.css.engine.value.RGBColorValue; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.css.engine.value.svg.ICCColor; -import io.sf.carte.echosvg.css.engine.value.svg12.CIELabColor; import io.sf.carte.echosvg.css.engine.value.svg12.DeviceColor; import io.sf.carte.echosvg.css.engine.value.svg12.ICCNamedColor; import io.sf.carte.echosvg.gvt.CompositeShapePainter; @@ -54,6 +53,13 @@ import io.sf.carte.echosvg.gvt.StrokeShapePainter; import io.sf.carte.echosvg.util.CSSConstants; import io.sf.carte.echosvg.util.SVGConstants; +import io.sf.graphics.java2d.color.ColorSpaces; +import io.sf.graphics.java2d.color.ColorWithAlternatives; +import io.sf.graphics.java2d.color.DeviceCMYKColorSpace; +import io.sf.graphics.java2d.color.ICCColorSpaceWithIntent; +import io.sf.graphics.java2d.color.NamedColorSpace; +import io.sf.graphics.java2d.color.profile.NamedColorProfile; +import io.sf.graphics.java2d.color.profile.NamedColorProfileParser; /** * A collection of utility methods to deliver java.awt.Paint, @@ -61,10 +67,13 @@ * This class also provides additional methods the deliver SVG Paint using the * ShapePainter interface. * - * @author Thierry Kormann - * @author For later modifications, see Git history. + *

+ * Original author: Thierry Kormann. + * For later modifications, see Git history. + *

* @version $Id$ */ +@SuppressWarnings("deprecation") public abstract class PaintServer implements SVGConstants, CSSConstants, ErrorConstants { /** @@ -119,10 +128,10 @@ public static ShapePainter convertMarkers(Element e, ShapeNode node, BridgeConte */ public static Marker convertMarker(Element e, Value v, BridgeContext ctx) { - if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { + if (v.getPrimitiveType() == Type.IDENT) { return null; // 'none' } else { - String uri = v.getStringValue(); + String uri = v.getURIValue(); Element markerElement = ctx.getReferencedElement(e, uri); if (markerElement == null) { return null; // Missing reference @@ -245,51 +254,57 @@ public static Paint convertFillPaint(Element filledElement, GraphicsNode filledN */ public static Paint convertPaint(Element paintedElement, GraphicsNode paintedNode, Value paintDef, float opacity, BridgeContext ctx) { - if (paintDef.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (paintDef.getCssValueType() == CssType.TYPED) { switch (paintDef.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_IDENT: + case IDENT: return null; // none - - case CSSPrimitiveValue.CSS_RGBCOLOR: - return convertColor(paintDef, opacity); - - case CSSPrimitiveValue.CSS_URI: + case COLOR: + return convertColor(paintDef.getColorValue(), opacity, ctx); + case URI: return convertURIPaint(paintedElement, paintedNode, paintDef, opacity, ctx); - default: - throw new IllegalArgumentException("Paint argument is not an appropriate CSS value"); + break; } } else { // List Value v = paintDef.item(0); switch (v.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_RGBCOLOR: - return convertRGBICCColor(paintedElement, v, paintDef.item(1), opacity, ctx); + case COLOR: + switch ((v.getColorValue()).getCSSColorSpace()) { + case ColorValue.RGB_FUNCTION: + return convertRGBICCColor(paintedElement, v, paintDef.item(1), opacity, ctx); + } + break; - case CSSPrimitiveValue.CSS_URI: { + case URI: Paint result = silentConvertURIPaint(paintedElement, paintedNode, v, opacity, ctx); - if (result != null) + if (result != null) { return result; + } v = paintDef.item(1); switch (v.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_IDENT: + case IDENT: return null; // none - - case CSSPrimitiveValue.CSS_RGBCOLOR: - if (paintDef.getLength() == 2) { - return convertColor(v, opacity); - } else { - return convertRGBICCColor(paintedElement, v, paintDef.item(2), opacity, ctx); + case COLOR: + ColorValue color = v.getColorValue(); + switch (color.getCSSColorSpace()) { + case ColorValue.RGB_FUNCTION: + if (paintDef.getLength() == 2) { + return convertColor((RGBColorValue) color, opacity); + } else { + return convertRGBICCColor(paintedElement, v, paintDef.item(2), opacity, ctx); + } } + break; default: - throw new IllegalArgumentException("Paint argument is not an appropriate CSS value"); + break; } - } + default: - // can't be reached - throw new IllegalArgumentException("Paint argument is not an appropriate CSS value"); + break; } } + throw new IllegalArgumentException("Paint argument is not an appropriate CSS value"); } /** @@ -326,7 +341,7 @@ public static Paint silentConvertURIPaint(Element paintedElement, GraphicsNode p public static Paint convertURIPaint(Element paintedElement, GraphicsNode paintedNode, Value paintDef, float opacity, BridgeContext ctx) { - String uri = paintDef.getStringValue(); + String uri = paintDef.getURIValue(); Element paintElement = ctx.getReferencedElement(paintedElement, uri); if (paintElement == null) { return null; // Missing reference @@ -369,14 +384,12 @@ public static Color convertRGBICCColor(Element paintedElement, Value colorDef, V color = convertICCColor(paintedElement, (ICCColor) iccColor, opacity, ctx); } else if (iccColor instanceof ICCNamedColor) { color = convertICCNamedColor(paintedElement, (ICCNamedColor) iccColor, opacity, ctx); - } else if (iccColor instanceof CIELabColor) { - color = convertCIELabColor(paintedElement, (CIELabColor) iccColor, opacity, ctx); } else if (iccColor instanceof DeviceColor) { color = convertDeviceColor(paintedElement, colorDef, (DeviceColor) iccColor, opacity, ctx); } } if (color == null) { - color = convertColor(colorDef, opacity); + color = convertColor(colorDef.getColorValue(), opacity, ctx); } return color; } @@ -398,13 +411,14 @@ public static Color convertICCColor(Element e, ICCColor c, float opacity, Bridge return null; } // Ask the bridge to map the ICC profile name to an ICC_Profile object - SVGColorProfileElementBridge profileBridge = (SVGColorProfileElementBridge) ctx.getBridge(SVG_NAMESPACE_URI, - SVG_COLOR_PROFILE_TAG); + SVGColorProfileElementBridge profileBridge = (SVGColorProfileElementBridge) ctx.getBridge( + SVG_NAMESPACE_URI, SVG_COLOR_PROFILE_TAG); if (profileBridge == null) { return null; // no bridge for color profile } - ICCColorSpaceWithIntent profileCS = profileBridge.createICCColorSpaceWithIntent(ctx, e, iccProfileName); + ICCColorSpaceWithIntent profileCS = profileBridge.createICCColorSpaceWithIntent(ctx, e, + iccProfileName); if (profileCS == null) { return null; // no profile } @@ -443,8 +457,8 @@ public static Color convertICCNamedColor(Element e, ICCNamedColor c, float opaci return null; } // Ask the bridge to map the ICC profile name to an ICC_Profile object - SVGColorProfileElementBridge profileBridge = (SVGColorProfileElementBridge) ctx.getBridge(SVG_NAMESPACE_URI, - SVG_COLOR_PROFILE_TAG); + SVGColorProfileElementBridge profileBridge = (SVGColorProfileElementBridge) ctx.getBridge( + SVG_NAMESPACE_URI, SVG_COLOR_PROFILE_TAG); if (profileBridge == null) { return null; // no bridge for color profile } @@ -482,22 +496,6 @@ public static Color convertICCNamedColor(Element e, ICCNamedColor c, float opaci return null; } - /** - * Returns a Color object that corresponds to the input Paint's CIE Lab color - * value. - * - * @param e the element using the color - * @param c the CIE Lab color definition - * @param opacity the opacity - * @param ctx the bridge context to use - */ - public static Color convertCIELabColor(Element e, CIELabColor c, float opacity, BridgeContext ctx) { - CIELabColorSpace cs = new CIELabColorSpace(c.getWhitePoint()); - float[] lab = c.getColorValues(); - Color specColor = cs.toColor(lab[0], lab[1], lab[2], opacity); - return specColor; - } - /** * Returns a Color object that corresponds to the input Paint's device-specific * color value. @@ -508,9 +506,11 @@ public static Color convertCIELabColor(Element e, CIELabColor c, float opacity, * @param opacity the opacity * @param ctx the bridge context to use */ - public static Color convertDeviceColor(Element e, Value srgb, DeviceColor c, float opacity, BridgeContext ctx) { + public static Color convertDeviceColor(Element e, Value srgb, DeviceColor c, float opacity, + BridgeContext ctx) { + ColorValue color = srgb.getColorValue(); if (c.isNChannel()) { - return convertColor(srgb, opacity); // NYI + return convertColor(color, opacity, ctx); // NYI } else { if (c.getNumberOfColors() == 4) { DeviceCMYKColorSpace cmykCs = ColorSpaces.getDeviceCMYKColorSpace(); @@ -519,15 +519,16 @@ public static Color convertDeviceColor(Element e, Value srgb, DeviceColor c, flo comps[i] = c.getColor(i); } Color cmyk = new ColorWithAlternatives(cmykCs, comps, opacity, null); - int r = resolveColorComponent(srgb.getRed()); - int g = resolveColorComponent(srgb.getGreen()); - int b = resolveColorComponent(srgb.getBlue()); + RGBColorValue rgb = (RGBColorValue) color; + int r = resolveColorComponent(rgb.getR()); + int g = resolveColorComponent(rgb.getG()); + int b = resolveColorComponent(rgb.getB()); float a = resolveAlphaComponent(c.getAlpha()); Color specColor = new ColorWithAlternatives(r, g, b, Math.round(a * opacity * 255f), new Color[] { cmyk }); return specColor; } else { - return convertColor(srgb, opacity); // NYI + return convertColor(color, opacity, ctx); // NYI } } } @@ -537,15 +538,140 @@ public static Color convertDeviceColor(Element e, Value srgb, DeviceColor c, flo * * @param c The CSS color to convert. * @param opacity The opacity value (0 <= o <= 1). + * @param ctx the bridge context. */ - public static Color convertColor(Value c, float opacity) { - int r = resolveColorComponent(c.getRed()); - int g = resolveColorComponent(c.getGreen()); - int b = resolveColorComponent(c.getBlue()); + public static Color convertColor(ColorValue c, float opacity, BridgeContext ctx) { + switch (c.getCSSColorSpace()) { + case ColorValue.RGB_FUNCTION: + return convertColor((RGBColorValue) c, opacity); + case ColorValue.LAB: + case ColorValue.LCH: + throw new UnsupportedOperationException(); + default: + // Color() function + return convertColor((ColorFunction) c, opacity, ctx); + } + } + + /** + * Converts the given Value and opacity to a Color object. + * + * @param c The CSS color to convert. + * @param opacity The opacity value (0 <= o <= 1). + */ + public static Color convertColor(RGBColorValue c, float opacity) { + int r = resolveColorComponent(c.getR()); + int g = resolveColorComponent(c.getG()); + int b = resolveColorComponent(c.getB()); float a = resolveAlphaComponent(c.getAlpha()); return new Color(r, g, b, Math.round(a * opacity * 255f)); } + /** + * Converts the given color() function Value and opacity to a Color object. + * + * @param c The CSS color function to convert. + * @param opacity The opacity value (0 <= o <= 1). + * @param ctx the bridge context. + */ + public static Color convertColor(ColorFunction c, float opacity, BridgeContext ctx) { + switch (c.getCSSColorSpace()) { + case ColorValue.CS_DISPLAY_P3: + ICC_ColorSpace space = CSSColorSpaces.getDisplayP3(); + Color color = convert3Color(space, c, opacity); + ctx.updateColorSpace(color, space); + return color; + case ColorValue.CS_A98_RGB: + space = CSSColorSpaces.getA98RGB(); + color = convert3Color(space, c, opacity); + ctx.updateColorSpace(color, space); + return color; + case ColorValue.CS_PROPHOTO_RGB: + space = CSSColorSpaces.getProphotoRGB(); + color = convert3Color(space, c, opacity); + ctx.updateColorSpace(color, space); + return color; + case ColorValue.CS_REC2020: + space = CSSColorSpaces.getRec2020(); + color = convert3Color(space, c, opacity); + ctx.updateColorSpace(color, space); + return color; + case ColorValue.CS_SRGB_LINEAR: + ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB); + return convert3Color(cs, c, opacity); + case ColorValue.CS_XYZ: + case ColorValue.CS_XYZ_D65: + CSSStyleValueList chs = c.getChannels(); + float[] ch = new float[3]; + ch[0] = resolveColorFunctionComponent(chs.item(0)); + ch[1] = resolveColorFunctionComponent(chs.item(1)); + ch[2] = resolveColorFunctionComponent(chs.item(2)); + float[] xyzd50 = d65xyzToD50(ch); + float a = resolveAlphaComponent(c.getAlpha()); + cs = ColorSpace.getInstance(ColorSpace.CS_CIEXYZ); + color = new Color(cs, xyzd50, a * opacity); + cs = CSSColorSpaces.containerRGBSpace(color, ctx.getColorSpace()); + if (cs != null) { + ctx.updateColorSpace(color, cs); + } + return color; + case ColorValue.CS_XYZ_D50: + cs = ColorSpace.getInstance(ColorSpace.CS_CIEXYZ); + color = convert3Color(cs, c, opacity); + cs = CSSColorSpaces.containerRGBSpace(color, ctx.getColorSpace()); + if (cs != null) { + ctx.updateColorSpace(color, cs); + } + return color; + default: + throw new UnsupportedOperationException(); + } + } + + private static Color convert3Color(ColorSpace space, ColorFunction c, float opacity) { + CSSStyleValueList chs = c.getChannels(); + float[] ch = new float[3]; + ch[0] = resolveColorFunctionComponent(chs.item(0)); + ch[1] = resolveColorFunctionComponent(chs.item(1)); + ch[2] = resolveColorFunctionComponent(chs.item(2)); + float a = resolveAlphaComponent(c.getAlpha()); + return new Color(space, ch, a * opacity); + } + + private static float resolveColorFunctionComponent(NumericValue item) { + float f = item.getFloatValue(); + switch (item.getCSSUnit()) { + case CSSUnit.CSS_NUMBER: + if (f < 0f) { + f = 0f; + } else if (f > 1f) { + f = 1f; + } + return f; + case CSSUnit.CSS_PERCENTAGE: + if (f < 0f) { + f = 0f; + } else if (f > 100f) { + f = 100f; + } + return f * 0.01f; + } + throw new IllegalArgumentException("Invalid color component: " + item.getCssText()); + } + + private static float[] d65xyzToD50(float[] xyz) { + // Chromatic adjustment: D65 to D50, Bradford + // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html + float[] xyzadj = new float[3]; + xyzadj[0] = (float) (1.0478112436606313d * xyz[0] + 0.022886602481693052d * xyz[1] + - 0.05012697596852886d * xyz[2]); + xyzadj[1] = (float) (0.029542398290574905d * xyz[0] + 0.9904844034904394d * xyz[1] + - 0.017049095628961564d * xyz[2]); + xyzadj[2] = (float) (-0.009234489723309473d * xyz[0] + 0.015043616793498756d * xyz[1] + + 0.7521316354746059d * xyz[2]); + return xyzadj; + } + ///////////////////////////////////////////////////////////////////////// // java.awt.stroke ///////////////////////////////////////////////////////////////////////// @@ -611,7 +737,7 @@ public static Stroke convertStroke(Element e) { */ public static float[] convertStrokeDasharray(Value v) { float[] dasharray = null; - if (v.getCssValueType() == CSSValue.CSS_VALUE_LIST) { + if (v.getCssValueType() == CssType.LIST) { int length = v.getLength(); dasharray = new float[length]; float sum = 0; @@ -646,7 +772,7 @@ public static float convertStrokeMiterlimit(Value v) { * @param v the CSS value describing the linecap property */ public static int convertStrokeLinecap(Value v) { - String s = v.getStringValue(); + String s = v.getIdentifierValue(); switch (s.charAt(0)) { case 'b': return BasicStroke.CAP_BUTT; @@ -665,7 +791,7 @@ public static int convertStrokeLinecap(Value v) { * @param v the CSS value describing the linejoin property */ public static int convertStrokeLinejoin(Value v) { - String s = v.getStringValue(); + String s = v.getIdentifierValue(); switch (s.charAt(0)) { case 'm': return BasicStroke.JOIN_MITER; @@ -689,12 +815,12 @@ public static int convertStrokeLinejoin(Value v) { */ public static int resolveColorComponent(Value v) { float f; - switch (v.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_PERCENTAGE: + switch (v.getCSSUnit()) { + case CSSUnit.CSS_PERCENTAGE: f = v.getFloatValue(); f = (f > 100f) ? 100f : (f < 0f) ? 0f : f; return Math.round(255f * f / 100f); - case CSSPrimitiveValue.CSS_NUMBER: + case CSSUnit.CSS_NUMBER: f = v.getFloatValue(); f = (f > 255f) ? 255f : (f < 0f) ? 0f : f; return Math.round(f); @@ -705,12 +831,12 @@ public static int resolveColorComponent(Value v) { private static float resolveAlphaComponent(Value v) { float f; - switch (v.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_PERCENTAGE: + switch (v.getCSSUnit()) { + case CSSUnit.CSS_PERCENTAGE: f = v.getFloatValue(); f = (f > 100f) ? 100f : (f < 0f) ? 0f : f; return f * 0.01f; - case CSSPrimitiveValue.CSS_NUMBER: + case CSSUnit.CSS_NUMBER: f = v.getFloatValue(); f = (f > 1f) ? 1f : (f < 0f) ? 0f : f; return f; diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/SVGAnimationEngine.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/SVGAnimationEngine.java index 38b03f225..cc91c3b18 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/SVGAnimationEngine.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/SVGAnimationEngine.java @@ -28,11 +28,10 @@ import java.util.LinkedList; import java.util.Set; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSValue; import org.w3c.dom.events.EventTarget; import org.w3c.dom.svg.SVGAngle; import org.w3c.dom.svg.SVGLength; @@ -66,11 +65,11 @@ import io.sf.carte.echosvg.anim.values.AnimatableStringValue; import io.sf.carte.echosvg.anim.values.AnimatableValue; import io.sf.carte.echosvg.constants.XMLConstants; +import io.sf.carte.echosvg.css.dom.CSSValue.CssType; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.StyleMap; -import io.sf.carte.echosvg.css.engine.value.FloatValue; -import io.sf.carte.echosvg.css.engine.value.StringValue; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.css.engine.value.ValueManager; import io.sf.carte.echosvg.parser.DefaultLengthHandler; @@ -93,8 +92,10 @@ /** * An AnimationEngine for SVG documents. * - * @author Cameron McCormack - * @author For later modifications, see Git history. + *

+ * Original author: Cameron McCormack. + * For later modifications, see Git history. + *

* @version $Id$ */ public class SVGAnimationEngine extends AnimationEngine { @@ -1090,7 +1091,7 @@ protected Value computeValue(CSSStylableElement elt, String pn, Value v) { ValueManager[] vms = cssEngine.getValueManagers(); int idx = cssEngine.getPropertyIndex(pn); if (idx != -1) { - if (v.getCssValueType() == CSSValue.CSS_INHERIT) { + if (v.getPrimitiveType() == Type.INHERIT) { elt = CSSEngine.getParentCSSStylableElement(elt); if (elt != null) { return cssEngine.getComputedStyle(elt, null, idx); @@ -1200,10 +1201,10 @@ public AnimatableValue createValue(AnimationTarget target, String ns, String ln, */ @Override public AnimatableValue createValue(AnimationTarget target, String pn, Value v) { - switch (v.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_PERCENTAGE: + switch (v.getCSSUnit()) { + case CSSUnit.CSS_PERCENTAGE: return new AnimatableNumberOrPercentageValue(target, v.getFloatValue(), true); - case CSSPrimitiveValue.CSS_NUMBER: + case CSSUnit.CSS_NUMBER: return new AnimatableNumberOrPercentageValue(target, v.getFloatValue()); } // XXX Do something better than returning null. @@ -1760,12 +1761,11 @@ protected class AnimatableLengthOrIdentFactory extends CSSValueFactory { @Override protected AnimatableValue createAnimatableValue(AnimationTarget target, String pn, Value v) { - if (v instanceof StringValue) { - return new AnimatableLengthOrIdentValue(target, v.getStringValue()); + if (v.getPrimitiveType() == Type.IDENT) { + return new AnimatableLengthOrIdentValue(target, v.getIdentifierValue()); } short pcInterp = target.getPercentageInterpretation(null, pn, true); - FloatValue fv = (FloatValue) v; - return new AnimatableLengthOrIdentValue(target, fv.getPrimitiveType(), fv.getFloatValue(), pcInterp); + return new AnimatableLengthOrIdentValue(target, v.getCSSUnit(), v.getFloatValue(), pcInterp); } } @@ -1787,11 +1787,10 @@ public AnimatableNumberOrIdentFactory(boolean numericIdents) { @Override protected AnimatableValue createAnimatableValue(AnimationTarget target, String pn, Value v) { - if (v instanceof StringValue) { - return new AnimatableNumberOrIdentValue(target, v.getStringValue()); + if (v.getPrimitiveType() == Type.IDENT) { + return new AnimatableNumberOrIdentValue(target, v.getIdentifierValue()); } - FloatValue fv = (FloatValue) v; - return new AnimatableNumberOrIdentValue(target, fv.getFloatValue(), numericIdents); + return new AnimatableNumberOrIdentValue(target, v.getFloatValue(), numericIdents); } } @@ -1803,24 +1802,23 @@ protected class AnimatableAngleValueFactory extends CSSValueFactory { @Override protected AnimatableValue createAnimatableValue(AnimationTarget target, String pn, Value v) { - FloatValue fv = (FloatValue) v; short unit; - switch (fv.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_NUMBER: - case CSSPrimitiveValue.CSS_DEG: + switch (v.getCSSUnit()) { + case CSSUnit.CSS_NUMBER: + case CSSUnit.CSS_DEG: unit = SVGAngle.SVG_ANGLETYPE_DEG; break; - case CSSPrimitiveValue.CSS_RAD: + case CSSUnit.CSS_RAD: unit = SVGAngle.SVG_ANGLETYPE_RAD; break; - case CSSPrimitiveValue.CSS_GRAD: + case CSSUnit.CSS_GRAD: unit = SVGAngle.SVG_ANGLETYPE_GRAD; break; default: // XXX Do something better than returning null. return null; } - return new AnimatableAngleValue(target, fv.getFloatValue(), unit); + return new AnimatableAngleValue(target, v.getFloatValue(), unit); } } @@ -1832,27 +1830,26 @@ protected class AnimatableAngleOrIdentFactory extends CSSValueFactory { @Override protected AnimatableValue createAnimatableValue(AnimationTarget target, String pn, Value v) { - if (v instanceof StringValue) { - return new AnimatableAngleOrIdentValue(target, v.getStringValue()); + if (v.getPrimitiveType() == Type.IDENT) { + return new AnimatableAngleOrIdentValue(target, v.getIdentifierValue()); } - FloatValue fv = (FloatValue) v; short unit; - switch (fv.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_NUMBER: - case CSSPrimitiveValue.CSS_DEG: + switch (v.getCSSUnit()) { + case CSSUnit.CSS_NUMBER: + case CSSUnit.CSS_DEG: unit = SVGAngle.SVG_ANGLETYPE_DEG; break; - case CSSPrimitiveValue.CSS_RAD: + case CSSUnit.CSS_RAD: unit = SVGAngle.SVG_ANGLETYPE_RAD; break; - case CSSPrimitiveValue.CSS_GRAD: + case CSSUnit.CSS_GRAD: unit = SVGAngle.SVG_ANGLETYPE_GRAD; break; default: // XXX Do something better than returning null. return null; } - return new AnimatableAngleOrIdentValue(target, fv.getFloatValue(), unit); + return new AnimatableAngleOrIdentValue(target, v.getFloatValue(), unit); } } @@ -1891,35 +1888,36 @@ protected AnimatablePaintValue createColorPaintValue(AnimationTarget t, Color c) @Override protected AnimatableValue createAnimatableValue(AnimationTarget target, String pn, Value v) { - if (v.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (v.getCssValueType() != CssType.LIST) { switch (v.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_IDENT: + case IDENT: return AnimatablePaintValue.createNonePaintValue(target); - case CSSPrimitiveValue.CSS_RGBCOLOR: { + case COLOR: { Paint p = PaintServer.convertPaint(target.getElement(), null, v, 1.0f, ctx); return createColorPaintValue(target, (Color) p); } - case CSSPrimitiveValue.CSS_URI: - return AnimatablePaintValue.createURIPaintValue(target, v.getStringValue()); + case URI: + return AnimatablePaintValue.createURIPaintValue(target, v.getURIValue()); } } else { Value v1 = v.item(0); switch (v1.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_RGBCOLOR: { + case COLOR: Paint p = PaintServer.convertPaint(target.getElement(), null, v, 1.0f, ctx); return createColorPaintValue(target, (Color) p); - } - case CSSPrimitiveValue.CSS_URI: { + case URI: Value v2 = v.item(1); switch (v2.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_IDENT: - return AnimatablePaintValue.createURINonePaintValue(target, v1.getStringValue()); - case CSSPrimitiveValue.CSS_RGBCOLOR: { - Paint p = PaintServer.convertPaint(target.getElement(), null, v.item(1), 1.0f, ctx); + case IDENT: + return AnimatablePaintValue.createURINonePaintValue(target, v1.getIdentifierValue()); + case COLOR: + p = PaintServer.convertPaint(target.getElement(), null, v.item(1), 1.0f, ctx); return createColorPaintValue(target, (Color) p); + default: + break; } - } - } + default: + break; } } // XXX Indicate that the specified Value wasn't a Color? diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/SVGGVTFont.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/SVGGVTFont.java index ba1ac0c2f..43b9a29f2 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/SVGGVTFont.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/SVGGVTFont.java @@ -117,7 +117,7 @@ public SVGGVTFont(float fontSize, GVTFontFace fontFace, String[] glyphUnicodes, this.language = XMLSupport.getXMLLang(textElement); Value v = CSSUtilities.getComputedStyle(textElement, SVGCSSEngine.WRITING_MODE_INDEX); - if (v.getStringValue().startsWith(CSS_TB_VALUE)) { + if (v.getIdentifierValue().startsWith(CSS_TB_VALUE)) { // top to bottom, so set orientation to "v" this.orientation = SVG_V_VALUE; } else { diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/SVGTextElementBridge.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/SVGTextElementBridge.java index e6d2b21fa..ee9cd9aa7 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/SVGTextElementBridge.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/SVGTextElementBridge.java @@ -40,10 +40,9 @@ import java.util.Set; import java.util.WeakHashMap; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.Element; import org.w3c.dom.Node; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; import org.w3c.dom.events.Event; import org.w3c.dom.events.EventListener; import org.w3c.dom.events.MutationEvent; @@ -52,6 +51,7 @@ import org.w3c.dom.svg.SVGTextContentElement; import org.w3c.dom.svg.SVGTextPositioningElement; +import io.sf.carte.doc.style.css.property.NumberValue; import io.sf.carte.echosvg.anim.dom.AbstractSVGAnimatedLength; import io.sf.carte.echosvg.anim.dom.AnimatedLiveAttributeValue; import io.sf.carte.echosvg.anim.dom.SVGOMAnimatedEnumeration; @@ -61,11 +61,11 @@ import io.sf.carte.echosvg.anim.dom.SVGOMTextPositioningElement; import io.sf.carte.echosvg.bridge.StrokingTextPainter.TextRun; import io.sf.carte.echosvg.constants.XMLConstants; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngineEvent; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.SVGCSSEngine; import io.sf.carte.echosvg.css.engine.StyleMap; -import io.sf.carte.echosvg.css.engine.value.ListValue; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.dom.events.NodeEventTarget; import io.sf.carte.echosvg.dom.svg.LiveAttributeException; @@ -1379,7 +1379,8 @@ protected List getFontList(BridgeContext ctx, Element element, Map getAttributeMap(BridgeContext ctx, Element elem // Unicode-bidi mode Value val = CSSUtilities.getComputedStyle(element, SVGCSSEngine.UNICODE_BIDI_INDEX); - s = val.getStringValue(); + s = val.getIdentifierValue(); if (s.charAt(0) == 'n') { if (bidiLevel != null) result.put(TextAttribute.BIDI_EMBEDDING, bidiLevel); @@ -1498,7 +1499,7 @@ protected Map getAttributeMap(BridgeContext ctx, Element elem // normal writing direction for a string/substring. val = CSSUtilities.getComputedStyle(element, SVGCSSEngine.DIRECTION_INDEX); - String rs = val.getStringValue(); + String rs = val.getIdentifierValue(); int cbidi = 0; if (bidiLevel != null) cbidi = bidiLevel; @@ -1537,7 +1538,7 @@ protected Map getAttributeMap(BridgeContext ctx, Element elem // Writing mode val = CSSUtilities.getComputedStyle(element, SVGCSSEngine.WRITING_MODE_INDEX); - s = val.getStringValue(); + s = val.getIdentifierValue(); switch (s.charAt(0)) { case 'l': result.put(GVTAttributedCharacterIterator.TextAttribute.WRITING_MODE, @@ -1556,53 +1557,58 @@ protected Map getAttributeMap(BridgeContext ctx, Element elem // glyph-orientation-vertical val = CSSUtilities.getComputedStyle(element, SVGCSSEngine.GLYPH_ORIENTATION_VERTICAL_INDEX); - int primitiveType = val.getPrimitiveType(); + Type primitiveType = val.getPrimitiveType(); switch (primitiveType) { - case CSSPrimitiveValue.CSS_IDENT: // auto + case IDENT: // auto result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION, GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_AUTO); break; - case CSSPrimitiveValue.CSS_DEG: - result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION, - GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_ANGLE); - result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION_ANGLE, val.getFloatValue()); - break; - case CSSPrimitiveValue.CSS_RAD: - result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION, - GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_ANGLE); - result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION_ANGLE, - (float) Math.toDegrees(val.getFloatValue())); - break; - case CSSPrimitiveValue.CSS_GRAD: - result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION, - GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_ANGLE); - result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION_ANGLE, - val.getFloatValue() * 9 / 5); + case NUMERIC: + switch (val.getCSSUnit()) { + case CSSUnit.CSS_DEG: + case CSSUnit.CSS_NUMBER: + result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION, + GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_ANGLE); + result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION_ANGLE, val.getFloatValue()); + break; + case CSSUnit.CSS_RAD: + result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION, + GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_ANGLE); + result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION_ANGLE, + (float) Math.toDegrees(val.getFloatValue())); + break; + case CSSUnit.CSS_GRAD: + result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION, + GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_ANGLE); + result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION_ANGLE, + val.getFloatValue() * 9 / 5); + break; + default: + if (CSSUnit.isAngleUnitType(val.getCSSUnit())) { + float f = NumberValue.floatValueConversion(val.getFloatValue(), val.getCSSUnit(), CSSUnit.CSS_DEG); + result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION, + GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_ANGLE); + result.put(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION_ANGLE, f); + break; + } + throw new IllegalStateException("unexpected value (V):" + val.getCssText()); + } break; default: - // Cannot happen throw new IllegalStateException("unexpected primitiveType (V):" + primitiveType); } // glyph-orientation-horizontal val = CSSUtilities.getComputedStyle(element, SVGCSSEngine.GLYPH_ORIENTATION_HORIZONTAL_INDEX); - primitiveType = val.getPrimitiveType(); - switch (primitiveType) { - case CSSPrimitiveValue.CSS_DEG: + short unit = val.getCSSUnit(); + if (unit == CSSUnit.CSS_NUMBER || unit == CSSUnit.CSS_DEG) { result.put(GVTAttributedCharacterIterator.TextAttribute.HORIZONTAL_ORIENTATION_ANGLE, val.getFloatValue()); - break; - case CSSPrimitiveValue.CSS_RAD: - result.put(GVTAttributedCharacterIterator.TextAttribute.HORIZONTAL_ORIENTATION_ANGLE, - (float) Math.toDegrees(val.getFloatValue())); - break; - case CSSPrimitiveValue.CSS_GRAD: - result.put(GVTAttributedCharacterIterator.TextAttribute.HORIZONTAL_ORIENTATION_ANGLE, - val.getFloatValue() * 9 / 5); - break; - default: - // Cannot happen - throw new IllegalStateException("unexpected primitiveType (H):" + primitiveType); + } else if (CSSUnit.isAngleUnitType(unit)) { + float f = NumberValue.floatValueConversion(val.getFloatValue(), val.getCSSUnit(), CSSUnit.CSS_DEG); + result.put(GVTAttributedCharacterIterator.TextAttribute.HORIZONTAL_ORIENTATION_ANGLE, f); + } else { + throw new IllegalStateException("unexpected value (H):" + val.getCssText()); } // text spacing properties... @@ -1730,13 +1736,11 @@ public void setDecorationTextPaintInfo(TextPaintInfo pi, Element element) { Value val = CSSUtilities.getComputedStyle(element, SVGCSSEngine.TEXT_DECORATION_INDEX); switch (val.getCssValueType()) { - case CSSValue.CSS_VALUE_LIST: - ListValue lst = (ListValue) val; - - int len = lst.getLength(); + case LIST: + int len = val.getLength(); for (int i = 0; i < len; i++) { - Value v = lst.item(i); - String s = v.getStringValue(); + Value v = val.item(i); + String s = v.getIdentifierValue(); switch (s.charAt(0)) { case 'u': if (pi.fillPaint != null) { diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/TextUtilities.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/TextUtilities.java index a72e9b321..95f0b5e34 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/TextUtilities.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/TextUtilities.java @@ -24,8 +24,8 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; -import org.w3c.dom.css.CSSPrimitiveValue; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.SVGCSSEngine; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.util.CSSConstants; @@ -135,7 +135,7 @@ public static Float convertFontSize(Element e) { */ public static Float convertFontStyle(Element e) { Value v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.FONT_STYLE_INDEX); - switch (v.getStringValue().charAt(0)) { + switch (v.getIdentifierValue().charAt(0)) { case 'n': return TextAttribute.POSTURE_REGULAR; default: @@ -150,7 +150,7 @@ public static Float convertFontStyle(Element e) { */ public static Float convertFontStretch(Element e) { Value v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.FONT_STRETCH_INDEX); - String s = v.getStringValue(); + String s = v.getIdentifierValue(); switch (s.charAt(0)) { case 'u': if (s.charAt(6) == 'c') { @@ -234,7 +234,7 @@ public static Float convertFontWeight(Element e) { */ public static TextNode.Anchor convertTextAnchor(Element e) { Value v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.TEXT_ANCHOR_INDEX); - switch (v.getStringValue().charAt(0)) { + switch (v.getIdentifierValue().charAt(0)) { case 's': return TextNode.Anchor.START; case 'm': @@ -252,8 +252,8 @@ public static TextNode.Anchor convertTextAnchor(Element e) { */ public static Object convertBaselineShift(Element e) { Value v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.BASELINE_SHIFT_INDEX); - if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { - String s = v.getStringValue(); + if (v.getPrimitiveType() == Type.IDENT) { + String s = v.getIdentifierValue(); switch (s.charAt(2)) { case 'p': // suPerscript return TextAttribute.SUPERSCRIPT_SUPER; @@ -276,7 +276,7 @@ public static Object convertBaselineShift(Element e) { */ public static Float convertKerning(Element e) { Value v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.KERNING_INDEX); - if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { + if (v.getPrimitiveType() == Type.IDENT) { return null; } return v.getFloatValue(); @@ -290,7 +290,7 @@ public static Float convertKerning(Element e) { */ public static Float convertLetterSpacing(Element e) { Value v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.LETTER_SPACING_INDEX); - if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { + if (v.getPrimitiveType() == Type.IDENT) { return null; } return v.getFloatValue(); @@ -304,7 +304,7 @@ public static Float convertLetterSpacing(Element e) { */ public static Float convertWordSpacing(Element e) { Value v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.WORD_SPACING_INDEX); - if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { + if (v.getPrimitiveType() == Type.IDENT) { return null; } return v.getFloatValue(); diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/Viewport.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/Viewport.java index 987dffd53..612c859b7 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/Viewport.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/Viewport.java @@ -22,20 +22,12 @@ /** * Defines a viewport. * - * @author Thierry Kormann - * @author For later modifications, see Git history. + *

+ * Original author: Thierry Kormann. + * For later modifications, see Git history. + *

* @version $Id$ */ -public interface Viewport { - - /** - * Returns the width of this viewport. - */ - float getWidth(); - - /** - * Returns the height of this viewport. - */ - float getHeight(); +public interface Viewport extends io.sf.carte.echosvg.css.Viewport { } diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/svg12/SVGSolidColorElementBridge.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/svg12/SVGSolidColorElementBridge.java index 5cce3d879..084bbcd5f 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/svg12/SVGSolidColorElementBridge.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/svg12/SVGSolidColorElementBridge.java @@ -24,7 +24,6 @@ import java.util.Map; import org.w3c.dom.Element; -import org.w3c.dom.css.CSSValue; import io.sf.carte.echosvg.anim.dom.SVGOMDocument; import io.sf.carte.echosvg.bridge.AnimatableGenericSVGBridge; @@ -34,6 +33,7 @@ import io.sf.carte.echosvg.bridge.ErrorConstants; import io.sf.carte.echosvg.bridge.PaintBridge; import io.sf.carte.echosvg.bridge.PaintServer; +import io.sf.carte.echosvg.css.dom.CSSValue.CssType; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.StyleMap; @@ -48,8 +48,10 @@ /** * Bridge class for a regular polygon element. * - * @author Thomas Deweese - * @author For later modifications, see Git history. + *

+ * Original author: Thomas Deweese. + * For later modifications, see Git history. + *

* @version $Id$ */ public class SVGSolidColorElementBridge extends AnimatableGenericSVGBridge implements PaintBridge { @@ -143,8 +145,8 @@ protected static Color extractColor(Element paintElement, float opacity, BridgeC StyleMap sm = ((CSSStylableElement) paintElement).getComputedStyleMap(null); if (!sm.isNullCascaded(pidx)) { // It was explicit... - if (colorDef.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - return PaintServer.convertColor(colorDef, opacity); + if (colorDef.getCssValueType() != CssType.LIST) { + return PaintServer.convertColor(colorDef.getColorValue(), opacity, ctx); } else { return PaintServer.convertRGBICCColor(paintElement, colorDef.item(0), colorDef.item(1), opacity, ctx); diff --git a/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/A98RGBCompat-v4.icc b/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/A98RGBCompat-v4.icc new file mode 100644 index 000000000..4ac101af0 Binary files /dev/null and b/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/A98RGBCompat-v4.icc differ diff --git a/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/Display P3.icc b/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/Display P3.icc new file mode 100644 index 000000000..e310029c3 Binary files /dev/null and b/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/Display P3.icc differ diff --git a/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/ITU-R_BT2020.icc b/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/ITU-R_BT2020.icc new file mode 100644 index 000000000..cf554acba Binary files /dev/null and b/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/ITU-R_BT2020.icc differ diff --git a/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/NOTICE.txt b/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/NOTICE.txt new file mode 100644 index 000000000..6b3bee480 --- /dev/null +++ b/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/NOTICE.txt @@ -0,0 +1,8 @@ +The WideGamutPhoto (ProPhoto-compatible) and A98RGB-like color profiles by +Clinton Ingram are CC-licensed as shown in the 'Compact-ICC-Profiles-license' +file. + +The Display P3 profile was made by Apple and was obtained from color.org (ICC). + +The profile for the ITU-R Recommendation BT.2020 was also obtained from +color.org (ICC). diff --git a/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/WideGamutPhoto-v4.icc b/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/WideGamutPhoto-v4.icc new file mode 100644 index 000000000..2b1209d66 Binary files /dev/null and b/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/color/profiles/WideGamutPhoto-v4.icc differ diff --git a/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/resources/Messages.properties b/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/resources/Messages.properties index 8030d99c7..77e5fca02 100644 --- a/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/resources/Messages.properties +++ b/echosvg-bridge/src/main/resources/io/sf/carte/echosvg/bridge/resources/Messages.properties @@ -39,6 +39,11 @@ length.negative = \ {0}:{1}\n\ The attribute "{3}" of the element <{2}> cannot be negative +css.badValue = \ +{0}:{1}\n\ +Error in a computed value for the element <{2}>:\n\ +{3} + css.length.negative = \ {0}:{1}\n\ The CSS property "{3}" found on the element <{2}> cannot be negative diff --git a/echosvg-bridge/src/test/java/io/sf/carte/echosvg/bridge/PaintServerTest.java b/echosvg-bridge/src/test/java/io/sf/carte/echosvg/bridge/PaintServerTest.java new file mode 100644 index 000000000..958304754 --- /dev/null +++ b/echosvg-bridge/src/test/java/io/sf/carte/echosvg/bridge/PaintServerTest.java @@ -0,0 +1,219 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.bridge; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Paint; +import java.awt.geom.Dimension2D; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentType; +import org.w3c.dom.Element; +import org.w3c.dom.svg.SVGDocument; +import org.w3c.dom.svg.SVGSVGElement; + +import io.sf.carte.echosvg.anim.dom.SVGDOMImplementation; +import io.sf.carte.echosvg.constants.XMLConstants; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; +import io.sf.carte.echosvg.css.engine.CSSEngine; +import io.sf.carte.echosvg.css.engine.CSSStylableElement; +import io.sf.carte.echosvg.css.engine.value.ColorValue; +import io.sf.carte.echosvg.css.engine.value.Value; +import io.sf.carte.echosvg.gvt.GraphicsNode; +import io.sf.carte.echosvg.util.CSSConstants; +import io.sf.carte.echosvg.util.SVGConstants; + +/** + * Test PaintServer. + */ +public class PaintServerTest { + + BridgeContext context; + + @BeforeEach + public void setupBeforeEach() { + context = createBridgeContext(); + } + + @Test + public void testConvertRGB() { + Color color = convertPaint(CSSConstants.CSS_FILL_PROPERTY, "rgb(120, 30, 200)", + ColorValue.RGB_FUNCTION); + assertNotNull(color); + assertEquals(120, color.getRed()); + assertEquals(30, color.getGreen()); + assertEquals(200, color.getBlue()); + assertEquals(255, color.getAlpha()); + + assertNull(context.getColorSpace()); + } + + @Test + public void testConvertColorFunction() { + Color color = convertPaint(CSSConstants.CSS_FILL_PROPERTY, "color(display-p3 0.6 0.2 0.7)", + ColorValue.CS_DISPLAY_P3); + assertNotNull(color); + float[] comp = new float[3]; + color.getColorComponents(comp); + assertEquals(.6f, comp[0]); + assertEquals(.2f, comp[1]); + assertEquals(.7f, comp[2]); + assertEquals(255, color.getAlpha()); + + assertSame(CSSColorSpaces.getDisplayP3(), context.getColorSpace()); + } + + @Test + public void testConvertColorFunctionXYZD50_P3() { + Color color = convertPaint(CSSConstants.CSS_FILL_PROPERTY, "color(xyz-d50 0.07 0.08 0.19 / 0.969)", + ColorValue.CS_XYZ_D50); + assertNotNull(color); + float[] comp = new float[3]; + color.getColorComponents(comp); + assertEquals(.07f, comp[0], 1e-5f); + assertEquals(.08f, comp[1], 1e-5f); + assertEquals(.19f, comp[2], 1e-5f); + assertEquals(247, color.getAlpha()); + + assertSame(CSSColorSpaces.getDisplayP3(), context.getColorSpace()); + } + + @Test + public void testConvertColorFunctionXYZD50_A98() { + Color color = convertPaint(CSSConstants.CSS_FILL_PROPERTY, "color(xyz-d50 0.07 0.08 0.23 / 0.969)", + ColorValue.CS_XYZ_D50); + assertNotNull(color); + float[] comp = new float[3]; + color.getColorComponents(comp); + assertEquals(.07f, comp[0], 1e-5f); + assertEquals(.08f, comp[1], 1e-5f); + assertEquals(.23f, comp[2], 1e-5f); + assertEquals(247, color.getAlpha()); + + assertSame(CSSColorSpaces.getA98RGB(), context.getColorSpace()); + } + + @Test + public void testConvertColorFunctionXYZD50_REC() { + Color color = convertPaint(CSSConstants.CSS_FILL_PROPERTY, "color(xyz-d50 0.07 0.08 0.28)", + ColorValue.CS_XYZ_D50); + assertNotNull(color); + float[] comp = new float[3]; + color.getColorComponents(comp); + assertEquals(.07f, comp[0], 1e-5f); + assertEquals(.08f, comp[1], 1e-5f); + assertEquals(.28f, comp[2], 1e-5f); + assertEquals(255, color.getAlpha()); + + assertSame(CSSColorSpaces.getRec2020(), context.getColorSpace()); + } + + @Test + public void testConvertColorFunctionXYZD50_ProPhoto() { + Color color = convertPaint(CSSConstants.CSS_FILL_PROPERTY, "color(xyz-d50 0.2 0.08 0.3 / 0.969)", + ColorValue.CS_XYZ_D50); + assertNotNull(color); + float[] comp = new float[3]; + color.getColorComponents(comp); + assertEquals(.2f, comp[0], 1e-5f); + assertEquals(.08f, comp[1], 1e-5f); + assertEquals(.3f, comp[2], 1e-5f); + assertEquals(247, color.getAlpha()); + + assertSame(CSSColorSpaces.getProphotoRGB(), context.getColorSpace()); + } + + @Test + public void testConvertColorFunctionXYZD65() { + Color color = convertPaint(CSSConstants.CSS_FILL_PROPERTY, "color(xyz-d65 0.065 0.033 0.06 / 0.2)", + ColorValue.CS_XYZ_D65); + assertNotNull(color); + float[] comp = new float[3]; + color.getColorComponents(comp); + assertEquals(.06586f, comp[0], 1e-5f); // D50 + assertEquals(.0335833f, comp[1], 1e-5f); // D50 + assertEquals(.045024f, comp[2], 1e-5f); // D50 + assertEquals(51, color.getAlpha()); + + assertNull(context.getColorSpace()); + } + + private Color convertPaint(String ptyName, String paintDef, String cssSpace) { + SVGDocument doc = createDocumentWithPaint(ptyName + ':' + paintDef); + GraphicsNode gn = createGraphicsNode(context, doc); + CSSStylableElement rect = (CSSStylableElement) doc.getElementById("rect1"); + assertNotNull(rect); + + CSSEngine cssEng = CSSUtilities.getCSSEngine(rect); + int index = cssEng.getPropertyIndex(ptyName); + Value val = cssEng.getComputedStyle(rect, null, index); + + assertNotNull(val); + assertEquals(Type.COLOR, val.getPrimitiveType()); + ColorValue cssColor = val.getColorValue(); + assertEquals(cssSpace, cssColor.getCSSColorSpace()); + assertEquals(paintDef, cssColor.getCssText()); + + Paint paint = PaintServer.convertPaint(rect, gn, val, 1f, context); + assertNotNull(paint); + + return PaintServer.convertColor(cssColor, 1f, context); + } + + private static SVGDocument createDocumentWithPaint(String rectStyle) { + DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); + DocumentType dtd = impl.createDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", + "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"); + SVGDocument doc = (SVGDocument) impl.createDocument(SVGConstants.SVG_NAMESPACE_URI, + SVGConstants.SVG_SVG_TAG, dtd); + SVGSVGElement svg = doc.getRootElement(); + svg.setAttribute("width", "200"); + svg.setAttribute("height", "200"); + Element rect = doc.createElementNS(SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_RECT_TAG); + rect.setAttribute(XMLConstants.XML_ID_ATTRIBUTE, "rect1"); + rect.setAttribute(SVGConstants.SVG_STYLE_ATTRIBUTE, rectStyle); + svg.appendChild(rect); + return doc; + } + + private static BridgeContext createBridgeContext() { + return new BridgeContext(new UserAgentAdapter() { + + @Override + public Dimension2D getViewportSize() { + return new Dimension(200, 200); + } + + }); + } + + private static GraphicsNode createGraphicsNode(BridgeContext ctx, Document document) { + return new GVTBuilder().build(ctx, document); + } + +} diff --git a/echosvg-css/build.gradle b/echosvg-css/build.gradle index e1b82473b..a1f3d484b 100644 --- a/echosvg-css/build.gradle +++ b/echosvg-css/build.gradle @@ -5,6 +5,7 @@ plugins { dependencies { api project(':echosvg-util') implementation project(':echosvg-i18n') + api "io.sf.w3:domview-api:${domViewVersion}" api "io.sf.carte:svgom-api:${svgomVersion}" api "io.sf.carte:css4j:${css4jVersion}" testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}" diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/Viewport.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/Viewport.java new file mode 100644 index 000000000..fa8ef9425 --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/Viewport.java @@ -0,0 +1,39 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ + +package io.sf.carte.echosvg.css; + +/** + * A viewport. + * + * @version $Id$ + */ +public interface Viewport { + + /** + * @return the width of this viewport. + */ + float getWidth(); + + /** + * @return the height of this viewport. + */ + float getHeight(); + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMComputedStyle.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMComputedStyle.java index 780ff0ea9..4cfa82f2c 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMComputedStyle.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMComputedStyle.java @@ -21,10 +21,9 @@ import java.util.HashMap; import java.util.Map; +import org.w3c.css.om.CSSRule; +import org.w3c.css.om.CSSStyleDeclaration; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSValue; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; @@ -33,8 +32,10 @@ /** * This class represents the computed style of an element. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class CSSOMComputedStyle implements CSSStyleDeclaration { @@ -108,12 +109,12 @@ public String getPropertyValue(String propertyName) { return v.getCssText(); } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSStyleDeclaration#getPropertyCSSValue(String)}. - */ @Override - public CSSValue getPropertyCSSValue(String propertyName) { + public CSSValue getCSSStyleValue(String propertyName) { + return getCSSValue(propertyName); + } + + public CSSValue getCSSValue(String propertyName) { CSSValue result = values.get(propertyName); if (result == null) { int idx = cssEngine.getPropertyIndex(propertyName); diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGColor.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGColor.java index bd78f4f54..63c91db66 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGColor.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGColor.java @@ -18,33 +18,33 @@ */ package io.sf.carte.echosvg.css.dom; -import java.util.ArrayList; - +import org.w3c.css.om.typed.CSSColorValue; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.Counter; import org.w3c.dom.css.RGBColor; -import org.w3c.dom.css.Rect; import org.w3c.dom.svg.SVGColor; import org.w3c.dom.svg.SVGICCColor; import org.w3c.dom.svg.SVGNumber; import org.w3c.dom.svg.SVGNumberList; -import io.sf.carte.echosvg.css.engine.value.FloatValue; +import io.sf.carte.echosvg.css.engine.value.ColorFunction; +import io.sf.carte.echosvg.css.engine.value.ColorValue; +import io.sf.carte.echosvg.css.engine.value.NumericValue; import io.sf.carte.echosvg.css.engine.value.RGBColorValue; import io.sf.carte.echosvg.css.engine.value.Value; -import io.sf.carte.echosvg.css.engine.value.svg.ICCColor; +import io.sf.carte.echosvg.css.engine.value.ValueModificationHandler; import io.sf.carte.echosvg.util.CSSConstants; /** * This class implements the {@link SVGColor} interface. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ -public class CSSOMSVGColor implements SVGColor, RGBColor, SVGICCColor, SVGNumberList { +@SuppressWarnings("removal") +public class CSSOMSVGColor implements CSSValue, CSSColorValue, SVGICCColor, SVGNumberList { /** * The associated value. @@ -54,27 +54,7 @@ public class CSSOMSVGColor implements SVGColor, RGBColor, SVGICCColor, SVGNumber /** * The modifications handler. */ - protected ModificationHandler handler; - - /** - * The red component, if this value is a RGBColor. - */ - protected RedComponent redComponent; - - /** - * The green component, if this value is a RGBColor. - */ - protected GreenComponent greenComponent; - - /** - * The blue component, if this value is a RGBColor. - */ - protected BlueComponent blueComponent; - - /** - * To store the ICC color list. - */ - protected ArrayList iccColors; + protected ValueModificationHandler handler; /** * Creates a new CSSOMSVGColor. @@ -86,110 +66,166 @@ public CSSOMSVGColor(ValueProvider vp) { /** * Sets the modification handler of this value. */ - public void setModificationHandler(ModificationHandler h) { + public void setModificationHandler(ValueModificationHandler h) { handler = h; } - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#getCssText()}. - */ @Override public String getCssText() { return valueProvider.getValue().getCssText(); } - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ @Override public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - iccColors = null; - handler.textChanged(cssText); - } + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); + } + + @Override + public String toString() { + return getCssText(); + } + + @Override + public CssType getCssValueType() { + return CssType.TYPED; + } + + @Override + public Type getPrimitiveType() { + return valueProvider.getValue().getPrimitiveType(); + } + + @Override + public float getFloatValue() { + return valueProvider.getValue().getFloatValue(); + } + + @Override + public int getLength() { + return valueProvider.getValue().getLength(); + } + + @Override + public Value item(int index) { + valueProvider.getValue().setModificationHandler(handler); + return valueProvider.getValue().item(index); } - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#getCssValueType()}. - */ @Override - public short getCssValueType() { - return CSS_CUSTOM; + public String getIdentifierValue() throws DOMException { + return valueProvider.getValue().getIdentifierValue(); + } + + @Override + public String getStringValue() throws DOMException { + return valueProvider.getValue().getStringValue(); + } + + @Override + public String getURIValue() throws DOMException { + return valueProvider.getValue().getURIValue(); } /** * DOM: Implements {@link org.w3c.dom.svg.SVGColor#getColorType()}. */ - @Override + @SuppressWarnings("deprecation") public short getColorType() { Value value = valueProvider.getValue(); - int cssValueType = value.getCssValueType(); - switch (cssValueType) { - case CSSValue.CSS_PRIMITIVE_VALUE: - int primitiveType = value.getPrimitiveType(); - switch (primitiveType) { - case CSSPrimitiveValue.CSS_IDENT: { - if (value.getStringValue().equalsIgnoreCase(CSSConstants.CSS_CURRENTCOLOR_VALUE)) - return SVG_COLORTYPE_CURRENTCOLOR; - return SVG_COLORTYPE_RGBCOLOR; - } - case CSSPrimitiveValue.CSS_RGBCOLOR: - return SVG_COLORTYPE_RGBCOLOR; + switch (value.getCssValueType()) { + case TYPED: + switch (value.getPrimitiveType()) { + case IDENT: { + if (CSSConstants.CSS_CURRENTCOLOR_VALUE.equalsIgnoreCase(value.getIdentifierValue())) + return SVGColor.SVG_COLORTYPE_CURRENTCOLOR; + return SVGColor.SVG_COLORTYPE_RGBCOLOR; + } + case COLOR: + ColorValue color = value.getColorValue(); + switch (color.getCSSColorSpace()) { + case ColorValue.RGB_FUNCTION: + return SVGColor.SVG_COLORTYPE_RGBCOLOR; + default: + throw new IllegalStateException("Found unexpected color type:" + color.getCSSColorSpace()); + } + default: + // there was no case for this primitiveType, prevent throwing the other + // exception + throw new IllegalStateException("Found unexpected PrimitiveType:" + value.getPrimitiveType()); } - // there was no case for this primitiveType, prevent throwing the other - // exception - throw new IllegalStateException("Found unexpected PrimitiveType:" + primitiveType); - case CSSValue.CSS_VALUE_LIST: - return SVG_COLORTYPE_RGBCOLOR_ICCCOLOR; + case LIST: + return SVGColor.SVG_COLORTYPE_RGBCOLOR_ICCCOLOR; + default: + // should not happen + throw new IllegalStateException("Found unexpected CssValueType:" + value.getCssValueType()); } - // should not happen - throw new IllegalStateException("Found unexpected CssValueType:" + cssValueType); } /** * DOM: Implements {@link org.w3c.dom.svg.SVGColor#getRGBColor()}. */ - @Override public RGBColor getRGBColor() { - return this; + throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Legacy value API not supported."); } /** - * Returns the RGBColor value for this SVGColor. For the SVG 1.1 ECMAScript + * Returns the CSSColorValue value for this SVGColor. For the SVG ECMAScript * binding. */ - public RGBColor getRgbColor() { - return this; + public ColorValue getCSSColorValue() { + valueProvider.getValue().setModificationHandler(handler); + return valueProvider.getValue().getColorValue(); + } + + public String getCSSColorSpace() { + return getCSSColorValue().getCSSColorSpace(); + } + + public NumericValue getAlpha() { + return getCSSColorValue().getAlpha(); } /** - * DOM: Implements {@link org.w3c.dom.svg.SVGColor#setRGBColor(String)}. + * Sets the alpha channel as a percentage. + * + * @param alpha the alpha channel as a percentage. */ - @Override - public void setRGBColor(String color) { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - handler.rgbColorChanged(color); + public void setAlpha(double alpha) { + getCSSColorValue().setAlpha(alpha); + } + + public NumericValue getR() { + return getRGBColorValue().getR(); + } + + RGBColorValue getRGBColorValue() { + ColorValue color = getCSSColorValue(); + if (ColorValue.RGB_FUNCTION.equals(color.getCSSColorSpace())) { + return (RGBColorValue) color; } + throw new DOMException(DOMException.INVALID_ACCESS_ERR, "Not an RGB color."); + } + + public NumericValue getG() { + return getRGBColorValue().getG(); + } + + public NumericValue getB() { + return getRGBColorValue().getB(); } /** - * DOM: Implements {@link org.w3c.dom.svg.SVGColor#getICCColor()}. + * DOM: Implements {@link org.w3c.dom.svg.SVGColor#setRGBColor(String)}. */ - @Override - public SVGICCColor getICCColor() { - return this; + public void setRGBColor(String color) { + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } /** - * Returns the SVGICCColor value of this SVGColor. For the SVG 1.1 ECMAScript - * binding. + * DOM: Implements {@link org.w3c.dom.svg.SVGColor#getICCColor()}. */ - public SVGICCColor getIccColor() { + public SVGICCColor getICCColor() { return this; } @@ -197,80 +233,23 @@ public SVGICCColor getIccColor() { * DOM: Implements * {@link org.w3c.dom.svg.SVGColor#setRGBColorICCColor(String,String)}. */ - @Override public void setRGBColorICCColor(String rgb, String icc) { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - iccColors = null; - handler.rgbColorICCColorChanged(rgb, icc); - } + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } /** * DOM: Implements * {@link org.w3c.dom.svg.SVGColor#setColor(short,String,String)}. */ - @Override public void setColor(short type, String rgb, String icc) { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - iccColors = null; - handler.colorChanged(type, rgb, icc); - } - } - - // RGBColor /////////////////////////////////////////////////// - - /** - * DOM: Implements {@link org.w3c.dom.css.RGBColor#getRed()}. - */ - @Override - public CSSPrimitiveValue getRed() { - valueProvider.getValue().getRed(); - if (redComponent == null) { - redComponent = new RedComponent(); - } - return redComponent; - } - - /** - * DOM: Implements {@link org.w3c.dom.css.RGBColor#getGreen()}. - */ - @Override - public CSSPrimitiveValue getGreen() { - valueProvider.getValue().getGreen(); - if (greenComponent == null) { - greenComponent = new GreenComponent(); - } - return greenComponent; - } - - /** - * DOM: Implements {@link org.w3c.dom.css.RGBColor#getBlue()}. - */ - @Override - public CSSPrimitiveValue getBlue() { - valueProvider.getValue().getBlue(); - if (blueComponent == null) { - blueComponent = new BlueComponent(); - } - return blueComponent; + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } // SVGICCColor ////////////////////////////////////////////////// - /** - * DOM: Implements {@link org.w3c.dom.svg.SVGICCColor#getColorProfile()}. - */ @Override public String getColorProfile() { - if (getColorType() != SVG_COLORTYPE_RGBCOLOR_ICCCOLOR) { - throw new DOMException(DOMException.SYNTAX_ERR, ""); - } - Value value = valueProvider.getValue(); - return ((ICCColor) value.item(1)).getColorProfile(); + return getCSSColorValue().getCSSColorSpace(); } /** @@ -278,11 +257,7 @@ public String getColorProfile() { */ @Override public void setColorProfile(String colorProfile) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - handler.colorProfileChanged(colorProfile); - } + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } /** @@ -300,11 +275,11 @@ public SVGNumberList getColors() { */ @Override public int getNumberOfItems() { - if (getColorType() != SVG_COLORTYPE_RGBCOLOR_ICCCOLOR) { - throw new DOMException(DOMException.SYNTAX_ERR, ""); + ColorValue value = getCSSColorValue(); + if (!(value instanceof ColorFunction)) { + throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); } - Value value = valueProvider.getValue(); - return ((ICCColor) value.item(1)).getNumberOfColors(); + return ((ColorFunction) value).getChannels().getLength(); } /** @@ -312,12 +287,7 @@ public int getNumberOfItems() { */ @Override public void clear() throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - iccColors = null; - handler.colorsCleared(); - } + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } /** @@ -325,40 +295,28 @@ public void clear() throws DOMException { */ @Override public SVGNumber initialize(SVGNumber newItem) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - float f = newItem.getValue(); - iccColors = new ArrayList<>(); - SVGNumber result = new ColorNumber(f); - iccColors.add(result); - handler.colorsInitialized(f); - return result; - } + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } /** * DOM: Implements {@link SVGNumberList#getItem(int)}. */ + @SuppressWarnings("deprecation") @Override public SVGNumber getItem(int index) throws DOMException { - if (getColorType() != SVG_COLORTYPE_RGBCOLOR_ICCCOLOR) { + if (getColorType() != SVGColor.SVG_COLORTYPE_RGBCOLOR_ICCCOLOR) { throw new DOMException(DOMException.INDEX_SIZE_ERR, ""); } int n = getNumberOfItems(); if (index < 0 || index >= n) { throw new DOMException(DOMException.INDEX_SIZE_ERR, ""); } - if (iccColors == null) { - iccColors = new ArrayList<>(n); - for (int i = iccColors.size(); i < n; i++) { - iccColors.add(null); - } + ColorValue value = getCSSColorValue(); + if (!(value instanceof ColorFunction)) { + throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); } - Value value = valueProvider.getValue().item(1); - float f = ((ICCColor) value).getColor(index); + float f = ((ColorFunction) value).getChannels().item(index).getFloatValue(); SVGNumber result = new ColorNumber(f); - iccColors.set(index, result); return result; } @@ -367,25 +325,7 @@ public SVGNumber getItem(int index) throws DOMException { */ @Override public SVGNumber insertItemBefore(SVGNumber newItem, int index) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - int n = getNumberOfItems(); - if (index < 0 || index > n) { - throw new DOMException(DOMException.INDEX_SIZE_ERR, ""); - } - if (iccColors == null) { - iccColors = new ArrayList<>(n); - for (int i = iccColors.size(); i < n; i++) { - iccColors.add(null); - } - } - float f = newItem.getValue(); - SVGNumber result = new ColorNumber(f); - iccColors.add(index, result); - handler.colorInsertedBefore(f, index); - return result; - } + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } /** @@ -393,25 +333,7 @@ public SVGNumber insertItemBefore(SVGNumber newItem, int index) throws DOMExcept */ @Override public SVGNumber replaceItem(SVGNumber newItem, int index) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - int n = getNumberOfItems(); - if (index < 0 || index >= n) { - throw new DOMException(DOMException.INDEX_SIZE_ERR, ""); - } - if (iccColors == null) { - iccColors = new ArrayList<>(n); - for (int i = iccColors.size(); i < n; i++) { - iccColors.add(null); - } - } - float f = newItem.getValue(); - SVGNumber result = new ColorNumber(f); - iccColors.set(index, result); - handler.colorReplaced(f, index); - return result; - } + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } /** @@ -419,24 +341,7 @@ public SVGNumber replaceItem(SVGNumber newItem, int index) throws DOMException { */ @Override public SVGNumber removeItem(int index) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - int n = getNumberOfItems(); - if (index < 0 || index >= n) { - throw new DOMException(DOMException.INDEX_SIZE_ERR, ""); - } - SVGNumber result = null; - if (iccColors != null) { - result = iccColors.get(index); - } - if (result == null) { - Value value = valueProvider.getValue().item(1); - result = new ColorNumber(((ICCColor) value).getColor(index)); - } - handler.colorRemoved(index); - return result; - } + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } /** @@ -444,22 +349,7 @@ public SVGNumber removeItem(int index) throws DOMException { */ @Override public SVGNumber appendItem(SVGNumber newItem) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - if (iccColors == null) { - int n = getNumberOfItems(); - iccColors = new ArrayList<>(n); - for (int i = 0; i < n; i++) { - iccColors.add(null); - } - } - float f = newItem.getValue(); - SVGNumber result = new ColorNumber(f); - iccColors.add(result); - handler.colorAppend(f); - return result; - } + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } /** @@ -484,15 +374,7 @@ public ColorNumber(float f) { */ @Override public float getValue() { - if (iccColors == null) { - return value; - } - int idx = iccColors.indexOf(this); - if (idx == -1) { - return value; - } - Value value = valueProvider.getValue().item(1); - return ((ICCColor) value).getColor(idx); + return value; } /** @@ -500,19 +382,7 @@ public float getValue() { */ @Override public void setValue(float f) { - value = f; - if (iccColors == null) { - return; - } - int idx = iccColors.indexOf(this); - if (idx == -1) { - return; - } - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - handler.colorReplaced(f, idx); - } + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } } @@ -529,720 +399,4 @@ public interface ValueProvider { } - /** - * To manage the modifications on a CSS value. - */ - public interface ModificationHandler { - - /** - * Called when the value text has changed. - */ - void textChanged(String text) throws DOMException; - - /** - * Called when the red value text has changed. - */ - void redTextChanged(String text) throws DOMException; - - /** - * Called when the red float value has changed. - */ - void redFloatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the green value text has changed. - */ - void greenTextChanged(String text) throws DOMException; - - /** - * Called when the green float value has changed. - */ - void greenFloatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the blue value text has changed. - */ - void blueTextChanged(String text) throws DOMException; - - /** - * Called when the blue float value has changed. - */ - void blueFloatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the alpha value text has changed. - */ - void alphaTextChanged(String text) throws DOMException; - - /** - * Called when the alpha float value has changed. - */ - void alphaFloatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the RGBColor text has changed. - */ - void rgbColorChanged(String text) throws DOMException; - - /** - * Called when the RGBColor and the ICCColor text has changed. - */ - void rgbColorICCColorChanged(String rgb, String icc) throws DOMException; - - /** - * Called when the SVGColor has changed. - */ - void colorChanged(short type, String rgb, String icc) throws DOMException; - - /** - * Called when the ICC color profile has changed. - */ - void colorProfileChanged(String cp) throws DOMException; - - /** - * Called when the ICC colors has changed. - */ - void colorsCleared() throws DOMException; - - /** - * Called when the ICC colors has been initialized. - */ - void colorsInitialized(float f) throws DOMException; - - /** - * Called when the ICC color has been inserted. - */ - void colorInsertedBefore(float f, int idx) throws DOMException; - - /** - * Called when the ICC color has been replaced. - */ - void colorReplaced(float f, int idx) throws DOMException; - - /** - * Called when the ICC color has been removed. - */ - void colorRemoved(int idx) throws DOMException; - - /** - * Called when the ICC color has been append. - */ - void colorAppend(float f) throws DOMException; - - } - - /** - * Provides an abstract implementation of a ModificationHandler. - */ - public abstract class AbstractModificationHandler implements ModificationHandler { - - /** - * Returns the associated value. - */ - protected abstract Value getValue(); - - /** - * Called when the red value text has changed. - */ - @Override - public void redTextChanged(String text) throws DOMException { - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR: - text = RGBColorValue.toString(text, getValue().getGreen().getCssText(), - getValue().getBlue().getCssText(), getValue().getAlpha().getCssText()); - break; - - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - text = RGBColorValue.toString(text, getValue().item(0).getGreen().getCssText(), - getValue().item(0).getBlue().getCssText(), getValue().item(0).getAlpha().getCssText()) + ' ' - + getValue().item(1).getCssText(); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - textChanged(text); - } - - /** - * Called when the red float value has changed. - */ - @Override - public void redFloatValueChanged(short unit, float fValue) throws DOMException { - redTextChanged(FloatValue.getCssText(unit, fValue)); - } - - /** - * Called when the green value text has changed. - */ - @Override - public void greenTextChanged(String text) throws DOMException { - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR: - text = RGBColorValue.toString(getValue().getRed().getCssText(), text, getValue().getBlue().getCssText(), - getValue().getAlpha().getCssText()); - break; - - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - text = RGBColorValue.toString(getValue().item(0).getRed().getCssText(), text, - getValue().item(0).getBlue().getCssText(), getValue().item(0).getAlpha().getCssText()) + ' ' - + getValue().item(1).getCssText(); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - textChanged(text); - } - - /** - * Called when the green float value has changed. - */ - @Override - public void greenFloatValueChanged(short unit, float fValue) throws DOMException { - greenTextChanged(FloatValue.getCssText(unit, fValue)); - } - - /** - * Called when the blue value text has changed. - */ - @Override - public void blueTextChanged(String text) throws DOMException { - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR: - text = RGBColorValue.toString(getValue().getRed().getCssText(), getValue().getGreen().getCssText(), - text, getValue().getAlpha().getCssText()); - break; - - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - text = RGBColorValue.toString(getValue().item(0).getRed().getCssText(), - getValue().item(0).getGreen().getCssText(), text, getValue().item(0).getAlpha().getCssText()) - + ' ' + getValue().item(1).getCssText(); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - textChanged(text); - } - - /** - * Called when the blue float value has changed. - */ - @Override - public void blueFloatValueChanged(short unit, float fValue) throws DOMException { - blueTextChanged(FloatValue.getCssText(unit, fValue)); - } - - @Override - public void alphaTextChanged(String text) throws DOMException { - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR: - text = RGBColorValue.toString(getValue().getRed().getCssText(), getValue().getGreen().getCssText(), - getValue().getBlue().getCssText(), text); - break; - - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - text = RGBColorValue.toString(getValue().item(0).getRed().getCssText(), - getValue().item(0).getGreen().getCssText(), getValue().item(0).getBlue().getCssText(), text) - + ' ' + getValue().item(1).getCssText(); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - textChanged(text); - } - - @Override - public void alphaFloatValueChanged(short unit, float fValue) throws DOMException { - alphaTextChanged(FloatValue.getCssText(unit, fValue)); - } - - /** - * Called when the RGBColor text has changed. - */ - @Override - public void rgbColorChanged(String text) throws DOMException { - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR: - break; - - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - text += getValue().item(1).getCssText(); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - textChanged(text); - } - - /** - * Called when the RGBColor and the ICCColor text has changed. - */ - @Override - public void rgbColorICCColorChanged(String rgb, String icc) throws DOMException { - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - textChanged(rgb + ' ' + icc); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the SVGColor has changed. - */ - @Override - public void colorChanged(short type, String rgb, String icc) throws DOMException { - switch (type) { - case SVG_COLORTYPE_CURRENTCOLOR: - textChanged(CSSConstants.CSS_CURRENTCOLOR_VALUE); - break; - - case SVG_COLORTYPE_RGBCOLOR: - textChanged(rgb); - break; - - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - textChanged(rgb + ' ' + icc); - break; - - default: - throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); - } - } - - /** - * Called when the ICC color profile has changed. - */ - @Override - public void colorProfileChanged(String cp) throws DOMException { - Value value = getValue(); - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(value.item(0).getCssText()); - sb.append(" icc-color("); - sb.append(cp); - ICCColor iccc = (ICCColor) value.item(1); - for (int i = 0; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the ICC colors has changed. - */ - @Override - public void colorsCleared() throws DOMException { - Value value = getValue(); - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(value.item(0).getCssText()); - sb.append(" icc-color("); - ICCColor iccc = (ICCColor) value.item(1); - sb.append(iccc.getColorProfile()); - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the ICC colors has been initialized. - */ - @Override - public void colorsInitialized(float f) throws DOMException { - Value value = getValue(); - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(value.item(0).getCssText()); - sb.append(" icc-color("); - ICCColor iccc = (ICCColor) value.item(1); - sb.append(iccc.getColorProfile()); - sb.append(','); - sb.append(f); - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the ICC color has been inserted. - */ - @Override - public void colorInsertedBefore(float f, int idx) throws DOMException { - Value value = getValue(); - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(value.item(0).getCssText()); - sb.append(" icc-color("); - ICCColor iccc = (ICCColor) value.item(1); - sb.append(iccc.getColorProfile()); - for (int i = 0; i < idx; i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(','); - sb.append(f); - for (int i = idx; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the ICC color has been replaced. - */ - @Override - public void colorReplaced(float f, int idx) throws DOMException { - Value value = getValue(); - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(value.item(0).getCssText()); - sb.append(" icc-color("); - ICCColor iccc = (ICCColor) value.item(1); - sb.append(iccc.getColorProfile()); - for (int i = 0; i < idx; i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(','); - sb.append(f); - for (int i = idx + 1; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the ICC color has been removed. - */ - @Override - public void colorRemoved(int idx) throws DOMException { - Value value = getValue(); - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(value.item(0).getCssText()); - sb.append(" icc-color("); - ICCColor iccc = (ICCColor) value.item(1); - sb.append(iccc.getColorProfile()); - for (int i = 0; i < idx; i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - for (int i = idx + 1; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the ICC color has been append. - */ - @Override - public void colorAppend(float f) throws DOMException { - Value value = getValue(); - switch (getColorType()) { - case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(value.item(0).getCssText()); - sb.append(" icc-color("); - ICCColor iccc = (ICCColor) value.item(1); - sb.append(iccc.getColorProfile()); - for (int i = 0; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(','); - sb.append(f); - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - } - - /** - * To store a component. - */ - protected abstract class AbstractComponent implements CSSPrimitiveValue { - - /** - * The returns the actual value of this component. - */ - protected abstract Value getValue(); - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#getCssText()}. - */ - @Override - public String getCssText() { - return getValue().getCssText(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#getCssValueType()}. - */ - @Override - public short getCssValueType() { - return getValue().getCssValueType(); - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getPrimitiveType()}. - */ - @Override - public short getPrimitiveType() { - return getValue().getPrimitiveType(); - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getFloatValue(short)}. - */ - @Override - public float getFloatValue(short unitType) throws DOMException { - return CSSOMValue.convertFloatValue(unitType, getValue()); - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getStringValue()}. - */ - @Override - public String getStringValue() throws DOMException { - return valueProvider.getValue().getStringValue(); - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getCounterValue()}. - */ - @Override - public Counter getCounterValue() throws DOMException { - throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getRectValue()}. - */ - @Override - public Rect getRectValue() throws DOMException { - throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getRGBColorValue()}. - */ - @Override - public RGBColor getRGBColorValue() throws DOMException { - throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); - } - - // CSSValueList /////////////////////////////////////////////////////// - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValueList#getLength()}. - */ - public int getLength() { - throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValueList#item(int)}. - */ - public CSSValue item(int index) { - throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); - } - - } - - /** - * To store a Float component. - */ - protected abstract class FloatComponent extends AbstractComponent { - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setStringValue(short,String)}. - */ - @Override - public void setStringValue(short stringType, String stringValue) throws DOMException { - throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); - } - - } - - /** - * To represents a red component. - */ - protected class RedComponent extends FloatComponent { - - /** - * The returns the actual value of this component. - */ - @Override - protected Value getValue() { - return valueProvider.getValue().getRed(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ - @Override - public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.redTextChanged(cssText); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ - @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.redFloatValueChanged(unitType, floatValue); - } - } - - } - - /** - * To represents a green component. - */ - protected class GreenComponent extends FloatComponent { - - /** - * The returns the actual value of this component. - */ - @Override - protected Value getValue() { - return valueProvider.getValue().getGreen(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ - @Override - public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.greenTextChanged(cssText); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ - @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.greenFloatValueChanged(unitType, floatValue); - } - } - - } - - /** - * To represents a blue component. - */ - protected class BlueComponent extends FloatComponent { - - /** - * The returns the actual value of this component. - */ - @Override - protected Value getValue() { - return valueProvider.getValue().getBlue(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ - @Override - public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.blueTextChanged(cssText); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ - @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.blueFloatValueChanged(unitType, floatValue); - } - } - - } - } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGComputedStyle.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGComputedStyle.java index c7a77277c..1dd5ee7de 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGComputedStyle.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGComputedStyle.java @@ -18,8 +18,6 @@ */ package io.sf.carte.echosvg.css.dom; -import org.w3c.dom.css.CSSValue; - import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.SVGCSSEngine; diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGPaint.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGPaint.java index 2e9a92cb1..5df3c3105 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGPaint.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGPaint.java @@ -19,24 +19,25 @@ package io.sf.carte.echosvg.css.dom; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; import org.w3c.dom.svg.SVGPaint; -import io.sf.carte.echosvg.css.engine.value.FloatValue; -import io.sf.carte.echosvg.css.engine.value.RGBColorValue; +import io.sf.carte.echosvg.css.engine.value.AbstractValueModificationHandler; +import io.sf.carte.echosvg.css.engine.value.ColorValue; import io.sf.carte.echosvg.css.engine.value.Value; -import io.sf.carte.echosvg.css.engine.value.svg.ICCColor; +import io.sf.carte.echosvg.css.engine.value.ValueModificationHandler; import io.sf.carte.echosvg.util.CSSConstants; /** * This class implements the {@link SVGPaint} interface. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ -public class CSSOMSVGPaint extends CSSOMSVGColor implements SVGPaint { +@SuppressWarnings("deprecation") +public class CSSOMSVGPaint extends CSSOMSVGColor { /** * Creates a new CSSOMSVGPaint. @@ -49,7 +50,7 @@ public CSSOMSVGPaint(ValueProvider vp) { * Sets the modification handler of this value. */ @Override - public void setModificationHandler(ModificationHandler h) { + public void setModificationHandler(ValueModificationHandler h) { if (!(h instanceof PaintModificationHandler)) { throw new IllegalArgumentException(); } @@ -67,74 +68,104 @@ public short getColorType() { /** * DOM: Implements {@link org.w3c.dom.svg.SVGPaint#getPaintType()}. */ - @Override public short getPaintType() { Value value = valueProvider.getValue(); switch (value.getCssValueType()) { - case CSSValue.CSS_PRIMITIVE_VALUE: + case TYPED: switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_IDENT: { - String str = value.getStringValue(); + case IDENT: + String str = value.getIdentifierValue(); if (str.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) { - return SVG_PAINTTYPE_NONE; + return SVGPaint.SVG_PAINTTYPE_NONE; } else if (str.equalsIgnoreCase(CSSConstants.CSS_CURRENTCOLOR_VALUE)) { - return SVG_PAINTTYPE_CURRENTCOLOR; + return SVGPaint.SVG_PAINTTYPE_CURRENTCOLOR; } - return SVG_PAINTTYPE_RGBCOLOR; - } - case CSSPrimitiveValue.CSS_RGBCOLOR: - return SVG_PAINTTYPE_RGBCOLOR; - - case CSSPrimitiveValue.CSS_URI: - return SVG_PAINTTYPE_URI; + return SVGPaint.SVG_PAINTTYPE_RGBCOLOR; + case COLOR: + ColorValue color = value.getColorValue(); + switch (color.getCSSColorSpace()) { + case ColorValue.RGB_FUNCTION: + return SVGPaint.SVG_PAINTTYPE_RGBCOLOR; + default: + break; + } + break; + case URI: + return SVGPaint.SVG_PAINTTYPE_URI; + default: + break; } break; - case CSSValue.CSS_VALUE_LIST: + case LIST: Value v0 = value.item(0); Value v1 = value.item(1); switch (v0.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_IDENT: - return SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR; - case CSSPrimitiveValue.CSS_URI: - if (v1.getCssValueType() == CSSValue.CSS_VALUE_LIST) - // Should probably check this more deeply... - return SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR; + case IDENT: + return SVGPaint.SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR; + case URI: + if (v1.getCssValueType() == Value.CssType.LIST) + // FIXME: Should probably check this more deeply... + return SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR; switch (v1.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_IDENT: { - String str = v1.getStringValue(); + case IDENT: + String str = v1.getIdentifierValue(); if (str.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) { - return SVG_PAINTTYPE_URI_NONE; + return SVGPaint.SVG_PAINTTYPE_URI_NONE; } else if (str.equalsIgnoreCase(CSSConstants.CSS_CURRENTCOLOR_VALUE)) { - return SVG_PAINTTYPE_URI_CURRENTCOLOR; + return SVGPaint.SVG_PAINTTYPE_URI_CURRENTCOLOR; } - return SVG_PAINTTYPE_URI_RGBCOLOR; - } - case CSSPrimitiveValue.CSS_RGBCOLOR: - return SVG_PAINTTYPE_URI_RGBCOLOR; + return SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR; + case COLOR: + ColorValue color = v1.getColorValue(); + switch (color.getCSSColorSpace()) { + case ColorValue.RGB_FUNCTION: + return SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR; + default: + break; + } + default: + break; } - case CSSPrimitiveValue.CSS_RGBCOLOR: - return SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR; + break; + case COLOR: + ColorValue color = v0.getColorValue(); + switch (color.getCSSColorSpace()) { + case ColorValue.RGB_FUNCTION: + return SVGPaint.SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR; + default: + break; + } + default: + break; } + default: + break; + } - return SVG_PAINTTYPE_UNKNOWN; + + return SVGPaint.SVG_PAINTTYPE_UNKNOWN; + } + + @Override + public String getURIValue() throws DOMException { + return getUri(); } /** * DOM: Implements {@link org.w3c.dom.svg.SVGPaint#getUri()}. */ - @Override public String getUri() { switch (getPaintType()) { - case SVG_PAINTTYPE_URI: - return valueProvider.getValue().getStringValue(); + case SVGPaint.SVG_PAINTTYPE_URI: + return valueProvider.getValue().getURIValue(); - case SVG_PAINTTYPE_URI_NONE: - case SVG_PAINTTYPE_URI_CURRENTCOLOR: - case SVG_PAINTTYPE_URI_RGBCOLOR: - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: + case SVGPaint.SVG_PAINTTYPE_URI_NONE: + case SVGPaint.SVG_PAINTTYPE_URI_CURRENTCOLOR: + case SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR: + case SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: return valueProvider.getValue().item(0).getStringValue(); } throw new InternalError(); @@ -143,12 +174,11 @@ public String getUri() { /** * DOM: Implements {@link org.w3c.dom.svg.SVGPaint#setUri(String)}. */ - @Override public void setUri(String uri) { if (handler == null) { throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } else { - ((PaintModificationHandler) handler).uriChanged(uri); + ((PaintModificationHandler) handler).uriValueChanged(uri); } } @@ -156,7 +186,6 @@ public void setUri(String uri) { * DOM: Implements * {@link org.w3c.dom.svg.SVGPaint#setPaint(short,String,String,String)}. */ - @Override public void setPaint(short paintType, String uri, String rgbColor, String iccColor) { if (handler == null) { throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); @@ -168,12 +197,12 @@ public void setPaint(short paintType, String uri, String rgbColor, String iccCol /** * To manage the modifications on a SVGPaint value. */ - public interface PaintModificationHandler extends ModificationHandler { + public interface PaintModificationHandler extends ValueModificationHandler { /** * Called when the URI has been modified. */ - void uriChanged(String uri); + void uriValueChanged(String uri); /** * Called when the paint value has beem modified. @@ -185,559 +214,15 @@ public interface PaintModificationHandler extends ModificationHandler { /** * Provides an abstract implementation of a PaintModificationHandler. */ - public abstract class AbstractModificationHandler implements PaintModificationHandler { - - /** - * Returns the associated value. - */ - protected abstract Value getValue(); - - /** - * Called when the red value text has changed. - */ - @Override - public void redTextChanged(String text) throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR: - text = RGBColorValue.toString(text, getValue().getGreen().getCssText(), - getValue().getBlue().getCssText(), getValue().getAlpha().getCssText()); - break; - - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - text = RGBColorValue.toString(text, getValue().item(0).getGreen().getCssText(), - getValue().item(0).getBlue().getCssText(), getValue().item(0).getAlpha().getCssText()) + ' ' - + getValue().item(1).getCssText(); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR: - text = getValue().item(0).getCssText() + ' ' - + RGBColorValue.toString(text, getValue().item(1).getGreen().getCssText(), - getValue().item(1).getBlue().getCssText(), getValue().item(1).getAlpha().getCssText()); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - text = getValue().item(0).getCssText() + ' ' - + RGBColorValue.toString(text, getValue().item(1).getGreen().getCssText(), - getValue().item(1).getBlue().getCssText(), getValue().item(1).getAlpha().getCssText()) - + ' ' + getValue().item(2).getCssText(); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - textChanged(text); - } - - /** - * Called when the red float value has changed. - */ - @Override - public void redFloatValueChanged(short unit, float value) throws DOMException { - redTextChanged(FloatValue.getCssText(unit, value)); - } - - /** - * Called when the green value text has changed. - */ - @Override - public void greenTextChanged(String text) throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR: - text = RGBColorValue.toString(getValue().getRed().getCssText(), text, getValue().getBlue().getCssText(), - getValue().getAlpha().getCssText()); - break; - - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - text = RGBColorValue.toString(getValue().item(0).getRed().getCssText(), text, - getValue().item(0).getBlue().getCssText(), getValue().item(0).getAlpha().getCssText()) + ' ' - + getValue().item(1).getCssText(); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR: - text = getValue().item(0).getCssText() + ' ' - + RGBColorValue.toString(getValue().item(1).getRed().getCssText(), text, - getValue().item(1).getBlue().getCssText(), getValue().item(1).getAlpha().getCssText()); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - text = getValue().item(0).getCssText() + ' ' - + RGBColorValue.toString(getValue().item(1).getRed().getCssText(), text, - getValue().item(1).getBlue().getCssText(), getValue().item(1).getAlpha().getCssText()) - + ' ' + getValue().item(2).getCssText(); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - textChanged(text); - } - - /** - * Called when the green float value has changed. - */ - @Override - public void greenFloatValueChanged(short unit, float value) throws DOMException { - greenTextChanged(FloatValue.getCssText(unit, value)); - } - - /** - * Called when the blue value text has changed. - */ - @Override - public void blueTextChanged(String text) throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR: - text = RGBColorValue.toString(getValue().getRed().getCssText(), getValue().getGreen().getCssText(), - text, getValue().getAlpha().getCssText()); - break; - - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - text = RGBColorValue.toString(getValue().item(0).getRed().getCssText(), - getValue().item(0).getGreen().getCssText(), text, getValue().item(0).getAlpha().getCssText()) - + ' ' + getValue().item(1).getCssText(); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR: - text = getValue().item(0).getCssText() + ' ' - + RGBColorValue.toString(getValue().item(1).getRed().getCssText(), - getValue().item(1).getGreen().getCssText(), text, - getValue().item(1).getAlpha().getCssText()); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - text = getValue().item(0).getCssText() + ' ' - + RGBColorValue.toString(getValue().item(1).getRed().getCssText(), - getValue().item(1).getGreen().getCssText(), text, - getValue().item(1).getAlpha().getCssText()) - + ' ' + getValue().item(2).getCssText(); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - textChanged(text); - } - - /** - * Called when the blue float value has changed. - */ - @Override - public void blueFloatValueChanged(short unit, float value) throws DOMException { - blueTextChanged(FloatValue.getCssText(unit, value)); - } - - @Override - public void alphaTextChanged(String text) throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR: - text = RGBColorValue.toString(getValue().getRed().getCssText(), getValue().getGreen().getCssText(), - getValue().getBlue().getCssText(), text); - break; - - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - text = RGBColorValue.toString(getValue().item(0).getRed().getCssText(), - getValue().item(0).getGreen().getCssText(), getValue().item(0).getBlue().getCssText(), text) - + ' ' + getValue().item(1).getCssText(); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR: - text = getValue().item(0).getCssText() + ' ' - + RGBColorValue.toString(getValue().item(1).getRed().getCssText(), - getValue().item(1).getGreen().getCssText(), getValue().item(1).getBlue().getCssText(), - text); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - text = getValue().item(0).getCssText() + ' ' - + RGBColorValue.toString(getValue().item(1).getRed().getCssText(), - getValue().item(1).getGreen().getCssText(), getValue().item(1).getBlue().getCssText(), - text) - + ' ' + getValue().item(2).getCssText(); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - textChanged(text); - } - - @Override - public void alphaFloatValueChanged(short unit, float value) throws DOMException { - alphaTextChanged(FloatValue.getCssText(unit, value)); - } - - /** - * Called when the RGBColor text has changed. - */ - @Override - public void rgbColorChanged(String text) throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR: - break; - - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - text += getValue().item(1).getCssText(); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR: - text = getValue().item(0).getCssText() + ' ' + text; - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - text = getValue().item(0).getCssText() + ' ' + text + ' ' + getValue().item(2).getCssText(); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - textChanged(text); - } - - /** - * Called when the RGBColor and the ICCColor text has changed. - */ - @Override - public void rgbColorICCColorChanged(String rgb, String icc) throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - textChanged(rgb + ' ' + icc); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - textChanged(getValue().item(0).getCssText() + ' ' + rgb + ' ' + icc); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the SVGColor has changed. - */ - @Override - public void colorChanged(short type, String rgb, String icc) throws DOMException { - switch (type) { - case SVG_PAINTTYPE_CURRENTCOLOR: - textChanged("currentcolor"); - break; - - case SVG_PAINTTYPE_RGBCOLOR: - textChanged(rgb); - break; - - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - textChanged(rgb + ' ' + icc); - break; - - default: - throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); - } - } - - /** - * Called when the ICC color profile has changed. - */ - @Override - public void colorProfileChanged(String cp) throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(" icc-color("); - sb.append(cp); - ICCColor iccc = (ICCColor) getValue().item(1); - for (int i = 0; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(')'); - textChanged(sb.toString()); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(' '); - sb.append(getValue().item(1).getCssText()); - sb.append(" icc-color("); - sb.append(cp); - iccc = (ICCColor) getValue().item(1); - for (int i = 0; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the ICC colors has changed. - */ - @Override - public void colorsCleared() throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(" icc-color("); - ICCColor iccc = (ICCColor) getValue().item(1); - sb.append(iccc.getColorProfile()); - sb.append(')'); - textChanged(sb.toString()); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(' '); - sb.append(getValue().item(1).getCssText()); - sb.append(" icc-color("); - iccc = (ICCColor) getValue().item(1); - sb.append(iccc.getColorProfile()); - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the ICC colors has been initialized. - */ - @Override - public void colorsInitialized(float f) throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(" icc-color("); - ICCColor iccc = (ICCColor) getValue().item(1); - sb.append(iccc.getColorProfile()); - sb.append(','); - sb.append(f); - sb.append(')'); - textChanged(sb.toString()); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(' '); - sb.append(getValue().item(1).getCssText()); - sb.append(" icc-color("); - iccc = (ICCColor) getValue().item(1); - sb.append(iccc.getColorProfile()); - sb.append(','); - sb.append(f); - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the ICC color has been inserted. - */ - @Override - public void colorInsertedBefore(float f, int idx) throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(" icc-color("); - ICCColor iccc = (ICCColor) getValue().item(1); - sb.append(iccc.getColorProfile()); - for (int i = 0; i < idx; i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(','); - sb.append(f); - for (int i = idx; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(')'); - textChanged(sb.toString()); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(' '); - sb.append(getValue().item(1).getCssText()); - sb.append(" icc-color("); - iccc = (ICCColor) getValue().item(1); - sb.append(iccc.getColorProfile()); - for (int i = 0; i < idx; i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(','); - sb.append(f); - for (int i = idx; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the ICC color has been replaced. - */ - @Override - public void colorReplaced(float f, int idx) throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(" icc-color("); - ICCColor iccc = (ICCColor) getValue().item(1); - sb.append(iccc.getColorProfile()); - for (int i = 0; i < idx; i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(','); - sb.append(f); - for (int i = idx + 1; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(')'); - textChanged(sb.toString()); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(' '); - sb.append(getValue().item(1).getCssText()); - sb.append(" icc-color("); - iccc = (ICCColor) getValue().item(1); - sb.append(iccc.getColorProfile()); - for (int i = 0; i < idx; i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(','); - sb.append(f); - for (int i = idx + 1; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the ICC color has been removed. - */ - @Override - public void colorRemoved(int idx) throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(" icc-color("); - ICCColor iccc = (ICCColor) getValue().item(1); - sb.append(iccc.getColorProfile()); - for (int i = 0; i < idx; i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - for (int i = idx + 1; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(')'); - textChanged(sb.toString()); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(' '); - sb.append(getValue().item(1).getCssText()); - sb.append(" icc-color("); - iccc = (ICCColor) getValue().item(1); - sb.append(iccc.getColorProfile()); - for (int i = 0; i < idx; i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - for (int i = idx + 1; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } - - /** - * Called when the ICC color has been append. - */ - @Override - public void colorAppend(float f) throws DOMException { - switch (getPaintType()) { - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - StringBuilder sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(" icc-color("); - ICCColor iccc = (ICCColor) getValue().item(1); - sb.append(iccc.getColorProfile()); - for (int i = 0; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(','); - sb.append(f); - sb.append(')'); - textChanged(sb.toString()); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - sb = new StringBuilder(getValue().item(0).getCssText()); - sb.append(' '); - sb.append(getValue().item(1).getCssText()); - sb.append(" icc-color("); - iccc = (ICCColor) getValue().item(1); - sb.append(iccc.getColorProfile()); - for (int i = 0; i < iccc.getLength(); i++) { - sb.append(','); - sb.append(iccc.getColor(i)); - } - sb.append(','); - sb.append(f); - sb.append(')'); - textChanged(sb.toString()); - break; - - default: - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - } + public abstract class AbstractModificationHandler extends AbstractValueModificationHandler + implements PaintModificationHandler { /** * Called when the URI has been modified. */ @Override - public void uriChanged(String uri) { - textChanged("url(" + uri + ") none"); + public void uriValueChanged(String uri) { + setPropertyText("url(" + uri + ") none"); } /** @@ -746,40 +231,40 @@ public void uriChanged(String uri) { @Override public void paintChanged(short type, String uri, String rgb, String icc) { switch (type) { - case SVG_PAINTTYPE_NONE: - textChanged("none"); + case SVGPaint.SVG_PAINTTYPE_NONE: + setPropertyText("none"); break; - case SVG_PAINTTYPE_CURRENTCOLOR: - textChanged("currentcolor"); + case SVGPaint.SVG_PAINTTYPE_CURRENTCOLOR: + setPropertyText("currentcolor"); break; - case SVG_PAINTTYPE_RGBCOLOR: - textChanged(rgb); + case SVGPaint.SVG_PAINTTYPE_RGBCOLOR: + setPropertyText(rgb); break; - case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: - textChanged(rgb + ' ' + icc); + case SVGPaint.SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: + setPropertyText(rgb + ' ' + icc); break; - case SVG_PAINTTYPE_URI: - textChanged("url(" + uri + ')'); + case SVGPaint.SVG_PAINTTYPE_URI: + setPropertyText("url(" + uri + ')'); break; - case SVG_PAINTTYPE_URI_NONE: - textChanged("url(" + uri + ") none"); + case SVGPaint.SVG_PAINTTYPE_URI_NONE: + setPropertyText("url(" + uri + ") none"); break; - case SVG_PAINTTYPE_URI_CURRENTCOLOR: - textChanged("url(" + uri + ") currentcolor"); + case SVGPaint.SVG_PAINTTYPE_URI_CURRENTCOLOR: + setPropertyText("url(" + uri + ") currentcolor"); break; - case SVG_PAINTTYPE_URI_RGBCOLOR: - textChanged("url(" + uri + ") " + rgb); + case SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR: + setPropertyText("url(" + uri + ") " + rgb); break; - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - textChanged("url(" + uri + ") " + rgb + ' ' + icc); + case SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: + setPropertyText("url(" + uri + ") " + rgb + ' ' + icc); } } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGStyleDeclaration.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGStyleDeclaration.java index 0ac061739..d942e17e5 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGStyleDeclaration.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGStyleDeclaration.java @@ -18,12 +18,12 @@ */ package io.sf.carte.echosvg.css.dom; +import org.w3c.css.om.CSSRule; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSValue; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.SVGCSSEngine; +import io.sf.carte.echosvg.css.engine.value.AbstractValueModificationHandler; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.css.engine.value.svg.SVGColorManager; import io.sf.carte.echosvg.css.engine.value.svg.SVGPaintManager; @@ -31,8 +31,10 @@ /** * This class represents a SVG style declaration. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class CSSOMSVGStyleDeclaration extends CSSOMStyleDeclaration { @@ -94,14 +96,14 @@ public class StyleDeclarationColorValue extends CSSOMSVGColor implements CSSOMSV public StyleDeclarationColorValue(String prop) { super(null); valueProvider = this; - setModificationHandler(new AbstractModificationHandler() { + setModificationHandler(new AbstractValueModificationHandler() { @Override protected Value getValue() { return StyleDeclarationColorValue.this.getValue(); } @Override - public void textChanged(String text) throws DOMException { + protected void setPropertyText(String text) throws DOMException { if (handler == null) { throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } @@ -148,7 +150,7 @@ protected Value getValue() { } @Override - public void textChanged(String text) throws DOMException { + protected void setPropertyText(String text) throws DOMException { if (handler == null) { throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGViewCSS.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGViewCSS.java index a7aca0835..e6d45f4e8 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGViewCSS.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMSVGViewCSS.java @@ -18,8 +18,8 @@ */ package io.sf.carte.echosvg.css.dom; +import org.w3c.css.om.CSSStyleDeclaration; import org.w3c.dom.Element; -import org.w3c.dom.css.CSSStyleDeclaration; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMStyleDeclaration.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMStyleDeclaration.java index 75d3f324e..1ed9456d5 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMStyleDeclaration.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMStyleDeclaration.java @@ -21,18 +21,20 @@ import java.util.HashMap; import java.util.Map; +import org.w3c.css.om.CSSRule; +import org.w3c.css.om.CSSStyleDeclaration; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSValue; +import io.sf.carte.echosvg.css.engine.value.AbstractValueModificationHandler; import io.sf.carte.echosvg.css.engine.value.Value; /** * This class represents a style declaration. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class CSSOMStyleDeclaration implements CSSStyleDeclaration { @@ -72,19 +74,11 @@ public void setModificationHandler(ModificationHandler h) { handler = h; } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSStyleDeclaration#getCssText()}. - */ @Override public String getCssText() { return valueProvider.getText(); } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSStyleDeclaration#setCssText(String)}. - */ @Override public void setCssText(String cssText) throws DOMException { if (handler == null) { @@ -95,10 +89,6 @@ public void setCssText(String cssText) throws DOMException { } } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSStyleDeclaration#getPropertyValue(String)}. - */ @Override public String getPropertyValue(String propertyName) { Value value = valueProvider.getValue(propertyName); @@ -108,12 +98,8 @@ public String getPropertyValue(String propertyName) { return value.getCssText(); } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSStyleDeclaration#getPropertyCSSValue(String)}. - */ @Override - public CSSValue getPropertyCSSValue(String propertyName) { + public CSSValue getCSSStyleValue(String propertyName) { Value value = valueProvider.getValue(propertyName); if (value == null) { return null; @@ -121,10 +107,6 @@ public CSSValue getPropertyCSSValue(String propertyName) { return getCSSValue(propertyName); } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSStyleDeclaration#removeProperty(String)}. - */ @Override public String removeProperty(String propertyName) throws DOMException { String result = getPropertyValue(propertyName); @@ -141,19 +123,11 @@ public String removeProperty(String propertyName) throws DOMException { return result; } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSStyleDeclaration#getPropertyPriority(String)}. - */ @Override public String getPropertyPriority(String propertyName) { return (valueProvider.isImportant(propertyName)) ? "important" : ""; } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSStyleDeclaration#setProperty(String,String,String)}. - */ @Override public void setProperty(String propertyName, String value, String prio) throws DOMException { if (handler == null) { @@ -163,10 +137,6 @@ public void setProperty(String propertyName, String value, String prio) throws D } } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSStyleDeclaration#getLength()}. - */ @Override public int getLength() { return valueProvider.getLength(); @@ -180,10 +150,6 @@ public String item(int index) { return valueProvider.item(index); } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSStyleDeclaration#getParentRule()}. - */ @Override public CSSRule getParentRule() { return parentRule; @@ -247,12 +213,12 @@ public interface ValueProvider { } /** - * To manage the modifications on a CSS value. + * To manage the modifications on a CSS style declaration. */ public interface ModificationHandler { /** - * Called when the value text has changed. + * Called when the declaration text has changed. */ void textChanged(String text) throws DOMException; @@ -284,14 +250,14 @@ public class StyleDeclarationValue extends CSSOMValue implements CSSOMValue.Valu public StyleDeclarationValue(String prop) { super(null); this.valueProvider = this; - this.setModificationHandler(new AbstractModificationHandler() { + this.setModificationHandler(new AbstractValueModificationHandler() { @Override protected Value getValue() { return StyleDeclarationValue.this.getValue(); } @Override - public void textChanged(String text) throws DOMException { + protected void setPropertyText(String text) throws DOMException { if (values == null || StyleDeclarationValue.this.handler == null) { throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMValue.java index 2b111d58b..1c089c02f 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMValue.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMValue.java @@ -18,30 +18,25 @@ */ package io.sf.carte.echosvg.css.dom; +import org.w3c.css.om.typed.CSSCounterValue; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.CSSValueList; -import org.w3c.dom.css.Counter; -import org.w3c.dom.css.RGBColor; -import org.w3c.dom.css.Rect; -import io.sf.carte.echosvg.css.engine.value.FloatValue; -import io.sf.carte.echosvg.css.engine.value.ListValue; -import io.sf.carte.echosvg.css.engine.value.RGBColorValue; -import io.sf.carte.echosvg.css.engine.value.StringValue; +import io.sf.carte.echosvg.css.engine.value.ColorValue; +import io.sf.carte.echosvg.css.engine.value.RectValue; import io.sf.carte.echosvg.css.engine.value.Value; +import io.sf.carte.echosvg.css.engine.value.ValueModificationHandler; /** - * This class implements the {@link org.w3c.dom.css.CSSValue}, - * {@link org.w3c.dom.css.CSSPrimitiveValue}, - * {@link org.w3c.dom.css.CSSValueList} interfaces. - * - * @author Stephane Hillion - * @author For later modifications, see Git history. + * This class implements the {@link org.w3c.css.om.typed.CSSStyleValue} + * interface. + *

+ * Original author Stephane Hillion + *

+ * * @version $Id$ */ -public class CSSOMValue implements CSSPrimitiveValue, CSSValueList, Counter, Rect, RGBColor { +public class CSSOMValue implements Value { /** * The associated value. @@ -51,52 +46,7 @@ public class CSSOMValue implements CSSPrimitiveValue, CSSValueList, Counter, Rec /** * The modifications handler. */ - protected ModificationHandler handler; - - /** - * The left component, if this value is a Rect. - */ - protected LeftComponent leftComponent; - - /** - * The right component, if this value is a Rect. - */ - protected RightComponent rightComponent; - - /** - * The bottom component, if this value is a Rect. - */ - protected BottomComponent bottomComponent; - - /** - * The top component, if this value is a Rect. - */ - protected TopComponent topComponent; - - /** - * The red component, if this value is a RGBColor. - */ - protected RedComponent redComponent; - - /** - * The green component, if this value is a RGBColor. - */ - protected GreenComponent greenComponent; - - /** - * The blue component, if this value is a RGBColor. - */ - protected BlueComponent blueComponent; - - /** - * The alpha component, if this value is a RGBColor. - */ - protected AlphaComponent alphaComponent; - - /** - * The list items. - */ - protected CSSValue[] items; + protected ValueModificationHandler handler; /** * Creates a new CSSOMValue. @@ -108,7 +58,7 @@ public CSSOMValue(ValueProvider vp) { /** * Sets the modification handler of this value. */ - public void setModificationHandler(ModificationHandler h) { + public void setModificationHandler(ValueModificationHandler h) { handler = h; } @@ -120,55 +70,38 @@ public String getCssText() { return valueProvider.getValue().getCssText(); } - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ @Override public void setCssText(String cssText) throws DOMException { if (handler == null) { throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } else { - handler.textChanged(cssText); + valueProvider.getValue().setCssText(cssText); + handler.valueChanged(valueProvider.getValue()); } } - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#getCssValueType()}. - */ @Override - public short getCssValueType() { + public CssType getCssValueType() { return valueProvider.getValue().getCssValueType(); } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getPrimitiveType()}. - */ @Override - public short getPrimitiveType() { + public Type getPrimitiveType() { return valueProvider.getValue().getPrimitiveType(); } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { + public void setFloatValue(float floatValue) throws DOMException { if (handler == null) { throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); } else { - handler.floatValueChanged(unitType, floatValue); + handler.valueChanged(this); } } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getFloatValue(short)}. - */ @Override - public float getFloatValue(short unitType) throws DOMException { - return convertFloatValue(unitType, valueProvider.getValue()); + public float getFloatValue() throws DOMException { + return valueProvider.getValue().getFloatValue(); } /** @@ -176,39 +109,39 @@ public float getFloatValue(short unitType) throws DOMException { */ public static float convertFloatValue(short unitType, Value value) { switch (unitType) { - case CSSPrimitiveValue.CSS_NUMBER: - case CSSPrimitiveValue.CSS_PERCENTAGE: - case CSSPrimitiveValue.CSS_EMS: - case CSSPrimitiveValue.CSS_EXS: - case CSSPrimitiveValue.CSS_DIMENSION: - case CSSPrimitiveValue.CSS_PX: - if (value.getPrimitiveType() == unitType) { + case CSSUnit.CSS_NUMBER: + case CSSUnit.CSS_PERCENTAGE: + case CSSUnit.CSS_EM: + case CSSUnit.CSS_EX: + case CSSUnit.CSS_OTHER: + case CSSUnit.CSS_PX: + if (value.getCSSUnit() == unitType) { return value.getFloatValue(); } break; - case CSSPrimitiveValue.CSS_CM: + case CSSUnit.CSS_CM: return toCentimeters(value); - case CSSPrimitiveValue.CSS_MM: + case CSSUnit.CSS_MM: return toMillimeters(value); - case CSSPrimitiveValue.CSS_IN: + case CSSUnit.CSS_IN: return toInches(value); - case CSSPrimitiveValue.CSS_PT: + case CSSUnit.CSS_PT: return toPoints(value); - case CSSPrimitiveValue.CSS_PC: + case CSSUnit.CSS_PC: return toPicas(value); - case CSSPrimitiveValue.CSS_DEG: + case CSSUnit.CSS_DEG: return toDegrees(value); - case CSSPrimitiveValue.CSS_RAD: + case CSSUnit.CSS_RAD: return toRadians(value); - case CSSPrimitiveValue.CSS_GRAD: + case CSSUnit.CSS_GRAD: return toGradians(value); - case CSSPrimitiveValue.CSS_MS: + case CSSUnit.CSS_MS: return toMilliseconds(value); - case CSSPrimitiveValue.CSS_S: + case CSSUnit.CSS_S: return toSeconds(value); - case CSSPrimitiveValue.CSS_HZ: + case CSSUnit.CSS_HZ: return toHertz(value); - case CSSPrimitiveValue.CSS_KHZ: + case CSSUnit.CSS_KHZ: return tokHertz(value); } throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); @@ -218,16 +151,16 @@ public static float convertFloatValue(short unitType, Value value) { * Converts the current value into centimeters. */ protected static float toCentimeters(Value value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_CM: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_CM: return value.getFloatValue(); - case CSSPrimitiveValue.CSS_MM: + case CSSUnit.CSS_MM: return (value.getFloatValue() / 10); - case CSSPrimitiveValue.CSS_IN: + case CSSUnit.CSS_IN: return (value.getFloatValue() * 2.54f); - case CSSPrimitiveValue.CSS_PT: + case CSSUnit.CSS_PT: return (value.getFloatValue() * 2.54f / 72); - case CSSPrimitiveValue.CSS_PC: + case CSSUnit.CSS_PC: return (value.getFloatValue() * 2.54f / 6); default: throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); @@ -238,16 +171,16 @@ protected static float toCentimeters(Value value) { * Converts the current value into inches. */ protected static float toInches(Value value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_CM: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_CM: return (value.getFloatValue() / 2.54f); - case CSSPrimitiveValue.CSS_MM: + case CSSUnit.CSS_MM: return (value.getFloatValue() / 25.4f); - case CSSPrimitiveValue.CSS_IN: + case CSSUnit.CSS_IN: return value.getFloatValue(); - case CSSPrimitiveValue.CSS_PT: + case CSSUnit.CSS_PT: return (value.getFloatValue() / 72); - case CSSPrimitiveValue.CSS_PC: + case CSSUnit.CSS_PC: return (value.getFloatValue() / 6); default: throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); @@ -258,16 +191,16 @@ protected static float toInches(Value value) { * Converts the current value into millimeters. */ protected static float toMillimeters(Value value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_CM: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_CM: return (value.getFloatValue() * 10); - case CSSPrimitiveValue.CSS_MM: + case CSSUnit.CSS_MM: return value.getFloatValue(); - case CSSPrimitiveValue.CSS_IN: + case CSSUnit.CSS_IN: return (value.getFloatValue() * 25.4f); - case CSSPrimitiveValue.CSS_PT: + case CSSUnit.CSS_PT: return (value.getFloatValue() * 25.4f / 72); - case CSSPrimitiveValue.CSS_PC: + case CSSUnit.CSS_PC: return (value.getFloatValue() * 25.4f / 6); default: throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); @@ -278,16 +211,16 @@ protected static float toMillimeters(Value value) { * Converts the current value into points. */ protected static float toPoints(Value value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_CM: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_CM: return (value.getFloatValue() * 72 / 2.54f); - case CSSPrimitiveValue.CSS_MM: + case CSSUnit.CSS_MM: return (value.getFloatValue() * 72 / 25.4f); - case CSSPrimitiveValue.CSS_IN: + case CSSUnit.CSS_IN: return (value.getFloatValue() * 72); - case CSSPrimitiveValue.CSS_PT: + case CSSUnit.CSS_PT: return value.getFloatValue(); - case CSSPrimitiveValue.CSS_PC: + case CSSUnit.CSS_PC: return (value.getFloatValue() * 12); default: throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); @@ -298,16 +231,16 @@ protected static float toPoints(Value value) { * Converts the current value into picas. */ protected static float toPicas(Value value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_CM: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_CM: return (value.getFloatValue() * 6 / 2.54f); - case CSSPrimitiveValue.CSS_MM: + case CSSUnit.CSS_MM: return (value.getFloatValue() * 6 / 25.4f); - case CSSPrimitiveValue.CSS_IN: + case CSSUnit.CSS_IN: return (value.getFloatValue() * 6); - case CSSPrimitiveValue.CSS_PT: + case CSSUnit.CSS_PT: return (value.getFloatValue() / 12); - case CSSPrimitiveValue.CSS_PC: + case CSSUnit.CSS_PC: return value.getFloatValue(); default: throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); @@ -318,12 +251,12 @@ protected static float toPicas(Value value) { * Converts the current value into degrees. */ protected static float toDegrees(Value value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_DEG: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_DEG: return value.getFloatValue(); - case CSSPrimitiveValue.CSS_RAD: + case CSSUnit.CSS_RAD: return (float) Math.toDegrees(value.getFloatValue()); - case CSSPrimitiveValue.CSS_GRAD: + case CSSUnit.CSS_GRAD: return (value.getFloatValue() * 9 / 5); default: throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); @@ -334,12 +267,12 @@ protected static float toDegrees(Value value) { * Converts the current value into radians. */ protected static float toRadians(Value value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_DEG: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_DEG: return (value.getFloatValue() * 5 / 9); // todo ?? - case CSSPrimitiveValue.CSS_RAD: + case CSSUnit.CSS_RAD: return value.getFloatValue(); - case CSSPrimitiveValue.CSS_GRAD: + case CSSUnit.CSS_GRAD: return (float) (value.getFloatValue() * 100 / Math.PI); default: throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); @@ -350,12 +283,12 @@ protected static float toRadians(Value value) { * Converts the current value into gradians. */ protected static float toGradians(Value value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_DEG: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_DEG: return (float) (value.getFloatValue() * Math.PI / 180); // todo ???? - case CSSPrimitiveValue.CSS_RAD: + case CSSUnit.CSS_RAD: return (float) (value.getFloatValue() * Math.PI / 100); - case CSSPrimitiveValue.CSS_GRAD: + case CSSUnit.CSS_GRAD: return value.getFloatValue(); default: throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); @@ -366,10 +299,10 @@ protected static float toGradians(Value value) { * Converts the current value into milliseconds. */ protected static float toMilliseconds(Value value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_MS: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_MS: return value.getFloatValue(); - case CSSPrimitiveValue.CSS_S: + case CSSUnit.CSS_S: return (value.getFloatValue() * 1000); default: throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); @@ -380,10 +313,10 @@ protected static float toMilliseconds(Value value) { * Converts the current value into seconds. */ protected static float toSeconds(Value value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_MS: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_MS: return (value.getFloatValue() / 1000); - case CSSPrimitiveValue.CSS_S: + case CSSUnit.CSS_S: return value.getFloatValue(); default: throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); @@ -394,10 +327,10 @@ protected static float toSeconds(Value value) { * Converts the current value into Hertz. */ protected static float toHertz(Value value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_HZ: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_HZ: return value.getFloatValue(); - case CSSPrimitiveValue.CSS_KHZ: + case CSSUnit.CSS_KHZ: return (value.getFloatValue() / 1000); default: throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); @@ -408,94 +341,72 @@ protected static float toHertz(Value value) { * Converts the current value into kHertz. */ protected static float tokHertz(Value value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_HZ: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_HZ: return (value.getFloatValue() * 1000); - case CSSPrimitiveValue.CSS_KHZ: + case CSSUnit.CSS_KHZ: return value.getFloatValue(); default: throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); } } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setStringValue(short,String)}. - */ @Override - public void setStringValue(short stringType, String stringValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - handler.stringValueChanged(stringType, stringValue); - } + public String getIdentifierValue() throws DOMException { + return valueProvider.getValue().getIdentifierValue(); + } + + @Override + public short getCSSUnit() { + return valueProvider.getValue().getCSSUnit(); } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getStringValue()}. - */ @Override public String getStringValue() throws DOMException { return valueProvider.getValue().getStringValue(); } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getCounterValue()}. - */ @Override - public Counter getCounterValue() throws DOMException { - return this; + public ValueModificationHandler getModificationHandler() { + return handler; } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getRectValue()}. - */ @Override - public Rect getRectValue() throws DOMException { - return this; + public String getURIValue() throws DOMException { + return valueProvider.getValue().getIdentifierValue(); + } + + @Override + public CSSCounterValue getCounterValue() throws DOMException { + return valueProvider.getValue().getCounterValue(); + } + + @Override + public RectValue getRectValue() throws DOMException { + return valueProvider.getValue().getRectValue(); } - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getRGBColorValue()}. - */ @Override - public RGBColor getRGBColorValue() throws DOMException { - return this; + public ColorValue getColorValue() throws DOMException { + return valueProvider.getValue().getColorValue(); } // CSSValueList /////////////////////////////////////////////////////// - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValueList#getLength()}. - */ @Override public int getLength() { return valueProvider.getValue().getLength(); } - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValueList#item(int)}. - */ @Override - public CSSValue item(int index) { + public Value item(int index) { int len = valueProvider.getValue().getLength(); if (index < 0 || index >= len) { return null; } - if (items == null) { - items = new CSSValue[valueProvider.getValue().getLength()]; - } else if (items.length < len) { - CSSValue[] nitems = new CSSValue[len]; - System.arraycopy(items, 0, nitems, 0, items.length); - items = nitems; - } - CSSValue result = items[index]; - if (result == null) { - items[index] = result = new ListComponent(index); + Value result = valueProvider.getValue().item(index); + if (result.getModificationHandler() == null) { + result.setModificationHandler(handler); } return result; } @@ -507,123 +418,11 @@ public CSSValue item(int index) { */ @Override public String getIdentifier() { - return valueProvider.getValue().getIdentifier(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.Counter#getListStyle()}. - */ - @Override - public String getListStyle() { - return valueProvider.getValue().getListStyle(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.Counter#getSeparator()}. - */ - @Override - public String getSeparator() { - return valueProvider.getValue().getSeparator(); - } - - // Rect /////////////////////////////////////////////////////////////// - - /** - * DOM: Implements {@link org.w3c.dom.css.Rect#getTop()}. - */ - @Override - public CSSPrimitiveValue getTop() { - valueProvider.getValue().getTop(); - if (topComponent == null) { - topComponent = new TopComponent(); - } - return topComponent; - } - - /** - * DOM: Implements {@link org.w3c.dom.css.Rect#getRight()}. - */ - @Override - public CSSPrimitiveValue getRight() { - valueProvider.getValue().getRight(); - if (rightComponent == null) { - rightComponent = new RightComponent(); - } - return rightComponent; - } - - /** - * DOM: Implements {@link org.w3c.dom.css.Rect#getBottom()}. - */ - @Override - public CSSPrimitiveValue getBottom() { - valueProvider.getValue().getBottom(); - if (bottomComponent == null) { - bottomComponent = new BottomComponent(); - } - return bottomComponent; - } - - /** - * DOM: Implements {@link org.w3c.dom.css.Rect#getLeft()}. - */ - @Override - public CSSPrimitiveValue getLeft() { - valueProvider.getValue().getLeft(); - if (leftComponent == null) { - leftComponent = new LeftComponent(); - } - return leftComponent; - } - - // RGBColor /////////////////////////////////////////////////// - - /** - * DOM: Implements {@link org.w3c.dom.css.RGBColor#getRed()}. - */ - @Override - public CSSPrimitiveValue getRed() { - valueProvider.getValue().getRed(); - if (redComponent == null) { - redComponent = new RedComponent(); - } - return redComponent; - } - - /** - * DOM: Implements {@link org.w3c.dom.css.RGBColor#getGreen()}. - */ - @Override - public CSSPrimitiveValue getGreen() { - valueProvider.getValue().getGreen(); - if (greenComponent == null) { - greenComponent = new GreenComponent(); - } - return greenComponent; - } - - /** - * DOM: Implements {@link org.w3c.dom.css.RGBColor#getBlue()}. - */ - @Override - public CSSPrimitiveValue getBlue() { - valueProvider.getValue().getBlue(); - if (blueComponent == null) { - blueComponent = new BlueComponent(); - } - return blueComponent; - } - - public CSSPrimitiveValue getAlpha() { - valueProvider.getValue().getAlpha(); - if (alphaComponent == null) { - alphaComponent = new AlphaComponent(); - } - return alphaComponent; + return valueProvider.getValue().getIdentifierValue(); } /** - * To provides the actual value. + * To provide the actual value. */ public interface ValueProvider { @@ -635,888 +434,62 @@ public interface ValueProvider { } /** - * To manage the modifications on a CSS value. - */ - public interface ModificationHandler { - - /** - * Called when the value text has changed. - */ - void textChanged(String text) throws DOMException; - - /** - * Called when the float value has changed. - */ - void floatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the string value has changed. - */ - void stringValueChanged(short type, String value) throws DOMException; - - /** - * Called when the left value text has changed. - */ - void leftTextChanged(String text) throws DOMException; - - /** - * Called when the left float value has changed. - */ - void leftFloatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the top value text has changed. - */ - void topTextChanged(String text) throws DOMException; - - /** - * Called when the top float value has changed. - */ - void topFloatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the right value text has changed. - */ - void rightTextChanged(String text) throws DOMException; - - /** - * Called when the right float value has changed. - */ - void rightFloatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the bottom value text has changed. - */ - void bottomTextChanged(String text) throws DOMException; - - /** - * Called when the bottom float value has changed. - */ - void bottomFloatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the red value text has changed. - */ - void redTextChanged(String text) throws DOMException; - - /** - * Called when the red float value has changed. - */ - void redFloatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the green value text has changed. - */ - void greenTextChanged(String text) throws DOMException; - - /** - * Called when the green float value has changed. - */ - void greenFloatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the blue value text has changed. - */ - void blueTextChanged(String text) throws DOMException; - - /** - * Called when the blue float value has changed. - */ - void blueFloatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the alpha value text has changed. - */ - void alphaTextChanged(String text) throws DOMException; - - /** - * Called when the alpha float value has changed. - */ - void alphaFloatValueChanged(short unit, float value) throws DOMException; - - /** - * Called when the list value text has changed. - */ - void listTextChanged(int idx, String text) throws DOMException; - - /** - * Called when the list float value has changed. - */ - void listFloatValueChanged(int idx, short unit, float value) throws DOMException; - - /** - * Called when the list string value has changed. - */ - void listStringValueChanged(int idx, short unit, String value) throws DOMException; - - } - - /** - * This class provides an abstract implementation of a ModificationHandler. + * To store a component. */ - public abstract static class AbstractModificationHandler implements ModificationHandler { + protected abstract class AbstractComponent implements Value { /** - * Returns the associated value. + * The returns the actual value of this component. */ protected abstract Value getValue(); - /** - * Called when the float value has changed. - */ - @Override - public void floatValueChanged(short unit, float value) throws DOMException { - textChanged(FloatValue.getCssText(unit, value)); - } - - /** - * Called when the string value has changed. - */ - @Override - public void stringValueChanged(short type, String value) throws DOMException { - textChanged(StringValue.getCssText(type, value)); - } - - /** - * Called when the left value text has changed. - */ - @Override - public void leftTextChanged(String text) throws DOMException { - final Value val = getValue(); - text = "rect(" + val.getTop().getCssText() + ", " + val.getRight().getCssText() + ", " - + val.getBottom().getCssText() + ", " + text + ')'; - textChanged(text); - } - - /** - * Called when the left float value has changed. - */ - @Override - public void leftFloatValueChanged(short unit, float value) throws DOMException { - final Value val = getValue(); - String text = "rect(" + val.getTop().getCssText() + ", " + val.getRight().getCssText() + ", " - + val.getBottom().getCssText() + ", " + FloatValue.getCssText(unit, value) + ')'; - textChanged(text); - } - - /** - * Called when the top value text has changed. - */ - @Override - public void topTextChanged(String text) throws DOMException { - final Value val = getValue(); - text = "rect(" + text + ", " + val.getRight().getCssText() + ", " + val.getBottom().getCssText() + ", " - + val.getLeft().getCssText() + ')'; - textChanged(text); - } - - /** - * Called when the top float value has changed. - */ - @Override - public void topFloatValueChanged(short unit, float value) throws DOMException { - final Value val = getValue(); - String text = "rect(" + FloatValue.getCssText(unit, value) + ", " + val.getRight().getCssText() + ", " - + val.getBottom().getCssText() + ", " + val.getLeft().getCssText() + ')'; - textChanged(text); - } - - /** - * Called when the right value text has changed. - */ - @Override - public void rightTextChanged(String text) throws DOMException { - final Value val = getValue(); - text = "rect(" + val.getTop().getCssText() + ", " + text + ", " + val.getBottom().getCssText() + ", " - + val.getLeft().getCssText() + ')'; - textChanged(text); - } - - /** - * Called when the right float value has changed. - */ @Override - public void rightFloatValueChanged(short unit, float value) throws DOMException { - final Value val = getValue(); - String text = "rect(" + val.getTop().getCssText() + ", " + FloatValue.getCssText(unit, value) + ", " - + val.getBottom().getCssText() + ", " + val.getLeft().getCssText() + ')'; - textChanged(text); + public String getCssText() { + return valueProvider.getValue().getCssText(); } - /** - * Called when the bottom value text has changed. - */ @Override - public void bottomTextChanged(String text) throws DOMException { - final Value val = getValue(); - text = "rect(" + val.getTop().getCssText() + ", " + val.getRight().getCssText() + ", " + text + ", " - + val.getLeft().getCssText() + ')'; - textChanged(text); + public CssType getCssValueType() { + return valueProvider.getValue().getCssValueType(); } - /** - * Called when the bottom float value has changed. - */ @Override - public void bottomFloatValueChanged(short unit, float value) throws DOMException { - final Value val = getValue(); - String text = "rect(" + val.getTop().getCssText() + ", " + val.getRight().getCssText() + ", " - + FloatValue.getCssText(unit, value) + ", " + val.getLeft().getCssText() + ')'; - textChanged(text); + public Type getPrimitiveType() { + return valueProvider.getValue().getPrimitiveType(); } - /** - * Called when the red value text has changed. - */ @Override - public void redTextChanged(String text) throws DOMException { - final Value val = getValue(); - text = RGBColorValue.toString(text, val.getGreen().getCssText(), val.getBlue().getCssText(), - val.getAlpha().getCssText()); - textChanged(text); + public float getFloatValue() throws DOMException { + return valueProvider.getValue().getFloatValue(); } - /** - * Called when the red float value has changed. - */ @Override - public void redFloatValueChanged(short unit, float value) throws DOMException { - redTextChanged(FloatValue.getCssText(unit, value)); + public String getStringValue() throws DOMException { + return valueProvider.getValue().getStringValue(); } - /** - * Called when the green value text has changed. - */ @Override - public void greenTextChanged(String text) throws DOMException { - final Value val = getValue(); - text = RGBColorValue.toString(val.getRed().getCssText(), text, val.getBlue().getCssText(), - val.getAlpha().getCssText()); - textChanged(text); + public CSSCounterValue getCounterValue() throws DOMException { + throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); } - /** - * Called when the green float value has changed. - */ @Override - public void greenFloatValueChanged(short unit, float value) throws DOMException { - greenTextChanged(FloatValue.getCssText(unit, value)); + public RectValue getRectValue() throws DOMException { + throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); } - /** - * Called when the blue value text has changed. - */ @Override - public void blueTextChanged(String text) throws DOMException { - final Value val = getValue(); - text = RGBColorValue.toString(val.getRed().getCssText(), val.getGreen().getCssText(), text, - val.getAlpha().getCssText()); - textChanged(text); + public ColorValue getColorValue() throws DOMException { + throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); } - /** - * Called when the blue float value has changed. - */ - @Override - public void blueFloatValueChanged(short unit, float value) throws DOMException { - blueTextChanged(FloatValue.getCssText(unit, value)); - } + // CSSStyleValueList /////////////////////////////////////////////////// @Override - public void alphaTextChanged(String text) throws DOMException { - final Value val = getValue(); - text = RGBColorValue.toString(val.getRed().getCssText(), val.getGreen().getCssText(), - val.getBlue().getCssText(), text); - textChanged(text); - } - - @Override - public void alphaFloatValueChanged(short unit, float value) throws DOMException { - alphaTextChanged(FloatValue.getCssText(unit, value)); - } - - /** - * Called when the list value text has changed. - */ - @Override - public void listTextChanged(int idx, String text) throws DOMException { - ListValue lv = (ListValue) getValue(); - int len = lv.getLength(); - StringBuilder sb = new StringBuilder(len * 8); - for (int i = 0; i < idx; i++) { - sb.append(lv.item(i).getCssText()); - sb.append(lv.getSeparatorChar()); - } - sb.append(text); - for (int i = idx + 1; i < len; i++) { - sb.append(lv.getSeparatorChar()); - sb.append(lv.item(i).getCssText()); - } - text = sb.toString(); - textChanged(text); - } - - /** - * Called when the list float value has changed. - */ - @Override - public void listFloatValueChanged(int idx, short unit, float value) throws DOMException { - ListValue lv = (ListValue) getValue(); - int len = lv.getLength(); - StringBuilder sb = new StringBuilder(len * 8); - for (int i = 0; i < idx; i++) { - sb.append(lv.item(i).getCssText()); - sb.append(lv.getSeparatorChar()); - } - sb.append(FloatValue.getCssText(unit, value)); - for (int i = idx + 1; i < len; i++) { - sb.append(lv.getSeparatorChar()); - sb.append(lv.item(i).getCssText()); - } - textChanged(sb.toString()); - } - - /** - * Called when the list string value has changed. - */ - @Override - public void listStringValueChanged(int idx, short unit, String value) throws DOMException { - ListValue lv = (ListValue) getValue(); - int len = lv.getLength(); - StringBuilder sb = new StringBuilder(len * 8); - for (int i = 0; i < idx; i++) { - sb.append(lv.item(i).getCssText()); - sb.append(lv.getSeparatorChar()); - } - sb.append(StringValue.getCssText(unit, value)); - for (int i = idx + 1; i < len; i++) { - sb.append(lv.getSeparatorChar()); - sb.append(lv.item(i).getCssText()); - } - textChanged(sb.toString()); - } - - } - - /** - * To store a component. - */ - protected abstract class AbstractComponent implements CSSPrimitiveValue { - - /** - * The returns the actual value of this component. - */ - protected abstract Value getValue(); - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#getCssText()}. - */ - @Override - public String getCssText() { - return getValue().getCssText(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#getCssValueType()}. - */ - @Override - public short getCssValueType() { - return getValue().getCssValueType(); - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getPrimitiveType()}. - */ - @Override - public short getPrimitiveType() { - return getValue().getPrimitiveType(); - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getFloatValue(short)}. - */ - @Override - public float getFloatValue(short unitType) throws DOMException { - return convertFloatValue(unitType, getValue()); - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getStringValue()}. - */ - @Override - public String getStringValue() throws DOMException { - return valueProvider.getValue().getStringValue(); - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getCounterValue()}. - */ - @Override - public Counter getCounterValue() throws DOMException { - throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getRectValue()}. - */ - @Override - public Rect getRectValue() throws DOMException { - throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#getRGBColorValue()}. - */ - @Override - public RGBColor getRGBColorValue() throws DOMException { - throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); - } - - // CSSValueList /////////////////////////////////////////////////////// - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValueList#getLength()}. - */ public int getLength() { throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); } - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValueList#item(int)}. - */ - public CSSValue item(int index) { - throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); - } - - } - - /** - * To store a Float component. - */ - protected abstract class FloatComponent extends AbstractComponent { - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setStringValue(short,String)}. - */ - @Override - public void setStringValue(short stringType, String stringValue) throws DOMException { - throw new DOMException(DOMException.INVALID_ACCESS_ERR, ""); - } - - } - - /** - * To represents a left component. - */ - protected class LeftComponent extends FloatComponent { - - /** - * The returns the actual value of this component. - */ - @Override - protected Value getValue() { - return valueProvider.getValue().getLeft(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ - @Override - public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.leftTextChanged(cssText); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ - @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.leftFloatValueChanged(unitType, floatValue); - } - } - - } - - /** - * To represents a top component. - */ - protected class TopComponent extends FloatComponent { - - /** - * The returns the actual value of this component. - */ - @Override - protected Value getValue() { - return valueProvider.getValue().getTop(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ - @Override - public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.topTextChanged(cssText); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ - @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.topFloatValueChanged(unitType, floatValue); - } - } - - } - - /** - * To represents a right component. - */ - protected class RightComponent extends FloatComponent { - - /** - * The returns the actual value of this component. - */ - @Override - protected Value getValue() { - return valueProvider.getValue().getRight(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ - @Override - public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.rightTextChanged(cssText); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ - @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.rightFloatValueChanged(unitType, floatValue); - } - } - - } - - /** - * To represents a bottom component. - */ - protected class BottomComponent extends FloatComponent { - - /** - * The returns the actual value of this component. - */ - @Override - protected Value getValue() { - return valueProvider.getValue().getBottom(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ - @Override - public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.bottomTextChanged(cssText); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ - @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.bottomFloatValueChanged(unitType, floatValue); - } - } - - } - - /** - * To represents a red component. - */ - protected class RedComponent extends FloatComponent { - - /** - * The returns the actual value of this component. - */ - @Override - protected Value getValue() { - return valueProvider.getValue().getRed(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ - @Override - public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.redTextChanged(cssText); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ - @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.redFloatValueChanged(unitType, floatValue); - } - } - - } - - /** - * To represents a green component. - */ - protected class GreenComponent extends FloatComponent { - - /** - * The returns the actual value of this component. - */ - @Override - protected Value getValue() { - return valueProvider.getValue().getGreen(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ - @Override - public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.greenTextChanged(cssText); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ - @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.greenFloatValueChanged(unitType, floatValue); - } - } - - } - - /** - * To represents a blue component. - */ - protected class BlueComponent extends FloatComponent { - - /** - * The returns the actual value of this component. - */ - @Override - protected Value getValue() { - return valueProvider.getValue().getBlue(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ - @Override - public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.blueTextChanged(cssText); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ - @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.blueFloatValueChanged(unitType, floatValue); - } - } - - } - - /** - * To represents an alpha component. - */ - protected class AlphaComponent extends FloatComponent { - - /** - * The returns the actual value of this component. - */ - @Override - protected Value getValue() { - return valueProvider.getValue().getAlpha(); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ - @Override - public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.alphaTextChanged(cssText); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ - @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.alphaFloatValueChanged(unitType, floatValue); - } - } - - } - - /** - * To represents a List component. - */ - protected class ListComponent extends AbstractComponent { - - /** - * The index of this component. - */ - protected int index; - - /** - * Creates a new ListComponent. - */ - public ListComponent(int idx) { - index = idx; - } - - /** - * The returns the actual value of this component. - */ - @Override - protected Value getValue() { - if (index >= valueProvider.getValue().getLength()) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } - return valueProvider.getValue().item(index); - } - - /** - * DOM: Implements {@link org.w3c.dom.css.CSSValue#setCssText(String)}. - */ - @Override - public void setCssText(String cssText) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.listTextChanged(index, cssText); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}. - */ - @Override - public void setFloatValue(short unitType, float floatValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.listFloatValueChanged(index, unitType, floatValue); - } - } - - /** - * DOM: Implements - * {@link org.w3c.dom.css.CSSPrimitiveValue#setStringValue(short,String)}. - */ - @Override - public void setStringValue(short stringType, String stringValue) throws DOMException { - if (handler == null) { - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } else { - getValue(); - handler.listStringValueChanged(index, stringType, stringValue); - } - } - } } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMViewCSS.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMViewCSS.java index a7a397134..aa8a050ab 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMViewCSS.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSOMViewCSS.java @@ -19,9 +19,9 @@ package io.sf.carte.echosvg.css.dom; +import org.w3c.css.om.CSSStyleDeclaration; import org.w3c.dom.Element; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.ViewCSS; +import org.w3c.dom.view.ViewCSS; import org.w3c.dom.views.DocumentView; import io.sf.carte.echosvg.css.engine.CSSEngine; diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSValue.java new file mode 100644 index 000000000..fd021a246 --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/dom/CSSValue.java @@ -0,0 +1,358 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.dom; + +import org.w3c.css.om.typed.CSSKeywordValue; +import org.w3c.css.om.typed.CSSStringValue; +import org.w3c.css.om.typed.CSSStyleValue; +import org.w3c.dom.DOMException; + +import org.w3c.css.om.unit.CSSUnit; +import io.sf.carte.doc.style.css.property.KeywordValue; +import io.sf.carte.echosvg.css.engine.value.ListValue; +import io.sf.carte.echosvg.css.engine.value.NumericValue; +import io.sf.carte.echosvg.css.engine.value.StringValue; + +/** + * A gateway value, useful in the transition to Typed OM. + * + * @author See Git history. + * @version $Id$ + */ +public interface CSSValue extends CSSStyleValue { + + /** + * The main categories of values. + */ + enum CssType { + + /** + * A CSS-wide keyword like {@code inherit}. + */ + KEYWORD, + + /** + *

+ * A vehicle towards a final value, of a CSS type that cannot be anticipated. + *

+ *

+ * Example: {@code var()} or {@code attr()}. + *

+ *

+ * (note that {@code attr()} has two components, a main one whose type + * could be anticipated, and a fallback that could be of a different type). + *

+ */ + PROXY, + + /** + * A typed primitive value, includes numbers and identifiers. + */ + TYPED, + + /** + * A list of values. + *

+ * You can cast to {@link ListValue}. + *

+ */ + LIST, + + /** + * A shorthand property. + */ + SHORTHAND + } + + /** + * The type of value. For keywords, it is the keyword. + */ + enum Type { + /** + * Unknown type, probably a system default or a compat value. + */ + UNKNOWN, + + /** + * {@code inherit} keyword. + */ + INHERIT, + + /** + * {@code initial} keyword. + */ + INITIAL, + + /** + * {@code unset} keyword. + */ + UNSET, + + /** + * {@code revert} keyword. + */ + REVERT, + + /** + * Numeric type (excludes {@code calc()} which is an {@link #EXPRESSION}). + *

+ * Cast to {@link NumericValue}. + *

+ */ + NUMERIC, + + /** + * String. + *

+ * Cast to {@link StringValue}. + *

+ */ + STRING, + + /** + * Identifier. + *

+ * Cast to {@link KeywordValue}. + *

+ */ + IDENT, + + /** + * Color. + */ + COLOR, + + /** + * Color-Mix function. + */ + COLOR_MIX, + + /** + * URI ({@code url()}). + *

+ * Cast to {@link CSSStringValue}. + *

+ */ + URI, + + /** + * {@code rect()} function. + */ + RECT, + + /** + * An expression with algebraic syntax (i.e. calc()). + */ + EXPRESSION, + + /** + * Gradient function. + */ + GRADIENT, + + /** + * CSS counter() function. + */ + COUNTER, + + /** + * CSS counters() function. + */ + COUNTERS, + + /** + * cubic-bezier() easing function. + */ + CUBIC_BEZIER, + + /** + * steps() easing function. + */ + STEPS, + + /** + * Function. + */ + FUNCTION, + + /** + * Mathematical function (as defined by CSS Values and Units). + */ + MATH_FUNCTION, + + /** + * Unicode range. + */ + UNICODE_RANGE, + + /** + * Unicode character. + */ + UNICODE_CHARACTER, + + /** + * Unicode wildcard. + */ + UNICODE_WILDCARD, + + /** + * Element reference. + *

+ * Cast to {@link CSSKeywordValue}. + *

+ */ + ELEMENT_REFERENCE, + + /** + * Ratio value. + */ + RATIO, + + /** + * {@code attr()} function. + */ + ATTR, + + /** + * Custom property reference. + */ + VAR, + + /** + * Environment variable. + */ + ENV, + + /** + * Lexical value. + */ + LEXICAL, + + /** + * For this library's internal use. + */ + INTERNAL, + + /** + * Invalid (non-primitive and non-keyword) value. + *

+ * The value is either a list or a shorthand. + *

+ */ + INVALID + + } + + /** + * Get the general category to which this value belongs. + * + * @return the general value type. + */ + CssType getCssValueType(); + + /** + * Get the primitive type. + * + * @return the primitive type. + */ + Type getPrimitiveType(); + + /** + * Gets the css unit as in CSS4J's {@code CSSUnit}. + *

+ * If the value has no valid CSS unit, returns {@code CSSUnit.CSS_INVALID}. + *

+ * + * @return the css unit as in CSS4J's {@code CSSUnit}. + */ + default short getCSSUnit() { + return CSSUnit.CSS_INVALID; + } + + /** + * Set this value to the result of parsing the argument. + * + * @param cssText a CSS serialization to set this value. + * @throws DOMException + */ + void setCssText(String cssText) throws DOMException; + + /** + * Get a parsable representation of this value. + * + * @return the CSS serialization of this value. + */ + String getCssText(); + + /** + * Convenience method that either returns the float value, if the value is + * numeric, or throws an exception. + * + * @return the float value. + */ + float getFloatValue(); + + /** + * Convenience method that either returns an identifier or throws an exception. + * + * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't + * contain an identifier value. + */ + String getIdentifierValue() throws DOMException; + + /** + * If this value can be used where a string is expected, get the value. + * + * @return the string value, without the commas. + * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't + * contain a String. + */ + String getStringValue() throws DOMException; + + /** + * Convenience method that either returns a String or URI or throws an exception. + * + * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't + * contain a String nor a URI value. + */ + String getURIValue() throws DOMException; + + /** + * If this value is a list or contains components, the number of + * CSSStyleValues in the list. The range of valid values of the + * indices is 0 to length-1 inclusive. + * + * @return the number of components, or {@code 0} if this value is not a list + * nor does it contain components. + */ + int getLength(); + + /** + * If this value is a list, give the item corresponding to the requested index. + * If there is no item at such index, return {@code null} If this object is not + * a list and the index is {@code 0}, return itself. + * + * @param index the index on the list. + * @return the item, or {@code null} if there is no item on that index. + */ + default CSSValue item(int index) { + return index == 0 ? this : null; + } + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/CSSContext.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/CSSContext.java index c3fbb843e..e423b7561 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/CSSContext.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/CSSContext.java @@ -20,6 +20,7 @@ import org.w3c.dom.Element; +import io.sf.carte.echosvg.css.Viewport; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.util.ParsedURL; @@ -27,8 +28,10 @@ * This interface allows the user of a CSSEngine to provide contextual * informations. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public interface CSSContext { @@ -84,6 +87,13 @@ default float getPixelToMillimeter() { */ float getBlockHeight(Element elt); + /** + * Returns the viewport of the specified element. + * + * @param e the element interested in its viewport + */ + Viewport getViewport(Element e); + /** * This method should throw a SecurityException if the resource found at url and * referenced from docURL should not be loaded. diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/SystemColorSupport.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/SystemColorSupport.java index 1e2651143..2e935611a 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/SystemColorSupport.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/SystemColorSupport.java @@ -21,9 +21,10 @@ import java.awt.SystemColor; import java.util.HashMap; +import java.util.Locale; import java.util.Map; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.w3c.css.om.unit.CSSUnit; import io.sf.carte.echosvg.css.engine.value.FloatValue; import io.sf.carte.echosvg.css.engine.value.RGBColorValue; @@ -33,8 +34,10 @@ /** * This class provides support for AWT system colors. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class SystemColorSupport implements CSSConstants { @@ -43,11 +46,11 @@ public class SystemColorSupport implements CSSConstants { * Returns the Value corresponding to the given system color. */ public static Value getSystemColor(String ident) { - ident = ident.toLowerCase(); // todo locale?? + ident = ident.toLowerCase(Locale.ROOT); SystemColor sc = factories.get(ident); - return new RGBColorValue(new FloatValue(CSSPrimitiveValue.CSS_NUMBER, sc.getRed()), - new FloatValue(CSSPrimitiveValue.CSS_NUMBER, sc.getGreen()), - new FloatValue(CSSPrimitiveValue.CSS_NUMBER, sc.getBlue())); + return new RGBColorValue(new FloatValue(CSSUnit.CSS_NUMBER, sc.getRed()), + new FloatValue(CSSUnit.CSS_NUMBER, sc.getGreen()), + new FloatValue(CSSUnit.CSS_NUMBER, sc.getBlue())); } /** diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractColorManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractColorManager.java index 3d4d755d7..cd5423e61 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractColorManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractColorManager.java @@ -21,8 +21,8 @@ import java.io.IOException; import java.io.StringReader; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.CSSTypedValue; import io.sf.carte.doc.style.css.CSSValue.CssType; @@ -32,17 +32,21 @@ import io.sf.carte.doc.style.css.parser.CSSParser; import io.sf.carte.doc.style.css.property.StyleValue; import io.sf.carte.doc.style.css.property.ValueFactory; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.StyleMap; +import io.sf.carte.echosvg.css.engine.value.svg.SVGValueConstants; import io.sf.carte.echosvg.util.CSSConstants; /** * This class provides a manager for the property with support for CSS color * values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public abstract class AbstractColorManager extends IdentifierManager { @@ -130,13 +134,17 @@ public abstract class AbstractColorManager extends IdentifierManager { @Override public Value createValue(LexicalUnit lunit, CSSEngine engine) throws DOMException { switch (lunit.getLexicalUnitType()) { + case COLOR_FUNCTION: + Value colorFunction = createColorFunction(lunit); + if (colorFunction != null) { + return colorFunction; + } case HSLCOLOR: case HWBCOLOR: case LABCOLOR: case LCHCOLOR: case OKLABCOLOR: case OKLCHCOLOR: - case COLOR_FUNCTION: case COLOR_MIX: ValueFactory vf = new ValueFactory(); String rgbSerialization; @@ -157,34 +165,7 @@ public Value createValue(LexicalUnit lunit, CSSEngine engine) throws DOMExceptio throw createInvalidLexicalUnitDOMException(lunit.getLexicalUnitType()); } case RGBCOLOR: - LexicalUnit lu = lunit.getParameters(); - Value red = createColorComponent(lu); - lu = lu.getNextLexicalUnit(); - if (lu.getLexicalUnitType() == LexicalUnit.LexicalType.OPERATOR_COMMA) { - lu = lu.getNextLexicalUnit(); - } - Value green = createColorComponent(lu); - lu = lu.getNextLexicalUnit(); - if (lu.getLexicalUnitType() == LexicalUnit.LexicalType.OPERATOR_COMMA) { - lu = lu.getNextLexicalUnit(); - } - Value blue = createColorComponent(lu); - // Alpha channel - lu = lu.getNextLexicalUnit(); - Value alpha; - if (lu != null) { - if (lu.getLexicalUnitType() == LexicalUnit.LexicalType.OPERATOR_COMMA - || lu.getLexicalUnitType() == LexicalUnit.LexicalType.OPERATOR_SLASH) { - lu = lu.getNextLexicalUnit(); - if (lu == null) { - throw new DOMException(DOMException.SYNTAX_ERR, "Invalid color: " + lunit.getCssText()); - } - } - alpha = createColorComponent(lu); - } else { - alpha = null; - } - return createRGBColor(red, green, blue, alpha); + return createRGBColor(lunit); default: return super.createValue(lunit, engine); } @@ -197,8 +178,8 @@ public Value createValue(LexicalUnit lunit, CSSEngine engine) throws DOMExceptio @Override public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { - if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { - String ident = value.getStringValue(); + if (value.getPrimitiveType() == Type.IDENT) { + String ident = ((AbstractStringValue) value).getValue(); // Search for a direct computed value. Value v = (Value) computedValues.get(ident); if (v != null) { @@ -213,26 +194,138 @@ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engin return super.computeValue(elt, pseudo, engine, idx, sm, value); } + private Value createRGBColor(LexicalUnit lunit) { + LexicalUnit lu = lunit.getParameters(); + + boolean pcntSpecified = lu.getLexicalUnitType() == LexicalType.PERCENTAGE; + NumericValue red = createRGBColorComponent(lu); + lu = lu.getNextLexicalUnit(); + if (lu.getLexicalUnitType() == LexicalUnit.LexicalType.OPERATOR_COMMA) { + lu = lu.getNextLexicalUnit(); + } + + pcntSpecified = pcntSpecified || lu.getLexicalUnitType() == LexicalType.PERCENTAGE; + NumericValue green = createRGBColorComponent(lu); + lu = lu.getNextLexicalUnit(); + if (lu.getLexicalUnitType() == LexicalUnit.LexicalType.OPERATOR_COMMA) { + lu = lu.getNextLexicalUnit(); + } + + pcntSpecified = pcntSpecified || lu.getLexicalUnitType() == LexicalType.PERCENTAGE; + NumericValue blue = createRGBColorComponent(lu); + + // Alpha channel + lu = lu.getNextLexicalUnit(); + NumericValue alpha; + boolean alphaPcntSpecified = false; + if (lu != null) { + if (lu.getLexicalUnitType() == LexicalUnit.LexicalType.OPERATOR_COMMA + || lu.getLexicalUnitType() == LexicalUnit.LexicalType.OPERATOR_SLASH) { + lu = lu.getNextLexicalUnit(); + if (lu == null) { + throw new DOMException(DOMException.SYNTAX_ERR, "Invalid color: " + lunit.getCssText()); + } + } + alphaPcntSpecified = lu.getLexicalUnitType() == LexicalType.PERCENTAGE; + alpha = createColorComponent(lu); + } else { + alpha = null; + } + return createRGBColor(red, green, blue, pcntSpecified, alpha, alphaPcntSpecified); + } + /** * Creates an RGB(A) color. */ - protected Value createRGBColor(Value r, Value g, Value b, Value a) { - return a == null ? new RGBColorValue(r, g, b) : new RGBColorValue(r, g, b, a); + protected Value createRGBColor(NumericValue r, NumericValue g, NumericValue b, boolean pcntSpecified, + NumericValue a, boolean alphaPcntSpecified) { + RGBColorValue c = a == null ? new RGBColorValue(r, g, b) : new RGBColorValue(r, g, b, a); + c.setSpecifiedAsPercentage(pcntSpecified); + c.setAlphaSpecifiedAsPercentage(alphaPcntSpecified); + return c; + } + + private ColorFunction createColorFunction(LexicalUnit lunit) { + LexicalUnit lu = lunit.getParameters(); + AbstractValueList components = new AbstractValueList<>(' ', 4); + + // Color space + if (lu.getLexicalUnitType() != LexicalUnit.LexicalType.IDENT) { + throw new DOMException(DOMException.TYPE_MISMATCH_ERR, + "Color space must be identifier: " + lunit.toString()); + } + + String colorSpace = lu.getStringValue(); + lu = lu.getNextLexicalUnit(); + if (lu == null) { + throw new DOMException(DOMException.SYNTAX_ERR, "Wrong value: " + lunit.toString()); + } + + // Components + NumericValue alpha = null; + NumericValue primi; + while (true) { + primi = createColorComponent(lu); + components.add(primi); + lu = lu.getNextLexicalUnit(); + + if (lu == null) { + break; + } + if (lu.getLexicalUnitType() == LexicalUnit.LexicalType.OPERATOR_SLASH) { + lu = lu.getNextLexicalUnit(); // Alpha + alpha = createColorComponent(lu); + lu = lu.getNextLexicalUnit(); + if (lu != null) { + throw new DOMException(DOMException.SYNTAX_ERR, + "Wrong value: " + lunit.toString()); + } + break; + } + } + + ColorFunction color = new ColorFunction(colorSpace, components); + + if (alpha == null) { + alpha = SVGValueConstants.NUMBER_1; + } + color.setAlpha(alpha); + + return color; + } + + /** + * Creates an RGB color component from a lexical unit. + */ + protected NumericValue createRGBColorComponent(LexicalUnit lu) throws DOMException { + switch (lu.getLexicalUnitType()) { + case INTEGER: + return new FloatValue(CSSUnit.CSS_PERCENTAGE, lu.getIntegerValue() / 2.55f); + + case REAL: + return new FloatValue(CSSUnit.CSS_PERCENTAGE, lu.getFloatValue() / 2.55f); + + case PERCENTAGE: + return new FloatValue(CSSUnit.CSS_PERCENTAGE, lu.getFloatValue()); + + default: + } + throw createInvalidRGBComponentUnitDOMException(lu.getLexicalUnitType()); } /** * Creates a color component from a lexical unit. */ - protected Value createColorComponent(LexicalUnit lu) throws DOMException { + protected NumericValue createColorComponent(LexicalUnit lu) throws DOMException { switch (lu.getLexicalUnitType()) { case INTEGER: - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getIntegerValue()); + return new FloatValue(CSSUnit.CSS_NUMBER, lu.getIntegerValue()); case REAL: - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getFloatValue()); + return new FloatValue(CSSUnit.CSS_NUMBER, lu.getFloatValue()); case PERCENTAGE: - return new FloatValue(CSSPrimitiveValue.CSS_PERCENTAGE, lu.getFloatValue()); + return new FloatValue(CSSUnit.CSS_PERCENTAGE, lu.getFloatValue()); default: } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractCounterValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractCounterValue.java new file mode 100644 index 000000000..3d8b10286 --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractCounterValue.java @@ -0,0 +1,141 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import java.util.Objects; + +import org.w3c.css.om.typed.CSSCounterValue; +import org.w3c.dom.DOMException; + +/** + * Abstract class for counter() and counters() functions. + * + */ +abstract class AbstractCounterValue extends ComponentValue implements CSSCounterValue { + + private String identifier; + private Value listStyle = null; + + protected AbstractCounterValue() { + super(); + } + + AbstractCounterValue(String identifier, Value listStyle) { + super(); + this.identifier = identifier; + this.listStyle = listStyle; + } + + @Override + public String getName() { + return identifier; + } + + public void setName(String identifier) { + this.identifier = identifier; + if (handler != null) { + handler.valueChanged(this); + } + } + + @Override + public Value getCounterStyle() { + return listStyle; + } + + void setCounterStyle(AbstractValue listStyle) { + componentize(listStyle); + this.listStyle = listStyle; + if (handler != null) { + handler.valueChanged(this); + } + } + + @Override + public String getSeparator() { + return ""; + } + + @Override + public Value item(int index) { + if (index == 0) { + return getCounterStyle(); + } + return null; + } + + void set(int index, Value component) throws DOMException { + if (index == 0) { + setCounterStyle((AbstractValue) component); + } + } + + @Override + public int getLength() { + return 1; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((identifier == null) ? 0 : identifier.hashCode()); + result = prime * result + ((listStyle == null) ? decimalHashCode() : listStyle.hashCode()); + return result; + } + + private int decimalHashCode() { + int result = 31 * CssType.TYPED.hashCode() + Type.IDENT.hashCode(); + result = 31 * result + "decimal".hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + AbstractCounterValue other = (AbstractCounterValue) obj; + if (identifier == null) { + if (other.identifier != null) { + return false; + } + } else if (!identifier.equals(other.identifier)) { + return false; + } + + return Objects.equals(listStyle, other.listStyle); + } + + static void quoteSeparator(String separator, StringBuilder buf) { + if (!separator.contains("'")) { + buf.append('\'').append(separator).append('\''); + } else { + buf.append('"').append(separator).append('"'); + } + } + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractStringValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractStringValue.java new file mode 100644 index 000000000..6dcdf2bb9 --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractStringValue.java @@ -0,0 +1,86 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import java.util.Objects; + +import org.w3c.api.DOMTypeException; + +/** + * Abstract class for string values. + * + * @version $Id$ + */ +public abstract class AbstractStringValue extends AbstractValue { + + /** + * The value of the string + */ + String value; + + /** + * Creates a new StringValue. + */ + public AbstractStringValue(String s) { + value = s; + } + + @Override + public int hashCode() { + return Objects.hash(getPrimitiveType(), value); + } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param obj the reference object with which to compare. + */ + @Override + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof AbstractStringValue) + || getPrimitiveType() != ((AbstractStringValue) obj).getPrimitiveType()) { + return false; + } + AbstractStringValue v = (AbstractStringValue) obj; + return value.equals(v.value); + } + + /** + * This method is used to get the string value. + * + */ + public String getValue() { + return value; + } + + public void setValue(String value) throws DOMTypeException { + if (value == null || value.isEmpty()) { + throw new DOMTypeException("Value is null or empty."); + } + this.value = value; + + if (handler != null) { + handler.valueChanged(this); + } + } + + @Override + public abstract AbstractStringValue clone(); + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValue.java index 2323ae514..b5d4121ea 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValue.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValue.java @@ -18,161 +18,138 @@ */ package io.sf.carte.echosvg.css.engine.value; +import org.w3c.css.om.typed.CSSCounterValue; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSValue; /** * This class provides an abstract implementation of the Value interface. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + *

* @version $Id$ */ -public abstract class AbstractValue implements Value { +public abstract class AbstractValue implements Value, Cloneable { - /** - * Implements {@link Value#getCssValueType()}. - */ - @Override - public short getCssValueType() { - return CSSValue.CSS_PRIMITIVE_VALUE; - } + ValueModificationHandler handler; - /** - * Implements {@link Value#getPrimitiveType()}. - */ @Override - public short getPrimitiveType() { - throw createDOMException(); + public CssType getCssValueType() { + return Value.CssType.TYPED; } - /** - * Implements {@link Value#getFloatValue()}. - */ @Override - public float getFloatValue() throws DOMException { + public Type getPrimitiveType() { throw createDOMException(); } - /** - * Implements {@link Value#getStringValue()}. - */ @Override - public String getStringValue() throws DOMException { - throw createDOMException(); + public short getCSSUnit() { + return CSSUnit.CSS_INVALID; } - /** - * Implements {@link Value#getRed()}. - */ @Override - public Value getRed() throws DOMException { + public void setCssText(String cssText) throws DOMException { throw createDOMException(); } - /** - * Implements {@link Value#getGreen()}. - */ @Override - public Value getGreen() throws DOMException { - throw createDOMException(); + public String toString() { + return getCssText(); } /** - * Implements {@link Value#getBlue()}. + * Implements {@link Value#getFloatValue()}. */ @Override - public Value getBlue() throws DOMException { + public float getFloatValue() throws DOMException { throw createDOMException(); } - /** - * Implements {@link Value#getAlpha()}. - */ @Override - public Value getAlpha() throws DOMException { + public void setFloatValue(float value) throws DOMException { throw createDOMException(); } - /** - * Implements {@link Value#getLength()}. - */ @Override - public int getLength() throws DOMException { + public String getStringValue() throws DOMException { throw createDOMException(); } - /** - * Implements {@link Value#item(int)}. - */ @Override - public Value item(int index) throws DOMException { - throw createDOMException(); + public int getLength() throws DOMException { + return 0; } - /** - * Implements {@link Value#getTop()}. - */ @Override - public Value getTop() throws DOMException { + public String getIdentifierValue() throws DOMException { throw createDOMException(); } - /** - * Implements {@link Value#getRight()}. - */ @Override - public Value getRight() throws DOMException { + public String getURIValue() throws DOMException { throw createDOMException(); } - /** - * Implements {@link Value#getBottom()}. - */ @Override - public Value getBottom() throws DOMException { + public CSSCounterValue getCounterValue() throws DOMException { throw createDOMException(); } - /** - * Implements {@link Value#getLeft()}. - */ @Override - public Value getLeft() throws DOMException { + public RectValue getRectValue() throws DOMException { throw createDOMException(); } - /** - * Implements {@link Value#getIdentifier()}. - */ @Override - public String getIdentifier() throws DOMException { + public ColorValue getColorValue() throws DOMException { throw createDOMException(); } - /** - * Implements {@link Value#getListStyle()}. - */ @Override - public String getListStyle() throws DOMException { - throw createDOMException(); + public void setModificationHandler(ValueModificationHandler handler) { + this.handler = handler; } - /** - * Implements {@link Value#getSeparator()}. - */ @Override - public String getSeparator() throws DOMException { - throw createDOMException(); + public ValueModificationHandler getModificationHandler() { + return handler; } /** * Creates an INVALID_ACCESS_ERR exception. */ protected DOMException createDOMException() { - Object[] p = { (int) getCssValueType() }; + Object[] p = { getPrimitiveType() }; String s = Messages.formatMessage("invalid.value.access", p); return new DOMException(DOMException.INVALID_ACCESS_ERR, s); } + @Override + public int hashCode() { + return getPrimitiveType().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Value)) + return false; + Value other = (Value) obj; + return getPrimitiveType() == other.getPrimitiveType(); + } + + @Override + public AbstractValue clone() { + try { + return (AbstractValue) super.clone(); + } catch (CloneNotSupportedException e) { + return null; + } + } + } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueFactory.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueFactory.java index 5758187be..70d1e007e 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueFactory.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueFactory.java @@ -21,13 +21,16 @@ import org.w3c.dom.DOMException; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.util.ParsedURL; /** * This class provides a base implementation for the value factories. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public abstract class AbstractValueFactory { @@ -83,8 +86,8 @@ protected DOMException createInvalidFloatValueDOMException(float f) { /** * Creates a DOM exception, given an invalid string type. */ - protected DOMException createInvalidStringTypeDOMException(short t) { - Object[] p = { getPropertyName(), (int) t }; + protected DOMException createInvalidStringTypeDOMException(Type t) { + Object[] p = { getPropertyName(), t }; String s = Messages.formatMessage("invalid.string.type", p); return new DOMException(DOMException.INVALID_ACCESS_ERR, s); } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueList.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueList.java new file mode 100644 index 000000000..dccf0fe17 --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueList.java @@ -0,0 +1,151 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import java.util.ArrayList; +import java.util.Iterator; + +import org.w3c.css.om.typed.CSSStyleValueList; + +/** + * This class represents a list of values. + * + * @author See Git history. + * @version $Id$ + */ +public class AbstractValueList extends ComponentValue implements CSSStyleValueList { + + /** + * The items. + */ + private ArrayList items; + + /** + * The list separator. + */ + private char separator; + + /** + * Creates a ListValue. + */ + public AbstractValueList() { + this(','); + } + + /** + * Creates a ListValue with the given separator. + */ + public AbstractValueList(char s) { + this(s, 5); + } + + /** + * Creates a ListValue with the given separator and an initial capacity. + */ + public AbstractValueList(char s, int initialCapacity) { + separator = s; + items = new ArrayList<>(initialCapacity); + } + + @Override + public AbstractValueList clone() { + AbstractValueList clon = new AbstractValueList<>(separator, items.size()); + clon.items.addAll(items); + return clon; + } + + /** + * Returns the separator used for this list. + */ + public char getSeparatorChar() { + return separator; + } + + @Override + public CssType getCssValueType() { + return CssType.LIST; + } + + @Override + public Type getPrimitiveType() { + return Type.INVALID; // Not a primitive + } + + /** + * Appends an item to the list. + */ + public boolean add(V value) { + boolean b = items.add(value); + componentAdded(value); + return b; + } + + /** + * A string representation of the current value. + */ + @Override + public String getCssText() { + int length = items.size(); + StringBuilder sb = new StringBuilder(length * 8); + if (length > 0) { + sb.append(items.get(0).toString()); + } + for (int i = 1; i < length; i++) { + sb.append(separator); + sb.append(items.get(i).toString()); + } + return sb.toString(); + } + + @Override + public V item(int index) { + return items.get(index); + } + + @Override + public int getLength() { + return items.size(); + } + + @Override + public Iterator iterator() { + return items.iterator(); + } + + public void clear() { + items.clear(); + } + + public boolean isEmpty() { + return items.isEmpty(); + } + + public V remove(int index) { + V item = items.remove(index); + componentRemoved(item); + return item; + } + + public V set(int index, V value) { + V v = items.set(index, value); + getComponentHandler().listValueChanged(index, value); + return v; + } + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueManager.java index a704fc886..4b6ada07d 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueManager.java @@ -19,9 +19,9 @@ package io.sf.carte.echosvg.css.engine.value; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; +import org.w3c.css.om.unit.CSSUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.StyleMap; @@ -29,8 +29,10 @@ /** * This class provides an abstract implementation of the ValueManager interface. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public abstract class AbstractValueManager extends AbstractValueFactory implements ValueManager { @@ -43,11 +45,8 @@ public Value createFloatValue(short unitType, float floatValue) throws DOMExcept throw createDOMException(); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { throw createDOMException(); } @@ -59,12 +58,31 @@ public Value createStringValue(short type, String value, CSSEngine engine) throw public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { - if ((value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) - && (value.getPrimitiveType() == CSSPrimitiveValue.CSS_URI)) { - // Reveal the absolute value as the cssText now. - return new URIValue(value.getStringValue(), value.getStringValue()); + if (value.getPrimitiveType() == Type.URI) { + // For performance, set the parsed value as the cssText now. + String uri = value.getURIValue(); + return new URIValue(uri, uri); } + return value; } + protected float lengthValue(Value cv) { + short unit = cv.getCSSUnit(); + if (!CSSUnit.isLengthUnitType(unit) && unit != CSSUnit.CSS_NUMBER) { + throw createDOMException(unit); + } + return cv.getFloatValue(); + } + + /** + * Creates an INVALID_ACCESS_ERR exception. + * @param unit the unit. + */ + protected DOMException createDOMException(int unit) { + Object[] p = { unit }; + String s = Messages.formatMessage("invalid.value.access", p); + return new DOMException(DOMException.INVALID_ACCESS_ERR, s); + } + } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueModificationHandler.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueModificationHandler.java new file mode 100644 index 000000000..1eac5ce13 --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/AbstractValueModificationHandler.java @@ -0,0 +1,64 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import org.w3c.dom.DOMException; + +/** + * Base class for modification handlers. + */ +public abstract class AbstractValueModificationHandler implements ValueModificationHandler { + + /** + * Creates a new AbstractValueModificationHandler. + */ + protected AbstractValueModificationHandler() { + super(); + } + + /** + * Returns the associated value. + */ + protected abstract Value getValue(); + + /** + * Called when the value has changed. + * + * @param v the value that changed. + */ + @Override + public void valueChanged(Value v) throws DOMException { + propertyTextChanged(); + } + + /** + * To trigger a full property set. + */ + protected void propertyTextChanged() throws DOMException { + setPropertyText(getValue().getCssText()); + } + + /** + * To trigger a full property reparse. + * + * @param text the property serialization. + */ + protected abstract void setPropertyText(String text) throws DOMException; + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ColorFunction.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ColorFunction.java new file mode 100644 index 000000000..a336e248b --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ColorFunction.java @@ -0,0 +1,189 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import java.util.HashSet; +import java.util.Locale; +import java.util.Set; + +import org.w3c.api.DOMSyntaxException; +import org.w3c.css.om.typed.CSSColor; +import org.w3c.css.om.typed.CSSStyleValueList; +import org.w3c.dom.DOMException; + +import org.w3c.css.om.unit.CSSUnit; + +/** + * color() function. + * + * @author See Git history. + * @version $Id$ + */ +public class ColorFunction extends ColorValue implements CSSColor { + + private IdentValue colorSpace; + + /** + * The channels. + */ + private AbstractValueList channels; + + private static final Set predefinedSpaces; + + static { + predefinedSpaces = new HashSet<>(9); + predefinedSpaces.add(ColorValue.CS_SRGB); + predefinedSpaces.add(ColorValue.CS_SRGB_LINEAR); + predefinedSpaces.add(ColorValue.CS_A98_RGB); + predefinedSpaces.add(ColorValue.CS_DISPLAY_P3); + predefinedSpaces.add(ColorValue.CS_PROPHOTO_RGB); + predefinedSpaces.add(ColorValue.CS_REC2020); + predefinedSpaces.add(ColorValue.CS_XYZ); + predefinedSpaces.add(ColorValue.CS_XYZ_D50); + predefinedSpaces.add(ColorValue.CS_XYZ_D65); + } + + /** + * Creates a new ColorFunction. + * + * @param colorSpace the color space. + * @param channels a channel list to copy from. + * @throws DOMSyntaxException if a supplied component is invalid. + */ + public ColorFunction(String colorSpace, CSSStyleValueList channels) + throws DOMSyntaxException { + super(); + this.colorSpace = new IdentValue(canonicalName(colorSpace)); + componentize(this.colorSpace); + componentizeChannels(channels); + } + + private void componentizeChannels(CSSStyleValueList channels) { + // Clone channels if the list belongs to some other value + boolean clone = channels instanceof AbstractValue && ((AbstractValue) channels).handler != null; + int len = channels.getLength(); + this.channels = new AbstractValueList(' ', len); + for (NumericValue channel : channels) { + if (clone) { + channel = channel.clone(); + } + this.channels.add(numericComponent(channel)); + } + componentize(this.channels); + } + + /** + * Get the color space as defined by the Typed OM specification. + * + * @return the color space. + */ + @Override + public IdentValue getColorSpace() { + return colorSpace; + } + + @Override + public String getCSSColorSpace() { + return colorSpace.getValue(); + } + + @Override + public void setColorSpace(String cs) { + colorSpace.setValue(canonicalName(cs)); + componentChanged(colorSpace); + } + + static String canonicalName(String cs) throws DOMException { + cs = cs.toLowerCase(Locale.ROOT); + if (!predefinedSpaces.contains(cs)) { + throw new DOMException(DOMException.NOT_SUPPORTED_ERR, + "Unsupported color space: " + cs); + } + return cs; + } + + @Override + public CSSStyleValueList getChannels() { + return channels; + } + + @Override + public int getLength() throws DOMException { + return channels.getLength() + 2; + } + + @Override + public Value item(int index) throws DOMException { + if (index == 0) { + return getColorSpace(); + } else if (index == channels.getLength() + 1) { + return getAlpha(); + } + return channels.item(index - 1); + } + + @Override + public ColorFunction getColorValue() { + return this; + } + + /** + * A string representation of the current value. + */ + @Override + public String getCssText() { + StringBuilder buf = new StringBuilder(15 + colorSpace.value.length() + channels.getLength() * 8); + buf.append("color(").append(colorSpace.getCssText()); + for (NumericValue ch : channels) { + buf.append(' ').append(ch.getCssText()); + } + if (!isOpaque()) { + buf.append(" / ").append(getAlpha().getCssText()); + } + buf.append(')'); + return buf.toString(); + } + + /** + * Initialize a numeric component of this value. + * + * @param ch the component. + * @return the initialized component. + * @throws DOMSyntaxException if the value is inadequate for a component. + */ + private NumericValue numericComponent(NumericValue ch) throws DOMSyntaxException { + if (ch.getCSSUnit() != CSSUnit.CSS_PERCENTAGE && ch.getCSSUnit() != CSSUnit.CSS_NUMBER) { + throw new DOMSyntaxException("color() component must be a number or percentage."); + } + componentize(ch); + return ch; + } + + @Override + public ColorFunction clone() { + ColorFunction clon; + try { + clon = new ColorFunction(getColorSpace().getValue(), this.channels); + } catch (DOMSyntaxException e) { + clon = null; + } + return clon; + } + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ColorValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ColorValue.java new file mode 100644 index 000000000..02e2addce --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ColorValue.java @@ -0,0 +1,164 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import org.w3c.api.DOMSyntaxException; +import org.w3c.css.om.typed.CSSColorValue; +import org.w3c.css.om.typed.CSSNumericValue; +import org.w3c.css.om.unit.CSSUnit; + +/** + * CSS colors. + * + * @author See Git history. + * @version $Id$ + */ +public abstract class ColorValue extends ComponentValue implements CSSColorValue { + + public static final String RGB_FUNCTION = "rgb"; + + public static final String CS_SRGB = "srgb"; + + public static final String LAB = "lab"; + + public static final String LCH = "lch"; + + public static final String CS_DISPLAY_P3 = "display-p3"; + + public static final String CS_SRGB_LINEAR = "srgb-linear"; + + public static final String CS_A98_RGB = "a98-rgb"; + + public static final String CS_PROPHOTO_RGB = "prophoto-rgb"; + + public static final String CS_REC2020 = "rec2020"; + + /** + * The {@code xyz-d50} color space. + */ + public static final String CS_XYZ_D50 = "xyz-d50"; + + /** + * The {@code xyz-d65} color space (same as {@code xyz}). + */ + public static final String CS_XYZ_D65 = "xyz-d65"; + + /** + * The {@code xyz} color space (same as {@code xyz-d65}). + */ + public static final String CS_XYZ = "xyz"; + + /** + * The alpha channel. + */ + protected NumericValue alpha; + + /** + * Creates a new RGBColorValue. + */ + protected ColorValue() { + } + + /** + * Creates a new RGBColorValue. + * + * @param a the alpha channel. + * @throws DOMSyntaxException if the value is an invalid opacity. + */ + protected ColorValue(NumericValue a) throws DOMSyntaxException { + super(); + setAlpha(a); + } + + /** + * The type of the value. + */ + @Override + public Type getPrimitiveType() { + return Type.COLOR; + } + + /** + * Get the color space as defined by the Typed OM specification. + * + * @return the color space. + */ + public abstract String getCSSColorSpace(); + + /** + * Gets the value of the {@code alpha} component. + * + * @return the {@code alpha} component. + */ + public NumericValue getAlpha() { + return alpha; + } + + /** + * Sets the alpha channel as a percentage. + * + * @param alpha the alpha channel as a percentage. + */ + public void setAlpha(double alpha) { + this.alpha = new FloatValue(CSSUnit.CSS_PERCENTAGE, (float) alpha * 100); + componentize(this.alpha); + + componentChanged(this.alpha); + } + + /** + * Sets the alpha channel. + * + * @param alpha the alpha channel. + * @throws DOMSyntaxException if alpha is not a percentage. + */ + public void setAlpha(CSSNumericValue alpha) throws DOMSyntaxException { + NumericValue a = (NumericValue) alpha; + if (a.getCSSUnit() != CSSUnit.CSS_PERCENTAGE && a.getCSSUnit() != CSSUnit.CSS_NUMBER) { + throw new DOMSyntaxException("Alpha channel must be a number or percentage."); + } + componentize(a); + this.alpha = a; + + componentChanged(a); + } + + boolean isOpaque() { + switch (alpha.getCSSUnit()) { + case CSSUnit.CSS_NUMBER: + return alpha.getFloatValue() == 1f; + case CSSUnit.CSS_PERCENTAGE: + return alpha.getFloatValue() == 100f; + } + return false; + } + + @Override + public ColorValue getColorValue() { + return this; + } + + @Override + public ColorValue clone() { + ColorValue c = (ColorValue) super.clone(); + c.alpha = alpha.clone(); + return c; + } + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ComponentHandler.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ComponentHandler.java new file mode 100644 index 000000000..cf4a84edb --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ComponentHandler.java @@ -0,0 +1,61 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import org.w3c.dom.DOMException; + +/** + * Manage the modification of value components. + */ +public interface ComponentHandler extends ValueModificationHandler { + + /** + * Notify that a component of this value changed. + * + * @param c the modified value. + */ + void componentChanged(Value c); + + /** + * Notify that a component was added to this value. + * + * @param c the new value. + */ + void componentAdded(Value c); + + /** + * Notify that a component was removed from this value. + * + * @param c the removed value. + */ + void componentRemoved(Value c); + + /** + * Called when a list value has changed. + */ + void listValueChanged(int index, Value value) throws DOMException; + + /** + * Get the value that owns the components (a list, a color, etc). + * + * @return the main value. + */ + Value getValue(); + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ComponentValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ComponentValue.java new file mode 100644 index 000000000..bdb09ea64 --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ComponentValue.java @@ -0,0 +1,96 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import org.w3c.dom.DOMException; + +/** + * A Value made of components. + * + * @version $Id$ + */ +public abstract class ComponentValue extends AbstractValue { + + private ComponentModificationHandler componentHandler = new ComponentModificationHandler(); + + protected ComponentValue() { + super(); + } + + protected ComponentModificationHandler getComponentHandler() { + return componentHandler; + } + + protected void componentize(Value value) { + value.setModificationHandler(componentHandler); + } + + protected void componentChanged(Value v) { + componentHandler.componentChanged(v); + } + + protected void componentAdded(Value v) { + componentHandler.componentAdded(v); + } + + protected void componentRemoved(Value v) { + componentHandler.componentRemoved(v); + } + + class ComponentModificationHandler implements ComponentHandler { + + @Override + public void componentChanged(Value c) { + propertyChanged(); + } + + @Override + public void componentAdded(Value c) { + propertyChanged(); + } + + @Override + public void componentRemoved(Value c) { + propertyChanged(); + } + + @Override + public void listValueChanged(int index, Value value) throws DOMException { + propertyChanged(); + } + + @Override + public void valueChanged(Value v) { + propertyChanged(); + } + + private void propertyChanged() { + if (handler != null) { + handler.valueChanged(getValue()); + } + } + + @Override + public Value getValue() { + return ComponentValue.this; + } + + } + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ComputedValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ComputedValue.java index 173550a90..0fb8ed4b4 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ComputedValue.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ComputedValue.java @@ -18,13 +18,15 @@ */ package io.sf.carte.echosvg.css.engine.value; +import org.w3c.css.om.typed.CSSCounterValue; import org.w3c.dom.DOMException; /** * This class represents a computed property value. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. See Git history. + *

* @version $Id$ */ public class ComputedValue implements Value { @@ -77,137 +79,95 @@ public String getCssText() { return computedValue.getCssText(); } - /** - * Implements {@link Value#getCssValueType()}. - */ @Override - public short getCssValueType() { + public CssType getCssValueType() { return computedValue.getCssValueType(); } - /** - * Implements {@link Value#getPrimitiveType()}. - */ + @Override - public short getPrimitiveType() { + public Type getPrimitiveType() { return computedValue.getPrimitiveType(); } - /** - * Implements {@link Value#getFloatValue()}. - */ @Override - public float getFloatValue() throws DOMException { - return computedValue.getFloatValue(); + public short getCSSUnit() { + return computedValue.getCSSUnit(); } - /** - * Implements {@link Value#getStringValue()}. - */ @Override - public String getStringValue() throws DOMException { - return computedValue.getStringValue(); + public void setFloatValue(float value) throws DOMException { + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Cannot modify computed value."); } - /** - * Implements {@link Value#getRed()}. - */ @Override - public Value getRed() throws DOMException { - return computedValue.getRed(); + public void setModificationHandler(ValueModificationHandler handler) { + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Cannot modify computed value."); } - /** - * Implements {@link Value#getGreen()}. - */ @Override - public Value getGreen() throws DOMException { - return computedValue.getGreen(); + public ValueModificationHandler getModificationHandler() { + return computedValue.getModificationHandler(); } - /** - * Implements {@link Value#getBlue()}. - */ @Override - public Value getBlue() throws DOMException { - return computedValue.getBlue(); + public float getFloatValue() throws DOMException { + return computedValue.getFloatValue(); } @Override - public Value getAlpha() throws DOMException { - return computedValue.getAlpha(); + public String getIdentifierValue() throws DOMException { + return computedValue.getIdentifierValue(); } /** - * Implements {@link Value#getLength()}. + * Implements {@link Value#getStringValue()}. */ @Override - public int getLength() throws DOMException { - return computedValue.getLength(); + public String getStringValue() throws DOMException { + return computedValue.getStringValue(); } - /** - * Implements {@link Value#item(int)}. - */ @Override - public Value item(int index) throws DOMException { - return computedValue.item(index); + public String getURIValue() throws DOMException { + return computedValue.getURIValue(); } - /** - * Implements {@link Value#getTop()}. - */ @Override - public Value getTop() throws DOMException { - return computedValue.getTop(); + public void setCssText(String cssText) throws DOMException { + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Cannot modify computed value."); } - /** - * Implements {@link Value#getRight()}. - */ @Override - public Value getRight() throws DOMException { - return computedValue.getRight(); + public int getLength() throws DOMException { + return computedValue.getLength(); } - /** - * Implements {@link Value#getBottom()}. - */ @Override - public Value getBottom() throws DOMException { - return computedValue.getBottom(); + public Value item(int index) throws DOMException { + return computedValue.item(index); } - /** - * Implements {@link Value#getLeft()}. - */ @Override - public Value getLeft() throws DOMException { - return computedValue.getLeft(); + public CSSCounterValue getCounterValue() throws DOMException { + return computedValue.getCounterValue(); } - /** - * Implements {@link Value#getIdentifier()}. - */ @Override - public String getIdentifier() throws DOMException { - return computedValue.getIdentifier(); + public RectValue getRectValue() throws DOMException { + return computedValue.getRectValue(); } - /** - * Implements {@link Value#getListStyle()}. - */ @Override - public String getListStyle() throws DOMException { - return computedValue.getListStyle(); + public ColorValue getColorValue() throws DOMException { + return computedValue.getColorValue(); } - /** - * Implements {@link Value#getSeparator()}. - */ @Override - public String getSeparator() throws DOMException { - return computedValue.getSeparator(); + public ComputedValue clone() { + ComputedValue cv = new ComputedValue(cascadedValue); + cv.setComputedValue(computedValue); + return cv; } } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/CounterValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/CounterValue.java new file mode 100644 index 000000000..1f3592eea --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/CounterValue.java @@ -0,0 +1,65 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import org.w3c.dom.DOMException; + +/** + * counter() function. + * + */ +class CounterValue extends AbstractCounterValue { + + public CounterValue() { + super(); + } + + CounterValue(String identifier, Value listStyle) { + super(identifier, listStyle); + } + + @Override + public CounterValue clone() { + return new CounterValue(getName(), getCounterStyle()); + } + + @Override + public Type getPrimitiveType() { + return Type.COUNTER; + } + + @Override + public String getCssText() { + StringBuilder buf = new StringBuilder(); + buf.append("counter(").append(getName()); + Value style = getCounterStyle(); + String listStyle; + if (style != null && !"decimal".equalsIgnoreCase(listStyle = style.getCssText())) { + buf.append(',').append(' ').append(listStyle); + } + buf.append(')'); + return buf.toString(); + } + + @Override + public CounterValue getCounterValue() throws DOMException { + return this; + } + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/CountersValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/CountersValue.java new file mode 100644 index 000000000..9d1b9ee05 --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/CountersValue.java @@ -0,0 +1,77 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import org.w3c.dom.DOMException; + +/** + * counters() function. + * + */ +class CountersValue extends AbstractCounterValue { + + private String separator = ""; + + public CountersValue() { + super(); + } + + CountersValue(String identifier, Value listStyle, String separator) { + super(identifier, listStyle); + this.separator = separator; + } + + @Override + public CountersValue clone() { + return new CountersValue(getName(), getCounterStyle(), getSeparator()); + } + + @Override + public Type getPrimitiveType() { + return Type.COUNTERS; + } + + @Override + public String getSeparator() { + return separator; + } + + public void setSeparator(String separator) { + this.separator = separator; + } + + @Override + public String getCssText() { + StringBuilder buf = new StringBuilder(); + buf.append("counter(").append(getName()); + Value style = getCounterStyle(); + String listStyle; + if (style != null && !"decimal".equalsIgnoreCase(listStyle = style.getCssText())) { + buf.append(',').append(' ').append(listStyle); + } + buf.append(')'); + return buf.toString(); + } + + @Override + public CountersValue getCounterValue() throws DOMException { + return this; + } + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/FloatValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/FloatValue.java index 400834715..d5d0a4ff2 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/FloatValue.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/FloatValue.java @@ -18,47 +18,53 @@ */ package io.sf.carte.echosvg.css.engine.value; +import java.io.IOException; +import java.io.StringReader; +import java.util.Objects; + +import org.w3c.api.DOMSyntaxException; +import org.w3c.api.DOMTypeException; +import org.w3c.css.om.typed.CSSUnitValue; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; + +import io.sf.carte.doc.style.css.nsac.CSSParseException; +import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.doc.style.css.parser.CSSParser; +import io.sf.carte.doc.style.css.parser.ParseHelper; +import io.sf.carte.doc.style.css.property.NumberValue; /** * This class represents float values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + * @author See Git history. * @version $Id$ */ -public class FloatValue extends AbstractValue { +public class FloatValue extends NumericValue implements CSSUnitValue { /** * Returns the CSS text associated with the given type/value pair. */ public static String getCssText(short unit, float value) { - if (unit < 0 || unit >= UNITS.length) { + if (unit == CSSUnit.CSS_INVALID) { throw new DOMException(DOMException.SYNTAX_ERR, ""); } String s = String.valueOf(value); if (s.endsWith(".0")) { s = s.substring(0, s.length() - 2); } - return s + UNITS[unit - CSSPrimitiveValue.CSS_NUMBER]; + return s + CSSUnit.dimensionUnitString(unit); } - /** - * The unit types representations - */ - protected static final String[] UNITS = { "", "%", "em", "ex", "px", "cm", "mm", "in", "pt", "pc", "deg", "rad", - "grad", "ms", "s", "Hz", "kHz", "" }; - /** * The float value */ - protected float floatValue; + private float floatValue; /** * The unit type */ - protected short unitType; + private short unitType; /** * Creates a new value. @@ -72,7 +78,12 @@ public FloatValue(short unitType, float floatValue) { * The type of the value. */ @Override - public short getPrimitiveType() { + public Type getPrimitiveType() { + return Type.NUMERIC; + } + + @Override + public short getCSSUnit() { return unitType; } @@ -84,6 +95,29 @@ public float getFloatValue() { return floatValue; } + @Override + public double getValue() { + return floatValue; + } + + @Override + public void setValue(double value) { + this.floatValue = (float) value; + + if (handler != null) { + handler.valueChanged(this); + } + } + + public void setValue(String cssText) throws DOMException { + setCssText(cssText); + } + + @Override + public String getUnit() { + return CSSUnit.dimensionUnitString(unitType); + } + /** * A string representation of the current value. */ @@ -92,6 +126,44 @@ public String getCssText() { return getCssText(unitType, floatValue); } + @Override + public void setCssText(String cssText) throws DOMException { + CSSParser parser = new CSSParser(); + try { + LexicalUnit lu = parser.parsePropertyValue(new StringReader(cssText)); + if (lu.getNextLexicalUnit() != null) { + throw new DOMSyntaxException("Invalid number " + cssText); + } + switch (lu.getLexicalUnitType()) { + case INTEGER: + floatValue = lu.getIntegerValue(); + unitType = CSSUnit.CSS_NUMBER; + break; + case REAL: + floatValue = lu.getFloatValue(); + unitType = CSSUnit.CSS_NUMBER; + break; + case PERCENTAGE: + floatValue = lu.getFloatValue(); + unitType = CSSUnit.CSS_PERCENTAGE; + break; + case DIMENSION: + floatValue = lu.getFloatValue(); + unitType = lu.getCssUnit(); + break; + default: + throw new DOMTypeException("Invalid unit value: " + cssText); + } + } catch (IOException e) { + } catch (CSSParseException e) { + throw new DOMSyntaxException(e); + } + + if (handler != null) { + handler.valueChanged(this); + } + } + /** * Returns a printable representation of this value. */ @@ -100,4 +172,103 @@ public String toString() { return getCssText(); } + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Objects.hash(floatValue, unitType); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (!(obj instanceof Value)) + return false; + Value other = (Value) obj; + return other.getCSSUnit() == unitType + && Float.floatToIntBits(floatValue) == Float.floatToIntBits(other.getFloatValue()); + } + + @Override + public CSSUnitValue to(String unit) { + short destUnit = ParseHelper.unitFromString(unit); + float destValue = NumberValue.floatValueConversion(floatValue, unitType, destUnit); + FloatValue toVal = new FloatValue(destUnit, destValue); + return toVal; + } + + @Override + public CSSNumericType type() { + return new NumericType(); + } + + class NumericType implements CSSNumericType { + + @Override + public int getLength() { + return CSSUnit.isLengthUnitType(unitType) ? 1 : 0; + } + + @Override + public int getAngle() { + return CSSUnit.isAngleUnitType(unitType) ? 1 : 0; + } + + @Override + public int getTime() { + return CSSUnit.isTimeUnitType(unitType) ? 1 : 0; + } + + @Override + public int getFrequency() { + return unitType == CSSUnit.CSS_HZ || unitType == CSSUnit.CSS_KHZ ? 1 : 0; + } + + @Override + public int getResolution() { + return CSSUnit.isResolutionUnitType(unitType) ? 1 : 0; + } + + @Override + public int getFlex() { + return unitType == CSSUnit.CSS_FR ? 1 : 0; + } + + @Override + public int getPercent() { + return unitType == CSSUnit.CSS_PERCENTAGE ? 1 : 0; + } + + @Override + public CSSNumericBaseType getPercentHint() { + CSSNumericBaseType baseType = null; + if (CSSUnit.isLengthUnitType(unitType)) { + baseType = CSSNumericBaseType.length; + } else if (unitType == CSSUnit.CSS_PERCENTAGE) { + baseType = CSSNumericBaseType.percent; + } else if (CSSUnit.isTimeUnitType(unitType)) { + baseType = CSSNumericBaseType.time; + } else if (CSSUnit.isAngleUnitType(unitType)) { + baseType = CSSNumericBaseType.angle; + } else if (CSSUnit.isResolutionUnitType(unitType)) { + baseType = CSSNumericBaseType.resolution; + } else if (unitType == CSSUnit.CSS_HZ || unitType == CSSUnit.CSS_KHZ) { + baseType = CSSNumericBaseType.frequency; + } else if (unitType == CSSUnit.CSS_FR) { + baseType = CSSNumericBaseType.flex; + } + return baseType; + } + + } + + @Override + public FloatValue clone() { + return new FloatValue(unitType, floatValue); + } + } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/IdentValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/IdentValue.java new file mode 100644 index 000000000..b83fad064 --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/IdentValue.java @@ -0,0 +1,85 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import org.w3c.css.om.typed.CSSKeywordValue; + +import io.sf.carte.doc.style.css.parser.ParseHelper; + +/** + * Identifier values. + * + * @author See Git history. + * @version $Id$ + */ +public class IdentValue extends AbstractStringValue implements CSSKeywordValue { + + /** + * Creates a new IdentValue. + */ + public IdentValue(String s) { + super(s); + } + + /** + * The type of the value. + */ + @Override + public Type getPrimitiveType() { + return Type.IDENT; + } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param obj the reference object with which to compare. + */ + @Override + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof Value)) { + return false; + } + Value v = (Value) obj; + return v.getPrimitiveType() == Type.IDENT && value.equals(v.getIdentifierValue()); + } + + /** + * A string representation of the current value. + */ + @Override + public String getCssText() { + return ParseHelper.escape(value); + } + + @Override + public String getIdentifierValue() { + return value; + } + + @Override + public String getStringValue() { + return value; + } + + @Override + public IdentValue clone() { + return new IdentValue(value); + } + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/IdentifierManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/IdentifierManager.java index 5185fb45f..2b54976c6 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/IdentifierManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/IdentifierManager.java @@ -18,18 +18,22 @@ */ package io.sf.carte.echosvg.css.engine.value; +import java.util.Locale; + import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; /** * This class provides a manager for the property with support for identifier * values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public abstract class IdentifierManager extends AbstractValueManager { @@ -44,7 +48,7 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return ValueConstants.INHERIT_VALUE; case IDENT: - String s = lu.getStringValue().toLowerCase().intern(); + String s = lu.getStringValue().toLowerCase(Locale.ROOT).intern(); Object v = getIdentifiers().get(s); if (v == null) { throw createInvalidIdentifierDOMException(lu.getStringValue()); @@ -56,15 +60,12 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { } } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { - if (type != CSSPrimitiveValue.CSS_IDENT) { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { + if (type != Type.IDENT) { throw createInvalidStringTypeDOMException(type); } - Object v = getIdentifiers().get(value.toLowerCase().intern()); + Object v = getIdentifiers().get(value.toLowerCase(Locale.ROOT).intern()); if (v == null) { throw createInvalidIdentifierDOMException(value); } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/InheritValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/InheritValue.java index acc026f0a..3b036b598 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/InheritValue.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/InheritValue.java @@ -18,16 +18,19 @@ */ package io.sf.carte.echosvg.css.engine.value; -import org.w3c.dom.css.CSSValue; +import org.w3c.api.DOMTypeException; +import org.w3c.css.om.typed.CSSKeywordValue; /** * This singleton class represents the 'inherit' value. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ -public class InheritValue extends AbstractValue { +public class InheritValue extends AbstractValue implements CSSKeywordValue { /** * The only instance of this class. @@ -45,15 +48,35 @@ protected InheritValue() { */ @Override public String getCssText() { + return getValue(); + } + + @Override + public String getValue() { return "inherit"; } + @Override + public void setValue(String value) throws DOMTypeException { + throw new DOMTypeException("Not supported."); + } + /** * A code defining the type of the value. */ @Override - public short getCssValueType() { - return CSSValue.CSS_INHERIT; + public CssType getCssValueType() { + return CssType.KEYWORD; + } + + @Override + public Type getPrimitiveType() { + return Type.INHERIT; + } + + @Override + public InheritValue clone() { + return INSTANCE; } /** diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/LCHColorValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/LCHColorValue.java new file mode 100644 index 000000000..52d79fa6b --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/LCHColorValue.java @@ -0,0 +1,207 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import org.w3c.api.DOMSyntaxException; +import org.w3c.css.om.typed.CSSLCH; +import org.w3c.css.om.typed.CSSNumericValue; +import org.w3c.dom.DOMException; + +import org.w3c.css.om.unit.CSSUnit; +import io.sf.carte.echosvg.css.engine.value.svg.SVGValueConstants; + +/** + * LCH colors. + * + * @version $Id$ + */ +public class LCHColorValue extends ColorValue implements CSSLCH { + + /** + * The lightness component. + */ + protected NumericValue l; + + /** + * The chroma component. + */ + protected NumericValue c; + + /** + * The hue component. + */ + protected NumericValue h; + + /** + * Creates a new, opaque LCHColorValue. + * + * @throws DOMSyntaxException if a supplied component is invalid. + */ + public LCHColorValue(NumericValue l, NumericValue c, NumericValue h) throws DOMSyntaxException { + this(l, c, h, SVGValueConstants.NUMBER_1); + } + + /** + * Creates a new LCHColorValue. + * + * @throws DOMSyntaxException if a supplied component is invalid. + */ + public LCHColorValue(NumericValue l, NumericValue c, NumericValue h, NumericValue alpha) + throws DOMSyntaxException { + super(alpha); + setL(l); + setC(c); + setH(h); + } + + @Override + public String getCSSColorSpace() { + return ColorValue.LCH; + } + + @Override + public String getCssText() { + StringBuilder buf = new StringBuilder(); + buf.append("lch(").append(l.getCssText()).append(' ').append(c.getCssText()).append(' ') + .append(h.getCssText()); + if (!isOpaque()) { + buf.append(' ').append(getAlpha().getCssText()); + } + buf.append(')'); + return buf.toString(); + } + + @Override + public NumericValue getL() { + return l; + } + + @Override + public NumericValue getC() { + return c; + } + + @Override + public NumericValue getH() { + return h; + } + + @Override + public void setL(double lightness) { + l = new FloatValue(CSSUnit.CSS_PERCENTAGE, (float) lightness); + componentize(l); + componentChanged(l); + } + + @Override + public void setL(CSSNumericValue lightness) throws DOMSyntaxException { + l = component(lightness); + componentChanged(l); + } + + /** + * Initialize a component of this value. + * + * @param c the component. + * @return the initialized component. + * @throws DOMSyntaxException if the value is inadequate for a component. + */ + private NumericValue component(CSSNumericValue c) throws DOMSyntaxException { + NumericValue ch = (NumericValue) c; + if (ch.getCSSUnit() != CSSUnit.CSS_PERCENTAGE && ch.getCSSUnit() != CSSUnit.CSS_NUMBER) { + throw new DOMSyntaxException("LC component must be a number or percentage."); + } + if (ch.handler != null) { + ch = ch.clone(); + } + componentize(ch); + return ch; + } + + @Override + public void setC(double c) { + this.c = new FloatValue(CSSUnit.CSS_PERCENTAGE, (float) c); + componentize(this.c); + componentChanged(this.c); + } + + @Override + public void setC(CSSNumericValue c) throws DOMSyntaxException { + this.c = component(c); + componentChanged(this.c); + } + + @Override + public void setH(double h) { + this.h = new FloatValue(CSSUnit.CSS_DEG, (float) h); + componentize(this.h); + componentChanged(this.h); + } + + @Override + public void setH(CSSNumericValue h) throws DOMSyntaxException { + this.h = hueComponent(h); + componentChanged(this.h); + } + + private NumericValue hueComponent(CSSNumericValue h) { + NumericValue ch = (NumericValue) h; + if (ch.getCSSUnit() != CSSUnit.CSS_NUMBER && !CSSUnit.isAngleUnitType(ch.getCSSUnit())) { + throw new DOMSyntaxException("Hue component must be a number or angle."); + } + if (ch.handler != null) { + ch = ch.clone(); + } + componentize(ch); + return ch; + } + + @Override + public int getLength() throws DOMException { + return 4; + } + + @Override + public Value item(int index) throws DOMException { + switch (index) { + case 0: + return getL(); + case 1: + return getC(); + case 2: + return getH(); + case 3: + return getAlpha(); + default: + return null; + } + } + + @Override + public LCHColorValue clone() { + LCHColorValue clon; + try { + clon = new LCHColorValue(l, c, h, alpha); + } catch (DOMSyntaxException e) { + clon = null; + } + return clon; + } + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/LabColorValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/LabColorValue.java new file mode 100644 index 000000000..edf8eb465 --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/LabColorValue.java @@ -0,0 +1,195 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import org.w3c.api.DOMSyntaxException; +import org.w3c.css.om.typed.CSSLab; +import org.w3c.css.om.typed.CSSNumericValue; +import org.w3c.dom.DOMException; + +import org.w3c.css.om.unit.CSSUnit; +import io.sf.carte.echosvg.css.engine.value.svg.SVGValueConstants; + +/** + * Lab colors. + * + * @version $Id$ + */ +public class LabColorValue extends ColorValue implements CSSLab { + + /** + * The lightness component. + */ + protected NumericValue l; + + /** + * The a component. + */ + protected NumericValue a; + + /** + * The b component. + */ + protected NumericValue b; + + /** + * Creates a new, opaque LabColorValue. + * + * @throws DOMSyntaxException if a supplied component is invalid. + */ + public LabColorValue(NumericValue l, NumericValue a, NumericValue b) throws DOMSyntaxException { + this(l, a, b, SVGValueConstants.NUMBER_1); + } + + /** + * Creates a new LabColorValue. + * + * @throws DOMSyntaxException if a supplied component is invalid. + */ + public LabColorValue(NumericValue l, NumericValue a, NumericValue b, NumericValue alpha) + throws DOMSyntaxException { + super(alpha); + setL(l); + setA(a); + setB(b); + } + + @Override + public String getCSSColorSpace() { + return ColorValue.LAB; + } + + @Override + public String getCssText() { + StringBuilder buf = new StringBuilder(); + buf.append("lab(").append(l.getCssText()).append(' ').append(a.getCssText()).append(' ') + .append(b.getCssText()); + if (!isOpaque()) { + buf.append(' ').append(getAlpha().getCssText()); + } + buf.append(')'); + return buf.toString(); + } + + @Override + public NumericValue getL() { + return l; + } + + @Override + public NumericValue getA() { + return a; + } + + @Override + public NumericValue getB() { + return b; + } + + @Override + public void setL(double lightness) { + l = new FloatValue(CSSUnit.CSS_PERCENTAGE, (float) lightness); + componentize(l); + componentChanged(l); + } + + @Override + public void setL(CSSNumericValue lightness) throws DOMSyntaxException { + l = component(lightness); + componentChanged(l); + } + + /** + * Initialize a component of this value. + * + * @param c the component. + * @return the initialized component. + * @throws DOMSyntaxException if the value is inadequate for a component. + */ + private NumericValue component(CSSNumericValue c) throws DOMSyntaxException { + NumericValue ch = (NumericValue) c; + if (ch.getCSSUnit() != CSSUnit.CSS_PERCENTAGE && ch.getCSSUnit() != CSSUnit.CSS_NUMBER) { + throw new DOMSyntaxException("Lab component must be a number or percentage."); + } + if (ch.handler != null) { + ch = ch.clone(); + } + componentize(ch); + return ch; + } + + @Override + public void setA(double a) { + this.a = new FloatValue(CSSUnit.CSS_NUMBER, (float) a); + componentize(this.a); + componentChanged(this.a); + } + + @Override + public void setA(CSSNumericValue a) throws DOMSyntaxException { + this.a = component(a); + componentChanged(this.a); + } + + @Override + public void setB(double b) { + this.b = new FloatValue(CSSUnit.CSS_NUMBER, (float) b); + componentize(this.b); + componentChanged(this.b); + } + + @Override + public void setB(CSSNumericValue b) throws DOMSyntaxException { + this.b = component(b); + componentChanged(this.b); + } + + @Override + public int getLength() throws DOMException { + return 4; + } + + @Override + public Value item(int index) throws DOMException { + switch (index) { + case 0: + return getL(); + case 1: + return getA(); + case 2: + return getB(); + case 3: + return getAlpha(); + default: + return null; + } + } + + @Override + public LabColorValue clone() { + LabColorValue clon; + try { + clon = new LabColorValue(l, a, b, alpha); + } catch (DOMSyntaxException e) { + clon = null; + } + return clon; + } + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/LengthManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/LengthManager.java index a0927f152..153e68e82 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/LengthManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/LengthManager.java @@ -19,11 +19,11 @@ package io.sf.carte.echosvg.css.engine.value; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; -import io.sf.carte.doc.style.css.CSSUnit; +import org.w3c.css.om.unit.CSSUnit; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.doc.style.css.property.NumberValue; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSContext; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; @@ -33,8 +33,10 @@ * This class provides a manager for the property with support for length * values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public abstract class LengthManager extends AbstractValueManager { @@ -58,51 +60,22 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { break; case INTEGER: - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getIntegerValue()); + return new FloatValue(CSSUnit.CSS_NUMBER, lu.getIntegerValue()); case REAL: - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getFloatValue()); + return new FloatValue(CSSUnit.CSS_NUMBER, lu.getFloatValue()); case PERCENTAGE: - return new FloatValue(CSSPrimitiveValue.CSS_PERCENTAGE, lu.getFloatValue()); + return new FloatValue(CSSUnit.CSS_PERCENTAGE, lu.getFloatValue()); default: break; } throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); } - static Value createLength(LexicalUnit lu) { + static FloatValue createLength(LexicalUnit lu) { if (CSSUnit.isLengthUnitType(lu.getCssUnit())) { - short omUnit; - switch (lu.getCssUnit()) { - case CSSUnit.CSS_PX: - omUnit = CSSPrimitiveValue.CSS_PX; - break; - case CSSUnit.CSS_IN: - omUnit = CSSPrimitiveValue.CSS_IN; - break; - case CSSUnit.CSS_PC: - omUnit = CSSPrimitiveValue.CSS_PC; - break; - case CSSUnit.CSS_PT: - omUnit = CSSPrimitiveValue.CSS_PT; - break; - case CSSUnit.CSS_CM: - omUnit = CSSPrimitiveValue.CSS_CM; - break; - case CSSUnit.CSS_MM: - omUnit = CSSPrimitiveValue.CSS_MM; - break; - case CSSUnit.CSS_EM: - omUnit = CSSPrimitiveValue.CSS_EMS; - break; - case CSSUnit.CSS_EX: - omUnit = CSSPrimitiveValue.CSS_EXS; - break; - default: - return null; - } - return new FloatValue(omUnit, lu.getFloatValue()); + return new FloatValue(lu.getCssUnit(), lu.getFloatValue()); } return null; } @@ -113,16 +86,16 @@ static Value createLength(LexicalUnit lu) { @Override public Value createFloatValue(short type, float floatValue) throws DOMException { switch (type) { - case CSSPrimitiveValue.CSS_PERCENTAGE: - case CSSPrimitiveValue.CSS_EMS: - case CSSPrimitiveValue.CSS_EXS: - case CSSPrimitiveValue.CSS_PX: - case CSSPrimitiveValue.CSS_CM: - case CSSPrimitiveValue.CSS_MM: - case CSSPrimitiveValue.CSS_IN: - case CSSPrimitiveValue.CSS_PT: - case CSSPrimitiveValue.CSS_PC: - case CSSPrimitiveValue.CSS_NUMBER: + case CSSUnit.CSS_PERCENTAGE: + case CSSUnit.CSS_EM: + case CSSUnit.CSS_EX: + case CSSUnit.CSS_PX: + case CSSUnit.CSS_CM: + case CSSUnit.CSS_MM: + case CSSUnit.CSS_IN: + case CSSUnit.CSS_PT: + case CSSUnit.CSS_PC: + case CSSUnit.CSS_NUMBER: return new FloatValue(type, floatValue); } throw createInvalidFloatTypeDOMException(type); @@ -135,58 +108,59 @@ public Value createFloatValue(short type, float floatValue) throws DOMException @Override public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { - if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) { + if (value.getPrimitiveType() != Type.NUMERIC) { return value; } - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_NUMBER: - case CSSPrimitiveValue.CSS_PX: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_NUMBER: + case CSSUnit.CSS_PX: return value; - case CSSPrimitiveValue.CSS_MM: + case CSSUnit.CSS_MM: CSSContext ctx = engine.getCSSContext(); float v = value.getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v / ctx.getPixelUnitToMillimeter()); + return new FloatValue(CSSUnit.CSS_NUMBER, v / ctx.getPixelUnitToMillimeter()); - case CSSPrimitiveValue.CSS_CM: + case CSSUnit.CSS_CM: ctx = engine.getCSSContext(); v = value.getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v * 10f / ctx.getPixelUnitToMillimeter()); + return new FloatValue(CSSUnit.CSS_NUMBER, v * 10f / ctx.getPixelUnitToMillimeter()); - case CSSPrimitiveValue.CSS_IN: + case CSSUnit.CSS_IN: ctx = engine.getCSSContext(); v = value.getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v * 25.4f / ctx.getPixelUnitToMillimeter()); + return new FloatValue(CSSUnit.CSS_NUMBER, v * 25.4f / ctx.getPixelUnitToMillimeter()); - case CSSPrimitiveValue.CSS_PT: + case CSSUnit.CSS_PT: ctx = engine.getCSSContext(); v = value.getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v * 25.4f / (72f * ctx.getPixelUnitToMillimeter())); + return new FloatValue(CSSUnit.CSS_NUMBER, v * 25.4f / (72f * ctx.getPixelUnitToMillimeter())); - case CSSPrimitiveValue.CSS_PC: + case CSSUnit.CSS_PC: ctx = engine.getCSSContext(); v = value.getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, (v * 25.4f / (6f * ctx.getPixelUnitToMillimeter()))); + return new FloatValue(CSSUnit.CSS_NUMBER, (v * 25.4f / (6f * ctx.getPixelUnitToMillimeter()))); - case CSSPrimitiveValue.CSS_EMS: + case CSSUnit.CSS_EM: sm.putFontSizeRelative(idx, true); v = value.getFloatValue(); int fsidx = engine.getFontSizeIndex(); - float fs; - fs = engine.getComputedStyle(elt, pseudo, fsidx).getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v * fs); + Value cv = engine.getComputedStyle(elt, pseudo, fsidx); + float fs = lengthValue(cv); + return new FloatValue(CSSUnit.CSS_NUMBER, v * fs); - case CSSPrimitiveValue.CSS_EXS: + case CSSUnit.CSS_EX: sm.putFontSizeRelative(idx, true); v = value.getFloatValue(); fsidx = engine.getFontSizeIndex(); - fs = engine.getComputedStyle(elt, pseudo, fsidx).getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v * fs * 0.5f); + cv = engine.getComputedStyle(elt, pseudo, fsidx); + fs = lengthValue(cv); + return new FloatValue(CSSUnit.CSS_NUMBER, v * fs * 0.5f); - case CSSPrimitiveValue.CSS_PERCENTAGE: + case CSSUnit.CSS_PERCENTAGE: ctx = engine.getCSSContext(); switch (getOrientation()) { case HORIZONTAL_ORIENTATION: @@ -204,8 +178,18 @@ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engin double h = ctx.getBlockHeight(elt); fs = (float) (value.getFloatValue() * (Math.sqrt(w * w + h * h) / SQRT2) / 100.0); } - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, fs); + return new FloatValue(CSSUnit.CSS_NUMBER, fs); + case CSSUnit.CSS_INVALID: + break; + default: + // Maybe it is one of the new absolute length units + try { + value = new FloatValue(CSSUnit.CSS_NUMBER, + NumberValue.floatValueConversion(value.getFloatValue(), value.getCSSUnit(), CSSUnit.CSS_PX)); + } catch (DOMException e) { + } } + return value; } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ListValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ListValue.java index 7ea0db5b8..d6aabf205 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ListValue.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ListValue.java @@ -18,111 +18,39 @@ */ package io.sf.carte.echosvg.css.engine.value; -import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSValue; - /** * This class represents a list of values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + * @author See Git history. * @version $Id$ */ -public class ListValue extends AbstractValue { - - /** - * The length of the list. - */ - protected int length; - - /** - * The items. - */ - protected Value[] items = new Value[5]; - - /** - * The list separator. - */ - protected char separator = ','; - +public class ListValue extends AbstractValueList { /** * Creates a ListValue. */ public ListValue() { + super(','); } /** * Creates a ListValue with the given separator. */ public ListValue(char s) { - separator = s; - } - - /** - * Returns the separator used for this list. - */ - public char getSeparatorChar() { - return separator; - } - - /** - * Implements {@link Value#getCssValueType()}. - */ - @Override - public short getCssValueType() { - return CSSValue.CSS_VALUE_LIST; - } - - /** - * A string representation of the current value. - */ - @Override - public String getCssText() { - StringBuilder sb = new StringBuilder(length * 8); - if (length > 0) { - sb.append(items[0].getCssText()); - } - for (int i = 1; i < length; i++) { - sb.append(separator); - sb.append(items[i].getCssText()); - } - return sb.toString(); - } - - /** - * Implements {@link Value#getLength()}. - */ - @Override - public int getLength() throws DOMException { - return length; - } - - /** - * Implements {@link Value#item(int)}. - */ - @Override - public Value item(int index) throws DOMException { - return items[index]; + super(s); } /** - * Returns a printable representation of this value. + * Creates a ListValue with the given separator. */ - @Override - public String toString() { - return getCssText(); + ListValue(char s, int initialCapacity) { + super(s, initialCapacity); } /** * Appends an item to the list. */ public void append(Value v) { - if (length == items.length) { - Value[] t = new Value[length * 2]; - System.arraycopy(items, 0, t, 0, length); - items = t; - } - items[length++] = v; + add(v); } } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/NumericValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/NumericValue.java new file mode 100644 index 000000000..24568e3b5 --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/NumericValue.java @@ -0,0 +1,41 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +import org.w3c.css.om.typed.CSSNumericValue; + +/** + * Base class for numeric values. + * + * @author See Git history. + * @version $Id$ + */ +public abstract class NumericValue extends AbstractValue implements CSSNumericValue { + + /** + * Creates a new value. + */ + public NumericValue() { + super(); + } + + @Override + public abstract NumericValue clone(); + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/RGBColorValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/RGBColorValue.java index b1c86e4f5..b74456ef8 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/RGBColorValue.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/RGBColorValue.java @@ -18,63 +18,81 @@ */ package io.sf.carte.echosvg.css.engine.value; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Locale; + +import org.w3c.api.DOMSyntaxException; +import org.w3c.css.om.typed.CSSNumericValue; +import org.w3c.css.om.typed.CSSRGB; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.echosvg.css.engine.value.svg.SVGValueConstants; /** - * This class represents RGB colors. + * RGB colors. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + * @author See Git history. * @version $Id$ */ -public class RGBColorValue extends AbstractValue { +public class RGBColorValue extends ColorValue implements CSSRGB { /** * The red component. */ - protected Value red; + private NumericValue red; /** * The green component. */ - protected Value green; + private NumericValue green; /** * The blue component. */ - protected Value blue; + private NumericValue blue; /** - * The alpha channel. + * Whether components were specified as percentages */ - protected Value alpha; + private transient boolean pcntSpecified; + + private transient boolean alphaPcntSpecified; /** * Creates a new, opaque RGBColorValue. + * + * @throws DOMSyntaxException if a supplied component is invalid. */ - public RGBColorValue(Value r, Value g, Value b) { + public RGBColorValue(NumericValue r, NumericValue g, NumericValue b) throws DOMSyntaxException { this(r, g, b, SVGValueConstants.NUMBER_1); } /** * Creates a new RGBColorValue. + * + * @throws DOMSyntaxException if a supplied component is invalid. */ - public RGBColorValue(Value r, Value g, Value b, Value a) { - red = r; - green = g; - blue = b; - alpha = a; + public RGBColorValue(NumericValue r, NumericValue g, NumericValue b, NumericValue a) + throws DOMSyntaxException { + super(a); + setR(r); + setG(g); + setB(b); + } + + void setSpecifiedAsPercentage(boolean spec) { + pcntSpecified = spec; + } + + void setAlphaSpecifiedAsPercentage(boolean spec) { + alphaPcntSpecified = spec; } - /** - * The type of the value. - */ @Override - public short getPrimitiveType() { - return CSSPrimitiveValue.CSS_RGBCOLOR; + public String getCSSColorSpace() { + return ColorValue.RGB_FUNCTION; } /** @@ -82,52 +100,189 @@ public short getPrimitiveType() { */ @Override public String getCssText() { - return toString(red.getCssText(), green.getCssText(), blue.getCssText(), alpha.getCssText()); + DecimalFormat df = null; + if (!pcntSpecified || !alphaPcntSpecified) { + DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.ROOT); + df = new DecimalFormat("#.#", dfs); + df.setMinimumFractionDigits(0); + df.setMaximumFractionDigits(4); + } + + String sr = rgbComponentText(red, df); + String sg = rgbComponentText(green, df); + String sb = rgbComponentText(blue, df); + + StringBuilder buf = new StringBuilder(sr.length() + sg.length() + sb.length() + 16); + boolean opaque = isOpaque(); + if (opaque) { + buf.append("rgb("); + } else { + buf.append("rgba("); + } + buf.append(sr).append(", ").append(sg).append(", ").append(sb); + if (!opaque) { + buf.append(", ").append(alphaComponentText(alpha, df)); + } + buf.append(')'); + return buf.toString(); + } + + private String rgbComponentText(NumericValue comp, DecimalFormat df) { + if (pcntSpecified || comp.getCSSUnit() == CSSUnit.CSS_NUMBER) { + return comp.getCssText(); + } + + return df.format(comp.getFloatValue() * 2.55f); + } + + private String alphaComponentText(NumericValue alpha, DecimalFormat df) { + if (alphaPcntSpecified || alpha.getCSSUnit() == CSSUnit.CSS_NUMBER) { + return alpha.getCssText(); + } + + return df.format(alpha.getFloatValue() * 0.01f); + } + + @Override + public RGBColorValue getColorValue() { + return this; + } + + @Override + public NumericValue getR() { + return red; + } + + @Override + public NumericValue getG() { + return green; + } + + @Override + public NumericValue getB() { + return blue; } /** - * Implements {@link Value#getRed()}. + * Get the red component. + * + * @return the red component. */ - @Override - public Value getRed() throws DOMException { + public Value getRed() { return red; } /** - * Implements {@link Value#getGreen()}. + * Get the green component. + * + * @return the green component. */ - @Override - public Value getGreen() throws DOMException { + public Value getGreen() { return green; } /** - * Implements {@link Value#getBlue()}. + * Get the blue component. + * + * @return the blue component. */ - @Override - public Value getBlue() throws DOMException { + public Value getBlue() { return blue; } @Override - public Value getAlpha() throws DOMException { - return alpha; + public void setR(double r) { + red = new FloatValue(CSSUnit.CSS_PERCENTAGE, (float) r * 100); + pcntSpecified = true; + componentize(red); + componentChanged(red); + } + + @Override + public void setR(CSSNumericValue r) throws DOMSyntaxException { + red = component(r); + componentChanged(red); + pcntSpecified = red.getCSSUnit() == CSSUnit.CSS_PERCENTAGE; } /** - * Returns a printable representation of the color. + * Initialize a component of this value. + * + * @param c the component. + * @return the initialized component. + * @throws DOMSyntaxException if the value is inadequate for a component. */ + private NumericValue component(CSSNumericValue c) throws DOMSyntaxException { + NumericValue ch = (NumericValue) c; + if (ch.getCSSUnit() != CSSUnit.CSS_PERCENTAGE && ch.getCSSUnit() != CSSUnit.CSS_NUMBER) { + throw new DOMSyntaxException("RGB component must be a number or percentage, not a " + + CSSUnit.dimensionUnitString(ch.getCSSUnit()) + '.'); + } + if (ch.handler != null) { + ch = ch.clone(); + } + componentize(ch); + return ch; + } + @Override - public String toString() { - return getCssText(); + public void setG(double g) { + green = new FloatValue(CSSUnit.CSS_PERCENTAGE, (float) g * 100); + pcntSpecified = true; + componentize(green); + componentChanged(green); } - public static String toString(String red, String green, String blue, String alpha) { - if ("1".equals(alpha)) { - return "rgb(" + red + ", " + green + ", " + blue + ')'; - } else { - return "rgba(" + red + ", " + green + ", " + blue + ", " + alpha + ')'; + @Override + public void setG(CSSNumericValue g) throws DOMSyntaxException { + green = component(g); + componentChanged(green); + } + + @Override + public void setB(double b) { + blue = new FloatValue(CSSUnit.CSS_PERCENTAGE, (float) b * 100); + pcntSpecified = true; + componentize(blue); + componentChanged(blue); + } + + @Override + public void setB(CSSNumericValue b) throws DOMSyntaxException { + blue = component(b); + componentChanged(blue); + } + + @Override + public int getLength() throws DOMException { + return 4; + } + + @Override + public Value item(int index) throws DOMException { + switch (index) { + case 0: + return getR(); + case 1: + return getG(); + case 2: + return getB(); + case 3: + return getAlpha(); + default: + return null; + } + } + + @Override + public RGBColorValue clone() { + RGBColorValue clon; + try { + clon = new RGBColorValue(red, green, blue, alpha); + } catch (DOMSyntaxException e) { + clon = null; } + return clon; } } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/RectManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/RectManager.java index 9e54138a5..e816010c4 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/RectManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/RectManager.java @@ -18,11 +18,11 @@ */ package io.sf.carte.echosvg.css.engine.value; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.StyleMap; @@ -31,8 +31,11 @@ /** * This class provides a manager for the property with support for rect values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

+ * * @version $Id$ */ public abstract class RectManager extends LengthManager { @@ -88,17 +91,17 @@ private Value createRectComponent(LexicalUnit lu) throws DOMException { } break; case DIMENSION: - Value value = createLength(lu); + NumericValue value = createLength(lu); if (value != null) { return value; } break; case INTEGER: - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getIntegerValue()); + return new FloatValue(CSSUnit.CSS_NUMBER, lu.getIntegerValue()); case REAL: - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getFloatValue()); + return new FloatValue(CSSUnit.CSS_NUMBER, lu.getFloatValue()); case PERCENTAGE: - return new FloatValue(CSSPrimitiveValue.CSS_PERCENTAGE, lu.getFloatValue()); + return new FloatValue(CSSUnit.CSS_PERCENTAGE, lu.getFloatValue()); default: break; } @@ -112,13 +115,11 @@ private Value createRectComponent(LexicalUnit lu) throws DOMException { @Override public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { - if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) { + if (value.getPrimitiveType() != Type.RECT) { return value; } - if (value.getPrimitiveType() != CSSPrimitiveValue.CSS_RECT) { - return value; - } - RectValue rect = (RectValue) value; + + RectValue rect = value.getRectValue(); orientation = VERTICAL_ORIENTATION; Value top = super.computeValue(elt, pseudo, engine, idx, sm, rect.getTop()); @@ -126,7 +127,8 @@ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engin orientation = HORIZONTAL_ORIENTATION; Value left = super.computeValue(elt, pseudo, engine, idx, sm, rect.getLeft()); Value right = super.computeValue(elt, pseudo, engine, idx, sm, rect.getRight()); - if (top != rect.getTop() || right != rect.getRight() || bottom != rect.getBottom() || left != rect.getLeft()) { + if (top != rect.getTop() || right != rect.getRight() || bottom != rect.getBottom() + || left != rect.getLeft()) { return new RectValue(top, right, bottom, left); } else { return value; diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/RectValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/RectValue.java index 14f01aa9b..9505cba4a 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/RectValue.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/RectValue.java @@ -18,17 +18,22 @@ */ package io.sf.carte.echosvg.css.engine.value; +import org.w3c.api.DOMSyntaxException; +import org.w3c.css.om.typed.CSSRectValue; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; + +import org.w3c.css.om.unit.CSSUnit; /** * This class represents CSS rect values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ -public class RectValue extends AbstractValue { +public class RectValue extends ComponentValue implements CSSRectValue { /** * The top value. @@ -54,18 +59,18 @@ public class RectValue extends AbstractValue { * Creates a new Rect value. */ public RectValue(Value t, Value r, Value b, Value l) { - top = t; - right = r; - bottom = b; - left = l; + setTop(t); + setRight(r); + setBottom(b); + setLeft(l); } /** * The type of the value. */ @Override - public short getPrimitiveType() { - return CSSPrimitiveValue.CSS_RECT; + public Type getPrimitiveType() { + return Type.RECT; } /** @@ -77,44 +82,94 @@ public String getCssText() { + left.getCssText() + ')'; } - /** - * Implements {@link Value#getTop()}. - */ @Override public Value getTop() throws DOMException { return top; } - /** - * Implements {@link Value#getRight()}. - */ @Override public Value getRight() throws DOMException { return right; } - /** - * Implements {@link Value#getBottom()}. - */ @Override public Value getBottom() throws DOMException { return bottom; } - /** - * Implements {@link Value#getLeft()}. - */ @Override public Value getLeft() throws DOMException { return left; } + void setTop(Value top) { + this.top = component(top); + } + /** - * Returns a printable representation of this value. + * Initialize a component of this value. + * + * @param c the component. + * @return the initialized component. + * @throws DOMSyntaxException if the value is inadequate for a component. */ + Value component(Value c) throws DOMSyntaxException { + short unit = c.getCSSUnit(); + if (unit != CSSUnit.CSS_PERCENTAGE && unit != CSSUnit.CSS_NUMBER + && !CSSUnit.isLengthUnitType(unit) && c.getPrimitiveType() != Type.IDENT) { + throw new DOMSyntaxException("rect() component must be a length or percentage."); + } + + if (c.getModificationHandler() != null) { + c = ((AbstractValue) c).clone(); + } + componentize(c); + + return c; + } + + void setRight(Value right) { + this.right = component(right); + } + + void setBottom(Value bottom) { + this.bottom = component(bottom); + } + + void setLeft(Value left) { + this.left = component(left); + } + + @Override + public RectValue getRectValue() throws DOMException { + return this; + } + + @Override + public int getLength() throws DOMException { + return 4; + } + + @Override + public Value item(int index) throws DOMException { + switch (index) { + case 0: + return getTop(); + case 1: + return getRight(); + case 2: + return getBottom(); + case 3: + return getLeft(); + default: + return null; + } + } + @Override - public String toString() { - return getCssText(); + public RectValue clone() { + RectValue clon = new RectValue(top, right, bottom, left); + return clon; } } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/StringValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/StringValue.java index 478fab143..47706e301 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/StringValue.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/StringValue.java @@ -18,64 +18,44 @@ */ package io.sf.carte.echosvg.css.engine.value; -import java.util.Objects; +import org.w3c.css.om.typed.CSSStringValue; -import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; +import io.sf.carte.doc.style.css.parser.ParseHelper; /** * This class represents string values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ -public class StringValue extends AbstractValue { - - /** - * Returns the CSS text associated with the given type/value pair. - */ - public static String getCssText(short type, String value) { - switch (type) { - case CSSPrimitiveValue.CSS_URI: - return "url(" + value + ')'; - - case CSSPrimitiveValue.CSS_STRING: - char q = (value.indexOf('"') != -1) ? '\'' : '"'; - return q + value + q; - } - return value; - } - - /** - * The value of the string - */ - protected String value; - - /** - * The unit type - */ - protected short unitType; +public class StringValue extends AbstractStringValue implements CSSStringValue { /** * Creates a new StringValue. */ - public StringValue(short type, String s) { - unitType = type; - value = s; + public StringValue(String s) { + super(s); } /** * The type of the value. */ @Override - public short getPrimitiveType() { - return unitType; + public Type getPrimitiveType() { + return Type.STRING; + } + + @Override + public String getStringValue() { + return value; } @Override - public int hashCode() { - return Objects.hash(unitType, value); + public String getURIValue() { + return value; } /** @@ -85,14 +65,11 @@ public int hashCode() { */ @Override public boolean equals(Object obj) { - if (obj == null || !(obj instanceof StringValue)) { + if (obj == null || !(obj instanceof Value)) { return false; } - StringValue v = (StringValue) obj; - if (unitType != v.unitType) { - return false; - } - return value.equals(v.value); + Value v = (Value) obj; + return v.getPrimitiveType() == Type.STRING && value.equals(v.getStringValue()); } /** @@ -100,26 +77,12 @@ public boolean equals(Object obj) { */ @Override public String getCssText() { - return getCssText(unitType, value); - } - - /** - * This method is used to get the string value. - * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a string value. - */ - @Override - public String getStringValue() throws DOMException { - return value; + return ParseHelper.quote(value, '\''); } - /** - * Returns a printable representation of this value. - */ @Override - public String toString() { - return getCssText(); + public StringValue clone() { + return new StringValue(value); } } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/URIValue.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/URIValue.java index 130501e11..000614ece 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/URIValue.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/URIValue.java @@ -18,27 +18,56 @@ */ package io.sf.carte.echosvg.css.engine.value; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.w3c.css.om.typed.CSSStringValue; /** - * This class represents uri values. + * This class represents URI values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ -public class URIValue extends StringValue { +public class URIValue extends AbstractStringValue implements CSSStringValue { - String cssText; + private String cssText; /** - * Creates a new StringValue. + * Creates a new URIValue. */ - public URIValue(String cssText, String uri) { - super(CSSPrimitiveValue.CSS_URI, uri); + public URIValue(String cssText, String s) { + super(s); this.cssText = cssText; } + /** + * The type of the value. + */ + @Override + public Type getPrimitiveType() { + return Type.URI; + } + + @Override + public String getURIValue() { + return value; + } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param obj the reference object with which to compare. + */ + @Override + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof Value)) { + return false; + } + Value v = (Value) obj; + return v.getPrimitiveType() == Type.URI && value.equals(v.getURIValue()); + } + /** * A string representation of the current value. */ @@ -47,4 +76,9 @@ public String getCssText() { return "url(" + cssText + ')'; } + @Override + public URIValue clone() { + return new URIValue(cssText, value); + } + } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/Value.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/Value.java index f0ec16a1f..f0b961e7c 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/Value.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/Value.java @@ -18,153 +18,98 @@ */ package io.sf.carte.echosvg.css.engine.value; +import org.w3c.css.om.typed.CSSCounterValue; import org.w3c.dom.DOMException; +import io.sf.carte.echosvg.css.dom.CSSValue; + /** * This interface represents a property value. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + * @author See Git history. * @version $Id$ */ -public interface Value { - - /** - * A string representation of the current value. - */ - String getCssText(); - - /** - * A code defining the type of the value. - */ - short getCssValueType(); - - /** - * The type of the value. - */ - short getPrimitiveType(); - - /** - * This method is used to get the float value. - * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a float value. - */ - float getFloatValue() throws DOMException; - - /** - * This method is used to get the string value. - * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a string value. - */ - String getStringValue() throws DOMException; - - /** - * The red value of the RGB color. - * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a RGB color value. - */ - Value getRed() throws DOMException; - - /** - * The green value of the RGB color. - * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a RGB color value. - */ - Value getGreen() throws DOMException; - - /** - * The blue value of the RGB color. - * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a RGB color value. - */ - Value getBlue() throws DOMException; - - /** - * The alpha channel value of the RGBA color. - * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a RGB color value. - */ - Value getAlpha() throws DOMException; +public interface Value extends CSSValue { /** - * The number of CSSValues in the list. The range of valid values - * of the indices is 0 to length-1 inclusive. + * Convenience method that either returns an identifier or throws an exception. * * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a list value. + * contain an identifier value. + * @Deprecated use {@link #getgetIdentifierValue()} instead. */ - int getLength() throws DOMException; + @Deprecated + default String getIdentifier() throws DOMException { + return getIdentifierValue(); + } /** - * Used to retrieve a rule by ordinal index. + * If this value is a list, give the item corresponding to the requested index. + * If there is no item at such index, return {@code null} If this object is not + * a list and the index is {@code 0}, return itself. * - * @return The style rule at the index position in the list, or - * null if that is not a valid index. - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a list value. + * @param index the index on the list. + * @return the item, or {@code null} if there is no item on that index. */ - Value item(int index) throws DOMException; + @Override + default Value item(int index) { + return index == 0 ? this : null; + } /** - * The top value of the rect. + * If this value is a counter() or counters() value, get it. * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a Rect value. + * @return the counter() value. + * @throws DOMException INVALID_ACCESS_ERR if this is not a counter() or + * counters() value. */ - Value getTop() throws DOMException; + CSSCounterValue getCounterValue() throws DOMException; /** - * The right value of the rect. + * If this value is a rect() value, get it. * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a Rect value. + * @return the rect() value. + * @throws DOMException INVALID_ACCESS_ERR if this is not a rect() value. */ - Value getRight() throws DOMException; + RectValue getRectValue() throws DOMException; /** - * The bottom value of the rect. + * If this value is a color value, get it. * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a Rect value. + * @return the color value. + * @throws DOMException INVALID_ACCESS_ERR if this is not a color value. */ - Value getBottom() throws DOMException; + ColorValue getColorValue() throws DOMException; /** - * The left value of the rect. + * If this value is a unit value, set the float value. * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a Rect value. + * @param value the new value, in the current unit. + * @throws DOMException if the value is not a unit value. */ - Value getLeft() throws DOMException; + void setFloatValue(float value) throws DOMException; /** - * The identifier value of the counter. + * Set the modification handler. * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a Counter value. + * @param handler the modification handler. */ - String getIdentifier() throws DOMException; + void setModificationHandler(ValueModificationHandler handler); /** - * The listStyle value of the counter. + * Get the modification handler. * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a Counter value. + * @return the modification handler, or {@code null} if there is no handler. */ - String getListStyle() throws DOMException; + ValueModificationHandler getModificationHandler(); /** - * The separator value of the counter. + * Is this value a component? * - * @exception DOMException INVALID_ACCESS_ERR: Raised if the value doesn't - * contain a Counter value. + * @return {@code true} if the value is a component. */ - String getSeparator() throws DOMException; + default boolean isComponent() { + return false; + } } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ValueConstants.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ValueConstants.java index 0f39fb26d..da510bb64 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ValueConstants.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ValueConstants.java @@ -18,15 +18,16 @@ */ package io.sf.carte.echosvg.css.engine.value; -import org.w3c.dom.css.CSSPrimitiveValue; - +import org.w3c.css.om.unit.CSSUnit; import io.sf.carte.echosvg.util.CSSConstants; /** * This interface defines constants for CSS values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public interface ValueConstants { @@ -34,67 +35,67 @@ public interface ValueConstants { /** * 0 */ - Value NUMBER_0 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 0); + NumericValue NUMBER_0 = new FloatValue(CSSUnit.CSS_NUMBER, 0); /** * 100 */ - Value NUMBER_100 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 100); + NumericValue NUMBER_100 = new FloatValue(CSSUnit.CSS_NUMBER, 100); /** * 128 */ - Value NUMBER_128 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 128); + NumericValue NUMBER_128 = new FloatValue(CSSUnit.CSS_NUMBER, 128); /** * 192 */ - Value NUMBER_192 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 192); + NumericValue NUMBER_192 = new FloatValue(CSSUnit.CSS_NUMBER, 192); /** * 200 */ - Value NUMBER_200 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 200); + NumericValue NUMBER_200 = new FloatValue(CSSUnit.CSS_NUMBER, 200); /** * 255 */ - Value NUMBER_255 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 255); + NumericValue NUMBER_255 = new FloatValue(CSSUnit.CSS_NUMBER, 255); /** * 300 */ - Value NUMBER_300 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 300); + NumericValue NUMBER_300 = new FloatValue(CSSUnit.CSS_NUMBER, 300); /** * 400 */ - Value NUMBER_400 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 400); + NumericValue NUMBER_400 = new FloatValue(CSSUnit.CSS_NUMBER, 400); /** * 500 */ - Value NUMBER_500 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 500); + NumericValue NUMBER_500 = new FloatValue(CSSUnit.CSS_NUMBER, 500); /** * 600 */ - Value NUMBER_600 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 600); + NumericValue NUMBER_600 = new FloatValue(CSSUnit.CSS_NUMBER, 600); /** * 700 */ - Value NUMBER_700 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 700); + NumericValue NUMBER_700 = new FloatValue(CSSUnit.CSS_NUMBER, 700); /** * 800 */ - Value NUMBER_800 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 800); + NumericValue NUMBER_800 = new FloatValue(CSSUnit.CSS_NUMBER, 800); /** * 900 */ - Value NUMBER_900 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 900); + NumericValue NUMBER_900 = new FloatValue(CSSUnit.CSS_NUMBER, 900); /** * The 'inherit' value. @@ -104,648 +105,642 @@ public interface ValueConstants { /** * The 'all' keyword. */ - Value ALL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ALL_VALUE); + Value ALL_VALUE = new IdentValue(CSSConstants.CSS_ALL_VALUE); /** * The 'auto' keyword. */ - Value AUTO_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_AUTO_VALUE); + Value AUTO_VALUE = new IdentValue(CSSConstants.CSS_AUTO_VALUE); /** * The 'bidi-override' keyword. */ - Value BIDI_OVERRIDE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BIDI_OVERRIDE_VALUE); + Value BIDI_OVERRIDE_VALUE = new IdentValue(CSSConstants.CSS_BIDI_OVERRIDE_VALUE); /** * The 'blink' keyword. */ - Value BLINK_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BLINK_VALUE); + Value BLINK_VALUE = new IdentValue(CSSConstants.CSS_BLINK_VALUE); /** * The 'block' keyword. */ - Value BLOCK_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BLOCK_VALUE); + Value BLOCK_VALUE = new IdentValue(CSSConstants.CSS_BLOCK_VALUE); /** * The 'bold' keyword. */ - Value BOLD_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BOLD_VALUE); + Value BOLD_VALUE = new IdentValue(CSSConstants.CSS_BOLD_VALUE); /** * The 'bolder' keyword. */ - Value BOLDER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BOLDER_VALUE); + Value BOLDER_VALUE = new IdentValue(CSSConstants.CSS_BOLDER_VALUE); /** * The 'bottom' keyword. */ - Value BOTTOM_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BOTTOM_VALUE); + Value BOTTOM_VALUE = new IdentValue(CSSConstants.CSS_BOTTOM_VALUE); /** * The 'collapse' keyword. */ - Value COLLAPSE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_COLLAPSE_VALUE); + Value COLLAPSE_VALUE = new IdentValue(CSSConstants.CSS_COLLAPSE_VALUE); /** * The 'compact' keyword. */ - Value COMPACT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_COMPACT_VALUE); + Value COMPACT_VALUE = new IdentValue(CSSConstants.CSS_COMPACT_VALUE); /** * The 'condensed' keyword. */ - Value CONDENSED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CONDENSED_VALUE); + Value CONDENSED_VALUE = new IdentValue(CSSConstants.CSS_CONDENSED_VALUE); /** * The 'crispedges' keyword. */ - Value CRISPEDGES_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CRISPEDGES_VALUE); + Value CRISPEDGES_VALUE = new IdentValue(CSSConstants.CSS_CRISPEDGES_VALUE); /** * The 'crosshair' keyword. */ - Value CROSSHAIR_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CROSSHAIR_VALUE); + Value CROSSHAIR_VALUE = new IdentValue(CSSConstants.CSS_CROSSHAIR_VALUE); /** * The 'cursive' keyword. */ - Value CURSIVE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CURSIVE_VALUE); + Value CURSIVE_VALUE = new IdentValue(CSSConstants.CSS_CURSIVE_VALUE); /** * The 'default' keyword. */ - Value DEFAULT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DEFAULT_VALUE); + Value DEFAULT_VALUE = new IdentValue(CSSConstants.CSS_DEFAULT_VALUE); /** * The 'e-resize' keyword. */ - Value E_RESIZE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_E_RESIZE_VALUE); + Value E_RESIZE_VALUE = new IdentValue(CSSConstants.CSS_E_RESIZE_VALUE); /** * The 'embed' keyword. */ - Value EMBED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_EMBED_VALUE); + Value EMBED_VALUE = new IdentValue(CSSConstants.CSS_EMBED_VALUE); /** * The 'expanded' keyword. */ - Value EXPANDED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_EXPANDED_VALUE); + Value EXPANDED_VALUE = new IdentValue(CSSConstants.CSS_EXPANDED_VALUE); /** * The 'extra-condensed' keyword. */ - Value EXTRA_CONDENSED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_EXTRA_CONDENSED_VALUE); + Value EXTRA_CONDENSED_VALUE = new IdentValue(CSSConstants.CSS_EXTRA_CONDENSED_VALUE); /** * The 'extra-expanded' keyword. */ - Value EXTRA_EXPANDED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_EXTRA_EXPANDED_VALUE); + Value EXTRA_EXPANDED_VALUE = new IdentValue(CSSConstants.CSS_EXTRA_EXPANDED_VALUE); /** * The 'fantasy' keyword. */ - Value FANTASY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_FANTASY_VALUE); + Value FANTASY_VALUE = new IdentValue(CSSConstants.CSS_FANTASY_VALUE); /** * The 'help' keyword. */ - Value HELP_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_HELP_VALUE); + Value HELP_VALUE = new IdentValue(CSSConstants.CSS_HELP_VALUE); /** * The 'hidden' keyword. */ - Value HIDDEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_HIDDEN_VALUE); + Value HIDDEN_VALUE = new IdentValue(CSSConstants.CSS_HIDDEN_VALUE); /** * The 'inline' keyword. */ - Value INLINE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_INLINE_VALUE); + Value INLINE_VALUE = new IdentValue(CSSConstants.CSS_INLINE_VALUE); /** * The 'inline-block' keyword. */ - Value INLINE_BLOCK_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_INLINE_BLOCK_VALUE); + Value INLINE_BLOCK_VALUE = new IdentValue(CSSConstants.CSS_INLINE_BLOCK_VALUE); /** * The 'inline-table' keyword. */ - Value INLINE_TABLE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_INLINE_TABLE_VALUE); + Value INLINE_TABLE_VALUE = new IdentValue(CSSConstants.CSS_INLINE_TABLE_VALUE); /** * The 'italic' keyword. */ - Value ITALIC_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ITALIC_VALUE); + Value ITALIC_VALUE = new IdentValue(CSSConstants.CSS_ITALIC_VALUE); /** * The 'large' keyword. */ - Value LARGE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LARGE_VALUE); + Value LARGE_VALUE = new IdentValue(CSSConstants.CSS_LARGE_VALUE); /** * The 'larger' keyword. */ - Value LARGER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LARGER_VALUE); + Value LARGER_VALUE = new IdentValue(CSSConstants.CSS_LARGER_VALUE); /** * The 'lighter' keyword. */ - Value LIGHTER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTER_VALUE); + Value LIGHTER_VALUE = new IdentValue(CSSConstants.CSS_LIGHTER_VALUE); /** * The 'line_through' keyword. */ - Value LINE_THROUGH_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LINE_THROUGH_VALUE); + Value LINE_THROUGH_VALUE = new IdentValue(CSSConstants.CSS_LINE_THROUGH_VALUE); /** * The 'list-item' keyword. */ - Value LIST_ITEM_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIST_ITEM_VALUE); + Value LIST_ITEM_VALUE = new IdentValue(CSSConstants.CSS_LIST_ITEM_VALUE); /** * The 'ltr' keyword. */ - Value LTR_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LTR_VALUE); + Value LTR_VALUE = new IdentValue(CSSConstants.CSS_LTR_VALUE); /** * The 'marker' keyword. */ - Value MARKER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MARKER_VALUE); + Value MARKER_VALUE = new IdentValue(CSSConstants.CSS_MARKER_VALUE); /** * The 'medium' keyword. */ - Value MEDIUM_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MEDIUM_VALUE); + Value MEDIUM_VALUE = new IdentValue(CSSConstants.CSS_MEDIUM_VALUE); /** * The 'monospaced' keyword. */ - Value MONOSPACE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MONOSPACE_VALUE); + Value MONOSPACE_VALUE = new IdentValue(CSSConstants.CSS_MONOSPACE_VALUE); /** * The 'move' keyword. */ - Value MOVE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MOVE_VALUE); + Value MOVE_VALUE = new IdentValue(CSSConstants.CSS_MOVE_VALUE); /** * The 'n-resize' keyword. */ - Value N_RESIZE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_N_RESIZE_VALUE); + Value N_RESIZE_VALUE = new IdentValue(CSSConstants.CSS_N_RESIZE_VALUE); /** * The 'narrower' keyword. */ - Value NARROWER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_NARROWER_VALUE); + Value NARROWER_VALUE = new IdentValue(CSSConstants.CSS_NARROWER_VALUE); /** * The 'ne-resize' keyword. */ - Value NE_RESIZE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_NE_RESIZE_VALUE); + Value NE_RESIZE_VALUE = new IdentValue(CSSConstants.CSS_NE_RESIZE_VALUE); /** * The 'nw-resize' keyword. */ - Value NW_RESIZE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_NW_RESIZE_VALUE); + Value NW_RESIZE_VALUE = new IdentValue(CSSConstants.CSS_NW_RESIZE_VALUE); /** * The 'none' keyword. */ - Value NONE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_NONE_VALUE); + Value NONE_VALUE = new IdentValue(CSSConstants.CSS_NONE_VALUE); /** * The 'normal' keyword. */ - Value NORMAL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_NORMAL_VALUE); + Value NORMAL_VALUE = new IdentValue(CSSConstants.CSS_NORMAL_VALUE); /** * The 'oblique' keyword. */ - Value OBLIQUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_OBLIQUE_VALUE); + Value OBLIQUE_VALUE = new IdentValue(CSSConstants.CSS_OBLIQUE_VALUE); /** * The 'overline' keyword. */ - Value OVERLINE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_OVERLINE_VALUE); + Value OVERLINE_VALUE = new IdentValue(CSSConstants.CSS_OVERLINE_VALUE); /** * The 'pointer' keyword. */ - Value POINTER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_POINTER_VALUE); + Value POINTER_VALUE = new IdentValue(CSSConstants.CSS_POINTER_VALUE); /** * The 'painted' keyword. */ - Value PAINTED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_PAINTED_VALUE); + Value PAINTED_VALUE = new IdentValue(CSSConstants.CSS_PAINTED_VALUE); /** * The 'rtl' keyword. */ - Value RTL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_RTL_VALUE); + Value RTL_VALUE = new IdentValue(CSSConstants.CSS_RTL_VALUE); /** * The 'run-in' keyword. */ - Value RUN_IN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_RUN_IN_VALUE); + Value RUN_IN_VALUE = new IdentValue(CSSConstants.CSS_RUN_IN_VALUE); /** * The 's-resize' keyword. */ - Value S_RESIZE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_S_RESIZE_VALUE); + Value S_RESIZE_VALUE = new IdentValue(CSSConstants.CSS_S_RESIZE_VALUE); /** * The 'sans-serif' keyword. */ - Value SANS_SERIF_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SANS_SERIF_VALUE); + Value SANS_SERIF_VALUE = new IdentValue(CSSConstants.CSS_SANS_SERIF_VALUE); /** * The 'scroll' keyword. */ - Value SCROLL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SCROLL_VALUE); + Value SCROLL_VALUE = new IdentValue(CSSConstants.CSS_SCROLL_VALUE); /** * The 'se-resize' keyword. */ - Value SE_RESIZE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SE_RESIZE_VALUE); + Value SE_RESIZE_VALUE = new IdentValue(CSSConstants.CSS_SE_RESIZE_VALUE); /** * The 'semi-condensed' keyword. */ - Value SEMI_CONDENSED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SEMI_CONDENSED_VALUE); + Value SEMI_CONDENSED_VALUE = new IdentValue(CSSConstants.CSS_SEMI_CONDENSED_VALUE); /** * The 'semi-expanded' keyword. */ - Value SEMI_EXPANDED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SEMI_EXPANDED_VALUE); + Value SEMI_EXPANDED_VALUE = new IdentValue(CSSConstants.CSS_SEMI_EXPANDED_VALUE); /** * The 'serif' keyword. */ - Value SERIF_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SERIF_VALUE); + Value SERIF_VALUE = new IdentValue(CSSConstants.CSS_SERIF_VALUE); /** * The 'small' keyword. */ - Value SMALL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SMALL_VALUE); + Value SMALL_VALUE = new IdentValue(CSSConstants.CSS_SMALL_VALUE); /** * The 'small-caps' keyword. */ - Value SMALL_CAPS_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SMALL_CAPS_VALUE); + Value SMALL_CAPS_VALUE = new IdentValue(CSSConstants.CSS_SMALL_CAPS_VALUE); /** * The 'smaller' keyword. */ - Value SMALLER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SMALLER_VALUE); + Value SMALLER_VALUE = new IdentValue(CSSConstants.CSS_SMALLER_VALUE); /** * The 'stroke' keyword. */ - Value STROKE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_STROKE_VALUE); + Value STROKE_VALUE = new IdentValue(CSSConstants.CSS_STROKE_VALUE); /** * The 'sw-resize' keyword. */ - Value SW_RESIZE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SW_RESIZE_VALUE); + Value SW_RESIZE_VALUE = new IdentValue(CSSConstants.CSS_SW_RESIZE_VALUE); /** * The 'table' keyword. */ - Value TABLE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TABLE_VALUE); + Value TABLE_VALUE = new IdentValue(CSSConstants.CSS_TABLE_VALUE); /** * The 'table-caption' keyword. */ - Value TABLE_CAPTION_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TABLE_CAPTION_VALUE); + Value TABLE_CAPTION_VALUE = new IdentValue(CSSConstants.CSS_TABLE_CAPTION_VALUE); /** * The 'table-cell' keyword. */ - Value TABLE_CELL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TABLE_CELL_VALUE); + Value TABLE_CELL_VALUE = new IdentValue(CSSConstants.CSS_TABLE_CELL_VALUE); /** * The 'table-column' keyword. */ - Value TABLE_COLUMN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TABLE_COLUMN_VALUE); + Value TABLE_COLUMN_VALUE = new IdentValue(CSSConstants.CSS_TABLE_COLUMN_VALUE); /** * The 'table-column-group' keyword. */ - Value TABLE_COLUMN_GROUP_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_TABLE_COLUMN_GROUP_VALUE); + Value TABLE_COLUMN_GROUP_VALUE = new IdentValue(CSSConstants.CSS_TABLE_COLUMN_GROUP_VALUE); /** * The 'table-footer-group' keyword. */ - Value TABLE_FOOTER_GROUP_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_TABLE_FOOTER_GROUP_VALUE); + Value TABLE_FOOTER_GROUP_VALUE = new IdentValue(CSSConstants.CSS_TABLE_FOOTER_GROUP_VALUE); /** * The 'table-header-group' keyword. */ - Value TABLE_HEADER_GROUP_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_TABLE_HEADER_GROUP_VALUE); + Value TABLE_HEADER_GROUP_VALUE = new IdentValue(CSSConstants.CSS_TABLE_HEADER_GROUP_VALUE); /** * The 'table-row' keyword. */ - Value TABLE_ROW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TABLE_ROW_VALUE); + Value TABLE_ROW_VALUE = new IdentValue(CSSConstants.CSS_TABLE_ROW_VALUE); /** * The 'table-row-group' keyword. */ - Value TABLE_ROW_GROUP_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TABLE_ROW_GROUP_VALUE); + Value TABLE_ROW_GROUP_VALUE = new IdentValue(CSSConstants.CSS_TABLE_ROW_GROUP_VALUE); /** * The 'text' keyword. */ - Value TEXT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TEXT_VALUE); + Value TEXT_VALUE = new IdentValue(CSSConstants.CSS_TEXT_VALUE); /** * The 'ultra-condensed' keyword. */ - Value ULTRA_CONDENSED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ULTRA_CONDENSED_VALUE); + Value ULTRA_CONDENSED_VALUE = new IdentValue(CSSConstants.CSS_ULTRA_CONDENSED_VALUE); /** * The 'ultra-expanded' keyword. */ - Value ULTRA_EXPANDED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ULTRA_EXPANDED_VALUE); + Value ULTRA_EXPANDED_VALUE = new IdentValue(CSSConstants.CSS_ULTRA_EXPANDED_VALUE); /** * The 'top' keyword. */ - Value TOP_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TOP_VALUE); + Value TOP_VALUE = new IdentValue(CSSConstants.CSS_TOP_VALUE); /** * The 'underline' keyword. */ - Value UNDERLINE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_UNDERLINE_VALUE); + Value UNDERLINE_VALUE = new IdentValue(CSSConstants.CSS_UNDERLINE_VALUE); /** * The 'visible' keyword. */ - Value VISIBLE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_VISIBLE_VALUE); + Value VISIBLE_VALUE = new IdentValue(CSSConstants.CSS_VISIBLE_VALUE); /** * The 'w-resize' keyword. */ - Value W_RESIZE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_W_RESIZE_VALUE); + Value W_RESIZE_VALUE = new IdentValue(CSSConstants.CSS_W_RESIZE_VALUE); /** * The 'wait' keyword. */ - Value WAIT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_WAIT_VALUE); + Value WAIT_VALUE = new IdentValue(CSSConstants.CSS_WAIT_VALUE); /** * The 'wider' keyword. */ - Value WIDER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_WIDER_VALUE); + Value WIDER_VALUE = new IdentValue(CSSConstants.CSS_WIDER_VALUE); /** * The 'x-large' keyword. */ - Value X_LARGE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_X_LARGE_VALUE); + Value X_LARGE_VALUE = new IdentValue(CSSConstants.CSS_X_LARGE_VALUE); /** * The 'x-small' keyword. */ - Value X_SMALL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_X_SMALL_VALUE); + Value X_SMALL_VALUE = new IdentValue(CSSConstants.CSS_X_SMALL_VALUE); /** * The 'xx-large' keyword. */ - Value XX_LARGE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_XX_LARGE_VALUE); + Value XX_LARGE_VALUE = new IdentValue(CSSConstants.CSS_XX_LARGE_VALUE); /** * The 'xx-small' keyword. */ - Value XX_SMALL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_XX_SMALL_VALUE); + Value XX_SMALL_VALUE = new IdentValue(CSSConstants.CSS_XX_SMALL_VALUE); /** * The 'aqua' color name. */ - Value AQUA_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_AQUA_VALUE); + Value AQUA_VALUE = new IdentValue(CSSConstants.CSS_AQUA_VALUE); /** * The 'black' color name. */ - Value BLACK_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BLACK_VALUE); + Value BLACK_VALUE = new IdentValue(CSSConstants.CSS_BLACK_VALUE); /** * The 'blue' color name. */ - Value BLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BLUE_VALUE); + Value BLUE_VALUE = new IdentValue(CSSConstants.CSS_BLUE_VALUE); /** * The 'fuchsia' color name. */ - Value FUCHSIA_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_FUCHSIA_VALUE); + Value FUCHSIA_VALUE = new IdentValue(CSSConstants.CSS_FUCHSIA_VALUE); /** * The 'gray' color name. */ - Value GRAY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_GRAY_VALUE); + Value GRAY_VALUE = new IdentValue(CSSConstants.CSS_GRAY_VALUE); /** * The 'green' color name. */ - Value GREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_GREEN_VALUE); + Value GREEN_VALUE = new IdentValue(CSSConstants.CSS_GREEN_VALUE); /** * The 'lime' color name. */ - Value LIME_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIME_VALUE); + Value LIME_VALUE = new IdentValue(CSSConstants.CSS_LIME_VALUE); /** * The 'maroon' color name. */ - Value MAROON_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MAROON_VALUE); + Value MAROON_VALUE = new IdentValue(CSSConstants.CSS_MAROON_VALUE); /** * The 'navy' color name. */ - Value NAVY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_NAVY_VALUE); + Value NAVY_VALUE = new IdentValue(CSSConstants.CSS_NAVY_VALUE); /** * The 'olive' color name. */ - Value OLIVE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_OLIVE_VALUE); + Value OLIVE_VALUE = new IdentValue(CSSConstants.CSS_OLIVE_VALUE); /** * The 'purple' color name. */ - Value PURPLE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_PURPLE_VALUE); + Value PURPLE_VALUE = new IdentValue(CSSConstants.CSS_PURPLE_VALUE); /** * The 'red' color name. */ - Value RED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_RED_VALUE); + Value RED_VALUE = new IdentValue(CSSConstants.CSS_RED_VALUE); /** * The 'silver' color name. */ - Value SILVER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SILVER_VALUE); + Value SILVER_VALUE = new IdentValue(CSSConstants.CSS_SILVER_VALUE); /** * The 'teal' color name. */ - Value TEAL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TEAL_VALUE); + Value TEAL_VALUE = new IdentValue(CSSConstants.CSS_TEAL_VALUE); /** * The 'transparent' color name. */ - Value TRANSPARENT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TRANSPARENT_VALUE); + Value TRANSPARENT_VALUE = new IdentValue(CSSConstants.CSS_TRANSPARENT_VALUE); /** * The 'white' color name. */ - Value WHITE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_WHITE_VALUE); + Value WHITE_VALUE = new IdentValue(CSSConstants.CSS_WHITE_VALUE); /** * The 'yellow' color name. */ - Value YELLOW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_YELLOW_VALUE); + Value YELLOW_VALUE = new IdentValue(CSSConstants.CSS_YELLOW_VALUE); /** * The 'ACTIVEBORDER' color name. */ - Value ACTIVEBORDER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ACTIVEBORDER_VALUE); + Value ACTIVEBORDER_VALUE = new IdentValue(CSSConstants.CSS_ACTIVEBORDER_VALUE); /** * The 'ACTIVECAPTION' color name. */ - Value ACTIVECAPTION_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ACTIVECAPTION_VALUE); + Value ACTIVECAPTION_VALUE = new IdentValue(CSSConstants.CSS_ACTIVECAPTION_VALUE); /** * The 'APPWORKSPACE' color name. */ - Value APPWORKSPACE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_APPWORKSPACE_VALUE); + Value APPWORKSPACE_VALUE = new IdentValue(CSSConstants.CSS_APPWORKSPACE_VALUE); /** * The 'BACKGROUND' color name. */ - Value BACKGROUND_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BACKGROUND_VALUE); + Value BACKGROUND_VALUE = new IdentValue(CSSConstants.CSS_BACKGROUND_VALUE); /** * The 'BUTTONFACE' color name. */ - Value BUTTONFACE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BUTTONFACE_VALUE); + Value BUTTONFACE_VALUE = new IdentValue(CSSConstants.CSS_BUTTONFACE_VALUE); /** * The 'BUTTONHIGHLIGHT' color name. */ - Value BUTTONHIGHLIGHT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BUTTONHIGHLIGHT_VALUE); + Value BUTTONHIGHLIGHT_VALUE = new IdentValue(CSSConstants.CSS_BUTTONHIGHLIGHT_VALUE); /** * The 'BUTTONSHADOW' color name. */ - Value BUTTONSHADOW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BUTTONSHADOW_VALUE); + Value BUTTONSHADOW_VALUE = new IdentValue(CSSConstants.CSS_BUTTONSHADOW_VALUE); /** * The 'BUTTONTEXT' color name. */ - Value BUTTONTEXT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BUTTONTEXT_VALUE); + Value BUTTONTEXT_VALUE = new IdentValue(CSSConstants.CSS_BUTTONTEXT_VALUE); /** * The 'CAPTIONTEXT' color name. */ - Value CAPTIONTEXT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CAPTIONTEXT_VALUE); + Value CAPTIONTEXT_VALUE = new IdentValue(CSSConstants.CSS_CAPTIONTEXT_VALUE); /** * The 'GRAYTEXT' color name. */ - Value GRAYTEXT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_GRAYTEXT_VALUE); + Value GRAYTEXT_VALUE = new IdentValue(CSSConstants.CSS_GRAYTEXT_VALUE); /** * The 'HIGHLIGHT' color name. */ - Value HIGHLIGHT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_HIGHLIGHT_VALUE); + Value HIGHLIGHT_VALUE = new IdentValue(CSSConstants.CSS_HIGHLIGHT_VALUE); /** * The 'HIGHLIGHTTEXT' color name. */ - Value HIGHLIGHTTEXT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_HIGHLIGHTTEXT_VALUE); + Value HIGHLIGHTTEXT_VALUE = new IdentValue(CSSConstants.CSS_HIGHLIGHTTEXT_VALUE); /** * The 'INACTIVEBORDER' color name. */ - Value INACTIVEBORDER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_INACTIVEBORDER_VALUE); + Value INACTIVEBORDER_VALUE = new IdentValue(CSSConstants.CSS_INACTIVEBORDER_VALUE); /** * The 'INACTIVECAPTION' color name. */ - Value INACTIVECAPTION_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_INACTIVECAPTION_VALUE); + Value INACTIVECAPTION_VALUE = new IdentValue(CSSConstants.CSS_INACTIVECAPTION_VALUE); /** * The 'INACTIVECAPTIONTEXT' color name. */ - Value INACTIVECAPTIONTEXT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_INACTIVECAPTIONTEXT_VALUE); + Value INACTIVECAPTIONTEXT_VALUE = new IdentValue(CSSConstants.CSS_INACTIVECAPTIONTEXT_VALUE); /** * The 'INFOBACKGROUND' color name. */ - Value INFOBACKGROUND_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_INFOBACKGROUND_VALUE); + Value INFOBACKGROUND_VALUE = new IdentValue(CSSConstants.CSS_INFOBACKGROUND_VALUE); /** * The 'INFOTEXT' color name. */ - Value INFOTEXT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_INFOTEXT_VALUE); + Value INFOTEXT_VALUE = new IdentValue(CSSConstants.CSS_INFOTEXT_VALUE); /** * The 'MENU' color name. */ - Value MENU_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MENU_VALUE); + Value MENU_VALUE = new IdentValue(CSSConstants.CSS_MENU_VALUE); /** * The 'MENUTEXT' color name. */ - Value MENUTEXT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MENUTEXT_VALUE); + Value MENUTEXT_VALUE = new IdentValue(CSSConstants.CSS_MENUTEXT_VALUE); /** * The 'SCROLLBAR' color name. */ - Value SCROLLBAR_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SCROLLBAR_VALUE); + Value SCROLLBAR_VALUE = new IdentValue(CSSConstants.CSS_SCROLLBAR_VALUE); /** * The 'THREEDDARKSHADOW' color name. */ - Value THREEDDARKSHADOW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_THREEDDARKSHADOW_VALUE); + Value THREEDDARKSHADOW_VALUE = new IdentValue(CSSConstants.CSS_THREEDDARKSHADOW_VALUE); /** * The 'THREEDFACE' color name. */ - Value THREEDFACE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_THREEDFACE_VALUE); + Value THREEDFACE_VALUE = new IdentValue(CSSConstants.CSS_THREEDFACE_VALUE); /** * The 'THREEDHIGHLIGHT' color name. */ - Value THREEDHIGHLIGHT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_THREEDHIGHLIGHT_VALUE); + Value THREEDHIGHLIGHT_VALUE = new IdentValue(CSSConstants.CSS_THREEDHIGHLIGHT_VALUE); /** * The 'THREEDLIGHTSHADOW' color name. */ - Value THREEDLIGHTSHADOW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_THREEDLIGHTSHADOW_VALUE); + Value THREEDLIGHTSHADOW_VALUE = new IdentValue(CSSConstants.CSS_THREEDLIGHTSHADOW_VALUE); /** * The 'THREEDSHADOW' color name. */ - Value THREEDSHADOW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_THREEDSHADOW_VALUE); + Value THREEDSHADOW_VALUE = new IdentValue(CSSConstants.CSS_THREEDSHADOW_VALUE); /** * The 'WINDOW' color name. */ - Value WINDOW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_WINDOW_VALUE); + Value WINDOW_VALUE = new IdentValue(CSSConstants.CSS_WINDOW_VALUE); /** * The 'WINDOWFRAME' color name. */ - Value WINDOWFRAME_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_WINDOWFRAME_VALUE); + Value WINDOWFRAME_VALUE = new IdentValue(CSSConstants.CSS_WINDOWFRAME_VALUE); /** * The 'WINDOWTEXT' color name. */ - Value WINDOWTEXT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_WINDOWTEXT_VALUE); + Value WINDOWTEXT_VALUE = new IdentValue(CSSConstants.CSS_WINDOWTEXT_VALUE); /** * The 'black' RGB color. diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ValueManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ValueManager.java index aabe4ac2a..8fee9a3a8 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ValueManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ValueManager.java @@ -22,6 +22,7 @@ import org.w3c.dom.DOMException; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.StyleMap; @@ -30,8 +31,10 @@ * This interface is implemented by objects which manage the values associated * with a property. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public interface ValueManager { @@ -87,12 +90,12 @@ public interface ValueManager { /** * Creates and returns a new string value. * - * @param type A string code as defined in CSSPrimitiveValue. The string code - * can only be a string unit type. + * @param type A value type as defined in Value.Type. The string code + * can only be a string-like unit type. * @param value The new string value. * @param engine The CSS engine. */ - Value createStringValue(short type, String value, CSSEngine engine) throws DOMException; + Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException; /** * Computes the given value. diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ValueModificationHandler.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ValueModificationHandler.java new file mode 100644 index 000000000..b8fd52bf0 --- /dev/null +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/ValueModificationHandler.java @@ -0,0 +1,31 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.css.engine.value; + +/** + * Manage the modification of values. + */ +public interface ValueModificationHandler { + + /** + * Notify that the value changed. + */ + void valueChanged(Value v); + +} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/ClipManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/ClipManager.java index fbac5d7c3..d40f3c4c2 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/ClipManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/ClipManager.java @@ -19,9 +19,9 @@ package io.sf.carte.echosvg.css.engine.value.css2; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.value.InheritValue; import io.sf.carte.echosvg.css.engine.value.RectManager; @@ -34,8 +34,10 @@ /** * This class provides a manager for the 'clip' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class ClipManager extends RectManager { @@ -107,12 +109,9 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return super.createValue(lu, engine); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { - if (type != CSSPrimitiveValue.CSS_IDENT) { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { + if (type != Type.IDENT) { throw createInvalidStringTypeDOMException(type); } if (!value.equalsIgnoreCase(CSSConstants.CSS_AUTO_VALUE)) { diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/CursorManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/CursorManager.java index 31adc5819..3a393a584 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/CursorManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/CursorManager.java @@ -18,11 +18,12 @@ */ package io.sf.carte.echosvg.css.engine.value.css2; +import java.util.Locale; + import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.StyleMap; @@ -39,8 +40,10 @@ /** * This class provides a manager for the 'cursor' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class CursorManager extends AbstractValueManager { @@ -148,7 +151,7 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { // Fall through... case IDENT: - String s = lu.getStringValue().toLowerCase().intern(); + String s = lu.getStringValue().toLowerCase(Locale.ROOT).intern(); Object v = values.get(s); if (v == null) { throw createInvalidIdentifierDOMException(lu.getStringValue()); @@ -165,22 +168,18 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return result; } - /** - * Implements - * {@link ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}. - */ @Override public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { - if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { - ListValue lv = (ListValue) value; - int len = lv.getLength(); + if (value.getCssValueType() == Value.CssType.LIST) { + int len = value.getLength(); ListValue result = new ListValue(' '); for (int i = 0; i < len; i++) { - Value v = lv.item(0); - if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_URI) { - // Reveal the absolute value as the cssText now. - result.append(new URIValue(v.getStringValue(), v.getStringValue())); + Value v = value.item(0); + if (v.getPrimitiveType() == Type.URI) { + // For performance, use the absolute value as the cssText now. + String uri = v.getURIValue(); + result.append(new URIValue(uri, uri)); } else { result.append(v); } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontFamilyManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontFamilyManager.java index 05f8bf701..93b223382 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontFamilyManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontFamilyManager.java @@ -18,8 +18,9 @@ */ package io.sf.carte.echosvg.css.engine.value.css2; +import java.util.Locale; + import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; import io.sf.carte.doc.style.css.nsac.LexicalUnit.LexicalType; @@ -28,6 +29,7 @@ import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.StyleMap; import io.sf.carte.echosvg.css.engine.value.AbstractValueManager; +import io.sf.carte.echosvg.css.engine.value.IdentValue; import io.sf.carte.echosvg.css.engine.value.ListValue; import io.sf.carte.echosvg.css.engine.value.StringMap; import io.sf.carte.echosvg.css.engine.value.StringValue; @@ -40,8 +42,10 @@ /** * This class provides a factory for the 'font-family' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class FontFamilyManager extends AbstractValueManager { @@ -51,9 +55,9 @@ public class FontFamilyManager extends AbstractValueManager { */ protected static final ListValue DEFAULT_VALUE = new ListValue(); static { - DEFAULT_VALUE.append(new StringValue(CSSPrimitiveValue.CSS_STRING, "Arial")); - DEFAULT_VALUE.append(new StringValue(CSSPrimitiveValue.CSS_STRING, "Helvetica")); - DEFAULT_VALUE.append(new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SANS_SERIF_VALUE)); + DEFAULT_VALUE.append(new StringValue("Arial")); + DEFAULT_VALUE.append(new StringValue("Helvetica")); + DEFAULT_VALUE.append(new IdentValue(CSSConstants.CSS_SANS_SERIF_VALUE)); } /** @@ -135,7 +139,7 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { for (;;) { switch (lu.getLexicalUnitType()) { case STRING: - result.append(new StringValue(CSSPrimitiveValue.CSS_STRING, lu.getStringValue())); + result.append(new StringValue(lu.getStringValue())); lu = lu.getNextLexicalUnit(); break; @@ -158,12 +162,12 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { } lu = lu.getNextLexicalUnit(); } while (lu != null && isIdentOrNumber(lu)); - result.append(new StringValue(CSSPrimitiveValue.CSS_STRING, sb.toString())); + result.append(new StringValue(sb.toString())); } else { String id = sb.toString(); - String s = id.toLowerCase().intern(); + String s = id.toLowerCase(Locale.ROOT).intern(); Value v = (Value) values.get(s); - result.append((v != null) ? v : new StringValue(CSSPrimitiveValue.CSS_STRING, id)); + result.append((v != null) ? v : new StringValue(id)); } break; default: diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontShorthandManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontShorthandManager.java index 5094a239b..aa4641841 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontShorthandManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontShorthandManager.java @@ -22,9 +22,11 @@ import java.io.IOException; import java.io.StringReader; import java.util.HashSet; +import java.util.Locale; import java.util.Set; -import io.sf.carte.doc.style.css.CSSUnit; +import org.w3c.css.om.unit.CSSUnit; + import io.sf.carte.doc.style.css.nsac.CSSParseException; import io.sf.carte.doc.style.css.nsac.LexicalUnit; import io.sf.carte.doc.style.css.parser.CSSParser; @@ -49,8 +51,10 @@ * considering the 'last' number before an 'ident' or '/' to be font-size and * any preceeding number to be font-weight. * - * @author deweese - * @author For later modifications, see Git history. + *

+ * Original author: deweese. + * For later modifications, see Git history. + *

* @version $Id$ */ public class FontShorthandManager extends AbstractValueFactory implements ShorthandManager { @@ -147,7 +151,7 @@ public void setValues(CSSEngine eng, ShorthandManager.PropertyHandler ph, Lexica case INHERIT: return; case IDENT: { - String s = lu.getStringValue().toLowerCase(); + String s = lu.getStringValue().toLowerCase(Locale.ROOT); if (values.contains(s)) { handleSystemFont(eng, ph, s, imp); return; @@ -190,7 +194,7 @@ public void setValues(CSSEngine eng, ShorthandManager.PropertyHandler ph, Lexica while (!svwDone && (lu != null)) { switch (lu.getLexicalUnitType()) { case IDENT: { - String s = lu.getStringValue().toLowerCase().intern(); + String s = lu.getStringValue().toLowerCase(Locale.ROOT).intern(); if (fontStyle == null && fstSM.get(s) != null) { fontStyle = lu; if (intLU != null) { @@ -248,7 +252,7 @@ public void setValues(CSSEngine eng, ShorthandManager.PropertyHandler ph, Lexica // Now we need to get font-size switch (lu.getLexicalUnitType()) { case IDENT: { - String s = lu.getStringValue().toLowerCase().intern(); + String s = lu.getStringValue().toLowerCase(Locale.ROOT).intern(); if (fszSM.get(s) != null) { fontSize = lu; // This is a font-size ident. lu = lu.getNextLexicalUnit(); diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontSizeAdjustManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontSizeAdjustManager.java index f537b68a6..a48ed888b 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontSizeAdjustManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontSizeAdjustManager.java @@ -18,10 +18,11 @@ */ package io.sf.carte.echosvg.css.engine.value.css2; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.value.AbstractValueManager; import io.sf.carte.echosvg.css.engine.value.FloatValue; @@ -34,8 +35,10 @@ /** * This class provides a manager for the 'font-size-adjust' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class FontSizeAdjustManager extends AbstractValueManager { @@ -98,10 +101,10 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return ValueConstants.INHERIT_VALUE; case INTEGER: - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getIntegerValue()); + return new FloatValue(CSSUnit.CSS_NUMBER, lu.getIntegerValue()); case REAL: - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getFloatValue()); + return new FloatValue(CSSUnit.CSS_NUMBER, lu.getFloatValue()); case IDENT: if (lu.getStringValue().equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) { @@ -115,12 +118,9 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { - if (type != CSSPrimitiveValue.CSS_IDENT) { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { + if (type != Type.IDENT) { throw createInvalidStringTypeDOMException(type); } if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) { @@ -134,7 +134,7 @@ public Value createStringValue(short type, String value, CSSEngine engine) throw */ @Override public Value createFloatValue(short type, float floatValue) throws DOMException { - if (type == CSSPrimitiveValue.CSS_NUMBER) { + if (type == CSSUnit.CSS_NUMBER) { return new FloatValue(type, floatValue); } throw createInvalidFloatTypeDOMException(type); diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontSizeManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontSizeManager.java index 33794635b..7a11f41b5 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontSizeManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontSizeManager.java @@ -18,10 +18,14 @@ */ package io.sf.carte.echosvg.css.engine.value.css2; +import java.util.Locale; + +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.Viewport; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSContext; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; @@ -39,8 +43,10 @@ /** * This class provides a manager for the 'font-size' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class FontSizeManager extends LengthManager { @@ -127,7 +133,7 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return ValueConstants.INHERIT_VALUE; case IDENT: - String s = lu.getStringValue().toLowerCase().intern(); + String s = lu.getStringValue().toLowerCase(Locale.ROOT).intern(); Object v = values.get(s); if (v == null) { throw createInvalidIdentifierDOMException(s); @@ -139,15 +145,12 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return super.createValue(lu, engine); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { - if (type != CSSPrimitiveValue.CSS_IDENT) { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { + if (type != Type.IDENT) { throw createInvalidStringTypeDOMException(type); } - Object v = values.get(value.toLowerCase().intern()); + Object v = values.get(value.toLowerCase(Locale.ROOT).intern()); if (v == null) { throw createInvalidIdentifierDOMException(value); } @@ -164,48 +167,76 @@ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engin float scale = 1.0f; boolean doParentRelative = false; - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_NUMBER: - case CSSPrimitiveValue.CSS_PX: + switch (value.getCSSUnit()) { + case CSSUnit.CSS_NUMBER: + case CSSUnit.CSS_PX: return value; - case CSSPrimitiveValue.CSS_MM: + case CSSUnit.CSS_MM: CSSContext ctx = engine.getCSSContext(); - float v = value.getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v / ctx.getPixelUnitToMillimeter()); + float v = lengthValue(value); + return new FloatValue(CSSUnit.CSS_NUMBER, v / ctx.getPixelUnitToMillimeter()); - case CSSPrimitiveValue.CSS_CM: + case CSSUnit.CSS_CM: ctx = engine.getCSSContext(); - v = value.getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v * 10f / ctx.getPixelUnitToMillimeter()); + v = lengthValue(value); + return new FloatValue(CSSUnit.CSS_NUMBER, v * 10f / ctx.getPixelUnitToMillimeter()); - case CSSPrimitiveValue.CSS_IN: + case CSSUnit.CSS_IN: ctx = engine.getCSSContext(); - v = value.getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v * 25.4f / ctx.getPixelUnitToMillimeter()); + v = lengthValue(value); + return new FloatValue(CSSUnit.CSS_NUMBER, v * 25.4f / ctx.getPixelUnitToMillimeter()); - case CSSPrimitiveValue.CSS_PT: + case CSSUnit.CSS_PT: ctx = engine.getCSSContext(); - v = value.getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v * 25.4f / (72f * ctx.getPixelUnitToMillimeter())); + v = lengthValue(value); + return new FloatValue(CSSUnit.CSS_NUMBER, v * 25.4f / (72f * ctx.getPixelUnitToMillimeter())); - case CSSPrimitiveValue.CSS_PC: + case CSSUnit.CSS_PC: ctx = engine.getCSSContext(); - v = value.getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, (v * 25.4f / (6f * ctx.getPixelUnitToMillimeter()))); + v = lengthValue(value); + return new FloatValue(CSSUnit.CSS_NUMBER, (v * 25.4f / (6f * ctx.getPixelUnitToMillimeter()))); - case CSSPrimitiveValue.CSS_EMS: + case CSSUnit.CSS_EM: doParentRelative = true; - scale = value.getFloatValue(); + scale = lengthValue(value); break; - case CSSPrimitiveValue.CSS_EXS: + case CSSUnit.CSS_EX: doParentRelative = true; - scale = value.getFloatValue() * 0.5f; // !!! x-height + scale = lengthValue(value) * 0.5f; // !!! x-height break; - case CSSPrimitiveValue.CSS_PERCENTAGE: + case CSSUnit.CSS_PERCENTAGE: doParentRelative = true; scale = value.getFloatValue() * 0.01f; break; + case CSSUnit.CSS_REM: + scale = lengthValue(value); + return rootRelative(elt, engine, idx, scale); + case CSSUnit.CSS_REX: + scale = lengthValue(value) * 0.5f; + return rootRelative(elt, engine, idx, scale); + case CSSUnit.CSS_VW: + v = lengthValue(value); + return new FloatValue(CSSUnit.CSS_NUMBER, v * + engine.getCSSContext().getViewport(elt).getWidth() * 0.01f); + case CSSUnit.CSS_VH: + v = lengthValue(value); + return new FloatValue(CSSUnit.CSS_NUMBER, v * + engine.getCSSContext().getViewport(elt).getHeight() * 0.01f); + case CSSUnit.CSS_VMIN: + v = lengthValue(value); + Viewport vp = engine.getCSSContext().getViewport(elt); + float w = vp.getWidth(); + float h = vp.getHeight(); + float min = Math.min(w, h); + return new FloatValue(CSSUnit.CSS_NUMBER, v * min * 0.01f); + case CSSUnit.CSS_VMAX: + v = lengthValue(value); + vp = engine.getCSSContext().getViewport(elt); + w = vp.getWidth(); + h = vp.getHeight(); + float max = Math.max(w, h); + return new FloatValue(CSSUnit.CSS_NUMBER, v * max * 0.01f); default: } @@ -227,15 +258,17 @@ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engin CSSContext ctx = engine.getCSSContext(); fs = ctx.getMediumFontSize(); } else { - fs = engine.getComputedStyle(p, null, idx).getFloatValue(); + Value cs = engine.getComputedStyle(p, null, idx); + fs = lengthValue(cs); } - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, fs * scale); + return new FloatValue(CSSUnit.CSS_NUMBER, fs * scale); } // absolute identifiers CSSContext ctx = engine.getCSSContext(); float fs = ctx.getMediumFontSize(); - String s = value.getStringValue(); + + String s = value.getIdentifierValue(); switch (s.charAt(0)) { case 'm': break; @@ -272,7 +305,20 @@ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engin } } } - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, fs); + return new FloatValue(CSSUnit.CSS_NUMBER, fs); + } + + private Value rootRelative(CSSStylableElement elt, CSSEngine engine, int idx, float scale) { + CSSStylableElement root = (CSSStylableElement) elt.getOwnerDocument().getDocumentElement(); + if (elt == root) { + CSSContext ctx = engine.getCSSContext(); + float f = ctx.getMediumFontSize() * scale; + return new FloatValue(CSSUnit.CSS_NUMBER, f); + } + + Value cs = engine.getComputedStyle(root, null, idx); + float f = lengthValue(cs) * scale; + return new FloatValue(CSSUnit.CSS_NUMBER, f); } /** diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontWeightManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontWeightManager.java index f158907d3..80f334dfa 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontWeightManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/FontWeightManager.java @@ -18,8 +18,8 @@ */ package io.sf.carte.echosvg.css.engine.value.css2; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; import io.sf.carte.echosvg.css.engine.CSSContext; @@ -37,8 +37,10 @@ /** * This class provides a manager for the 'font-weight' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class FontWeightManager extends IdentifierManager { @@ -140,7 +142,7 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { */ @Override public Value createFloatValue(short type, float floatValue) throws DOMException { - if (type == CSSPrimitiveValue.CSS_NUMBER) { + if (type == CSSUnit.CSS_NUMBER) { int i = (int) floatValue; if (floatValue == i) { switch (i) { @@ -185,7 +187,7 @@ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engin fw = 400; } else { Value v = engine.getComputedStyle(p, pseudo, idx); - fw = v.getFloatValue(); + fw = lengthValue(v); } return createFontWeight(ctx.getBolderFontWeight(fw)); } else if (value == ValueConstants.LIGHTER_VALUE) { @@ -198,7 +200,7 @@ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engin fw = 400; } else { Value v = engine.getComputedStyle(p, pseudo, idx); - fw = v.getFloatValue(); + fw = lengthValue(v); } return createFontWeight(ctx.getLighterFontWeight(fw)); } else if (value == ValueConstants.NORMAL_VALUE) { diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/SrcManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/SrcManager.java index c7426976c..23b188ccc 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/SrcManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/SrcManager.java @@ -18,8 +18,9 @@ */ package io.sf.carte.echosvg.css.engine.value.css2; +import java.util.Locale; + import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; import io.sf.carte.echosvg.css.engine.CSSEngine; @@ -38,9 +39,10 @@ * One line Class Desc * * Complete Class Desc - * - * @author l449433 - * @author For later modifications, see Git history. + *

+ * Original author: l449433. + * For later modifications, see Git history. + *

* @version $Id$ */ public class SrcManager extends IdentifierManager { @@ -129,7 +131,7 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { for (;;) { switch (lu.getLexicalUnitType()) { case STRING: - result.append(new StringValue(CSSPrimitiveValue.CSS_STRING, lu.getStringValue())); + result.append(new StringValue(lu.getStringValue())); lu = lu.getNextLexicalUnit(); break; @@ -159,12 +161,12 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { sb.append(lu.getStringValue()); lu = lu.getNextLexicalUnit(); } while (lu != null && lu.getLexicalUnitType() == LexicalUnit.LexicalType.IDENT); - result.append(new StringValue(CSSPrimitiveValue.CSS_STRING, sb.toString())); + result.append(new StringValue(sb.toString())); } else { String id = sb.toString(); - String s = id.toLowerCase().intern(); + String s = id.toLowerCase(Locale.ROOT).intern(); Value v = (Value) values.get(s); - result.append((v != null) ? v : new StringValue(CSSPrimitiveValue.CSS_STRING, id)); + result.append((v != null) ? v : new StringValue(id)); } break; diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/TextDecorationManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/TextDecorationManager.java index 2fd62c2df..b2b8fc9e5 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/TextDecorationManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/TextDecorationManager.java @@ -18,10 +18,12 @@ */ package io.sf.carte.echosvg.css.engine.value.css2; +import java.util.Locale; + import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.value.AbstractValueManager; import io.sf.carte.echosvg.css.engine.value.ListValue; @@ -35,8 +37,10 @@ /** * This class provides a manager for the 'text-decoration' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class TextDecorationManager extends AbstractValueManager { @@ -116,7 +120,7 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { ListValue lv = new ListValue(' '); do { if (lu.getLexicalUnitType() == LexicalUnit.LexicalType.IDENT) { - String s = lu.getStringValue().toLowerCase().intern(); + String s = lu.getStringValue().toLowerCase(Locale.ROOT).intern(); Object obj = values.get(s); if (obj == null) { throw createInvalidIdentifierDOMException(lu.getStringValue()); @@ -136,12 +140,9 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { - if (type != CSSPrimitiveValue.CSS_IDENT) { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { + if (type != Type.IDENT) { throw createInvalidStringTypeDOMException(type); } if (!value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) { diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/BaselineShiftManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/BaselineShiftManager.java index 94bdbaba5..35b0e7fee 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/BaselineShiftManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/BaselineShiftManager.java @@ -18,10 +18,13 @@ */ package io.sf.carte.echosvg.css.engine.value.svg; +import java.util.Locale; + +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.StyleMap; @@ -37,8 +40,10 @@ /** * This class provides a manager for the 'baseline-shift' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class BaselineShiftManager extends LengthManager { @@ -111,7 +116,7 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return ValueConstants.INHERIT_VALUE; case IDENT: - Object v = values.get(lu.getStringValue().toLowerCase().intern()); + Object v = values.get(lu.getStringValue().toLowerCase(Locale.ROOT).intern()); if (v == null) { throw createInvalidIdentifierDOMException(lu.getStringValue()); } @@ -122,15 +127,12 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return super.createValue(lu, engine); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { - if (type != CSSPrimitiveValue.CSS_IDENT) { - throw createInvalidIdentifierDOMException(value); + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { + if (type != Type.IDENT) { + throw createInvalidStringTypeDOMException(type); } - Object v = values.get(value.toLowerCase().intern()); + Object v = values.get(value.toLowerCase(Locale.ROOT).intern()); if (v == null) { throw createInvalidIdentifierDOMException(value); } @@ -144,7 +146,7 @@ public Value createStringValue(short type, String value, CSSEngine engine) throw @Override public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { - if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_PERCENTAGE) { + if (value.getCSSUnit() == CSSUnit.CSS_PERCENTAGE) { sm.putLineHeightRelative(idx, true); int fsi = engine.getLineHeightIndex(); @@ -157,9 +159,9 @@ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engin parent = elt; } Value fs = engine.getComputedStyle(parent, pseudo, fsi); - float fsv = fs.getFloatValue(); + float fsv = lengthValue(fs); float v = value.getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, (fsv * v) / 100f); + return new FloatValue(CSSUnit.CSS_NUMBER, (fsv * v) / 100f); } return super.computeValue(elt, pseudo, engine, idx, sm, value); } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/ClipPathManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/ClipPathManager.java index 2d212656a..a191545c8 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/ClipPathManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/ClipPathManager.java @@ -19,9 +19,9 @@ package io.sf.carte.echosvg.css.engine.value.svg; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.value.AbstractValueManager; import io.sf.carte.echosvg.css.engine.value.URIValue; @@ -34,8 +34,10 @@ /** * This class provides a manager for the 'clip-path' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class ClipPathManager extends AbstractValueManager { @@ -110,20 +112,19 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { switch (type) { - case CSSPrimitiveValue.CSS_IDENT: + case IDENT: if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) { return ValueConstants.NONE_VALUE; } break; - case CSSPrimitiveValue.CSS_URI: + case URI: return new URIValue(value, resolveURI(engine.getCSSBaseURI(), value)); + default: + break; } throw createInvalidStringTypeDOMException(type); } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/ColorProfileManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/ColorProfileManager.java index 3110d72c9..1a1b8bb11 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/ColorProfileManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/ColorProfileManager.java @@ -18,13 +18,15 @@ */ package io.sf.carte.echosvg.css.engine.value.svg; +import java.util.Locale; + import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.value.AbstractValueManager; -import io.sf.carte.echosvg.css.engine.value.StringValue; +import io.sf.carte.echosvg.css.engine.value.IdentValue; import io.sf.carte.echosvg.css.engine.value.URIValue; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.css.engine.value.ValueConstants; @@ -35,8 +37,10 @@ /** * This class provides a manager for the 'color-interpolation' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class ColorProfileManager extends AbstractValueManager { @@ -99,14 +103,14 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return ValueConstants.INHERIT_VALUE; case IDENT: - String s = lu.getStringValue().toLowerCase(); + String s = lu.getStringValue().toLowerCase(Locale.ROOT); if (s.equals(CSSConstants.CSS_AUTO_VALUE)) { return ValueConstants.AUTO_VALUE; } if (s.equals(CSSConstants.CSS_SRGB_VALUE)) { return SVGValueConstants.SRGB_VALUE; } - return new StringValue(CSSPrimitiveValue.CSS_IDENT, s); + return new IdentValue(s); case URI: return new URIValue(lu.getStringValue(), resolveURI(engine.getCSSBaseURI(), lu.getStringValue())); @@ -116,24 +120,23 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { switch (type) { - case CSSPrimitiveValue.CSS_IDENT: - String s = value.toLowerCase(); + case IDENT: + String s = value.toLowerCase(Locale.ROOT); if (s.equals(CSSConstants.CSS_AUTO_VALUE)) { return ValueConstants.AUTO_VALUE; } if (s.equals(CSSConstants.CSS_SRGB_VALUE)) { return SVGValueConstants.SRGB_VALUE; } - return new StringValue(CSSPrimitiveValue.CSS_IDENT, s); + return new IdentValue(s); - case CSSPrimitiveValue.CSS_URI: + case URI: return new URIValue(value, resolveURI(engine.getCSSBaseURI(), value)); + default: + break; } throw createInvalidStringTypeDOMException(type); } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/EnableBackgroundManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/EnableBackgroundManager.java index 6c9ff6d62..ceb0500fd 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/EnableBackgroundManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/EnableBackgroundManager.java @@ -18,11 +18,12 @@ */ package io.sf.carte.echosvg.css.engine.value.svg; +import java.util.Locale; + import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.StyleMap; @@ -37,8 +38,10 @@ /** * This class provides a manager for the 'enable-background' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class EnableBackgroundManager extends LengthManager { @@ -109,7 +112,7 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); case IDENT: - String id = lu.getStringValue().toLowerCase().intern(); + String id = lu.getStringValue().toLowerCase(Locale.ROOT).intern(); if (id == CSSConstants.CSS_ACCUMULATE_VALUE) { return SVGValueConstants.ACCUMULATE_VALUE; } @@ -134,12 +137,9 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { } } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) { - if (type != CSSPrimitiveValue.CSS_IDENT) { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { + if (type != Type.IDENT) { throw createInvalidStringTypeDOMException(type); } if (!value.equalsIgnoreCase(CSSConstants.CSS_ACCUMULATE_VALUE)) { @@ -156,32 +156,27 @@ public Value createFloatValue(short unitType, float floatValue) throws DOMExcept throw createDOMException(); } - /** - * Implements - * {@link ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}. - */ @Override public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { - if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { - ListValue lv = (ListValue) value; - if (lv.getLength() == 5) { - Value lv1 = lv.item(1); + if (value.getCssValueType() == Value.CssType.LIST) { + if (value.getLength() == 5) { + Value lv1 = value.item(1); orientation = HORIZONTAL_ORIENTATION; Value v1 = super.computeValue(elt, pseudo, engine, idx, sm, lv1); - Value lv2 = lv.item(2); + Value lv2 = value.item(2); orientation = VERTICAL_ORIENTATION; Value v2 = super.computeValue(elt, pseudo, engine, idx, sm, lv2); - Value lv3 = lv.item(3); + Value lv3 = value.item(3); orientation = HORIZONTAL_ORIENTATION; Value v3 = super.computeValue(elt, pseudo, engine, idx, sm, lv3); - Value lv4 = lv.item(4); + Value lv4 = value.item(4); orientation = VERTICAL_ORIENTATION; Value v4 = super.computeValue(elt, pseudo, engine, idx, sm, lv4); if (lv1 != v1 || lv2 != v2 || lv3 != v3 || lv4 != v4) { ListValue result = new ListValue(' '); - result.append(lv.item(0)); + result.append(value.item(0)); result.append(v1); result.append(v2); result.append(v3); diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/FilterManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/FilterManager.java index c9748c2a7..97557d101 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/FilterManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/FilterManager.java @@ -19,9 +19,9 @@ package io.sf.carte.echosvg.css.engine.value.svg; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.value.AbstractValueManager; import io.sf.carte.echosvg.css.engine.value.URIValue; @@ -34,8 +34,10 @@ /** * This class provides a factory for the 'filter' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class FilterManager extends AbstractValueManager { @@ -112,18 +114,15 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { - if (type == CSSPrimitiveValue.CSS_IDENT) { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { + if (type == Type.IDENT) { if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) { return ValueConstants.NONE_VALUE; } throw createInvalidIdentifierDOMException(value); } - if (type == CSSPrimitiveValue.CSS_URI) { + if (type == Type.URI) { return new URIValue(value, resolveURI(engine.getCSSBaseURI(), value)); } throw createInvalidStringTypeDOMException(type); diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/GlyphOrientationManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/GlyphOrientationManager.java index dfdd7ad43..efaa647a9 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/GlyphOrientationManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/GlyphOrientationManager.java @@ -18,10 +18,9 @@ */ package io.sf.carte.echosvg.css.engine.value.svg; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import io.sf.carte.doc.style.css.CSSUnit; import io.sf.carte.doc.style.css.nsac.LexicalUnit; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.value.AbstractValueManager; @@ -34,8 +33,10 @@ /** * This class provides a manager for the 'glyph-orientation' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public abstract class GlyphOrientationManager extends AbstractValueManager { @@ -85,23 +86,23 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { case DIMENSION: switch (lu.getCssUnit()) { case CSSUnit.CSS_DEG: - return new FloatValue(CSSPrimitiveValue.CSS_DEG, lu.getFloatValue()); + return new FloatValue(CSSUnit.CSS_DEG, lu.getFloatValue()); case CSSUnit.CSS_RAD: - return new FloatValue(CSSPrimitiveValue.CSS_RAD, lu.getFloatValue()); + return new FloatValue(CSSUnit.CSS_RAD, lu.getFloatValue()); case CSSUnit.CSS_GRAD: - return new FloatValue(CSSPrimitiveValue.CSS_GRAD, lu.getFloatValue()); + return new FloatValue(CSSUnit.CSS_GRAD, lu.getFloatValue()); case CSSUnit.CSS_TURN: - return new FloatValue(CSSPrimitiveValue.CSS_DEG, lu.getFloatValue() * 360f); + return new FloatValue(CSSUnit.CSS_DEG, lu.getFloatValue() * 360f); } // For SVG angle properties unit defaults to 'deg'. case INTEGER: { int n = lu.getIntegerValue(); - return new FloatValue(CSSPrimitiveValue.CSS_DEG, n); + return new FloatValue(CSSUnit.CSS_DEG, n); } case REAL: { float n = lu.getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_DEG, n); + return new FloatValue(CSSUnit.CSS_DEG, n); } default: break; @@ -116,9 +117,9 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { @Override public Value createFloatValue(short type, float floatValue) throws DOMException { switch (type) { - case CSSPrimitiveValue.CSS_DEG: - case CSSPrimitiveValue.CSS_GRAD: - case CSSPrimitiveValue.CSS_RAD: + case CSSUnit.CSS_DEG: + case CSSUnit.CSS_GRAD: + case CSSUnit.CSS_RAD: return new FloatValue(type, floatValue); } throw createInvalidFloatValueDOMException(floatValue); diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/GlyphOrientationVerticalManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/GlyphOrientationVerticalManager.java index 36cf91f04..f0513416a 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/GlyphOrientationVerticalManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/GlyphOrientationVerticalManager.java @@ -19,9 +19,9 @@ package io.sf.carte.echosvg.css.engine.value.svg; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.css.engine.value.ValueConstants; @@ -32,8 +32,10 @@ * This class provides a manager for the 'glyph-orientation-vertical' property * values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class GlyphOrientationVerticalManager extends GlyphOrientationManager { @@ -68,12 +70,9 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return super.createValue(lu, engine); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { - if (type != CSSPrimitiveValue.CSS_IDENT) { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { + if (type != Type.IDENT) { throw createInvalidStringTypeDOMException(type); } if (value.equalsIgnoreCase(CSSConstants.CSS_AUTO_VALUE)) { diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/ICCColor.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/ICCColor.java index 985786c39..99e224670 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/ICCColor.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/ICCColor.java @@ -19,7 +19,6 @@ package io.sf.carte.echosvg.css.engine.value.svg; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSValue; import io.sf.carte.echosvg.css.engine.value.AbstractValue; @@ -56,15 +55,6 @@ public ICCColor(String name) { colorProfile = name; } - /** - * Implements - * {@link io.sf.carte.echosvg.css.engine.value.Value#getCssValueType()}. - */ - @Override - public short getCssValueType() { - return CSSValue.CSS_CUSTOM; - } - /** * Returns the color name. */ @@ -120,4 +110,17 @@ public String toString() { return getCssText(); } + @Override + public Type getPrimitiveType() { + return Type.COLOR; + } + + @Override + public ICCColor clone() { + ICCColor icc = new ICCColor(colorProfile); + icc.colors = colors.clone(); + icc.count = count; + return icc; + } + } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/KerningManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/KerningManager.java index 3b939950c..74dd4d9a9 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/KerningManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/KerningManager.java @@ -19,9 +19,9 @@ package io.sf.carte.echosvg.css.engine.value.svg; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.value.LengthManager; import io.sf.carte.echosvg.css.engine.value.Value; @@ -33,8 +33,10 @@ /** * This class provides a manager for the 'kerning' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class KerningManager extends LengthManager { @@ -107,12 +109,9 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return super.createValue(lu, engine); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { - if (type != CSSPrimitiveValue.CSS_IDENT) { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { + if (type != Type.IDENT) { throw createInvalidStringTypeDOMException(type); } if (value.equalsIgnoreCase(CSSConstants.CSS_AUTO_VALUE)) { diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/MarkerManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/MarkerManager.java index 4a75f5d93..b1e3b6b14 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/MarkerManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/MarkerManager.java @@ -19,9 +19,9 @@ package io.sf.carte.echosvg.css.engine.value.svg; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.value.AbstractValueManager; import io.sf.carte.echosvg.css.engine.value.URIValue; @@ -34,8 +34,10 @@ /** * This class provides a manager for the 'marker-*' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class MarkerManager extends AbstractValueManager { @@ -123,22 +125,20 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { switch (type) { - case CSSPrimitiveValue.CSS_IDENT: + case IDENT: if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) { return ValueConstants.NONE_VALUE; } - break; + throw createInvalidIdentifierDOMException(value); - case CSSPrimitiveValue.CSS_URI: + case URI: return new URIValue(value, resolveURI(engine.getCSSBaseURI(), value)); + default: + throw createInvalidStringTypeDOMException(type); } - throw createInvalidStringTypeDOMException(type); } } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/MaskManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/MaskManager.java index aefd3ec02..7181b4807 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/MaskManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/MaskManager.java @@ -19,9 +19,9 @@ package io.sf.carte.echosvg.css.engine.value.svg; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.value.AbstractValueManager; import io.sf.carte.echosvg.css.engine.value.URIValue; @@ -34,8 +34,10 @@ /** * This class provides a manager for the 'mask' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class MaskManager extends AbstractValueManager { @@ -111,20 +113,19 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { switch (type) { - case CSSPrimitiveValue.CSS_IDENT: + case IDENT: if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) { return ValueConstants.NONE_VALUE; } break; - case CSSPrimitiveValue.CSS_URI: + case URI: return new URIValue(value, resolveURI(engine.getCSSBaseURI(), value)); + default: + break; } throw createInvalidStringTypeDOMException(type); } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/OpacityManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/OpacityManager.java index 8415290a4..da37217b3 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/OpacityManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/OpacityManager.java @@ -18,8 +18,8 @@ */ package io.sf.carte.echosvg.css.engine.value.svg; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; import io.sf.carte.echosvg.css.engine.CSSEngine; @@ -33,8 +33,10 @@ /** * This class provides a manager for the '*-opacity' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class OpacityManager extends AbstractValueManager { @@ -115,10 +117,10 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return ValueConstants.INHERIT_VALUE; case INTEGER: - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getIntegerValue()); + return new FloatValue(CSSUnit.CSS_NUMBER, lu.getIntegerValue()); case REAL: - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getFloatValue()); + return new FloatValue(CSSUnit.CSS_NUMBER, lu.getFloatValue()); default: break; @@ -131,7 +133,7 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { */ @Override public Value createFloatValue(short type, float floatValue) throws DOMException { - if (type == CSSPrimitiveValue.CSS_NUMBER) { + if (type == CSSUnit.CSS_NUMBER) { return new FloatValue(type, floatValue); } throw createInvalidFloatTypeDOMException(type); diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SVGColorManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SVGColorManager.java index 946ae6ee7..489a3d7c6 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SVGColorManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SVGColorManager.java @@ -19,7 +19,6 @@ package io.sf.carte.echosvg.css.engine.value.svg; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; import io.sf.carte.echosvg.css.engine.CSSEngine; @@ -29,18 +28,16 @@ import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.css.engine.value.ValueConstants; import io.sf.carte.echosvg.css.engine.value.ValueManager; -import io.sf.carte.echosvg.css.engine.value.svg12.CIELCHColor; -import io.sf.carte.echosvg.css.engine.value.svg12.CIELabColor; -import io.sf.carte.echosvg.css.engine.value.svg12.DeviceColor; -import io.sf.carte.echosvg.css.engine.value.svg12.ICCNamedColor; import io.sf.carte.echosvg.util.CSSConstants; import io.sf.carte.echosvg.util.SVGTypes; /** * This class provides a manager for the SVGColor property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class SVGColorManager extends ColorManager { @@ -161,6 +158,9 @@ private Value parseColorFunction(LexicalUnit lu, Value v) { } private Value parseColor12Function(LexicalUnit lu, Value v) { + throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Deprecated color."); + /* + * @formatter: off String functionName = lu.getFunctionName(); if (functionName.equalsIgnoreCase(ICCNamedColor.ICC_NAMED_COLOR_FUNCTION)) { return createICCNamedColorValue(lu, v); @@ -178,6 +178,8 @@ private Value parseColor12Function(LexicalUnit lu, Value v) { return createDeviceColorValue(lu, v, 0); } return null; + * @formatter: on + */ } private Value createICCColorValue(LexicalUnit lu, Value v) { @@ -196,81 +198,6 @@ private Value createICCColorValue(LexicalUnit lu, Value v) { return icc; } - private Value createICCNamedColorValue(LexicalUnit lu, Value v) { - lu = lu.getParameters(); - expectIdent(lu); - String profileName = lu.getStringValue(); - - lu = lu.getNextLexicalUnit(); - expectComma(lu); - lu = lu.getNextLexicalUnit(); - expectIdent(lu); - String colorName = lu.getStringValue(); - - ICCNamedColor icc = new ICCNamedColor(profileName, colorName); - - lu = lu.getNextLexicalUnit(); - return icc; - } - - private Value createCIELabColorValue(LexicalUnit lu, Value v) { - lu = lu.getParameters(); - float l = getColorValue(lu); - lu = lu.getNextLexicalUnit(); - expectComma(lu); - lu = lu.getNextLexicalUnit(); - float a = getColorValue(lu); - lu = lu.getNextLexicalUnit(); - expectComma(lu); - lu = lu.getNextLexicalUnit(); - float b = getColorValue(lu); - - CIELabColor icc = new CIELabColor(l, a, b); - - lu = lu.getNextLexicalUnit(); - return icc; - } - - private Value createCIELCHColorValue(LexicalUnit lu, Value v) { - lu = lu.getParameters(); - float l = getColorValue(lu); - lu = lu.getNextLexicalUnit(); - expectComma(lu); - lu = lu.getNextLexicalUnit(); - float c = getColorValue(lu); - lu = lu.getNextLexicalUnit(); - expectComma(lu); - lu = lu.getNextLexicalUnit(); - float h = getColorValue(lu); - - CIELCHColor icc = new CIELCHColor(l, c, h); - - lu = lu.getNextLexicalUnit(); - return icc; - } - - private Value createDeviceColorValue(LexicalUnit lu, Value v, int expectedComponents) { - lu = lu.getParameters(); - - boolean nChannel = (expectedComponents <= 0); - DeviceColor col = new DeviceColor(nChannel); - - col.append(getColorValue(lu)); - LexicalUnit lastUnit = lu; - lu = lu.getNextLexicalUnit(); - while (lu != null) { - expectComma(lu); - lu = lu.getNextLexicalUnit(); - col.append(getColorValue(lu)); - lastUnit = lu; - lu = lu.getNextLexicalUnit(); - } - if (!nChannel && expectedComponents != col.getNumberOfColors()) { - throw createInvalidLexicalUnitDOMException(lastUnit.getLexicalUnitType()); - } - return col; - } - private void expectIdent(LexicalUnit lu) { if (lu.getLexicalUnitType() != LexicalUnit.LexicalType.IDENT) { throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); @@ -302,14 +229,13 @@ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engin int ci = engine.getColorIndex(); return engine.getComputedStyle(elt, pseudo, ci); } - if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { - ListValue lv = (ListValue) value; - Value v = lv.item(0); + if (value.getCssValueType() == Value.CssType.LIST) { + Value v = value.item(0); Value t = super.computeValue(elt, pseudo, engine, idx, sm, v); if (t != v) { ListValue result = new ListValue(' '); result.append(t); - result.append(lv.item(1)); + result.append(value.item(1)); return result; } return value; diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SVGPaintManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SVGPaintManager.java index 83412670f..383d3b24b 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SVGPaintManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SVGPaintManager.java @@ -19,8 +19,6 @@ package io.sf.carte.echosvg.css.engine.value.svg; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; import io.sf.carte.echosvg.css.engine.CSSEngine; @@ -37,8 +35,10 @@ /** * This class provides a manager for the SVGPaint property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class SVGPaintManager extends SVGColorManager { @@ -124,10 +124,9 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { } } Value v = super.createValue(lu, engine); - if (v.getCssValueType() == CSSValue.CSS_CUSTOM) { - ListValue lv = (ListValue) v; - for (int i = 0; i < lv.getLength(); i++) { - result.append(lv.item(i)); + if (v instanceof ListValue) { + for (int i = 0; i < v.getLength(); i++) { + result.append(v.item(i)); } } else { result.append(v); @@ -145,21 +144,20 @@ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engin if (value == ValueConstants.NONE_VALUE) { return value; } - if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { - ListValue lv = (ListValue) value; - Value v = lv.item(0); - if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_URI) { - v = lv.item(1); + if (value.getCssValueType() == Value.CssType.LIST) { + Value v = value.item(0); + if (v.getPrimitiveType() == Value.Type.URI) { + v = value.item(1); if (v == ValueConstants.NONE_VALUE) { return value; } Value t = super.computeValue(elt, pseudo, engine, idx, sm, v); if (t != v) { ListValue result = new ListValue(' '); - result.append(lv.item(0)); + result.append(value.item(0)); result.append(t); - if (lv.getLength() == 3) { - result.append(lv.item(1)); + if (value.getLength() == 3) { + result.append(value.item(1)); } return result; } diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SVGValueConstants.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SVGValueConstants.java index 78b7b3ec4..84d6c3870 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SVGValueConstants.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SVGValueConstants.java @@ -18,11 +18,12 @@ */ package io.sf.carte.echosvg.css.engine.value.svg; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.w3c.css.om.unit.CSSUnit; import io.sf.carte.echosvg.css.engine.value.FloatValue; +import io.sf.carte.echosvg.css.engine.value.IdentValue; +import io.sf.carte.echosvg.css.engine.value.NumericValue; import io.sf.carte.echosvg.css.engine.value.RGBColorValue; -import io.sf.carte.echosvg.css.engine.value.StringValue; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.css.engine.value.ValueConstants; import io.sf.carte.echosvg.util.CSSConstants; @@ -30,8 +31,10 @@ /** * This interface provides constants for SVG values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public interface SVGValueConstants extends ValueConstants { @@ -39,1564 +42,1557 @@ public interface SVGValueConstants extends ValueConstants { /** * 0 degree */ - Value ZERO_DEGREE = new FloatValue(CSSPrimitiveValue.CSS_DEG, 0); + NumericValue ZERO_DEGREE = new FloatValue(CSSUnit.CSS_DEG, 0); /** * 1 */ - Value NUMBER_1 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 1); + NumericValue NUMBER_1 = new FloatValue(CSSUnit.CSS_NUMBER, 1); /** * 4 */ - Value NUMBER_4 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 4); + NumericValue NUMBER_4 = new FloatValue(CSSUnit.CSS_NUMBER, 4); /** * 11 */ - Value NUMBER_11 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 11); + NumericValue NUMBER_11 = new FloatValue(CSSUnit.CSS_NUMBER, 11); /** * 19 */ - Value NUMBER_19 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 19); + NumericValue NUMBER_19 = new FloatValue(CSSUnit.CSS_NUMBER, 19); /** * 20 */ - Value NUMBER_20 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 20); + NumericValue NUMBER_20 = new FloatValue(CSSUnit.CSS_NUMBER, 20); /** * 21 */ - Value NUMBER_21 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 21); + NumericValue NUMBER_21 = new FloatValue(CSSUnit.CSS_NUMBER, 21); /** * 25 */ - Value NUMBER_25 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 25); + NumericValue NUMBER_25 = new FloatValue(CSSUnit.CSS_NUMBER, 25); /** * 30 */ - Value NUMBER_30 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 30); + NumericValue NUMBER_30 = new FloatValue(CSSUnit.CSS_NUMBER, 30); /** * 32 */ - Value NUMBER_32 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 32); + NumericValue NUMBER_32 = new FloatValue(CSSUnit.CSS_NUMBER, 32); /** * 34 */ - Value NUMBER_34 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 34); + NumericValue NUMBER_34 = new FloatValue(CSSUnit.CSS_NUMBER, 34); /** * 35 */ - Value NUMBER_35 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 35); + NumericValue NUMBER_35 = new FloatValue(CSSUnit.CSS_NUMBER, 35); /** * 42 */ - Value NUMBER_42 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 42); + NumericValue NUMBER_42 = new FloatValue(CSSUnit.CSS_NUMBER, 42); /** * 43 */ - Value NUMBER_43 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 43); + NumericValue NUMBER_43 = new FloatValue(CSSUnit.CSS_NUMBER, 43); /** * 45 */ - Value NUMBER_45 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 45); + NumericValue NUMBER_45 = new FloatValue(CSSUnit.CSS_NUMBER, 45); /** * 46 */ - Value NUMBER_46 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 46); + NumericValue NUMBER_46 = new FloatValue(CSSUnit.CSS_NUMBER, 46); /** * 47 */ - Value NUMBER_47 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 47); + NumericValue NUMBER_47 = new FloatValue(CSSUnit.CSS_NUMBER, 47); /** * 50 */ - Value NUMBER_50 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 50); + NumericValue NUMBER_50 = new FloatValue(CSSUnit.CSS_NUMBER, 50); /** * 60 */ - Value NUMBER_60 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 60); + NumericValue NUMBER_60 = new FloatValue(CSSUnit.CSS_NUMBER, 60); /** * 61 */ - Value NUMBER_61 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 61); + NumericValue NUMBER_61 = new FloatValue(CSSUnit.CSS_NUMBER, 61); /** * 63 */ - Value NUMBER_63 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 63); + NumericValue NUMBER_63 = new FloatValue(CSSUnit.CSS_NUMBER, 63); /** * 64 */ - Value NUMBER_64 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 64); + NumericValue NUMBER_64 = new FloatValue(CSSUnit.CSS_NUMBER, 64); /** * 65 */ - Value NUMBER_65 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 65); + NumericValue NUMBER_65 = new FloatValue(CSSUnit.CSS_NUMBER, 65); /** * 69 */ - Value NUMBER_69 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 69); + NumericValue NUMBER_69 = new FloatValue(CSSUnit.CSS_NUMBER, 69); /** * 70 */ - Value NUMBER_70 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 70); + NumericValue NUMBER_70 = new FloatValue(CSSUnit.CSS_NUMBER, 70); /** * 71 */ - Value NUMBER_71 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 71); + NumericValue NUMBER_71 = new FloatValue(CSSUnit.CSS_NUMBER, 71); /** * 72 */ - Value NUMBER_72 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 72); + NumericValue NUMBER_72 = new FloatValue(CSSUnit.CSS_NUMBER, 72); /** * 75 */ - Value NUMBER_75 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 75); + NumericValue NUMBER_75 = new FloatValue(CSSUnit.CSS_NUMBER, 75); /** * 79 */ - Value NUMBER_79 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 79); + NumericValue NUMBER_79 = new FloatValue(CSSUnit.CSS_NUMBER, 79); /** * 80 */ - Value NUMBER_80 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 80); + NumericValue NUMBER_80 = new FloatValue(CSSUnit.CSS_NUMBER, 80); /** * 82 */ - Value NUMBER_82 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 82); + NumericValue NUMBER_82 = new FloatValue(CSSUnit.CSS_NUMBER, 82); /** * 85 */ - Value NUMBER_85 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 85); + NumericValue NUMBER_85 = new FloatValue(CSSUnit.CSS_NUMBER, 85); /** * 87 */ - Value NUMBER_87 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 87); + NumericValue NUMBER_87 = new FloatValue(CSSUnit.CSS_NUMBER, 87); /** * 90 */ - Value NUMBER_90 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 90); + NumericValue NUMBER_90 = new FloatValue(CSSUnit.CSS_NUMBER, 90); /** * 91 */ - Value NUMBER_91 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 91); + NumericValue NUMBER_91 = new FloatValue(CSSUnit.CSS_NUMBER, 91); /** * 92 */ - Value NUMBER_92 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 92); + NumericValue NUMBER_92 = new FloatValue(CSSUnit.CSS_NUMBER, 92); /** * 95 */ - Value NUMBER_95 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 95); + NumericValue NUMBER_95 = new FloatValue(CSSUnit.CSS_NUMBER, 95); /** * 96 */ - Value NUMBER_96 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 96); + NumericValue NUMBER_96 = new FloatValue(CSSUnit.CSS_NUMBER, 96); /** * 99 */ - Value NUMBER_99 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 99); + NumericValue NUMBER_99 = new FloatValue(CSSUnit.CSS_NUMBER, 99); /** * 102 */ - Value NUMBER_102 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 102); + NumericValue NUMBER_102 = new FloatValue(CSSUnit.CSS_NUMBER, 102); /** * 104 */ - Value NUMBER_104 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 104); + NumericValue NUMBER_104 = new FloatValue(CSSUnit.CSS_NUMBER, 104); /** * 105 */ - Value NUMBER_105 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 105); + NumericValue NUMBER_105 = new FloatValue(CSSUnit.CSS_NUMBER, 105); /** * 106 */ - Value NUMBER_106 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 106); + NumericValue NUMBER_106 = new FloatValue(CSSUnit.CSS_NUMBER, 106); /** * 107 */ - Value NUMBER_107 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 107); + NumericValue NUMBER_107 = new FloatValue(CSSUnit.CSS_NUMBER, 107); /** * 112 */ - Value NUMBER_112 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 112); + NumericValue NUMBER_112 = new FloatValue(CSSUnit.CSS_NUMBER, 112); /** * 113 */ - Value NUMBER_113 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 113); + NumericValue NUMBER_113 = new FloatValue(CSSUnit.CSS_NUMBER, 113); /** * 114 */ - Value NUMBER_114 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 114); + NumericValue NUMBER_114 = new FloatValue(CSSUnit.CSS_NUMBER, 114); /** * 119 */ - Value NUMBER_119 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 119); + NumericValue NUMBER_119 = new FloatValue(CSSUnit.CSS_NUMBER, 119); /** * 122 */ - Value NUMBER_122 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 122); + NumericValue NUMBER_122 = new FloatValue(CSSUnit.CSS_NUMBER, 122); /** * 123 */ - Value NUMBER_123 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 123); + NumericValue NUMBER_123 = new FloatValue(CSSUnit.CSS_NUMBER, 123); /** * 124 */ - Value NUMBER_124 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 124); + NumericValue NUMBER_124 = new FloatValue(CSSUnit.CSS_NUMBER, 124); /** * 127 */ - Value NUMBER_127 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 127); + NumericValue NUMBER_127 = new FloatValue(CSSUnit.CSS_NUMBER, 127); /** * 130 */ - Value NUMBER_130 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 130); + NumericValue NUMBER_130 = new FloatValue(CSSUnit.CSS_NUMBER, 130); /** * 133 */ - Value NUMBER_133 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 133); + NumericValue NUMBER_133 = new FloatValue(CSSUnit.CSS_NUMBER, 133); /** * 134 */ - Value NUMBER_134 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 134); + NumericValue NUMBER_134 = new FloatValue(CSSUnit.CSS_NUMBER, 134); /** * 135 */ - Value NUMBER_135 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 135); + NumericValue NUMBER_135 = new FloatValue(CSSUnit.CSS_NUMBER, 135); /** * 136 */ - Value NUMBER_136 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 136); + NumericValue NUMBER_136 = new FloatValue(CSSUnit.CSS_NUMBER, 136); /** * 138 */ - Value NUMBER_138 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 138); + NumericValue NUMBER_138 = new FloatValue(CSSUnit.CSS_NUMBER, 138); /** * 139 */ - Value NUMBER_139 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 139); + NumericValue NUMBER_139 = new FloatValue(CSSUnit.CSS_NUMBER, 139); /** * 140 */ - Value NUMBER_140 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 140); + NumericValue NUMBER_140 = new FloatValue(CSSUnit.CSS_NUMBER, 140); /** * 142 */ - Value NUMBER_142 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 142); + NumericValue NUMBER_142 = new FloatValue(CSSUnit.CSS_NUMBER, 142); /** * 143 */ - Value NUMBER_143 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 143); + NumericValue NUMBER_143 = new FloatValue(CSSUnit.CSS_NUMBER, 143); /** * 144 */ - Value NUMBER_144 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 144); + NumericValue NUMBER_144 = new FloatValue(CSSUnit.CSS_NUMBER, 144); /** * 147 */ - Value NUMBER_147 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 147); + NumericValue NUMBER_147 = new FloatValue(CSSUnit.CSS_NUMBER, 147); /** * 148 */ - Value NUMBER_148 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 148); + NumericValue NUMBER_148 = new FloatValue(CSSUnit.CSS_NUMBER, 148); /** * 149 */ - Value NUMBER_149 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 149); + NumericValue NUMBER_149 = new FloatValue(CSSUnit.CSS_NUMBER, 149); /** * 150 */ - Value NUMBER_150 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 150); + NumericValue NUMBER_150 = new FloatValue(CSSUnit.CSS_NUMBER, 150); /** * 152 */ - Value NUMBER_152 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 152); + NumericValue NUMBER_152 = new FloatValue(CSSUnit.CSS_NUMBER, 152); /** * 153 */ - Value NUMBER_153 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 153); + NumericValue NUMBER_153 = new FloatValue(CSSUnit.CSS_NUMBER, 153); /** * 154 */ - Value NUMBER_154 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 154); + NumericValue NUMBER_154 = new FloatValue(CSSUnit.CSS_NUMBER, 154); /** * 158 */ - Value NUMBER_158 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 158); + NumericValue NUMBER_158 = new FloatValue(CSSUnit.CSS_NUMBER, 158); /** * 160 */ - Value NUMBER_160 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 160); + NumericValue NUMBER_160 = new FloatValue(CSSUnit.CSS_NUMBER, 160); /** * 164 */ - Value NUMBER_164 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 164); + NumericValue NUMBER_164 = new FloatValue(CSSUnit.CSS_NUMBER, 164); /** * 165 */ - Value NUMBER_165 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 165); + NumericValue NUMBER_165 = new FloatValue(CSSUnit.CSS_NUMBER, 165); /** * 169 */ - Value NUMBER_169 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 169); + NumericValue NUMBER_169 = new FloatValue(CSSUnit.CSS_NUMBER, 169); /** * 170 */ - Value NUMBER_170 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 170); + NumericValue NUMBER_170 = new FloatValue(CSSUnit.CSS_NUMBER, 170); /** * 173 */ - Value NUMBER_173 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 173); + NumericValue NUMBER_173 = new FloatValue(CSSUnit.CSS_NUMBER, 173); /** * 175 */ - Value NUMBER_175 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 175); + NumericValue NUMBER_175 = new FloatValue(CSSUnit.CSS_NUMBER, 175); /** * 176 */ - Value NUMBER_176 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 176); + NumericValue NUMBER_176 = new FloatValue(CSSUnit.CSS_NUMBER, 176); /** * 178 */ - Value NUMBER_178 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 178); + NumericValue NUMBER_178 = new FloatValue(CSSUnit.CSS_NUMBER, 178); /** * 179 */ - Value NUMBER_179 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 179); + NumericValue NUMBER_179 = new FloatValue(CSSUnit.CSS_NUMBER, 179); /** * 180 */ - Value NUMBER_180 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 180); + NumericValue NUMBER_180 = new FloatValue(CSSUnit.CSS_NUMBER, 180); /** * 181 */ - Value NUMBER_181 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 181); + NumericValue NUMBER_181 = new FloatValue(CSSUnit.CSS_NUMBER, 181); /** * 182 */ - Value NUMBER_182 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 182); + NumericValue NUMBER_182 = new FloatValue(CSSUnit.CSS_NUMBER, 182); /** * 183 */ - Value NUMBER_183 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 183); + NumericValue NUMBER_183 = new FloatValue(CSSUnit.CSS_NUMBER, 183); /** * 184 */ - Value NUMBER_184 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 184); + NumericValue NUMBER_184 = new FloatValue(CSSUnit.CSS_NUMBER, 184); /** * 185 */ - Value NUMBER_185 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 185); + NumericValue NUMBER_185 = new FloatValue(CSSUnit.CSS_NUMBER, 185); /** * 186 */ - Value NUMBER_186 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 186); + NumericValue NUMBER_186 = new FloatValue(CSSUnit.CSS_NUMBER, 186); /** * 188 */ - Value NUMBER_188 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 188); + NumericValue NUMBER_188 = new FloatValue(CSSUnit.CSS_NUMBER, 188); /** * 189 */ - Value NUMBER_189 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 189); + NumericValue NUMBER_189 = new FloatValue(CSSUnit.CSS_NUMBER, 189); /** * 191 */ - Value NUMBER_191 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 191); + NumericValue NUMBER_191 = new FloatValue(CSSUnit.CSS_NUMBER, 191); /** * 193 */ - Value NUMBER_193 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 193); + NumericValue NUMBER_193 = new FloatValue(CSSUnit.CSS_NUMBER, 193); /** * 196 */ - Value NUMBER_196 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 196); + NumericValue NUMBER_196 = new FloatValue(CSSUnit.CSS_NUMBER, 196); /** * 199 */ - Value NUMBER_199 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 199); + NumericValue NUMBER_199 = new FloatValue(CSSUnit.CSS_NUMBER, 199); /** * 203 */ - Value NUMBER_203 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 203); + NumericValue NUMBER_203 = new FloatValue(CSSUnit.CSS_NUMBER, 203); /** * 204 */ - Value NUMBER_204 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 204); + NumericValue NUMBER_204 = new FloatValue(CSSUnit.CSS_NUMBER, 204); /** * 205 */ - Value NUMBER_205 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 205); + NumericValue NUMBER_205 = new FloatValue(CSSUnit.CSS_NUMBER, 205); /** * 206 */ - Value NUMBER_206 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 206); + NumericValue NUMBER_206 = new FloatValue(CSSUnit.CSS_NUMBER, 206); /** * 208 */ - Value NUMBER_208 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 208); + NumericValue NUMBER_208 = new FloatValue(CSSUnit.CSS_NUMBER, 208); /** * 209 */ - Value NUMBER_209 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 209); + NumericValue NUMBER_209 = new FloatValue(CSSUnit.CSS_NUMBER, 209); /** * 210 */ - Value NUMBER_210 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 210); + NumericValue NUMBER_210 = new FloatValue(CSSUnit.CSS_NUMBER, 210); /** * 211 */ - Value NUMBER_211 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 211); + NumericValue NUMBER_211 = new FloatValue(CSSUnit.CSS_NUMBER, 211); /** * 212 */ - Value NUMBER_212 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 212); + NumericValue NUMBER_212 = new FloatValue(CSSUnit.CSS_NUMBER, 212); /** * 213 */ - Value NUMBER_213 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 213); + NumericValue NUMBER_213 = new FloatValue(CSSUnit.CSS_NUMBER, 213); /** * 214 */ - Value NUMBER_214 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 214); + NumericValue NUMBER_214 = new FloatValue(CSSUnit.CSS_NUMBER, 214); /** * 215 */ - Value NUMBER_215 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 215); + NumericValue NUMBER_215 = new FloatValue(CSSUnit.CSS_NUMBER, 215); /** * 216 */ - Value NUMBER_216 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 216); + NumericValue NUMBER_216 = new FloatValue(CSSUnit.CSS_NUMBER, 216); /** * 218 */ - Value NUMBER_218 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 218); + NumericValue NUMBER_218 = new FloatValue(CSSUnit.CSS_NUMBER, 218); /** * 219 */ - Value NUMBER_219 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 219); + NumericValue NUMBER_219 = new FloatValue(CSSUnit.CSS_NUMBER, 219); /** * 220 */ - Value NUMBER_220 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 220); + NumericValue NUMBER_220 = new FloatValue(CSSUnit.CSS_NUMBER, 220); /** * 221 */ - Value NUMBER_221 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 221); + NumericValue NUMBER_221 = new FloatValue(CSSUnit.CSS_NUMBER, 221); /** * 222 */ - Value NUMBER_222 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 222); + NumericValue NUMBER_222 = new FloatValue(CSSUnit.CSS_NUMBER, 222); /** * 224 */ - Value NUMBER_224 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 224); + NumericValue NUMBER_224 = new FloatValue(CSSUnit.CSS_NUMBER, 224); /** * 225 */ - Value NUMBER_225 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 225); + NumericValue NUMBER_225 = new FloatValue(CSSUnit.CSS_NUMBER, 225); /** * 226 */ - Value NUMBER_226 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 226); + NumericValue NUMBER_226 = new FloatValue(CSSUnit.CSS_NUMBER, 226); /** * 228 */ - Value NUMBER_228 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 228); + NumericValue NUMBER_228 = new FloatValue(CSSUnit.CSS_NUMBER, 228); /** * 230 */ - Value NUMBER_230 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 230); + NumericValue NUMBER_230 = new FloatValue(CSSUnit.CSS_NUMBER, 230); /** * 232 */ - Value NUMBER_232 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 232); + NumericValue NUMBER_232 = new FloatValue(CSSUnit.CSS_NUMBER, 232); /** * 233 */ - Value NUMBER_233 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 233); + NumericValue NUMBER_233 = new FloatValue(CSSUnit.CSS_NUMBER, 233); /** * 235 */ - Value NUMBER_235 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 235); + NumericValue NUMBER_235 = new FloatValue(CSSUnit.CSS_NUMBER, 235); /** * 237 */ - Value NUMBER_237 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 237); + NumericValue NUMBER_237 = new FloatValue(CSSUnit.CSS_NUMBER, 237); /** * 238 */ - Value NUMBER_238 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 238); + NumericValue NUMBER_238 = new FloatValue(CSSUnit.CSS_NUMBER, 238); /** * 239 */ - Value NUMBER_239 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 239); + NumericValue NUMBER_239 = new FloatValue(CSSUnit.CSS_NUMBER, 239); /** * 240 */ - Value NUMBER_240 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 240); + NumericValue NUMBER_240 = new FloatValue(CSSUnit.CSS_NUMBER, 240); /** * 244 */ - Value NUMBER_244 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 244); + NumericValue NUMBER_244 = new FloatValue(CSSUnit.CSS_NUMBER, 244); /** * 245 */ - Value NUMBER_245 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 245); + NumericValue NUMBER_245 = new FloatValue(CSSUnit.CSS_NUMBER, 245); /** * 248 */ - Value NUMBER_248 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 248); + NumericValue NUMBER_248 = new FloatValue(CSSUnit.CSS_NUMBER, 248); /** * 250 */ - Value NUMBER_250 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 250); + NumericValue NUMBER_250 = new FloatValue(CSSUnit.CSS_NUMBER, 250); /** * 251 */ - Value NUMBER_251 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 251); + NumericValue NUMBER_251 = new FloatValue(CSSUnit.CSS_NUMBER, 251); /** * 252 */ - Value NUMBER_252 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 252); + NumericValue NUMBER_252 = new FloatValue(CSSUnit.CSS_NUMBER, 252); /** * 253 */ - Value NUMBER_253 = new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 253); + NumericValue NUMBER_253 = new FloatValue(CSSUnit.CSS_NUMBER, 253); /** * The 'accumulate' keyword. */ - Value ACCUMULATE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ACCUMULATE_VALUE); + Value ACCUMULATE_VALUE = new IdentValue(CSSConstants.CSS_ACCUMULATE_VALUE); /** * The 'after-edge' keyword. */ - Value AFTER_EDGE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_AFTER_EDGE_VALUE); + Value AFTER_EDGE_VALUE = new IdentValue(CSSConstants.CSS_AFTER_EDGE_VALUE); /** * The 'alphabetic' keyword. */ - Value ALPHABETIC_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ALPHABETIC_VALUE); + Value ALPHABETIC_VALUE = new IdentValue(CSSConstants.CSS_ALPHABETIC_VALUE); /** * The 'baseline' keyword. */ - Value BASELINE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BASELINE_VALUE); + Value BASELINE_VALUE = new IdentValue(CSSConstants.CSS_BASELINE_VALUE); /** * The 'before-edge' keyword. */ - Value BEFORE_EDGE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BEFORE_EDGE_VALUE); + Value BEFORE_EDGE_VALUE = new IdentValue(CSSConstants.CSS_BEFORE_EDGE_VALUE); /** * The 'bevel' keyword. */ - Value BEVEL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BEVEL_VALUE); + Value BEVEL_VALUE = new IdentValue(CSSConstants.CSS_BEVEL_VALUE); /** * The 'butt' keyword. */ - Value BUTT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BUTT_VALUE); + Value BUTT_VALUE = new IdentValue(CSSConstants.CSS_BUTT_VALUE); /** * The 'central' keyword. */ - Value CENTRAL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CENTRAL_VALUE); + Value CENTRAL_VALUE = new IdentValue(CSSConstants.CSS_CENTRAL_VALUE); /** * The 'currentcolor' keyword. */ - Value CURRENTCOLOR_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CURRENTCOLOR_VALUE); + Value CURRENTCOLOR_VALUE = new IdentValue(CSSConstants.CSS_CURRENTCOLOR_VALUE); /** * The 'end' keyword. */ - Value END_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_END_VALUE); + Value END_VALUE = new IdentValue(CSSConstants.CSS_END_VALUE); /** * The 'evenodd' keyword. */ - Value EVENODD_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_EVENODD_VALUE); + Value EVENODD_VALUE = new IdentValue(CSSConstants.CSS_EVENODD_VALUE); /** * The 'fill' keyword. */ - Value FILL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_FILL_VALUE); + Value FILL_VALUE = new IdentValue(CSSConstants.CSS_FILL_VALUE); /** * The 'fillstroke' keyword. */ - Value FILLSTROKE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_FILLSTROKE_VALUE); + Value FILLSTROKE_VALUE = new IdentValue(CSSConstants.CSS_FILLSTROKE_VALUE); /** * The 'geometricprecision' keyword. */ - Value GEOMETRICPRECISION_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_GEOMETRICPRECISION_VALUE); + Value GEOMETRICPRECISION_VALUE = new IdentValue(CSSConstants.CSS_GEOMETRICPRECISION_VALUE); /** * The 'hanging' keyword. */ - Value HANGING_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_HANGING_VALUE); + Value HANGING_VALUE = new IdentValue(CSSConstants.CSS_HANGING_VALUE); /** * The 'ideographic' keyword. */ - Value IDEOGRAPHIC_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_IDEOGRAPHIC_VALUE); + Value IDEOGRAPHIC_VALUE = new IdentValue(CSSConstants.CSS_IDEOGRAPHIC_VALUE); /** * The 'linearRGB' keyword. */ - Value LINEARRGB_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LINEARRGB_VALUE); + Value LINEARRGB_VALUE = new IdentValue(CSSConstants.CSS_LINEARRGB_VALUE); /** * The 'lr' keyword. */ - Value LR_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LR_VALUE); + Value LR_VALUE = new IdentValue(CSSConstants.CSS_LR_VALUE); /** * The 'lr-tb' keyword. */ - Value LR_TB_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LR_TB_VALUE); + Value LR_TB_VALUE = new IdentValue(CSSConstants.CSS_LR_TB_VALUE); /** * The 'mathematical' keyword. */ - Value MATHEMATICAL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MATHEMATICAL_VALUE); + Value MATHEMATICAL_VALUE = new IdentValue(CSSConstants.CSS_MATHEMATICAL_VALUE); /** * The 'middle' keyword. */ - Value MIDDLE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MIDDLE_VALUE); + Value MIDDLE_VALUE = new IdentValue(CSSConstants.CSS_MIDDLE_VALUE); /** * The 'new' keyword. */ - Value NEW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_NEW_VALUE); + Value NEW_VALUE = new IdentValue(CSSConstants.CSS_NEW_VALUE); /** * The 'miter' keyword. */ - Value MITER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MITER_VALUE); + Value MITER_VALUE = new IdentValue(CSSConstants.CSS_MITER_VALUE); /** * The 'no-change' keyword. */ - Value NO_CHANGE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_NO_CHANGE_VALUE); + Value NO_CHANGE_VALUE = new IdentValue(CSSConstants.CSS_NO_CHANGE_VALUE); /** * The 'nonzero' keyword. */ - Value NONZERO_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_NONZERO_VALUE); + Value NONZERO_VALUE = new IdentValue(CSSConstants.CSS_NONZERO_VALUE); /** * The 'optimizeLegibility' keyword. */ - Value OPTIMIZELEGIBILITY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_OPTIMIZELEGIBILITY_VALUE); + Value OPTIMIZELEGIBILITY_VALUE = new IdentValue(CSSConstants.CSS_OPTIMIZELEGIBILITY_VALUE); /** * The 'optimizeQuality' keyword. */ - Value OPTIMIZEQUALITY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_OPTIMIZEQUALITY_VALUE); + Value OPTIMIZEQUALITY_VALUE = new IdentValue(CSSConstants.CSS_OPTIMIZEQUALITY_VALUE); /** * The 'optimizeSpeed' keyword. */ - Value OPTIMIZESPEED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_OPTIMIZESPEED_VALUE); + Value OPTIMIZESPEED_VALUE = new IdentValue(CSSConstants.CSS_OPTIMIZESPEED_VALUE); /** * The 'reset-size' keyword. */ - Value RESET_SIZE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_RESET_SIZE_VALUE); + Value RESET_SIZE_VALUE = new IdentValue(CSSConstants.CSS_RESET_SIZE_VALUE); /** * The 'rl' keyword. */ - Value RL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_RL_VALUE); + Value RL_VALUE = new IdentValue(CSSConstants.CSS_RL_VALUE); /** * The 'rl-tb' keyword. */ - Value RL_TB_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_RL_TB_VALUE); + Value RL_TB_VALUE = new IdentValue(CSSConstants.CSS_RL_TB_VALUE); /** * The 'round' keyword. */ - Value ROUND_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ROUND_VALUE); + Value ROUND_VALUE = new IdentValue(CSSConstants.CSS_ROUND_VALUE); /** * The 'square' keyword. */ - Value SQUARE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SQUARE_VALUE); + Value SQUARE_VALUE = new IdentValue(CSSConstants.CSS_SQUARE_VALUE); /** * The 'sRGB' keyword. */ - Value SRGB_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SRGB_VALUE); + Value SRGB_VALUE = new IdentValue(CSSConstants.CSS_SRGB_VALUE); /** * The 'start' keyword. */ - Value START_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_START_VALUE); + Value START_VALUE = new IdentValue(CSSConstants.CSS_START_VALUE); /** * The 'sub' keyword. */ - Value SUB_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SUB_VALUE); + Value SUB_VALUE = new IdentValue(CSSConstants.CSS_SUB_VALUE); /** * The 'super' keyword. */ - Value SUPER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SUPER_VALUE); + Value SUPER_VALUE = new IdentValue(CSSConstants.CSS_SUPER_VALUE); /** * The 'tb' keyword. */ - Value TB_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TB_VALUE); + Value TB_VALUE = new IdentValue(CSSConstants.CSS_TB_VALUE); /** * The 'tb-rl' keyword. */ - Value TB_RL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TB_RL_VALUE); + Value TB_RL_VALUE = new IdentValue(CSSConstants.CSS_TB_RL_VALUE); /** * The 'text-after-edge' keyword. */ - Value TEXT_AFTER_EDGE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TEXT_AFTER_EDGE_VALUE); + Value TEXT_AFTER_EDGE_VALUE = new IdentValue(CSSConstants.CSS_TEXT_AFTER_EDGE_VALUE); /** * The 'text-before-edge' keyword. */ - Value TEXT_BEFORE_EDGE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_TEXT_BEFORE_EDGE_VALUE); + Value TEXT_BEFORE_EDGE_VALUE = new IdentValue(CSSConstants.CSS_TEXT_BEFORE_EDGE_VALUE); /** * The 'text-bottom' keyword. */ - Value TEXT_BOTTOM_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TEXT_BOTTOM_VALUE); + Value TEXT_BOTTOM_VALUE = new IdentValue(CSSConstants.CSS_TEXT_BOTTOM_VALUE); /** * The 'text-top' keyword. */ - Value TEXT_TOP_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TEXT_TOP_VALUE); + Value TEXT_TOP_VALUE = new IdentValue(CSSConstants.CSS_TEXT_TOP_VALUE); /** * The 'use-script' keyword. */ - Value USE_SCRIPT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_USE_SCRIPT_VALUE); + Value USE_SCRIPT_VALUE = new IdentValue(CSSConstants.CSS_USE_SCRIPT_VALUE); /** * The 'visiblefill' keyword. */ - Value VISIBLEFILL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_VISIBLEFILL_VALUE); + Value VISIBLEFILL_VALUE = new IdentValue(CSSConstants.CSS_VISIBLEFILL_VALUE); /** * The 'visiblefillstroke' keyword. */ - Value VISIBLEFILLSTROKE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_VISIBLEFILLSTROKE_VALUE); + Value VISIBLEFILLSTROKE_VALUE = new IdentValue(CSSConstants.CSS_VISIBLEFILLSTROKE_VALUE); /** * The 'visiblepainted' keyword. */ - Value VISIBLEPAINTED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_VISIBLEPAINTED_VALUE); + Value VISIBLEPAINTED_VALUE = new IdentValue(CSSConstants.CSS_VISIBLEPAINTED_VALUE); /** * The 'visiblestroke' keyword. */ - Value VISIBLESTROKE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_VISIBLESTROKE_VALUE); + Value VISIBLESTROKE_VALUE = new IdentValue(CSSConstants.CSS_VISIBLESTROKE_VALUE); /** * The 'aliceblue' color name. */ - Value ALICEBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ALICEBLUE_VALUE); + Value ALICEBLUE_VALUE = new IdentValue(CSSConstants.CSS_ALICEBLUE_VALUE); /** * The 'antiquewhite' color name. */ - Value ANTIQUEWHITE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ANTIQUEWHITE_VALUE); + Value ANTIQUEWHITE_VALUE = new IdentValue(CSSConstants.CSS_ANTIQUEWHITE_VALUE); /** * The 'aquamarine' color name. */ - Value AQUAMARINE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_AQUAMARINE_VALUE); + Value AQUAMARINE_VALUE = new IdentValue(CSSConstants.CSS_AQUAMARINE_VALUE); /** * The 'azure' color name. */ - Value AZURE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_AZURE_VALUE); + Value AZURE_VALUE = new IdentValue(CSSConstants.CSS_AZURE_VALUE); /** * The 'beige' color name. */ - Value BEIGE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BEIGE_VALUE); + Value BEIGE_VALUE = new IdentValue(CSSConstants.CSS_BEIGE_VALUE); /** * The 'bisque' color name. */ - Value BISQUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BISQUE_VALUE); + Value BISQUE_VALUE = new IdentValue(CSSConstants.CSS_BISQUE_VALUE); /** * The 'blanchedalmond' color name. */ - Value BLANCHEDALMOND_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BLANCHEDALMOND_VALUE); + Value BLANCHEDALMOND_VALUE = new IdentValue(CSSConstants.CSS_BLANCHEDALMOND_VALUE); /** * The 'blueviolet' color name. */ - Value BLUEVIOLET_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BLUEVIOLET_VALUE); + Value BLUEVIOLET_VALUE = new IdentValue(CSSConstants.CSS_BLUEVIOLET_VALUE); /** * The 'brown' color name. */ - Value BROWN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BROWN_VALUE); + Value BROWN_VALUE = new IdentValue(CSSConstants.CSS_BROWN_VALUE); /** * The 'burlywood' color name. */ - Value BURLYWOOD_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_BURLYWOOD_VALUE); + Value BURLYWOOD_VALUE = new IdentValue(CSSConstants.CSS_BURLYWOOD_VALUE); /** * The 'cadetblue' color name. */ - Value CADETBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CADETBLUE_VALUE); + Value CADETBLUE_VALUE = new IdentValue(CSSConstants.CSS_CADETBLUE_VALUE); /** * The 'chartreuse' color name. */ - Value CHARTREUSE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CHARTREUSE_VALUE); + Value CHARTREUSE_VALUE = new IdentValue(CSSConstants.CSS_CHARTREUSE_VALUE); /** * The 'chocolate' color name. */ - Value CHOCOLATE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CHOCOLATE_VALUE); + Value CHOCOLATE_VALUE = new IdentValue(CSSConstants.CSS_CHOCOLATE_VALUE); /** * The 'coral' color name. */ - Value CORAL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CORAL_VALUE); + Value CORAL_VALUE = new IdentValue(CSSConstants.CSS_CORAL_VALUE); /** * The 'cornflowerblue' color name. */ - Value CORNFLOWERBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CORNFLOWERBLUE_VALUE); + Value CORNFLOWERBLUE_VALUE = new IdentValue(CSSConstants.CSS_CORNFLOWERBLUE_VALUE); /** * The 'cornsilk' color name. */ - Value CORNSILK_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CORNSILK_VALUE); + Value CORNSILK_VALUE = new IdentValue(CSSConstants.CSS_CORNSILK_VALUE); /** * The 'crimson' color name. */ - Value CRIMSON_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CRIMSON_VALUE); + Value CRIMSON_VALUE = new IdentValue(CSSConstants.CSS_CRIMSON_VALUE); /** * The 'cyan' color name. */ - Value CYAN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CYAN_VALUE); + Value CYAN_VALUE = new IdentValue(CSSConstants.CSS_CYAN_VALUE); /** * The 'darkblue' color name. */ - Value DARKBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKBLUE_VALUE); + Value DARKBLUE_VALUE = new IdentValue(CSSConstants.CSS_DARKBLUE_VALUE); /** * The 'darkcyan' color name. */ - Value DARKCYAN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKCYAN_VALUE); + Value DARKCYAN_VALUE = new IdentValue(CSSConstants.CSS_DARKCYAN_VALUE); /** * The 'darkgoldenrod' color name. */ - Value DARKGOLDENROD_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKGOLDENROD_VALUE); + Value DARKGOLDENROD_VALUE = new IdentValue(CSSConstants.CSS_DARKGOLDENROD_VALUE); /** * The 'darkgray' color name. */ - Value DARKGRAY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKGRAY_VALUE); + Value DARKGRAY_VALUE = new IdentValue(CSSConstants.CSS_DARKGRAY_VALUE); /** * The 'darkgreen' color name. */ - Value DARKGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKGREEN_VALUE); + Value DARKGREEN_VALUE = new IdentValue(CSSConstants.CSS_DARKGREEN_VALUE); /** * The 'darkgrey' color name. */ - Value DARKGREY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKGREY_VALUE); + Value DARKGREY_VALUE = new IdentValue(CSSConstants.CSS_DARKGREY_VALUE); /** * The 'darkkhaki' color name. */ - Value DARKKHAKI_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKKHAKI_VALUE); + Value DARKKHAKI_VALUE = new IdentValue(CSSConstants.CSS_DARKKHAKI_VALUE); /** * The 'darkmagenta' color name. */ - Value DARKMAGENTA_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKMAGENTA_VALUE); + Value DARKMAGENTA_VALUE = new IdentValue(CSSConstants.CSS_DARKMAGENTA_VALUE); /** * The 'darkolivegreen' color name. */ - Value DARKOLIVEGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKOLIVEGREEN_VALUE); + Value DARKOLIVEGREEN_VALUE = new IdentValue(CSSConstants.CSS_DARKOLIVEGREEN_VALUE); /** * The 'darkorange' color name. */ - Value DARKORANGE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKORANGE_VALUE); + Value DARKORANGE_VALUE = new IdentValue(CSSConstants.CSS_DARKORANGE_VALUE); /** * The 'darkorchid' color name. */ - Value DARKORCHID_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKORCHID_VALUE); + Value DARKORCHID_VALUE = new IdentValue(CSSConstants.CSS_DARKORCHID_VALUE); /** * The 'darkred' color name. */ - Value DARKRED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKRED_VALUE); + Value DARKRED_VALUE = new IdentValue(CSSConstants.CSS_DARKRED_VALUE); /** * The 'darksalmon' color name. */ - Value DARKSALMON_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKSALMON_VALUE); + Value DARKSALMON_VALUE = new IdentValue(CSSConstants.CSS_DARKSALMON_VALUE); /** * The 'darkseagreen' color name. */ - Value DARKSEAGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKSEAGREEN_VALUE); + Value DARKSEAGREEN_VALUE = new IdentValue(CSSConstants.CSS_DARKSEAGREEN_VALUE); /** * The 'darkslateblue' color name. */ - Value DARKSLATEBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKSLATEBLUE_VALUE); + Value DARKSLATEBLUE_VALUE = new IdentValue(CSSConstants.CSS_DARKSLATEBLUE_VALUE); /** * The 'darkslategray' color name. */ - Value DARKSLATEGRAY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKSLATEGRAY_VALUE); + Value DARKSLATEGRAY_VALUE = new IdentValue(CSSConstants.CSS_DARKSLATEGRAY_VALUE); /** * The 'darkslategrey' color name. */ - Value DARKSLATEGREY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKSLATEGREY_VALUE); + Value DARKSLATEGREY_VALUE = new IdentValue(CSSConstants.CSS_DARKSLATEGREY_VALUE); /** * The 'darkturquoise' color name. */ - Value DARKTURQUOISE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKTURQUOISE_VALUE); + Value DARKTURQUOISE_VALUE = new IdentValue(CSSConstants.CSS_DARKTURQUOISE_VALUE); /** * The 'darkviolet' color name. */ - Value DARKVIOLET_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DARKVIOLET_VALUE); + Value DARKVIOLET_VALUE = new IdentValue(CSSConstants.CSS_DARKVIOLET_VALUE); /** * The 'deeppink' color name. */ - Value DEEPPINK_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DEEPPINK_VALUE); + Value DEEPPINK_VALUE = new IdentValue(CSSConstants.CSS_DEEPPINK_VALUE); /** * The 'deepskyblue' color name. */ - Value DEEPSKYBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DEEPSKYBLUE_VALUE); + Value DEEPSKYBLUE_VALUE = new IdentValue(CSSConstants.CSS_DEEPSKYBLUE_VALUE); /** * The 'dimgray' color name. */ - Value DIMGRAY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DIMGRAY_VALUE); + Value DIMGRAY_VALUE = new IdentValue(CSSConstants.CSS_DIMGRAY_VALUE); /** * The 'dimgrey' color name. */ - Value DIMGREY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DIMGREY_VALUE); + Value DIMGREY_VALUE = new IdentValue(CSSConstants.CSS_DIMGREY_VALUE); /** * The 'dodgerblue' color name. */ - Value DODGERBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_DODGERBLUE_VALUE); + Value DODGERBLUE_VALUE = new IdentValue(CSSConstants.CSS_DODGERBLUE_VALUE); /** * The 'firebrick' color name. */ - Value FIREBRICK_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_FIREBRICK_VALUE); + Value FIREBRICK_VALUE = new IdentValue(CSSConstants.CSS_FIREBRICK_VALUE); /** * The 'floralwhite' color name. */ - Value FLORALWHITE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_FLORALWHITE_VALUE); + Value FLORALWHITE_VALUE = new IdentValue(CSSConstants.CSS_FLORALWHITE_VALUE); /** * The 'forestgreen' color name. */ - Value FORESTGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_FORESTGREEN_VALUE); + Value FORESTGREEN_VALUE = new IdentValue(CSSConstants.CSS_FORESTGREEN_VALUE); /** * The 'gainsboro' color name. */ - Value GAINSBORO_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_GAINSBORO_VALUE); + Value GAINSBORO_VALUE = new IdentValue(CSSConstants.CSS_GAINSBORO_VALUE); /** * The 'ghostwhite' color name. */ - Value GHOSTWHITE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_GHOSTWHITE_VALUE); + Value GHOSTWHITE_VALUE = new IdentValue(CSSConstants.CSS_GHOSTWHITE_VALUE); /** * The 'gold' color name. */ - Value GOLD_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_GOLD_VALUE); + Value GOLD_VALUE = new IdentValue(CSSConstants.CSS_GOLD_VALUE); /** * The 'goldenrod' color name. */ - Value GOLDENROD_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_GOLDENROD_VALUE); + Value GOLDENROD_VALUE = new IdentValue(CSSConstants.CSS_GOLDENROD_VALUE); /** * The 'greenyellow' color name. */ - Value GREENYELLOW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_GREENYELLOW_VALUE); + Value GREENYELLOW_VALUE = new IdentValue(CSSConstants.CSS_GREENYELLOW_VALUE); /** * The 'grey' color name. */ - Value GREY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_GREY_VALUE); + Value GREY_VALUE = new IdentValue(CSSConstants.CSS_GREY_VALUE); /** * The 'honeydew' color name. */ - Value HONEYDEW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_HONEYDEW_VALUE); + Value HONEYDEW_VALUE = new IdentValue(CSSConstants.CSS_HONEYDEW_VALUE); /** * The 'hotpink' color name. */ - Value HOTPINK_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_HOTPINK_VALUE); + Value HOTPINK_VALUE = new IdentValue(CSSConstants.CSS_HOTPINK_VALUE); /** * The 'indianred' color name. */ - Value INDIANRED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_INDIANRED_VALUE); + Value INDIANRED_VALUE = new IdentValue(CSSConstants.CSS_INDIANRED_VALUE); /** * The 'indigo' color name. */ - Value INDIGO_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_INDIGO_VALUE); + Value INDIGO_VALUE = new IdentValue(CSSConstants.CSS_INDIGO_VALUE); /** * The 'ivory' color name. */ - Value IVORY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_IVORY_VALUE); + Value IVORY_VALUE = new IdentValue(CSSConstants.CSS_IVORY_VALUE); /** * The 'khaki' color name. */ - Value KHAKI_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_KHAKI_VALUE); + Value KHAKI_VALUE = new IdentValue(CSSConstants.CSS_KHAKI_VALUE); /** * The 'lavender' color name. */ - Value LAVENDER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LAVENDER_VALUE); + Value LAVENDER_VALUE = new IdentValue(CSSConstants.CSS_LAVENDER_VALUE); /** * The 'lavenderblush' color name. */ - Value LAVENDERBLUSH_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LAVENDERBLUSH_VALUE); + Value LAVENDERBLUSH_VALUE = new IdentValue(CSSConstants.CSS_LAVENDERBLUSH_VALUE); /** * The 'lawngreen' color name. */ - Value LAWNGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LAWNGREEN_VALUE); + Value LAWNGREEN_VALUE = new IdentValue(CSSConstants.CSS_LAWNGREEN_VALUE); /** * The 'lemonchiffon' color name. */ - Value LEMONCHIFFON_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LEMONCHIFFON_VALUE); + Value LEMONCHIFFON_VALUE = new IdentValue(CSSConstants.CSS_LEMONCHIFFON_VALUE); /** * The 'lightblue' color name. */ - Value LIGHTBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTBLUE_VALUE); + Value LIGHTBLUE_VALUE = new IdentValue(CSSConstants.CSS_LIGHTBLUE_VALUE); /** * The 'lightcoral' color name. */ - Value LIGHTCORAL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTCORAL_VALUE); + Value LIGHTCORAL_VALUE = new IdentValue(CSSConstants.CSS_LIGHTCORAL_VALUE); /** * The 'lightcyan' color name. */ - Value LIGHTCYAN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTCYAN_VALUE); + Value LIGHTCYAN_VALUE = new IdentValue(CSSConstants.CSS_LIGHTCYAN_VALUE); /** * The 'lightgoldenrodyellow' color name. */ - Value LIGHTGOLDENRODYELLOW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_LIGHTGOLDENRODYELLOW_VALUE); + Value LIGHTGOLDENRODYELLOW_VALUE = new IdentValue(CSSConstants.CSS_LIGHTGOLDENRODYELLOW_VALUE); /** * The 'lightgray' color name. */ - Value LIGHTGRAY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTGRAY_VALUE); + Value LIGHTGRAY_VALUE = new IdentValue(CSSConstants.CSS_LIGHTGRAY_VALUE); /** * The 'lightgreen' color name. */ - Value LIGHTGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTGREEN_VALUE); + Value LIGHTGREEN_VALUE = new IdentValue(CSSConstants.CSS_LIGHTGREEN_VALUE); /** * The 'lightgrey' color name. */ - Value LIGHTGREY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTGREY_VALUE); + Value LIGHTGREY_VALUE = new IdentValue(CSSConstants.CSS_LIGHTGREY_VALUE); /** * The 'lightpink' color name. */ - Value LIGHTPINK_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTPINK_VALUE); + Value LIGHTPINK_VALUE = new IdentValue(CSSConstants.CSS_LIGHTPINK_VALUE); /** * The 'lightsalmon' color name. */ - Value LIGHTSALMON_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTSALMON_VALUE); + Value LIGHTSALMON_VALUE = new IdentValue(CSSConstants.CSS_LIGHTSALMON_VALUE); /** * The 'lightseagreen' color name. */ - Value LIGHTSEAGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTSEAGREEN_VALUE); + Value LIGHTSEAGREEN_VALUE = new IdentValue(CSSConstants.CSS_LIGHTSEAGREEN_VALUE); /** * The 'lightskyblue' color name. */ - Value LIGHTSKYBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTSKYBLUE_VALUE); + Value LIGHTSKYBLUE_VALUE = new IdentValue(CSSConstants.CSS_LIGHTSKYBLUE_VALUE); /** * The 'lightslategray' color name. */ - Value LIGHTSLATEGRAY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTSLATEGRAY_VALUE); + Value LIGHTSLATEGRAY_VALUE = new IdentValue(CSSConstants.CSS_LIGHTSLATEGRAY_VALUE); /** * The 'lightslategrey' color name. */ - Value LIGHTSLATEGREY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTSLATEGREY_VALUE); + Value LIGHTSLATEGREY_VALUE = new IdentValue(CSSConstants.CSS_LIGHTSLATEGREY_VALUE); /** * The 'lightsteelblue' color name. */ - Value LIGHTSTEELBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTSTEELBLUE_VALUE); + Value LIGHTSTEELBLUE_VALUE = new IdentValue(CSSConstants.CSS_LIGHTSTEELBLUE_VALUE); /** * The 'lightyellow' color name. */ - Value LIGHTYELLOW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIGHTYELLOW_VALUE); + Value LIGHTYELLOW_VALUE = new IdentValue(CSSConstants.CSS_LIGHTYELLOW_VALUE); /** * The 'limegreen' color name. */ - Value LIMEGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LIMEGREEN_VALUE); + Value LIMEGREEN_VALUE = new IdentValue(CSSConstants.CSS_LIMEGREEN_VALUE); /** * The 'linen' color name. */ - Value LINEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_LINEN_VALUE); + Value LINEN_VALUE = new IdentValue(CSSConstants.CSS_LINEN_VALUE); /** * The 'magenta' color name. */ - Value MAGENTA_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MAGENTA_VALUE); + Value MAGENTA_VALUE = new IdentValue(CSSConstants.CSS_MAGENTA_VALUE); /** * The 'mediumaquamarine' color name. */ - Value MEDIUMAQUAMARINE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_MEDIUMAQUAMARINE_VALUE); + Value MEDIUMAQUAMARINE_VALUE = new IdentValue(CSSConstants.CSS_MEDIUMAQUAMARINE_VALUE); /** * The 'mediumblue' color name. */ - Value MEDIUMBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MEDIUMBLUE_VALUE); + Value MEDIUMBLUE_VALUE = new IdentValue(CSSConstants.CSS_MEDIUMBLUE_VALUE); /** * The 'mediumorchid' color name. */ - Value MEDIUMORCHID_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MEDIUMORCHID_VALUE); + Value MEDIUMORCHID_VALUE = new IdentValue(CSSConstants.CSS_MEDIUMORCHID_VALUE); /** * The 'mediumpurple' color name. */ - Value MEDIUMPURPLE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MEDIUMPURPLE_VALUE); + Value MEDIUMPURPLE_VALUE = new IdentValue(CSSConstants.CSS_MEDIUMPURPLE_VALUE); /** * The 'mediumseagreen' color name. */ - Value MEDIUMSEAGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MEDIUMSEAGREEN_VALUE); + Value MEDIUMSEAGREEN_VALUE = new IdentValue(CSSConstants.CSS_MEDIUMSEAGREEN_VALUE); /** * The 'mediumslateblue' color name. */ - Value MEDIUMSLATEBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MEDIUMSLATEBLUE_VALUE); + Value MEDIUMSLATEBLUE_VALUE = new IdentValue(CSSConstants.CSS_MEDIUMSLATEBLUE_VALUE); /** * The 'mediumspringgreen' color name. */ - Value MEDIUMSPRINGGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, - CSSConstants.CSS_MEDIUMSPRINGGREEN_VALUE); + Value MEDIUMSPRINGGREEN_VALUE = new IdentValue(CSSConstants.CSS_MEDIUMSPRINGGREEN_VALUE); /** * The 'mediumturquoise' color name. */ - Value MEDIUMTURQUOISE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MEDIUMTURQUOISE_VALUE); + Value MEDIUMTURQUOISE_VALUE = new IdentValue(CSSConstants.CSS_MEDIUMTURQUOISE_VALUE); /** * The 'mediumvioletred' color name. */ - Value MEDIUMVIOLETRED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MEDIUMVIOLETRED_VALUE); + Value MEDIUMVIOLETRED_VALUE = new IdentValue(CSSConstants.CSS_MEDIUMVIOLETRED_VALUE); /** * The 'midnightblue' color name. */ - Value MIDNIGHTBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MIDNIGHTBLUE_VALUE); + Value MIDNIGHTBLUE_VALUE = new IdentValue(CSSConstants.CSS_MIDNIGHTBLUE_VALUE); /** * The 'mintcream' color name. */ - Value MINTCREAM_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MINTCREAM_VALUE); + Value MINTCREAM_VALUE = new IdentValue(CSSConstants.CSS_MINTCREAM_VALUE); /** * The 'mistyrose' color name. */ - Value MISTYROSE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MISTYROSE_VALUE); + Value MISTYROSE_VALUE = new IdentValue(CSSConstants.CSS_MISTYROSE_VALUE); /** * The 'moccasin' color name. */ - Value MOCCASIN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_MOCCASIN_VALUE); + Value MOCCASIN_VALUE = new IdentValue(CSSConstants.CSS_MOCCASIN_VALUE); /** * The 'navajowhite' color name. */ - Value NAVAJOWHITE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_NAVAJOWHITE_VALUE); + Value NAVAJOWHITE_VALUE = new IdentValue(CSSConstants.CSS_NAVAJOWHITE_VALUE); /** * The 'oldlace' color name. */ - Value OLDLACE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_OLDLACE_VALUE); + Value OLDLACE_VALUE = new IdentValue(CSSConstants.CSS_OLDLACE_VALUE); /** * The 'olivedrab' color name. */ - Value OLIVEDRAB_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_OLIVEDRAB_VALUE); + Value OLIVEDRAB_VALUE = new IdentValue(CSSConstants.CSS_OLIVEDRAB_VALUE); /** * The 'orange' color name. */ - Value ORANGE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ORANGE_VALUE); + Value ORANGE_VALUE = new IdentValue(CSSConstants.CSS_ORANGE_VALUE); /** * The 'orangered' color name. */ - Value ORANGERED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ORANGERED_VALUE); + Value ORANGERED_VALUE = new IdentValue(CSSConstants.CSS_ORANGERED_VALUE); /** * The 'orchid' color name. */ - Value ORCHID_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ORCHID_VALUE); + Value ORCHID_VALUE = new IdentValue(CSSConstants.CSS_ORCHID_VALUE); /** * The 'palegoldenrod' color name. */ - Value PALEGOLDENROD_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_PALEGOLDENROD_VALUE); + Value PALEGOLDENROD_VALUE = new IdentValue(CSSConstants.CSS_PALEGOLDENROD_VALUE); /** * The 'palegreen' color name. */ - Value PALEGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_PALEGREEN_VALUE); + Value PALEGREEN_VALUE = new IdentValue(CSSConstants.CSS_PALEGREEN_VALUE); /** * The 'paleturquoise' color name. */ - Value PALETURQUOISE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_PALETURQUOISE_VALUE); + Value PALETURQUOISE_VALUE = new IdentValue(CSSConstants.CSS_PALETURQUOISE_VALUE); /** * The 'palevioletred' color name. */ - Value PALEVIOLETRED_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_PALEVIOLETRED_VALUE); + Value PALEVIOLETRED_VALUE = new IdentValue(CSSConstants.CSS_PALEVIOLETRED_VALUE); /** * The 'papayawhip' color name. */ - Value PAPAYAWHIP_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_PAPAYAWHIP_VALUE); + Value PAPAYAWHIP_VALUE = new IdentValue(CSSConstants.CSS_PAPAYAWHIP_VALUE); /** * The 'peachpuff' color name. */ - Value PEACHPUFF_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_PEACHPUFF_VALUE); + Value PEACHPUFF_VALUE = new IdentValue(CSSConstants.CSS_PEACHPUFF_VALUE); /** * The 'peru' color name. */ - Value PERU_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_PERU_VALUE); + Value PERU_VALUE = new IdentValue(CSSConstants.CSS_PERU_VALUE); /** * The 'pink' color name. */ - Value PINK_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_PINK_VALUE); + Value PINK_VALUE = new IdentValue(CSSConstants.CSS_PINK_VALUE); /** * The 'plum' color name. */ - Value PLUM_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_PLUM_VALUE); + Value PLUM_VALUE = new IdentValue(CSSConstants.CSS_PLUM_VALUE); /** * The 'powderblue' color name. */ - Value POWDERBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_POWDERBLUE_VALUE); + Value POWDERBLUE_VALUE = new IdentValue(CSSConstants.CSS_POWDERBLUE_VALUE); /** * The 'purple' color name. */ - Value PURPLE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_PURPLE_VALUE); + Value PURPLE_VALUE = new IdentValue(CSSConstants.CSS_PURPLE_VALUE); /** * The 'rosybrown' color name. */ - Value ROSYBROWN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ROSYBROWN_VALUE); + Value ROSYBROWN_VALUE = new IdentValue(CSSConstants.CSS_ROSYBROWN_VALUE); /** * The 'royalblue' color name. */ - Value ROYALBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_ROYALBLUE_VALUE); + Value ROYALBLUE_VALUE = new IdentValue(CSSConstants.CSS_ROYALBLUE_VALUE); /** * The 'saddlebrown' color name. */ - Value SADDLEBROWN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SADDLEBROWN_VALUE); + Value SADDLEBROWN_VALUE = new IdentValue(CSSConstants.CSS_SADDLEBROWN_VALUE); /** * The 'salmon' color name. */ - Value SALMON_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SALMON_VALUE); + Value SALMON_VALUE = new IdentValue(CSSConstants.CSS_SALMON_VALUE); /** * The 'sandybrown' color name. */ - Value SANDYBROWN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SANDYBROWN_VALUE); + Value SANDYBROWN_VALUE = new IdentValue(CSSConstants.CSS_SANDYBROWN_VALUE); /** * The 'seagreen' color name. */ - Value SEAGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SEAGREEN_VALUE); + Value SEAGREEN_VALUE = new IdentValue(CSSConstants.CSS_SEAGREEN_VALUE); /** * The 'seashell' color name. */ - Value SEASHELL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SEASHELL_VALUE); + Value SEASHELL_VALUE = new IdentValue(CSSConstants.CSS_SEASHELL_VALUE); /** * The 'sienna' color name. */ - Value SIENNA_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SIENNA_VALUE); + Value SIENNA_VALUE = new IdentValue(CSSConstants.CSS_SIENNA_VALUE); /** * The 'skyblue' color name. */ - Value SKYBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SKYBLUE_VALUE); + Value SKYBLUE_VALUE = new IdentValue(CSSConstants.CSS_SKYBLUE_VALUE); /** * The 'slateblue' color name. */ - Value SLATEBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SLATEBLUE_VALUE); + Value SLATEBLUE_VALUE = new IdentValue(CSSConstants.CSS_SLATEBLUE_VALUE); /** * The 'slategray' color name. */ - Value SLATEGRAY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SLATEGRAY_VALUE); + Value SLATEGRAY_VALUE = new IdentValue(CSSConstants.CSS_SLATEGRAY_VALUE); /** * The 'slategrey' color name. */ - Value SLATEGREY_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SLATEGREY_VALUE); + Value SLATEGREY_VALUE = new IdentValue(CSSConstants.CSS_SLATEGREY_VALUE); /** * The 'snow' color name. */ - Value SNOW_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SNOW_VALUE); + Value SNOW_VALUE = new IdentValue(CSSConstants.CSS_SNOW_VALUE); /** * The 'springgreen' color name. */ - Value SPRINGGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_SPRINGGREEN_VALUE); + Value SPRINGGREEN_VALUE = new IdentValue(CSSConstants.CSS_SPRINGGREEN_VALUE); /** * The 'steelblue' color name. */ - Value STEELBLUE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_STEELBLUE_VALUE); + Value STEELBLUE_VALUE = new IdentValue(CSSConstants.CSS_STEELBLUE_VALUE); /** * The 'tan' color name. */ - Value TAN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TAN_VALUE); + Value TAN_VALUE = new IdentValue(CSSConstants.CSS_TAN_VALUE); /** * The 'thistle' color name. */ - Value THISTLE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_THISTLE_VALUE); + Value THISTLE_VALUE = new IdentValue(CSSConstants.CSS_THISTLE_VALUE); /** * The 'tomato' color name. */ - Value TOMATO_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TOMATO_VALUE); + Value TOMATO_VALUE = new IdentValue(CSSConstants.CSS_TOMATO_VALUE); /** * The 'turquoise' color name. */ - Value TURQUOISE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_TURQUOISE_VALUE); + Value TURQUOISE_VALUE = new IdentValue(CSSConstants.CSS_TURQUOISE_VALUE); /** * The 'violet' color name. */ - Value VIOLET_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_VIOLET_VALUE); + Value VIOLET_VALUE = new IdentValue(CSSConstants.CSS_VIOLET_VALUE); /** * The 'wheat' color name. */ - Value WHEAT_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_WHEAT_VALUE); + Value WHEAT_VALUE = new IdentValue(CSSConstants.CSS_WHEAT_VALUE); /** * The 'whitesmoke' color name. */ - Value WHITESMOKE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_WHITESMOKE_VALUE); + Value WHITESMOKE_VALUE = new IdentValue(CSSConstants.CSS_WHITESMOKE_VALUE); /** * The 'yellowgreen' color name. */ - Value YELLOWGREEN_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_YELLOWGREEN_VALUE); + Value YELLOWGREEN_VALUE = new IdentValue(CSSConstants.CSS_YELLOWGREEN_VALUE); /** * The 'aliceblue' RGB color. diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SpacingManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SpacingManager.java index 3e307b3eb..85c7f57f9 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SpacingManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/SpacingManager.java @@ -19,9 +19,9 @@ package io.sf.carte.echosvg.css.engine.value.svg; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.value.LengthManager; import io.sf.carte.echosvg.css.engine.value.Value; @@ -33,8 +33,10 @@ /** * This class provides a manager for the '*-spacing' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class SpacingManager extends LengthManager { @@ -119,12 +121,9 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return super.createValue(lu, engine); } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { - if (type != CSSPrimitiveValue.CSS_IDENT) { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { + if (type != Type.IDENT) { throw createInvalidStringTypeDOMException(type); } if (value.equalsIgnoreCase(CSSConstants.CSS_NORMAL_VALUE)) { diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/StrokeDasharrayManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/StrokeDasharrayManager.java index 14fce3047..fa976a1f1 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/StrokeDasharrayManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/StrokeDasharrayManager.java @@ -19,10 +19,9 @@ package io.sf.carte.echosvg.css.engine.value.svg; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; +import io.sf.carte.echosvg.css.dom.CSSValue.Type; import io.sf.carte.echosvg.css.engine.CSSEngine; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.StyleMap; @@ -37,8 +36,10 @@ /** * This class provides a factory for the 'stroke-dasharray' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class StrokeDasharrayManager extends LengthManager { @@ -120,12 +121,9 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { } } - /** - * Implements {@link ValueManager#createStringValue(short,String,CSSEngine)}. - */ @Override - public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { - if (type != CSSPrimitiveValue.CSS_IDENT) { + public Value createStringValue(Type type, String value, CSSEngine engine) throws DOMException { + if (type != Type.IDENT) { throw createInvalidStringTypeDOMException(type); } if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) { @@ -142,16 +140,18 @@ public Value createStringValue(short type, String value, CSSEngine engine) throw public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { switch (value.getCssValueType()) { - case CSSValue.CSS_PRIMITIVE_VALUE: + case TYPED: return value; + case LIST: + ListValue result = new ListValue(' '); + for (int i = 0; i < value.getLength(); i++) { + result.append(super.computeValue(elt, pseudo, engine, idx, sm, value.item(i))); + } + return result; + default: + throw createDOMException(); } - ListValue lv = (ListValue) value; - ListValue result = new ListValue(' '); - for (int i = 0; i < lv.getLength(); i++) { - result.append(super.computeValue(elt, pseudo, engine, idx, sm, lv.item(i))); - } - return result; } /** diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/StrokeMiterlimitManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/StrokeMiterlimitManager.java index 94117a433..7a3203431 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/StrokeMiterlimitManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg/StrokeMiterlimitManager.java @@ -18,8 +18,8 @@ */ package io.sf.carte.echosvg.css.engine.value.svg; +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; import io.sf.carte.echosvg.css.engine.CSSEngine; @@ -34,8 +34,10 @@ /** * This class provides a factory for the 'stroke-miterlimit' property values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class StrokeMiterlimitManager extends AbstractValueManager { @@ -98,10 +100,10 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { return ValueConstants.INHERIT_VALUE; case INTEGER: - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getIntegerValue()); + return new FloatValue(CSSUnit.CSS_NUMBER, lu.getIntegerValue()); case REAL: - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getFloatValue()); + return new FloatValue(CSSUnit.CSS_NUMBER, lu.getFloatValue()); default: throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); @@ -113,7 +115,7 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { */ @Override public Value createFloatValue(short unitType, float floatValue) throws DOMException { - if (unitType == CSSPrimitiveValue.CSS_NUMBER) { + if (unitType == CSSUnit.CSS_NUMBER) { return new FloatValue(unitType, floatValue); } throw createInvalidFloatTypeDOMException(unitType); diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/AbstractCIEColor.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/AbstractCIEColor.java index 3d909795e..f0af88ee1 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/AbstractCIEColor.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/AbstractCIEColor.java @@ -18,9 +18,7 @@ */ package io.sf.carte.echosvg.css.engine.value.svg12; -import org.w3c.dom.css.CSSValue; - -import io.sf.carte.echosvg.css.engine.value.AbstractValue; +import io.sf.carte.echosvg.css.engine.value.ColorValue; /** * This is a base class for CIE Lab/LCH color values. @@ -28,7 +26,7 @@ * @author For later modifications, see Git history. * @version $Id$ */ -public abstract class AbstractCIEColor extends AbstractValue { +public abstract class AbstractCIEColor extends ColorValue { /** The three color values. */ protected float[] values = new float[3]; @@ -78,15 +76,6 @@ public float[] getWhitePoint() { public abstract String getFunctionName(); - /** - * Implements - * {@link io.sf.carte.echosvg.css.engine.value.Value#getCssValueType()}. - */ - @Override - public short getCssValueType() { - return CSSValue.CSS_CUSTOM; - } - /** * A string representation of the current value. */ diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/CIELCHColor.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/CIELCHColor.java deleted file mode 100644 index d7c6f4b4d..000000000 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/CIELCHColor.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - - See the NOTICE file distributed with this work for additional - information regarding copyright ownership. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - */ -package io.sf.carte.echosvg.css.engine.value.svg12; - -/** - * This class represents an CIE LCH color value. - * - * @author For later modifications, see Git history. - * @version $Id$ - */ -public class CIELCHColor extends AbstractCIEColor { - - public static final String CIE_LCH_COLOR_FUNCTION = "cielch"; - - /** - * Creates a new CIELCHColor. - * - * @param l the lightness (L) value - * @param c the chroma (C) value - * @param h the hue (H) value - * @param whitepoint the white point in CIE XYZ coordinates - */ - public CIELCHColor(float l, float c, float h, float[] whitepoint) { - super(new float[] { l, c, h }, whitepoint); - } - - /** - * Creates a new CIELCHColor with D65 as illuminant. - * - * @param l the lightness (L) value - * @param c the chroma (C) value - * @param h the hue (H) value - */ - public CIELCHColor(float l, float c, float h) { - this(l, c, h, null); - } - - /** {@inheritDoc} */ - @Override - public String getFunctionName() { - return CIE_LCH_COLOR_FUNCTION; - } - -} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/CIELabColor.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/CIELabColor.java deleted file mode 100644 index 95b6e2d35..000000000 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/CIELabColor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - - See the NOTICE file distributed with this work for additional - information regarding copyright ownership. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - */ -package io.sf.carte.echosvg.css.engine.value.svg12; - -/** - * This class represents an CIE L*a*b* color value. - * - * @author For later modifications, see Git history. - * @version $Id$ - */ -public class CIELabColor extends AbstractCIEColor { - - public static final String CIE_LAB_COLOR_FUNCTION = "cielab"; - - /** - * Creates a new CIELabColor. - * - * @param l the L* value - * @param a the a* value - * @param b the b* value - * @param whitepoint the white point in CIE XYZ coordinates - */ - public CIELabColor(float l, float a, float b, float[] whitepoint) { - super(new float[] { l, a, b }, whitepoint); - } - - /** - * Creates a new CIELabColor with D50 as illuminant. - */ - public CIELabColor(float l, float a, float b) { - this(l, a, b, null); - } - - /** {@inheritDoc} */ - @Override - public String getFunctionName() { - return CIE_LAB_COLOR_FUNCTION; - } - -} diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/DeviceColor.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/DeviceColor.java index cf6d71e12..8ff887d13 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/DeviceColor.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/DeviceColor.java @@ -19,17 +19,16 @@ package io.sf.carte.echosvg.css.engine.value.svg12; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSValue; -import io.sf.carte.echosvg.css.engine.value.AbstractValue; +import io.sf.carte.echosvg.css.engine.value.ColorValue; /** * This class represents an device-specific color value. * - * @author For later modifications, see Git history. * @version $Id$ */ -public class DeviceColor extends AbstractValue { +@Deprecated +public class DeviceColor extends ColorValue { public static final String DEVICE_GRAY_COLOR_FUNCTION = "device-gray"; public static final String DEVICE_RGB_COLOR_FUNCTION = "device-rgb"; @@ -58,15 +57,6 @@ public DeviceColor(boolean nChannel) { this.nChannel = nChannel; } - /** - * Implements - * {@link io.sf.carte.echosvg.css.engine.value.Value#getCssValueType()}. - */ - @Override - public short getCssValueType() { - return CSSValue.CSS_CUSTOM; - } - /** * Indicates whether this color uses an N-Channel color space. * @@ -90,6 +80,38 @@ public float getColor(int i) throws DOMException { return colors[i]; } + @Override + public String getCSSColorSpace() { + String cs; + if (nChannel) { + cs = DEVICE_NCHANNEL_COLOR_FUNCTION; + } else { + switch (count) { + case 1: + cs = DEVICE_GRAY_COLOR_FUNCTION; + break; + case 3: + cs = DEVICE_RGB_COLOR_FUNCTION; + break; + case 4: + cs = DEVICE_CMYK_COLOR_FUNCTION; + break; + default: + throw new IllegalStateException("Invalid number of components encountered"); + } + } + return cs; + } + + @Override + public DeviceColor clone() { + DeviceColor c = (DeviceColor) super.clone(); + c.nChannel = nChannel; + c.count = count; + c.colors = colors.clone(); + return c; + } + /** * A string representation of the current value. */ diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/ICCNamedColor.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/ICCNamedColor.java index ef5fd4c2a..744207c66 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/ICCNamedColor.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/ICCNamedColor.java @@ -19,17 +19,16 @@ package io.sf.carte.echosvg.css.engine.value.svg12; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSValue; -import io.sf.carte.echosvg.css.engine.value.AbstractValue; +import io.sf.carte.echosvg.css.engine.value.ColorValue; /** * This class represents an ICC named color value. * - * @author For later modifications, see Git history. * @version $Id$ */ -public class ICCNamedColor extends AbstractValue { +@Deprecated +public class ICCNamedColor extends ColorValue { public static final String ICC_NAMED_COLOR_FUNCTION = "icc-named-color"; @@ -51,13 +50,9 @@ public ICCNamedColor(String profileName, String colorName) { this.colorName = colorName; } - /** - * Implements - * {@link io.sf.carte.echosvg.css.engine.value.Value#getCssValueType()}. - */ @Override - public short getCssValueType() { - return CSSValue.CSS_CUSTOM; + public String getCSSColorSpace() { + return colorProfile; } /** @@ -74,6 +69,14 @@ public String getColorName() throws DOMException { return colorName; } + @Override + public ColorValue clone() { + ICCNamedColor c = (ICCNamedColor) super.clone(); + c.colorName = colorName; + c.colorProfile = colorProfile; + return c; + } + /** * A string representation of the current value. */ diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/LineHeightManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/LineHeightManager.java index cf96e4374..ce54fc147 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/LineHeightManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/LineHeightManager.java @@ -19,9 +19,10 @@ package io.sf.carte.echosvg.css.engine.value.svg12; +import java.util.Locale; + +import org.w3c.css.om.unit.CSSUnit; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; import io.sf.carte.doc.style.css.nsac.LexicalUnit; import io.sf.carte.echosvg.css.engine.CSSEngine; @@ -39,8 +40,10 @@ /** * This class provides a factory for the 'margin-*' properties values. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public class LineHeightManager extends LengthManager { @@ -106,7 +109,7 @@ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { case INHERIT: return ValueConstants.INHERIT_VALUE; case IDENT: { - String s = lu.getStringValue().toLowerCase(); + String s = lu.getStringValue().toLowerCase(Locale.ROOT); if (SVG12CSSConstants.CSS_NORMAL_VALUE.equals(s)) return SVG12ValueConstants.NORMAL_VALUE; throw createInvalidIdentifierDOMException(lu.getStringValue()); @@ -132,18 +135,18 @@ protected int getOrientation() { @Override public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { - if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) + if (value.getCssValueType() != Value.CssType.TYPED) return value; - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_NUMBER: - return new LineHeightValue(CSSPrimitiveValue.CSS_NUMBER, value.getFloatValue(), true); + switch (value.getCSSUnit()) { + case CSSUnit.CSS_NUMBER: + return new LineHeightValue(CSSUnit.CSS_NUMBER, value.getFloatValue(), true); - case CSSPrimitiveValue.CSS_PERCENTAGE: { + case CSSUnit.CSS_PERCENTAGE: { float v = value.getFloatValue(); int fsidx = engine.getFontSizeIndex(); float fs = engine.getComputedStyle(elt, pseudo, fsidx).getFloatValue(); - return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v * fs * 0.01f); + return new FloatValue(CSSUnit.CSS_NUMBER, v * fs * 0.01f); } default: diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/SVG12ValueConstants.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/SVG12ValueConstants.java index 0d53a5355..18afe845d 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/SVG12ValueConstants.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/SVG12ValueConstants.java @@ -19,9 +19,7 @@ package io.sf.carte.echosvg.css.engine.value.svg12; -import org.w3c.dom.css.CSSPrimitiveValue; - -import io.sf.carte.echosvg.css.engine.value.StringValue; +import io.sf.carte.echosvg.css.engine.value.IdentValue; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.css.engine.value.svg.SVGValueConstants; import io.sf.carte.echosvg.util.CSSConstants; @@ -30,21 +28,23 @@ /** * This interface provides constants for SVG 1.2 values. * - * @author deweese - * @author For later modifications, see Git history. + *

+ * Original author: deweese. + * For later modifications, see Git history. + *

* @version $Id$ */ public interface SVG12ValueConstants extends SVGValueConstants { /** The 'start' keyword. */ - Value START_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, SVG12CSSConstants.CSS_FULL_VALUE); + Value START_VALUE = new IdentValue(SVG12CSSConstants.CSS_START_VALUE); /** The 'center' keyword. */ - Value CENTER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CENTER_VALUE); + Value CENTER_VALUE = new IdentValue(CSSConstants.CSS_CENTER_VALUE); /** The 'end' keyword. */ - Value END_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, SVG12CSSConstants.CSS_END_VALUE); + Value END_VALUE = new IdentValue(SVG12CSSConstants.CSS_END_VALUE); /** The 'full' keyword. */ - Value FULL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, SVG12CSSConstants.CSS_FULL_VALUE); + Value FULL_VALUE = new IdentValue(SVG12CSSConstants.CSS_FULL_VALUE); /** The 'normal' keyword, for 'line-height'. */ - Value NORMAL_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, SVG12CSSConstants.CSS_NORMAL_VALUE); + Value NORMAL_VALUE = new IdentValue(SVG12CSSConstants.CSS_NORMAL_VALUE); } diff --git a/echosvg-css/src/main/java/module-info.java b/echosvg-css/src/main/java/module-info.java index 46c922146..b8ae3f6f8 100644 --- a/echosvg-css/src/main/java/module-info.java +++ b/echosvg-css/src/main/java/module-info.java @@ -20,6 +20,7 @@ * CSS support. */ module io.sf.carte.echosvg.css { + exports io.sf.carte.echosvg.css; exports io.sf.carte.echosvg.css.engine; exports io.sf.carte.echosvg.css.engine.value.css2; exports io.sf.carte.echosvg.css.engine.value.svg; @@ -33,6 +34,7 @@ requires transitive io.sf.carte.css4j; requires io.sf.carte.util; requires transitive org.w3c.dom.svg; + requires transitive org.w3c.dom.view; requires java.xml; requires jdk.xml.dom; diff --git a/echosvg-css/src/main/resources/io/sf/carte/echosvg/css/engine/value/resources/Messages.properties b/echosvg-css/src/main/resources/io/sf/carte/echosvg/css/engine/value/resources/Messages.properties index f8e3d835d..30f1da964 100644 --- a/echosvg-css/src/main/resources/io/sf/carte/echosvg/css/engine/value/resources/Messages.properties +++ b/echosvg-css/src/main/resources/io/sf/carte/echosvg/css/engine/value/resources/Messages.properties @@ -22,17 +22,11 @@ invalid.access = \ The invoked method is not enabled for the "{0}" property. invalid.value.access = \ -The invoked method cannot be called for {0,choice,\ -0#the inherit value|\ -1#a primitive value|\ -2#the value list|\ -3#a custom value\ -} type. +The invoked method cannot be called for {0} type. invalid.string.type = \ The given string type ({1}) is invalid for \ -the "{0}" property \ -(see org.w3c.dom.css.CSSPrimitiveValue). +the "{0}" property. invalid.identifier = \ The "{1}" identifier is not a valid value for the "{0}" property. @@ -46,16 +40,7 @@ malformed.rect = \ The ''{0}'' property value is malformed. invalid.float.type = \ -The given CSS primitive value ({1,choice,\ -0#CSS_UNKNOWN|\ -19#CSS_STRING|\ -20#CSS_URI|\ -30#CSS_IDENT|\ -31#CSS_ATTR|\ -32#CSS_COUNTER|\ -33#CSS_RECT|\ -34#CSS_RGBCOLOR\ -}) represents an invalid type for the "{0}". +The given CSS primitive value ({1}) represents an invalid type for the "{0}". invalid.float.value = \ The number ''{1}'' represents an invalid value for the ''{0}'' property. diff --git a/echosvg-dom/src/main/java/io/sf/carte/echosvg/dom/AbstractStylableDocument.java b/echosvg-dom/src/main/java/io/sf/carte/echosvg/dom/AbstractStylableDocument.java index 519d19a70..75a705d33 100644 --- a/echosvg-dom/src/main/java/io/sf/carte/echosvg/dom/AbstractStylableDocument.java +++ b/echosvg-dom/src/main/java/io/sf/carte/echosvg/dom/AbstractStylableDocument.java @@ -19,12 +19,12 @@ package io.sf.carte.echosvg.dom; +import org.w3c.css.om.CSSStyleDeclaration; import org.w3c.dom.DOMImplementation; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.DocumentCSS; import org.w3c.dom.stylesheets.StyleSheetList; +import org.w3c.dom.view.DocumentCSS; import org.w3c.dom.views.AbstractView; import org.w3c.dom.views.DocumentView; diff --git a/echosvg-dom/src/main/java/io/sf/carte/echosvg/dom/ExtensibleDOMImplementation.java b/echosvg-dom/src/main/java/io/sf/carte/echosvg/dom/ExtensibleDOMImplementation.java index 4d0e6b011..0a6ac758c 100644 --- a/echosvg-dom/src/main/java/io/sf/carte/echosvg/dom/ExtensibleDOMImplementation.java +++ b/echosvg-dom/src/main/java/io/sf/carte/echosvg/dom/ExtensibleDOMImplementation.java @@ -29,7 +29,7 @@ import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.css.DOMImplementationCSS; -import org.w3c.dom.css.ViewCSS; +import org.w3c.dom.view.ViewCSS; import io.sf.carte.doc.style.css.nsac.Parser; import io.sf.carte.doc.style.css.parser.CSSParser; diff --git a/echosvg-dom/src/main/java/io/sf/carte/echosvg/dom/util/CSSStyleDeclarationFactory.java b/echosvg-dom/src/main/java/io/sf/carte/echosvg/dom/util/CSSStyleDeclarationFactory.java index 789bfa509..f17c17a7c 100644 --- a/echosvg-dom/src/main/java/io/sf/carte/echosvg/dom/util/CSSStyleDeclarationFactory.java +++ b/echosvg-dom/src/main/java/io/sf/carte/echosvg/dom/util/CSSStyleDeclarationFactory.java @@ -18,13 +18,15 @@ */ package io.sf.carte.echosvg.dom.util; -import org.w3c.dom.css.CSSStyleDeclaration; +import org.w3c.css.om.CSSStyleDeclaration; /** * This interface represents CSSStyleDeclaration factories. * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ public interface CSSStyleDeclarationFactory { diff --git a/echosvg-dom/src/main/java/module-info.java b/echosvg-dom/src/main/java/module-info.java index efb7f0ad6..6789d62dc 100644 --- a/echosvg-dom/src/main/java/module-info.java +++ b/echosvg-dom/src/main/java/module-info.java @@ -37,6 +37,8 @@ requires io.sf.carte.xml.dtd; + requires transitive org.w3c.dom.view; + requires transitive java.xml; requires transitive jdk.xml.dom; diff --git a/echosvg-extension/src/main/java/io/sf/carte/echosvg/extension/StylableExtensionElement.java b/echosvg-extension/src/main/java/io/sf/carte/echosvg/extension/StylableExtensionElement.java index 0af8f556e..1f8fc3cb6 100644 --- a/echosvg-extension/src/main/java/io/sf/carte/echosvg/extension/StylableExtensionElement.java +++ b/echosvg-extension/src/main/java/io/sf/carte/echosvg/extension/StylableExtensionElement.java @@ -18,12 +18,13 @@ */ package io.sf.carte.echosvg.extension; +import org.w3c.css.om.CSSStyleDeclaration; +import org.w3c.css.om.typed.CSSStyleValue; import org.w3c.dom.Node; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSValue; import org.w3c.dom.svg.SVGAnimatedString; -import org.w3c.dom.svg.SVGStylable; +import org.w3c.dom.svg.SVGStylableP; +import io.sf.carte.echosvg.css.dom.CSSValue; import io.sf.carte.echosvg.css.engine.CSSStylableElement; import io.sf.carte.echosvg.css.engine.StyleDeclarationProvider; import io.sf.carte.echosvg.css.engine.StyleMap; @@ -35,11 +36,14 @@ * usable as a foreign element within an SVGOMDocument, and the support for both * the 'style' attribute and the style attributes (ie: fill="red", ...). * - * @author Stephane Hillion - * @author For later modifications, see Git history. + *

+ * Original author: Stephane Hillion. + * For later modifications, see Git history. + *

* @version $Id$ */ -public abstract class StylableExtensionElement extends ExtensionElement implements CSSStylableElement, SVGStylable { +public abstract class StylableExtensionElement extends ExtensionElement implements CSSStylableElement, + SVGStylableP { private static final long serialVersionUID = 1L; diff --git a/echosvg-svggen/src/main/java/io/sf/carte/echosvg/svggen/SVGColor.java b/echosvg-svggen/src/main/java/io/sf/carte/echosvg/svggen/SVGColor.java index f78f6a955..ef9e6cd03 100644 --- a/echosvg-svggen/src/main/java/io/sf/carte/echosvg/svggen/SVGColor.java +++ b/echosvg-svggen/src/main/java/io/sf/carte/echosvg/svggen/SVGColor.java @@ -93,9 +93,7 @@ public class SVGColor extends AbstractSVGConverter { colorMap.put(aqua, "aqua"); /* - * CSS standard color spaces. A98-rgb and Prophoto-rgb are never going to match - * in practice and probably should be removed; they are left for now, just in - * case they are useful. + * CSS standard color spaces. */ String[] knownProfiles = { "display-p3", "a98-rgb", "prophoto-rgb", "rec2020" }; cssProfileNames = new HashSet<>(knownProfiles.length); @@ -204,9 +202,17 @@ private static String lcColorProfileName(ICC_ColorSpace cs) { iccProfileName = new String(bdesc, offset, len, StandardCharsets.UTF_16BE).trim(); iccProfileName = iccProfileName.toLowerCase(Locale.ROOT).replace(' ', '-'); if (iccProfileName.contains("bt.2020")) { - // recommendation 2020 + // ITU recommendation 2020 iccProfileName = "rec2020"; - } else if ("adobe-rgb-(1998)".equals(iccProfileName)) { + } else if ("romm".equals(iccProfileName) + || "largergb-elle-v4-g18.icc".equals(iccProfileName) + || "prophoto".equals(iccProfileName)) { + // Names used in "freely available profiles" for Prophoto + iccProfileName = "prophoto-rgb"; + } else if ("a98c".equals(iccProfileName) + || "adobe-rgb-(1998)".equals(iccProfileName) // the 'official' name + || "clayrgb-elle-v4-g22.icc".equals(iccProfileName) + || "adobe98".equals(iccProfileName)) { // A98 iccProfileName = "a98-rgb"; } diff --git a/echosvg-test/src/test/java/io/sf/carte/echosvg/bridge/test/ModificationsTest.java b/echosvg-test/src/test/java/io/sf/carte/echosvg/bridge/test/ModificationsTest.java new file mode 100644 index 000000000..ea0c2399f --- /dev/null +++ b/echosvg-test/src/test/java/io/sf/carte/echosvg/bridge/test/ModificationsTest.java @@ -0,0 +1,134 @@ +/* + + See the NOTICE file distributed with this work for additional + information regarding copyright ownership. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package io.sf.carte.echosvg.bridge.test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.awt.Dimension; +import java.awt.geom.Dimension2D; + +import org.junit.jupiter.api.Test; +import org.w3c.css.om.CSSStyleDeclaration; +import org.w3c.css.om.typed.CSSStyleValue; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentType; +import org.w3c.dom.Element; +import org.w3c.dom.svg.SVGDocument; +import org.w3c.dom.svg.SVGSVGElement; +import org.w3c.dom.view.ViewCSS; +import org.w3c.dom.views.DocumentView; + +import io.sf.carte.echosvg.anim.dom.SVGDOMImplementation; +import io.sf.carte.echosvg.anim.dom.SVGStylableElement; +import io.sf.carte.echosvg.bridge.BridgeContext; +import io.sf.carte.echosvg.bridge.GVTBuilder; +import io.sf.carte.echosvg.bridge.UserAgentAdapter; +import io.sf.carte.echosvg.constants.XMLConstants; +import io.sf.carte.echosvg.css.dom.CSSValue; +import io.sf.carte.echosvg.css.dom.CSSValue.CssType; +import io.sf.carte.echosvg.gvt.GraphicsNode; +import io.sf.carte.echosvg.util.CSSConstants; +import io.sf.carte.echosvg.util.SVGConstants; + +/** + * Test value modifications. + */ +public class ModificationsTest { + + @Test + void testFillRGB() { + CSSStyleValue value = updateValue(CSSConstants.CSS_FILL_PROPERTY, "rgb(120, 30, 200)", + "color(display-p3 0.6 0.2 0.7)"); + assertNotNull(value); + } + + @Test + void testFillColorFunction() { + CSSStyleValue value = updateValue(CSSConstants.CSS_FILL_PROPERTY, "color(display-p3 0.6 0.2 0.7)", + "rgb(120, 30, 200)"); + assertNotNull(value); + } + + static CSSStyleValue updateValue(String ptyName, String ptyValue, String newValue) { + BridgeContext ctx = createBridgeContext(); + SVGDocument doc = createDocumentWithStyle(ptyName + ':' + ptyValue); + GraphicsNode gn = createGraphicsNode(ctx, doc); + assertNotNull(gn); + SVGStylableElement rect = (SVGStylableElement) doc.getElementById("rect1"); + assertNotNull(rect); + + ViewCSS view = (ViewCSS) ((DocumentView) doc).getDefaultView(); + CSSStyleDeclaration cs = view.getComputedStyle(rect, null); + CSSValue val = (CSSValue) cs.getCSSStyleValue(ptyName); + + assertNotNull(val); + assertEquals(CssType.TYPED, val.getCssValueType()); + assertEquals(ptyValue, val.getCssText()); + + rect.getStyle().setProperty(ptyName, newValue, null); + String styleDecl = ptyName + ": " + newValue + ';'; + assertEquals(styleDecl, rect.getStyle().getCssText().replace("\n", "")); + assertEquals(styleDecl, rect.getAttribute("style").replace("\n", "")); + + cs = view.getComputedStyle(rect, null); + CSSStyleValue modval = cs.getCSSStyleValue(ptyName); + + assertNotNull(modval); + assertEquals(newValue, modval.toString()); + + return modval; + } + + private static SVGDocument createDocumentWithStyle(String rectStyle) { + DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); + DocumentType dtd = impl.createDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", + "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"); + SVGDocument doc = (SVGDocument) impl.createDocument(SVGConstants.SVG_NAMESPACE_URI, + SVGConstants.SVG_SVG_TAG, dtd); + SVGSVGElement svg = doc.getRootElement(); + svg.setAttribute("width", "200"); + svg.setAttribute("height", "200"); + Element rect = doc.createElementNS(SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_RECT_TAG); + rect.setAttribute(XMLConstants.XML_ID_ATTRIBUTE, "rect1"); + rect.setAttribute(SVGConstants.SVG_STYLE_ATTRIBUTE, rectStyle); + svg.appendChild(rect); + return doc; + } + + private static BridgeContext createBridgeContext() { + BridgeContext ctx = new BridgeContext(new UserAgentAdapter() { + + @Override + public Dimension2D getViewportSize() { + return new Dimension(200, 200); + } + + }); + ctx.setDynamic(true); + + return ctx; + } + + private static GraphicsNode createGraphicsNode(BridgeContext ctx, Document document) { + return new GVTBuilder().build(ctx, document); + } + +} diff --git a/echosvg-test/src/test/java/io/sf/carte/echosvg/svggen/test/FontDecoration.java b/echosvg-test/src/test/java/io/sf/carte/echosvg/svggen/test/FontDecoration.java index ff1ba8780..890f5cd97 100644 --- a/echosvg-test/src/test/java/io/sf/carte/echosvg/svggen/test/FontDecoration.java +++ b/echosvg-test/src/test/java/io/sf/carte/echosvg/svggen/test/FontDecoration.java @@ -71,17 +71,17 @@ public void paint(Graphics2D g) { // Prepare a color Color stColor; - // Load a color profile that does not match a known space (although it is). + // Load a color profile try (InputStream is = getClass().getResourceAsStream( - "/io/sf/carte/echosvg/css/color/profiles/LargeRGB-elle-V4-g18.icc")) { + "/io/sf/carte/echosvg/css/color/profiles/WideGamutPhoto-v4.icc")) { ICC_Profile profile = ICC_Profile.getInstance(is); ICC_ColorSpace cs = new ICC_ColorSpace(profile); float[] comps = { 0.33f, 0.34f, 0.43f }; stColor = new Color(cs, comps, 1f); } catch (IOException e) { + e.printStackTrace(); stColor = new Color(0x666699); } - // The color will be translated to XYZ (D50) // Set the STRIKETHROUGH font and a color g.setFont(fontST); @@ -101,6 +101,7 @@ public void paint(Graphics2D g) { float[] comps = { .55f, .6f, .34f }; lColor = new Color(cs, comps, 1f); } catch (IOException e) { + e.printStackTrace(); lColor = Color.magenta; } @@ -119,6 +120,7 @@ public void paint(Graphics2D g) { float[] comps = { .36f, .35f, .33f }; ulColor = new Color(cs, comps, 1f); } catch (IOException e) { + e.printStackTrace(); ulColor = Color.black; } diff --git a/echosvg-test/src/test/java/io/sf/carte/echosvg/test/svg/SamplesCanvgRenderingTest.java b/echosvg-test/src/test/java/io/sf/carte/echosvg/test/svg/SamplesCanvgRenderingTest.java index 3124b37c6..602b95b40 100644 --- a/echosvg-test/src/test/java/io/sf/carte/echosvg/test/svg/SamplesCanvgRenderingTest.java +++ b/echosvg-test/src/test/java/io/sf/carte/echosvg/test/svg/SamplesCanvgRenderingTest.java @@ -913,7 +913,7 @@ public void testIssue289() throws TranscoderException, IOException { */ @Test public void testIssue320() throws TranscoderException, IOException { - testNVErrIgnore("samples/canvg/issue320.svg", BROWSER_MEDIA, 1); + testNV("samples/canvg/issue320.svg"); } @Test @@ -1049,7 +1049,7 @@ public void testIssue620() throws TranscoderException, IOException { @Test public void testIssue690() throws TranscoderException, IOException { - testNVErrIgnore("samples/canvg/issue690.svg", BROWSER_MEDIA, 4); + testNV("samples/canvg/issue690.svg"); } @Test diff --git a/echosvg-test/src/test/java/io/sf/carte/echosvg/test/svg/SamplesSpecRenderingTest.java b/echosvg-test/src/test/java/io/sf/carte/echosvg/test/svg/SamplesSpecRenderingTest.java index e1e7f3279..781220d6e 100644 --- a/echosvg-test/src/test/java/io/sf/carte/echosvg/test/svg/SamplesSpecRenderingTest.java +++ b/echosvg-test/src/test/java/io/sf/carte/echosvg/test/svg/SamplesSpecRenderingTest.java @@ -27,6 +27,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import io.sf.carte.echosvg.test.ScriptUtil; import io.sf.carte.echosvg.test.TestFonts; import io.sf.carte.echosvg.transcoder.TranscoderException; @@ -47,6 +48,7 @@ public class SamplesSpecRenderingTest extends AbstractSamplesRendering { @BeforeAll public static void setUpBeforeClass() throws Exception { TestFonts.loadTestFonts(); + ScriptUtil.defaultRhinoShutter(); } /* @@ -294,7 +296,7 @@ public void testAnchor() throws TranscoderException, IOException { @Test public void testImageBadUrl() throws TranscoderException, IOException { /* - * Admits one error (the broken link being reported). + * Admits errors (the broken link and the invalid x,y being reported). */ testNVErrIgnore("samples/tests/spec/linking/imageBadUrl.svg", null, 5); } diff --git a/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/image/PNGTranscoder.java b/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/image/PNGTranscoder.java index 26f1d7508..5680b7466 100644 --- a/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/image/PNGTranscoder.java +++ b/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/image/PNGTranscoder.java @@ -18,10 +18,16 @@ */ package io.sf.carte.echosvg.transcoder.image; +import java.awt.Transparency; +import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; +import java.awt.image.ComponentColorModel; +import java.awt.image.DataBuffer; import java.awt.image.SinglePixelPackedSampleModel; +import java.awt.image.WritableRaster; import java.io.OutputStream; +import io.sf.carte.echosvg.bridge.BridgeContext; import io.sf.carte.echosvg.transcoder.TranscoderException; import io.sf.carte.echosvg.transcoder.TranscoderOutput; import io.sf.carte.echosvg.transcoder.TranscodingHints; @@ -54,7 +60,19 @@ public PNGTranscoder() { */ @Override public BufferedImage createImage(int width, int height) { - return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + BufferedImage image; + BridgeContext ctx = getBridgeContext(); + ColorSpace space; + if (ctx == null || (space = ctx.getColorSpace()) == null) { + image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + } else { + int[] bits = { 16, 16, 16, 16 }; + ComponentColorModel cm = new ComponentColorModel(space, bits, true, false, + Transparency.TRANSLUCENT, DataBuffer.TYPE_USHORT); + WritableRaster raster = cm.createCompatibleWritableRaster(width, height); + image = new BufferedImage(cm, raster, false, null); + } + return image; } /** diff --git a/gradle.properties b/gradle.properties index 59c8f269d..3c5adc532 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,8 @@ css4jAwtVersion=4.0 xmlDtdVersion=4.3 rhinoVersion=1.7.15 legacyColorsVersion=1.0 -svgomVersion=1.0.1 +domViewVersion=1.0 +svgomVersion=1.1 xmlApisVersion=1.4.01 commonsIOVersion=2.16.1 htmlParserVersion=1.4.16 diff --git a/samples/tests/spec/scripting/domSVGColor.svg b/samples/tests/spec/scripting/domSVGColor.svg index 9a97c3915..126e4ebd7 100644 --- a/samples/tests/spec/scripting/domSVGColor.svg +++ b/samples/tests/spec/scripting/domSVGColor.svg @@ -23,8 +23,8 @@ - - + + @@ -45,60 +45,67 @@ test(); } - function showFill(id, suff) { + function showFill(id, suff, newValue) { var elem = document.getElementById(id); - var fill = elem.style.getPropertyCSSValue("fill"); - var tb = document.getElementById(id+suff); - tb.appendChild(document.createTextNode(fill.getCssText())); + var st = elem.style; + var fill = st.getCSSStyleValue("fill"); + var tb = document.getElementById(id+suff); + var text = fill.getCssText(); + tb.appendChild(document.createTextNode(text)); + if (newValue) { + st.setProperty("fill", newValue, ""); + fill = st.getCSSStyleValue("fill"); + } return fill; } function test() { var fill, r, g, b; - fill = showFill("r1", ".b"); - fill.setCssText("gold"); - showFill("r1", ".a"); - - fill = showFill("r2", ".b"); - fill.setCssText("gold"); - showFill("r2", ".a"); + fill = showFill("r1", ".b", "gold"); + showFill("r1", ".a"); - fill = showFill("r3", ".b"); - r = fill.getRed(); r.setCssText("50"); - showFill("r3", ".a"); + fill = showFill("r2", ".b"); + r = fill.getR(); r.setValue(31.4); + fill.b.setValue(50); + showFill("r2", ".a"); - fill = showFill("r4", ".b"); - r = fill.getRed(); r.setFloatValue(UNIT_NUMBER, 50); - showFill("r4", ".a"); - - fill = showFill("r5", ".b"); - r = fill.getRed(); r.setFloatValue(UNIT_NUMBER, 128); - showFill("r5", ".a"); - - fill = showFill("r6", ".b"); - g = fill.getGreen(); g.setCssText("50"); - showFill("r6", ".a"); + fill = showFill("r3", ".b"); + r = fill.getR(); r.setValue(19.6); + showFill("r3", ".a"); + + fill = showFill("r4", ".b", "color(display-p3 0.94 0.55 0.31)"); + fill.item(2).setValue(0.64); + showFill("r4", ".a"); + + fill = showFill("r5", ".b"); + r = fill.getR(); r.setValue("128"); + fill.setAlpha(0.95); + showFill("r5", ".a"); + + fill = showFill("r6", ".b"); + g = fill.getG(); g.setValue("19.6%"); + showFill("r6", ".a"); - fill = showFill("r7", ".b"); - g = fill.getGreen(); g.setFloatValue(UNIT_PERCENT, 19.6); - showFill("r7", ".a"); + fill = showFill("r7", ".b"); + g = fill.getG(); g.setValue(19.6); + showFill("r7", ".a"); - fill = showFill("r8", ".b"); - g = fill.getGreen(); g.setFloatValue(UNIT_NUMBER, 128); - showFill("r8", ".a"); + fill = showFill("r8", ".b"); + g = fill.getG(); g.setValue("50%"); + showFill("r8", ".a"); - fill = showFill("r9", ".b"); - b = fill.getBlue(); b.setCssText("50"); - showFill("r9", ".a"); - - fill = showFill("r10", ".b"); - b = fill.getBlue(); b.setFloatValue(UNIT_NUMBER, 50); - showFill("r10", ".a"); + fill = showFill("r9", ".b"); + b = fill.getB(); b.setValue("50"); + showFill("r9", ".a"); + + fill = showFill("r10", ".b"); + b = fill.getB(); b.setValue(19.6); + showFill("r10", ".a"); - fill = showFill("r11", ".b"); - fill.setCssText("rgb(220, 0, 128, 0.87)"); - showFill("r11", ".a"); + fill = showFill("r11", ".b", "rgba(220, 0, 128, 1)"); + fill.setAlpha(0.87); + showFill("r11", ".a"); } ]]> diff --git a/samples/tests/spec/scripting/paintType.svg b/samples/tests/spec/scripting/paintType.svg index 2c3cab35f..439eddde3 100644 --- a/samples/tests/spec/scripting/paintType.svg +++ b/samples/tests/spec/scripting/paintType.svg @@ -54,7 +54,7 @@ function getType(id, attr) { var e = document.getElementById(id); - var pa = e.getPresentationAttribute(attr); + var pa = e.getPresentationAttributeValue(attr); var pt = pa.paintType; var txt; if (pt == UNKNOWN) txt="UNKNOWN"; diff --git a/samples/tests/spec/scripting/relativeURI.svg b/samples/tests/spec/scripting/relativeURI.svg index a83684761..dcbaa2b61 100644 --- a/samples/tests/spec/scripting/relativeURI.svg +++ b/samples/tests/spec/scripting/relativeURI.svg @@ -83,7 +83,7 @@ function init() { cssStyle.setProperty("cursor", "url(#cur),crosshair",""); localStr = cssStyle.getPropertyValue("cursor"); - absStr = computedStyle.getPropertyCSSValue("cursor"); + absStr = computedStyle.getCSSStyleValue("cursor"); absStr = absStr.item(0).getCssText(); t3.firstChild.nodeValue = unifyURL(localStr); t4.firstChild.nodeValue = unifyURL(absStr); diff --git a/samples/tests/spec/scripting/setProperty.svg b/samples/tests/spec/scripting/setProperty.svg index 5960648bd..e26db294d 100644 --- a/samples/tests/spec/scripting/setProperty.svg +++ b/samples/tests/spec/scripting/setProperty.svg @@ -49,7 +49,7 @@ e = document.getElementById("r2"); style = e.getStyle(); - var paint = style.getPropertyCSSValue("fill"); + var paint = style.getCSSStyleValue("fill"); paint.setPaint(SVGPaint.SVG_PAINTTYPE_URI, "#lg", "", ""); if (paint.getPaintType() != SVGPaint.SVG_PAINTTYPE_URI) throw ("Wrong paint type: " + paint.getPaintType()); diff --git a/test-references/io/sf/carte/echosvg/svggen/ContextFontDecoration.svg b/test-references/io/sf/carte/echosvg/svggen/ContextFontDecoration.svg index a456361db..f6ab1e643 100644 --- a/test-references/io/sf/carte/echosvg/svggen/ContextFontDecoration.svg +++ b/test-references/io/sf/carte/echosvg/svggen/ContextFontDecoration.svg @@ -5,7 +5,7 @@ >