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);
}
// 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) {}
+
+ }
+
}
}
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();
}
}
- 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())
}
- 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);
}
/**
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) {}
-
}
public void startRenderer(OutputStream outputStream)
import java.awt.geom.Dimension2D;
import java.awt.Point;
import java.awt.RenderingHints;
-import java.awt.font.FontRenderContext;
import java.awt.Dimension;
/**
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
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];
+ 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: "
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
*
}
}
- 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) {}
-
-
- }
}
import java.awt.geom.Dimension2D;
import java.awt.Point;
import java.awt.RenderingHints;
-import java.awt.font.FontRenderContext;
import java.awt.Dimension;
/**
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");
}
// 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()
}
}
- 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).
* @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;
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;
* @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();
* @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;
}
* @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;
}
* @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;
}
* 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;
}
* 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;
}
* @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;
}
* @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);
}
* @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;
}
* @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;
}
* @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;
}
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;
// 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);
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();
}
}
- 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
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.net.URL;
import java.util.List;
import java.util.ArrayList;
+import java.awt.geom.AffineTransform;
/**
* class representing svg:svg pseudo flow object.
PropertyList propertyList) throws FOPException {
return new SVGElement(parent, propertyList);
}
-
}
/**
};
((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();
--- /dev/null
+/*
+ * $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) {}
+
+
+}
+