From: Keiron Liddle Date: Wed, 11 Sep 2002 09:51:13 +0000 (+0000) Subject: fixed most style errors X-Git-Tag: Alt-Design-integration-base~402 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8485a25d67eae55873689d9bd80f6935f8fd418b;p=xmlgraphics-fop.git fixed most style errors git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195168 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/render/pdf/PDFXMLHandler.java b/src/org/apache/fop/render/pdf/PDFXMLHandler.java index b91baa660..d111aeb1f 100644 --- a/src/org/apache/fop/render/pdf/PDFXMLHandler.java +++ b/src/org/apache/fop/render/pdf/PDFXMLHandler.java @@ -1,64 +1,122 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 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.render.pdf; -import org.apache.fop.fo.FOUserAgent; import org.apache.fop.render.XMLHandler; import org.apache.fop.render.RendererContext; -import org.apache.fop.pdf.*; -import org.apache.fop.svg.*; +import org.apache.fop.pdf.PDFDocument; +import org.apache.fop.pdf.PDFPage; +import org.apache.fop.pdf.PDFState; +import org.apache.fop.pdf.PDFStream; +import org.apache.fop.pdf.PDFNumber; +import org.apache.fop.svg.PDFTextElementBridge; +import org.apache.fop.svg.PDFAElementBridge; +import org.apache.fop.svg.PDFGraphics2D; import org.apache.fop.svg.SVGUserAgent; import org.apache.fop.layout.FontInfo; -import org.apache.batik.dom.util.DOMUtilities; - import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Attr; -import java.io.IOException; import java.io.OutputStream; -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.apache.batik.bridge.GVTBuilder; +import org.apache.batik.bridge.BridgeContext; +import org.apache.batik.bridge.ViewBox; + +import org.apache.batik.gvt.GraphicsNode; -import org.w3c.dom.*; -import org.w3c.dom.svg.*; -import org.w3c.dom.css.*; -import org.w3c.dom.svg.SVGLength; +import org.w3c.dom.svg.SVGDocument; +import org.w3c.dom.svg.SVGSVGElement; import java.awt.geom.AffineTransform; /** + * PDF XML handler. + * This handler handles XML for foreign objects when rendering to PDF. + * It renders SVG to the PDF document using the PDFGraphics2D. + * The properties from the PDF renderer are subject to change. */ public class PDFXMLHandler implements XMLHandler { -public static final String PDF_DOCUMENT = "pdfDoc"; -public static final String OUTPUT_STREAM = "outputStream"; -public static final String PDF_STATE = "pdfState"; -public static final String PDF_PAGE = "pdfPage"; -public static final String PDF_STREAM = "pdfStream"; -public static final String PDF_WIDTH = "width"; -public static final String PDF_HEIGHT = "height"; -public static final String PDF_FONT_INFO = "fontInfo"; -public static final String PDF_FONT_NAME = "fontName"; -public static final String PDF_FONT_SIZE = "fontSize"; -public static final String PDF_XPOS = "xpos"; -public static final String PDF_YPOS = "ypos"; + /** + * The PDF document that is being drawn into. + */ + public static final String PDF_DOCUMENT = "pdfDoc"; + + /** + * The output stream that the document is being sent to. + */ + public static final String OUTPUT_STREAM = "outputStream"; + + /** + * The current pdf state. + */ + public static final String PDF_STATE = "pdfState"; + /** + * The current PDF page for page renference and as a resource context. + */ + public static final String PDF_PAGE = "pdfPage"; + + /** + * The current PDF stream to draw directly to. + */ + public static final String PDF_STREAM = "pdfStream"; + + /** + * The width of the current pdf page. + */ + public static final String PDF_WIDTH = "width"; + + /** + * The height of the current pdf page. + */ + public static final String PDF_HEIGHT = "height"; + + /** + * The current font information for the pdf renderer. + */ + public static final String PDF_FONT_INFO = "fontInfo"; + + /** + * The current pdf font name. + */ + public static final String PDF_FONT_NAME = "fontName"; + + /** + * The current pdf font size. + */ + public static final String PDF_FONT_SIZE = "fontSize"; + + /** + * The x position that this is being drawn at. + */ + public static final String PDF_XPOS = "xpos"; + + /** + * The y position that this is being drawn at. + */ + public static final String PDF_YPOS = "ypos"; + + /** + * Create a new PDF XML handler for use by the PDF renderer. + */ public PDFXMLHandler() { } + /** + * Handle the XML. + * This checks the type of XML and handles appropraitely. + * + * @param context the renderer context + * @param doc the XML document to render + * @param ns the namespace of the XML document + * @throws Exception any sort of exception could be thrown and shuld be handled + */ public void handleXML(RendererContext context, Document doc, String ns) throws Exception { PDFInfo pdfi = getPDFInfo(context); @@ -71,6 +129,12 @@ public static final String PDF_YPOS = "ypos"; } } + /** + * Get the pdf information from the render context. + * + * @param context the renderer context + * @return the pdf information retrieved from the context + */ public static PDFInfo getPDFInfo(RendererContext context) { PDFInfo pdfi = new PDFInfo(); pdfi.pdfDoc = (PDFDocument)context.getProperty(PDF_DOCUMENT); @@ -88,19 +152,34 @@ public static final String PDF_YPOS = "ypos"; return pdfi; } + /** + * PDF information structure for drawing the XML document. + */ public static class PDFInfo { - PDFDocument pdfDoc; - OutputStream outputStream; - PDFState pdfState; - PDFPage pdfPage; + /** see PDF_DOCUMENT */ + public PDFDocument pdfDoc; + /** see OUTPUT_STREAM */ + public OutputStream outputStream; + /** see PDF_STATE */ + public PDFState pdfState; + /** see PDF_PAGE */ + public PDFPage pdfPage; + /** see PDF_STREAM */ public PDFStream currentStream; - int width; - int height; - FontInfo fi; - String currentFontName; - int currentFontSize; - int currentXPosition; - int currentYPosition; + /** see PDF_WIDTH */ + public int width; + /** see PDF_HEIGHT */ + public int height; + /** see PDF_FONT_INFO */ + public FontInfo fi; + /** see PDF_FONT_NAME */ + public String currentFontName; + /** see PDF_FONT_SIZE */ + public int currentFontSize; + /** see PDF_XPOS */ + public int currentXPosition; + /** see PDF_YPOS */ + public int currentYPosition; } /** @@ -108,6 +187,12 @@ public static final String PDF_YPOS = "ypos"; * loading errors if batik is not present. */ protected class SVGHandler { + /** + * Render the svg document. + * @param context the renderer context + * @param doc the svg document + * @param pdfInfo the pdf information of the current context + */ protected void renderSVGDocument(RendererContext context, Document doc, PDFInfo pdfInfo) { int xOffset = pdfInfo.currentXPosition; int yOffset = pdfInfo.currentYPosition; @@ -159,7 +244,7 @@ public static final String PDF_YPOS = "ypos"; SVGSVGElement svg = ((SVGDocument)doc).getRootElement(); AffineTransform at = ViewBox.getPreserveAspectRatioTransform(svg, w / 1000f, h / 1000f); - if(!at.isIdentity()) { + if (!at.isIdentity()) { double[] vals = new double[6]; at.getMatrix(vals); pdfInfo.currentStream.add(PDFNumber.doubleOut(vals[0]) + " " @@ -171,14 +256,13 @@ public static final String PDF_YPOS = "ypos"; } PDFGraphics2D graphics = new PDFGraphics2D(true, pdfInfo.fi, pdfInfo.pdfDoc, - pdfInfo.pdfPage, pdfInfo.pdfPage.referencePDF(), pdfInfo.currentFontName, - pdfInfo.currentFontSize, - pdfInfo.currentXPosition, - pdfInfo.currentYPosition); + pdfInfo.pdfPage, pdfInfo.pdfPage.referencePDF(), + pdfInfo.currentFontName, + pdfInfo.currentFontSize); graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext()); pdfInfo.pdfState.push(); transform = new AffineTransform(); - // TODO scale to viewbox + // scale to viewbox transform.translate(xOffset / 1000f, yOffset / 1000f); pdfInfo.pdfState.setTransform(transform); graphics.setPDFState(pdfInfo.pdfState); diff --git a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java index 4ce026dc5..072fcde85 100644 --- a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java +++ b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java @@ -63,15 +63,12 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D { // FontInfo.NORMAL, 12, 0); } - standalone = true; this.pdfDoc = new PDFDocument("FOP SVG Renderer"); graphicsState = new PDFState(); currentFontName = ""; currentFontSize = 0; - currentYPosition = 0; - currentXPosition = 0; pdfStream = this.pdfDoc.makeStream(PDFStream.CONTENT_FILTER, false); } diff --git a/src/org/apache/fop/svg/PDFGraphics2D.java b/src/org/apache/fop/svg/PDFGraphics2D.java index 4a30f87ff..b6d28779f 100644 --- a/src/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/org/apache/fop/svg/PDFGraphics2D.java @@ -82,8 +82,6 @@ import java.util.HashMap; * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D */ public class PDFGraphics2D extends AbstractGraphics2D { - protected boolean standalone = false; - /** * the PDF Document being created */ @@ -93,21 +91,37 @@ public class PDFGraphics2D extends AbstractGraphics2D { * The current resource context for adding fonts, patterns etc. */ protected PDFResourceContext resourceContext; + + /** + * The PDF reference of the current page. + */ protected String pageRef; /** * the current state of the pdf graphics */ protected PDFState graphicsState; - int baseLevel = 0; + /** + * The PDF graphics state level that this svg is being drawn into. + */ + protected int baseLevel = 0; + + /** + * The current font information. + */ protected FontInfo fontInfo; + + /** + * The override font state used when drawing text and the font cannot be + * set using java fonts. + */ protected FontState ovFontState = null; /** * the current stream to add PDF commands to */ - StringWriter currentStream = new StringWriter(); + protected StringWriter currentStream = new StringWriter(); /** * the current (internal) font name @@ -119,16 +133,6 @@ public class PDFGraphics2D extends AbstractGraphics2D { */ protected float currentFontSize; - /** - * the current vertical position in millipoints from bottom - */ - protected int currentYPosition = 0; - - /** - * the current horizontal position in millipoints from left - */ - protected int currentXPosition = 0; - /** * The output stream for the pdf document. * If this is set then it can progressively output @@ -141,48 +145,93 @@ public class PDFGraphics2D extends AbstractGraphics2D { * Create a new PDFGraphics2D with the given pdf document info. * This is used to create a Graphics object for use inside an already * existing document. + * + * @param textAsShapes if true then draw text as shapes + * @param fi the current font information + * @param doc the pdf document for creating pdf objects + * @param page the current resource context or page + * @param pref the PDF reference of the current page + * @param font the current font name + * @param size the current font size */ public PDFGraphics2D(boolean textAsShapes, FontInfo fi, PDFDocument doc, - PDFResourceContext page, String pref, String font, float size, int xpos, int ypos) { + PDFResourceContext page, String pref, String font, float size) { super(textAsShapes); pdfDoc = doc; resourceContext = page; currentFontName = font; currentFontSize = size; - currentYPosition = ypos; - currentXPosition = xpos; fontInfo = fi; pageRef = pref; graphicsState = new PDFState(); } + /** + * Create a new PDFGraphics2D. + * + * @param textAsShapes true if drawing text as shapes + */ protected PDFGraphics2D(boolean textAsShapes) { super(textAsShapes); } + /** + * Set the PDF state to use when starting to draw + * into the PDF graphics. + * + * @param state the PDF state + */ public void setPDFState(PDFState state) { graphicsState = state; baseLevel = graphicsState.getStackLevel(); } + /** + * Set the output stream that this PDF document is + * being drawn to. This is so that it can progressively + * use the PDF document to output data such as images. + * This results in a significant saving on memory. + * + * @param os the output stream that is being used for the PDF document + */ public void setOutputStream(OutputStream os) { outputStream = os; } + /** + * Get the string containing all the commands written into this + * Grpahics. + * @return the string containing the PDF markup + */ public String getString() { return currentStream.toString(); } + /** + * Set the Grpahics context. + * @param c the graphics context to use + */ public void setGraphicContext(GraphicContext c) { gc = c; } + /** + * Set the override font state for drawing text. + * This is used by the PDF text painter so that it can temporarily + * set the font state when a java font cannot be used. + * The next drawString will use this font state. + * + * @param infont the font state to use + */ public void setOverrideFontState(FontState infont) { ovFontState = infont; } /** - * This constructor supports the create method + * This constructor supports the create method. + * This is not implemented properly. + * + * @param g the PDF graphics to make a copy of */ public PDFGraphics2D(PDFGraphics2D g) { super(g); @@ -198,6 +247,9 @@ public class PDFGraphics2D extends AbstractGraphics2D { return new PDFGraphics2D(this); } + /** + * Restore the PDF graphics state to the starting state level. + */ public void restorePDFState() { for (int count = graphicsState.getStackLevel(); count > baseLevel; count--) { currentStream.write("Q\n"); @@ -208,6 +260,11 @@ public class PDFGraphics2D extends AbstractGraphics2D { /** * This is a pdf specific method used to add a link to the * pdf document. + * + * @param bounds the bounds of the link in user coordinates + * @param trans the transform of the current drawing position + * @param dest the PDF destination + * @param linkType the type of link, internal or external */ public void addLink(Rectangle2D bounds, AffineTransform trans, String dest, int linkType) { AffineTransform at = getTransform(); @@ -224,6 +281,18 @@ public class PDFGraphics2D extends AbstractGraphics2D { } } + /** + * Add a JPEG image directly to the PDF document. + * This is used by the PDFImageElementBridge to draw a JPEG + * directly into the pdf document rather than converting the image into + * a bitmap and increasing the size. + * + * @param jpeg the jpeg image to draw + * @param x the x position + * @param y the y position + * @param width the width to draw the image + * @param height the height to draw the image + */ public void addJpegImage(JpegImage jpeg, float x, float y, float width, float height) { FopPDFImage fopimage = new FopPDFImage(jpeg, jpeg.getURL()); int xObjectNum = this.pdfDoc.addImage(resourceContext, fopimage).getXNumber(); @@ -275,6 +344,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { * @param y the y coordinate. * @param observer object to be notified as more of * the image is converted. + * @return true if the image was drawn * @see java.awt.Image * @see java.awt.image.ImageObserver * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) @@ -339,7 +409,9 @@ public class PDFGraphics2D extends AbstractGraphics2D { mask[maskpos++] = (byte)(alpha & 0xFF); if (alpha != 255) { hasMask = true; - if (alpha != 0) binaryMask = false; + if (alpha != 0) { + binaryMask = false; + } // System.out.println("Alpha: " + alpha); // Composite with opaque white... @@ -369,7 +441,9 @@ public class PDFGraphics2D extends AbstractGraphics2D { String ref = null; if (hasMask) { // if the mask is binary then we could convert it into a bitmask - BitmapImage fopimg = new BitmapImage("TempImageMask:" + img.toString(), buf.getWidth(), buf.getHeight(), mask, null); + BitmapImage fopimg = new BitmapImage("TempImageMask:" + + img.toString(), buf.getWidth(), + buf.getHeight(), mask, null); fopimg.setColorSpace(new PDFColorSpace(PDFColorSpace.DEVICE_GRAY)); PDFXObject xobj = pdfDoc.addImage(resourceContext, fopimg); ref = xobj.referencePDF(); @@ -385,7 +459,9 @@ public class PDFGraphics2D extends AbstractGraphics2D { mask = null; } - BitmapImage fopimg = new BitmapImage("TempImage:" + img.toString(), buf.getWidth(), buf.getHeight(), result, ref); + BitmapImage fopimg = new BitmapImage("TempImage:" + + img.toString(), buf.getWidth(), + buf.getHeight(), result, ref); fopimg.setTransparent(new PDFColor(255, 255, 255)); imageInfo = pdfDoc.addImage(resourceContext, fopimg); int xObjectNum = imageInfo.getXNumber(); @@ -420,7 +496,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { return true; } - public BufferedImage buildBufferedImage(Dimension size) { + private BufferedImage buildBufferedImage(Dimension size) { return new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); } @@ -454,6 +530,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { * @param height the height of the rectangle. * @param observer object to be notified as more of * the image is converted. + * @return true if the image was drawn * @see java.awt.Image * @see java.awt.image.ImageObserver * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) @@ -614,7 +691,8 @@ public class PDFGraphics2D extends AbstractGraphics2D { public void clip(Shape cl) { super.clip(cl); Shape newClip = getClip(); - if (newClip == null || lastClip == null || !(new Area(newClip).equals(new Area(lastClip)))) { + if (newClip == null || lastClip == null + || !(new Area(newClip).equals(new Area(lastClip)))) { graphicsState.setClip(newClip); writeClip(newClip); } @@ -625,7 +703,8 @@ public class PDFGraphics2D extends AbstractGraphics2D { public void setClip(Shape cl) { super.setClip(cl); Shape newClip = getClip(); - if (newClip == null || lastClip == null || !(new Area(newClip).equals(new Area(lastClip)))) { + if (newClip == null || lastClip == null + || !(new Area(newClip).equals(new Area(lastClip)))) { for (int count = graphicsState.getStackLevel(); count > baseLevel; count--) { currentStream.write("Q\n"); } @@ -641,6 +720,14 @@ public class PDFGraphics2D extends AbstractGraphics2D { lastClip = newClip; } */ + + /** + * Set the clipping shape for future PDF drawing in the current graphics state. + * This sets creates and writes a clipping shape that will apply + * to future drawings in the current graphics state. + * + * @param s the clipping shape + */ protected void writeClip(Shape s) { if (s == null) { return; @@ -685,6 +772,14 @@ public class PDFGraphics2D extends AbstractGraphics2D { currentStream.write("n\n"); } + /** + * Apply the java Color to PDF. + * This converts the java colour to a PDF colour and + * sets it for the next drawing. + * + * @param col the java colour + * @param fill true if the colour will be used for filling + */ protected void applyColor(Color col, boolean fill) { Color c = col; if (c.getColorSpace().getType() @@ -717,6 +812,15 @@ public class PDFGraphics2D extends AbstractGraphics2D { } } + /** + * Apply the java paint to the PDF. + * This takes the java paint sets up the appropraite PDF commands + * for the drawing with that paint. + * Currently this supports the gradients and patterns from batik. + * + * @param paint the paint to convert to PDF + * @param fill true if the paint should be set for filling + */ protected void applyPaint(Paint paint, boolean fill) { if (paint instanceof LinearGradientPaint) { @@ -804,7 +908,8 @@ public class PDFGraphics2D extends AbstractGraphics2D { Color[] cols = rgp.getColors(); ArrayList someColors = new ArrayList(); for (int count = 0; count < cols.length; count++) { - someColors.add(new PDFColor(cols[count].getRed(), cols[count].getGreen(), cols[count].getBlue())); + Color cc = cols[count]; + someColors.add(new PDFColor(cc.getRed(), cc.getGreen(), cc.getBlue())); } float[] fractions = rgp.getFractions(); @@ -821,72 +926,81 @@ public class PDFGraphics2D extends AbstractGraphics2D { } else if (paint instanceof PatternPaint) { PatternPaint pp = (PatternPaint)paint; - Rectangle2D rect = pp.getPatternRect(); - - FontInfo fi = new FontInfo(); - FontSetup.setup(fi, null); - - PDFResources res = pdfDoc.makeResources(); - PDFResourceContext context = new PDFResourceContext(0, pdfDoc, res); - PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fi, - pdfDoc, context, pageRef, - "", 0, - currentYPosition, currentXPosition); - pattGraphic.gc = (GraphicContext)this.gc.clone(); - pattGraphic.gc.validateTransformStack(); - pattGraphic.setOutputStream(outputStream); - - GraphicsNode gn = pp.getGraphicsNode(); - gn.paint(pattGraphic); - - StringWriter pattStream = new StringWriter(); - pattStream.write("q\n"); - - // this makes the pattern the right way up, since - // it is outside the original transform around the - // whole svg document - pattStream.write("1 0 0 -1 0 " + (rect.getHeight() + rect.getY()) + " cm\n"); - - pattStream.write(pattGraphic.getString()); - pattStream.write("Q"); - - ArrayList bbox = new ArrayList(); - bbox.add(new Double(0)); - bbox.add(new Double(0)); - bbox.add(new Double(rect.getWidth() + rect.getX())); - bbox.add(new Double(rect.getHeight() + rect.getY())); - - ArrayList translate = new ArrayList(); - AffineTransform pattt = pp.getPatternTransform(); - pattt.translate(rect.getWidth() + rect.getX(), rect.getHeight() + rect.getY()); - double[] flatmatrix = new double[6]; - pattt.getMatrix(flatmatrix); - translate.add(new Double(flatmatrix[0])); - translate.add(new Double(flatmatrix[1])); - translate.add(new Double(flatmatrix[2])); - translate.add(new Double(flatmatrix[3])); - translate.add(new Double(flatmatrix[4])); - translate.add(new Double(flatmatrix[5])); - - FontSetup.addToResources(pdfDoc, res, fi); - - PDFPattern myPat = pdfDoc.makePattern(resourceContext, 1, res, 1, 1, bbox, - rect.getWidth(), rect.getHeight(), - translate, null, pattStream.getBuffer()); + createPattern(pp, fill); + } + } - currentStream.write(myPat.getColorSpaceOut(fill)); + private void createPattern(PatternPaint pp, boolean fill) { + Rectangle2D rect = pp.getPatternRect(); + + FontInfo fi = new FontInfo(); + FontSetup.setup(fi, null); + + PDFResources res = pdfDoc.makeResources(); + PDFResourceContext context = new PDFResourceContext(0, pdfDoc, res); + PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fi, + pdfDoc, context, pageRef, + "", 0); + pattGraphic.gc = (GraphicContext)this.gc.clone(); + pattGraphic.gc.validateTransformStack(); + pattGraphic.setOutputStream(outputStream); + + GraphicsNode gn = pp.getGraphicsNode(); + gn.paint(pattGraphic); + + StringWriter pattStream = new StringWriter(); + pattStream.write("q\n"); + + // this makes the pattern the right way up, since + // it is outside the original transform around the + // whole svg document + pattStream.write("1 0 0 -1 0 " + (rect.getHeight() + rect.getY()) + " cm\n"); + + pattStream.write(pattGraphic.getString()); + pattStream.write("Q"); + + ArrayList bbox = new ArrayList(); + bbox.add(new Double(0)); + bbox.add(new Double(0)); + bbox.add(new Double(rect.getWidth() + rect.getX())); + bbox.add(new Double(rect.getHeight() + rect.getY())); + + ArrayList translate = new ArrayList(); + AffineTransform pattt = pp.getPatternTransform(); + pattt.translate(rect.getWidth() + rect.getX(), rect.getHeight() + rect.getY()); + double[] flatmatrix = new double[6]; + pattt.getMatrix(flatmatrix); + translate.add(new Double(flatmatrix[0])); + translate.add(new Double(flatmatrix[1])); + translate.add(new Double(flatmatrix[2])); + translate.add(new Double(flatmatrix[3])); + translate.add(new Double(flatmatrix[4])); + translate.add(new Double(flatmatrix[5])); + + FontSetup.addToResources(pdfDoc, res, fi); + + PDFPattern myPat = pdfDoc.makePattern(resourceContext, 1, res, 1, 1, bbox, + rect.getWidth(), rect.getHeight(), + translate, null, pattStream.getBuffer()); + + currentStream.write(myPat.getColorSpaceOut(fill)); - if (outputStream != null) { - try { - this.pdfDoc.output(outputStream); - } catch (IOException ioe) { - // ignore exception, will be thrown again later - } + if (outputStream != null) { + try { + this.pdfDoc.output(outputStream); + } catch (IOException ioe) { + // ignore exception, will be thrown again later } - } } + /** + * Apply the stroke to the PDF. + * This takes the java stroke and outputs the appropriate settings + * to the PDF so that the stroke attributes are handled. + * + * @param stroke the java stroke + */ protected void applyStroke(Stroke stroke) { if (stroke instanceof BasicStroke) { BasicStroke bs = (BasicStroke)stroke; @@ -1015,7 +1129,9 @@ public class PDFGraphics2D extends AbstractGraphics2D { * left, in which case the coordinate supplied is the location of the * leftmost character on the baseline. * @param s the String to be rendered - * @param x, y the coordinates where the String + * @param x the coordinate where the String + * should be rendered + * @param y the coordinate where the String * should be rendered * @see #setPaint * @see java.awt.Graphics#setColor @@ -1042,7 +1158,8 @@ public class PDFGraphics2D extends AbstractGraphics2D { fontState = new FontState(fname, metrics, siz * 1000); } else { FontMetric metrics = fontInfo.getMetricsFor(ovFontState.getFontName()); - fontState = new FontState(ovFontState.getFontName(), metrics, ovFontState.getFontSize()); + fontState = new FontState(ovFontState.getFontName(), + metrics, ovFontState.getFontSize()); ovFontState = null; } String name; @@ -1080,7 +1197,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { boolean kerningAvailable = false; kerning = fontState.getKerning(); - if (kerning != null &&!kerning.isEmpty()) { + if (kerning != null && !kerning.isEmpty()) { kerningAvailable = true; } @@ -1088,11 +1205,11 @@ public class PDFGraphics2D extends AbstractGraphics2D { boolean useMultiByte = false; org.apache.fop.render.pdf.Font f = (org.apache.fop.render.pdf.Font)fontInfo.getFonts().get(name); - if (f instanceof LazyFont){ - if (((LazyFont) f).getRealFont() instanceof CIDFont){ + if (f instanceof LazyFont) { + if (((LazyFont) f).getRealFont() instanceof CIDFont) { useMultiByte = true; } - } else if (f instanceof CIDFont){ + } else if (f instanceof CIDFont) { useMultiByte = true; } @@ -1186,10 +1303,11 @@ public class PDFGraphics2D extends AbstractGraphics2D { : (int)uniBytes[i]; String hexString = Integer.toHexString(b); - if (hexString.length() == 1) + if (hexString.length() == 1) { buf = buf.append("0" + hexString); - else + } else { buf = buf.append(hexString); + } } return buf.toString(); @@ -1210,7 +1328,9 @@ public class PDFGraphics2D extends AbstractGraphics2D { * coordinate supplied is the location of the leftmost character * on the baseline. * @param iterator the iterator whose text is to be rendered - * @param x, y the coordinates where the iterator's text is to be + * @param x the coordinate where the iterator's text is to be + * rendered + * @param y the coordinate where the iterator's text is to be * rendered * @see #setPaint * @see java.awt.Graphics#setColor @@ -1381,6 +1501,15 @@ public class PDFGraphics2D extends AbstractGraphics2D { } } + /** + * Do the PDF drawing command. + * This does the PDF drawing command according to fill + * stroke and winding rule. + * + * @param fill true if filling the path + * @param stroke true if stroking the path + * @param nonzero true if using the non-zero winding rule + */ protected void doDrawing(boolean fill, boolean stroke, boolean nonzero) { if (fill) { if (stroke) { @@ -1405,6 +1534,8 @@ public class PDFGraphics2D extends AbstractGraphics2D { /** * Returns the device configuration associated with this * Graphics2D. + * + * @return the PDF graphics configuration */ public GraphicsConfiguration getDeviceConfiguration() { return new PDFGraphicsConfiguration(); diff --git a/src/org/apache/fop/svg/PDFGraphicsConfiguration.java b/src/org/apache/fop/svg/PDFGraphicsConfiguration.java index 1392101ed..7d13a03f8 100644 --- a/src/org/apache/fop/svg/PDFGraphicsConfiguration.java +++ b/src/org/apache/fop/svg/PDFGraphicsConfiguration.java @@ -1,20 +1,19 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 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.*; -import java.awt.Font; -import java.awt.Image; -import java.awt.image.*; -import java.awt.font.*; -import java.awt.geom.*; -import java.awt.color.ColorSpace; -import java.awt.image.renderable.*; +import java.awt.GraphicsConfiguration; +import java.awt.Rectangle; +import java.awt.GraphicsDevice; +import java.awt.Transparency; +import java.awt.image.ColorModel; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; /** * Our implementation of the class that returns information about @@ -22,28 +21,38 @@ import java.awt.image.renderable.*; */ class PDFGraphicsConfiguration extends GraphicsConfiguration { // We use this to get a good colormodel.. - static BufferedImage BIWithAlpha = + private static final BufferedImage BI_WITH_ALPHA = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); // We use this to get a good colormodel.. - static BufferedImage BIWithOutAlpha = + private static final BufferedImage BI_WITHOUT_ALPHA = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); /** * Construct a buffered image with an alpha channel, unless * transparencty is OPAQUE (no alpha at all). + * + * @param width the width of the image + * @param height the height of the image + * @param transparency the alpha value of the image + * @return the new buffered image */ public BufferedImage createCompatibleImage(int width, int height, int transparency) { - if (transparency == Transparency.OPAQUE) + if (transparency == Transparency.OPAQUE) { return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); - else + } else { return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + } } /** * Construct a buffered image with an alpha channel. + * + * @param width the width of the image + * @param height the height of the image + * @return the new buffered image */ public BufferedImage createCompatibleImage(int width, int height) { return new BufferedImage(width, height, @@ -55,6 +64,8 @@ class PDFGraphicsConfiguration extends GraphicsConfiguration { * I couldn't figure out how to get this for the current * page from the PDFDocument (this still works for now, * but it should be fixed...). + * + * @return the bounds of the PDF document page */ public Rectangle getBounds() { System.out.println("getting getBounds"); @@ -63,23 +74,30 @@ class PDFGraphicsConfiguration extends GraphicsConfiguration { /** * Return a good default color model for this 'device'. + * @return the colour model for the configuration */ public ColorModel getColorModel() { - return BIWithAlpha.getColorModel(); + return BI_WITH_ALPHA.getColorModel(); } /** * Return a good color model given transparency + * + * @param transparency the alpha value for the colour model + * @return the colour model for the configuration */ public ColorModel getColorModel(int transparency) { - if (transparency == Transparency.OPAQUE) - return BIWithOutAlpha.getColorModel(); - else - return BIWithAlpha.getColorModel(); + if (transparency == Transparency.OPAQUE) { + return BI_WITHOUT_ALPHA.getColorModel(); + } else { + return BI_WITH_ALPHA.getColorModel(); + } } /** * The default transform (1:1). + * + * @return the default transform for the configuration */ public AffineTransform getDefaultTransform() { System.out.println("getting getDefaultTransform"); @@ -90,6 +108,8 @@ class PDFGraphicsConfiguration extends GraphicsConfiguration { * The normalizing transform (1:1) (since we currently * render images at 72dpi, which we might want to change * in the future). + * + * @return the normalizing transform for the configuration */ public AffineTransform getNormalizingTransform() { System.out.println("getting getNormalizingTransform"); @@ -98,6 +118,8 @@ class PDFGraphicsConfiguration extends GraphicsConfiguration { /** * Return our dummy instance of GraphicsDevice + * + * @return the PDF graphics device */ public GraphicsDevice getDevice() { return new PDFGraphicsDevice(this); diff --git a/src/org/apache/fop/svg/PDFGraphicsDevice.java b/src/org/apache/fop/svg/PDFGraphicsDevice.java index ff2fa430f..048b7865c 100644 --- a/src/org/apache/fop/svg/PDFGraphicsDevice.java +++ b/src/org/apache/fop/svg/PDFGraphicsDevice.java @@ -1,16 +1,15 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 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.*; -import java.awt.Image; -import java.awt.image.*; -import java.awt.image.renderable.*; +import java.awt.GraphicsDevice; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsConfigTemplate; /** * This implements the GraphicsDevice interface as appropriate for @@ -23,9 +22,11 @@ class PDFGraphicsDevice extends GraphicsDevice { /** * The Graphics Config that created us... */ - GraphicsConfiguration gc; + protected GraphicsConfiguration gc; /** + * Create a new PDF graphics device. + * * @param The gc we should reference */ PDFGraphicsDevice(PDFGraphicsConfiguration gc) { @@ -34,6 +35,9 @@ class PDFGraphicsDevice extends GraphicsDevice { /** * Ignore template and return the only config we have + * + * @param gct the template configuration + * @return the best configuration which is the only one */ public GraphicsConfiguration getBestConfiguration( GraphicsConfigTemplate gct) { @@ -42,6 +46,8 @@ class PDFGraphicsDevice extends GraphicsDevice { /** * Return an array of our one GraphicsConfig + * + * @return an array containing the one graphics configuration */ public GraphicsConfiguration[] getConfigurations() { return new GraphicsConfiguration[]{ gc }; @@ -49,6 +55,8 @@ class PDFGraphicsDevice extends GraphicsDevice { /** * Return out sole GraphicsConfig. + * + * @return the grpahics configuration that created this object */ public GraphicsConfiguration getDefaultConfiguration() { return gc; @@ -56,6 +64,8 @@ class PDFGraphicsDevice extends GraphicsDevice { /** * Generate an IdString.. + * + * @return the ID string for this device, uses toString */ public String getIDstring() { return toString(); @@ -63,6 +73,8 @@ class PDFGraphicsDevice extends GraphicsDevice { /** * Let the caller know that we are "a printer" + * + * @return the type which is always printer */ public int getType() { return GraphicsDevice.TYPE_PRINTER;