Browse Source

cleaned up some style errors


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195843 13f79535-47bb-0310-9956-ffa450edef68
tags/Alt-Design-integration-base
Keiron Liddle 21 years ago
parent
commit
2c1fdfe32e
39 changed files with 1526 additions and 438 deletions
  1. 1
    1
      src/org/apache/fop/pdf/BitmapImage.java
  2. 19
    1
      src/org/apache/fop/pdf/DCTFilter.java
  3. 19
    6
      src/org/apache/fop/pdf/InMemoryStreamCache.java
  4. 18
    2
      src/org/apache/fop/pdf/PDFCIDFontDescriptor.java
  5. 17
    4
      src/org/apache/fop/pdf/PDFCIDSystemInfo.java
  6. 262
    10
      src/org/apache/fop/pdf/PDFCMap.java
  7. 10
    5
      src/org/apache/fop/pdf/PDFCharProcs.java
  8. 179
    48
      src/org/apache/fop/pdf/PDFColor.java
  9. 82
    17
      src/org/apache/fop/pdf/PDFColorSpace.java
  10. 186
    60
      src/org/apache/fop/pdf/PDFDocument.java
  11. 7
    6
      src/org/apache/fop/pdf/PDFEncoding.java
  12. 1
    1
      src/org/apache/fop/pdf/PDFFileSpec.java
  13. 30
    10
      src/org/apache/fop/pdf/PDFFilter.java
  14. 16
    7
      src/org/apache/fop/pdf/PDFFilterException.java
  15. 1
    0
      src/org/apache/fop/pdf/PDFFormXObject.java
  16. 46
    17
      src/org/apache/fop/pdf/PDFFunction.java
  17. 20
    14
      src/org/apache/fop/pdf/PDFGoTo.java
  18. 7
    10
      src/org/apache/fop/pdf/PDFGoToRemote.java
  19. 91
    19
      src/org/apache/fop/pdf/PDFImage.java
  20. 27
    7
      src/org/apache/fop/pdf/PDFInfo.java
  21. 2
    3
      src/org/apache/fop/pdf/PDFInternalLink.java
  22. 27
    28
      src/org/apache/fop/pdf/PDFNumber.java
  23. 5
    1
      src/org/apache/fop/pdf/PDFObject.java
  24. 71
    63
      src/org/apache/fop/pdf/PDFOutline.java
  25. 11
    1
      src/org/apache/fop/pdf/PDFPage.java
  26. 3
    3
      src/org/apache/fop/pdf/PDFPages.java
  27. 33
    4
      src/org/apache/fop/pdf/PDFPathPaint.java
  28. 22
    8
      src/org/apache/fop/pdf/PDFPattern.java
  29. 6
    1
      src/org/apache/fop/pdf/PDFRectangle.java
  30. 34
    8
      src/org/apache/fop/pdf/PDFResourceContext.java
  31. 49
    12
      src/org/apache/fop/pdf/PDFResources.java
  32. 16
    12
      src/org/apache/fop/pdf/PDFRoot.java
  33. 46
    21
      src/org/apache/fop/pdf/PDFShading.java
  34. 94
    7
      src/org/apache/fop/pdf/PDFState.java
  35. 1
    1
      src/org/apache/fop/pdf/PDFStream.java
  36. 5
    6
      src/org/apache/fop/pdf/PDFUri.java
  37. 27
    5
      src/org/apache/fop/pdf/StreamCache.java
  38. 31
    8
      src/org/apache/fop/pdf/TempFileStreamCache.java
  39. 4
    1
      src/org/apache/fop/pdf/TransitionDictionary.java

+ 1
- 1
src/org/apache/fop/pdf/BitmapImage.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/

+ 19
- 1
src/org/apache/fop/pdf/DCTFilter.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -22,14 +22,32 @@ import java.io.OutputStream;
* @author Eric Dalquist
*/
public class DCTFilter extends PDFFilter {

/**
* Get filter name.
* @return the pdf name for the DCT filter
*/
public String getName() {
return "/DCTDecode";
}

/**
* Get the decode params for this filter.
* @return the DCT filter has no decode params
*/
public String getDecodeParms() {
return null;
}

/**
* Encode a stream with this filter.
* Currently no encoding is performed, it is assumed that the data
* is already encoded.
* @param in the input data stream
* @param out the output stream
* @param length the length of the data
* @throws IOException if there is an io error
*/
public void encode(InputStream in, OutputStream out, int length) throws IOException {
StreamUtilities.streamCopy(in, out, length);
out.close();

+ 19
- 6
src/org/apache/fop/pdf/InMemoryStreamCache.java View File

@@ -9,7 +9,6 @@ package org.apache.fop.pdf;

import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

@@ -32,19 +31,25 @@ public class InMemoryStreamCache extends StreamCache {
/**
* Get the current OutputStream. Do not store it - it may change
* from call to call.
* @throws IOException if there is an error getting the output stream
* @return the output stream containing the data
*/
public OutputStream getOutputStream() throws IOException {
if (output == null)
if (output == null) {
output = new ByteArrayOutputStream();
}
return output;
}

/**
* Filter the cache with the supplied PDFFilter.
* @param filter the filter to apply
* @throws IOException if an IO error occurs
*/
public void applyFilter(PDFFilter filter) throws IOException {
if (output == null)
if (output == null) {
return;
}

output.close();

@@ -64,26 +69,33 @@ public class InMemoryStreamCache extends StreamCache {

/**
* Outputs the cached bytes to the given stream.
* @param stream the output stream to write to
* @throws IOException if there is an IO error writing to the output stream
*/
public void outputStreamData(OutputStream stream) throws IOException {
if (output == null)
if (output == null) {
return;
}

output.writeTo(stream);
}

/**
* Returns the current size of the stream.
* @throws IOException if there is an error getting the size
* @return the length of the stream
*/
public int getSize() throws IOException {
if (output == null)
if (output == null) {
return 0;
else
} else {
return output.size();
}
}

/**
* Closes the cache and frees resources.
* @throws IOException if there is an error closing the stream
*/
public void close() throws IOException {
if (output != null) {
@@ -94,6 +106,7 @@ public class InMemoryStreamCache extends StreamCache {

/**
* Clears and resets the cache.
* @throws IOException if there is an error closing the stream
*/
public void reset() throws IOException {
if (output != null) {

+ 18
- 2
src/org/apache/fop/pdf/PDFCIDFontDescriptor.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -16,7 +16,14 @@ package org.apache.fop.pdf;
*/
public class PDFCIDFontDescriptor extends PDFFontDescriptor {

/**
* The language for the font
*/
protected String lang;

/**
* The cid set stream
*/
protected PDFStream cidSet;

/**
@@ -41,10 +48,19 @@ public class PDFCIDFontDescriptor extends PDFFontDescriptor {
this.lang = lang;
}

/**
* Set the CID set stream.
* @param cidSet the pdf stream cotnaining the CID set
*/
public void setCIDSet(PDFStream cidSet) {
this.cidSet = cidSet;
}

/**
* Fill in the pdf data for this font descriptor.
* The charset specific dictionary entries are output.
* @param p the string buffer to append the data
*/
protected void fillInPDF(StringBuffer p) {
p.append("\n/MissingWidth 500\n");
if (lang != null) {
@@ -53,7 +69,7 @@ public class PDFCIDFontDescriptor extends PDFFontDescriptor {
}
if (cidSet != null) {
p.append("\n/CIDSet /");
this.cidSet.referencePDF();
p.append(this.cidSet.referencePDF());
}
}


+ 17
- 4
src/org/apache/fop/pdf/PDFCIDSystemInfo.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -15,10 +15,17 @@ package org.apache.fop.pdf;
* this small object is used in the CID fonts and in the CMaps.
*/
public class PDFCIDSystemInfo extends PDFObject {
protected String registry;
protected String ordering;
protected int supplement;
private String registry;
private String ordering;
private int supplement;

/**
* Create a CID system info.
*
* @param registry the registry value
* @param ordering the ordering value
* @param supplement the supplement value
*/
public PDFCIDSystemInfo(String registry, String ordering,
int supplement) {
this.registry = registry;
@@ -38,6 +45,12 @@ public class PDFCIDSystemInfo extends PDFObject {
return toPDFString().getBytes();
}

/**
* Create a string for the CIDSystemInfo dictionary.
* The entries are placed as an inline dictionary.
*
* @return the string for the CIDSystemInfo entry with the inline dictionary
*/
public String toPDFString() {
StringBuffer p = new StringBuffer();
p.setLength(0);

+ 262
- 10
src/org/apache/fop/pdf/PDFCMap.java View File

@@ -8,79 +8,322 @@
package org.apache.fop.pdf;

/**
* class representing the CMap encodings.
* Class representing the CMap encodings.
*
* CMaps are defined on page 215 and onwards.
* The predefined CMap names are drawn from Table 7.20
* on pages 215, 216 and 217 .
* CMaps are defined in the "Predefined CJK CMap names" table.
* In section 5.6.4 of PDF reference 1.4.
*/
public class PDFCMap extends PDFStream {

/**
/*
* Chinese (simplified)
*/

/**
* GB-EUC-H Microsoft Code Page 936 (lfCharSet 0x86), GB 2312-80
* character set, EUC-CN encoding
*/
public static final String GB_EUC_H = "GB-EUC-H";

/**
* GB-EUC-V Vertical version of GB-EUC-H
*/
public static final String GB_EUC_V = "GB_EUC_V";

/**
* GBpc-EUC-H Mac OS, GB 2312-80 character set, EUC-CN encoding, Script Manager code 19
*/
public static final String GBpc_EUC_H = "GBpc-EUC-H";

/**
* GBpc-EUC-V Vertical version of GBpc-EUC-H
*/
public static final String GBpc_EUC_V = "GBpc-EUC-V";

/**
* GBK-EUC-H Microsoft Code Page 936 (lfCharSet 0x86), GBK character set, GBK encoding
*/
public static final String GBK_EUC_H = "GBK-EUC-H";

/**
* GBK-EUC-V Vertical version of GBK-EUC-H
*/
public static final String GBK_EUC_V = "GBK-EUC-V";

/**
* GBKp-EUC-H Same as GBK-EUC-H, but replaces half-width
* Latin characters with proportional forms and maps character
* code 0x24 to a dollar sign ($) instead of a yuan symbol
*/
public static final String GBKp_EUC_H = "GBKp-EUC-H";

/**
* GBKp-EUC-V Vertical version of GBKp-EUC-H
*/
public static final String GBKp_EUC_V = "GBKp-EUC-V";

/**
* GBK2K-H GB 18030-2000 character set, mixed 1-, 2-, and 4-byte encoding
*/
public static final String GBK2K_H = "GBK2K-H";

/**
* GBK2K-V Vertical version of GBK2K-H
*/
public static final String GBK2K_V = "GBK2K-V";

/**
* UniGB-UCS2-H Unicode (UCS-2) encoding for the Adobe-GB1 character collection
*/
public static final String UniGB_UCS2_H = "UniGB-UCS2-H";

/**
* UniGB-UCS2-V Vertical version of UniGB-UCS2-H
*/
public static final String UniGB_UCS2_V = "UniGB-UCS2-V";


/*
* Chinese (Traditional)
*/

/**
* Chinese (traditional)
* B5pc-H Mac OS, Big Five character set, Big Five encoding, Script Manager code 2
*/
public static final String B5pc_H = "B5pc-H";

/**
* B5pc-V Vertical version of B5pc-H
*/
public static final String B5pc_V = "B5pc-V";

/**
* HKscs-B5-H Hong Kong SCS, an extension to the Big Five
* character set and encoding
*/
public static final String HKscs_B5_H = "HKscs-B5-H";

/**
* HKscs-B5-V Vertical version of HKscs-B5-H
*/
public static final String HKscs_B5_V = "HKscs-B5-V";

/**
* ETen-B5-H Microsoft Code Page 950 (lfCharSet 0x88), Big Five
* character set with ETen extensions
*/
public static final String ETen_B5_H = "ETen-B5-H";

/**
* ETen-B5-V Vertical version of ETen-B5-H
*/
public static final String ETen_B5_V = "ETen-B5-V";

/**
* ETenms-B5-H Same as ETen-B5-H, but replaces half-width
* Latin characters with proportional forms
*/
public static final String ETenms_B5_H = "ETenms-B5-H";

/**
* ETenms-B5-V Vertical version of ETenms-B5-H
*/
public static final String ETenms_B5_V = "ETenms-B5-V";

/**
* CNS-EUC-H CNS 11643-1992 character set, EUC-TW encoding
*/
public static final String CNS_EUC_H = "CNS-EUC-H";

/**
* CNS-EUC-V Vertical version of CNS-EUC-H
*/
public static final String CNS_EUC_V = "CNS-EUC-V";

/**
* UniCNS-UCS2-H Unicode (UCS-2) encoding for the
* Adobe-CNS1 character collection
*/
public static final String UniCNS_UCS2_H = "UniCNS-UCS2-H";
public static final String UniCNS_UCS2_V = "UniCNS-UCS2-V";

/**
* UniCNS-UCS2-V Vertical version of UniCNS-UCS2-H
*/
public static final String UniCNS_UCS2_V = "UniCNS-UCS2-V";

/*
* Japanese
*/

/**
* 83pv-RKSJ-H Mac OS, JIS X 0208 character set with KanjiTalk6
* extensions, Shift-JIS encoding, Script Manager code 1
*/
public static final String _83pv_RKSJ_H = "83pv-RKSJ-H"; // no V version

/**
* 90ms-RKSJ-H Microsoft Code Page 932 (lfCharSet 0x80), JIS X 0208
* character set with NEC and IBM extensions
*/
public static final String _90ms_RKSJ_H = "90ms-RKSJ-H";

/**
* 90ms-RKSJ-V Vertical version of 90ms-RKSJ-H
*/
public static final String _90ms_RKSJ_V = "90ms-RKSJ-V";

/**
* 90msp-RKSJ-H Same as 90ms-RKSJ-H, but replaces half-width Latin
* characters with proportional forms
*/
public static final String _90msp_RKSJ_H = "90msp-RKSJ-H";

/**
* 90msp-RKSJ-V Vertical version of 90msp-RKSJ-H
*/
public static final String _90msp_RKSJ_V = "90msp-RKSJ-V";

/**
* 90pv-RKSJ-H Mac OS, JIS X 0208 character set with KanjiTalk7
* extensions, Shift-JIS encoding, Script Manager code 1
*/
public static final String _90pv_RKSJ_H = "90pv-RKSJ-H"; // no V version

/**
* Add-RKSJ-H JIS X 0208 character set with Fujitsu FMR
* extensions, Shift-JIS encoding
*/
public static final String Add_RKSJ_H = "Add-RKSJ-H";

/**
* Add-RKSJ-V Vertical version of Add-RKSJ-H
*/
public static final String Add_RKSJ_V = "Add-RKSJ-V";

/**
* EUC-H JIS X 0208 character set, EUC-JP encoding
*/
public static final String EUC_H = "EUC-H";

/**
* EUC-V Vertical version of EUC-H
*/
public static final String EUC_V = "EUC-V";

/**
* Ext-RKSJ-H JIS C 6226 (JIS78) character set with
* NEC extensions, Shift-JIS encoding
*/
public static final String Ext_RKSJ_H = "Ext-RKSJ-H";

/**
* Ext-RKSJ-V Vertical version of Ext-RKSJ-H
*/
public static final String Ext_RKSJ_V = "Ext-RKSJ-V";

/**
* H JIS X 0208 character set, ISO-2022-JP encoding
*/
public static final String H = "H";

/**
* V Vertical version of H
*/
public static final String V = "V";

/**
* UniJIS-UCS2-H Unicode (UCS-2) encoding for the
* Adobe-Japan1 character collection
*/
public static final String UniJIS_UCS2_H = "UniJIS-UCS2-H";

/**
* UniJIS-UCS2-V Vertical version of UniJIS-UCS2-H
*/
public static final String UniJIS_UCS2_V = "UniJIS-UCS2-V";

/**
* UniJIS-UCS2-HW-H Same as UniJIS-UCS2-H, but replaces proportional
* Latin characters with half-width forms
*/
public static final String UniJIS_UCS2_HW_H = "UniJIS-UCS2-HW-H";
public static final String UniJIS_UCS2_HW_V = "UniJIS-UCS2-HW-V";

/**
* UniJIS-UCS2-HW-V Vertical version of UniJIS-UCS2-HW-H
*/
public static final String UniJIS_UCS2_HW_V = "UniJIS-UCS2-HW-V";

/*
* Korean
*/

/**
* KSC-EUC-H KS X 1001:1992 character set, EUC-KR encoding
*/
public static final String KSC_EUC_H = "KSC-EUC-H";

/**
* KSC-EUC-V Vertical version of KSC-EUC-H
*/
public static final String KSC_EUC_V = "KSC-EUC-V";

/**
* KSCms-UHC-H Microsoft Code Page 949 (lfCharSet 0x81), KS X 1001:1992
* character set plus 8822 additional hangul,
* Unified Hangul Code (UHC) encoding
*/
public static final String KSCms_UHC_H = "KSCms-UHC-H";

/**
* KSCms-UHC-V Vertical version of KSCms-UHC-H
*/
public static final String KSCms_UHC_V = "KSCms-UHC-V";

/**
* KSCms-UHC-HW-H Same as KSCms-UHC-H, but replaces proportional
* Latin characters with half-width forms
*/
public static final String KSCms_UHC_HW_H = "KSCms-UHC-HW-H";

/**
* KSCms-UHC-HW-V Vertical version of KSCms-UHC-HW-H
*/
public static final String KSCms_UHC_HW_V = "KSCms-UHC-HW-V";

/**
* KSCpc-EUC-H Mac OS, KS X 1001:1992 character set with
* Mac OS KH extensions, Script Manager Code 3
*/
public static final String KSCpc_EUC_H = "KSCpc-EUC-H"; // no V version

/**
* UniKS-UCS2-H Unicode (UCS-2) encoding for the
* Adobe-Korea1 character collection
*/
public static final String UniKSC_UCS2_H = "UniKSC-UCS2-H";
public static final String UniKSC_UCS2_V = "UniKSC-UCS2-V";

/**
* UniKS-UCS2-V Vertical version of UniKS-UCS2-H
*/
public static final String UniKSC_UCS2_V = "UniKSC-UCS2-V";

/*
* Generic
*/

/**
* Identity-H The horizontal identity mapping for 2-byte CIDs;
* may be used with CIDFonts using any Registry, Ordering, and
* Supplement values. It maps 2-byte character codes ranging from
* 0 to 65,535 to the same 2-byte CID value, interpreted
* high-order byte first.
*/
public static final String Identity_H = "Identity-H";

/**
* Identity-V Vertical version of Identity-H. The mapping
* is the same as for Identity-H.
*/
public static final String Identity_V = "Identity-V";

/**
@@ -116,6 +359,7 @@ public class PDFCMap extends PDFStream {
/**
* create the /CMap object
*
* @param number the pdf object number
* @param name one the registered names (see Table 7.20 on p 215)
* @param sysInfo the attributes of the character collection of the CIDFont
*/
@@ -136,6 +380,9 @@ public class PDFCMap extends PDFStream {
this.wMode = mode;
}

/**
* Add the contents of this pdf object to the PDF stream.
*/
public void addContents() {
StringBuffer p = new StringBuffer();
fillInPDF(p);
@@ -145,7 +392,7 @@ public class PDFCMap extends PDFStream {
/**
* set the base CMap
*
* @param base the name of the base CMap (see Table 7.20)
* @param base the name of the base CMap
*/
public void setUseCMap(String base) {
this.base = base;
@@ -160,6 +407,11 @@ public class PDFCMap extends PDFStream {
this.base = base;
}

/**
* Fill in the pdf string for this CMap.
*
* @param p the string buffer to add the pdf data to
*/
public void fillInPDF(StringBuffer p) {
// p.append("/Type /CMap\n");
// p.append(sysInfo.toPDFString());

+ 10
- 5
src/org/apache/fop/pdf/PDFCharProcs.java View File

@@ -1,13 +1,14 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 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.util.Hashtable;
import java.util.Map;
import java.util.HashMap;

/**
* class representing a /CharProcs dictionary for Type3 fonts.
@@ -23,10 +24,13 @@ public class PDFCharProcs extends PDFObject {
/**
* the (character name, drawing stream) pairs for a Type3 font
*/
protected Hashtable keys;
protected Map keys;

/**
* Create a new PDF char proc store.
*/
public PDFCharProcs() {
keys = new Hashtable();
keys = new HashMap();
}

/**
@@ -41,9 +45,10 @@ public class PDFCharProcs extends PDFObject {

/**
* not done yet
* @return the pdf byte array
*/
public byte[] toPDF() {
// TODO: implement this org.apache.fop.pdf.PDFObject abstract method
// todo implement this org.apache.fop.pdf.PDFObject abstract method
return new byte[0];
}


+ 179
- 48
src/org/apache/fop/pdf/PDFColor.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -8,19 +8,32 @@
package org.apache.fop.pdf;

// Java
import java.util.List;
import java.util.ArrayList;

/**
* PDF Color object.
* This is used to output color to a PDF content stream.
*/
public class PDFColor extends PDFPathPaint {
protected static double blackFactor = 2.0; // could be 3.0 as well.
protected double red = -1.0;
protected double green = -1.0;
protected double blue = -1.0;

protected double cyan = -1.0;
protected double magenta = -1.0;
protected double yellow = -1.0;
protected double black = -1.0;

// could be 3.0 as well.
private static double blackFactor = 2.0;
private double red = -1.0;
private double green = -1.0;
private double blue = -1.0;

private double cyan = -1.0;
private double magenta = -1.0;
private double yellow = -1.0;
private double black = -1.0;

/**
* Create a PDF color with double values ranging from 0 to 1
*
* @param theRed the red double value
* @param theGreen the green double value
* @param theBlue the blue double value
*/
public PDFColor(double theRed, double theGreen, double theBlue) {
// super(theNumber);
this.colorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
@@ -30,13 +43,27 @@ public class PDFColor extends PDFPathPaint {
this.blue = theBlue;
}

// components from 0 to 255
/**
* Create a PDF color with int values ranging from 0 to 255
*
* @param theRed the red integer value
* @param theGreen the green integer value
* @param theBlue the blue integer value
*/
public PDFColor(int theRed, int theGreen, int theBlue) {
this(((double)theRed) / 255d, ((double)theGreen) / 255d,
((double)theBlue) / 255d);

}

/**
* Create a PDF color with CMYK values.
*
* @param theCyan the cyan value
* @param theMagenta the magenta value
* @param theYellow the yellow value
* @param theBlack the black value
*/
public PDFColor(double theCyan, double theMagenta, double theYellow,
double theBlack) {
// super(theNumber);//?
@@ -49,90 +76,153 @@ public class PDFColor extends PDFPathPaint {
this.black = theBlack;
}


public ArrayList getVector() { // return a vector representation of the color
// in the appropriate colorspace.
ArrayList theColorVector = new ArrayList();
if (this.colorSpace.getColorSpace() == PDFColorSpace.DEVICE_RGB) { // RGB
/**
* Return a vector representation of the color
* in the appropriate colorspace.
*
* @return a list containing the Double values of the color
*/
public List getVector() {
List theColorVector = new ArrayList();
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()
== PDFColorSpace.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));
theColorVector.add(new Double(this.black));
} else { // GRAY
} else {
// GRAY
theColorVector.add(new Double(this.black));
}
return (theColorVector);
}

/**
* Get the red component.
*
* @return the red double value
*/
public double red() {
return (this.red);
}

/**
* Get the green component.
*
* @return the green double value
*/
public double green() {
return (this.green);
}

/**
* Get the blue component.
*
* @return the blue double value
*/
public double blue() {
return (this.blue);
}

/**
* Get the red integer component.
*
* @return the red integer value
*/
public int red255() {
return (int)(this.red * 255d);
}

/**
* Get the green integer component.
*
* @return the green integer value
*/
public int green255() {
return (int)(this.green * 255d);
}

/**
* Get the blue integer component.
*
* @return the blue integer value
*/
public int blue255() {
return (int)(this.blue * 255d);
}

/**
* Get the cyan component.
*
* @return the cyan double value
*/
public double cyan() {
return (this.cyan);
}

/**
* Get the magenta component.
*
* @return the magenta double value
*/
public double magenta() {
return (this.magenta);
}

/**
* Get the yellow component.
*
* @return the yellow double value
*/
public double yellow() {
return (this.yellow);
}

/**
* Get the black component.
*
* @return the black double value
*/
public double black() {
return (this.black);
}

/**
* Set the color space for this color.
* If the new color space is different the values are converted
* to the new color space.
*
* @param theColorSpace the new color space
*/
public void setColorSpace(int theColorSpace) {
int theOldColorSpace = this.colorSpace.getColorSpace();
if (theOldColorSpace != theColorSpace) {
if (theOldColorSpace == PDFColorSpace.DEVICE_RGB) {
if (theColorSpace == PDFColorSpace.DEVICE_CMYK) {
this.convertRGBtoCMYK();
} else // convert to Gray?
{
} else {
// convert to Gray?
this.convertRGBtoGRAY();
}

} else if (theOldColorSpace == PDFColorSpace.DEVICE_CMYK) {
if (theColorSpace == PDFColorSpace.DEVICE_RGB) {
this.convertCMYKtoRGB();
} else // convert to Gray?
{
} else {
// convert to Gray?
this.convertCMYKtoGRAY();
}
} else // used to be Gray
{
} else {
// used to be Gray
if (theColorSpace == PDFColorSpace.DEVICE_RGB) {
this.convertGRAYtoRGB();
} else // convert to CMYK?
{
} else {
// convert to CMYK?
this.convertGRAYtoCMYK();
}
}
@@ -140,6 +230,14 @@ public class PDFColor extends PDFPathPaint {
}
}

/**
* Get the PDF output string for this color.
* This returns the string to be inserted into PDF for setting
* the current color.
*
* @param fillNotStroke whether to return fill or stroke command
* @return the PDF string for setting the fill/stroke color
*/
public String getColorSpaceOut(boolean fillNotStroke) {
StringBuffer p = new StringBuffer("");

@@ -154,7 +252,8 @@ public class PDFColor extends PDFPathPaint {
same = true;
}
// output RGB
if (fillNotStroke) { // fill
if (fillNotStroke) {
// fill
if (same) {
p.append(PDFNumber.doubleOut(this.red) + " g\n");
} else {
@@ -163,7 +262,8 @@ public class PDFColor extends PDFPathPaint {
+ PDFNumber.doubleOut(this.blue)
+ " rg\n");
}
} else { // stroke/border
} else {
// stroke/border
if (same) {
p.append(PDFNumber.doubleOut(this.red) + " G\n");
} else {
@@ -173,24 +273,26 @@ public class PDFColor extends PDFPathPaint {
+ " RG\n");
}
}
} // end of output RGB
else if (this.colorSpace.getColorSpace()
== PDFColorSpace.DEVICE_CMYK) { // colorspace is CMYK
} else if (this.colorSpace.getColorSpace()
== PDFColorSpace.DEVICE_CMYK) {
// colorspace is CMYK

if (fillNotStroke) { // fill
if (fillNotStroke) {
// fill
p.append(PDFNumber.doubleOut(this.cyan) + " "
+ PDFNumber.doubleOut(this.magenta) + " "
+ PDFNumber.doubleOut(this.yellow) + " "
+ PDFNumber.doubleOut(this.black) + " k\n");
} else { // fill
} else {
// stroke
p.append(PDFNumber.doubleOut(this.cyan) + " "
+ PDFNumber.doubleOut(this.magenta) + " "
+ PDFNumber.doubleOut(this.yellow) + " "
+ PDFNumber.doubleOut(this.black) + " K\n");
}

} // end of if CMYK
else { // means we're in DeviceGray or Unknown.
} else {
// means we're in DeviceGray or Unknown.
// assume we're in DeviceGray, because otherwise we're screwed.

if (fillNotStroke) {
@@ -203,9 +305,9 @@ public class PDFColor extends PDFPathPaint {
return (p.toString());
}

/**
* Convert the color from CMYK to RGB.
*/
protected void convertCMYKtoRGB() {
// convert CMYK to RGB
this.red = 1.0 - this.cyan;
@@ -218,6 +320,9 @@ public class PDFColor extends PDFPathPaint {

}

/**
* Convert the color from RGB to CMYK.
*/
protected void convertRGBtoCMYK() {
// convert RGB to CMYK
this.cyan = 1.0 - this.red;
@@ -240,12 +345,18 @@ public class PDFColor extends PDFPathPaint {
*/
}

/**
* Convert the color from Gray to RGB.
*/
protected void convertGRAYtoRGB() {
this.red = 1.0 - this.black;
this.green = 1.0 - this.black;
this.blue = 1.0 - this.black;
}

/**
* Convert the color from Gray to CMYK.
*/
protected void convertGRAYtoCMYK() {
this.cyan = this.black;
this.magenta = this.black;
@@ -253,43 +364,63 @@ public class PDFColor extends PDFPathPaint {
// this.black=0.0;//?
}

/**
* Convert the color from CMYK to Gray.
*/
protected void convertCMYKtoGRAY() {
double tempDouble = 0.0;

// pick the lowest color
tempDouble = this.cyan;

if (this.magenta < tempDouble)
if (this.magenta < tempDouble) {
tempDouble = this.magenta;
}

if (this.yellow < tempDouble)
if (this.yellow < tempDouble) {
tempDouble = this.yellow;
}

this.black = (tempDouble / this.blackFactor);

}

/**
* Convert the color from RGB to Gray.
*/
protected void convertRGBtoGRAY() {
double tempDouble = 0.0;

// pick the lowest color
tempDouble = this.red;

if (this.green < tempDouble)
if (this.green < tempDouble) {
tempDouble = this.green;
}

if (this.blue < tempDouble)
if (this.blue < tempDouble) {
tempDouble = this.blue;
}

this.black = 1.0 - (tempDouble / this.blackFactor);

}

byte[] toPDF() {
/**
* Create pdf.
* Not used for this object.
*
* @return the bytes for the pdf
*/
public byte[] toPDF() {
return (new byte[0]);
}

} // end of toPDF

/**
* Check for equality of color with another object.
*
* @param obj the object to compare
* @return true if colors are equal
*/
public boolean equals(Object obj) {
if (!(obj instanceof PDFColor)) {
return false;

+ 82
- 17
src/org/apache/fop/pdf/PDFColorSpace.java View File

@@ -1,12 +1,15 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 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;

/**
* PDF Color space.
*/
public class PDFColorSpace {
private boolean hasICCProfile;
private byte[] iccProfile;
@@ -15,17 +18,38 @@ public class PDFColorSpace {
// 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;
/**
* Unknown colorspace
*/
public static final int DEVICE_UNKNOWN = -1;

/**
* Gray colorspace
*/
public static final int DEVICE_GRAY = 1;

/**
* RGB colorspace
*/
public static final int DEVICE_RGB = 2;

/**
* CMYK colorspace
*/
public static final int DEVICE_CMYK = 3;

// Are there any others?

/**
* Current color space value.
*/
protected int currentColorSpace = DEVICE_UNKNOWN;

/**
* Create a PDF colorspace object.
*
* @param theColorSpace the current colorspace
*/
public PDFColorSpace(int theColorSpace) {
this.currentColorSpace = theColorSpace;
hasICCProfile = false;
@@ -44,46 +68,87 @@ public class PDFColorSpace {
}
}

/**
* Set the current colorspace.
*
* @param theColorSpace the new color space value
*/
public void setColorSpace(int theColorSpace) {
this.currentColorSpace = theColorSpace;
numComponents = calculateNumComponents();
}

/**
* Check if this colorspace has an ICC profile.
*
* @return true if this has an ICC profile
*/
public boolean hasICCProfile() {
return hasICCProfile;
}

/**
* Get the ICC profile for this colorspace
*
* @return the byte array containing the ICC profile data
*/
public byte[] getICCProfile() {
if (hasICCProfile)
if (hasICCProfile) {
return iccProfile;
else
} else {
return new byte[0];
}
}

/**
* Set the ICC profile for this colorspace.
*
* @param iccProfile the ICC profile data
*/
public void setICCProfile(byte[] iccProfile) {
this.iccProfile = iccProfile;
hasICCProfile = true;
}

/**
* Get the colorspace value
*
* @return the colorspace value
*/
public int getColorSpace() {
return (this.currentColorSpace);
}

/**
* Get the number of color components for this colorspace
*
* @return the number of components
*/
public int getNumComponents() {
return numComponents;
}

/**
* Get the PDF string for this colorspace.
*
* @return the PDF string for the colorspace
*/
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");
switch (currentColorSpace) {
case DEVICE_CMYK:
return "DeviceCMYK";
//break;
case DEVICE_GRAY:
return "DeviceGray";
//break;
case DEVICE_RGB:
default:
// unknown... Error. Tell them it's RGB and hope they
// don't notice.
return ("DeviceRGB");
//break;
}
}


+ 186
- 60
src/org/apache/fop/pdf/PDFDocument.java View File

@@ -272,6 +272,15 @@ public class PDFDocument {
return pdfRoot;
}

/**
* Get the PDF root object.
*
* @return the PDFRoot object
*/
public PDFRoot getRoot() {
return this.root;
}

/**
* Make a /Pages object. This object is written in the trailer.
*
@@ -375,9 +384,9 @@ public class PDFDocument {
* This is not documented in the Function section of the PDF 1.3 spec,
* it was deduced from samples that this is sometimes used, even if we may never
* use it in FOP. It is added for completeness sake.
* @param theNumber The object number of this PDF object.
* @param theFunctionType This is the type of function (0,2,3, or 4).
* It should be 0 as this is the constructor for sampled functions.
* @return the PDF function that was created
*/
public PDFFunction makeFunction(int theFunctionType, List theDomain,
List theRange, List theSize,
@@ -430,6 +439,7 @@ public class PDFDocument {
* This attribute is required.
* PDF Spec page 268
* @param theFunctionType The type of the function, which should be 2.
* @return the PDF function that was created
*/
public PDFFunction makeFunction(int theFunctionType, List theDomain,
List theRange, List theCZero,
@@ -513,6 +523,7 @@ public class PDFDocument {
* See page 270 in the PDF 1.3 spec.
* @param theFunctionType This is the function type. It should be 3,
* for a stitching function.
* @return the PDF function that was created
*/
public PDFFunction makeFunction(int theFunctionType, List theDomain,
List theRange, List theFunctions,
@@ -540,15 +551,17 @@ public class PDFDocument {
/**
* make a postscript calculator function
*
* @param theNumber
* @param theFunctionType
* @param theDomain
* @param theRange
* @param theFunctionDataStream
* @param theNumber the PDF object number
* @param theFunctionType the type of function to make
* @param theDomain the domain values
* @param theRange the range values of the function
* @param theFunctionDataStream a string containing the pdf drawing
* @return the PDF function that was created
*/
public PDFFunction makeFunction(int theNumber, int theFunctionType,
List theDomain, List theRange,
StringBuffer theFunctionDataStream) { // Type 4
StringBuffer theFunctionDataStream) {
// Type 4
PDFFunction function = new PDFFunction(++this.objectcount,
theFunctionType, theDomain,
theRange,
@@ -570,6 +583,7 @@ public class PDFDocument {
/**
* make a function based shading object
*
* @param res the PDF resource context to add the shading, may be null
* @param theShadingType The type of shading object, which should be 1 for function
* based shading.
* @param theColorSpace The colorspace is 'DeviceRGB' or something similar.
@@ -587,6 +601,7 @@ public class PDFDocument {
* If it's a shading, then it maps it to current user space.
* It's optional, the default is the identity matrix
* @param theFunction The PDF Function that maps an (x,y) location to a color
* @return the PDF shading that was created
*/
public PDFShading makeShading(PDFResourceContext res, int theShadingType,
PDFColorSpace theColorSpace,
@@ -626,6 +641,7 @@ public class PDFDocument {
/**
* Make an axial or radial shading object.
*
* @param res the PDF resource context to add the shading, may be null
* @param theShadingType 2 or 3 for axial or radial shading
* @param theColorSpace "DeviceRGB" or similar.
* @param theBackground theBackground An array of color components appropriate to the
@@ -643,6 +659,7 @@ public class PDFDocument {
* @param theExtend List of Booleans of whether to extend the
* start and end colors past the start and end points
* The default is [false, false]
* @return the PDF shading that was created
*/
public PDFShading makeShading(PDFResourceContext res, int theShadingType,
PDFColorSpace theColorSpace,
@@ -683,6 +700,7 @@ public class PDFDocument {
* Make a free-form gouraud shaded triangle mesh, coons patch mesh, or tensor patch mesh
* shading object
*
* @param res the PDF resource context to add the shading, may be null
* @param theShadingType 4, 6, or 7 depending on whether it's
* Free-form gouraud-shaded triangle meshes, coons patch meshes,
* or tensor product patch meshes, respectively.
@@ -700,6 +718,7 @@ public class PDFDocument {
* @param theBitsPerFlag 2,4,8.
* @param theDecode List of Doubles see PDF 1.3 spec pages 303 to 312.
* @param theFunction the PDFFunction
* @return the PDF shading that was created
*/
public PDFShading makeShading(PDFResourceContext res, int theShadingType,
PDFColorSpace theColorSpace,
@@ -743,6 +762,7 @@ public class PDFDocument {
/**
* make a Lattice-Form Gouraud mesh shading object
*
* @param res the PDF resource context to add the shading, may be null
* @param theShadingType 5 for lattice-Form Gouraud shaded-triangle mesh
* without spaces. "Shading1" or "Sh1" are good examples.
* @param theColorSpace "DeviceRGB" or similar.
@@ -759,6 +779,7 @@ public class PDFDocument {
* @param theDecode List of Doubles. See page 305 in PDF 1.3 spec.
* @param theVerticesPerRow number of vertices in each "row" of the lattice.
* @param theFunction The PDFFunction that's mapped on to this shape
* @return the PDF shading that was created
*/
public PDFShading makeShading(PDFResourceContext res, int theShadingType,
PDFColorSpace theColorSpace,
@@ -801,6 +822,7 @@ public class PDFDocument {
/**
* Make a tiling pattern
*
* @param res the PDF resource context to add the shading, may be null
* @param thePatternType the type of pattern, which is 1 for tiling.
* @param theResources the resources associated with this pattern
* @param thePaintType 1 or 2, colored or uncolored.
@@ -811,6 +833,7 @@ public class PDFDocument {
* @param theMatrix Optional List of Doubles transformation matrix
* @param theXUID Optional vector of Integers that uniquely identify the pattern
* @param thePatternDataStream The stream of pattern data to be tiled.
* @return the PDF pattern that was created
*/
public PDFPattern makePattern(PDFResourceContext res, int thePatternType, // 1
PDFResources theResources, int thePaintType, int theTilingType,
@@ -849,11 +872,13 @@ public class PDFDocument {
/**
* Make a smooth shading pattern
*
* @param res the PDF resource context to add the shading, may be null
* @param thePatternType the type of the pattern, which is 2, smooth shading
* @param theShading the PDF Shading object that comprises this pattern
* @param theXUID optional:the extended unique Identifier if used.
* @param theExtGState optional: the extended graphics state, if used.
* @param theMatrix Optional:List of Doubles that specify the matrix.
* @return the PDF pattern that was created
*/
public PDFPattern makePattern(PDFResourceContext res,
int thePatternType, PDFShading theShading,
@@ -884,15 +909,37 @@ public class PDFDocument {
return (pattern);
}

/**
* Get the color space.
*
* @return the color space
*/
public int getColorSpace() {
return (this.colorspace.getColorSpace());
}

/**
* Set the color space.
* This is used when creating gradients.
*
* @param theColorspace the new color space
*/
public void setColorSpace(int theColorspace) {
this.colorspace.setColorSpace(theColorspace);
return;
}

/**
* Make a gradient
*
* @param res the PDF resource context to add the shading, may be null
* @param radial if true a radial gradient will be created
* @param theColorspace the colorspace of the gradient
* @param theColors the list of colors for the gradient
* @param theBounds the list of bounds associated with the colors
* @param theCoords the coordinates for the gradient
* @return the PDF pattern that was created
*/
public PDFPattern createGradient(PDFResourceContext res, boolean radial,
PDFColorSpace theColorspace,
List theColors, List theBounds,
@@ -995,12 +1042,13 @@ public class PDFDocument {
return encoding;
}

/**
* Create a PDFICCStream
@see PDFXObject
@see org.apache.fop.image.JpegImage
@see org.apache.fop.pdf.PDFColorSpace
*/
/**
* Create a PDFICCStream
* @see PDFXObject
* @see org.apache.fop.image.JpegImage
* @see org.apache.fop.pdf.PDFColorSpace
* @return the new PDF ICC stream object
*/
public PDFICCStream makePDFICCStream() {
PDFICCStream iccStream = new PDFICCStream(++this.objectcount);
this.objects.add(iccStream);
@@ -1119,6 +1167,9 @@ public class PDFDocument {

/**
* make a /FontDescriptor object
*
* @param desc the font descriptor
* @return the new PDF font descriptor
*/
public PDFFontDescriptor makeFontDescriptor(FontDescriptor desc) {
PDFFontDescriptor font = null;
@@ -1156,6 +1207,13 @@ public class PDFDocument {
return font;
}

/**
* Resolve a URI.
*
* @param uri the uri to resolve
* @throws java.io.FileNotFoundException if the URI could not be resolved
* @return the InputStream from the URI.
*/
protected InputStream resolveURI(String uri)
throws java.io.FileNotFoundException {
try {
@@ -1175,10 +1233,13 @@ public class PDFDocument {
*/
public PDFStream makeFontFile(int obj, FontDescriptor desc) {
if (desc.getFontType() == FontType.OTHER) {
throw new IllegalArgumentException("Trying to embed unsupported font type: " + desc.getFontType());
throw new IllegalArgumentException("Trying to embed unsupported font type: "
+ desc.getFontType());
}
if (!(desc instanceof CustomFont)) {
throw new IllegalArgumentException("FontDescriptor must be instance of CustomFont, but is a " + desc.getClass().getName());
throw new IllegalArgumentException(
"FontDescriptor must be instance of CustomFont, but is a "
+ desc.getClass().getName());
}
CustomFont font = (CustomFont)desc;
@@ -1186,52 +1247,59 @@ public class PDFDocument {
InputStream in = null;
try {
// Get file first
if (font.getEmbedFileName() != null) try {
in = resolveURI(font.getEmbedFileName());
} catch (Exception e) {
System.out.println("Failed to embed fontfile: "
+ font.getEmbedFileName());
if (font.getEmbedFileName() != null) {
try {
in = resolveURI(font.getEmbedFileName());
} catch (Exception e) {
System.out.println("Failed to embed fontfile: "
+ font.getEmbedFileName());
}
}
// Get resource
if (in == null && font.getEmbedResourceName() != null) try {
in = new java.io.BufferedInputStream(
this.getClass().getResourceAsStream(font.getEmbedResourceName()));
} catch (Exception e) {
System.out.println("Failed to embed fontresource: "
+ font.getEmbedResourceName());
if (in == null && font.getEmbedResourceName() != null) {
try {
in = new java.io.BufferedInputStream(
this.getClass().getResourceAsStream(font.getEmbedResourceName()));
} catch (Exception e) {
System.out.println("Failed to embed fontresource: "
+ font.getEmbedResourceName());
}
}
if (in == null) {
return null;
} else try {
PDFStream embeddedFont;
if (desc.getFontType() == FontType.TYPE0) {
MultiByteFont mbfont = (MultiByteFont)font;
FontFileReader reader = new FontFileReader(in);
TTFSubSetFile subset = new TTFSubSetFile();
byte[] subsetFont = subset.readFont(reader, mbfont.getTTCName(), mbfont.getUsedGlyphs());
// Only TrueType CID fonts are supported now
} else {
try {
PDFStream embeddedFont;
if (desc.getFontType() == FontType.TYPE0) {
MultiByteFont mbfont = (MultiByteFont)font;
FontFileReader reader = new FontFileReader(in);

TTFSubSetFile subset = new TTFSubSetFile();
embeddedFont = new PDFTTFStream(obj, subsetFont.length);
((PDFTTFStream)embeddedFont).setData(subsetFont, subsetFont.length);
} else if (desc.getFontType() == FontType.TYPE1) {
PFBParser parser = new PFBParser();
PFBData pfb = parser.parsePFB(in);
embeddedFont = new PDFT1Stream(obj);
((PDFT1Stream)embeddedFont).setData(pfb);
} else {
byte[] file = StreamUtilities.toByteArray(in, 128000);
embeddedFont = new PDFTTFStream(obj, file.length);
((PDFTTFStream)embeddedFont).setData(file, file.length);
byte[] subsetFont = subset.readFont(reader,
mbfont.getTTCName(), mbfont.getUsedGlyphs());
// Only TrueType CID fonts are supported now

embeddedFont = new PDFTTFStream(obj, subsetFont.length);
((PDFTTFStream)embeddedFont).setData(subsetFont, subsetFont.length);
} else if (desc.getFontType() == FontType.TYPE1) {
PFBParser parser = new PFBParser();
PFBData pfb = parser.parsePFB(in);
embeddedFont = new PDFT1Stream(obj);
((PDFT1Stream)embeddedFont).setData(pfb);
} else {
byte[] file = StreamUtilities.toByteArray(in, 128000);
embeddedFont = new PDFTTFStream(obj, file.length);
((PDFTTFStream)embeddedFont).setData(file, file.length);
}
embeddedFont.addFilter("flate");
embeddedFont.addFilter("ascii-85");
return embeddedFont;
} finally {
in.close();
}
embeddedFont.addFilter("flate");
embeddedFont.addFilter("ascii-85");
return embeddedFont;
} finally {
in.close();
}
} catch (IOException ioe) {
//log.error("Failed to embed font [" + obj + "] "
@@ -1239,8 +1307,6 @@ public class PDFDocument {
return (PDFStream) null;
}
}


/*
public PDFStream getFontFile(int i) {
@@ -1259,9 +1325,11 @@ public class PDFDocument {

/**
* make an Array object (ex. Widths array for a font)
*
* @param values the int array values
* @return the PDF Array with the int values
*/
public PDFArray makeArray(int[] values) {

PDFArray array = new PDFArray(++this.objectcount, values);
this.objects.add(array);
return array;
@@ -1269,6 +1337,13 @@ public class PDFDocument {

/**
* make an ExtGState for extra graphics options
* This tries to find a GState that will setup the correct values
* for the current context. If there is no suitable GState it will
* create a new one.
*
* @param settings the settings required by the caller
* @param current the current GState of the current PDF context
* @return a PDF GState, either an existing GState or a new one
*/
public PDFGState makeGState(Map settings, PDFGState current) {

@@ -1298,11 +1373,27 @@ public class PDFDocument {
return gstate;
}

/**
* Get an image from the image map.
*
* @param key the image key to look for
* @return the image or PDFXObject for the key if found
*/
public PDFXObject getImage(String key) {
PDFXObject xObject = (PDFXObject)xObjectsMap.get(key);
return xObject;
}

/**
* Add an image to the PDF document.
* This adds an image to the PDF objects.
* If an image with the same key already exists it will return the
* old PDFXObject.
*
* @param res the PDF resource context to add to, may be null
* @param img the PDF image to add
* @return the PDF XObject that references the PDF image data
*/
public PDFXObject addImage(PDFResourceContext res, PDFImage img) {
// check if already created
String key = img.getKey();
@@ -1328,7 +1419,20 @@ public class PDFDocument {
return xObject;
}

public PDFFormXObject addFormXObject(PDFResourceContext res, PDFStream cont, PDFResources formres, String key) {
/**
* Add a form XObject to the PDF document.
* This adds a Form XObject to the PDF objects.
* If a Form XObject with the same key already exists it will return the
* old PDFFormXObject.
*
* @param res the PDF resource context to add to, may be null
* @param cont the PDF Stream contents of the Form XObject
* @param formres the PDF Resources for the Form XObject data
* @param key the key for the object
* @return the PDF Form XObject that references the PDF data
*/
public PDFFormXObject addFormXObject(PDFResourceContext res, PDFStream cont,
PDFResources formres, String key) {
PDFFormXObject xObject;
xObject = new PDFFormXObject(++this.objectcount, ++this.xObjectCount,
cont, formres.referencePDF());
@@ -1338,14 +1442,12 @@ public class PDFDocument {
res.getPDFResources().addXObject(xObject);
}
return xObject;

}

/**
* make a /Page object
*
* @param resources resources object to use
* @param contents stream object with content
* @param pagewidth width of the page in points
* @param pageheight height of the page in points
*
@@ -1366,6 +1468,12 @@ public class PDFDocument {
return page;
}

/**
* Add a completed page to the PDF document.
* The page is added to the object list.
*
* @param page the page to add
*/
public void addPage(PDFPage page) {
/* add it to the list of objects */
this.objects.add(page);
@@ -1393,6 +1501,7 @@ public class PDFDocument {
* @param rect the clickable rectangle
* @param destination the destination file
* @param linkType the link type
* @param yoffset the yoffset on the page for an internal link
* @return the PDFLink object created
*/
public PDFLink makeLink(Rectangle2D rect, String destination,
@@ -1502,10 +1611,24 @@ public class PDFDocument {
return goToReference;
}

/**
* Add trailer object.
* Adds an object to the list of trailer objects.
*
* @param object the PDF object to add
*/
public void addTrailerObject(PDFObject object) {
this.trailerObjects.add(object);
}

/**
* Make an internal link.
*
* @param rect the hotspot position in absolute coordinates
* @param page the target page reference value
* @param dest the position destination
* @return the new PDF link object
*/
public PDFLink makeLink(Rectangle2D rect, String page, String dest) {
PDFLink link = new PDFLink(++this.objectcount, rect);
this.objects.add(link);
@@ -1520,8 +1643,8 @@ public class PDFDocument {
}

/**
Ensure there is room in the locations xref for the number of
objects that have been created.
* Ensure there is room in the locations xref for the number of
* objects that have been created.
*/
private void prepareLocations() {
while (location.size() < objectcount) {
@@ -1532,6 +1655,8 @@ public class PDFDocument {
/**
* make a stream object
*
* @param type the type of stream to be created
* @param add if true then the stream will be added immediately
* @return the stream object created
*/
public PDFStream makeStream(String type, boolean add) {
@@ -1607,6 +1732,7 @@ public class PDFDocument {
* @param parent parent PDFOutline object which may be null
* @param label the title for the new outline object
* @param destination the reference string for the action to go to
* @param yoffset the yoffset on the destination page
* @return the new PDF outline object
*/
public PDFOutline makeOutline(PDFOutline parent, String label,

+ 7
- 6
src/org/apache/fop/pdf/PDFEncoding.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -8,9 +8,10 @@
package org.apache.fop.pdf;

// Java
import java.util.List;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.ArrayList;

/**
* class representing an /Encoding object.
@@ -20,7 +21,7 @@ import java.util.ArrayList;
*
* The three base encodings are given by their name.
*
* Encodings are specified on page 213 and onwards of the PDF 1.3 spec.
* Encodings are specified in section 5.5.5 of the PDF 1.4 spec.
*/
public class PDFEncoding extends PDFObject {

@@ -49,7 +50,7 @@ public class PDFEncoding extends PDFObject {
/**
* the differences from the base encoding
*/
protected HashMap differences;
protected Map differences;

/**
* create the /Encoding object
@@ -73,7 +74,7 @@ public class PDFEncoding extends PDFObject {
* @param code the first index of the sequence to be changed
* @param sequence the sequence of glyph names (as String)
*/
public void addDifferences(int code, ArrayList sequence) {
public void addDifferences(int code, List sequence) {
differences.put(new Integer(code), sequence);
}

@@ -97,7 +98,7 @@ public class PDFEncoding extends PDFObject {
code = codes.next();
p.append(" ");
p.append(code);
ArrayList sequence = (ArrayList)differences.get(code);
List sequence = (List)differences.get(code);
for (int i = 0; i < sequence.size(); i++) {
p.append(" /");
p.append((String)sequence.get(i));

+ 1
- 1
src/org/apache/fop/pdf/PDFFileSpec.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/

+ 30
- 10
src/org/apache/fop/pdf/PDFFilter.java View File

@@ -1,18 +1,23 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/


// Author: Eric SCHAEFFER, Kelly A. Campbell
// Description: represent a PDF filter object

package org.apache.fop.pdf;

import java.io.*;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

/**
* PDF Filter class.
* This represents a PDF filter object.
* Filter implementations should extend this class.
*
* @author Eric SCHAEFFER, Kelly A. Campbell
*/
public abstract class PDFFilter {
/*
* These are no longer needed, but are here as a reminder about what
@@ -29,10 +34,15 @@ public abstract class PDFFilter {
/**
* Marker to know if this filter has already been applied to the data
*/
private boolean _applied = false;
private boolean applied = false;

/**
* Check if this filter has been applied.
*
* @return true if this filter has been applied
*/
public boolean isApplied() {
return _applied;
return applied;
}

/**
@@ -43,24 +53,34 @@ public abstract class PDFFilter {
* out of an image file in it's compressed format, then this
* should be set to true and the filter options should be set to
* those which the raw data was encoded with.
*
* @param b set the applied value to this
*/
public void setApplied(boolean b) {
_applied = b;
applied = b;
}


/**
* return a PDF string representation of the filter, e.g. /FlateDecode
*
* @return the filter PDF name
*/
public abstract String getName();

/**
* return a parameter dictionary for this filter, or null
*
* @return the decode params for the filter
*/
public abstract String getDecodeParms();

/**
* encode the given data with the filter
*
* @param in the input data stream to encode
* @param out the output stream to write the result
* @param length the length of data to read from the input stream
* @throws IOException if there is an error reading or writing the data
*/
public abstract void encode(InputStream in, OutputStream out, int length) throws IOException;


+ 16
- 7
src/org/apache/fop/pdf/PDFFilterException.java View File

@@ -1,23 +1,32 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/

// Author: Eric SCHAEFFER
// Description: Filter Exception

package org.apache.fop.pdf;

/**
* PDF Filter exception.
* This is used for exceptions relating to use a PDF filter.
*
* @author Eric SCHAEFFER
*/
public class PDFFilterException extends Exception {

/**
* Create a basic filter exception.
*/
public PDFFilterException() {
super();
}

/**
* Create a filter exception with a message.
*
* @param message the error message
*/
public PDFFilterException(String message) {
super(message);
}

}


+ 1
- 0
src/org/apache/fop/pdf/PDFFormXObject.java View File

@@ -28,6 +28,7 @@ public class PDFFormXObject extends PDFXObject {
* @param number the pdf object number
* @param xnumber the pdf object X number
* @param cont the pdf stream contents
* @param ref the resource PDF reference
*/
public PDFFormXObject(int number, int xnumber, PDFStream cont, String ref) {
super(number, xnumber, null);

+ 46
- 17
src/org/apache/fop/pdf/PDFFunction.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -13,7 +13,8 @@ import java.util.List;
/**
* class representing a PDF Function.
*
* PDF Functions represent parameterized mathematical formulas and sampled representations with
* PDF Functions represent parameterized mathematical formulas and
* sampled representations with
* arbitrary resolution. Functions are used in two areas: device-dependent
* rasterization information for halftoning and transfer
* functions, and color specification for smooth shading (a PDF 1.3 feature).
@@ -49,25 +50,32 @@ public class PDFFunction extends PDFObject {
protected List size = null;

/**
* Required for Type 0: Number of Bits used to represent each sample value. Limited to 1,2,4,8,12,16,24, or 32
* Required for Type 0: Number of Bits used to represent each sample value.
* Limited to 1,2,4,8,12,16,24, or 32
*/
protected int bitsPerSample = 1;

/**
* Optional for Type 0: order of interpolation between samples. Limited to linear (1) or cubic (3). Default is 1
* Optional for Type 0: order of interpolation between samples.
* Limited to linear (1) or cubic (3). Default is 1
*/
protected int order = 1;

/**
* Optional for Type 0: A 2 * m array of Doubles which provides a linear mapping of input values to the domain.
* Optional for Type 0: A 2 * m array of Doubles which provides a
* linear mapping of input values to the domain.
*
* Required for Type 3: A 2 * k array of Doubles that, taken in pairs, map each subset of the domain defined by Domain and the Bounds array to the domain of the corresponding function.
* Should be two values per function, usually (0,1), as in [0 1 0 1] for 2 functions.
* Required for Type 3: A 2 * k array of Doubles that, taken
* in pairs, map each subset of the domain defined by Domain
* and the Bounds array to the domain of the corresponding function.
* Should be two values per function, usually (0,1),
* as in [0 1 0 1] for 2 functions.
*/
protected List encode = null;

/**
* Optinoal for Type 0: A 2 * n array of Doubles which provides a linear mapping of sample values to the range. Defaults to Range.
* Optional for Type 0: A 2 * n array of Doubles which provides
* a linear mapping of sample values to the range. Defaults to Range.
*/
protected List decode = null;

@@ -76,24 +84,28 @@ public class PDFFunction extends PDFObject {
*/

/**
* Required For Type 4: Postscript Calculator function composed of arithmetic, boolean, and stack operators + boolean constants
* Required For Type 4: Postscript Calculator function
* composed of arithmetic, boolean, and stack operators + boolean constants
*/
protected StringBuffer functionDataStream = null;

/**
* Required (?) For Type 0: A vector of Strings for the various filters to be used to decode the stream.
* Required (?) For Type 0: A vector of Strings for the
* various filters to be used to decode the stream.
* These are how the string is compressed. Flate, LZW, etc.
*/
protected List filter = null;
/* *************************TYPE 2************************** */

/**
* Required For Type 2: An Array of n Doubles defining the function result when x=0. Default is [0].
* Required For Type 2: An Array of n Doubles defining
* the function result when x=0. Default is [0].
*/
protected List cZero = null;

/**
* Required For Type 2: An Array of n Doubles defining the function result when x=1. Default is [1].
* Required For Type 2: An Array of n Doubles defining
* the function result when x=1. Default is [1].
*/
protected List cOne = null;

@@ -107,12 +119,18 @@ public class PDFFunction extends PDFObject {
/* *************************TYPE 3************************** */

/**
* Required for Type 3: An vector of PDFFunctions which form an array of k single input functions making up the stitching function.
* Required for Type 3: An vector of PDFFunctions which
* form an array of k single input functions making up
* the stitching function.
*/
protected List functions = null;

/**
* Optional for Type 3: An array of (k-1) Doubles that, in combination with Domain, define the intervals to which each function from the Functions array apply. Bounds elements must be in order of increasing magnitude, and each value must be within the value of Domain.
* Optional for Type 3: An array of (k-1) Doubles that,
* in combination with Domain, define the intervals to which
* each function from the Functions array apply. Bounds
* elements must be in order of increasing magnitude,
* and each value must be within the value of Domain.
* k is the number of functions.
* If you pass null, it will output (1/k) in an array of k-1 elements.
* This makes each function responsible for an equal amount of the stitching function.
@@ -142,7 +160,8 @@ public class PDFFunction extends PDFObject {
* so maybe this should be an array of length 2.
*
* See page 265 of the PDF 1.3 Spec.
* @param theBitsPerSample An int specifying the number of bits user to represent each sample value.
* @param theBitsPerSample An int specifying the number of bits
used to represent each sample value.
* Limited to 1,2,4,8,12,16,24 or 32.
* See page 265 of the 1.3 PDF Spec.
* @param theOrder The order of interpolation between samples. Default is 1 (one). Limited
@@ -164,7 +183,8 @@ public class PDFFunction extends PDFObject {
*
* This attribute is optional.
* Read about it on page 265 of the PDF 1.3 spec.
* @param theFunctionDataStream The sample values that specify the function are provided in a stream.
* @param theFunctionDataStream The sample values that specify
* the function are provided in a stream.
*
* This is optional, but is almost always used.
*
@@ -310,7 +330,8 @@ public class PDFFunction extends PDFObject {
* @param theRange List object of Double objects.
* This is the Range of the function.
* See page 264 of the PDF 1.3 Spec.
* @param theFunctionDataStream This is a stream of arithmetic, boolean, and stack operators and boolean constants.
* @param theFunctionDataStream This is a stream of arithmetic,
* boolean, and stack operators and boolean constants.
* I end up enclosing it in the '{' and '}' braces for you, so don't do it
* yourself.
*
@@ -667,6 +688,14 @@ public class PDFFunction extends PDFObject {

}

/**
* Check if this function is equal to another object.
* This is used to find if a particular function already exists
* in a document.
*
* @param obj the obj to compare
* @return true if the functions are equal
*/
public boolean equals(Object obj) {
if (obj == null) {
return false;

+ 20
- 14
src/org/apache/fop/pdf/PDFGoTo.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -9,16 +9,18 @@ package org.apache.fop.pdf;

/**
* class representing a /GoTo object.
*
* This can either have a Goto to a page reference and location
* or to a specified PDF reference string.
*/
public class PDFGoTo extends PDFAction {

/**
* the pageReference
*/
protected String pageReference;
protected String destination = null;
protected float xPosition = 0, yPosition = 0;
private String pageReference;
private String destination = null;
private float xPosition = 0;
private float yPosition = 0;

/**
* create a /GoTo object.
@@ -27,26 +29,21 @@ public class PDFGoTo extends PDFAction {
* @param pageReference the pageReference represented by this object
*/
public PDFGoTo(int number, String pageReference) {

/* generic creation of object */
super(number);

this.pageReference = pageReference;
}


/**
* Sets page reference after object has been created
*
* @param pageReference
* the new page reference to use
* @param pageReference the new page reference to use
*/
public void setPageReference(String pageReference) {
this.pageReference = pageReference;
}



/**
* Sets the Y position to jump to
*
@@ -56,6 +53,11 @@ public class PDFGoTo extends PDFAction {
this.yPosition = yPosition;
}

/**
* Set the destination string for this Goto.
*
* @param dest the PDF destination string
*/
public void setDestination(String dest) {
destination = dest;
}
@@ -69,11 +71,15 @@ public class PDFGoTo extends PDFAction {
this.xPosition = (xPosition / 1000f);
}

/**
* Get the PDF reference for the GoTo action.
*
* @return the PDF reference for the action
*/
public String getAction() {
return referencePDF();
}


/**
* represent the object in PDF
*
@@ -81,7 +87,7 @@ public class PDFGoTo extends PDFAction {
*/
public byte[] toPDF() {
String dest;
if(destination == null) {
if (destination == null) {
dest = "/D [" + this.pageReference + " /XYZ " + xPosition
+ " " + yPosition + " null]\n";
} else {
@@ -130,7 +136,7 @@ public class PDFGoTo extends PDFAction {
}
}

if(destination == null) {
if (destination == null) {
if (!(gt.destination == null && gt.xPosition == xPosition
&& gt.yPosition == yPosition)) {
return false;

+ 7
- 10
src/org/apache/fop/pdf/PDFGoToRemote.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -15,18 +15,17 @@ public class PDFGoToRemote extends PDFAction {
/**
* the file specification
*/
protected PDFFileSpec pdfFileSpec;
protected int pageReference = 0;
protected String destination = null;
private PDFFileSpec pdfFileSpec;
private int pageReference = 0;
private String destination = null;

/**
* create an GoToR object.
*
* @param number the object's number
* @param fileSpec the fileSpec associated with the action
* @param pdfFileSpec the fileSpec associated with the action
*/
public PDFGoToRemote(int number, PDFFileSpec pdfFileSpec) {

/* generic creation of object */
super(number);

@@ -37,11 +36,10 @@ public class PDFGoToRemote extends PDFAction {
* create an GoToR object.
*
* @param number the object's number
* @param fileSpec the fileSpec associated with the action
* @param pdfFileSpec the fileSpec associated with the action
* @param page a page reference within the remote document
*/
public PDFGoToRemote(int number, PDFFileSpec pdfFileSpec, int page) {

/* generic creation of object */
super(number);

@@ -53,11 +51,10 @@ public class PDFGoToRemote extends PDFAction {
* create an GoToR object.
*
* @param number the object's number
* @param fileSpec the fileSpec associated with the action
* @param pdfFileSpec the fileSpec associated with the action
* @param dest a named destination within the remote document
*/
public PDFGoToRemote(int number, PDFFileSpec pdfFileSpec, String dest) {

/* generic creation of object */
super(number);


+ 91
- 19
src/org/apache/fop/pdf/PDFImage.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -9,36 +9,108 @@ package org.apache.fop.pdf;

import java.io.IOException;

/**
* Interface for a PDF image.
* This is used for inserting an image into PDF.
*/
public interface PDFImage {

// key to look up XObject
public String getKey();
/**
* Key to look up XObject.
* This should be a unique key to refer to the image.
*
* @return the key for this image
*/
String getKey();

/**
* Setup the PDF image for the current document.
* Some image formats may need to access the document.
*
* @param doc the PDF parent document
*/
void setup(PDFDocument doc);

/**
* Get the image width in pixels.
*
* @return the image width
*/
int getWidth();

/**
* Get the image height in pixels.
*
* @return the image height
*/
int getHeight();

/**
* Get the color space for this image.
* Possible results are: DeviceGray, DeviceRGB, or DeviceCMYK
*
* @return the color space
*/
PDFColorSpace getColorSpace();

public void setup(PDFDocument doc);
/**
* Get the bits per pixel for this image.
*
* @return the bits per pixel
*/
int getBitsPerPixel();

// image size
public int getWidth();
public int getHeight();
/**
* Check if this image is a PostScript image.
*
* @return true if this is a PostScript image
*/
boolean isPS();

// DeviceGray, DeviceRGB, or DeviceCMYK
public PDFColorSpace getColorSpace();
/**
* Check if this image has a transparent color transparency.
*
* @return true if it has transparency
*/
boolean isTransparent();

// bits per pixel
public int getBitsPerPixel();
/**
* Get the transparent color.
*
* @return the transparent color for this image
*/
PDFColor getTransparentColor();

public boolean isPS();
/**
* Get the PDF reference for a bitmap mask.
*
* @return the PDF reference for the mask image
*/
String getMask();

// For transparent images
public boolean isTransparent();
public PDFColor getTransparentColor();
public String getMask();
public String getSoftMask();
/**
* Get the PDF reference for a soft mask.
*
* @return the PDF reference for a soft mask image
*/
String getSoftMask();

// get the image bytes, and bytes properties

public PDFStream getDataStream() throws IOException;
/**
* Get the data stream containing the image contents.
*
* @throws IOException if there creating stream
* @return the PDFStream containing the image data
*/
PDFStream getDataStream() throws IOException;

public PDFICCStream getICCStream();
/**
* Get the ICC stream for this image.
*
* @return the ICC stream for this image if any
*/
PDFICCStream getICCStream();

}


+ 27
- 7
src/org/apache/fop/pdf/PDFInfo.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -18,16 +18,16 @@ public class PDFInfo extends PDFObject {
/**
* the application producing the PDF
*/
protected String producer;
private String producer;

protected String title = null;
protected String author = null;
protected String subject = null;
protected String keywords = null;
private String title = null;
private String author = null;
private String subject = null;
private String keywords = null;

// the name of the application that created the
// original document before converting to PDF
protected String creator;
private String creator;

/**
* create an Info object
@@ -56,18 +56,38 @@ public class PDFInfo extends PDFObject {
this.creator = creator;
}

/**
* set the title string
*
* @param t the document title
*/
public void setTitle(String t) {
this.title = t;
}

/**
* set the author string
*
* @param a the document author
*/
public void setAuthor(String a) {
this.author = a;
}

/**
* set the subject string
*
* @param s the document subject
*/
public void setSubject(String s) {
this.subject = s;
}

/**
* set the keywords string
*
* @param k the keywords for this document
*/
public void setKeywords(String k) {
this.keywords = k;
}

+ 2
- 3
src/org/apache/fop/pdf/PDFInternalLink.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -12,8 +12,7 @@ package org.apache.fop.pdf;
*/
public class PDFInternalLink extends PDFAction {


String goToReference;
private String goToReference;

/**
* create an internal link instance.

+ 27
- 28
src/org/apache/fop/pdf/PDFNumber.java View File

@@ -1,47 +1,37 @@
/*
* $Id$
* Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 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;

/**
* This class contains some utility methods for outputing numbers to PDF.
*/
public class PDFNumber {

/** prevent instantiation */
private PDFNumber() { }

/**
* Output a Double value to a string suitable for PDF.
*
* @param doubleDown the Double value
* @return the value as a string
*/
public static String doubleOut(Double doubleDown) {
StringBuffer p = new StringBuffer();
if (doubleDown.doubleValue() < 0) {
doubleDown = new Double(-doubleDown.doubleValue());
p.append("-");
}
double trouble = doubleDown.doubleValue() % 1;
if (trouble > 0.950) {
p.append(doubleDown.intValue() + 1);
} else if (trouble < 0.050) {
p.append(doubleDown.intValue());
} else {
String doubleString = new String(doubleDown + "");
int decimal = doubleString.indexOf(".");
if (decimal != -1) {
p.append(doubleString.substring(0, decimal));

if ((doubleString.length() - decimal) > 6) {
p.append(doubleString.substring(decimal, decimal + 6));
} else {
p.append(doubleString.substring(decimal));
}
} else {
p.append(doubleString);
}
}
return (p.toString());
return doubleOut(doubleDown.doubleValue());
}

/**
* Output a double value to a string suitable for PDF.
*
* @param doubleDown the double value
* @return the value as a string
*/
public static String doubleOut(double doubleDown) {

StringBuffer p = new StringBuffer();
if (doubleDown < 0) {
doubleDown = -doubleDown;
@@ -71,6 +61,15 @@ public class PDFNumber {
return (p.toString());
}

/**
* Output a double value to a string suitable for PDF.
* In this method it is possible to set the maximum
* number of decimal places to output.
*
* @param doubleDown the Double value
* @param dec the number of decimal places to output
* @return the value as a string
*/
public static String doubleOut(double doubleDown, int dec) {
StringBuffer p = new StringBuffer();
if (doubleDown < 0) {

+ 5
- 1
src/org/apache/fop/pdf/PDFObject.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -39,6 +39,9 @@ public abstract class PDFObject {
this.number = number;
}

/**
* Create a PDFObject
*/
public PDFObject() {
// do nothing
}
@@ -54,6 +57,7 @@ public abstract class PDFObject {
* write the PDF represention of this object
*
* @param stream the stream to write the PDF to
* @throws IOException if there is an error writing to the stream
* @return the number of bytes written
*/
protected int output(OutputStream stream) throws IOException {

+ 71
- 63
src/org/apache/fop/pdf/PDFOutline.java View File

@@ -1,14 +1,14 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 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.util.Vector;
import java.util.List;
import java.util.ArrayList;

/**
* This represents a single Outline object in a PDF, including the root Outlines
@@ -18,125 +18,133 @@ import java.util.Vector;
* @author Kelly A. Campbell
*
*/

public class PDFOutline extends PDFObject {

/**
* list of sub-entries (outline objects)
*/
private Vector _subentries;
private List subentries;

/**
* parent outline object. Root Outlines parent is null
*/
private PDFOutline _parent;
private PDFOutline parent;

private PDFOutline _prev;
private PDFOutline _next;
private PDFOutline prev;
private PDFOutline next;

private PDFOutline _first;
private PDFOutline _last;

private int _count;
private PDFOutline first;
private PDFOutline last;

private int count;

/**
* title to display for the bookmark entry
*/
private String _title;

String _actionRef;

private String title;

private String actionRef;

/**
* Create a PDF outline with the title and action.
*
* @param number the object id number
* @param title the title of the outline entry (can only be null for root Outlines obj)
* @param page the page which this outline refers to.
* @param action the action for this outline
*/
public PDFOutline(int number, String title, String action) {
super(number);
_subentries = new Vector();
_count = 0;
_parent = null;
_prev = null;
_next = null;
_first = null;
_last = null;
_title = title;
_actionRef = action;


subentries = new ArrayList();
count = 0;
parent = null;
prev = null;
next = null;
first = null;
last = null;
title = title;
actionRef = action;
}

public void setTitle(String title) {
_title = title;
/**
* Set the title of this Outline object.
*
* @param t the title of the outline
*/
public void setTitle(String t) {
title = t;
}

/**
* Add a sub element to this outline
* Add a sub element to this outline.
*
* @param outline a sub outline
*/
public void addOutline(PDFOutline outline) {
if (_subentries.size() > 0) {
outline._prev =
(PDFOutline)_subentries.elementAt(_subentries.size() - 1);
outline._prev._next = outline;
if (subentries.size() > 0) {
outline.prev =
(PDFOutline)subentries.get(subentries.size() - 1);
outline.prev.next = outline;
} else {
_first = outline;
first = outline;
}

_subentries.addElement(outline);
outline._parent = this;

incrementCount(); // note: count is not just the immediate children
subentries.add(outline);
outline.parent = this;

_last = outline;
// note: count is not just the immediate children
incrementCount();

last = outline;
}

/**
* Increment the number of subentries and descendants.
*/
private void incrementCount() {
// count is a total of our immediate subentries and all descendent subentries
_count++;
if (_parent != null) {
_parent.incrementCount();
// count is a total of our immediate subentries
// and all descendent subentries
count++;
if (parent != null) {
parent.incrementCount();
}
}


/**
* represent the object in PDF
*
* @return the PDF for this outline
*/
protected byte[] toPDF() {
StringBuffer result = new StringBuffer(this.number + " "
+ this.generation
+ " obj\n<<\n");
if (_parent == null) {
if (parent == null) {
// root Outlines object
if (_first != null && _last != null) {
result.append(" /First " + _first.referencePDF() + "\n");
result.append(" /Last " + _last.referencePDF() + "\n");
if (first != null && last != null) {
result.append(" /First " + first.referencePDF() + "\n");
result.append(" /Last " + last.referencePDF() + "\n");
// no count... we start with the outline completely closed for now
}
} else {
// subentry Outline object
result.append(" /Title (" + escapeString(_title) + ")\n");
result.append(" /Parent " + _parent.referencePDF() + "\n");
if (_first != null && _last != null) {
result.append(" /First " + _first.referencePDF() + "\n");
result.append(" /Last " + _last.referencePDF() + "\n");
result.append(" /Title (" + escapeString(title) + ")\n");
result.append(" /Parent " + parent.referencePDF() + "\n");
if (first != null && last != null) {
result.append(" /First " + first.referencePDF() + "\n");
result.append(" /Last " + last.referencePDF() + "\n");
}
if (_prev != null) {
result.append(" /Prev " + _prev.referencePDF() + "\n");
if (prev != null) {
result.append(" /Prev " + prev.referencePDF() + "\n");
}
if (_next != null) {
result.append(" /Next " + _next.referencePDF() + "\n");
if (next != null) {
result.append(" /Next " + next.referencePDF() + "\n");
}
if (_count > 0) {
result.append(" /Count -" + _count + "\n");
if (count > 0) {
result.append(" /Count -" + count + "\n");
}

if (_actionRef != null) {
result.append(" /A " + _actionRef + "\n");
if (actionRef != null) {
result.append(" /A " + actionRef + "\n");
}



+ 11
- 1
src/org/apache/fop/pdf/PDFPage.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -56,6 +56,7 @@ public class PDFPage extends PDFResourceContext {
/**
* create a /Page object
*
* @param doc the PDF document holding this page
* @param number the object's number
* @param resources the /Resources object
* @param contents the content stream
@@ -77,6 +78,7 @@ public class PDFPage extends PDFResourceContext {
/**
* create a /Page object
*
* @param doc the PDF document holding this page
* @param number the object's number
* @param resources the /Resources object
* @param pagewidth the page's width in points
@@ -111,6 +113,14 @@ public class PDFPage extends PDFResourceContext {
this.parent = parent.referencePDF();
}

/**
* Set the transition dictionary and duration.
* This sets the duration of the page and the transition
* dictionary used when going to the next page.
*
* @param dur the duration in seconds
* @param tr the transition dictionary
*/
public void setTransition(int dur, TransitionDictionary tr) {
duration = dur;
trDictionary = tr;

+ 3
- 3
src/org/apache/fop/pdf/PDFPages.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -8,7 +8,7 @@
package org.apache.fop.pdf;

// Java
import java.io.PrintWriter;
import java.util.List;
import java.util.ArrayList;

/**
@@ -23,7 +23,7 @@ public class PDFPages extends PDFObject {
/**
* the /Page objects
*/
protected ArrayList kids = new ArrayList();
protected List kids = new ArrayList();

/**
* the number of /Page objects

+ 33
- 4
src/org/apache/fop/pdf/PDFPathPaint.java View File

@@ -1,36 +1,65 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 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;

/**
* Base class for PDF painting operations.
*
*/
public abstract class PDFPathPaint extends PDFObject {

// protected int colorspace = 0; //default is 0:RGB, not 1:CMYK
/**
* The color space for this paint
*/
protected PDFColorSpace colorSpace;

/**
* Create a path paint with a PDF object number.
*
* @param theNumber the PDF object number
*/
public PDFPathPaint(int theNumber) {
super(theNumber);

}

/**
* Create an emty path paint.
*/
public PDFPathPaint() {
// do nothing
}

/**
* Get the PDF string for setting the path paint.
*
* @param fillNotStroke if true fill otherwise stroke
* @return the PDF instruction string
*/
public String getColorSpaceOut(boolean fillNotStroke) {
return ("");
}

/**
* Set the color space for this paint.
*
* @param theColorSpace the color space value
*/
public void setColorSpace(int theColorSpace) {
this.colorSpace.setColorSpace(theColorSpace);
}

/**
* Get the current color space value for this paint.
*
* @return the color space value
*/
public int getColorSpace() {
return (this.colorSpace.getColorSpace());
return this.colorSpace.getColorSpace();
}

}

+ 22
- 8
src/org/apache/fop/pdf/PDFPattern.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -28,8 +28,6 @@ public class PDFPattern extends PDFPathPaint {
/**
* The resources associated with this pattern
*/
// Guts common to all function types

protected PDFResources resources = null;

/**
@@ -170,6 +168,12 @@ public class PDFPattern extends PDFPathPaint {
return (this.patternName);
}

/**
* Get the PDF command for setting to this pattern.
*
* @param fillNotStroke if true fill otherwise stroke
* @return the PDF string for setting the pattern
*/
public String getColorSpaceOut(boolean fillNotStroke) {
if (fillNotStroke) { // fill but no stroke
return ("/Pattern cs /" + this.getName() + " scn \n");
@@ -178,7 +182,6 @@ public class PDFPattern extends PDFPathPaint {
}
}


/**
* represent as PDF. Whatever the FunctionType is, the correct
* representation spits out. The sets of required and optional
@@ -188,6 +191,8 @@ public class PDFPattern extends PDFPathPaint {
* by the construction is dutifully output.
* This policy should be reviewed.
*
* @param stream the stream to write to
* @throws IOException if there is an error writing to the stream
* @return the PDF string.
*/
protected int output(OutputStream stream) throws IOException {
@@ -254,8 +259,9 @@ public class PDFPattern extends PDFPathPaint {
+ " \n");
}

} else // if (this.patternType ==2)
{ // Smooth Shading...
} else {
// if (this.patternType ==2)
// Smooth Shading...
if (this.shading != null) {
p.append("/Shading " + this.shading.referencePDF() + " \n");
}
@@ -300,13 +306,21 @@ public class PDFPattern extends PDFPathPaint {
stream.write(end.getBytes());
length += end.length();


return length;

}

/**
* Output PDF bytes, not used.
* @return returns null
*/
public byte[] toPDF() { return null; }

/**
* Check if this pattern is equal to another.
*
* @param obj the object to compare against
* @return true if the patterns are equal
*/
public boolean equals(Object obj) {
if (obj == null) {
return false;

+ 6
- 1
src/org/apache/fop/pdf/PDFRectangle.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -70,6 +70,11 @@ public class PDFRectangle {
return toPDFString().getBytes();
}

/**
* Create a PDF string for this rectangle.
*
* @return the pdf string
*/
public String toPDFString() {
return new String(" [" + llx + " " + lly + " " + urx + " " + ury
+ "] ");

+ 34
- 8
src/org/apache/fop/pdf/PDFResourceContext.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -8,7 +8,7 @@
package org.apache.fop.pdf;

/**
* class representing a /Page object.
* The PDF resource context.
*
* There is one of these for every page in a PDF document. The object
* specifies the dimensions of the page and references a /Resources
@@ -32,18 +32,19 @@ public class PDFResourceContext extends PDFObject {
* the list of annotation objects for this page
*/
protected PDFAnnotList annotList;

/**
* Reference to document used when creating annotation list
*/
protected PDFDocument document;

/**
*
* @param number the object's number
* @param doc the PDF document this belongs to
* @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);

@@ -53,6 +54,11 @@ public class PDFResourceContext extends PDFObject {
this.annotList = null;
}

/**
* Get the resources for this resource context.
*
* @return the resources in this resource context
*/
public PDFResources getPDFResources() {
return this.resources;
}
@@ -60,27 +66,47 @@ public class PDFResourceContext extends PDFObject {
/**
* set this page's annotation list
*
* @param annotList a PDFAnnotList list of annotations
* @param annot a PDFAnnotList list of annotations
*/
public void addAnnotation(PDFObject annot) {
if(this.annotList == null) {
if (this.annotList == null) {
this.annotList = document.makeAnnotList();
}
this.annotList.addAnnot(annot);
}

/**
* Get the current annotations.
*
* @return the current annotation list
*/
public PDFAnnotList getAnnotations() {
return this.annotList;
}

/**
* A a GState to this resource context.
*
* @param gstate the GState to add
*/
public void addGState(PDFGState gstate) {
this.resources.addGState(gstate);
}

/**
* Add the shading tot he current resource context.
*
* @param shading the shading to add
*/
public void addShading(PDFShading shading) {
this.resources.addShading(shading);
}

/**
* Get the PDF, unused.
*
* @return null value
*/
public byte[] toPDF() {
return null;
}

+ 49
- 12
src/org/apache/fop/pdf/PDFResources.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -8,9 +8,9 @@
package org.apache.fop.pdf;

// Java
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import java.util.HashSet;

@@ -25,12 +25,27 @@ public class PDFResources extends PDFObject {
/**
* /Font objects keyed by their internal name
*/
protected HashMap fonts = new HashMap();
protected Map fonts = new HashMap();

protected HashSet xObjects = new HashSet();
protected HashSet patterns = new HashSet();
protected HashSet shadings = new HashSet();
protected HashSet gstates = new HashSet();
/**
* Set of XObjects
*/
protected Set xObjects = new HashSet();

/**
* Set of patterns
*/
protected Set patterns = new HashSet();

/**
* Set of shadings
*/
protected Set shadings = new HashSet();

/**
* Set of ExtGStates
*/
protected Set gstates = new HashSet();

/**
* create a /Resources object.
@@ -51,24 +66,46 @@ public class PDFResources extends PDFObject {
this.fonts.put(font.getName(), font);
}

/**
* Add a PDFGState to the resources.
*
* @param gs the PDFGState to add
*/
public void addGState(PDFGState gs) {
this.gstates.add(gs);
}

/**
* Add a Shading to the resources.
*
* @param theShading the shading to add
*/
public void addShading(PDFShading theShading) {
this.shadings.add(theShading);
}

/**
* Add the pattern to the resources.
*
* @param thePattern the pattern to add
*/
public void addPattern(PDFPattern thePattern) {
this.patterns.add(thePattern);
}

/**
* Add an XObject to the resources.
*
* @param xObject the XObject to add
*/
public void addXObject(PDFXObject xObject) {
this.xObjects.add(xObject);
}

/**
* represent the object in PDF
* This adds the references to all the objects in the current
* resource context.
*
* @return the PDF
*/
@@ -94,7 +131,7 @@ public class PDFResources extends PDFObject {
if (!this.shadings.isEmpty()) {
p.append("/Shading << ");

for (Iterator iter = shadings.iterator(); iter.hasNext(); ) {
for (Iterator iter = shadings.iterator(); iter.hasNext();) {
currentShading = (PDFShading)iter.next();
p.append("/" + currentShading.getName() + " "
+ currentShading.referencePDF() + " "); // \n ??????
@@ -109,7 +146,7 @@ public class PDFResources extends PDFObject {
if (!this.patterns.isEmpty()) {
p.append("/Pattern << ");

for (Iterator iter = patterns.iterator(); iter.hasNext(); ) {
for (Iterator iter = patterns.iterator(); iter.hasNext();) {
currentPattern = (PDFPattern)iter.next();
p.append("/" + currentPattern.getName() + " "
+ currentPattern.referencePDF() + " ");
@@ -124,7 +161,7 @@ public class PDFResources extends PDFObject {

if (this.xObjects != null && !this.xObjects.isEmpty()) {
p = p.append("/XObject <<");
for (Iterator iter = xObjects.iterator(); iter.hasNext(); ) {
for (Iterator iter = xObjects.iterator(); iter.hasNext();) {
PDFXObject xobj = (PDFXObject)iter.next();
p = p.append("/Im" + xobj.getXNumber() + " "
+ xobj.referencePDF()
@@ -135,7 +172,7 @@ public class PDFResources extends PDFObject {

if (!this.gstates.isEmpty()) {
p = p.append("/ExtGState <<");
for (Iterator iter = gstates.iterator(); iter.hasNext(); ) {
for (Iterator iter = gstates.iterator(); iter.hasNext();) {
PDFGState gs = (PDFGState)iter.next();
p = p.append("/" + gs.getName() + " "
+ gs.referencePDF()

+ 16
- 12
src/org/apache/fop/pdf/PDFRoot.java View File

@@ -1,16 +1,12 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 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;

// Java
import java.io.IOException;
import java.io.PrintWriter;

/**
* class representing a Root (/Catalog) object
*/
@@ -34,6 +30,7 @@ public class PDFRoot extends PDFObject {
* table as part of the trsailer). (mark-fop@inomial.com)
*
* @param number the object's number
* @param pages the PDFPages object
*/
public PDFRoot(int number, PDFPages pages) {
super(number);
@@ -45,9 +42,9 @@ public class PDFRoot extends PDFObject {
* make sure it's object number is set. Package-private access
* only; outsiders should not be fiddling with this stuff.
*/
void setNumber(int number) {
/*void setNumber(int number) {
this.number = number;
}
}*/

/**
* add a /Page object to the root /Pages object
@@ -67,10 +64,20 @@ public class PDFRoot extends PDFObject {
this.rootPages = pages;
}

/**
* Set the root outline for the PDF document.
*
* @param out the root PDF Outline
*/
public void setRootOutline(PDFOutline out) {
outline = out;
}

/**
* Get the root PDF outline for the document.
*
* @return the root PDF Outline
*/
public PDFOutline getRootOutline() {
return outline;
}
@@ -78,13 +85,9 @@ public class PDFRoot extends PDFObject {
/**
* represent the object as PDF.
*
* @throws IllegalStateException if the setNumber() method has
* not been called.
*
* @return the PDF string
*/
public byte[] toPDF()
throws IllegalStateException {
public byte[] toPDF() {
StringBuffer p = new StringBuffer(this.number + " " + this.generation
+ " obj\n<< /Type /Catalog\n/Pages "
+ this.rootPages.referencePDF()
@@ -93,6 +96,7 @@ public class PDFRoot extends PDFObject {
p.append(" /Outlines " + outline.referencePDF() + "\n");
p.append(" /PageMode /UseOutlines\n");
}
p.append(" /PageMode /FullScreen\n");
p.append(" >>\nendobj\n");
return p.toString().getBytes();
}

+ 46
- 21
src/org/apache/fop/pdf/PDFShading.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -36,7 +36,6 @@ public class PDFShading extends PDFObject {
/**
* A ColorSpace representing the colorspace. "DeviceRGB" is an example.
*/
// protected StringBuffer colorSpace = null;
protected PDFColorSpace colorSpace = null;

/**
@@ -57,11 +56,13 @@ public class PDFShading extends PDFObject {
protected boolean antiAlias = false;

/**
* Optional for Type 1: Array of four numbers, xmin, xmax, ymin, ymax. Default is [0 1 0 1]
* Optional for Type 2: An array of two numbers between which the blend varies between start and end points. Default is 0, 1.
* Optional for Type 3: An array of two numbers between which the blend varies between start and end points. Default is 0, 1.
* Optional for Type 1: Array of four numbers, xmin, xmax, ymin, ymax.
* Default is [0 1 0 1]
* Optional for Type 2: An array of two numbers between which the blend
* varies between start and end points. Default is 0, 1.
* Optional for Type 3: An array of two numbers between which the blend
* varies between start and end points. Default is 0, 1.
*/

protected List domain = null;

/**
@@ -77,46 +78,56 @@ public class PDFShading extends PDFObject {
protected PDFFunction function = null;

/**
* Required for Type 2: An Array of four numbers specifying the starting and ending coordinate pairs
* Required for Type 3: An Array of six numbers [x0,y0,r0,x1,y1,r1] specifying the centers and radii of
* the starting and ending circles.
* Required for Type 2: An Array of four numbers specifying
* the starting and ending coordinate pairs
* Required for Type 3: An Array of six numbers [x0,y0,r0,x1,y1,r1]
* specifying the centers and radii of
* the starting and ending circles.
*/
protected List coords = null;

/**
* Required for Type 2+3: An Array of two boolean values specifying whether to extend the
* start and end colors past the start and end points,
* respectively. Default is false, false.
* Required for Type 2+3: An Array of two boolean values specifying
* whether to extend the start and end colors past the start
* and end points, respectively.
* Default is false, false.
*/
protected List extend = null;

/**
* Required for Type 4,5,6, and 7: Specifies the number of bits used to represent each vertex coordinate.
* Required for Type 4,5,6, and 7: Specifies the number of bits used
* to represent each vertex coordinate.
* Allowed to be 1,2,4,8,12,16,24, or 32.
*/
protected int bitsPerCoordinate = 0;

/**
* Required for Type 4,5,6, and 7: Specifies the number of bits used to represent the edge flag for each vertex.
* Allowed to be 2,4,or 8, while the Edge flag itself is allowed to be 0,1 or 2.
* Required for Type 4,5,6, and 7: Specifies the number of bits used
* to represent the edge flag for each vertex.
* Allowed to be 2,4,or 8, while the Edge flag itself is allowed to
* be 0,1 or 2.
*/
protected int bitsPerFlag = 0;

/**
* Required for Type 4,5,6, and 7: Array of Doubles which specifies how to decode coordinate and color component values.
* Each type has a differing number of decode array members, so check the spec.
* Required for Type 4,5,6, and 7: Array of Doubles which specifies
* how to decode coordinate and color component values.
* Each type has a differing number of decode array members, so check
* the spec.
* Page 303 in PDF Spec 1.3
*/
protected List decode = null;

/**
* Required for Type 4,5,6, and 7: Specifies the number of bits used to represent each color coordinate.
* Required for Type 4,5,6, and 7: Specifies the number of bits used
* to represent each color coordinate.
* Allowed to be 1,2,4,8,12, or 16
*/
protected int bitsPerComponent = 0;

/**
* Required for Type 5:The number of vertices in each "row" of the lattice; it must be greater than or equal to 2.
* Required for Type 5:The number of vertices in each "row" of
* the lattice; it must be greater than or equal to 2.
*/
protected int verticesPerRow = 0;

@@ -181,8 +192,10 @@ public class PDFShading extends PDFObject {
* @param theAntiAlias Default is false
* @param theCoords List of four (type 2) or 6 (type 3) Double
* @param theDomain List of Doubles specifying the domain
* @param theFunction the Stitching (PDFfunction type 3) function, even if it's stitching a single function
* @param theExtend List of Booleans of whether to extend teh start and end colors past the start and end points
* @param theFunction the Stitching (PDFfunction type 3) function,
* even if it's stitching a single function
* @param theExtend List of Booleans of whether to extend the start
* and end colors past the start and end points
* The default is [false, false]
*/
public PDFShading(int theNumber, String theShadingName,
@@ -295,6 +308,11 @@ public class PDFShading extends PDFObject {

}

/**
* Get the name of this shading.
*
* @return the name of the shading
*/
public String getName() {
return (this.shadingName);
}
@@ -505,6 +523,13 @@ public class PDFShading extends PDFObject {
return (p.toString().getBytes());
}

/**
* Check if this shading is equal to another shading.
* This is used to check if a shading already exists.
*
* @param obj the object to compare against
* @return true if the shadings are equal
*/
public boolean equals(Object obj) {
if (obj == null) {
return false;

+ 94
- 7
src/org/apache/fop/pdf/PDFState.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -21,6 +21,8 @@ import java.awt.geom.AffineTransform;
/**
* This keeps information about the current state when writing to pdf.
* It allows for creating new graphics states with the q operator.
* This class is only used to store the information about the state
* the caller needs to handle the actual pdf operators.
*
* When setting the state for pdf there are three possible ways of
* handling the situation.
@@ -68,14 +70,20 @@ public class PDFState {
private Shape clip = null;
private PDFGState gstate = null;

ArrayList stateStack = new ArrayList();
private ArrayList stateStack = new ArrayList();

/**
* PDF State for storing graphics state.
*/
public PDFState() {

}

// this call should be used when the q operator is used
// so that the state is known when popped
/**
* Push the current state onto the stack.
* This call should be used when the q operator is used
* so that the state is known when popped.
*/
public void push() {
HashMap saveMap = new HashMap();
saveMap.put(COLOR, color);
@@ -100,6 +108,11 @@ public class PDFState {
transform = new AffineTransform();
}

/**
* Pop the state from the stack and set current values to popped state.
* This should be called when a Q operator is used so
* the state is restored to the correct values.
*/
public void pop() {
if (getStackLevel() > 0) {
HashMap saveMap = (HashMap)stateStack.get(stateStack.size() - 1);
@@ -123,13 +136,25 @@ public class PDFState {
}
}

/**
* Get the current stack level.
*
* @return the current stack level
*/
public int getStackLevel() {
return stateStack.size();
}

/**
* Restore the state to a particular level.
* this can be used to restore to a known level without making
* multiple pop calls.
*
* @param stack the level to restore to
*/
public void restoreLevel(int stack) {
int pos = stack;
while(stateStack.size() > pos + 1) {
while (stateStack.size() > pos + 1) {
stateStack.remove(stateStack.size() - 1);
}
if (stateStack.size() > pos) {
@@ -137,10 +162,26 @@ public class PDFState {
}
}

/**
* Set the current line dash.
* Check if setting the line dash to the given values
* will make a change and then set the state to the new values.
*
* @param array the line dash array
* @param offset the line dash start offset
* @return true if the line dash has changed
*/
public boolean setLineDash(int[] array, int offset) {
return false;
}

/**
* Set the current color.
* Check if the new color is a change and then set the current color.
*
* @param col the color to set
* @return true if the color has changed
*/
public boolean setColor(Color col) {
if (!col.equals(color)) {
color = col;
@@ -149,6 +190,13 @@ public class PDFState {
return false;
}

/**
* Set the current background color.
* Check if the background color will change and then set the new color.
*
* @param col the new background color
* @return true if the background color has changed
*/
public boolean setBackColor(Color col) {
if (!col.equals(backcolor)) {
backcolor = col;
@@ -157,6 +205,13 @@ public class PDFState {
return false;
}

/**
* Set the current paint.
* This checks if the paint will change and then sets the current paint.
*
* @param p the new paint
* @return true if the new paint changes the current paint
*/
public boolean setPaint(Paint p) {
if (paint == null) {
if (p != null) {
@@ -171,7 +226,16 @@ public class PDFState {
}

/**
* For clips it can start a new state
* Check if the clip will change the current state.
* A clip is assumed to be used in a situation where it will add
* to any clip in the current or parent states.
* A clip cannot be cleared, this can only be achieved by going to
* a parent level with the correct clip.
* If the clip is different then it may start a new state so that
* it can return to the previous clip.
*
* @param cl the clip shape to check
* @return true if the clip will change the current clip.
*/
public boolean checkClip(Shape cl) {
if (clip == null) {
@@ -181,9 +245,17 @@ public class PDFState {
} else if (!new Area(clip).equals(new Area(cl))) {
return true;
}
// todo check for clips that are larger than the current
return false;
}

/**
* Set the current clip.
* This either sets a new clip or sets the clip to the intersect of
* the old clip and the new clip.
*
* @param cl the new clip in the current state
*/
public void setClip(Shape cl) {
if (clip != null) {
Area newClip = new Area(clip);
@@ -194,6 +266,15 @@ public class PDFState {
}
}

/**
* Check the current transform.
* The transform for the current state is the combination of all
* transforms in the current state. The parameter is compared
* against this current transform.
*
* @param tf the transform the check against
* @return true if the new transform is different then the current transform
*/
public boolean checkTransform(AffineTransform tf) {
return !tf.equals(transform);
}
@@ -202,6 +283,8 @@ public class PDFState {
* Set a new transform.
* This transform is appended to the transform of
* the current graphic state.
*
* @param tf the transform to concatonate to the current level transform
*/
public void setTransform(AffineTransform tf) {
transform.concatenate(tf);
@@ -211,6 +294,8 @@ public class PDFState {
* Get the current transform.
* This gets the combination of all transforms in the
* current state.
*
* @return the calculate combined transform for the current state
*/
public AffineTransform getTransform() {
AffineTransform tf;
@@ -231,6 +316,8 @@ public class PDFState {
* the current context.
* This is the graphic state set with the gs operator not
* the other graphic state changes.
*
* @return the calculated ExtGState in the current context
*/
public PDFGState getGState() {
PDFGState defaultState = PDFGState.DEFAULT;
@@ -238,7 +325,7 @@ public class PDFState {
PDFGState state;
PDFGState newstate = new PDFGState(0);
newstate.addValues(defaultState);
for (Iterator iter = stateStack.iterator(); iter.hasNext(); ) {
for (Iterator iter = stateStack.iterator(); iter.hasNext();) {
HashMap map = (HashMap)iter.next();
state = (PDFGState)map.get(GSTATE);
if (state != null) {

+ 1
- 1
src/org/apache/fop/pdf/PDFStream.java View File

@@ -123,7 +123,7 @@ public class PDFStream extends PDFObject {
}
if (filterset == null || filterset.size() == 0) {
// built-in default to flate
addFilter(new FlateFilter());
//addFilter(new FlateFilter());
} else {
for (int i = 0; i < filterset.size(); i++) {
String v = (String)filterset.get(i);

+ 5
- 6
src/org/apache/fop/pdf/PDFUri.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -12,8 +12,7 @@ package org.apache.fop.pdf;
*/
public class PDFUri extends PDFAction {


String uri;
private String uri;

/**
* create a Uri instance.
@@ -21,7 +20,6 @@ public class PDFUri extends PDFAction {
* @param uri the uri to which the link should point
*/
public PDFUri(String uri) {

this.uri = uri;
}

@@ -35,9 +33,10 @@ public class PDFUri extends PDFAction {
}

/**
* there is nothing to return for the toPDF method, as it should not be called
* There is nothing to return for the toPDF method
* as it should not be called.
*
* @return an empty string
* @return an empty array
*/
public byte[] toPDF() {
return new byte[0];

+ 27
- 5
src/org/apache/fop/pdf/StreamCache.java View File

@@ -1,16 +1,14 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 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.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.ArrayList;

/**
* class used to store the bytes for a PDFStream. It's actually a generic
@@ -27,6 +25,8 @@ public abstract class StreamCache {

/**
* Change the global cacheToFile flag.
*
* @param tizit true if cache to file
*/
public static void setCacheToFile(boolean tizit) {
cacheToFile = tizit;
@@ -34,6 +34,8 @@ public abstract class StreamCache {

/**
* Get the value of the global cacheToFile flag.
*
* @return the current cache to file flag
*/
public static boolean getCacheToFile() {
return cacheToFile;
@@ -42,42 +44,62 @@ public abstract class StreamCache {
/**
* Get the correct implementation (based on cacheToFile) of
* StreamCache.
*
* @throws IOException if there is an IO error
* @return a new StreamCache for caching streams
*/
public static StreamCache createStreamCache() throws IOException {
if (cacheToFile)
if (cacheToFile) {
return new TempFileStreamCache();
else
} else {
return new InMemoryStreamCache();
}
}

/**
* Get the current OutputStream. Do not store it - it may change
* from call to call.
*
* @throws IOException if there is an IO error
* @return an output stream for this cache
*/
public abstract OutputStream getOutputStream() throws IOException;

/**
* Filter the cache with the supplied PDFFilter.
*
* @param filter the filter to apply
* @throws IOException if there is an IO error
*/
public abstract void applyFilter(PDFFilter filter) throws IOException;

/**
* Outputs the cached bytes to the given stream.
*
* @param stream the stream to write to
* @throws IOException if there is an IO error
*/
public abstract void outputStreamData(OutputStream stream) throws IOException;

/**
* Returns the current size of the stream.
*
* @throws IOException if there is an IO error
* @return the size of the cache
*/
public abstract int getSize() throws IOException;

/**
* Closes the cache and frees resources.
*
* @throws IOException if there is an IO error
*/
public abstract void close() throws IOException;

/**
* Clears and resets the cache.
*
* @throws IOException if there is an IO error
*/
public abstract void reset() throws IOException;
}

+ 31
- 8
src/org/apache/fop/pdf/TempFileStreamCache.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2002 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2002-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -13,7 +13,6 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.File;
@@ -35,6 +34,8 @@ public class TempFileStreamCache extends StreamCache {

/**
* Creates a new TempFileStreamCache.
*
* @throws IOException if there is an IO error
*/
public TempFileStreamCache() throws IOException {
tempFile = File.createTempFile("org.apache.fop.pdf.StreamCache-",
@@ -45,20 +46,28 @@ public class TempFileStreamCache extends StreamCache {
/**
* Get the current OutputStream. Do not store it - it may change
* from call to call.
*
* @throws IOException if there is an IO error
* @return the output stream for this cache
*/
public OutputStream getOutputStream() throws IOException {
if (output == null)
if (output == null) {
output = new BufferedOutputStream(
new FileOutputStream(tempFile));
}
return output;
}

/**
* Filter the cache with the supplied PDFFilter.
*
* @param filter the filter to apply
* @throws IOException if there is an IO error
*/
public void applyFilter(PDFFilter filter) throws IOException {
if (output == null)
if (output == null) {
return;
}

output.close();
output = null;
@@ -83,10 +92,14 @@ public class TempFileStreamCache extends StreamCache {

/**
* Outputs the cached bytes to the given stream.
*
* @param stream the output stream to write to
* @throws IOException if there is an IO error
*/
public void outputStreamData(OutputStream stream) throws IOException {
if (output == null)
if (output == null) {
return;
}

output.close();
output = null;
@@ -99,34 +112,44 @@ public class TempFileStreamCache extends StreamCache {

/**
* Returns the current size of the stream.
*
* @throws IOException if there is an IO error
* @return the size of the cache
*/
public int getSize() throws IOException {
if (output != null)
if (output != null) {
output.flush();
}
return (int) tempFile.length();
}

/**
* Closes the cache and frees resources.
*
* @throws IOException if there is an IO error
*/
public void close() throws IOException {
if (output != null) {
output.close();
output = null;
}
if (tempFile.exists())
if (tempFile.exists()) {
tempFile.delete();
}
}

/**
* Clears and resets the cache.
*
* @throws IOException if there is an IO error
*/
public void reset() throws IOException {
if (output != null) {
output.close();
output = null;
}
if (tempFile.exists())
if (tempFile.exists()) {
tempFile.delete();
}
}
}

+ 4
- 1
src/org/apache/fop/pdf/TransitionDictionary.java View File

@@ -1,6 +1,6 @@
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -31,9 +31,12 @@ public class TransitionDictionary extends PDFObject {
/**
* Get the dictionary.
* This returns the string containing the dictionary values.
*
* @return the string with the dictionary values
*/
public String getDictionary() {
StringBuffer sb = new StringBuffer();
sb.append("/Type /Trans\n");
for (Iterator iter = dictionaryValues.keySet().iterator(); iter.hasNext();) {
Object key = iter.next();
sb.append(key + " " + dictionaryValues.get(key) + "\n");

Loading…
Cancel
Save