aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2009-01-11 11:22:41 +0000
committerJeremias Maerki <jeremias@apache.org>2009-01-11 11:22:41 +0000
commite381d274f38598752ecc04a82085eea2962d5d4d (patch)
tree6eb4dec04783f4b0048b942a8afed7da5ba59598
parent55329301ca663f8a68d4c2b732210862e55b55b1 (diff)
downloadxmlgraphics-fop-e381d274f38598752ecc04a82085eea2962d5d4d.tar.gz
xmlgraphics-fop-e381d274f38598752ecc04a82085eea2962d5d4d.zip
Added shortcut that avoids painting text using the native text handler if the Graphics2D passed in is not compatible (as with SVG filter operations).
Avoid NPE when font size returns null. Do anchor evaluation before the getText() method as it returns null afterwards when the ACI's state has changed. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@733453 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/svg/AbstractFOPTextPainter.java31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/java/org/apache/fop/svg/AbstractFOPTextPainter.java b/src/java/org/apache/fop/svg/AbstractFOPTextPainter.java
index 560c76cb5..6520abd5d 100644
--- a/src/java/org/apache/fop/svg/AbstractFOPTextPainter.java
+++ b/src/java/org/apache/fop/svg/AbstractFOPTextPainter.java
@@ -43,6 +43,7 @@ import org.apache.batik.gvt.text.Mark;
import org.apache.batik.gvt.text.TextPaintInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.fop.afp.AFPGraphics2D;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
@@ -88,16 +89,29 @@ public abstract class AbstractFOPTextPainter implements TextPainter {
*/
public void paint(TextNode node, Graphics2D g2d) {
Point2D loc = node.getLocation();
- log.debug("painting text node " + node);
- if (hasUnsupportedAttributes(node)) {
- log.debug("hasUnsuportedAttributes");
+ if (!isSupportedGraphics2D(g2d) || hasUnsupportedAttributes(node)) {
+ if (log.isDebugEnabled()) {
+ log.debug("painting text node " + node
+ + " by stroking due to unsupported attributes or an incompatible Graphics2D");
+ }
PROXY_PAINTER.paint(node, g2d);
} else {
- log.debug("allAttributesSupported");
+ if (log.isDebugEnabled()) {
+ log.debug("painting text node " + node + " normally.");
+ }
paintTextRuns(node.getTextRuns(), g2d, loc);
}
}
+ /**
+ * Checks whether the Graphics2D is compatible with this text painter. Batik may
+ * pass in a Graphics2D instance that paints on a special buffer image, for example
+ * for filtering operations. In that case, the text painter should be bypassed.
+ * @param g2d the Graphics2D instance to check
+ * @return true if the Graphics2D is supported
+ */
+ protected abstract boolean isSupportedGraphics2D(Graphics2D g2d);
+
private boolean hasUnsupportedAttributes(TextNode node) {
Iterator iter = node.getTextRuns().iterator();
while (iter.hasNext()) {
@@ -246,12 +260,14 @@ public abstract class AbstractFOPTextPainter implements TextPainter {
}
g2d.setPaint(foreground);
+ // text anchor
+ TextNode.Anchor anchor = (TextNode.Anchor)aci.getAttribute(
+ GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE);
+
// text
String txt = getText(aci);
float advance = getStringWidth(txt, font);
float tx = 0;
- TextNode.Anchor anchor = (TextNode.Anchor)aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE);
if (anchor != null) {
switch (anchor.getType()) {
case TextNode.Anchor.ANCHOR_MIDDLE:
@@ -337,6 +353,9 @@ public abstract class AbstractFOPTextPainter implements TextPainter {
private Font getFont(AttributedCharacterIterator aci) {
Float fontSize = (Float)aci.getAttribute(TextAttribute.SIZE);
+ if (fontSize == null) {
+ fontSize = new Float(10f);
+ }
String style = getStyle(aci);
int weight = getWeight(aci);