You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2003/03/27 12:02:36 UTC
cvs commit: xml-fop/src/java/org/apache/fop/pdf PDFXObject.java
jeremias 2003/03/27 03:02:36
Modified: src/java/org/apache/fop/pdf PDFXObject.java
Log:
Adjust to the PDF Stream changes.
Revision Changes Path
1.2 +114 -98 xml-fop/src/java/org/apache/fop/pdf/PDFXObject.java
Index: PDFXObject.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/pdf/PDFXObject.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PDFXObject.java 11 Mar 2003 13:05:09 -0000 1.1
+++ PDFXObject.java 27 Mar 2003 11:02:36 -0000 1.2
@@ -67,7 +67,8 @@
* This is used as a reference for inserting the same image in the
* document in another place.
*/
-public class PDFXObject extends PDFObject {
+public class PDFXObject extends AbstractPDFStream {
+
private PDFImage pdfimage;
private int xnum;
@@ -75,12 +76,11 @@
* create an XObject with the given number and name and load the
* image in the object
*
- * @param number the pdf object number
* @param xnumber the pdf object X number
* @param img the pdf image that contains the image data
*/
- public PDFXObject(int number, int xnumber, PDFImage img) {
- super(number);
+ public PDFXObject(int xnumber, PDFImage img) {
+ super();
this.xnum = xnumber;
pdfimage = img;
}
@@ -103,111 +103,127 @@
* @return the length of the data written
*/
protected int output(OutputStream stream) throws IOException {
- int length = 0;
- int i = 0;
+ int length = super.output(stream);
+
+ // let it gc
+ // this object is retained as a reference to inserting
+ // the same image but the image data is no longer needed
+ pdfimage = null;
+ return length;
+ }
+ /**
+ * @see org.apache.fop.pdf.AbstractPDFStream#buildStreamDict(String)
+ */
+ protected String buildStreamDict(String lengthEntry) {
+ String dictEntries = getFilterList().buildFilterDictEntries();
if (pdfimage.isPS()) {
- length = outputEPSImage(stream);
+ return buildDictionaryFromPS(lengthEntry, dictEntries);
} else {
+ return buildDictionaryFromImage(lengthEntry, dictEntries);
+ }
+ }
+
+ private String buildDictionaryFromPS(String lengthEntry,
+ String dictEntries) {
+ StringBuffer sb = new StringBuffer(128);
+ sb.append(getObjectID());
+ sb.append("<</Type /XObject\n");
+ sb.append("/Subtype /PS\n");
+ sb.append("/Length " + lengthEntry);
+
+ sb.append(dictEntries);
+ sb.append("\n>>\n");
+ return sb.toString();
+ }
- PDFStream imgStream = pdfimage.getDataStream();
+ private String buildDictionaryFromImage(String lengthEntry,
+ String dictEntries) {
+ StringBuffer sb = new StringBuffer(128);
+ sb.append(getObjectID());
+ sb.append("<</Type /XObject\n");
+ sb.append("/Subtype /Image\n");
+ sb.append("/Name /Im" + xnum + "\n");
+ sb.append("/Length " + lengthEntry + "\n");
+ sb.append("/Width " + pdfimage.getWidth() + "\n");
+ sb.append("/Height " + pdfimage.getHeight() + "\n");
+ sb.append("/BitsPerComponent " + pdfimage.getBitsPerPixel() + "\n");
+
+ PDFICCStream pdfICCStream = pdfimage.getICCStream();
+ if (pdfICCStream != null) {
+ sb.append("/ColorSpace [/ICCBased "
+ + pdfICCStream.referencePDF() + "]\n");
+ } else {
+ PDFColorSpace cs = pdfimage.getColorSpace();
+ sb.append("/ColorSpace /" + cs.getColorSpacePDFString()
+ + "\n");
+ }
- String dictEntries = imgStream.applyFilters();
+ /* 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) {
+ sb.append("/Decode [ 1.0 0.0 1.0 0.0 1.0 0.0 1.1 0.0 ]\n");
+ }
- 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() + 1) + "\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";
- }
-
- 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";
- }
-
- 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();
+ sb.append("/Mask ["
+ + transp.red255() + " "
+ + transp.red255() + " "
+ + transp.green255() + " "
+ + transp.green255() + " "
+ + transp.blue255() + " "
+ + transp.blue255() + "]\n");
+ }
+ String ref = pdfimage.getSoftMask();
+ if (ref != null) {
+ sb.append("/SMask " + ref + "\n");
}
- // let it gc
- // this object is retained as a reference to inserting
- // the same image but the image data is no longer needed
- pdfimage = null;
- return length;
- }
- byte[] toPDF() {
- return null;
+ sb.append(dictEntries);
+ sb.append("\n>>\n");
+ return sb.toString();
+ }
+
+ /**
+ * @see org.apache.fop.pdf.PDFStream#outputRawStreamData(OutputStream)
+ */
+ protected void outputRawStreamData(OutputStream out) throws IOException {
+ pdfimage.outputContents(out);
}
- 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() + 1);
-
- 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;
+ /**
+ * @see org.apache.fop.pdf.AbstractPDFStream#getSizeHint()
+ */
+ protected int getSizeHint() throws IOException {
+ return 0;
+ }
- return length;
+ /**
+ * @see org.apache.fop.pdf.AbstractPDFStream#prepareImplicitFilters()
+ */
+ protected void prepareImplicitFilters() {
+ if (pdfimage.isDCT()) {
+ getFilterList().ensureDCTFilterInPlace();
+ }
+ }
+
+ /**
+ * This sets up the default filters for XObjects. It uses the PDFImage
+ * instance to determine what default filters to apply.
+ * @see org.apache.fop.pdf.AbstractPDFStream#setupFilterList()
+ */
+ protected void setupFilterList() {
+ if (!getFilterList().isInitialized()) {
+ getFilterList().addDefaultFilters(
+ getDocumentSafely().getFilterMap(),
+ pdfimage.getFilterHint());
+ }
+ super.setupFilterList();
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org