diff options
author | Keiron Liddle <keiron@apache.org> | 2001-10-12 06:40:13 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2001-10-12 06:40:13 +0000 |
commit | 49459fd44b6fd5bb44ce71beb2b0f5c0bcf06fc1 (patch) | |
tree | dcad463e87b7f8f7c211211da76485cdad0e8e90 /src | |
parent | cd8fe5f0219eedfa1a634e5c5e5c99efaa395f6a (diff) | |
download | xmlgraphics-fop-49459fd44b6fd5bb44ce71beb2b0f5c0bcf06fc1.tar.gz xmlgraphics-fop-49459fd44b6fd5bb44ce71beb2b0f5c0bcf06fc1.zip |
changed api associated with batik to current batik
added a half implemented bridge for jpg images
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194499 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/org/apache/fop/image/analyser/SVGReader.java | 5 | ||||
-rw-r--r-- | src/org/apache/fop/layout/LineArea.java | 2 | ||||
-rw-r--r-- | src/org/apache/fop/render/svg/SVGRenderer.java | 17 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFGraphics2D.java | 40 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFImageElementBridge.java | 141 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFTextPainter.java | 123 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFTranscoder.java | 6 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVGUserAgent.java | 4 |
8 files changed, 208 insertions, 130 deletions
diff --git a/src/org/apache/fop/image/analyser/SVGReader.java b/src/org/apache/fop/image/analyser/SVGReader.java index 57b0c0060..1178bf903 100644 --- a/src/org/apache/fop/image/analyser/SVGReader.java +++ b/src/org/apache/fop/image/analyser/SVGReader.java @@ -156,6 +156,11 @@ public class SVGReader extends AbstractImageReader { return "en"; // userLanguages; } + public String getMedia() { + return ""; + } + + /** * Returns the user stylesheet uri. * @return null if no user style sheet was specified. diff --git a/src/org/apache/fop/layout/LineArea.java b/src/org/apache/fop/layout/LineArea.java index d0a13d1b0..6c1c68429 100644 --- a/src/org/apache/fop/layout/LineArea.java +++ b/src/org/apache/fop/layout/LineArea.java @@ -876,7 +876,7 @@ public class LineArea extends Area { private String getHyphenationWord(char[] characters, int wordStart) { boolean wordendFound = false; int counter = 0; - char[] newWord = new char[100]; // create a buffer + char[] newWord = new char[characters.length]; // create a buffer while ((!wordendFound) && ((wordStart + counter) < characters.length)) { char tk = characters[wordStart + counter]; diff --git a/src/org/apache/fop/render/svg/SVGRenderer.java b/src/org/apache/fop/render/svg/SVGRenderer.java index af616d6d5..23b16c9be 100644 --- a/src/org/apache/fop/render/svg/SVGRenderer.java +++ b/src/org/apache/fop/render/svg/SVGRenderer.java @@ -98,13 +98,6 @@ public class SVGRenderer extends AbstractRenderer { protected float currentBlue = 0; /** - * The parent component, used to set up the font. - * This is needed as FontSetup needs a live AWT component - * in order to generate valid font measures. - */ - protected Component parent; - - /** * options */ protected Hashtable options; @@ -607,9 +600,13 @@ public class SVGRenderer extends AbstractRenderer { throws IOException { DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); svgDocument = impl.createDocument(svgNS, "svg", null); - - svgRoot = svgDocument.getDocumentElement(); - } + ProcessingInstruction pi = + svgDocument.createProcessingInstruction( + "xml", + " version=\"1.0\" encoding=\"ISO-8859-1\""); + svgRoot = svgDocument.getDocumentElement(); + svgDocument.insertBefore(pi, svgRoot); + } public void stopRenderer(OutputStream outputStream) throws IOException { diff --git a/src/org/apache/fop/svg/PDFGraphics2D.java b/src/org/apache/fop/svg/PDFGraphics2D.java index 5d89d2ea4..7fc44b294 100644 --- a/src/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/org/apache/fop/svg/PDFGraphics2D.java @@ -171,6 +171,26 @@ public class PDFGraphics2D extends AbstractGraphics2D { return currentAnnotList; } + public void addJpegImage(JpegImage jpeg, float x, float y, float width, float height) { + int xObjectNum = this.pdfDoc.addImage(jpeg); + + AffineTransform at = getTransform(); + double[] matrix = new double[6]; + at.getMatrix(matrix); + currentStream.write("q\n"); + Shape imclip = getClip(); + writeClip(imclip); + currentStream.write("" + matrix[0] + " " + matrix[1] + " " + + matrix[2] + " " + matrix[3] + " " + + matrix[4] + " " + matrix[5] + " cm\n"); + + currentStream.write("" + width + " 0 0 " + + (-height) + " " + + x + " " + + (y + height) + " cm\n" + "/Im" + + xObjectNum + " Do\nQ\n"); + } + /** * Draws as much of the specified image as is currently available. * The image is drawn with its top-left corner at @@ -205,17 +225,17 @@ public class PDFGraphics2D extends AbstractGraphics2D { return false; } - Dimension size = new Dimension(width, height); + Dimension size = new Dimension(width * 3, height * 3); BufferedImage buf = buildBufferedImage(size); java.awt.Graphics2D g = buf.createGraphics(); g.setComposite(AlphaComposite.SrcOver); g.setBackground(new Color(1, 1, 1, 0)); g.setPaint(new Color(1, 1, 1, 0)); - g.fillRect(0, 0, width, height); + g.fillRect(0, 0, width * 3, height * 3); g.clip(new Rectangle(0, 0, buf.getWidth(), buf.getHeight())); - if (!g.drawImage(img, 0, 0, observer)) { + if (!g.drawImage(img, 0, 0, buf.getWidth(), buf.getHeight(), observer)) { return false; } g.dispose(); @@ -267,7 +287,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { } try { - FopImage fopimg = new TempImage(width, height, result, mask); + FopImage fopimg = new TempImage(buf.getWidth(), buf.getHeight(), result, mask); int xObjectNum = this.pdfDoc.addImage(fopimg); AffineTransform at = getTransform(); double[] matrix = new double[6]; @@ -477,10 +497,15 @@ public class PDFGraphics2D extends AbstractGraphics2D { */ public void draw(Shape s) { // System.out.println("draw(Shape)"); + Color c; + c = getColor(); + if(c.getAlpha() == 0) { + return; + } + currentStream.write("q\n"); Shape imclip = getClip(); writeClip(imclip); - Color c = getColor(); applyColor(c, false); applyPaint(getPaint(), false); @@ -1169,6 +1194,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { * but it should be fixed...). */ public Rectangle getBounds() { +System.out.println("getting getBounds"); return null; } @@ -1193,6 +1219,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { * The default transform (1:1). */ public AffineTransform getDefaultTransform() { +System.out.println("getting getDefaultTransform"); return new AffineTransform(); } @@ -1202,7 +1229,8 @@ public class PDFGraphics2D extends AbstractGraphics2D { * in the future). */ public AffineTransform getNormalizingTransform() { - return new AffineTransform(); +System.out.println("getting getNormalizingTransform"); + return new AffineTransform(2, 0, 0, 2, 0, 0); } /** diff --git a/src/org/apache/fop/svg/PDFImageElementBridge.java b/src/org/apache/fop/svg/PDFImageElementBridge.java new file mode 100644 index 000000000..7bfb7a1fb --- /dev/null +++ b/src/org/apache/fop/svg/PDFImageElementBridge.java @@ -0,0 +1,141 @@ +/* + * $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 java.awt.geom.AffineTransform; + +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.apache.fop.image.*; +import org.apache.fop.apps.*; + +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; + +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.Graphics2D; +import java.awt.color.ICC_Profile; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.awt.geom.Rectangle2D; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Map; + +import org.apache.batik.dom.svg.SVGOMDocument; +import org.apache.batik.dom.util.XLinkSupport; +import org.apache.batik.ext.awt.color.ICCColorSpaceExt; +import org.apache.batik.ext.awt.image.renderable.ClipRable8Bit; +import org.apache.batik.ext.awt.image.renderable.Filter; +import org.apache.batik.ext.awt.image.spi.ImageTagRegistry; +import org.apache.batik.gvt.CompositeGraphicsNode; +import org.apache.batik.gvt.GraphicsNode; +import org.apache.batik.gvt.ImageNode; +import org.apache.batik.gvt.RasterImageNode; +import org.apache.batik.gvt.AbstractGraphicsNode; +import org.apache.batik.gvt.filter.GraphicsNodeRable8Bit; +import org.apache.batik.util.ParsedURL; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.css.CSSPrimitiveValue; +import org.w3c.dom.css.CSSStyleDeclaration; +import org.w3c.dom.svg.SVGDocument; +import org.w3c.dom.svg.SVGSVGElement; + +/** + * Bridge class for the <image> element when jpeg images. + * + * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a> + */ +public class PDFImageElementBridge extends SVGImageElementBridge { + + /** + * Constructs a new bridge for the <image> element. + */ + public PDFImageElementBridge() {} +/* + protected GraphicsNode createRasterImageNode(BridgeContext ctx, + Element e, ParsedURL purl) { + + try { + JpegImage jpeg = new JpegImage(new URL(purl.toString())); + PDFFilter filter = jpeg.getPDFFilter(); + PDFJpegNode node = new PDFJpegNode(jpeg); + Rectangle2D bounds = node.getPrimitiveBounds(); + float [] vb = new float[4]; + vb[0] = 0; // x + vb[1] = 0; // y + vb[2] = (float) bounds.getWidth(); // width + vb[3] = (float) bounds.getHeight(); // height + + // handles the 'preserveAspectRatio', 'overflow' and 'clip' and sets the + // appropriate AffineTransform to the image node + initializeViewport(ctx, e, node, vb, bounds); + + return node; + } catch (Exception ex) { + } + + return super.createRasterImageNode(ctx, e, purl); + } +*/ + public static class PDFJpegNode extends AbstractGraphicsNode { + JpegImage jpeg; + public PDFJpegNode(JpegImage j) { + jpeg = j; + } + + public Shape getOutline() { + return getPrimitiveBounds(); + } + + public void primitivePaint(Graphics2D g2d) { + if (g2d instanceof PDFGraphics2D) { + PDFGraphics2D pdfg = (PDFGraphics2D) g2d; + pdfg.setTransform(getTransform()); + float x = 0; + float y = 0; + try { + float width = jpeg.getWidth(); + float height = jpeg.getHeight(); + pdfg.addJpegImage(jpeg, x, y, width, height); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + public Rectangle2D getGeometryBounds() { + return getPrimitiveBounds(); + } + + public Rectangle2D getPrimitiveBounds() { + try { + return new Rectangle2D.Double(0, 0, jpeg.getWidth(), + jpeg.getHeight()); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + } + +} diff --git a/src/org/apache/fop/svg/PDFTextPainter.java b/src/org/apache/fop/svg/PDFTextPainter.java index 238406f33..1e55e7bfd 100644 --- a/src/org/apache/fop/svg/PDFTextPainter.java +++ b/src/org/apache/fop/svg/PDFTextPainter.java @@ -181,172 +181,69 @@ public class PDFTextPainter implements TextPainter { return wordWidth / 1000f; } - /** - * Initiates a text selection on a particular AttributedCharacterIterator, - * using the text/font metrics employed by this TextPainter instance. - * @param x the x coordinate, in the text layout's coordinate system, - * of the selection event. - * @param y the y coordinate, in the text layout's coordinate system, - * of the selection event. - * @param aci the AttributedCharacterIterator describing the text - * @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, + public Mark getMark(TextNode node, int pos, boolean all) { + System.out.println("PDFText getMark"); + return null; + } + + public Mark selectAt(double x, double y, TextNode node) { System.out.println("PDFText selectAt"); return null; } - /** - * Continues a text selection on a particular AttributedCharacterIterator, - * using the text/font metrics employed by this TextPainter instance. - * @param x the x coordinate, in the text layout's coordinate system, - * of the selection event. - * @param y the y coordinate, in the text layout's coordinate system, - * of the selection event. - * @param aci the AttributedCharacterIterator describing the text - * @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) { + public Mark selectTo(double x, double y, Mark beginMark) { System.out.println("PDFText selectTo"); return null; } - /** - * Select all of the text represented by an AttributedCharacterIterator, - * using the text/font metrics employed by this TextPainter instance. - * @param x the x coordinate, in the text layout's coordinate system, - * of the selection event. - * @param y the y coordinate, in the text layout's coordinate system, - * of the selection event. - * @param aci the AttributedCharacterIterator describing the text - * @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) { 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) { + public Mark selectFirst(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) { + public Mark selectLast(TextNode node) { System.out.println("PDFText selectLast"); return null; } - /* - * Get an array of index pairs corresponding to the indices within an - * AttributedCharacterIterator regions bounded by two Marks. - * Note that the instances of Mark passed to this function - * <em>must come</em> - * from the same TextPainter that generated them via selectAt() and - * selectTo(), since the TextPainter implementation may rely on hidden - * implementation details of its own Mark implementation. - */ - public int[] getSelected(AttributedCharacterIterator aci, Mark start, + public int[] getSelected(Mark start, Mark finish) { System.out.println("PDFText getSelected"); return null; } - - /* - * Get a Shape in userspace coords which encloses the textnode - * glyphs bounded by two Marks. - * Note that the instances of Mark passed to this function - * <em>must come</em> - * from the same TextPainter that generated them via selectAt() and - * selectTo(), since the TextPainter implementation may rely on hidden - * implementation details of its own Mark implementation. - */ public Shape getHighlightShape(Mark beginMark, Mark endMark) { System.out.println("PDFText getHighlightShape"); return null; } - /* - * Get a Shape in userspace coords which defines the textnode glyph outlines. - * @param node the TextNode to measure - * @param frc the font rendering context. - * @param includeDecoration whether to include text decoration - * outlines. - * @param includeStroke whether to create the "stroke shape outlines" - * instead of glyph outlines. - */ public Shape getShape(TextNode node) { System.out.println("PDFText getShape"); return null; } - /* - * Get a Shape in userspace coords which defines the textnode glyph outlines. - * @param node the TextNode to measure - * @param frc the font rendering context. - * @param includeDecoration whether to include text decoration - * outlines. - * @param includeStroke whether to create the "stroke shape outlines" - * instead of glyph outlines. - */ public Shape getDecoratedShape(TextNode node) { System.out.println("PDFText getDecoratedShape"); return new Rectangle(1, 1); } - /* - * Get a Rectangle2D in userspace coords which encloses the textnode - * glyphs composed from an AttributedCharacterIterator. - * @param node the TextNode to measure - * @param g2d the Graphics2D to use - * @param context rendering context. - */ public Rectangle2D getBounds(TextNode node) { System.out.println("PDFText getBounds"); return null; } - /* - * Get a Rectangle2D in userspace coords which encloses the textnode - * glyphs composed from an AttributedCharacterIterator, inclusive of - * glyph decoration (underline, overline, strikethrough). - * @param node the TextNode to measure - * @param g2d the Graphics2D to use - * @param context rendering context. - */ public Rectangle2D getDecoratedBounds(TextNode node) { System.out.println("PDFText getDecoratedBounds"); return null; } - /* - * Get a Rectangle2D in userspace coords which encloses the - * textnode glyphs (as-painted, inclusive of decoration and stroke, but - * exclusive of filters, etc.) composed from an AttributedCharacterIterator. - * @param node the TextNode to measure - * @param g2d the Graphics2D to use - * @param context rendering context. - */ public Rectangle2D getPaintedBounds(TextNode node) { // System.out.println("PDFText getPaintedBounds"); return null; diff --git a/src/org/apache/fop/svg/PDFTranscoder.java b/src/org/apache/fop/svg/PDFTranscoder.java index 73d5fcb46..21f5b5641 100644 --- a/src/org/apache/fop/svg/PDFTranscoder.java +++ b/src/org/apache/fop/svg/PDFTranscoder.java @@ -186,6 +186,7 @@ public class PDFTranscoder extends XMLAbstractTranscoder { AffineTransform currentTransform = new AffineTransform(1, 0, 0, 1, 0, 0); pdfAElementBridge.setCurrentTransform(currentTransform); ctx.putBridge(pdfAElementBridge); + ctx.putBridge(new PDFImageElementBridge()); GraphicsNode gvtRoot; try { gvtRoot = builder.build(ctx, svgDoc); @@ -377,6 +378,11 @@ public class PDFTranscoder extends XMLAbstractTranscoder { } } + public String getMedia() { + return ""; + } + + /** * Returns the user stylesheet specified in the * <tt>TranscodingHints</tt> or null if any. diff --git a/src/org/apache/fop/svg/SVGUserAgent.java b/src/org/apache/fop/svg/SVGUserAgent.java index bbd3b08e6..52873f18a 100644 --- a/src/org/apache/fop/svg/SVGUserAgent.java +++ b/src/org/apache/fop/svg/SVGUserAgent.java @@ -87,6 +87,10 @@ public class SVGUserAgent implements UserAgent { return "en"; // userLanguages; } + public String getMedia() { + return ""; + } + /** * Returns the user stylesheet uri. * @return null if no user style sheet was specified. |