From 3593265837342e063d2acf10f13a0562d12fa952 Mon Sep 17 00:00:00 2001 From: Carlos Amengual Date: Thu, 10 Oct 2024 14:36:36 +0200 Subject: [PATCH] css: move the margin properties from 1.2 to the base SVG implementation This is important for the future support of foreign elements. --- .../svg12/SVGFlowRootElementBridge.java | 8 ++--- .../echosvg/css/engine/SVG12CSSEngine.java | 15 ++-------- .../echosvg/css/engine/SVGCSSEngine.java | 19 ++++++++++-- .../MarginShorthandManager.java | 30 +++++++++---------- .../value/css2/TextDecorationManager.java | 2 +- .../sf/carte/echosvg/util/CSSConstants.java | 10 +++++++ .../carte/echosvg/util/SVG12CSSConstants.java | 10 ------- 7 files changed, 49 insertions(+), 45 deletions(-) rename echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/{svg12 => css2}/MarginShorthandManager.java (76%) diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/svg12/SVGFlowRootElementBridge.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/svg12/SVGFlowRootElementBridge.java index 79f206260..716e8b3e7 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/svg12/SVGFlowRootElementBridge.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/svg12/SVGFlowRootElementBridge.java @@ -818,10 +818,10 @@ protected void checkMap(Map attrs) { protected void initCSSPropertyIndexes(Element e) { CSSEngine eng = CSSUtilities.getCSSEngine(e); - marginTopIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_MARGIN_TOP_PROPERTY); - marginRightIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_MARGIN_RIGHT_PROPERTY); - marginBottomIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY); - marginLeftIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_MARGIN_LEFT_PROPERTY); + marginTopIndex = eng.getPropertyIndex(CSSConstants.CSS_MARGIN_TOP_PROPERTY); + marginRightIndex = eng.getPropertyIndex(CSSConstants.CSS_MARGIN_RIGHT_PROPERTY); + marginBottomIndex = eng.getPropertyIndex(CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY); + marginLeftIndex = eng.getPropertyIndex(CSSConstants.CSS_MARGIN_LEFT_PROPERTY); indentIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_INDENT_PROPERTY); textAlignIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_TEXT_ALIGN_PROPERTY); lineHeightIndex = eng.getLineHeightIndex(); diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/SVG12CSSEngine.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/SVG12CSSEngine.java index 2b6d4f54f..ffd49988c 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/SVG12CSSEngine.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/SVG12CSSEngine.java @@ -26,13 +26,12 @@ import io.sf.carte.echosvg.css.engine.value.svg.OpacityManager; import io.sf.carte.echosvg.css.engine.value.svg.SVGColorManager; import io.sf.carte.echosvg.css.engine.value.svg12.MarginLengthManager; -import io.sf.carte.echosvg.css.engine.value.svg12.MarginShorthandManager; import io.sf.carte.echosvg.css.engine.value.svg12.TextAlignManager; import io.sf.carte.echosvg.util.ParsedURL; import io.sf.carte.echosvg.util.SVG12CSSConstants; /** - * This class provides a CSS engine initialized for SVG. + * This class provides a CSS engine initialized for SVG 1.2. * * @author Stephane Hillion * @author For later modifications, see Git history. @@ -72,27 +71,19 @@ public SVG12CSSEngine(Document doc, ParsedURL uri, Parser p, ValueManager[] vms, */ public static final ValueManager[] SVG_VALUE_MANAGERS = { new MarginLengthManager(SVG12CSSConstants.CSS_INDENT_PROPERTY), - new MarginLengthManager(SVG12CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY), - new MarginLengthManager(SVG12CSSConstants.CSS_MARGIN_LEFT_PROPERTY), - new MarginLengthManager(SVG12CSSConstants.CSS_MARGIN_RIGHT_PROPERTY), - new MarginLengthManager(SVG12CSSConstants.CSS_MARGIN_TOP_PROPERTY), new SVGColorManager(SVG12CSSConstants.CSS_SOLID_COLOR_PROPERTY), new OpacityManager(SVG12CSSConstants.CSS_SOLID_OPACITY_PROPERTY, true), new TextAlignManager(), }; /** * The shorthand managers for SVG. */ - public static final ShorthandManager[] SVG_SHORTHAND_MANAGERS = { new MarginShorthandManager(), }; + public static final ShorthandManager[] SVG_SHORTHAND_MANAGERS = { }; // // The property indexes. // public static final int INDENT_INDEX = SVGCSSEngine.FINAL_INDEX + 1; - public static final int MARGIN_BOTTOM_INDEX = INDENT_INDEX + 1; - public static final int MARGIN_LEFT_INDEX = MARGIN_BOTTOM_INDEX + 1; - public static final int MARGIN_RIGHT_INDEX = MARGIN_LEFT_INDEX + 1; - public static final int MARGIN_TOP_INDEX = MARGIN_RIGHT_INDEX + 1; - public static final int SOLID_COLOR_INDEX = MARGIN_TOP_INDEX + 1; + public static final int SOLID_COLOR_INDEX = INDENT_INDEX + 1; public static final int SOLID_OPACITY_INDEX = SOLID_COLOR_INDEX + 1; public static final int TEXT_ALIGN_INDEX = SOLID_OPACITY_INDEX + 1; public static final int FINAL_INDEX = TEXT_ALIGN_INDEX; diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/SVGCSSEngine.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/SVGCSSEngine.java index debe05916..dd06b93be 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/SVGCSSEngine.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/SVGCSSEngine.java @@ -37,6 +37,7 @@ import io.sf.carte.echosvg.css.engine.value.css2.FontVariantManager; import io.sf.carte.echosvg.css.engine.value.css2.FontWeightManager; import io.sf.carte.echosvg.css.engine.value.css2.LineHeightManager; +import io.sf.carte.echosvg.css.engine.value.css2.MarginShorthandManager; import io.sf.carte.echosvg.css.engine.value.css2.OverflowManager; import io.sf.carte.echosvg.css.engine.value.css2.SrcManager; import io.sf.carte.echosvg.css.engine.value.css2.TextDecorationManager; @@ -77,6 +78,7 @@ import io.sf.carte.echosvg.css.engine.value.svg.TextAnchorManager; import io.sf.carte.echosvg.css.engine.value.svg.TextRenderingManager; import io.sf.carte.echosvg.css.engine.value.svg.WritingModeManager; +import io.sf.carte.echosvg.css.engine.value.svg12.MarginLengthManager; import io.sf.carte.echosvg.util.CSSConstants; import io.sf.carte.echosvg.util.ParsedURL; @@ -173,8 +175,14 @@ protected static ShorthandManager[] mergeArrays(ShorthandManager[] a1, Shorthand new ImageRenderingManager(), new KerningManager(), new SpacingManager(CSSConstants.CSS_LETTER_SPACING_PROPERTY), new SVGColorManager(CSSConstants.CSS_LIGHTING_COLOR_PROPERTY, ValueConstants.WHITE_RGB_VALUE), - new LineHeightManager(), new MarkerManager(CSSConstants.CSS_MARKER_END_PROPERTY), + new LineHeightManager(), + new MarginLengthManager(CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY), + new MarginLengthManager(CSSConstants.CSS_MARGIN_LEFT_PROPERTY), + new MarginLengthManager(CSSConstants.CSS_MARGIN_RIGHT_PROPERTY), + new MarginLengthManager(CSSConstants.CSS_MARGIN_TOP_PROPERTY), + + new MarkerManager(CSSConstants.CSS_MARKER_END_PROPERTY), new MarkerManager(CSSConstants.CSS_MARKER_MID_PROPERTY), new MarkerManager(CSSConstants.CSS_MARKER_START_PROPERTY), new MaskManager(), new OpacityManager(CSSConstants.CSS_OPACITY_PROPERTY, false), new OverflowManager(), @@ -197,7 +205,7 @@ protected static ShorthandManager[] mergeArrays(ShorthandManager[] a1, Shorthand * The shorthand managers for SVG. */ public static final ShorthandManager[] SVG_SHORTHAND_MANAGERS = { new FontShorthandManager(), - new MarkerShorthandManager(), }; + new MarginShorthandManager(), new MarkerShorthandManager(), }; // // The property indexes. @@ -243,7 +251,12 @@ protected static ShorthandManager[] mergeArrays(ShorthandManager[] a1, Shorthand public static final int LETTER_SPACING_INDEX = KERNING_INDEX + 1; public static final int LIGHTING_COLOR_INDEX = LETTER_SPACING_INDEX + 1; public static final int LINE_HEIGHT_INDEX = LIGHTING_COLOR_INDEX + 1; - public static final int MARKER_END_INDEX = LINE_HEIGHT_INDEX + 1; + + public static final int MARGIN_BOTTOM_INDEX = LINE_HEIGHT_INDEX + 1; + public static final int MARGIN_LEFT_INDEX = MARGIN_BOTTOM_INDEX + 1; + public static final int MARGIN_RIGHT_INDEX = MARGIN_LEFT_INDEX + 1; + public static final int MARGIN_TOP_INDEX = MARGIN_RIGHT_INDEX + 1; + public static final int MARKER_END_INDEX = MARGIN_TOP_INDEX + 1; public static final int MARKER_MID_INDEX = MARKER_END_INDEX + 1; public static final int MARKER_START_INDEX = MARKER_MID_INDEX + 1; diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/MarginShorthandManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/MarginShorthandManager.java similarity index 76% rename from echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/MarginShorthandManager.java rename to echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/MarginShorthandManager.java index b9a209bf5..71d8c73eb 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/MarginShorthandManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/css2/MarginShorthandManager.java @@ -16,7 +16,7 @@ limitations under the License. */ -package io.sf.carte.echosvg.css.engine.value.svg12; +package io.sf.carte.echosvg.css.engine.value.css2; import org.w3c.dom.DOMException; @@ -28,7 +28,7 @@ import io.sf.carte.echosvg.css.engine.value.ShorthandManager; import io.sf.carte.echosvg.css.engine.value.ValueConstants; import io.sf.carte.echosvg.css.engine.value.ValueManager; -import io.sf.carte.echosvg.util.SVG12CSSConstants; +import io.sf.carte.echosvg.util.CSSConstants; /** * This class represents an object which provide support for the 'margin' @@ -50,7 +50,7 @@ public MarginShorthandManager() { */ @Override public String getPropertyName() { - return SVG12CSSConstants.CSS_MARGIN_PROPERTY; + return CSSConstants.CSS_MARGIN_PROPERTY; } /** @@ -85,10 +85,10 @@ public void setValues(CSSEngine eng, ShorthandManager.PropertyHandler ph, final case INITIAL: // Set defaults LexicalUnit luZero = ValueConstants.ZERO_LEXICAL_UNIT; - ph.property(SVG12CSSConstants.CSS_MARGIN_TOP_PROPERTY, luZero, imp); - ph.property(SVG12CSSConstants.CSS_MARGIN_RIGHT_PROPERTY, luZero, imp); - ph.property(SVG12CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY, luZero, imp); - ph.property(SVG12CSSConstants.CSS_MARGIN_LEFT_PROPERTY, luZero, imp); + ph.property(CSSConstants.CSS_MARGIN_TOP_PROPERTY, luZero, imp); + ph.property(CSSConstants.CSS_MARGIN_RIGHT_PROPERTY, luZero, imp); + ph.property(CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY, luZero, imp); + ph.property(CSSConstants.CSS_MARGIN_LEFT_PROPERTY, luZero, imp); break; case VAR: @@ -127,18 +127,18 @@ public void setValues(CSSEngine eng, ShorthandManager.PropertyHandler ph, final default: } - ph.property(SVG12CSSConstants.CSS_MARGIN_TOP_PROPERTY, lus[0], imp); - ph.property(SVG12CSSConstants.CSS_MARGIN_RIGHT_PROPERTY, lus[1], imp); - ph.property(SVG12CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY, lus[2], imp); - ph.property(SVG12CSSConstants.CSS_MARGIN_LEFT_PROPERTY, lus[3], imp); + ph.property(CSSConstants.CSS_MARGIN_TOP_PROPERTY, lus[0], imp); + ph.property(CSSConstants.CSS_MARGIN_RIGHT_PROPERTY, lus[1], imp); + ph.property(CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY, lus[2], imp); + ph.property(CSSConstants.CSS_MARGIN_LEFT_PROPERTY, lus[3], imp); } private void setPendingLonghands(CSSEngine eng, PropertyHandler ph, LexicalUnit lunit, boolean imp) { PendingValue pending = new PendingValue(getPropertyName(), lunit); - ph.pendingValue(SVG12CSSConstants.CSS_MARGIN_TOP_PROPERTY, pending, imp); - ph.pendingValue(SVG12CSSConstants.CSS_MARGIN_RIGHT_PROPERTY, pending, imp); - ph.pendingValue(SVG12CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY, pending, imp); - ph.pendingValue(SVG12CSSConstants.CSS_MARGIN_LEFT_PROPERTY, pending, imp); + ph.pendingValue(CSSConstants.CSS_MARGIN_TOP_PROPERTY, pending, imp); + ph.pendingValue(CSSConstants.CSS_MARGIN_RIGHT_PROPERTY, pending, imp); + ph.pendingValue(CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY, pending, imp); + ph.pendingValue(CSSConstants.CSS_MARGIN_LEFT_PROPERTY, pending, imp); } } 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 a9f4c1bf3..065d52f7e 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 @@ -26,6 +26,7 @@ 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; +import io.sf.carte.echosvg.css.engine.value.LexicalValue; import io.sf.carte.echosvg.css.engine.value.ListValue; import io.sf.carte.echosvg.css.engine.value.RevertValue; import io.sf.carte.echosvg.css.engine.value.StringMap; @@ -33,7 +34,6 @@ 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.LexicalValue; import io.sf.carte.echosvg.util.CSSConstants; import io.sf.carte.echosvg.util.SVGTypes; diff --git a/echosvg-util/src/main/java/io/sf/carte/echosvg/util/CSSConstants.java b/echosvg-util/src/main/java/io/sf/carte/echosvg/util/CSSConstants.java index 96d55497e..845657e07 100644 --- a/echosvg-util/src/main/java/io/sf/carte/echosvg/util/CSSConstants.java +++ b/echosvg-util/src/main/java/io/sf/carte/echosvg/util/CSSConstants.java @@ -72,6 +72,16 @@ public interface CSSConstants { String CSS_LETTER_SPACING_PROPERTY = "letter-spacing"; String CSS_LIGHTING_COLOR_PROPERTY = "lighting-color"; String CSS_LINE_HEIGHT_PROPERTY = "line-height"; + /** Property name for margin shorthand */ + String CSS_MARGIN_PROPERTY = "margin"; + /** Property name for top-margin */ + String CSS_MARGIN_TOP_PROPERTY = "margin-top"; + /** Property name for right-margin */ + String CSS_MARGIN_RIGHT_PROPERTY = "margin-right"; + /** Property name for bottom-margin */ + String CSS_MARGIN_BOTTOM_PROPERTY = "margin-bottom"; + /** Property name for left-margin */ + String CSS_MARGIN_LEFT_PROPERTY = "margin-left"; String CSS_MARKER_PROPERTY = "marker"; String CSS_MARKER_END_PROPERTY = "marker-end"; String CSS_MARKER_MID_PROPERTY = "marker-mid"; diff --git a/echosvg-util/src/main/java/io/sf/carte/echosvg/util/SVG12CSSConstants.java b/echosvg-util/src/main/java/io/sf/carte/echosvg/util/SVG12CSSConstants.java index 796423078..9de25107e 100644 --- a/echosvg-util/src/main/java/io/sf/carte/echosvg/util/SVG12CSSConstants.java +++ b/echosvg-util/src/main/java/io/sf/carte/echosvg/util/SVG12CSSConstants.java @@ -29,16 +29,6 @@ */ public interface SVG12CSSConstants extends CSSConstants { - /** Property name for margin shorthand */ - String CSS_MARGIN_PROPERTY = "margin"; - /** Property name for top-margin */ - String CSS_MARGIN_TOP_PROPERTY = "margin-top"; - /** Property name for right-margin */ - String CSS_MARGIN_RIGHT_PROPERTY = "margin-right"; - /** Property name for bottom-margin */ - String CSS_MARGIN_BOTTOM_PROPERTY = "margin-bottom"; - /** Property name for left-margin */ - String CSS_MARGIN_LEFT_PROPERTY = "margin-left"; /** property name for indent */ String CSS_INDENT_PROPERTY = "indent"; /** property name for text-align */