--- /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 java.awt.Cursor;
+
+import org.apache.batik.bridge.*;
+
+import org.apache.batik.css.HiddenChildElementSupport;
+import org.apache.batik.gvt.CompositeGraphicsNode;
+import org.apache.batik.gvt.GraphicsNode;
+
+import org.apache.fop.pdf.*;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.events.Event;
+import org.w3c.dom.events.EventListener;
+import org.w3c.dom.events.EventTarget;
+import org.w3c.dom.svg.SVGAElement;
+
+/**
+ * Bridge class for the <a> element.
+ *
+ * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
+ */
+public class PDFAElementBridge extends AbstractGraphicsNodeBridge {
+ PDFGraphics2D pdfDoc;
+
+ /**
+ * Constructs a new bridge for the <a> element.
+ */
+ public PDFAElementBridge() {}
+
+ public void setPDFGraphics2D(PDFGraphics2D doc) {
+ this.pdfDoc = doc;
+ }
+
+ /**
+ * Returns 'a'.
+ */
+ public String getLocalName() {
+ return SVG_A_TAG;
+ }
+
+ /**
+ * Creates a <tt>CompositeGraphicsNode</tt>.
+ */
+ protected GraphicsNode instantiateGraphicsNode() {
+ return new PDFANode();
+ }
+
+ /**
+ * Builds using the specified BridgeContext and element, the
+ * specified graphics node.
+ *
+ * @param ctx the bridge context to use
+ * @param e the element that describes the graphics node to build
+ * @param node the graphics node to build
+ */
+ public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
+ PDFANode aNode = (PDFANode) super.createGraphicsNode(ctx, e);
+ return aNode;
+ }
+
+ /**
+ * Returns true as the <a> element is a container.
+ */
+ public boolean isComposite() {
+ return true;
+ }
+
+}
import java.awt.Font;
import java.awt.Image;
import java.awt.Color;
+import java.awt.Shape;
+import java.awt.font.FontRenderContext;
+import java.awt.font.GlyphVector;
import java.io.OutputStream;
import java.io.IOException;
OutputStream stream, int width, int height) {
super(textAsShapes);
- if(!textAsShapes) {
+ if (!textAsShapes) {
fontInfo = new FontInfo();
FontSetup.setup(fontInfo);
try {
- fontState = new FontState(fontInfo, "Helvetica", "normal", "normal", 12, 0);
- } catch(FOPException e) {
+ fontState = new FontState(fontInfo, "Helvetica", "normal",
+ "normal", 12, 0);
+ } catch (FOPException e) {
}
}
standalone = true;
}
+ public FontState getFontState() {
+ return fontState;
+ }
+
+ public PDFDocument getPDFDocument() {
+ return this.pdfDoc;
+ }
+
/**
* Set the dimensions of the svg document that will be drawn.
* This is useful if the dimensions of the svg document are different
* The result is scaled so that the svg fits correctly inside the pdf document.
*/
public void setSVGDimension(float w, float h) {
- currentStream.write("" + PDFNumber.doubleOut(width / w) + " 0 0 " + PDFNumber.doubleOut(height / h) + " 0 0 cm\n");
+ currentStream.write("" + PDFNumber.doubleOut(width / w) +
+ " 0 0 " + PDFNumber.doubleOut(height / h) + " 0 0 cm\n");
}
/**
PDFPage currentPage =
this.pdfDoc.makePage(pdfResources, pdfStream, width,
height, null);
- if(fontInfo != null) {
+ if (fontInfo != null) {
FontSetup.addToResources(this.pdfDoc, fontInfo);
}
this.pdfDoc.output(stream);
return new PDFDocumentGraphics2D(this);
}
+ public void drawString(String s, float x, float y) {
+ if (super.textAsShapes) {
+ Font font = super.getFont();
+ FontRenderContext frc = super.getFontRenderContext();
+ GlyphVector gv = font.createGlyphVector(frc, s);
+ Shape glyphOutline = gv.getOutline(x, y);
+ super.fill(glyphOutline);
+ } else {
+ super.drawString(s, x, y);
+ }
+ }
}
+
/* $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."
+ * LICENSE file included with these sources.
*/
package org.apache.fop.svg;
import org.w3c.dom.svg.SVGLength;
import org.apache.fop.svg.*;
+import org.apache.fop.pdf.*;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
*/
public class PDFTranscoder extends XMLAbstractTranscoder {
+ public static final TranscodingHints.Key KEY_STROKE_TEXT =
+ new StringKey();
+
/** The user agent dedicated to an <tt>ImageTranscoder</tt>. */
protected UserAgent userAgent = new ImageTranscoderUserAgent();
svgCtx.setPixelToMM(userAgent.getPixelToMM());
((SVGOMDocument) document).setSVGContext(svgCtx);
+ boolean stroke = true;
+ if (hints.containsKey(KEY_STROKE_TEXT)) {
+ stroke = ((Boolean) hints.get(KEY_STROKE_TEXT)).booleanValue();
+ }
+
// build the GVT tree
GVTBuilder builder = new GVTBuilder();
ImageRendererFactory rendFactory = new StaticRendererFactory();
- GraphicsNodeRenderContext rc = getRenderContext();
+ GraphicsNodeRenderContext rc = getRenderContext(stroke);
BridgeContext ctx = new BridgeContext(userAgent, rc);
+ PDFAElementBridge pdfAElementBridge = new PDFAElementBridge();
+ ctx.putBridge(pdfAElementBridge);
GraphicsNode gvtRoot;
try {
gvtRoot = builder.build(ctx, svgDoc);
// compute the image's width and height according the hints
float imgWidth = -1;
if (hints.containsKey(ImageTranscoder.KEY_WIDTH)) {
- imgWidth = ((Float) hints.get(ImageTranscoder.KEY_WIDTH)).floatValue();
+ imgWidth = ((Float) hints.get(ImageTranscoder.KEY_WIDTH)).
+ floatValue();
}
float imgHeight = -1;
if (hints.containsKey(ImageTranscoder.KEY_HEIGHT)) {
- imgHeight = ((Float) hints.get(ImageTranscoder.KEY_HEIGHT)).floatValue();
+ imgHeight = ((Float) hints.get(ImageTranscoder.KEY_HEIGHT)).
+ floatValue();
}
float width, height;
if (imgWidth > 0 && imgHeight > 0) {
}
// take the AOI into account if any
if (hints.containsKey(ImageTranscoder.KEY_AOI)) {
- Rectangle2D aoi = (Rectangle2D) hints.get(ImageTranscoder.KEY_AOI);
+ Rectangle2D aoi =
+ (Rectangle2D) hints.get(ImageTranscoder.KEY_AOI);
// transform the AOI into the image's coordinate system
aoi = Px.createTransformedShape(aoi).getBounds2D();
AffineTransform Mx = new AffineTransform();
int w = (int) width;
int h = (int) height;
- PDFDocumentGraphics2D graphics = new PDFDocumentGraphics2D(true,
+ PDFDocumentGraphics2D graphics = new PDFDocumentGraphics2D(stroke,
output.getOutputStream(), w, h);
graphics.setSVGDimension(docWidth, docHeight);
+
+ if (!stroke) {
+ TextPainter textPainter = null;
+ textPainter = new PDFTextPainter(graphics.getFontState());
+ rc.setTextPainter(textPainter);
+ }
+
+ pdfAElementBridge.setPDFGraphics2D(graphics);
if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) {
- graphics.setBackgroundColor((Color) hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR));
+ graphics.setBackgroundColor( (Color) hints.get(
+ ImageTranscoder.KEY_BACKGROUND_COLOR));
}
- // GraphicsNodeRenderContext rc = getRenderContext();
graphics.setGraphicContext(
new org.apache.batik.ext.awt.g2d.GraphicContext());
graphics.setRenderingHints(rc.getRenderingHints());
}
}
- public GraphicsNodeRenderContext getRenderContext() {
+ public GraphicsNodeRenderContext getRenderContext(boolean stroke) {
GraphicsNodeRenderContext nodeRenderContext = null;
if (nodeRenderContext == null) {
RenderingHints hints = new RenderingHints(null);
new FontRenderContext(new AffineTransform(), true,
true);
- TextPainter textPainter = new StrokingTextPainter();
+ TextPainter textPainter = null;
+ textPainter = new StrokingTextPainter();
GraphicsNodeRableFactory gnrFactory =
new ConcreteGraphicsNodeRableFactory();
nodeRenderContext = new GraphicsNodeRenderContext(
new AffineTransform(), null, hints,
fontRenderContext, textPainter, gnrFactory);
- nodeRenderContext.setTextPainter(textPainter);
}
return nodeRenderContext;
* <tt>TranscodingHints</tt> or 0.3528 if any.
*/
public float getPixelToMM() {
- if (getTranscodingHints().containsKey(ImageTranscoder.KEY_PIXEL_TO_MM)) {
+ if (getTranscodingHints().containsKey(
+ ImageTranscoder.KEY_PIXEL_TO_MM)) {
return ( (Float) getTranscodingHints().get(
ImageTranscoder.KEY_PIXEL_TO_MM)).floatValue();
} else {
* <tt>TranscodingHints</tt> or "en" (english) if any.
*/
public String getLanguages() {
- if (getTranscodingHints().containsKey(ImageTranscoder.KEY_LANGUAGE)) {
- return (String) getTranscodingHints().get(ImageTranscoder.KEY_LANGUAGE);
+ if (getTranscodingHints().containsKey(
+ ImageTranscoder.KEY_LANGUAGE)) {
+ return (String) getTranscodingHints().get(
+ ImageTranscoder.KEY_LANGUAGE);
} else {
return "en";
}
* Returns the XML parser to use from the TranscodingHints.
*/
public String getXMLParserClassName() {
- if (getTranscodingHints().containsKey(KEY_XML_PARSER_CLASSNAME)) {
- return (String)getTranscodingHints().get(KEY_XML_PARSER_CLASSNAME);
+ if (getTranscodingHints().containsKey(
+ KEY_XML_PARSER_CLASSNAME)) {
+ return (String) getTranscodingHints().get(
+ KEY_XML_PARSER_CLASSNAME);
} else {
return XMLResourceDescriptor.getXMLParserClassName();
}