Browse Source

updated use of batik to changed api

from cvs batik 23/9/2001
improved the user agent


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194478 13f79535-47bb-0310-9956-ffa450edef68
pull/33/head
Keiron Liddle 23 years ago
parent
commit
98ff1923e1

BIN
lib/batik.jar View File


+ 149
- 10
src/org/apache/fop/image/analyser/SVGReader.java View File

@@ -23,12 +23,36 @@ import org.xml.sax.XMLReader;

import org.apache.batik.dom.svg.SAXSVGDocumentFactory;

import org.apache.batik.dom.svg.*;
import org.w3c.dom.*;
import org.w3c.dom.svg.*;
import org.w3c.dom.svg.SVGLength;
import org.apache.batik.bridge.*;
import org.apache.batik.swing.svg.*;
import org.apache.batik.swing.gvt.*;
import org.apache.batik.gvt.*;
import org.apache.batik.gvt.renderer.*;
import org.apache.batik.gvt.filter.*;
import org.apache.batik.gvt.event.*;

import org.w3c.dom.DOMImplementation;
import org.apache.batik.dom.svg.SVGDOMImplementation;

import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.ArrayList;
import java.awt.geom.AffineTransform;
import java.awt.Point;
import java.awt.geom.Dimension2D;
import java.awt.Dimension;

/**
* ImageReader object for SVG document image type.
*/
public class SVGReader extends AbstractImageReader {
public boolean verifySignature(String uri, BufferedInputStream fis)
throws IOException {
public boolean verifySignature(String uri,
BufferedInputStream fis) throws IOException {
this.imageStream = fis;
return loadImage(uri);
}
@@ -45,24 +69,139 @@ public class SVGReader extends AbstractImageReader {
// parse document and get the size attributes of the svg element
try {
SAXSVGDocumentFactory factory =
new SAXSVGDocumentFactory(SVGImage.getParserName());
new SAXSVGDocumentFactory(SVGImage.getParserName());
SVGDocument doc = factory.createDocument(uri, imageStream);
// should check the stream contains text data
SVGSVGElement svg = doc.getRootElement();
this.width = (int)svg.getWidth().getBaseVal().getValue();
this.height = (int)svg.getHeight().getBaseVal().getValue();

// this is ugly preprocessing to get the width and height
UserAgent userAgent = new MUserAgent(new AffineTransform());
GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(userAgent);
GraphicsNode root;
root = builder.build(ctx, doc);
// get the 'width' and 'height' attributes of the SVG document
width = (int) ctx.getDocumentSize().getWidth();
height = (int) ctx.getDocumentSize().getHeight();
ctx = null;
builder = null;
///////

return true;
} catch (NoClassDefFoundError ncdfe) {
MessageHandler.errorln("Batik not in class path");
return false;
} catch (Exception e) {
MessageHandler.errorln("Could not load external SVG: "
+ e.getMessage());
}
catch (Exception e) {
MessageHandler.errorln("Could not load external SVG: " +
e.getMessage());
// assuming any exception means this document is not svg
// or could not be loaded for some reason
return false;
}
}

protected class MUserAgent implements UserAgent {
AffineTransform currentTransform = null;

/**
* Creates a new SVGUserAgent.
*/
protected MUserAgent(AffineTransform at) {
currentTransform = at;
}

/**
* Displays an error message.
*/
public void displayError(String message) {
System.err.println(message);
}

/**
* Displays an error resulting from the specified Exception.
*/
public void displayError(Exception ex) {
ex.printStackTrace(System.err);
}

/**
* Displays a message in the User Agent interface.
* The given message is typically displayed in a status bar.
*/
public void displayMessage(String message) {
System.out.println(message);
}

/**
* Returns a customized the pixel to mm factor.
*/
public float getPixelToMM() {
// this is set to 72dpi as the values in fo are 72dpi
return 0.35277777777777777778f; // 72 dpi
// return 0.26458333333333333333333333333333f; // 96dpi
}

/**
* Returns the language settings.
*/
public String getLanguages() {
return "en"; // userLanguages;
}

/**
* Returns the user stylesheet uri.
* @return null if no user style sheet was specified.
*/
public String getUserStyleSheetURI() {
return null; // userStyleSheetURI;
}

/**
* Returns the class name of the XML parser.
*/
public String getXMLParserClassName() {
return org.apache.fop.apps.Driver.getParserClassName();
}

/**
* Opens a link in a new component.
* @param doc The current document.
* @param uri The document URI.
*/
public void openLink(SVGAElement elt) {
}

public Point getClientAreaLocationOnScreen() {
return new Point(0, 0);
}

public void setSVGCursor(java.awt.Cursor cursor) {}


public AffineTransform getTransform() {
return currentTransform;
}

public Dimension2D getViewportSize() {
return new Dimension(100, 100);
}

public EventDispatcher getEventDispatcher() {
return null;
}

public boolean supportExtension(String str) {
return false;
}

public boolean hasFeature(String str) {
return false;
}

public void registerExtension(BridgeExtension be) {}

public void handleElement(Element elt, Object data) {}

}

}


+ 6
- 107
src/org/apache/fop/render/awt/AWTRenderer.java View File

@@ -693,21 +693,20 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
}

protected void renderSVGDocument(Document doc, int x, int y) {
UserAgent userAgent = new MUserAgent(new AffineTransform());
MUserAgent userAgent = new MUserAgent(new AffineTransform());
userAgent.setLogger(log);

GVTBuilder builder = new GVTBuilder();
GraphicsNodeRenderContext rc = getRenderContext();
BridgeContext ctx = new BridgeContext(userAgent, rc);
BridgeContext ctx = new BridgeContext(userAgent);
GraphicsNode root;

// correct integer roundoff aml/rlc
// graphics.translate(x / 1000f, pageHeight - y / 1000f);
graphics.translate((x + 500) / 1000, pageHeight - (y + 500) / 1000);

graphics.setRenderingHints(rc.getRenderingHints());
try {
root = builder.build(ctx, doc);
root.paint(graphics, rc);
root.paint(graphics);
} catch (Exception e) {
e.printStackTrace();
}
@@ -718,39 +717,10 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable

}

public GraphicsNodeRenderContext getRenderContext() {
GraphicsNodeRenderContext nodeRenderContext = null;
if (nodeRenderContext == null) {
RenderingHints hints = new RenderingHints(null);
hints.put(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);

hints.put(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);

FontRenderContext fontRenderContext =
new FontRenderContext(new AffineTransform(), true, true);

TextPainter textPainter = new StrokingTextPainter();

GraphicsNodeRableFactory gnrFactory =
new ConcreteGraphicsNodeRableFactory();

nodeRenderContext =
new GraphicsNodeRenderContext(new AffineTransform(), null,
hints, fontRenderContext,
textPainter, gnrFactory);
}

return nodeRenderContext;
}


public void setProducer(String producer) {
// defined in Renderer Interface
}


public int print(Graphics g, PageFormat pageFormat,
int pageIndex) throws PrinterException {
if (pageIndex >= pageList.size())
@@ -860,67 +830,13 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
}


protected class MUserAgent implements UserAgent {
AffineTransform currentTransform = null;
protected class MUserAgent extends org.apache.fop.svg.SVGUserAgent {

/**
* Creates a new SVGUserAgent.
*/
protected MUserAgent(AffineTransform at) {
currentTransform = at;
}

/**
* Displays an error message.
*/
public void displayError(String message) {
System.err.println(message);
}

/**
* Displays an error resulting from the specified Exception.
*/
public void displayError(Exception ex) {
ex.printStackTrace(System.err);
}

/**
* Displays a message in the User Agent interface.
* The given message is typically displayed in a status bar.
*/
public void displayMessage(String message) {
System.out.println(message);
}

/**
* Returns a customized the pixel to mm factor.
*/
public float getPixelToMM() {
// this is set to 72dpi as the values in fo are 72dpi
return 0.35277777777777777778f; // 72 dpi
// return 0.26458333333333333333333333333333f; // 96dpi
}

/**
* Returns the language settings.
*/
public String getLanguages() {
return "en"; // userLanguages;
}

/**
* Returns the user stylesheet uri.
* @return null if no user style sheet was specified.
*/
public String getUserStyleSheetURI() {
return null; // userStyleSheetURI;
}

/**
* Returns the class name of the XML parser.
*/
public String getXMLParserClassName() {
return Driver.getParserClassName();
super(at);
}

/**
@@ -940,10 +856,6 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
public void setSVGCursor(java.awt.Cursor cursor) {}


public AffineTransform getTransform() {
return currentTransform;
}

public Dimension2D getViewportSize() {
return new Dimension(100, 100);
}
@@ -951,19 +863,6 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
public EventDispatcher getEventDispatcher() {
return null;
}

public boolean supportExtension(String str) {
return false;
}

public boolean hasFeature(String str) {
return false;
}

public void registerExtension(BridgeExtension be) {}

public void handleElement(Element elt, Object data) {}

}

public void startRenderer(OutputStream outputStream)

+ 32
- 157
src/org/apache/fop/render/pdf/PDFRenderer.java View File

@@ -46,7 +46,6 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.Dimension;

/**
@@ -385,13 +384,38 @@ public class PDFRenderer extends PrintRenderer {

protected void renderSVGDocument(Document doc, int x, int y,
FontState fs) {
SVGSVGElement svg = ((SVGDocument)doc).getRootElement();
int w = (int)(svg.getWidth().getBaseVal().getValue() * 1000);
int h = (int)(svg.getHeight().getBaseVal().getValue() * 1000);

float sx = 1, sy = -1;
int xOffset = x, yOffset = y;

org.apache.fop.svg.SVGUserAgent userAgent
= new org.apache.fop.svg.SVGUserAgent(new AffineTransform());
userAgent.setLogger(log);

GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(userAgent);
TextPainter textPainter = null;
Boolean bl =
org.apache.fop.configuration.Configuration.getBooleanValue("strokeSVGText");
if (bl == null || bl.booleanValue()) {
textPainter = new StrokingTextPainter();
} else {
textPainter = new PDFTextPainter(fs);
}
ctx.setTextPainter(textPainter);

PDFAElementBridge aBridge = new PDFAElementBridge();
aBridge.setCurrentTransform(new AffineTransform(sx, 0, 0, sy, xOffset / 1000f, yOffset / 1000f));
ctx.putBridge(aBridge);


GraphicsNode root;
root = builder.build(ctx, doc);
// get the 'width' and 'height' attributes of the SVG document
float w = (float)ctx.getDocumentSize().getWidth() * 1000f;
float h = (float)ctx.getDocumentSize().getHeight() * 1000f;
ctx = null;
builder = null;

/*
* Clip to the svg area.
* Note: To have the svg overlay (under) a text area then use
@@ -414,6 +438,7 @@ public class PDFRenderer extends PrintRenderer {
currentStream.add(sx + " 0 0 " + sy + " " + xOffset / 1000f + " "
+ yOffset / 1000f + " cm\n");

SVGSVGElement svg = ((SVGDocument)doc).getRootElement();
AffineTransform at = ViewBox.getPreserveAspectRatioTransform(svg, w / 1000f, h / 1000f);
if(!at.isIdentity()) {
double[] vals = new double[6];
@@ -426,25 +451,15 @@ public class PDFRenderer extends PrintRenderer {
+ PDFNumber.doubleOut(vals[5]) + " cm\n");
}

UserAgent userAgent = new MUserAgent(new AffineTransform());

GVTBuilder builder = new GVTBuilder();
GraphicsNodeRenderContext rc = getRenderContext(fs);
BridgeContext ctx = new BridgeContext(userAgent, rc);
PDFAElementBridge aBridge = new PDFAElementBridge();
ctx.putBridge(aBridge);
GraphicsNode root;
PDFGraphics2D graphics = new PDFGraphics2D(true, fs, pdfDoc,
currentFontName,
currentFontSize,
currentXPosition,
currentYPosition);
graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
graphics.setRenderingHints(rc.getRenderingHints());
aBridge.setCurrentTransform(new AffineTransform(sx, 0, 0, sy, xOffset / 1000f, yOffset / 1000f));

try {
root = builder.build(ctx, doc);
root.paint(graphics, rc);
root.paint(graphics);
currentStream.add(graphics.getString());
} catch (Exception e) {
log.error("svg graphic could not be rendered: "
@@ -456,40 +471,6 @@ public class PDFRenderer extends PrintRenderer {
currentStream.add("Q\n");
}

public GraphicsNodeRenderContext getRenderContext(FontState fs) {
GraphicsNodeRenderContext nodeRenderContext = null;
if (nodeRenderContext == null) {
RenderingHints hints = new RenderingHints(null);
hints.put(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);

hints.put(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);

FontRenderContext fontRenderContext =
new FontRenderContext(new AffineTransform(), true, true);

TextPainter textPainter = null;
Boolean bl =
org.apache.fop.configuration.Configuration.getBooleanValue("strokeSVGText");
if (bl == null || bl.booleanValue()) {
textPainter = new StrokingTextPainter();
} else {
textPainter = new PDFTextPainter(fs);
}
GraphicsNodeRableFactory gnrFactory =
new ConcreteGraphicsNodeRableFactory();

nodeRenderContext =
new GraphicsNodeRenderContext(new AffineTransform(), null,
hints, fontRenderContext,
textPainter, gnrFactory);
nodeRenderContext.setTextPainter(textPainter);
}

return nodeRenderContext;
}

/**
* render inline area to PDF
*
@@ -867,110 +848,4 @@ public class PDFRenderer extends PrintRenderer {
}
}

protected class MUserAgent implements UserAgent {
AffineTransform currentTransform = null;

/**
* Creates a new SVGUserAgent.
*/
protected MUserAgent(AffineTransform at) {
currentTransform = at;
}

/**
* Displays an error message.
*/
public void displayError(String message) {
System.err.println(message);
}

/**
* Displays an error resulting from the specified Exception.
*/
public void displayError(Exception ex) {
ex.printStackTrace(System.err);
}

/**
* Displays a message in the User Agent interface.
* The given message is typically displayed in a status bar.
*/
public void displayMessage(String message) {
System.out.println(message);
}

/**
* Returns a customized the pixel to mm factor.
*/
public float getPixelToMM() {
// this is set to 72dpi as the values in fo are 72dpi
return 0.35277777777777777778f; // 72 dpi
// return 0.26458333333333333333333333333333f; // 96dpi
}

/**
* Returns the language settings.
*/
public String getLanguages() {
return "en"; // userLanguages;
}

/**
* Returns the user stylesheet uri.
* @return null if no user style sheet was specified.
*/
public String getUserStyleSheetURI() {
return null; // userStyleSheetURI;
}

/**
* Returns the class name of the XML parser.
*/
public String getXMLParserClassName() {
return org.apache.fop.apps.Driver.getParserClassName();
}

/**
* Opens a link in a new component.
* @param doc The current document.
* @param uri The document URI.
*/
public void openLink(SVGAElement elt) {
// application.openLink(uri);
}


public Point getClientAreaLocationOnScreen() {
return new Point(0, 0);
}

public void setSVGCursor(java.awt.Cursor cursor) {}


public AffineTransform getTransform() {
return currentTransform;
}

public Dimension2D getViewportSize() {
return new Dimension(100, 100);
}

public EventDispatcher getEventDispatcher() {
return null;
}

public boolean supportExtension(String str) {
return false;
}

public boolean hasFeature(String str) {
return false;
}

public void registerExtension(BridgeExtension be) {}

public void handleElement(Element elt, Object data) {}


}
}

+ 20
- 161
src/org/apache/fop/render/ps/PSRenderer.java View File

@@ -49,7 +49,6 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.Dimension;

/**
@@ -295,25 +294,31 @@ public class PSRenderer extends AbstractRenderer {
int x = this.currentXPosition;
int y = this.currentYPosition;
Document doc = area.getSVGDocument();
SVGSVGElement svg = ((SVGDocument)doc).getRootElement();
int w = (int)(svg.getWidth().getBaseVal().getValue() * 1000);
int h = (int)(svg.getHeight().getBaseVal().getValue() * 1000);

UserAgent userAgent = new org.apache.fop.svg.SVGUserAgent(new AffineTransform());

GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(userAgent);

GraphicsNode root;
root = builder.build(ctx, doc);
// get the 'width' and 'height' attributes of the SVG document
float w = (float)ctx.getDocumentSize().getWidth() * 1000f;
float h = (float)ctx.getDocumentSize().getHeight() * 1000f;
ctx = null;
builder = null;

float sx = 1, sy = -1;
int xOffset = x, yOffset = y;

/*
* Clip to the svg area.
* Note: To have the svg overlay (under) a text area then use
* an fo:block-container
*/
comment("% --- SVG Area");
write("gsave");
if (w != 0 && h != 0) {
write("newpath");
write(x / 1000f + " " + y / 1000f + " M");
write((x + w) / 1000f + " " + y / 1000f + " rlineto");
write((x + w) / 1000f + " " + (y - h) / 1000f + " rlineto");
write(x / 1000f + " " + (y - h) / 1000f + " rlineto");
write(x + " " + y + " M");
write((x + w) + " " + y + " rlineto");
write((x + w) + " " + (y - h) + " rlineto");
write(x + " " + (y - h) + " rlineto");
write("closepath");
write("clippath");
}
@@ -321,66 +326,27 @@ public class PSRenderer extends AbstractRenderer {
// and positive is down and to the right. (0,0) is where the
// viewBox puts it.
write(xOffset + " " + yOffset + " translate");
write(sx + " " + sy + " " + " scale");

write(sx + " " + sy + " scale");

UserAgent userAgent = new MUserAgent(new AffineTransform(), log);

GVTBuilder builder = new GVTBuilder();
GraphicsNodeRenderContext rc = getRenderContext();
BridgeContext ctx = new BridgeContext(userAgent, rc);
GraphicsNode root;
PSGraphics2D graphics = new PSGraphics2D(false, area.getFontState(),
this, currentFontName,
currentFontSize,
currentXPosition,
currentYPosition);
graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
graphics.setRenderingHints(rc.getRenderingHints());
try {
root = builder.build(ctx, doc);
root.paint(graphics, rc);
root.paint(graphics);
} catch (Exception e) {
log.error("svg graphic could not be rendered: "
+ e.getMessage(), e);
}


write("grestore");

comment("% --- SVG Area end");
movetoCurrPosition();
}

public GraphicsNodeRenderContext getRenderContext() {
GraphicsNodeRenderContext nodeRenderContext = null;
if (nodeRenderContext == null) {
RenderingHints hints = new RenderingHints(null);
hints.put(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);

hints.put(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);

FontRenderContext fontRenderContext =
new FontRenderContext(new AffineTransform(), true, true);

TextPainter textPainter = new StrokingTextPainter();
// TextPainter textPainter = new PDFTextPainter();

GraphicsNodeRableFactory gnrFactory =
new ConcreteGraphicsNodeRableFactory();

nodeRenderContext =
new GraphicsNodeRenderContext(new AffineTransform(), null,
hints, fontRenderContext,
textPainter, gnrFactory);
nodeRenderContext.setTextPainter(textPainter);
}

return nodeRenderContext;
}

public void renderBitmap(FopImage img, int x, int y, int w, int h) {
try {
boolean iscolor = img.getColorSpace().getColorSpace()
@@ -830,113 +796,6 @@ public class PSRenderer extends AbstractRenderer {
}
}

protected class MUserAgent implements UserAgent {
AffineTransform currentTransform = null;
Logger log;
/**
* Creates a new SVGUserAgent.
*/
protected MUserAgent(AffineTransform at, Logger logger) {
currentTransform = at;
log = logger;
}

/**
* Displays an error message.
*/
public void displayError(String message) {
log.error(message);
}

/**
* Displays an error resulting from the specified Exception.
*/
public void displayError(Exception ex) {
log.error("SVG Error" + ex.getMessage(), ex);
}

/**
* Displays a message in the User Agent interface.
* The given message is typically displayed in a status bar.
*/
public void displayMessage(String message) {
log.info(message);
}

/**
* Returns a customized the pixel to mm factor.
*/
public float getPixelToMM() {
// this is set to 72dpi as the values in fo are 72dpi
return 0.3527777777777777778f; // 72 dpi
// return 0.26458333333333333333333333333333f; // 96dpi
}

/**
* Returns the language settings.
*/
public String getLanguages() {
return "en"; // userLanguages;
}

/**
* Returns the user stylesheet uri.
* @return null if no user style sheet was specified.
*/
public String getUserStyleSheetURI() {
return null; // userStyleSheetURI;
}

/**
* Returns the class name of the XML parser.
*/
public String getXMLParserClassName() {
return org.apache.fop.apps.Driver.getParserClassName();
}

/**
* Opens a link in a new component.
* @param doc The current document.
* @param uri The document URI.
*/
public void openLink(SVGAElement elt) {
// application.openLink(uri);
}


public Point getClientAreaLocationOnScreen() {
return new Point(0, 0);
}

public void setSVGCursor(java.awt.Cursor cursor) {}


public AffineTransform getTransform() {
return currentTransform;
}

public Dimension2D getViewportSize() {
return new Dimension(100, 100);
}

public EventDispatcher getEventDispatcher() {
return null;
}

public boolean supportExtension(String str) {
return false;
}

public boolean hasFeature(String str) {
return false;
}

public void registerExtension(BridgeExtension be) {}

public void handleElement(Element elt, Object data) {}

}

/**
Default start renderer method. This would
normally be overridden. (mark-fop@inomial.com).

+ 3
- 3
src/org/apache/fop/svg/PDFANode.java View File

@@ -50,13 +50,13 @@ public class PDFANode extends CompositeGraphicsNode {
* @param g2d the Graphics2D to use
* @param rc the GraphicsNodeRenderContext to use
*/
public void paint(Graphics2D g2d, GraphicsNodeRenderContext rc) {
public void paint(Graphics2D g2d) {
if (isVisible) {
super.paint(g2d, rc);
super.paint(g2d);
if(g2d instanceof PDFGraphics2D) {
PDFGraphics2D pdfg = (PDFGraphics2D)g2d;
int type = org.apache.fop.layout.LinkSet.EXTERNAL;
Shape outline = getOutline(rc);
Shape outline = getOutline();
if(destination.startsWith("#svgView(viewBox(")) {
String nums = destination.substring(18, destination.length() - 2);
float x = 0;

+ 15
- 22
src/org/apache/fop/svg/PDFTextPainter.java View File

@@ -10,7 +10,6 @@ package org.apache.fop.svg;
import java.awt.Graphics2D;
import java.awt.*;
import java.text.AttributedCharacterIterator;
import java.awt.font.FontRenderContext;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.Font;
@@ -53,8 +52,7 @@ public class PDFTextPainter implements TextPainter {
* @param g2d the Graphics2D to use
* @param context the rendering context.
*/
public void paint(TextNode node, Graphics2D g2d,
GraphicsNodeRenderContext context) {
public void paint(TextNode node, Graphics2D g2d) {
// System.out.println("PDFText paint");
String txt = node.getText();
Point2D loc = node.getLocation();
@@ -191,12 +189,11 @@ public class PDFTextPainter implements TextPainter {
* @param y the y coordinate, in the text layout's coordinate system,
* of the selection event.
* @param aci the AttributedCharacterIterator describing the text
* @param context the GraphicsNodeRenderContext to use when doing text layout.
* @return an instance of Mark which encapsulates the state necessary to
* implement hit testing and text selection.
*/
public Mark selectAt(double x, double y, AttributedCharacterIterator aci,
TextNode node, GraphicsNodeRenderContext context) {
TextNode node) {
System.out.println("PDFText selectAt");
return null;
}
@@ -209,13 +206,12 @@ public class PDFTextPainter implements TextPainter {
* @param y the y coordinate, in the text layout's coordinate system,
* of the selection event.
* @param aci the AttributedCharacterIterator describing the text
* @param context the GraphicsNodeRenderContext to use when doing text layout.
* @return an instance of Mark which encapsulates the state necessary to
* implement hit testing and text selection.
*/
public Mark selectTo(double x, double y, Mark beginMark,
AttributedCharacterIterator aci, TextNode node,
GraphicsNodeRenderContext context) {
AttributedCharacterIterator aci,
TextNode node) {
System.out.println("PDFText selectTo");
return null;
}
@@ -228,13 +224,12 @@ public class PDFTextPainter implements TextPainter {
* @param y the y coordinate, in the text layout's coordinate system,
* of the selection event.
* @param aci the AttributedCharacterIterator describing the text
* @param context the GraphicsNodeRenderContext to use when doing text layout.
* @return an instance of Mark which encapsulates the state necessary to
* implement hit testing and text selection.
*/
public Mark selectAll(double x, double y,
AttributedCharacterIterator aci, TextNode node,
GraphicsNodeRenderContext context) {
AttributedCharacterIterator aci,
TextNode node) {
System.out.println("PDFText selectAll");
return null;
}
@@ -244,8 +239,8 @@ public class PDFTextPainter implements TextPainter {
* Selects the first glyph in the text node.
*/
public Mark selectFirst(double x, double y,
AttributedCharacterIterator aci, TextNode node,
GraphicsNodeRenderContext context) {
AttributedCharacterIterator aci,
TextNode node) {
System.out.println("PDFText selectFirst");
return null;
}
@@ -255,8 +250,8 @@ public class PDFTextPainter implements TextPainter {
* Selects the last glyph in the text node.
*/
public Mark selectLast(double x, double y,
AttributedCharacterIterator aci, TextNode node,
GraphicsNodeRenderContext context) {
AttributedCharacterIterator aci,
TextNode node) {
System.out.println("PDFText selectLast");
return null;
}
@@ -300,7 +295,7 @@ public class PDFTextPainter implements TextPainter {
* @param includeStroke whether to create the "stroke shape outlines"
* instead of glyph outlines.
*/
public Shape getShape(TextNode node, FontRenderContext frc) {
public Shape getShape(TextNode node) {
System.out.println("PDFText getShape");
return null;
}
@@ -314,7 +309,7 @@ public class PDFTextPainter implements TextPainter {
* @param includeStroke whether to create the "stroke shape outlines"
* instead of glyph outlines.
*/
public Shape getDecoratedShape(TextNode node, FontRenderContext frc) {
public Shape getDecoratedShape(TextNode node) {
System.out.println("PDFText getDecoratedShape");
return new Rectangle(1, 1);
}
@@ -326,7 +321,7 @@ public class PDFTextPainter implements TextPainter {
* @param g2d the Graphics2D to use
* @param context rendering context.
*/
public Rectangle2D getBounds(TextNode node, FontRenderContext frc) {
public Rectangle2D getBounds(TextNode node) {
System.out.println("PDFText getBounds");
return null;
}
@@ -339,8 +334,7 @@ public class PDFTextPainter implements TextPainter {
* @param g2d the Graphics2D to use
* @param context rendering context.
*/
public Rectangle2D getDecoratedBounds(TextNode node,
FontRenderContext frc) {
public Rectangle2D getDecoratedBounds(TextNode node) {
System.out.println("PDFText getDecoratedBounds");
return null;
}
@@ -353,8 +347,7 @@ public class PDFTextPainter implements TextPainter {
* @param g2d the Graphics2D to use
* @param context rendering context.
*/
public Rectangle2D getPaintedBounds(TextNode node,
FontRenderContext frc) {
public Rectangle2D getPaintedBounds(TextNode node) {
// System.out.println("PDFText getPaintedBounds");
return null;
}

+ 7
- 35
src/org/apache/fop/svg/PDFTranscoder.java View File

@@ -49,7 +49,6 @@ import org.apache.batik.dom.util.DocumentFactory;
import org.apache.batik.ext.awt.image.GraphicsUtil;

import org.apache.batik.gvt.GraphicsNode;
import org.apache.batik.gvt.GraphicsNodeRenderContext;
import org.apache.batik.gvt.event.EventDispatcher;
import org.apache.batik.gvt.renderer.ImageRenderer;
import org.apache.batik.gvt.renderer.ImageRendererFactory;
@@ -178,8 +177,11 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
// build the GVT tree
GVTBuilder builder = new GVTBuilder();
ImageRendererFactory rendFactory = new StaticRendererFactory();
GraphicsNodeRenderContext rc = getRenderContext(stroke);
BridgeContext ctx = new BridgeContext(userAgent, rc);
BridgeContext ctx = new BridgeContext(userAgent);
TextPainter textPainter = null;
textPainter = new StrokingTextPainter();
ctx.setTextPainter(textPainter);
PDFAElementBridge pdfAElementBridge = new PDFAElementBridge();
AffineTransform currentTransform = new AffineTransform(1, 0, 0, 1, 0, 0);
pdfAElementBridge.setCurrentTransform(currentTransform);
@@ -269,18 +271,16 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
graphics.setSVGDimension(docWidth, docHeight);
currentTransform.setTransform(1, 0, 0, -1, 0, height);
if (!stroke) {
TextPainter textPainter = null;
textPainter = new PDFTextPainter(graphics.getFontState());
rc.setTextPainter(textPainter);
ctx.setTextPainter(textPainter);
}

if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) {
graphics.setBackgroundColor((Color)hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR));
}
graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
graphics.setRenderingHints(rc.getRenderingHints());

gvtRoot.paint(graphics, rc);
gvtRoot.paint(graphics);

try {
graphics.finish();
@@ -290,34 +290,6 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
}
}

public GraphicsNodeRenderContext getRenderContext(boolean stroke) {
GraphicsNodeRenderContext nodeRenderContext = null;
if (nodeRenderContext == null) {
RenderingHints hints = new RenderingHints(null);
hints.put(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);

hints.put(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);

FontRenderContext fontRenderContext =
new FontRenderContext(new AffineTransform(), true, true);

TextPainter textPainter = null;
textPainter = new StrokingTextPainter();

GraphicsNodeRableFactory gnrFactory =
new ConcreteGraphicsNodeRableFactory();

nodeRenderContext =
new GraphicsNodeRenderContext(new AffineTransform(), null,
hints, fontRenderContext,
textPainter, gnrFactory);
}

return nodeRenderContext;
}

/**
* Creates a <tt>DocumentFactory</tt> that is used to create an SVG DOM
* tree. The specified DOM Implementation is ignored and the Batik

+ 22
- 5
src/org/apache/fop/svg/SVGElement.java View File

@@ -20,6 +20,13 @@ import org.apache.batik.dom.svg.*;
import org.w3c.dom.*;
import org.w3c.dom.svg.*;
import org.w3c.dom.svg.SVGLength;
import org.apache.batik.bridge.*;
import org.apache.batik.swing.svg.*;
import org.apache.batik.swing.gvt.*;
import org.apache.batik.gvt.*;
import org.apache.batik.gvt.renderer.*;
import org.apache.batik.gvt.filter.*;
import org.apache.batik.gvt.event.*;

import org.w3c.dom.DOMImplementation;
import org.apache.batik.dom.svg.SVGDOMImplementation;
@@ -28,6 +35,7 @@ import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.ArrayList;
import java.awt.geom.AffineTransform;

/**
* class representing svg:svg pseudo flow object.
@@ -51,7 +59,6 @@ public class SVGElement extends SVGObj {
PropertyList propertyList) throws FOPException {
return new SVGElement(parent, propertyList);
}

}

/**
@@ -131,10 +138,20 @@ public class SVGElement extends SVGObj {
};
((SVGOMDocument)doc).setSVGContext(dc);

float width =
((SVGSVGElement)element).getWidth().getBaseVal().getValue();
float height =
((SVGSVGElement)element).getHeight().getBaseVal().getValue();
// this is ugly preprocessing to get the width and height
SVGUserAgent userAgent = new SVGUserAgent(new AffineTransform());
userAgent.setLogger(log);
GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(userAgent);
GraphicsNode root;
root = builder.build(ctx, doc);
// get the 'width' and 'height' attributes of the SVG document
float width = (float)ctx.getDocumentSize().getWidth();
float height = (float)ctx.getDocumentSize().getHeight();
ctx = null;
builder = null;
///////

SVGArea svg = new SVGArea(fs, width, height);
svg.setSVGDocument(doc);
svg.start();

+ 146
- 0
src/org/apache/fop/svg/SVGUserAgent.java View File

@@ -0,0 +1,146 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/

package org.apache.fop.svg;

import org.apache.log.Logger;

import org.apache.batik.bridge.*;
import org.apache.batik.swing.svg.*;
import org.apache.batik.swing.gvt.*;
import org.apache.batik.gvt.*;
import org.apache.batik.gvt.renderer.*;
import org.apache.batik.gvt.filter.*;
import org.apache.batik.gvt.event.*;

import org.w3c.dom.*;
import org.w3c.dom.svg.*;
import org.w3c.dom.css.*;
import org.w3c.dom.svg.SVGLength;

// Java
import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Vector;
import java.util.Hashtable;
import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Dimension;

public class SVGUserAgent implements UserAgent {
AffineTransform currentTransform = null;
Logger log;

/**
* Creates a new SVGUserAgent.
*/
public SVGUserAgent(AffineTransform at) {
currentTransform = at;
}

public void setLogger(Logger logger) {
log = logger;
}

/**
* Displays an error message.
*/
public void displayError(String message) {
log.error(message);
}

/**
* Displays an error resulting from the specified Exception.
*/
public void displayError(Exception ex) {
log.error("SVG Error" + ex.getMessage(), ex);
}

/**
* Displays a message in the User Agent interface.
* The given message is typically displayed in a status bar.
*/
public void displayMessage(String message) {
log.info(message);
}

/**
* Returns a customized the pixel to mm factor.
*/
public float getPixelToMM() {
// this is set to 72dpi as the values in fo are 72dpi
return 0.35277777777777777778f; // 72 dpi
// return 0.26458333333333333333333333333333f; // 96dpi
}

/**
* Returns the language settings.
*/
public String getLanguages() {
return "en"; // userLanguages;
}

/**
* Returns the user stylesheet uri.
* @return null if no user style sheet was specified.
*/
public String getUserStyleSheetURI() {
return null; // userStyleSheetURI;
}

/**
* Returns the class name of the XML parser.
*/
public String getXMLParserClassName() {
return org.apache.fop.apps.Driver.getParserClassName();
}

/**
* Opens a link in a new component.
* @param doc The current document.
* @param uri The document URI.
*/
public void openLink(SVGAElement elt) {
}


public Point getClientAreaLocationOnScreen() {
return new Point(0, 0);
}

public void setSVGCursor(java.awt.Cursor cursor) {}

public AffineTransform getTransform() {
return currentTransform;
}

public Dimension2D getViewportSize() {
return new Dimension(100, 100);
}

public EventDispatcher getEventDispatcher() {
return null;
}

public boolean supportExtension(String str) {
return false;
}

public boolean hasFeature(String str) {
return false;
}

public void registerExtension(BridgeExtension be) {}

public void handleElement(Element elt, Object data) {}


}


Loading…
Cancel
Save