You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by ga...@apache.org on 2014/11/03 05:14:54 UTC

svn commit: r1636244 - in /xmlgraphics/batik/branches/text-background: sources/org/apache/batik/bridge/ sources/org/apache/batik/css/engine/ sources/org/apache/batik/css/engine/value/ sources/org/apache/batik/css/engine/value/css2/ sources/org/apache/b...

Author: gadams
Date: Mon Nov  3 04:14:53 2014
New Revision: 1636244

URL: http://svn.apache.org/r1636244
Log:
Initial support for text background color.

Added:
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/RGBAColorValue.java   (with props)
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/css2/BackgroundModeManager.java   (with props)
Modified:
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/PaintServer.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/SVGTextElementBridge.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/TextUtilities.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/SVGCSSEngine.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/AbstractColorManager.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/AbstractValue.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/ComputedValue.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/Value.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/ValueConstants.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/svg/ColorManager.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/svg/SVGValueConstants.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/TextNode.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/text/GVTAttributedCharacterIterator.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/text/TextPaintInfo.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/svggen/SVGStylingAttributes.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/util/CSSConstants.java
    xmlgraphics/batik/branches/text-background/sources/org/apache/batik/util/SVGConstants.java
    xmlgraphics/batik/branches/text-background/test-resources/org/apache/batik/css/engine/value/unitTesting.xml
    xmlgraphics/batik/branches/text-background/test-sources/org/apache/batik/css/engine/value/PropertyManagerTest.java

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/PaintServer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/PaintServer.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/PaintServer.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/PaintServer.java Mon Nov  3 04:14:53 2014
@@ -27,6 +27,8 @@ import java.awt.color.ICC_Profile;
 import java.io.IOException;
 
 import org.apache.batik.css.engine.SVGCSSEngine;
+import org.apache.batik.css.engine.value.ComputedValue;
+import org.apache.batik.css.engine.value.RGBAColorValue;
 import org.apache.batik.css.engine.value.Value;
 import org.apache.batik.css.engine.value.svg.ICCColor;
 import org.apache.batik.css.engine.value.svg12.CIELabColor;
@@ -247,6 +249,28 @@ public abstract class PaintServer
     }
 
     /**
+     * Converts for the specified element, its background paint properties
+     * to a Paint object.
+     *
+     * @param backgroundElement the element interested in a Paint
+     * @param backgroundNode the graphics node to fill
+     * @param ctx the bridge context
+     */
+    public static Paint convertBackgroundPaint(Element backgroundElement,
+                                         GraphicsNode backgroundNode,
+                                         BridgeContext ctx) {
+        Value v = CSSUtilities.getComputedStyle
+            (backgroundElement, SVGCSSEngine.BACKGROUND_INDEX);
+        float opacity = 1f;
+
+        return convertPaint(backgroundElement,
+                            backgroundNode,
+                            v,
+                            opacity,
+                            ctx);
+    }
+
+    /**
      * Converts a Paint definition to a concrete <code>java.awt.Paint</code>
      * instance according to the specified parameters.
      *
@@ -584,10 +608,16 @@ public abstract class PaintServer
      * @param opacity The opacity value (0 &lt;= o &lt;= 1).
      */
     public static Color convertColor(Value c, float opacity) {
+        if (c instanceof ComputedValue)
+            c = ((ComputedValue)c).getComputedValue();
         int r = resolveColorComponent(c.getRed());
         int g = resolveColorComponent(c.getGreen());
         int b = resolveColorComponent(c.getBlue());
-        return new Color(r, g, b, Math.round(opacity * 255f));
+        if (c instanceof RGBAColorValue) {
+            return new Color(r, g, b,
+                Math.round(resolveAlphaComponent(((RGBAColorValue)c).getAlpha()) * 255f));
+        } else
+            return new Color(r, g, b, Math.round(opacity * 255f));
     }
 
     /////////////////////////////////////////////////////////////////////////
@@ -758,6 +788,27 @@ public abstract class PaintServer
     }
 
     /**
+     * Returns the value of the alpha component as a float in range [0.0, 1.0].
+     * @param v the value that defines the alpha component
+     */
+    public static float resolveAlphaComponent(Value v) {
+        float f;
+        switch(v.getPrimitiveType()) {
+        case CSSPrimitiveValue.CSS_PERCENTAGE:
+            f = v.getFloatValue();
+            f = (f > 100f) ? 100f : (f < 0f) ? 0f : f;
+            return f / 100f;
+        case CSSPrimitiveValue.CSS_NUMBER:
+            f = v.getFloatValue();
+            f = (f > 1f) ? 1f : (f < 0f) ? 0f : f;
+            return f;
+        default:
+            throw new IllegalArgumentException
+                ("Alpha component argument is not an appropriate CSS value");
+        }
+    }
+
+    /**
      * Returns the opacity represented by the specified CSSValue.
      * @param v the value that represents the opacity
      * @return the opacity between 0 and 1

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/SVGTextElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/SVGTextElementBridge.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/SVGTextElementBridge.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/SVGTextElementBridge.java Mon Nov  3 04:14:53 2014
@@ -40,6 +40,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.WeakHashMap;
 
+import org.apache.batik.css.engine.CSSEngine;
 import org.apache.batik.css.engine.CSSEngineEvent;
 import org.apache.batik.css.engine.CSSStylableElement;
 import org.apache.batik.css.engine.SVGCSSEngine;
@@ -61,6 +62,7 @@ import org.apache.batik.dom.util.XLinkSu
 import org.apache.batik.dom.util.XMLSupport;
 import org.apache.batik.gvt.GraphicsNode;
 import org.apache.batik.gvt.TextNode;
+import org.apache.batik.gvt.TextNode.BackgroundMode;
 import org.apache.batik.gvt.font.GVTFont;
 import org.apache.batik.gvt.font.GVTFontFamily;
 import org.apache.batik.gvt.font.GVTGlyphMetrics;
@@ -73,6 +75,7 @@ import org.apache.batik.gvt.text.TextHit
 import org.apache.batik.gvt.text.TextPaintInfo;
 import org.apache.batik.gvt.text.TextPath;
 import org.apache.batik.gvt.text.TextSpanLayout;
+import org.apache.batik.util.SVG12CSSConstants;
 import org.apache.batik.util.XMLConstants;
 
 import org.w3c.dom.Element;
@@ -97,6 +100,8 @@ import org.w3c.dom.svg.SVGTextPositionin
 public class SVGTextElementBridge extends AbstractGraphicsNodeBridge
     implements SVGTextContent {
 
+    public static final Color TRANSPARENT = new Color(0, 0, 0, 0);
+
     protected static final Integer ZERO = new Integer(0);
 
     public static final
@@ -632,11 +637,13 @@ public class SVGTextElementBridge extend
         TextNode tn = (TextNode)node;
         elemTPI.clear();
 
-        AttributedString as = buildAttributedString(ctx, e);
+        Map[] returnTextAttributes = new Map[1];
+        AttributedString as = buildAttributedString(ctx, e, returnTextAttributes);
         if (as == null) {
             tn.setAttributedCharacterIterator(null);
             return;
         }
+        Map textAttributes = returnTextAttributes[0];
 
         addGlyphPositionAttributes(as, e, ctx);
         if (ctx.isDynamic()) {
@@ -644,7 +651,7 @@ public class SVGTextElementBridge extend
         }
 
         // Install the ACI in the text node.
-        tn.setAttributedCharacterIterator(as.getIterator());
+        tn.setAttributedCharacterIterator(as.getIterator(), textAttributes);
 
         // Now get the real paint into - this needs to
         // wait until the text node is laidout so we can get
@@ -658,7 +665,7 @@ public class SVGTextElementBridge extend
 
         if (usingComplexSVGFont) {
             // Force Complex SVG fonts to be recreated, if we have them.
-            tn.setAttributedCharacterIterator(as.getIterator());
+            tn.setAttributedCharacterIterator(as.getIterator(), textAttributes);
         }
 
         if (ctx.isDynamic()) {
@@ -752,6 +759,8 @@ public class SVGTextElementBridge extend
      */
     protected void handleCSSPropertyChanged(int property) {
         switch(property) {                  // fall-through is intended
+        case SVGCSSEngine.BACKGROUND_INDEX:
+        case SVGCSSEngine.BACKGROUND_MODE_INDEX:
         case SVGCSSEngine.FILL_INDEX:
         case SVGCSSEngine.FILL_OPACITY_INDEX:
         case SVGCSSEngine.STROKE_INDEX:
@@ -821,7 +830,8 @@ public class SVGTextElementBridge extend
         if (usingComplexSVGFont)
             // Force Complex SVG fonts to be recreated
             textNode.setAttributedCharacterIterator
-                (textNode.getAttributedCharacterIterator());
+                (textNode.getAttributedCharacterIterator(),
+                 textNode.getTextAttributes());
     }
 
     int getElementStartIndex(Element element) {
@@ -850,13 +860,16 @@ public class SVGTextElementBridge extend
      */
     protected AttributedString buildAttributedString(BridgeContext ctx,
                                                      Element element) {
+        return this.buildAttributedString(ctx, element, null);
+    }
 
+    protected AttributedString buildAttributedString(BridgeContext ctx,
+                                                     Element element, Map[] returnTextAttributes) {
         AttributedStringBuffer asb = new AttributedStringBuffer();
-        fillAttributedStringBuffer(ctx, element, true, null, null, null, asb);
+        fillAttributedStringBuffer(ctx, element, true, null, null, null, asb, returnTextAttributes);
         return asb.toAttributedString();
     }
 
-
     /**
      * This is used to store the end of the last piece of text
      * content from an element with xml:space="preserve".  When
@@ -875,6 +888,17 @@ public class SVGTextElementBridge extend
                                               Integer bidiLevel,
                                               Map initialAttributes,
                                               AttributedStringBuffer asb) {
+        this.fillAttributedStringBuffer(ctx, element, top, textPath, bidiLevel, initialAttributes, asb);
+    }
+
+    protected void fillAttributedStringBuffer(BridgeContext ctx,
+                                              Element element,
+                                              boolean top,
+                                              TextPath textPath,
+                                              Integer bidiLevel,
+                                              Map initialAttributes,
+                                              AttributedStringBuffer asb,
+                                              Map[] returnTextAttributes) {
         // 'requiredFeatures', 'requiredExtensions', 'systemLanguage' &
         // 'display="none".
         if ((!SVGUtilities.matchUserAgent(element, ctx.getUserAgent())) ||
@@ -900,6 +924,10 @@ public class SVGTextElementBridge extend
                 : new HashMap(initialAttributes);
         initialAttributes =
             getAttributeMap(ctx, element, textPath, bidiLevel, map);
+        // retain top level text element's attributes
+        if (returnTextAttributes != null)
+            returnTextAttributes[0] = map;
+        // batik bidi processing
         Object o = map.get(TextAttribute.BIDI_EMBEDDING);
         Integer subBidiLevel = bidiLevel;
         if (o != null) {
@@ -938,7 +966,7 @@ public class SVGTextElementBridge extend
                                                textPath,
                                                subBidiLevel,
                                                initialAttributes,
-                                               asb);
+                                               asb, null);
                     if (asb.count != before) {
                         initialAttributes = null;
                     }
@@ -955,7 +983,7 @@ public class SVGTextElementBridge extend
                                                    newTextPath,
                                                    subBidiLevel,
                                                    initialAttributes,
-                                                   asb);
+                                                   asb, null);
                         if (asb.count != before) {
                             initialAttributes = null;
                         }
@@ -1002,7 +1030,7 @@ public class SVGTextElementBridge extend
                                                textPath,
                                                subBidiLevel,
                                                initialAttributes,
-                                               asb);
+                                               asb, null);
                     if (asb.count != before) {
                         initialAttributes = null;
                     }
@@ -1497,7 +1525,7 @@ public class SVGTextElementBridge extend
         // Font weight
         result.put(TextAttribute.WEIGHT,
                 TextUtilities.convertFontWeight(element));
-
+    
         // Font weight
         Value v = CSSUtilities.getComputedStyle
             (element, SVGCSSEngine.FONT_WEIGHT_INDEX);
@@ -1589,6 +1617,8 @@ public class SVGTextElementBridge extend
         TextPaintInfo pi = new TextPaintInfo();
         // Set some basic props so we can get bounds info for complex paints.
         pi.visible   = true;
+        pi.backgroundPaint = TRANSPARENT;
+        pi.backgroundMode = BackgroundMode.LINE_HEIGHT;
         pi.fillPaint = Color.black;
         result.put(PAINT_INFO, pi);
         elemTPI.put(element, pi);
@@ -1893,7 +1923,8 @@ public class SVGTextElementBridge extend
             (sm.isNullCascaded(SVGCSSEngine.FILL_INDEX)) &&
             (sm.isNullCascaded(SVGCSSEngine.STROKE_INDEX)) &&
             (sm.isNullCascaded(SVGCSSEngine.STROKE_WIDTH_INDEX)) &&
-            (sm.isNullCascaded(SVGCSSEngine.OPACITY_INDEX))) {
+            (sm.isNullCascaded(SVGCSSEngine.OPACITY_INDEX)) &&
+            (sm.isNullCascaded(SVGCSSEngine.BACKGROUND_INDEX))) {
             // If not, keep the same decorations.
             return pi;
         }
@@ -1914,6 +1945,8 @@ public class SVGTextElementBridge extend
             pi.composite    = AlphaComposite.SrcOver;
 
         pi.visible      = CSSUtilities.convertVisibility(element);
+        pi.backgroundPaint = PaintServer.convertBackgroundPaint(element, node, ctx);
+        pi.backgroundMode = TextUtilities.convertBackgroundMode(element);
         pi.fillPaint    = PaintServer.convertFillPaint  (element, node, ctx);
         pi.strokePaint  = PaintServer.convertStrokePaint(element, node, ctx);
         pi.strokeStroke = PaintServer.convertStroke     (element);

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/TextUtilities.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/TextUtilities.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/TextUtilities.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/bridge/TextUtilities.java Mon Nov  3 04:14:53 2014
@@ -23,7 +23,11 @@ import java.util.ArrayList;
 import java.util.StringTokenizer;
 
 import org.apache.batik.css.engine.SVGCSSEngine;
+import org.apache.batik.css.engine.value.ComputedValue;
 import org.apache.batik.css.engine.value.Value;
+import org.apache.batik.css.engine.value.ValueConstants;
+import org.apache.batik.css.engine.value.svg12.LineHeightValue;
+import org.apache.batik.css.engine.value.svg12.SVG12ValueConstants;
 import org.apache.batik.gvt.TextNode;
 import org.apache.batik.util.CSSConstants;
 import org.w3c.dom.Element;
@@ -146,6 +150,25 @@ public abstract class TextUtilities impl
     }
 
     /**
+     * Converts the line-height CSS value to a float value.
+     * @param e the element
+     */
+    public static Float convertLineHeight(Element e, int lineHeightIndex, float fontSize) {
+        Value v = CSSUtilities.getComputedStyle(e, lineHeightIndex);
+        if ((v == ValueConstants.INHERIT_VALUE) ||
+            (v == SVG12ValueConstants.NORMAL_VALUE)) {
+            return fontSize*1.1f;
+        }
+        float lineHeight = v.getFloatValue();
+        if (v instanceof ComputedValue)
+            v = ((ComputedValue)v).getComputedValue();
+        if ((v instanceof LineHeightValue) &&
+            ((LineHeightValue)v).getFontSizeRelative())
+            lineHeight *= fontSize;
+        return Float.valueOf(lineHeight);
+    }
+
+    /**
      * Converts the font-style CSS value to a float value.
      * @param e the element
      */
@@ -263,6 +286,23 @@ public abstract class TextUtilities impl
     }
 
     /**
+     * Converts the backgorund-mode CSS value to a TextNode.BackgroundMode.
+     * @param e the element
+     */
+    public static TextNode.BackgroundMode convertBackgroundMode(Element e) {
+        Value v = CSSUtilities.getComputedStyle
+            (e, SVGCSSEngine.BACKGROUND_MODE_INDEX);
+        switch (v.getStringValue().charAt(0)) {
+        case 'b':
+            return TextNode.BackgroundMode.BBOX;
+        case 'l':
+            return TextNode.BackgroundMode.LINE_HEIGHT;
+        default:
+            return TextNode.BackgroundMode.LINE_HEIGHT;
+        }
+    }
+
+    /**
      * Converts a baseline-shift CSS value to a value usable as a text
      * attribute, or null.
      * @param e the element

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/SVGCSSEngine.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/SVGCSSEngine.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/SVGCSSEngine.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/SVGCSSEngine.java Mon Nov  3 04:14:53 2014
@@ -21,6 +21,7 @@ package org.apache.batik.css.engine;
 import org.apache.batik.css.engine.value.ShorthandManager;
 import org.apache.batik.css.engine.value.ValueConstants;
 import org.apache.batik.css.engine.value.ValueManager;
+import org.apache.batik.css.engine.value.css2.BackgroundModeManager;
 import org.apache.batik.css.engine.value.css2.ClipManager;
 import org.apache.batik.css.engine.value.css2.CursorManager;
 import org.apache.batik.css.engine.value.css2.DirectionManager;
@@ -62,6 +63,7 @@ import org.apache.batik.css.engine.value
 import org.apache.batik.css.engine.value.svg.PointerEventsManager;
 import org.apache.batik.css.engine.value.svg.SVGColorManager;
 import org.apache.batik.css.engine.value.svg.SVGPaintManager;
+import org.apache.batik.css.engine.value.svg.SVGValueConstants;
 import org.apache.batik.css.engine.value.svg.ShapeRenderingManager;
 import org.apache.batik.css.engine.value.svg.SpacingManager;
 import org.apache.batik.css.engine.value.svg.StrokeDasharrayManager;
@@ -193,6 +195,8 @@ public class SVGCSSEngine extends CSSEng
      */
     public static final ValueManager[] SVG_VALUE_MANAGERS = {
         new AlignmentBaselineManager(),
+        new SVGColorManager(CSSConstants.CSS_BACKGROUND_PROPERTY, ValueConstants.TRANSPARENT_VALUE),
+        new BackgroundModeManager(),
         new BaselineShiftManager(),
         new ClipManager(),
         new ClipPathManager(),
@@ -279,8 +283,10 @@ public class SVGCSSEngine extends CSSEng
     // The property indexes.
     //
     public static final int ALIGNMENT_BASELINE_INDEX = 0;
+    public static final int BACKGROUND_INDEX = ALIGNMENT_BASELINE_INDEX + 1;
+    public static final int BACKGROUND_MODE_INDEX = BACKGROUND_INDEX + 1;
     public static final int BASELINE_SHIFT_INDEX =
-        ALIGNMENT_BASELINE_INDEX + 1;
+        BACKGROUND_MODE_INDEX + 1;
     public static final int CLIP_INDEX = BASELINE_SHIFT_INDEX + 1;
     public static final int CLIP_PATH_INDEX = CLIP_INDEX +1;
     public static final int CLIP_RULE_INDEX = CLIP_PATH_INDEX + 1;

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/AbstractColorManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/AbstractColorManager.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/AbstractColorManager.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/AbstractColorManager.java Mon Nov  3 04:14:53 2014
@@ -68,6 +68,8 @@ public abstract class AbstractColorManag
                    ValueConstants.SILVER_VALUE);
         values.put(CSSConstants.CSS_TEAL_VALUE,
                    ValueConstants.TEAL_VALUE);
+        values.put(CSSConstants.CSS_TRANSPARENT_VALUE,
+                   ValueConstants.TRANSPARENT_VALUE);
         values.put(CSSConstants.CSS_WHITE_VALUE,
                    ValueConstants.WHITE_VALUE);
         values.put(CSSConstants.CSS_YELLOW_VALUE,
@@ -166,6 +168,8 @@ public abstract class AbstractColorManag
                            ValueConstants.BLUE_RGB_VALUE);
         computedValues.put(CSSConstants.CSS_TEAL_VALUE,
                            ValueConstants.TEAL_RGB_VALUE);
+        computedValues.put(CSSConstants.CSS_TRANSPARENT_VALUE,
+                           ValueConstants.TRANSPARENT_RGB_VALUE);
         computedValues.put(CSSConstants.CSS_AQUA_VALUE,
                            ValueConstants.AQUA_RGB_VALUE);
     }

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/AbstractValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/AbstractValue.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/AbstractValue.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/AbstractValue.java Mon Nov  3 04:14:53 2014
@@ -79,6 +79,13 @@ public abstract class AbstractValue impl
     }
 
     /**
+     * Implements {@link Value#getAlpha()}.
+     */
+    public Value getAlpha() throws DOMException {
+        throw createDOMException();
+    }
+
+    /**
      * Implements {@link Value#getLength()}.
      */
     public int getLength() throws DOMException {

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/ComputedValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/ComputedValue.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/ComputedValue.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/ComputedValue.java Mon Nov  3 04:14:53 2014
@@ -124,6 +124,13 @@ public class ComputedValue implements Va
     }
 
     /**
+     * Implements {@link Value#getGreen()}.
+     */
+    public Value getAlpha() throws DOMException {
+        return computedValue.getAlpha();
+    }
+
+    /**
      * Implements {@link Value#getLength()}.
      */
     public int getLength() throws DOMException {

Added: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/RGBAColorValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/RGBAColorValue.java?rev=1636244&view=auto
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/RGBAColorValue.java (added)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/RGBAColorValue.java Mon Nov  3 04:14:53 2014
@@ -0,0 +1,62 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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 org.apache.batik.css.engine.value;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.css.CSSPrimitiveValue;
+
+/**
+ * This class represents RGBA colors.
+ *
+ * @author <a href="mailto:gadams@apache.org">Glenn Adams</a>
+ * @version $Id$
+ */
+public class RGBAColorValue extends RGBColorValue {
+
+    /**
+     * The alpha component.
+     */
+    protected Value alpha;
+
+    /**
+     * Creates a new RGBAColorValue.
+     */
+    public RGBAColorValue(Value r, Value g, Value b, Value a) {
+        super(r, g, b);
+        alpha = a;
+    }
+
+    /**
+     * A string representation of the current value.
+     */
+    public String getCssText() {
+        return "rgba(" +
+            red.getCssText() + ", " +
+            green.getCssText() + ", " +
+            blue.getCssText() + ", " +
+            alpha.getCssText() + ')';
+    }
+
+    /**
+     * Implements {@link Value#getAlpha()}.
+     */
+    public Value getAlpha() throws DOMException {
+        return alpha;
+    }
+}

Propchange: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/RGBAColorValue.java
------------------------------------------------------------------------------
    svn:eol-style = LF

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/Value.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/Value.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/Value.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/Value.java Mon Nov  3 04:14:53 2014
@@ -84,6 +84,14 @@ public interface Value {
     Value getBlue() throws DOMException;
 
     /**
+     * The alpha 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;
+
+    /**
      * The number of <code>CSSValues</code> in the list. The range of valid 
      * values of the indices is <code>0</code> to <code>length-1</code> 
      * inclusive.

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/ValueConstants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/ValueConstants.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/ValueConstants.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/ValueConstants.java Mon Nov  3 04:14:53 2014
@@ -772,6 +772,13 @@ public interface ValueConstants {
                         CSSConstants.CSS_TEAL_VALUE);
 
     /**
+     * The 'transparent' color name.
+     */
+    Value TRANSPARENT_VALUE =
+        new StringValue(CSSPrimitiveValue.CSS_IDENT,
+                        CSSConstants.CSS_TRANSPARENT_VALUE);
+
+    /**
      * The 'white' color name.
      */
     Value WHITE_VALUE =
@@ -1073,6 +1080,12 @@ public interface ValueConstants {
         new RGBColorValue(NUMBER_0, NUMBER_128, NUMBER_128);
 
     /**
+     * The 'transparent' RGB color.
+     */
+    Value TRANSPARENT_RGB_VALUE =
+        new RGBAColorValue(NUMBER_0, NUMBER_0, NUMBER_0, NUMBER_0);
+
+    /**
      * The 'aqua' RGB color.
      */
     Value AQUA_RGB_VALUE =

Added: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/css2/BackgroundModeManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/css2/BackgroundModeManager.java?rev=1636244&view=auto
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/css2/BackgroundModeManager.java (added)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/css2/BackgroundModeManager.java Mon Nov  3 04:14:53 2014
@@ -0,0 +1,97 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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 org.apache.batik.css.engine.value.css2;
+
+import org.apache.batik.css.engine.value.IdentifierManager;
+import org.apache.batik.css.engine.value.StringMap;
+import org.apache.batik.css.engine.value.Value;
+import org.apache.batik.css.engine.value.ValueManager;
+import org.apache.batik.css.engine.value.svg.SVGValueConstants;
+import org.apache.batik.util.CSSConstants;
+import org.apache.batik.util.SVGTypes;
+
+/**
+ * This class provides a manager for the 'background-mode' property values.
+ *
+ * @author <a href="mailto:gadams@apache.org">Glenn Adams</a>
+ * @version $Id$
+ */
+public class BackgroundModeManager extends IdentifierManager {
+
+    /**
+     * The identifier values.
+     */
+    protected static final StringMap values = new StringMap();
+    static {
+        values.put(CSSConstants.CSS_BBOX_VALUE, SVGValueConstants.BBOX_VALUE);
+        values.put(CSSConstants.CSS_LINE_HEIGHT_VALUE, SVGValueConstants.LINE_HEIGHT_VALUE);
+    }
+
+    /**
+     * Implements {@link
+     * org.apache.batik.css.engine.value.ValueManager#isInheritedProperty()}.
+     */
+    public boolean isInheritedProperty() {
+        return true;
+    }
+
+    /**
+     * Implements {@link ValueManager#isAnimatableProperty()}.
+     */
+    public boolean isAnimatableProperty() {
+        return false;
+    }
+
+    /**
+     * Implements {@link ValueManager#isAdditiveProperty()}.
+     */
+    public boolean isAdditiveProperty() {
+        return false;
+    }
+
+    /**
+     * Implements {@link ValueManager#getPropertyType()}.
+     */
+    public int getPropertyType() {
+        return SVGTypes.TYPE_IDENT;
+    }
+
+    /**
+     * Implements {@link
+     * org.apache.batik.css.engine.value.ValueManager#getPropertyName()}.
+     */
+    public String getPropertyName() {
+        return CSSConstants.CSS_BACKGROUND_MODE_PROPERTY;
+    }
+
+    /**
+     * Implements {@link
+     * org.apache.batik.css.engine.value.ValueManager#getDefaultValue()}.
+     */
+    public Value getDefaultValue() {
+        return SVGValueConstants.LINE_HEIGHT_VALUE;
+    }
+
+    /**
+     * Implements {@link IdentifierManager#getIdentifiers()}.
+     */
+    public StringMap getIdentifiers() {
+        return values;
+    }
+}

Propchange: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/css2/BackgroundModeManager.java
------------------------------------------------------------------------------
    svn:eol-style = LF

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/svg/ColorManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/svg/ColorManager.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/svg/ColorManager.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/svg/ColorManager.java Mon Nov  3 04:14:53 2014
@@ -342,6 +342,8 @@ public class ColorManager extends Abstra
                            SVGValueConstants.BLUE_RGB_VALUE);
         computedValues.put(CSSConstants.CSS_TEAL_VALUE,
                            SVGValueConstants.TEAL_RGB_VALUE);
+        computedValues.put(CSSConstants.CSS_TRANSPARENT_VALUE,
+                           SVGValueConstants.TRANSPARENT_RGB_VALUE);
         computedValues.put(CSSConstants.CSS_AQUA_VALUE,
                            SVGValueConstants.AQUA_RGB_VALUE);
 

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/svg/SVGValueConstants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/svg/SVGValueConstants.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/svg/SVGValueConstants.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/css/engine/value/svg/SVGValueConstants.java Mon Nov  3 04:14:53 2014
@@ -719,6 +719,13 @@ public interface SVGValueConstants exten
                         CSSConstants.CSS_BASELINE_VALUE);
     
     /**
+     * The 'bbox' keyword.
+     */
+    Value BBOX_VALUE =
+        new StringValue(CSSPrimitiveValue.CSS_IDENT,
+                        CSSConstants.CSS_BBOX_VALUE);
+    
+    /**
      * The 'before-edge' keyword.
      */
     Value BEFORE_EDGE_VALUE =
@@ -810,6 +817,13 @@ public interface SVGValueConstants exten
                         CSSConstants.CSS_LINEARRGB_VALUE);
     
     /**
+     * The 'line-height' keyword (used with background-mode property).
+     */
+    Value LINE_HEIGHT_VALUE =
+        new StringValue(CSSPrimitiveValue.CSS_IDENT,
+                        CSSConstants.CSS_LINE_HEIGHT_VALUE);
+    
+    /**
      * The 'lr' keyword.
      */
     Value LR_VALUE =

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/TextNode.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/TextNode.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/TextNode.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/TextNode.java Mon Nov  3 04:14:53 2014
@@ -27,6 +27,7 @@ import java.awt.geom.Rectangle2D;
 import java.text.AttributedCharacterIterator;
 import java.text.CharacterIterator;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.batik.gvt.renderer.StrokingTextPainter;
 import org.apache.batik.gvt.text.AttributedCharacterSpanIterator;
@@ -65,6 +66,11 @@ public class TextNode extends AbstractGr
     protected String text;
 
     /**
+     * Attibutes that apply to text node as a whole (not to individual text runs).
+     */
+    protected Map textAttributes;
+
+    /**
      * The begin mark.
      */
     protected Mark beginMark = null;
@@ -167,6 +173,13 @@ public class TextNode extends AbstractGr
     }
 
     /**
+     * Returns the top level text attributes of text node.
+     */
+    public Map getTextAttributes() {
+        return textAttributes;
+    }
+
+    /**
      * Sets the location of this text node.
      *
      * @param newLocation the new location of this text node
@@ -195,19 +208,25 @@ public class TextNode extends AbstractGr
         fireGraphicsNodeChangeCompleted();
     }
                                   
-
     /**
      * Sets the attributed character iterator of this text node.
      *
      * @param newAci the new attributed character iterator
+     * @param textAttributes top-level text node attributes map
      */
     public void setAttributedCharacterIterator
         (AttributedCharacterIterator newAci) {
+        this.setAttributedCharacterIterator(newAci);
+    }
+
+    public void setAttributedCharacterIterator
+        (AttributedCharacterIterator newAci, Map textAttributes) {
         fireGraphicsNodeChangeStarted();
         invalidateGeometryCache();
         this.aci = newAci;
-        text = null;
-        textRuns = null;
+        this.text = null;
+        this.textAttributes = textAttributes;
+        this.textRuns = null;
         fireGraphicsNodeChangeCompleted();
     }
 
@@ -540,6 +559,11 @@ public class TextNode extends AbstractGr
             }
         }
     }
+
+    public enum BackgroundMode {
+        BBOX,
+        LINE_HEIGHT;
+    };
 }
 
 

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java Mon Nov  3 04:14:53 2014
@@ -19,6 +19,7 @@
 
 package org.apache.batik.gvt.renderer;
 
+import java.awt.Color;
 import java.awt.Graphics2D;
 import java.awt.Paint;
 import java.awt.RenderingHints;
@@ -36,15 +37,18 @@ import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.batik.gvt.TextNode;
+import org.apache.batik.gvt.TextNode.BackgroundMode;
 import org.apache.batik.gvt.TextPainter;
 import org.apache.batik.gvt.font.DefaultFontFamilyResolver;
 import org.apache.batik.gvt.font.FontFamilyResolver;
 import org.apache.batik.gvt.font.GVTFont;
 import org.apache.batik.gvt.font.GVTFontFamily;
 import org.apache.batik.gvt.font.GVTGlyphMetrics;
+import org.apache.batik.gvt.font.GVTGlyphVector;
 import org.apache.batik.gvt.font.GVTLineMetrics;
 import org.apache.batik.gvt.text.AttributedCharacterSpanIterator;
 import org.apache.batik.gvt.text.BidiAttributedCharacterIterator;
@@ -166,13 +170,17 @@ public class StrokingTextPainter extends
 
         List textRuns = getTextRuns(node, aci);
 
-        // draw the underline and overline first, then the actual text
-        // and finally the strikethrough
+        // 1. draw text node background
+        paintBackground(node, textRuns, g2d);
+        // 2. draw text run backgrounds
+        paintBackgrounds(textRuns, g2d);
+        // 3. draw text run underline and overline
         paintDecorations(textRuns, g2d, TextSpanLayout.DECORATION_UNDERLINE);
         paintDecorations(textRuns, g2d, TextSpanLayout.DECORATION_OVERLINE);
+        // 4. draw text run glyphs
         paintTextRuns(textRuns, g2d);
-        paintDecorations
-            (textRuns, g2d, TextSpanLayout.DECORATION_STRIKETHROUGH);
+        // 5. draw text run strike through
+        paintDecorations(textRuns, g2d, TextSpanLayout.DECORATION_STRIKETHROUGH);
     }
 
     protected void printAttrs(AttributedCharacterIterator aci) {
@@ -860,6 +868,103 @@ public class StrokingTextPainter extends
     }
 
     /**
+     * Paint text node background.
+     */
+    protected void paintBackground(TextNode node, List textRuns, Graphics2D g2d) {
+        Map textAttributes = node.getTextAttributes();
+        TextPaintInfo tpi = (textAttributes != null) ? (TextPaintInfo) textAttributes.get(PAINT_INFO) : null;
+        if (tpi != null) {
+            if (tpi.visible) {
+                Paint paint = tpi.backgroundPaint;
+                BackgroundMode mode = tpi.backgroundMode;
+                if (paint != null) {
+                    if ((paint instanceof Color) && (((Color)paint).getAlpha() != 0)) {
+                        Rectangle2D bounds = computeBackgroundBounds(node, textRuns, mode);
+                        if (!bounds.isEmpty()) {
+                            g2d.setPaint(paint);
+                            g2d.fill(bounds);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    private Rectangle2D computeBackgroundBounds(TextNode node, List textRuns, BackgroundMode mode) {
+        if (mode == BackgroundMode.BBOX) {
+            return node.getPrimitiveBounds();
+        } else if (mode == BackgroundMode.LINE_HEIGHT) {
+            TextRun run = (TextRun) textRuns.get(0);
+            TextSpanLayout layout = run.getLayout();
+            GVTLineMetrics lineMetrics = layout.getLineMetrics();
+            double ascent = lineMetrics.getAscent();
+            double descent = lineMetrics.getDescent();
+            double emHeight = ascent + descent;
+            GVTGlyphVector gv = layout.getGlyphVector();
+            Point2D firstPosition = gv.getGlyphPosition(0);
+            Map textAttributes = node.getTextAttributes();
+            double fontSize = (textAttributes != null) ? ((Float) textAttributes.get(TextAttribute.SIZE)).doubleValue() : 0d;
+            double lineHeight = fontSize * 1.25f;
+            return computeLineHeightBounds(firstPosition, ascent, emHeight, lineHeight, node.getPrimitiveBounds().getWidth());
+        } else {
+            return new Rectangle2D.Double();
+        }
+    }
+
+    /**
+     * Paint text run backgrounds.
+     */
+    protected void paintBackgrounds(List textRuns, Graphics2D g2d) {
+        for (int i = 0; i < textRuns.size(); i++) {
+            TextRun textRun = (TextRun)textRuns.get(i);
+            AttributedCharacterIterator runaci = textRun.getACI();
+            runaci.first();
+            TextPaintInfo tpi = (TextPaintInfo)runaci.getAttribute(PAINT_INFO);
+            if (tpi != null) {
+                if (tpi.visible) {
+                    Paint paint = tpi.backgroundPaint;
+                    BackgroundMode mode = tpi.backgroundMode;
+                    if (paint != null) {
+                        if ((paint instanceof Color) && (((Color)paint).getAlpha() != 0)) {
+                            Rectangle2D bounds = computeBackgroundBounds(textRun, mode);
+                            if (!bounds.isEmpty()) {
+                                g2d.setPaint(paint);
+                                g2d.fill(bounds);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    private Rectangle2D computeBackgroundBounds(TextRun run, BackgroundMode mode) {
+        if (mode == BackgroundMode.BBOX) {
+            return run.getLayout().getBounds2D();
+        } else if (mode == BackgroundMode.LINE_HEIGHT) {
+            TextSpanLayout layout = run.getLayout();
+            GVTLineMetrics lineMetrics = layout.getLineMetrics();
+            double ascent = lineMetrics.getAscent();
+            double descent = lineMetrics.getDescent();
+            double emHeight = ascent + descent;
+            GVTGlyphVector gv = layout.getGlyphVector();
+            Rectangle2D bbox = layout.getBounds2D();
+            Point2D firstPosition = new Point2D.Double(bbox.getX(), gv.getGlyphPosition(0).getY());
+            AttributedCharacterIterator aci = run.getACI();
+            double fontSize = (aci != null) ? ((Float) aci.getAttribute(TextAttribute.SIZE)).doubleValue() : 0d;
+            double lineHeight = fontSize * 1.25f;
+            return computeLineHeightBounds(firstPosition, ascent, emHeight, lineHeight, bbox.getWidth());
+        } else {
+            return new Rectangle2D.Double();
+        }
+    }
+
+    private Rectangle2D computeLineHeightBounds(Point2D position, double ascent, double emHeight, double lineHeight, double width) {
+            double y = position.getY() - (ascent / emHeight) * lineHeight;
+            return new Rectangle2D.Double(position.getX(), y, width, lineHeight);
+    }
+
+    /**
      * Paints decorations of the specified type.
      */
     protected void paintDecorations(List textRuns,

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/text/GVTAttributedCharacterIterator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/text/GVTAttributedCharacterIterator.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/text/GVTAttributedCharacterIterator.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/text/GVTAttributedCharacterIterator.java Mon Nov  3 04:14:53 2014
@@ -325,7 +325,7 @@ public interface GVTAttributedCharacterI
                                           new TextAttribute("HORIZONTAL_ORIENTATION_ANGLE");
 
         public static final TextAttribute GVT_FONT_FAMILIES =
-                       new TextAttribute("GVT_FONT_FAMILIES");
+                                          new TextAttribute("GVT_FONT_FAMILIES");
 
         public static final TextAttribute GVT_FONTS =
                                           new TextAttribute("GVT_FONTS");
@@ -351,6 +351,9 @@ public interface GVTAttributedCharacterI
         public static final TextAttribute LANGUAGE =
                                           new TextAttribute("LANGUAGE");
 
+        public static final TextAttribute BACKGROUND_MODE =
+                                          new TextAttribute("BACKGROUND_MODE");
+
         // VALUES
 
         /** Value for WRITING_MODE indicating left-to-right */

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/text/TextPaintInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/text/TextPaintInfo.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/text/TextPaintInfo.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/gvt/text/TextPaintInfo.java Mon Nov  3 04:14:53 2014
@@ -22,6 +22,8 @@ import java.awt.Composite;
 import java.awt.Paint;
 import java.awt.Stroke;
 
+import org.apache.batik.gvt.TextNode.BackgroundMode;
+
 /**
  * One line Class Desc
  *
@@ -32,6 +34,8 @@ import java.awt.Stroke;
  */
 public class TextPaintInfo {
     public boolean   visible;
+    public Paint     backgroundPaint;
+    public BackgroundMode backgroundMode;
     public Paint     fillPaint;
     public Paint     strokePaint;
     public Stroke    strokeStroke;
@@ -59,6 +63,8 @@ public class TextPaintInfo {
 
     public void set(TextPaintInfo pi) {
         if (pi == null) {
+            this.backgroundPaint = null;
+            this.backgroundMode = null;
             this.fillPaint    = null;
             this.strokePaint  = null;
             this.strokeStroke = null;
@@ -78,6 +84,8 @@ public class TextPaintInfo {
 
             this.visible = false;
         } else {
+            this.backgroundPaint = pi.backgroundPaint;
+            this.backgroundMode = pi.backgroundMode;
             this.fillPaint    = pi.fillPaint;
             this.strokePaint  = pi.strokePaint;
             this.strokeStroke = pi.strokeStroke;
@@ -105,6 +113,12 @@ public class TextPaintInfo {
             return false;
         } else if (tpi2 == null) return false;
 
+        if ((tpi1.backgroundPaint == null) != (tpi2.backgroundPaint == null))
+            return false;
+
+        if ((tpi1.backgroundMode == null) != (tpi2.backgroundMode == null))
+            return false;
+
         if ((tpi1.fillPaint == null) != (tpi2.fillPaint == null))
             return false;
 

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/svggen/SVGStylingAttributes.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/svggen/SVGStylingAttributes.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/svggen/SVGStylingAttributes.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/svggen/SVGStylingAttributes.java Mon Nov  3 04:14:53 2014
@@ -32,6 +32,7 @@ public class SVGStylingAttributes implem
     static Set attrSet = new HashSet();
 
     static {
+        attrSet.add(SVG_BACKGROUND_ATTRIBUTE);
         attrSet.add(SVG_CLIP_PATH_ATTRIBUTE);
         attrSet.add(SVG_COLOR_INTERPOLATION_ATTRIBUTE);
         attrSet.add(SVG_COLOR_RENDERING_ATTRIBUTE);

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/util/CSSConstants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/util/CSSConstants.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/util/CSSConstants.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/util/CSSConstants.java Mon Nov  3 04:14:53 2014
@@ -36,6 +36,8 @@ public interface CSSConstants {
     // The CSS property names.
     //
     String CSS_ALIGNMENT_BASELINE_PROPERTY = "alignment-baseline";
+    String CSS_BACKGROUND_PROPERTY = "background";
+    String CSS_BACKGROUND_MODE_PROPERTY = "background-mode";
     String CSS_BASELINE_SHIFT_PROPERTY = "baseline-shift";
     String CSS_CLIP_PROPERTY = "clip";
     String CSS_CLIP_PATH_PROPERTY = "clip-path";
@@ -118,6 +120,7 @@ public interface CSSConstants {
     String CSS_AZURE_VALUE = "azure";
     String CSS_BACKGROUND_VALUE = "background";
     String CSS_BASELINE_VALUE = "baseline";
+    String CSS_BBOX_VALUE = "bbox";
     String CSS_BEFORE_EDGE_VALUE = "before-edge";
     String CSS_BEIGE_VALUE = "beige";
     String CSS_BEVEL_VALUE = "bevel";
@@ -252,6 +255,7 @@ public interface CSSConstants {
     String CSS_LIGHTYELLOW_VALUE = "lightyellow";
     String CSS_LIMEGREEN_VALUE = "limegreen";
     String CSS_LIME_VALUE = "lime";
+    String CSS_LINE_HEIGHT_VALUE = "line-height";
     String CSS_LINEARRGB_VALUE = "linearrgb";
     String CSS_LINEN_VALUE = "linen";
     String CSS_LINE_THROUGH_VALUE = "line-through";
@@ -377,6 +381,7 @@ public interface CSSConstants {
     String CSS_TB_RL_VALUE = "tb-rl";
     String CSS_TB_VALUE = "tb";
     String CSS_TEAL_VALUE = "teal";
+    String CSS_TRANSPARENT_VALUE = "transparent";
     String CSS_TEXT_AFTER_EDGE_VALUE = "text-after-edge";
     String CSS_TEXT_BEFORE_EDGE_VALUE = "text-before-edge";
     String CSS_TEXT_BOTTOM_VALUE = "text-bottom";

Modified: xmlgraphics/batik/branches/text-background/sources/org/apache/batik/util/SVGConstants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/sources/org/apache/batik/util/SVGConstants.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/sources/org/apache/batik/util/SVGConstants.java (original)
+++ xmlgraphics/batik/branches/text-background/sources/org/apache/batik/util/SVGConstants.java Mon Nov  3 04:14:53 2014
@@ -440,6 +440,8 @@ public interface SVGConstants extends CS
     String SVG_ALPHABETIC_ATTRIBUTE = "alphabetic";
     String SVG_ATTRIBUTE_NAME_ATTRIBUTE = "attributeName";
     String SVG_ATTRIBUTE_TYPE_ATTRIBUTE = "attributeType";
+    String SVG_BACKGROUND_ATTRIBUTE = CSS_BACKGROUND_PROPERTY;
+    String SVG_BACKGROUND_MODE_ATTRIBUTE = CSS_BACKGROUND_MODE_PROPERTY;
     String SVG_BASE_FREQUENCY_ATTRIBUTE = "baseFrequency";
     String SVG_BASE_PROFILE_ATTRIBUTE = "baseProfile";
     String SVG_BEGIN_ATTRIBUTE = "begin";

Modified: xmlgraphics/batik/branches/text-background/test-resources/org/apache/batik/css/engine/value/unitTesting.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/test-resources/org/apache/batik/css/engine/value/unitTesting.xml?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/test-resources/org/apache/batik/css/engine/value/unitTesting.xml (original)
+++ xmlgraphics/batik/branches/text-background/test-resources/org/apache/batik/css/engine/value/unitTesting.xml Mon Nov  3 04:14:53 2014
@@ -37,6 +37,14 @@
 </test>
 
 <!-- ############################################################################## -->
+<test id="css.engine.value.svg.background">
+  <arg class="java.lang.String" value="org.apache.batik.css.engine.value.PropertyManagerTest$BackgroundManager" />
+  <arg class="java.lang.Boolean" value="true" />
+  <arg class="java.lang.String" value="rgb(0, 0, 0)" />
+  <arg class="java.lang.String" value="" />
+</test>
+
+<!-- ############################################################################## -->
 <test id="css.engine.value.svg.baseline-shift">
   <arg class="java.lang.String" value="org.apache.batik.css.engine.value.svg.BaselineShiftManager" />
   <arg class="java.lang.Boolean" value="false" />

Modified: xmlgraphics/batik/branches/text-background/test-sources/org/apache/batik/css/engine/value/PropertyManagerTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/text-background/test-sources/org/apache/batik/css/engine/value/PropertyManagerTest.java?rev=1636244&r1=1636243&r2=1636244&view=diff
==============================================================================
--- xmlgraphics/batik/branches/text-background/test-sources/org/apache/batik/css/engine/value/PropertyManagerTest.java (original)
+++ xmlgraphics/batik/branches/text-background/test-sources/org/apache/batik/css/engine/value/PropertyManagerTest.java Mon Nov  3 04:14:53 2014
@@ -199,6 +199,15 @@ public class PropertyManagerTest extends
     }
 
     /**
+     * Manager for 'background'.
+     */
+    public static class BackgroundManager extends SVGPaintManager {
+        public BackgroundManager() {
+            super(CSSConstants.CSS_BACKGROUND_PROPERTY);
+        }
+    }
+
+    /**
      * Manager for 'fill'.
      */
     public static class FillManager extends SVGPaintManager {