Skip to content

Commit

Permalink
css: move the margin properties from 1.2 to the base SVG implementation
Browse files Browse the repository at this point in the history
This is important for the future support of foreign elements.
  • Loading branch information
carlosame committed Oct 10, 2024
1 parent fa9a12d commit 3593265
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -818,10 +818,10 @@ protected void checkMap(Map<Attribute, Object> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="mailto:[email protected]">Stephane Hillion</a>
* @author For later modifications, see Git history.
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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(),
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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'
Expand All @@ -50,7 +50,7 @@ public MarginShorthandManager() {
*/
@Override
public String getPropertyName() {
return SVG12CSSConstants.CSS_MARGIN_PROPERTY;
return CSSConstants.CSS_MARGIN_PROPERTY;
}

/**
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
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;
import io.sf.carte.echosvg.css.engine.value.UnsetValue;
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 3593265

Please sign in to comment.