aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/pdf
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/apache/fop/pdf')
-rw-r--r--src/org/apache/fop/pdf/BitmapImage.java102
-rw-r--r--src/org/apache/fop/pdf/PDFColor.java35
-rw-r--r--src/org/apache/fop/pdf/PDFColorSpace.java89
-rw-r--r--src/org/apache/fop/pdf/PDFDocument.java59
-rw-r--r--src/org/apache/fop/pdf/PDFGState.java27
-rw-r--r--src/org/apache/fop/pdf/PDFICCStream.java30
-rw-r--r--src/org/apache/fop/pdf/PDFImage.java44
-rw-r--r--src/org/apache/fop/pdf/PDFPathPaint.java4
-rw-r--r--src/org/apache/fop/pdf/PDFPattern.java4
-rw-r--r--src/org/apache/fop/pdf/PDFShading.java13
-rw-r--r--src/org/apache/fop/pdf/PDFState.java4
-rw-r--r--src/org/apache/fop/pdf/PDFStream.java2
-rw-r--r--src/org/apache/fop/pdf/PDFXObject.java276
13 files changed, 421 insertions, 268 deletions
diff --git a/src/org/apache/fop/pdf/BitmapImage.java b/src/org/apache/fop/pdf/BitmapImage.java
new file mode 100644
index 000000000..dd11de8bb
--- /dev/null
+++ b/src/org/apache/fop/pdf/BitmapImage.java
@@ -0,0 +1,102 @@
+/*
+ * $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;
+
+import java.io.IOException;
+
+public class BitmapImage implements PDFImage {
+ int m_height;
+ int m_width;
+ int m_bitsPerPixel;
+ PDFColorSpace m_colorSpace;
+ byte[] m_bitmaps;
+ String maskRef;
+ PDFColor transparent = null;
+ String key;
+
+ public BitmapImage(String k, int width, int height, byte[] result,
+ String mask) {
+ this.key = k;
+ this.m_height = height;
+ this.m_width = width;
+ this.m_bitsPerPixel = 8;
+ this.m_colorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
+ this.m_bitmaps = result;
+ maskRef = mask;
+ }
+
+ public void setup(PDFDocument doc) {
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ // image size
+ public int getWidth() {
+ return m_width;
+ }
+
+ public int getHeight() {
+ return m_height;
+ }
+
+ public void setColorSpace(PDFColorSpace cs) {
+ m_colorSpace = cs;
+ }
+
+ // DeviceGray, DeviceRGB, or DeviceCMYK
+ public PDFColorSpace getColorSpace() {
+ return m_colorSpace;
+ }
+
+ // bits per pixel
+ public int getBitsPerPixel() {
+ return m_bitsPerPixel;
+ }
+
+ public void setTransparent(PDFColor t) {
+ transparent = t;
+ }
+
+ // For transparent images
+ public boolean isTransparent() {
+ return transparent != null;
+ }
+
+ public PDFColor getTransparentColor() {
+ return transparent;
+ }
+
+ public String getMask() {
+ return null;
+ }
+
+ public String getSoftMask() {
+ return maskRef;
+ }
+
+ public PDFStream getDataStream() throws IOException {
+ // delegate the stream work to PDFStream
+ PDFStream imgStream = new PDFStream(0);
+
+ imgStream.setData(m_bitmaps);
+
+ imgStream.addDefaultFilters();
+ return imgStream;
+ }
+
+ public PDFICCStream getICCStream() {
+ return null;
+ }
+
+ public boolean isPS() {
+ return false;
+ }
+ }
+
diff --git a/src/org/apache/fop/pdf/PDFColor.java b/src/org/apache/fop/pdf/PDFColor.java
index 379b1e2d8..b1f589be6 100644
--- a/src/org/apache/fop/pdf/PDFColor.java
+++ b/src/org/apache/fop/pdf/PDFColor.java
@@ -12,10 +12,6 @@ import java.util.ArrayList;
import java.io.IOException;
import java.io.PrintWriter;
-// FOP
-import org.apache.fop.datatypes.ColorType;
-import org.apache.fop.datatypes.ColorSpace;
-
public class PDFColor extends PDFPathPaint {
protected static double blackFactor = 2.0; // could be 3.0 as well.
protected double red = -1.0;
@@ -27,18 +23,9 @@ public class PDFColor extends PDFPathPaint {
protected double yellow = -1.0;
protected double black = -1.0;
- public PDFColor(org.apache.fop.datatypes.ColorType theColor) {
- this.colorSpace = new ColorSpace(ColorSpace.DEVICE_RGB);
- // super(theNumber)
- this.red = (double)theColor.red();
- this.green = (double)theColor.green();
- this.blue = (double)theColor.blue();
-
- }
-
public PDFColor(double theRed, double theGreen, double theBlue) {
// super(theNumber);
- this.colorSpace = new ColorSpace(ColorSpace.DEVICE_RGB);
+ this.colorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
this.red = theRed;
this.green = theGreen;
@@ -56,7 +43,7 @@ public class PDFColor extends PDFPathPaint {
double theBlack) {
// super(theNumber);//?
- this.colorSpace = new ColorSpace(ColorSpace.DEVICE_CMYK);
+ this.colorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_CMYK);
this.cyan = theCyan;
this.magenta = theMagenta;
@@ -68,12 +55,12 @@ public class PDFColor extends PDFPathPaint {
public ArrayList getVector() { // return a vector representation of the color
// in the appropriate colorspace.
ArrayList theColorVector = new ArrayList();
- if (this.colorSpace.getColorSpace() == ColorSpace.DEVICE_RGB) { // RGB
+ if (this.colorSpace.getColorSpace() == PDFColorSpace.DEVICE_RGB) { // RGB
theColorVector.add(new Double(this.red));
theColorVector.add(new Double(this.green));
theColorVector.add(new Double(this.blue));
} else if (this.colorSpace.getColorSpace()
- == ColorSpace.DEVICE_CMYK) { // CMYK
+ == PDFColorSpace.DEVICE_CMYK) { // CMYK
theColorVector.add(new Double(this.cyan));
theColorVector.add(new Double(this.magenta));
theColorVector.add(new Double(this.yellow));
@@ -127,16 +114,16 @@ public class PDFColor extends PDFPathPaint {
public void setColorSpace(int theColorSpace) {
int theOldColorSpace = this.colorSpace.getColorSpace();
if (theOldColorSpace != theColorSpace) {
- if (theOldColorSpace == ColorSpace.DEVICE_RGB) {
- if (theColorSpace == ColorSpace.DEVICE_CMYK) {
+ if (theOldColorSpace == PDFColorSpace.DEVICE_RGB) {
+ if (theColorSpace == PDFColorSpace.DEVICE_CMYK) {
this.convertRGBtoCMYK();
} else // convert to Gray?
{
this.convertRGBtoGRAY();
}
- } else if (theOldColorSpace == ColorSpace.DEVICE_CMYK) {
- if (theColorSpace == ColorSpace.DEVICE_RGB) {
+ } else if (theOldColorSpace == PDFColorSpace.DEVICE_CMYK) {
+ if (theColorSpace == PDFColorSpace.DEVICE_RGB) {
this.convertCMYKtoRGB();
} else // convert to Gray?
{
@@ -144,7 +131,7 @@ public class PDFColor extends PDFPathPaint {
}
} else // used to be Gray
{
- if (theColorSpace == ColorSpace.DEVICE_RGB) {
+ if (theColorSpace == PDFColorSpace.DEVICE_RGB) {
this.convertGRAYtoRGB();
} else // convert to CMYK?
{
@@ -161,7 +148,7 @@ public class PDFColor extends PDFPathPaint {
double tempDouble;
if (this.colorSpace.getColorSpace()
- == ColorSpace.DEVICE_RGB) { // colorspace is RGB
+ == PDFColorSpace.DEVICE_RGB) { // colorspace is RGB
// according to pdfspec 12.1 p.399
// if the colors are the same then just use the g or G operator
boolean same = false;
@@ -190,7 +177,7 @@ public class PDFColor extends PDFPathPaint {
}
} // end of output RGB
else if (this.colorSpace.getColorSpace()
- == ColorSpace.DEVICE_CMYK) { // colorspace is CMYK
+ == PDFColorSpace.DEVICE_CMYK) { // colorspace is CMYK
if (fillNotStroke) { // fill
p.append(PDFNumber.doubleOut(this.cyan) + " "
diff --git a/src/org/apache/fop/pdf/PDFColorSpace.java b/src/org/apache/fop/pdf/PDFColorSpace.java
new file mode 100644
index 000000000..62992b4af
--- /dev/null
+++ b/src/org/apache/fop/pdf/PDFColorSpace.java
@@ -0,0 +1,89 @@
+/*
+ * $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;
+
+public class PDFColorSpace {
+ private boolean hasICCProfile;
+ private byte[] iccProfile;
+ private int numComponents;
+
+ // Ok... so I had some grand purpose for this, but I can't recall.
+ // I'm just writing it
+
+ public static int DEVICE_UNKNOWN = -1;
+ public static int DEVICE_GRAY = 1;
+ // what's the *official* spelling?
+ // public static int DEVICE_GREY = 1;
+ public static int DEVICE_RGB = 2;
+ public static int DEVICE_CMYK = 3;
+
+ // Are there any others?
+
+ protected int currentColorSpace = DEVICE_UNKNOWN;
+
+ public PDFColorSpace(int theColorSpace) {
+ this.currentColorSpace = theColorSpace;
+ hasICCProfile = false;
+ numComponents = calculateNumComponents();
+ }
+
+ private int calculateNumComponents() {
+ if (currentColorSpace == DEVICE_GRAY)
+ return 1;
+ else if (currentColorSpace == DEVICE_RGB)
+ return 3;
+ else if (currentColorSpace == DEVICE_CMYK)
+ return 4;
+ else
+ return 0;
+ }
+
+ public void setColorSpace(int theColorSpace) {
+ this.currentColorSpace = theColorSpace;
+ numComponents = calculateNumComponents();
+ }
+
+ public boolean hasICCProfile() {
+ return hasICCProfile;
+ }
+
+ public byte[] getICCProfile() {
+ if (hasICCProfile)
+ return iccProfile;
+ else
+ return new byte[0];
+ }
+
+ public void setICCProfile(byte[] iccProfile) {
+ this.iccProfile = iccProfile;
+ hasICCProfile = true;
+ }
+
+ public int getColorSpace() {
+ return (this.currentColorSpace);
+ }
+
+ public int getNumComponents() {
+ return numComponents;
+ }
+
+ public String getColorSpacePDFString() {
+ // shouldn't this be a select-case? I can never remember
+ // the syntax for that.
+ if (this.currentColorSpace == this.DEVICE_RGB) {
+ return ("DeviceRGB");
+ } else if (this.currentColorSpace == this.DEVICE_CMYK) {
+ return ("DeviceCMYK");
+ } else if (this.currentColorSpace == this.DEVICE_GRAY) {
+ return ("DeviceGray");
+ } else { // unknown... Error. Tell them it's RGB and hope they don't notice.
+ return ("DeviceRGB");
+ }
+ }
+
+}
diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java
index b2547e975..79d7dde7b 100644
--- a/src/org/apache/fop/pdf/PDFDocument.java
+++ b/src/org/apache/fop/pdf/PDFDocument.java
@@ -10,16 +10,9 @@
package org.apache.fop.pdf;
-// images are the one place that FOP classes outside this package get
-// referenced and I'd rather not do it
-import org.apache.fop.image.FopImage;
-
-import org.apache.fop.datatypes.ColorSpace;
-
import org.apache.fop.render.pdf.CIDFont;
import org.apache.fop.render.pdf.fonts.LazyFont;
-import org.apache.fop.datatypes.IDReferences;
import org.apache.fop.layout.FontMetric;
import org.apache.fop.layout.FontDescriptor;
// Java
@@ -111,15 +104,10 @@ public class PDFDocument {
protected PDFResources resources;
/**
- * the documents idReferences
- */
- protected IDReferences idReferences;
-
- /**
* the colorspace (0=RGB, 1=CMYK)
*/
// protected int colorspace = 0;
- protected ColorSpace colorspace = new ColorSpace(ColorSpace.DEVICE_RGB);
+ protected PDFColorSpace colorspace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
/**
* the counter for Pattern name numbering (e.g. 'Pattern1')
@@ -439,7 +427,7 @@ public class PDFDocument {
* @param theFunction The PDF Function that maps an (x,y) location to a color
*/
public PDFShading makeShading(int theShadingType,
- ColorSpace theColorSpace,
+ PDFColorSpace theColorSpace,
ArrayList theBackground, ArrayList theBBox,
boolean theAntiAlias, ArrayList theDomain,
ArrayList theMatrix,
@@ -479,7 +467,7 @@ public class PDFDocument {
* The default is [false, false]
*/
public PDFShading makeShading(int theShadingType,
- ColorSpace theColorSpace,
+ PDFColorSpace theColorSpace,
ArrayList theBackground, ArrayList theBBox,
boolean theAntiAlias, ArrayList theCoords,
ArrayList theDomain, PDFFunction theFunction,
@@ -522,7 +510,7 @@ public class PDFDocument {
* @param theFunction the PDFFunction
*/
public PDFShading makeShading(int theShadingType,
- ColorSpace theColorSpace,
+ PDFColorSpace theColorSpace,
ArrayList theBackground, ArrayList theBBox,
boolean theAntiAlias,
int theBitsPerCoordinate,
@@ -567,7 +555,7 @@ public class PDFDocument {
* @param theFunction The PDFFunction that's mapped on to this shape
*/
public PDFShading makeShading(int theShadingType,
- ColorSpace theColorSpace,
+ PDFColorSpace theColorSpace,
ArrayList theBackground, ArrayList theBBox,
boolean theAntiAlias,
int theBitsPerCoordinate,
@@ -659,7 +647,7 @@ public class PDFDocument {
}
public PDFPattern createGradient(boolean radial,
- ColorSpace theColorspace,
+ PDFColorSpace theColorspace,
ArrayList theColors, ArrayList theBounds,
ArrayList theCoords) {
PDFShading myShad;
@@ -668,7 +656,7 @@ public class PDFDocument {
ArrayList theCzero;
ArrayList theCone;
PDFPattern myPattern;
- ColorSpace theColorSpace;
+ PDFColorSpace theColorSpace;
double interpolation = (double)1.000;
ArrayList theFunctions = new ArrayList();
@@ -930,19 +918,22 @@ public class PDFDocument {
return gstate;
}
- public int addImage(FopImage img) {
+ public PDFXObject addImage(PDFImage img) {
// check if already created
- String url = img.getURL();
- PDFXObject xObject = (PDFXObject)this.xObjectsMap.get(url);
+ String key = img.getKey();
+ PDFXObject xObject = (PDFXObject)xObjectsMap.get(key);
if (xObject != null)
- return xObject.getXNumber();
- // else, create a new one
+ return xObject;
+
+ // setup image
+ img.setup(this);
+ // create a new XObject
xObject = new PDFXObject(++this.objectcount, ++this.xObjectCount,
- img, this);
+ img);
this.objects.add(xObject);
this.xObjects.add(xObject);
- this.xObjectsMap.put(url, xObject);
- return xObjectCount;
+ this.xObjectsMap.put(key, xObject);
+ return xObject;
}
/**
@@ -1029,8 +1020,8 @@ public class PDFDocument {
}
private String getGoToReference(String destination) {
- String goToReference;
- if (idReferences.doesIDExist(destination)) {
+ String goToReference = null;
+ /*if (idReferences.doesIDExist(destination)) {
if (idReferences.doesGoToReferenceExist(destination)) {
goToReference =
idReferences.getInternalLinkGoToReference(destination);
@@ -1042,16 +1033,12 @@ public class PDFDocument {
}
} else { // id was not found, so create it
- //next line by lmckenzi@ca.ibm.com
- //solves when IDNode made before IDReferences.createID called
- //idReferences.createNewId(destination);
-
idReferences.createUnvalidatedID(destination);
idReferences.addToIdValidationList(destination);
goToReference = idReferences.createInternalLinkGoTo(destination,
++this.objectcount);
addTrailerObject(idReferences.getPDFGoTo(destination));
- }
+ }*/
return goToReference;
}
@@ -1306,8 +1293,4 @@ public class PDFDocument {
return pdfBytes.length;
}
- public void setIDReferences(IDReferences idReferences) {
- this.idReferences = idReferences;
- }
-
}
diff --git a/src/org/apache/fop/pdf/PDFGState.java b/src/org/apache/fop/pdf/PDFGState.java
index cf8d32c2a..99c21f85e 100644
--- a/src/org/apache/fop/pdf/PDFGState.java
+++ b/src/org/apache/fop/pdf/PDFGState.java
@@ -12,6 +12,33 @@ package org.apache.fop.pdf;
*
*/
public class PDFGState extends PDFObject {
+ public static final String LW = "lw";
+ public static final String LC = "lc";
+ public static final String LJ = "lj";
+ public static final String ML = "ml";
+ public static final String D = "d";
+ public static final String RI = "ri";
+ public static final String OP = "OP";
+ public static final String op = "op";
+ public static final String OPM = "opm";
+ public static final String Font = "font";
+ public static final String BG = "bg";
+ public static final String BG2 = "bg2";
+ public static final String UCR = "ucr";
+ public static final String UCR2 = "ucr2";
+ public static final String TR = "tr";
+ public static final String TR2 = "tr2";
+ public static final String HT = "ht";
+ public static final String FL = "fl";
+ public static final String SM = "sm";
+ public static final String SA = "sa";
+ public static final String BM = "bm";
+ public static final String SMask = "smask";
+ public static final String CA = "CA";
+ public static final String ca = "ca";
+ public static final String AIS = "ais";
+ public static final String TK = "tk";
+
float alphaFill = 1;
float alphaStroke = 1;
diff --git a/src/org/apache/fop/pdf/PDFICCStream.java b/src/org/apache/fop/pdf/PDFICCStream.java
index 55d444aca..b3d6cf875 100644
--- a/src/org/apache/fop/pdf/PDFICCStream.java
+++ b/src/org/apache/fop/pdf/PDFICCStream.java
@@ -6,41 +6,41 @@
*/
package org.apache.fop.pdf;
-import org.apache.fop.datatypes.ColorSpace;
+
+import java.awt.color.ICC_Profile;
public class PDFICCStream extends PDFStream {
private int origLength;
private int len1, len3;
- private ColorSpace cs;
-
- public void setColorSpace(ColorSpace cs) throws java.io.IOException {
- this.cs = cs;
- setData(cs.getICCProfile());
+ private ICC_Profile cp;
+ private PDFColorSpace pdfColorSpace;
+
+ public void setColorSpace(ICC_Profile cp, PDFColorSpace alt) {
+ this.cp = cp;
+ pdfColorSpace = alt;
}
public PDFICCStream(int num) {
super(num);
- cs = null;
- }
-
- public PDFICCStream(int num, ColorSpace cs) throws java.io.IOException {
- super(num);
- setColorSpace(cs);
+ cp = null;
}
// overload the base object method so we don't have to copy
// byte arrays around so much
protected int output(java.io.OutputStream stream)
throws java.io.IOException {
+
+ setData(cp.getData());
+
int length = 0;
String filterEntry = applyFilters();
StringBuffer pb = new StringBuffer();
pb.append(this.number).append(" ").append(this.generation).append(" obj\n<< ");
- pb.append("/N ").append(cs.getNumComponents()).append(" ");
+ pb.append("/N ").append(cp.getNumComponents()).append(" ");
- if (cs.getColorSpace() > 0)
- pb.append("/Alternate /").append(cs.getColorSpacePDFString()).append(" ");
+ if (pdfColorSpace != null)
+ pb.append("/Alternate /").append(pdfColorSpace.getColorSpacePDFString()).append(" ");
pb.append("/Length ").append((_data.getSize() + 1)).append(" ").append(filterEntry);
pb.append(" >>\n");
diff --git a/src/org/apache/fop/pdf/PDFImage.java b/src/org/apache/fop/pdf/PDFImage.java
new file mode 100644
index 000000000..05cedf753
--- /dev/null
+++ b/src/org/apache/fop/pdf/PDFImage.java
@@ -0,0 +1,44 @@
+/*
+ * $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;
+
+import java.io.IOException;
+
+public interface PDFImage {
+
+ // key to look up XObject
+ public String getKey();
+
+ public void setup(PDFDocument doc);
+
+ // image size
+ public int getWidth();
+ public int getHeight();
+
+ // DeviceGray, DeviceRGB, or DeviceCMYK
+ public PDFColorSpace getColorSpace();
+
+ // bits per pixel
+ public int getBitsPerPixel();
+
+ public boolean isPS();
+
+ // For transparent images
+ public boolean isTransparent();
+ public PDFColor getTransparentColor();
+ public String getMask();
+ public String getSoftMask();
+
+ // get the image bytes, and bytes properties
+
+ public PDFStream getDataStream() throws IOException;
+
+ public PDFICCStream getICCStream();
+
+}
+
diff --git a/src/org/apache/fop/pdf/PDFPathPaint.java b/src/org/apache/fop/pdf/PDFPathPaint.java
index 2c2292823..2f0c0ab96 100644
--- a/src/org/apache/fop/pdf/PDFPathPaint.java
+++ b/src/org/apache/fop/pdf/PDFPathPaint.java
@@ -7,12 +7,10 @@
package org.apache.fop.pdf;
-import org.apache.fop.datatypes.ColorSpace;
-
public abstract class PDFPathPaint extends PDFObject {
// protected int colorspace = 0; //default is 0:RGB, not 1:CMYK
- protected ColorSpace colorSpace;
+ protected PDFColorSpace colorSpace;
public PDFPathPaint(int theNumber) {
super(theNumber);
diff --git a/src/org/apache/fop/pdf/PDFPattern.java b/src/org/apache/fop/pdf/PDFPattern.java
index 412c923bd..ab9c0b645 100644
--- a/src/org/apache/fop/pdf/PDFPattern.java
+++ b/src/org/apache/fop/pdf/PDFPattern.java
@@ -10,9 +10,6 @@ package org.apache.fop.pdf;
// Java...
import java.util.ArrayList;
-// FOP...
-import org.apache.fop.datatypes.ColorSpace;
-
/**
* class representing a PDF Function.
*
@@ -131,6 +128,7 @@ public class PDFPattern extends PDFPathPaint {
this.yStep = theYStep;
this.matrix = theMatrix;
this.xUID = theXUID;
+ // TODO filter this stream
this.patternDataStream = thePatternDataStream;
}
diff --git a/src/org/apache/fop/pdf/PDFShading.java b/src/org/apache/fop/pdf/PDFShading.java
index 3bb284675..d4521e7ae 100644
--- a/src/org/apache/fop/pdf/PDFShading.java
+++ b/src/org/apache/fop/pdf/PDFShading.java
@@ -10,9 +10,6 @@ package org.apache.fop.pdf;
// Java...
import java.util.ArrayList;
-// FOP
-import org.apache.fop.datatypes.ColorSpace;
-
/**
* class representing a PDF Smooth Shading object.
*
@@ -40,7 +37,7 @@ public class PDFShading extends PDFObject {
* A ColorSpace representing the colorspace. "DeviceRGB" is an example.
*/
// protected StringBuffer colorSpace = null;
- protected ColorSpace colorSpace = null;
+ protected PDFColorSpace colorSpace = null;
/**
* The background color. Since shading is opaque,
@@ -148,7 +145,7 @@ public class PDFShading extends PDFObject {
* @param theFunction The PDF Function that maps an (x,y) location to a color
*/
public PDFShading(int theNumber, String theShadingName,
- int theShadingType, ColorSpace theColorSpace,
+ int theShadingType, PDFColorSpace theColorSpace,
ArrayList theBackground, ArrayList theBBox,
boolean theAntiAlias, ArrayList theDomain,
ArrayList theMatrix, PDFFunction theFunction) {
@@ -189,7 +186,7 @@ public class PDFShading extends PDFObject {
* The default is [false, false]
*/
public PDFShading(int theNumber, String theShadingName,
- int theShadingType, ColorSpace theColorSpace,
+ int theShadingType, PDFColorSpace theColorSpace,
ArrayList theBackground, ArrayList theBBox,
boolean theAntiAlias, ArrayList theCoords,
ArrayList theDomain, PDFFunction theFunction,
@@ -234,7 +231,7 @@ public class PDFShading extends PDFObject {
* @param theFunction the PDFFunction
*/
public PDFShading(int theNumber, String theShadingName,
- int theShadingType, ColorSpace theColorSpace,
+ int theShadingType, PDFColorSpace theColorSpace,
ArrayList theBackground, ArrayList theBBox,
boolean theAntiAlias, int theBitsPerCoordinate,
int theBitsPerComponent, int theBitsPerFlag,
@@ -277,7 +274,7 @@ public class PDFShading extends PDFObject {
* @param theNumber the object number of this PDF object.
*/
public PDFShading(int theNumber, String theShadingName,
- int theShadingType, ColorSpace theColorSpace,
+ int theShadingType, PDFColorSpace theColorSpace,
ArrayList theBackground, ArrayList theBBox,
boolean theAntiAlias, int theBitsPerCoordinate,
int theBitsPerComponent, ArrayList theDecode,
diff --git a/src/org/apache/fop/pdf/PDFState.java b/src/org/apache/fop/pdf/PDFState.java
index 45d91c5fb..036a00fed 100644
--- a/src/org/apache/fop/pdf/PDFState.java
+++ b/src/org/apache/fop/pdf/PDFState.java
@@ -47,6 +47,7 @@ public class PDFState {
private final static String FONTSIZE = "fontSize";
private final static String FONTNAME = "fontName";
private final static String CLIP = "clip";
+ private final static String GSTATE = "gstate";
Color color = Color.black;
Color backcolor = Color.white;
@@ -63,6 +64,7 @@ public class PDFState {
float fontSize = 0;
String fontName = "";
Shape clip = null;
+ PDFGState gstate = null;
ArrayList stateStack = new ArrayList();
@@ -89,6 +91,7 @@ public class PDFState {
saveMap.put(FONTSIZE, new Float(fontSize));
saveMap.put(FONTNAME, fontName);
saveMap.put(CLIP, clip);
+ saveMap.put(GSTATE, gstate);
stateStack.add(saveMap);
@@ -114,6 +117,7 @@ public class PDFState {
fontSize = ((Float)saveMap.get(FONTSIZE)).floatValue();
fontName = (String)saveMap.get(FONTNAME);
clip = (Shape)saveMap.get(CLIP);
+ gstate = (PDFGState)saveMap.get(GSTATE);
}
}
diff --git a/src/org/apache/fop/pdf/PDFStream.java b/src/org/apache/fop/pdf/PDFStream.java
index 20c3ef0cc..76f2e6719 100644
--- a/src/org/apache/fop/pdf/PDFStream.java
+++ b/src/org/apache/fop/pdf/PDFStream.java
@@ -96,7 +96,7 @@ public class PDFStream extends PDFObject {
}
- protected void addDefaultFilters() {
+ public void addDefaultFilters() {
ArrayList filters = Configuration.getListValue("stream-filter-list",
Configuration.PDF);
if (filters == null) {
diff --git a/src/org/apache/fop/pdf/PDFXObject.java b/src/org/apache/fop/pdf/PDFXObject.java
index 6b97e43c7..8a3b9ad46 100644
--- a/src/org/apache/fop/pdf/PDFXObject.java
+++ b/src/org/apache/fop/pdf/PDFXObject.java
@@ -13,14 +13,7 @@ package org.apache.fop.pdf;
// Java
import java.io.IOException;
import java.io.OutputStream;
-
-// FOP
-import org.apache.fop.datatypes.ColorSpace;
-import org.apache.fop.pdf.PDFDocument;
-import org.apache.fop.pdf.PDFICCStream;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.image.EPSImage;
-import org.apache.fop.image.JpegImage;
+import java.io.ByteArrayOutputStream;
/**
* PDF XObject
@@ -30,52 +23,19 @@ import org.apache.fop.image.JpegImage;
* the dictionary just provides information like the stream length
*/
public class PDFXObject extends PDFObject {
- private boolean isPS;
- private PDFDocument pdfDoc;
- private PDFICCStream pdfICCStream;
-
- FopImage fopimage;
+ PDFImage pdfimage;
int Xnum;
/**
- * create an Xobject with the given number and name and load the
+ * create an XObject with the given number and name and load the
* image in the object
*/
- public PDFXObject(int number, int Xnumber, FopImage img) {
- this(number, Xnumber, img, null);
- }
-
- public PDFXObject(int number, int Xnumber, FopImage img, PDFDocument pdfdoc) {
+ public PDFXObject(int number, int Xnumber, PDFImage img) {
super(number);
- isPS = false;
this.Xnum = Xnumber;
- if (img == null) {
- //log.error("FISH");
- }
- fopimage = img;
- this.pdfDoc = pdfdoc;
- pdfICCStream = null;
- try {
- if (fopimage instanceof JpegImage) {
- /* hasICCProfile is not initialized before
- the bitmaps is read - should maybe fix this in
- the JpegImage instead...
- */
- fopimage.getBitmaps();
- JpegImage jpegimage = (JpegImage)fopimage;
- if (jpegimage.getColorSpace().hasICCProfile()) {
- pdfICCStream = pdfDoc.makePDFICCStream();
- pdfICCStream.setColorSpace(jpegimage.getColorSpace());
- pdfICCStream.addDefaultFilters();
- }
- }
- } catch (Exception e) {
- //log.error("Error while reading image " +
- // fopimage.getURL() +
- // ": " + e.getMessage());
- }
+ pdfimage = img;
}
-
+
/**
* @return the PDF XObject number
*/
@@ -89,143 +49,107 @@ public class PDFXObject extends PDFObject {
protected int output(OutputStream stream) throws IOException {
int length = 0;
int i = 0;
-
- try {
- if (fopimage instanceof EPSImage) {
- isPS = true;
- EPSImage epsImage = (EPSImage)fopimage;
- int[] bbox = epsImage.getBBox();
- int bboxw = bbox[2] - bbox[0];
- int bboxh = bbox[3] - bbox[1];
-
- // delegate the stream work to PDFStream
- PDFStream imgStream = new PDFStream(0);
-
- StringBuffer preamble = new StringBuffer();
- preamble.append("%%BeginDocument: " + epsImage.getDocName() + "\n");
-
- preamble.append("userdict begin % Push userdict on dict stack\n");
- preamble.append("/PreEPS_state save def\n");
- preamble.append("/dict_stack countdictstack def\n");
- preamble.append("/ops_count count 1 sub def\n");
- preamble.append("/showpage {} def\n");
-
-
- preamble.append((double)(1f/(double)bboxw) + " " + (double)(1f/(double)bboxh) + " scale\n");
- preamble.append(-bbox[0] + " " + (-bbox[1]) + " translate\n");
- preamble.append(bbox[0] + " " + bbox[1] + " " + bboxw + " " + bboxh + " rectclip\n");
- preamble.append("newpath\n");
-
- StringBuffer post = new StringBuffer();
- post.append("%%EndDocument\n");
- post.append("count ops_count sub {pop} repeat\n");
- post.append("countdictstack dict_stack sub {end} repeat\n");
- post.append("PreEPS_state restore\n");
- post.append("end % userdict\n");
-
- byte[] preBytes = preamble.toString().getBytes();
- byte[] postBytes = post.toString().getBytes();
- byte[] imgData = new byte[preBytes.length + postBytes.length + fopimage.getBitmaps().length];
-
- System.arraycopy (preBytes, 0, imgData, 0, preBytes.length);
- System.arraycopy (fopimage.getBitmaps(), 0, imgData, preBytes.length, fopimage.getBitmaps().length);
- System.arraycopy (postBytes, 0, imgData, preBytes.length + fopimage.getBitmaps().length, postBytes.length);
-
-
- imgStream.setData(imgData);
- imgStream.addDefaultFilters();
-
- String dictEntries = imgStream.applyFilters();
-
- String p = this.number + " " + this.generation + " obj\n";
- p = p + "<</Type /XObject\n";
- p = p + "/Subtype /PS\n";
- p = p + "/Length " + imgStream.getDataLength();
-
- p = p + dictEntries;
- p = p + ">>\n";
-
- // push the pdf dictionary on the writer
- byte[] pdfBytes = p.getBytes();
- stream.write(pdfBytes);
- length += pdfBytes.length;
- // push all the image data on the writer and takes care of length for trailer
- length += imgStream.outputStreamData(stream);
-
- pdfBytes = ("endobj\n").getBytes();
- stream.write(pdfBytes);
- length += pdfBytes.length;
-
+
+ if (pdfimage.isPS()) {
+ length = outputEPSImage(stream);
+ } else {
+
+ PDFStream imgStream = pdfimage.getDataStream();
+
+ String dictEntries = imgStream.applyFilters();
+
+ String p = this.number + " " + this.generation + " obj\n";
+ p = p + "<</Type /XObject\n";
+ p = p + "/Subtype /Image\n";
+ p = p + "/Name /Im" + Xnum + "\n";
+ p = p + "/Length " + imgStream.getDataLength() + "\n";
+ p = p + "/Width " + pdfimage.getWidth() + "\n";
+ p = p + "/Height " + pdfimage.getHeight() + "\n";
+ p = p + "/BitsPerComponent " + pdfimage.getBitsPerPixel() +
+ "\n";
+
+ PDFICCStream pdfICCStream = pdfimage.getICCStream();
+ if (pdfICCStream != null) {
+ p = p + "/ColorSpace [/ICCBased " +
+ pdfICCStream.referencePDF() + "]\n";
} else {
+ PDFColorSpace cs = pdfimage.getColorSpace();
+ p = p + "/ColorSpace /" + cs.getColorSpacePDFString() +
+ "\n";
+ }
+
+ /* PhotoShop generates CMYK values that's inverse,
+ this will invert the values - too bad if it's not
+ a PhotoShop image...
+ */
+ if (pdfimage.getColorSpace().getColorSpace() ==
+ PDFColorSpace.DEVICE_CMYK) {
+ p = p + "/Decode [ 1.0 0.0 1.0 0.0 1.0 0.0 1.1 0.0 ]\n";
+ }
- // delegate the stream work to PDFStream
- PDFStream imgStream = new PDFStream(0);
-
- imgStream.setData(fopimage.getBitmaps());
-
- /*
- * Added by Eric Dalquist
- * If the DCT filter hasn't been added to the object we add it here
- */
- if (fopimage.getPDFFilter() != null) {
- imgStream.addFilter(fopimage.getPDFFilter());
- }
-
- imgStream.addDefaultFilters();
-
- String dictEntries = imgStream.applyFilters();
-
- String p = this.number + " " + this.generation + " obj\n";
- p = p + "<</Type /XObject\n";
- p = p + "/Subtype /Image\n";
- p = p + "/Name /Im" + Xnum + "\n";
- p = p + "/Length " + imgStream.getDataLength() + "\n";
- p = p + "/Width " + fopimage.getWidth() + "\n";
- p = p + "/Height " + fopimage.getHeight() + "\n";
- p = p + "/BitsPerComponent " + fopimage.getBitsPerPixel() + "\n";
-
- if (pdfICCStream != null ) {
- p = p + "/ColorSpace [/ICCBased " + pdfICCStream.referencePDF() + "]\n";
- } else {
- ColorSpace cs = fopimage.getColorSpace();
- p = p + "/ColorSpace /" + cs.getColorSpacePDFString() + "\n";
- }
-
- /* PhotoShop generates CMYK values that's inverse,
- this will invert the values - too bad if it's not a PhotoShop image...*/
- if (fopimage.getColorSpace().getColorSpace() == ColorSpace.DEVICE_CMYK) {
- p = p + "/Decode [ 1.0 0.0 1.0 0.0 1.0 0.0 1.1 0.0 ]\n";
- }
-
- if (fopimage.isTransparent()) {
- PDFColor transp = fopimage.getTransparentColor();
- p = p + "/Mask [" + transp.red255() + " " + transp.red255()
- + " " + transp.green255() + " " + transp.green255() + " "
- + transp.blue255() + " " + transp.blue255() + "]\n";
- }
- p = p + dictEntries;
- p = p + ">>\n";
-
- // push the pdf dictionary on the writer
- byte[] pdfBytes = p.getBytes();
- stream.write(pdfBytes);
- length += pdfBytes.length;
- // push all the image data on the writer and takes care of length for trailer
- length += imgStream.outputStreamData(stream);
-
- pdfBytes = ("endobj\n").getBytes();
- stream.write(pdfBytes);
- length += pdfBytes.length;
+ if (pdfimage.isTransparent()) {
+ PDFColor transp = pdfimage.getTransparentColor();
+ p = p + "/Mask [" + transp.red255() + " " +
+ transp.red255() + " " + transp.green255() +
+ " " + transp.green255() + " " +
+ transp.blue255() + " " + transp.blue255() + "]\n";
+ }
+ String ref = pdfimage.getSoftMask();
+ if (ref != null) {
+ p = p + "/SMask " + ref + "\n";
}
- } catch (Exception imgex) {
- //log.error("Error in XObject : "
- // + imgex.getMessage());
+
+ p = p + dictEntries;
+ p = p + ">>\n";
+
+ // push the pdf dictionary on the writer
+ byte[] pdfBytes = p.getBytes();
+ stream.write(pdfBytes);
+ length += pdfBytes.length;
+ // push all the image data on the writer
+ // and takes care of length for trailer
+ length += imgStream.outputStreamData(stream);
+
+ pdfBytes = ("endobj\n").getBytes();
+ stream.write(pdfBytes);
+ length += pdfBytes.length;
}
-
+ // let it gc
+ pdfimage = null;
return length;
}
-
+
byte[] toPDF() {
return null;
}
+
+ private int outputEPSImage(OutputStream stream) throws IOException {
+ int length = 0;
+ int i = 0;
+
+ PDFStream imgStream = pdfimage.getDataStream();
+ String dictEntries = imgStream.applyFilters();
+
+ String p = this.number + " " + this.generation + " obj\n";
+ p = p + "<</Type /XObject\n";
+ p = p + "/Subtype /PS\n";
+ p = p + "/Length " + imgStream.getDataLength();
+
+ p = p + dictEntries;
+ p = p + ">>\n";
+
+ // push the pdf dictionary on the writer
+ byte[] pdfBytes = p.getBytes();
+ stream.write(pdfBytes);
+ length += pdfBytes.length;
+ // push all the image data on the writer and takes care of length for trailer
+ length += imgStream.outputStreamData(stream);
+
+ pdfBytes = ("endobj\n").getBytes();
+ stream.write(pdfBytes);
+ length += pdfBytes.length;
+
+ return length;
+ }
+
}