diff options
author | Keiron Liddle <keiron@apache.org> | 2002-06-28 10:09:07 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-06-28 10:09:07 +0000 |
commit | 73d16e990b458dfbd9db7d68085da601c49d9c42 (patch) | |
tree | 776879d5a2a26abec2228cacf6ff0781db239256 /src/org/apache | |
parent | 00dd98af348dcae07fa4f0ea8838ccb2603e7d94 (diff) | |
download | xmlgraphics-fop-73d16e990b458dfbd9db7d68085da601c49d9c42.tar.gz xmlgraphics-fop-73d16e990b458dfbd9db7d68085da601c49d9c42.zip |
handles pattern resources better
made stream filters externally configured
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194934 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache')
-rw-r--r-- | src/org/apache/fop/pdf/BitmapImage.java | 6 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFDocument.java | 94 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFPage.java | 45 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFPattern.java | 40 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFResourceContext.java | 83 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFResources.java | 8 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFStream.java | 37 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/FontSetup.java | 3 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/FopPDFImage.java | 10 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFRenderer.java | 10 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFDocumentGraphics2D.java | 6 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFGraphics2D.java | 91 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFTextElementBridge.java | 4 |
13 files changed, 285 insertions, 152 deletions
diff --git a/src/org/apache/fop/pdf/BitmapImage.java b/src/org/apache/fop/pdf/BitmapImage.java index dd11de8bb..cc23f3df1 100644 --- a/src/org/apache/fop/pdf/BitmapImage.java +++ b/src/org/apache/fop/pdf/BitmapImage.java @@ -8,7 +8,7 @@ package org.apache.fop.pdf; import java.io.IOException; - +import java.util.HashMap; public class BitmapImage implements PDFImage { int m_height; int m_width; @@ -18,6 +18,7 @@ public class BitmapImage implements PDFImage { String maskRef; PDFColor transparent = null; String key; + HashMap filters; public BitmapImage(String k, int width, int height, byte[] result, String mask) { @@ -31,6 +32,7 @@ public class BitmapImage implements PDFImage { } public void setup(PDFDocument doc) { + filters = doc.getFilterMap(); } public String getKey() { @@ -87,7 +89,7 @@ public class BitmapImage implements PDFImage { imgStream.setData(m_bitmaps); - imgStream.addDefaultFilters(); + imgStream.addDefaultFilters(filters, PDFStream.CONTENT_FILTER); return imgStream; } diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index 79d7dde7b..b1471a3b6 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -136,10 +136,17 @@ public class PDFDocument { protected HashMap xObjectsMap = new HashMap(); /** + * the Font Map. + */ + protected HashMap fontMap = new HashMap(); + + /** * the objects themselves */ protected ArrayList pendingLinks = null; + protected HashMap filterMap = new HashMap(); + /** * creates an empty PDF document <p> * @@ -176,6 +183,14 @@ public class PDFDocument { this.info.setProducer(producer); } + public void setFilterMap(HashMap map) { + filterMap = map; + } + + public HashMap getFilterMap() { + return filterMap; + } + /** * Make a /Catalog (Root) object. This object is written in * the trailer. @@ -426,7 +441,7 @@ public class PDFDocument { * It's optional, the default is the identity matrix * @param theFunction The PDF Function that maps an (x,y) location to a color */ - public PDFShading makeShading(int theShadingType, + public PDFShading makeShading(PDFResourceContext res, int theShadingType, PDFColorSpace theColorSpace, ArrayList theBackground, ArrayList theBBox, boolean theAntiAlias, ArrayList theDomain, @@ -442,7 +457,11 @@ public class PDFDocument { this.objects.add(shading); // add this shading to resources - this.resources.addShading(shading); + if(res != null) { + res.getPDFResources().addShading(shading); + } else { + this.resources.addShading(shading); + } return (shading); } @@ -466,7 +485,7 @@ public class PDFDocument { * @param theExtend ArrayList of Booleans of whether to extend teh start and end colors past the start and end points * The default is [false, false] */ - public PDFShading makeShading(int theShadingType, + public PDFShading makeShading(PDFResourceContext res, int theShadingType, PDFColorSpace theColorSpace, ArrayList theBackground, ArrayList theBBox, boolean theAntiAlias, ArrayList theCoords, @@ -481,8 +500,11 @@ public class PDFDocument { theDomain, theFunction, theExtend); - this.resources.addShading(shading); - + if(res != null) { + res.getPDFResources().addShading(shading); + } else { + this.resources.addShading(shading); + } this.objects.add(shading); return (shading); } @@ -509,7 +531,7 @@ public class PDFDocument { * @param theDecode ArrayList of Doubles see PDF 1.3 spec pages 303 to 312. * @param theFunction the PDFFunction */ - public PDFShading makeShading(int theShadingType, + public PDFShading makeShading(PDFResourceContext res, int theShadingType, PDFColorSpace theColorSpace, ArrayList theBackground, ArrayList theBBox, boolean theAntiAlias, @@ -528,7 +550,11 @@ public class PDFDocument { theBitsPerFlag, theDecode, theFunction); - this.resources.addShading(shading); + if(res != null) { + res.getPDFResources().addShading(shading); + } else { + this.resources.addShading(shading); + } this.objects.add(shading); return (shading); @@ -554,7 +580,7 @@ public class PDFDocument { * @param theVerticesPerRow number of vertices in each "row" of the lattice. * @param theFunction The PDFFunction that's mapped on to this shape */ - public PDFShading makeShading(int theShadingType, + public PDFShading makeShading(PDFResourceContext res, int theShadingType, PDFColorSpace theColorSpace, ArrayList theBackground, ArrayList theBBox, boolean theAntiAlias, @@ -572,7 +598,11 @@ public class PDFDocument { theBitsPerComponent, theDecode, theVerticesPerRow, theFunction); - this.resources.addShading(shading); + if(res != null) { + res.getPDFResources().addShading(shading); + } else { + this.resources.addShading(shading); + } this.objects.add(shading); @@ -593,7 +623,7 @@ public class PDFDocument { * @param theXUID Optional vector of Integers that uniquely identify the pattern * @param thePatternDataStream The stream of pattern data to be tiled. */ - public PDFPattern makePattern(int thePatternType, // 1 + public PDFPattern makePattern(PDFResourceContext res, int thePatternType, // 1 PDFResources theResources, int thePaintType, int theTilingType, ArrayList theBBox, double theXStep, double theYStep, ArrayList theMatrix, ArrayList theXUID, StringBuffer thePatternDataStream) { @@ -607,7 +637,11 @@ public class PDFDocument { theMatrix, theXUID, thePatternDataStream); - this.resources.addPattern(pattern); + if(res != null) { + res.getPDFResources().addPattern(pattern); + } else { + this.resources.addPattern(pattern); + } this.objects.add(pattern); return (pattern); @@ -622,7 +656,7 @@ public class PDFDocument { * @param theExtGState optional: the extended graphics state, if used. * @param theMatrix Optional:ArrayList of Doubles that specify the matrix. */ - public PDFPattern makePattern(int thePatternType, PDFShading theShading, + public PDFPattern makePattern(PDFResourceContext res, int thePatternType, PDFShading theShading, ArrayList theXUID, StringBuffer theExtGState, ArrayList theMatrix) { String thePatternName = new String("Pa" + (++this.patternCount)); @@ -631,7 +665,11 @@ public class PDFDocument { thePatternName, 2, theShading, theXUID, theExtGState, theMatrix); - this.resources.addPattern(pattern); + if(res != null) { + res.getPDFResources().addPattern(pattern); + } else { + this.resources.addPattern(pattern); + } this.objects.add(pattern); return (pattern); @@ -646,7 +684,7 @@ public class PDFDocument { return; } - public PDFPattern createGradient(boolean radial, + public PDFPattern createGradient(PDFResourceContext res, boolean radial, PDFColorSpace theColorspace, ArrayList theColors, ArrayList theBounds, ArrayList theCoords) { @@ -697,7 +735,7 @@ public class PDFDocument { if (radial) { if (theCoords.size() == 6) { - myShad = this.makeShading(3, this.colorspace, null, null, + myShad = this.makeShading(res, 3, this.colorspace, null, null, false, theCoords, null, myfunky, null); } else { // if the center x, center y, and radius specifiy @@ -711,18 +749,18 @@ public class PDFDocument { newCoords.add(theCoords.get(1)); newCoords.add(new Double(0.0)); - myShad = this.makeShading(3, this.colorspace, null, null, + myShad = this.makeShading(res, 3, this.colorspace, null, null, false, newCoords, null, myfunky, null); } } else { - myShad = this.makeShading(2, this.colorspace, null, null, false, + myShad = this.makeShading(res, 2, this.colorspace, null, null, false, theCoords, null, myfunky, null); } - myPattern = this.makePattern(2, myShad, null, null, null); + myPattern = this.makePattern(res, 2, myShad, null, null, null); return (myPattern); } @@ -757,8 +795,11 @@ public class PDFDocument { this.objects.add(iccStream); return iccStream; } - - + + public HashMap getFontMap() { + return fontMap; + } + /** * make a Type1 /Font object * @@ -772,6 +813,9 @@ public class PDFDocument { public PDFFont makeFont(String fontname, String basefont, String encoding, FontMetric metrics, FontDescriptor descriptor) { + if(fontMap.containsKey(basefont)) { + return (PDFFont)fontMap.get(basefont); + } /* * create a PDFFont with the next object number and add to the @@ -918,7 +962,11 @@ public class PDFDocument { return gstate; } - public PDFXObject addImage(PDFImage img) { + public PDFXObject addImage(PDFResourceContext res, PDFImage img) { + if(res != null) { + res.getPDFResources().setXObjects(xObjects); + } + // check if already created String key = img.getKey(); PDFXObject xObject = (PDFXObject)xObjectsMap.get(key); @@ -1092,7 +1140,7 @@ public class PDFDocument { * * @return the stream object created */ - public PDFStream makeStream() { + public PDFStream makeStream(String type) { /* * create a PDFStream with the next object number and add it @@ -1100,7 +1148,7 @@ public class PDFDocument { * to the list of objects */ PDFStream obj = new PDFStream(++this.objectcount); - obj.addDefaultFilters(); + obj.addDefaultFilters(filterMap, type); this.objects.add(obj); return obj; diff --git a/src/org/apache/fop/pdf/PDFPage.java b/src/org/apache/fop/pdf/PDFPage.java index 739abe955..807dbc1d8 100644 --- a/src/org/apache/fop/pdf/PDFPage.java +++ b/src/org/apache/fop/pdf/PDFPage.java @@ -21,7 +21,7 @@ package org.apache.fop.pdf; * to the memory profile this was causing OOM issues. So, we store * only the object ID of the parent, rather than the parent itself. */ -public class PDFPage extends PDFObject { +public class PDFPage extends PDFResourceContext { /** * the page's parent, a PDF reference object @@ -29,11 +29,6 @@ public class PDFPage extends PDFObject { protected String parent; /** - * the page's /Resource object - */ - protected PDFResources resources; - - /** * the contents stream */ protected PDFStream contents; @@ -49,12 +44,6 @@ public class PDFPage extends PDFObject { protected int pageheight; /** - * the list of annotation objects for this page - */ - protected PDFAnnotList annotList; - protected PDFDocument document; - - /** * create a /Page object * * @param number the object's number @@ -67,16 +56,12 @@ public class PDFPage extends PDFObject { int pagewidth, int pageheight) { /* generic creation of object */ - super(number); + super(number, doc, resources); /* set fields using parameters */ - this.document = doc; - this.resources = resources; this.contents = contents; this.pagewidth = pagewidth; this.pageheight = pageheight; - - this.annotList = null; } /** @@ -91,15 +76,11 @@ public class PDFPage extends PDFObject { int pagewidth, int pageheight) { /* generic creation of object */ - super(number); + super(number, doc, resources); /* set fields using parameters */ - this.document = doc; - this.resources = resources; this.pagewidth = pagewidth; this.pageheight = pageheight; - - this.annotList = null; } /** @@ -121,26 +102,6 @@ public class PDFPage extends PDFObject { } /** - * set this page's annotation list - * - * @param annotList a PDFAnnotList list of annotations - */ - public void addAnnotation(PDFObject annot) { - if(this.annotList == null) { - this.annotList = document.makeAnnotList(); - } - this.annotList.addAnnot(annot); - } - - public void addGState(PDFGState gstate) { - this.resources.addGState(gstate); - } - - public void addShading(PDFShading shading) { - this.resources.addShading(shading); - } - - /** * represent this object as PDF * * @return the PDF string diff --git a/src/org/apache/fop/pdf/PDFPattern.java b/src/org/apache/fop/pdf/PDFPattern.java index ab9c0b645..432af941c 100644 --- a/src/org/apache/fop/pdf/PDFPattern.java +++ b/src/org/apache/fop/pdf/PDFPattern.java @@ -9,6 +9,9 @@ package org.apache.fop.pdf; // Java... import java.util.ArrayList; +import java.util.HashMap; +import java.io.ByteArrayOutputStream; +import java.io.IOException; /** * class representing a PDF Function. @@ -32,7 +35,7 @@ public class PDFPattern extends PDFPathPaint { /** * Either one (1) for tiling, or two (2) for shading. */ - protected int patternType = 2; // Default + protected int patternType = 2; // Default /** * The name of the pattern such as "Pa1" or "Pattern1" @@ -75,11 +78,11 @@ public class PDFPattern extends PDFPathPaint { protected ArrayList xUID = null; /** + * TODO use PDFGState * String representing the extended Graphics state. * Probably will never be used like this. */ protected StringBuffer extGState = null; - // eventually, need a PDFExtGSState object... but not now. /** * ArrayList of Doubles representing the Transformation matrix. @@ -128,7 +131,6 @@ public class PDFPattern extends PDFPathPaint { this.yStep = theYStep; this.matrix = theMatrix; this.xUID = theXUID; - // TODO filter this stream this.patternDataStream = thePatternDataStream; } @@ -198,12 +200,14 @@ public class PDFPattern extends PDFPathPaint { p.append(this.number + " " + this.generation + " obj\n<< \n/Type /Pattern \n"); - if (this.resources != null) { + if(this.resources != null) { p.append("/Resources " + this.resources.referencePDF() + " \n"); } p.append("/PatternType " + this.patternType + " \n"); + PDFStream dataStream = null; + if (this.patternType == 1) { p.append("/PaintType " + this.paintType + " \n"); p.append("/TilingType " + this.tilingType + " \n"); @@ -240,9 +244,19 @@ public class PDFPattern extends PDFPathPaint { } p.append("] \n"); } + // don't forget the length of the stream. if (this.patternDataStream != null) { - p.append("/Length " + (this.patternDataStream.length() + 1) + dataStream = new PDFStream(0); + dataStream.add(this.patternDataStream.toString()); + // TODO get the filters from the doc + dataStream.addDefaultFilters(new HashMap(), PDFStream.CONTENT_FILTER); + try { + p.append(dataStream.applyFilters()); + } catch(IOException e) { + + } + p.append("/Length " + (dataStream.getDataLength() + 1) + " \n"); } @@ -261,8 +275,7 @@ public class PDFPattern extends PDFPathPaint { p.append("] \n"); } - if (this.extGState - != null) { // will probably have to change this if it's used. + if (this.extGState != null) { p.append("/ExtGState " + this.extGState + " \n"); } @@ -280,8 +293,17 @@ public class PDFPattern extends PDFPathPaint { p.append(">> \n"); // stream representing the function - if (this.patternDataStream != null) { - p.append("stream\n" + this.patternDataStream + "\nendstream\n"); + if (dataStream != null) { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + baos.write(p.toString().getBytes()); + int length = dataStream.outputStreamData(baos); + + baos.write(("endobj\n").getBytes()); + return baos.toByteArray(); + } catch(IOException e) { + + } } p.append("endobj\n"); diff --git a/src/org/apache/fop/pdf/PDFResourceContext.java b/src/org/apache/fop/pdf/PDFResourceContext.java new file mode 100644 index 000000000..77039ab88 --- /dev/null +++ b/src/org/apache/fop/pdf/PDFResourceContext.java @@ -0,0 +1,83 @@ +/* + * $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.pdf; + +/** + * class representing a /Page object. + * + * There is one of these for every page in a PDF document. The object + * specifies the dimensions of the page and references a /Resources + * object, a contents stream and the page's parent in the page + * hierarchy. + * + * Modified by Mark Lillywhite, mark-fop@inomial.com. The Parent + * object was being referred to by reference, but all that we + * ever used from the Parent was it's PDF object ID, and according + * to the memory profile this was causing OOM issues. So, we store + * only the object ID of the parent, rather than the parent itself. + */ +public class PDFResourceContext extends PDFObject { + + /** + * the page's /Resource object + */ + protected PDFResources resources; + + /** + * the list of annotation objects for this page + */ + protected PDFAnnotList annotList; + protected PDFDocument document; + + /** + * + * @param number the object's number + * @param resources the /Resources object + * @param contents the content stream + * @param pagewidth the page's width in points + * @param pageheight the page's height in points + */ + public PDFResourceContext(int number, PDFDocument doc, PDFResources resources) { + + /* generic creation of object */ + super(number); + + /* set fields using parameters */ + this.document = doc; + this.resources = resources; + this.annotList = null; + } + + public PDFResources getPDFResources() { + return this.resources; + } + + /** + * set this page's annotation list + * + * @param annotList a PDFAnnotList list of annotations + */ + public void addAnnotation(PDFObject annot) { + if(this.annotList == null) { + this.annotList = document.makeAnnotList(); + } + this.annotList.addAnnot(annot); + } + + public void addGState(PDFGState gstate) { + this.resources.addGState(gstate); + } + + public void addShading(PDFShading shading) { + this.resources.addShading(shading); + } + + public byte[] toPDF() { + return null; + } +} diff --git a/src/org/apache/fop/pdf/PDFResources.java b/src/org/apache/fop/pdf/PDFResources.java index 34b5d82b9..778f05e4c 100644 --- a/src/org/apache/fop/pdf/PDFResources.java +++ b/src/org/apache/fop/pdf/PDFResources.java @@ -37,10 +37,8 @@ public class PDFResources extends PDFObject { * @param number the object's number */ public PDFResources(int number) { - /* generic creation of object */ super(number); - } /** @@ -131,7 +129,7 @@ public class PDFResources extends PDFObject { p.append("/ProcSet [ /PDF /ImageC /Text ]\n"); - if (!this.xObjects.isEmpty()) { + if (this.xObjects != null && !this.xObjects.isEmpty()) { p = p.append("/XObject <<"); for (int i = 1; i <= this.xObjects.size(); i++) { p = p.append("/Im" + i + " " @@ -147,9 +145,9 @@ public class PDFResources extends PDFObject { PDFGState gs = (PDFGState)this.gstates.get(i); p = p.append("/" + gs.getName() + " " + gs.referencePDF() - + "\n"); + + " "); } - p = p.append(" >>\n"); + p = p.append(">>\n"); } p = p.append(">>\nendobj\n"); diff --git a/src/org/apache/fop/pdf/PDFStream.java b/src/org/apache/fop/pdf/PDFStream.java index 76f2e6719..ef5dcd5f7 100644 --- a/src/org/apache/fop/pdf/PDFStream.java +++ b/src/org/apache/fop/pdf/PDFStream.java @@ -11,8 +11,8 @@ import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.Enumeration; -import org.apache.fop.configuration.Configuration; /** * class representing a PDF stream. @@ -23,6 +23,11 @@ import org.apache.fop.configuration.Configuration; * length. */ public class PDFStream extends PDFObject { + public static final String DEFAULT_FILTER = "default"; + public static final String CONTENT_FILTER = "content"; + public static final String IMAGE_FILTER = "image"; + public static final String JPEG_FILTER = "jpeg"; + public static final String FONT_FILTER = "font"; /** * the stream of PDF commands @@ -95,29 +100,22 @@ public class PDFStream extends PDFObject { } } - - public void addDefaultFilters() { - ArrayList filters = Configuration.getListValue("stream-filter-list", - Configuration.PDF); - if (filters == null) { - // try getting it as a String - String filter = Configuration.getStringValue("stream-filter-list", - Configuration.PDF); - if (filter == null) { - // built-in default to flate - addFilter(new FlateFilter()); - } else { - addFilter(filter); - } + public void addDefaultFilters(HashMap filters, String type) { + ArrayList filterset = (ArrayList)filters.get(type); + if(filterset == null) { + filterset = (ArrayList)filters.get(DEFAULT_FILTER); + } + if(filterset == null || filterset.size() == 0) { + // built-in default to flate + addFilter(new FlateFilter()); } else { - for (int i = 0; i < filters.size(); i++) { - String v = (String)filters.get(i); + for (int i = 0; i < filterset.size(); i++) { + String v = (String)filterset.get(i); addFilter(v); } } } - /** * append an array of xRGB pixels, ASCII Hex Encoding it first * @@ -175,8 +173,6 @@ public class PDFStream extends PDFObject { } } - - /** * represent as PDF. * @@ -236,7 +232,6 @@ public class PDFStream extends PDFObject { } - /** * Apply the filters to the data * in the order given and return the /Filter and /DecodeParms diff --git a/src/org/apache/fop/render/pdf/FontSetup.java b/src/org/apache/fop/render/pdf/FontSetup.java index f450a5b76..234c48219 100644 --- a/src/org/apache/fop/render/pdf/FontSetup.java +++ b/src/org/apache/fop/render/pdf/FontSetup.java @@ -189,10 +189,9 @@ public class FontSetup { * @param doc PDF document to add fonts to * @param fontInfo font info object to get font information from */ - public static void addToResources(PDFDocument doc, FontInfo fontInfo) { + public static void addToResources(PDFDocument doc, PDFResources resources, FontInfo fontInfo) { HashMap fonts = fontInfo.getUsedFonts(); Iterator e = fonts.keySet().iterator(); - PDFResources resources = doc.getResources(); while (e.hasNext()) { String f = (String)e.next(); Font font = (Font)fonts.get(f); diff --git a/src/org/apache/fop/render/pdf/FopPDFImage.java b/src/org/apache/fop/render/pdf/FopPDFImage.java index ca248b010..fac035be0 100644 --- a/src/org/apache/fop/render/pdf/FopPDFImage.java +++ b/src/org/apache/fop/render/pdf/FopPDFImage.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.awt.color.ColorSpace; import java.awt.color.ICC_ColorSpace; import java.awt.color.ICC_Profile; +import java.util.HashMap; public class FopPDFImage implements PDFImage { FopImage fopImage; @@ -32,6 +33,7 @@ public class FopPDFImage implements PDFImage { String maskRef; String softMaskRef; boolean isPS = false; + HashMap filters; public FopPDFImage(FopImage im) { fopImage = im; @@ -44,7 +46,7 @@ public class FopPDFImage implements PDFImage { } public void setup(PDFDocument doc) { - + filters = doc.getFilterMap(); if ("image/jpeg".equals(fopImage.getMimeType())) { pdfFilter = new DCTFilter(); pdfFilter.setApplied(true); @@ -55,7 +57,7 @@ public class FopPDFImage implements PDFImage { if (prof != null) { pdfICCStream = doc.makePDFICCStream(); pdfICCStream.setColorSpace(prof, pdfCS); - pdfICCStream.addDefaultFilters(); + pdfICCStream.addDefaultFilters(filters, PDFStream.CONTENT_FILTER); } } } @@ -116,7 +118,7 @@ public class FopPDFImage implements PDFImage { imgStream.addFilter(pdfFilter); } - imgStream.addDefaultFilters(); + imgStream.addDefaultFilters(filters, PDFStream.IMAGE_FILTER); return imgStream; } } @@ -170,7 +172,7 @@ public class FopPDFImage implements PDFImage { imgStream.setData(imgData); - imgStream.addDefaultFilters(); + imgStream.addDefaultFilters(filters, PDFStream.CONTENT_FILTER); return imgStream; } diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 69ed8770d..5fb059a83 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -165,7 +165,7 @@ public class PDFRenderer extends PrintRenderer { } public void stopRenderer() throws IOException { - FontSetup.addToResources(this.pdfDoc, fontInfo); + FontSetup.addToResources(pdfDoc, pdfDoc.getResources(), fontInfo); pdfDoc.outputTrailer(ostream); this.pdfDoc = null; @@ -217,7 +217,7 @@ public class PDFRenderer extends PrintRenderer { (int) Math.round(w / 1000), (int) Math.round(h / 1000)); pageReferences.put(page, currentPage.referencePDF()); } - currentStream = this.pdfDoc.makeStream(); + currentStream = this.pdfDoc.makeStream(PDFStream.CONTENT_FILTER); currentState = new PDFState(); currentState.setTransform(new AffineTransform(1, 0, 0, -1, 0, (int) Math.round(pageHeight / 1000))); @@ -498,21 +498,21 @@ public class PDFRenderer extends PrintRenderer { return; } FopPDFImage pdfimage = new FopPDFImage(fopimage); - int xobj = pdfDoc.addImage(pdfimage).getXNumber(); + int xobj = pdfDoc.addImage(null, pdfimage).getXNumber(); fact.releaseImage(url, userAgent); } else if("image/jpg".equals(mime)) { if(!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) { return; } FopPDFImage pdfimage = new FopPDFImage(fopimage); - int xobj = pdfDoc.addImage(pdfimage).getXNumber(); + int xobj = pdfDoc.addImage(null, pdfimage).getXNumber(); fact.releaseImage(url, userAgent); } else { if(!fopimage.load(FopImage.BITMAP, userAgent)) { return; } FopPDFImage pdfimage = new FopPDFImage(fopimage); - int xobj = pdfDoc.addImage(pdfimage).getXNumber(); + int xobj = pdfDoc.addImage(null, pdfimage).getXNumber(); fact.releaseImage(url, userAgent); closeText(); diff --git a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java index 355837630..628817b77 100644 --- a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java +++ b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java @@ -37,6 +37,7 @@ import org.apache.batik.ext.awt.g2d.GraphicContext; public class PDFDocumentGraphics2D extends PDFGraphics2D { OutputStream stream; + PDFPage currentPage; PDFStream pdfStream; int width; int height; @@ -69,7 +70,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D { standalone = true; this.pdfDoc = new PDFDocument(); this.pdfDoc.setProducer("FOP SVG Renderer"); - pdfStream = this.pdfDoc.makeStream(); + pdfStream = this.pdfDoc.makeStream(PDFStream.CONTENT_FILTER); graphicsState = new PDFState(); @@ -87,6 +88,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D { PDFResources pdfResources = this.pdfDoc.getResources(); currentPage = this.pdfDoc.makePage(pdfResources, width, height); + resourceContext = currentPage; currentStream.write("1 0 0 -1 0 " + height + " cm\n"); } @@ -156,7 +158,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D { currentPage.setContents(pdfStream); this.pdfDoc.addPage(currentPage); if (fontInfo != null) { - FontSetup.addToResources(this.pdfDoc, fontInfo); + FontSetup.addToResources(pdfDoc, pdfDoc.getResources(), fontInfo); } pdfDoc.outputHeader(stream); this.pdfDoc.output(stream); diff --git a/src/org/apache/fop/svg/PDFGraphics2D.java b/src/org/apache/fop/svg/PDFGraphics2D.java index 91c7389e6..db48aa2a4 100644 --- a/src/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/org/apache/fop/svg/PDFGraphics2D.java @@ -58,7 +58,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { * the PDF Document being created */ protected PDFDocument pdfDoc; - protected PDFPage currentPage; + protected PDFResourceContext resourceContext; /** * the current state of the pdf graphics @@ -113,10 +113,10 @@ public class PDFGraphics2D extends AbstractGraphics2D { * existing document. */ public PDFGraphics2D(boolean textAsShapes, FontState fs, PDFDocument doc, - PDFPage page, String font, float size, int xpos, int ypos) { + PDFResourceContext page, String font, float size, int xpos, int ypos) { super(textAsShapes); pdfDoc = doc; - currentPage = page; + resourceContext = page; currentFontName = font; currentFontSize = size; currentYPosition = ypos; @@ -175,16 +175,17 @@ public class PDFGraphics2D extends AbstractGraphics2D { if(linkType != PDFLink.EXTERNAL) { String pdfdest = "/FitR " + dest; - currentPage.addAnnotation(pdfDoc.makeLinkCurrentPage(rect, pdfdest)); + // TODO use page ref instead + resourceContext.addAnnotation(pdfDoc.makeLinkCurrentPage(rect, pdfdest)); } else { - currentPage.addAnnotation(pdfDoc.makeLink(rect, + resourceContext.addAnnotation(pdfDoc.makeLink(rect, dest, linkType)); } } public void addJpegImage(JpegImage jpeg, float x, float y, float width, float height) { FopPDFImage fopimage = new FopPDFImage(jpeg); - int xObjectNum = this.pdfDoc.addImage(fopimage).getXNumber(); + int xObjectNum = this.pdfDoc.addImage(resourceContext, fopimage).getXNumber(); AffineTransform at = getTransform(); double[] matrix = new double[6]; @@ -316,7 +317,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { // 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); fopimg.setColorSpace(new PDFColorSpace(PDFColorSpace.DEVICE_GRAY)); - PDFXObject xobj = pdfDoc.addImage(fopimg); + PDFXObject xobj = pdfDoc.addImage(resourceContext, fopimg); ref = xobj.referencePDF(); } else { mask = null; @@ -324,7 +325,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { BitmapImage fopimg = new BitmapImage("TempImage:" + img.toString(), buf.getWidth(), buf.getHeight(), result, ref); fopimg.setTransparent(new PDFColor(255, 255, 255)); - imageInfo.xObjectNum = pdfDoc.addImage(fopimg).getXNumber(); + imageInfo.xObjectNum = pdfDoc.addImage(resourceContext, fopimg).getXNumber(); imageInfos.put(img, imageInfo); } @@ -476,7 +477,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { if(c.getAlpha() != 255) { PDFGState gstate = pdfDoc.makeGState(); gstate.setAlpha(c.getAlpha() / 255f, false); - currentPage.addGState(gstate); + resourceContext.addGState(gstate); currentStream.write("/" + gstate.getName() + " gs\n"); } @@ -655,43 +656,63 @@ public class PDFGraphics2D extends AbstractGraphics2D { color1.getVector(), color2.getVector(), 1.0); PDFColorSpace aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); - PDFPattern myPat = this.pdfDoc.createGradient(false, aColorSpace, + PDFResources res = pdfDoc.makeResources(); + PDFPattern myPat = this.pdfDoc.createGradient(resourceContext, false, aColorSpace, someColors, null, theCoords); currentStream.write(myPat.getColorSpaceOut(fill)); } else if (paint instanceof RadialGradientPaint) { - System.err.println("Radial gradient paint not supported"); - RadialGradientPaint rgp = (RadialGradientPaint)paint; -/* + + float ar = rgp.getRadius(); + Point2D ac = rgp.getCenterPoint(); + Point2D af = rgp.getFocusPoint(); + ArrayList theCoords = new ArrayList(); - theCoords.add( new Double(currentXPosition / 1000f + acx)); - theCoords.add( new Double(currentYPosition / 1000f - acy)); + theCoords.add( new Double(currentXPosition + ac.getX())); + theCoords.add( new Double(currentYPosition - ac.getY())); theCoords.add(new Double(0)); - theCoords.add( new Double(currentXPosition / 1000f + afx)); // Fx - theCoords.add(new Double(currentYPosition / 1000f - afy)); // Fy + theCoords.add( new Double(currentXPosition + af.getX())); // Fx + theCoords.add(new Double(currentYPosition - af.getY())); // Fy theCoords.add(new Double(ar)); - float lastoffset = 0; - PDFColor color = new PDFColor(0, 0, 0); - color = new PDFColor(red, green, blue); + 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())); + } - float offset = stop.getOffset().getBaseVal(); -// create bounds from last to offset + float[] fractions = rgp.getFractions(); + ArrayList theBounds = new ArrayList(); + float lastoffset = 0; + for(int count = 0; count < fractions.length; count++) { + float offset = fractions[count]; + // create bounds from last to offset lastoffset = offset; - someColors.add(color); } - PDFPattern myPat = pdfDoc.createGradient(true, aColorSpace, + PDFColorSpace colSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); + PDFPattern myPat = pdfDoc.createGradient(resourceContext, true, colSpace, someColors, theBounds, theCoords); currentStream.write(myPat.getColorSpaceOut(fill)); -*/ + } else if (paint instanceof PatternPaint) { PatternPaint pp = (PatternPaint)paint; Rectangle2D rect = pp.getPatternRect(); - PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontState, - pdfDoc, currentPage, + FontInfo fi = new FontInfo(); + FontSetup.setup(fi); + FontState fs = null; + try { + fs = new FontState(fi, "sans-serif", "normal", + "normal", 1, 0); + } catch (org.apache.fop.apps.FOPException fope) { + fope.printStackTrace(); + } + PDFResources res = pdfDoc.makeResources(); + PDFResourceContext context = new PDFResourceContext(0, pdfDoc, res); + PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fs, + pdfDoc, context, currentFontName, currentFontSize, currentYPosition, currentXPosition); pattGraphic.gc = (GraphicContext)this.gc.clone(); @@ -722,10 +743,12 @@ public class PDFGraphics2D extends AbstractGraphics2D { translate.add(new Double(0)); translate.add(new Double(0)); translate.add(new Double(1)); - translate.add(new Double(rect.getX())); - translate.add(new Double(rect.getY())); - // TODO handle PDFResources - PDFPattern myPat = pdfDoc.makePattern(1, null, 1, 1, bbox, + translate.add(new Double(0/*rect.getX()*/)); + translate.add(new Double(0/*rect.getY()*/)); + + FontSetup.addToResources(pdfDoc, res, fi); + + PDFPattern myPat = pdfDoc.makePattern(resourceContext, 1, res, 1, 1, bbox, rect.getWidth(), rect.getHeight(), translate, null, pattStream.getBuffer()); @@ -916,11 +939,11 @@ public class PDFGraphics2D extends AbstractGraphics2D { c = getBackground(); applyColor(c, false); - if(salpha != 255 || c.getAlpha() != 255) { + if(salpha != 255/* || c.getAlpha() != 255*/) { PDFGState gstate = pdfDoc.makeGState(); gstate.setAlpha(salpha / 255f, true); //gstate.setAlpha(c.getAlpha() / 255f, false); - currentPage.addGState(gstate); + resourceContext.addGState(gstate); currentStream.write("/" + gstate.getName() + " gs\n"); } @@ -1150,7 +1173,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { if(c.getAlpha() != 255) { PDFGState gstate = pdfDoc.makeGState(); gstate.setAlpha(c.getAlpha() / 255f, true); - currentPage.addGState(gstate); + resourceContext.addGState(gstate); currentStream.write("/" + gstate.getName() + " gs\n"); } diff --git a/src/org/apache/fop/svg/PDFTextElementBridge.java b/src/org/apache/fop/svg/PDFTextElementBridge.java index 933165b97..fc2fd9fdd 100644 --- a/src/org/apache/fop/svg/PDFTextElementBridge.java +++ b/src/org/apache/fop/svg/PDFTextElementBridge.java @@ -60,9 +60,7 @@ public class PDFTextElementBridge extends SVGTextElementBridge { private boolean isSimple(BridgeContext ctx, Element element, GraphicsNode node) { // Font size, in user space units. float fs = TextUtilities.convertFontSize(element).floatValue(); - /*if(((int)fs) != fs) { - return false; - }*/ + // PDF cannot display fonts over 36pt if(fs > 36) { return false; } |