You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ge...@locus.apache.org on 2000/05/15 15:00:32 UTC

cvs commit: xml-fop/src/org/apache/fop/render/pdf PDFRenderer.java

gears       00/05/15 06:00:29

  Modified:    src/org/apache/fop/pdf PDFColor.java PDFFunction.java
                        PDFPathPaint.java PDFPattern.java PDFShading.java
               src/org/apache/fop/render/pdf PDFRenderer.java
  Added:       src/org/apache/fop/pdf PDFNumber.java
  Log:
  This is to use colors instead of numbers, the first step in supporting gradientsand shadings.
  
  Revision  Changes    Path
  1.3       +19 -52    xml-fop/src/org/apache/fop/pdf/PDFColor.java
  
  Index: PDFColor.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFColor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PDFColor.java	2000/04/27 19:33:50	1.2
  +++ PDFColor.java	2000/05/15 13:00:17	1.3
  @@ -1,4 +1,4 @@
  -/*-- $Id: PDFColor.java,v 1.2 2000/04/27 19:33:50 gears Exp $ -- 
  +/*-- $Id: PDFColor.java,v 1.3 2000/05/15 13:00:17 gears Exp $ -- 
   
    ============================================================================
   						 The Apache Software License, Version 1.1
  @@ -69,7 +69,8 @@
   	protected double magenta= -1.0;
   	protected double yellow = -1.0;
   	protected double black	= -1.0;
  -
  +	
  +	private PDFNumber pdfNumber = new PDFNumber();
   	
   	public PDFColor(org.apache.fop.datatypes.ColorType theColor)
   	{
  @@ -202,25 +203,22 @@
   		
   		double tempDouble;
   		
  -		//if the color was constructed in a different colorspace,
  -		//then we need to convert it.
  -		
   		if(this.colorSpace.getColorSpace()==ColorSpace.DEVICE_RGB)
   		{//colorspace is RGB
   				
   			//output RGB
   			if(fillNotStroke)
   			{ //fill
  -				p.append(this.doubleOut(this.red)+" "
  -					+this.doubleOut(this.green)+" "
  -					+this.doubleOut(this.blue)+" "
  +				p.append(pdfNumber.doubleOut(this.red)+" "
  +					+pdfNumber.doubleOut(this.green)+" "
  +					+pdfNumber.doubleOut(this.blue)+" "
   					+" rg \n");
   			} 
   			else
   			{//stroke/border
  -				p.append(this.doubleOut(this.red)+" "
  -					+this.doubleOut(this.green)+" "
  -					+this.doubleOut(this.blue)+" "
  +				p.append(pdfNumber.doubleOut(this.red)+" "
  +					+pdfNumber.doubleOut(this.green)+" "
  +					+pdfNumber.doubleOut(this.blue)+" "
   					+" RG \n");
   			}
   		}//end of output RGB
  @@ -229,17 +227,17 @@
   			
   			if(fillNotStroke)
   			{ //fill
  -				p.append(this.doubleOut(this.cyan) + " "
  -					+ this.doubleOut(this.magenta) + " "
  -					+ this.doubleOut(this.yellow) + " "
  -					+ this.doubleOut(this.black) + " k \n");
  +				p.append(pdfNumber.doubleOut(this.cyan) + " "
  +					+ pdfNumber.doubleOut(this.magenta) + " "
  +					+ pdfNumber.doubleOut(this.yellow) + " "
  +					+ pdfNumber.doubleOut(this.black) + " k \n");
   			}
   			else
   			{ //fill
  -				p.append(this.doubleOut(this.cyan) + " "
  -					+ this.doubleOut(this.magenta) + " "
  -					+ this.doubleOut(this.yellow) + " "
  -					+ this.doubleOut(this.black) + " K \n");
  +				p.append(pdfNumber.doubleOut(this.cyan) + " "
  +					+ pdfNumber.doubleOut(this.magenta) + " "
  +					+ pdfNumber.doubleOut(this.yellow) + " "
  +					+ pdfNumber.doubleOut(this.black) + " K \n");
   			}
   			
   		}//end of if CMYK
  @@ -248,11 +246,11 @@
   		
   			if(fillNotStroke)
   			{
  -				p.append(this.doubleOut(this.black)	+ " g \n");
  +				p.append(pdfNumber.doubleOut(this.black)	+ " g \n");
   			}
   			else
   			{
  -				p.append(this.doubleOut(this.black)	+ " G \n");
  +				p.append(pdfNumber.doubleOut(this.black)	+ " G \n");
   			}
   		
   		}
  @@ -261,37 +259,6 @@
   
   	
   	
  -	public String doubleOut(double doubleDown)
  -	{
  -		
  -		StringBuffer p = new StringBuffer();
  -		double trouble = doubleDown % 1;
  -		
  -		if(trouble > 0.950)
  -		{
  -			p.append((int)doubleDown+1);
  -		}
  -		else if (trouble < 0.050)
  -		{
  -			p.append((int)doubleDown);
  -		}
  -		else
  -		{
  -			String doubleString = new String(doubleDown+"");
  -			int decimal = doubleString.indexOf(".");
  -			p.append(doubleString.substring(0, decimal));
  -
  -			if ((doubleString.length() - decimal) > 6)
  -			{
  -				p.append(doubleString.substring(decimal,decimal+6));
  -			}
  -			else
  -			{
  -				p.append(doubleString.substring(decimal));
  -			}
  -		}
  -		return(p.toString());
  -	}
   	
   	protected void convertCMYKtoRGB()
   	{
  
  
  
  1.3       +758 -801  xml-fop/src/org/apache/fop/pdf/PDFFunction.java
  
  Index: PDFFunction.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFFunction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PDFFunction.java	2000/04/21 16:43:19	1.2
  +++ PDFFunction.java	2000/05/15 13:00:18	1.3
  @@ -1,801 +1,758 @@
  -/*-- $Id: PDFFunction.java,v 1.2 2000/04/21 16:43:19 gears Exp $ -- 
  -
  - ============================================================================
  -						 The Apache Software License, Version 1.1
  - ============================================================================
  - 
  -	 Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  - 
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  - 
  - 1. Redistributions of	source code must	retain the above copyright  notice,
  -	 this list of conditions and the following disclaimer.
  - 
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -	 this list of conditions and the following disclaimer in the documentation
  -	 and/or other materials provided with the distribution.
  - 
  - 3. The end-user documentation included with the redistribution, if any, must
  -	 include  the following  acknowledgment:	"This product includes	software
  -	 developed	by the  Apache Software Foundation	(http://www.apache.org/)."
  -	 Alternately, this  acknowledgment may  appear in the software itself,	if
  -	 and wherever such third-party acknowledgments normally appear.
  - 
  - 4. The names "Fop" and  "Apache Software Foundation"  must not be used to
  -	 endorse  or promote  products derived  from this	software without	prior
  -	 written permission. For written permission, please contact
  -	 apache@apache.org.
  - 
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -	 "Apache" appear	in their name,  without prior written permission  of the
  -	 Apache Software Foundation.
  - 
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.	IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE	FOUNDATION	OR ITS CONTRIBUTORS	BE LIABLE FOR	ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,	EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY	THEORY OF LIABILITY,  WHETHER  IN CONTRACT,	STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN	ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  - 
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software	Foundation and was  originally created by
  - James Tauber <jt...@jtauber.com>. For more  information on the Apache 
  - Software Foundation, please see <http://www.apache.org/>.
  - 
  - */
  -
  -package org.apache.fop.pdf;
  -
  -//Java... 
  -import java.util.Vector;
  -
  -/**
  - * class representing a PDF Function.
  - * 
  - * 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).
  - * 
  - * All PDF Functions have a FunctionType (0,2,3, or 4), a Domain, and a Range.
  - */
  -public class PDFFunction extends PDFObject {
  -	//Guts common to all function types
  -	/** Required: The Type of function (0,2,3,4) default is 0.*/
  -	protected int functionType =0; //Default
  -	
  -	/**
  -	 * Required: 2 * m Array of Double numbers which are possible inputs to the function
  -	 */
  -	protected Vector domain = null;
  -
  -	/**
  -	 * Required: 2 * n Array of Double numbers which are possible outputs to the function
  -	 */	 
  -	protected Vector range = null;
  -	
  -	/* ********************TYPE 0***************************** */
  -	//FunctionType 0 specific function guts
  -	/**
  -	 * Required: Array containing the Integer size of the Domain and Range, respectively.
  -	 * Note: This is really more like two seperate integers, sizeDomain, and sizeRange,
  -	 * but since they're expressed as an array in PDF, my implementation reflects that.
  -	 */ 
  -	protected Vector 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 */
  -	protected int bitsPerSample = 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.
  -	 * 
  -	 * 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 Vector 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.
  -	 */
  -	protected Vector decode = null;
  -	/** Optional For Type 0: A stream of sample values */
  -	/** 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.
  -	 * These are how the string is compressed. Flate, LZW, etc.
  -	 */
  -	protected Vector filter = null;
  -	/* *************************TYPE 2************************** */
  -	/**
  -	 * Required For Type 2: An Array of n Doubles defining the function result when x=0. Default is [0].
  -	 */
  -	protected Vector cZero = null;
  -	/**
  -	 * Required For Type 2: An Array of n Doubles defining the function result when x=1. Default is [1].
  -	 */
  -	protected Vector cOne = null;
  -	/**
  -	 * Required for Type 2: The interpolation exponent.
  -	 * Each value x will return n results.
  -	 * Must be greater than 0.
  -	 */
  -	protected double interpolationExponentN = 1;
  -
  -	/* *************************TYPE 3************************** */
  -	/** Required for Type 3: An vector of PDFFunctions which form an array of k single input functions making up the stitching function. */
  -	protected Vector 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.
  -	 * 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.
  -	 * It makes the gradient even.
  -	 */
  -	protected Vector bounds = null;
  -   // See encode above, as it's also part of Type 3 Functions.
  -   
  -	/* *************************TYPE 4************************** */
  -	//See 'data' above.
  -	
  -	/**
  -	 * create an complete Function object of Type 0, A Sampled function.
  -	 * 
  -	 * Use null for an optional object parameter if you choose not to use it.
  -	 * For optional int parameters, pass the default.
  -	 * 
  -	 * @param theDomain Vector objects of Double objects.
  -	 * This is the domain of the function.
  -	 * See page 264 of the PDF 1.3 Spec.
  -	 * @param theRange Vector objects of Double objects.
  -	 * This is the Range of the function.
  -	 * See page 264 of the PDF 1.3 Spec.
  -	 * @param theSize A Vector object of Integer objects.
  -	 * This is the number of samples in each input dimension.
  -	 * I can't imagine there being more or less than two input dimensions,
  -	 * 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.
  -	 * 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
  -	 * to 1 (one) or 3, which means linear or cubic-spline interpolation.
  -	 * 
  -	 * This attribute is optional.
  -	 * 
  -	 * See page 265 in the PDF 1.3 spec.
  -	 * @param theEncode Vector objects of Double objects.
  -	 * This is the linear mapping of input values intop the domain
  -	 * of the function's sample table. Default is hard to represent in
  -	 * ascii, but basically [0 (Size0 1) 0 (Size1 1)...].
  -	 * This attribute is optional.
  -	 * 
  -	 * See page 265 in the PDF 1.3 spec.
  -	 * @param theDecode Vector objects of Double objects.
  -	 * This is a linear mapping of sample values into the range.
  -	 * The default is just the range.
  -	 * 
  -	 * 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.
  -	 * 
  -	 * This is optional, but is almost always used.
  -	 * 
  -	 * Page 265 of the PDF 1.3 spec has more.
  -	 * @param theFilter This is a vector of String objects which are the various filters that
  -	 * have are to be applied to the stream to make sense of it. Order matters,
  -	 * so watch out.
  -	 * 
  -	 * 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.
  -	 */
  -	public PDFFunction(int theNumber, int theFunctionType,
  -			Vector theDomain, Vector theRange,
  -			Vector theSize,int theBitsPerSample,
  -			int theOrder,Vector theEncode,Vector theDecode,
  -			StringBuffer theFunctionDataStream, Vector theFilter)
  -	{
  -		super(theNumber);
  -		
  -		this.functionType = 0; //dang well better be 0;
  -		this.size = theSize;
  -		this.bitsPerSample = theBitsPerSample; 
  -		this.order = theOrder; //int
  -		this.encode = theEncode;//vector of int
  -		this.decode = theDecode; //vector of int
  -		this.functionDataStream = theFunctionDataStream;
  -		this.filter = theFilter;//vector of Strings
  -		
  -		//the domain and range are actually two dimensional arrays.
  -		//so if there's not an even number of items, bad stuff
  -		//happens.
  -		this.domain =  theDomain;
  -		this.range =  theRange;
  -	}
  -	
  -	/**
  -	 * create an complete Function object of Type 2, an Exponential Interpolation function.
  -	 * 
  -	 * Use null for an optional object parameter if you choose not to use it.
  -	 * For optional int parameters, pass the default.
  -	 * 
  -	 * @param theNumber the object's number
  -	 * @param theDomain Vector objects of Double objects.
  -	 * This is the domain of the function.
  -	 * See page 264 of the PDF 1.3 Spec.
  -	 * @param theRange Vector of Doubles that is the Range of the function.
  -	 * See page 264 of the PDF 1.3 Spec.
  -	 * @param theCZero This is a vector of Double objects which defines the function result
  -	 * when x=0.
  -	 * 
  -	 * This attribute is optional.
  -	 * It's described on page 268 of the PDF 1.3 spec.
  -	 * @param theCOne This is a vector of Double objects which defines the function result
  -	 * when x=1.
  -	 * 
  -	 * This attribute is optional.
  -	 * It's described on page 268 of the PDF 1.3 spec.
  -	 * @param theInterpolationExponentN This is the inerpolation exponent.
  -	 * 
  -	 * This attribute is required.
  -	 * PDF Spec page 268
  -	 * @param theFunctionType The type of the function, which should be 2.
  -	 */
  -	public PDFFunction(int theNumber, int theFunctionType,
  -						Vector theDomain, Vector theRange,
  -						Vector theCZero, Vector theCOne,
  -						double theInterpolationExponentN)
  -	{
  -		super(theNumber);
  -		
  -		this.functionType = 2; //dang well better be 2;
  -		
  -		this.cZero = theCZero;
  -		this.cOne = theCOne;
  -		this.interpolationExponentN = theInterpolationExponentN;
  -		
  -
  -		this.domain = theDomain;
  -		this.range = theRange;
  -		
  -	}
  -
  -	/**
  -	 * create an complete Function object of Type 3, a Stitching function.
  -	 * 
  -	 * Use null for an optional object parameter if you choose not to use it.
  -	 * For optional int parameters, pass the default.
  -	 * 
  -	 * @param theNumber the object's number
  -	 * @param theDomain Vector objects of Double objects.
  -	 * This is the domain of the function.
  -	 * See page 264 of the PDF 1.3 Spec.
  -	 * @param theRange Vector objects of Double objects.
  -	 * This is the Range of the function.
  -	 * See page 264 of the PDF 1.3 Spec.
  -	 * @param theFunctions A Vector of the PDFFunction objects that the stitching function stitches.
  -	 * 
  -	 * This attributed is required.
  -	 * It is described on page 269 of the PDF spec.
  -	 * @param theBounds This is a vector of Doubles representing the numbers that,
  -	 * in conjunction with Domain define the intervals to which each function from
  -	 * the 'functions' object applies. It must be in order of increasing magnitude,
  -	 * and each must be within Domain.
  -	 * 
  -	 * It basically sets how much of the gradient each function handles.
  -	 * 
  -	 * This attributed is required.
  -	 * It's described on page 269 of the PDF 1.3 spec.
  -	 * @param theEncode Vector objects of Double objects.
  -	 * This is the linear mapping of input values intop the domain
  -	 * of the function's sample table. Default is hard to represent in
  -	 * ascii, but basically [0 (Size0 1) 0 (Size1 1)...].
  -	 * This attribute is required.
  -	 * 
  -	 * See page 270 in the PDF 1.3 spec.
  -	 * @param theFunctionType This is the function type. It should be 3,
  -	 * for a stitching function.
  -	 */
  -	public PDFFunction(int theNumber, int theFunctionType,
  -			Vector theDomain, Vector theRange,
  -			Vector theFunctions, Vector theBounds,
  -			Vector theEncode)
  -	{
  -		super(theNumber);
  -		
  -		this.functionType = 3; //dang well better be 3;
  -				
  -		this.functions = theFunctions;
  -		this.bounds = theBounds;
  -		this.encode = theEncode;
  -		this.domain = theDomain;
  -		this.range =  theRange;
  -
  -	}
  -	
  -	/**
  -	 * create an complete Function object of Type 4, a postscript calculator function.
  -	 * 
  -	 * Use null for an optional object parameter if you choose not to use it.
  -	 * For optional int parameters, pass the default.
  -	 * 
  -	 * @param theDomain Vector object of Double objects.
  -	 * This is the domain of the function.
  -	 * See page 264 of the PDF 1.3 Spec.
  -	 * @param theRange Vector 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.
  -	 * I end up enclosing it in the '{' and '}' braces for you, so don't do it
  -	 * yourself.
  -	 * 
  -	 * This attribute is required.
  -	 * It's described on page 269 of the PDF 1.3 spec.
  -	 * @param theNumber The object number of this PDF object.
  -	 * @param theFunctionType The type of function which should be 4, as this is
  -	 * a Postscript calculator function
  -	 */
  -	public PDFFunction(int theNumber, int theFunctionType,
  -			Vector theDomain, Vector theRange,
  -			StringBuffer theFunctionDataStream)
  -	{
  -		super(theNumber);
  -		
  -		this.functionType = 4; //dang well better be 4;
  -		this.functionDataStream = theFunctionDataStream;
  -
  -		this.domain =  theDomain;
  -		
  -		this.range = theRange;
  -
  -	}
  -	
  -	/**
  -	 * This converts an Object of type double to a prettily printed
  -	 * floating point number that PDF won't choke on. If a number's
  -	 * value is close to an integer, it's printed as an integer.
  -	 * Excess digits after the decimal place are trimmed (no rounding).
  -	 * Always print 0 in front of the decimal point of a number
  -	 * that is between 0 and 1.
  -	 * Note: Negative values are untested, as I assume they don't
  -	 * come up. Should work anyway.
  -	 * 
  -	 * @param doubleDown Cool name, eh?
  -	 * @return String representation of Double that PDF won't choke on.
  -	 */
  -	public String doubleOut(Double doubleDown)
  -	{
  -		StringBuffer p = new StringBuffer();
  -		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(".");
  -			p.append(doubleString.substring(0, decimal));
  -
  -			if ((doubleString.length() - decimal) > 6)
  -			{
  -				p.append(doubleString.substring(decimal,decimal+6));
  -			}
  -			else
  -			{
  -				p.append(doubleString.substring(decimal));
  -			}
  -		}
  -		return(p.toString());
  -	}
  -	
  -				
  -
  -	 /**
  -	  * represent as PDF. Whatever the FunctionType is, the correct
  -	  * representation spits out. The sets of required and optional
  -	  * attributes are different for each type, but if a required
  -	  * attribute's object was constructed as null, then no error
  -	  * is raised. Instead, the malformed PDF that was requested
  -	  * by the construction is dutifully output.
  -	  * This policy should be reviewed.
  -	  * 
  -	  * @return the PDF string.
  -	  */ 
  -	public String toPDF() {
  -		int vectorSize=0;
  -		int numberOfFunctions=0;
  -		int tempInt=0;
  -		StringBuffer p = new StringBuffer();
  -		p.append(this.number + " " +this.generation 
  -			+ " obj\n<< \n/FunctionType "+this.functionType+" \n");
  -
  -		//FunctionType 0
  -		if(this.functionType == 0)
  -		{
  -			if(this.domain != null)
  -			{
  -				//DOMAIN
  -				p.append("/Domain [ ");
  -				vectorSize = this.domain.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -						(Double)this.domain.elementAt(tempInt))
  -						+" ");
  -				}
  -				
  -				p.append("] \n");
  -			}			
  -			else
  -			{
  -				p.append("/Domain [ 0 1 ] \n");
  -			}
  -
  -			//SIZE
  -			if(this.size != null)
  -			{
  -				p.append("/Size [ ");
  -				vectorSize = this.size.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.size.elementAt(tempInt)) +" ");
  -				}
  -				p.append("] \n");
  -			}
  -			//ENCODE
  -			if(this.encode != null)
  -			{
  -				p.append("/Encode [ ");
  -				vectorSize = this.encode.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.encode.elementAt(tempInt)) +" ");
  -				}
  -				p.append("] \n");
  -			}
  -			else
  -			{
  -				p.append("/Encode [ ");
  -				vectorSize = this.functions.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append("0 1 ");
  -				}
  -				p.append("] \n");
  -				
  -			}
  -			
  -			//BITSPERSAMPLE
  -			p.append("/BitsPerSample "+this.bitsPerSample);
  -			
  -			//ORDER (optional)
  -			if(this.order ==1 || this.order == 3)
  -			{
  -				p.append(" \n/Order "+this.order+" \n");
  -			}
  -			
  -			//RANGE
  -			if(this.range != null)
  -			{
  -				p.append("/Range [ ");
  -				vectorSize = this.range.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.range.elementAt(tempInt)) +" ");
  -				}
  -				
  -				p.append("] \n");
  -			}
  -			
  -			//DECODE
  -			if(this.decode != null)
  -			{
  -				p.append("/Decode [ ");
  -				vectorSize = this.decode.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.decode.elementAt(tempInt)) +" ");
  -				}
  -				
  -				p.append("] \n");
  -			}
  -			
  -			//LENGTH		
  -			if(this.functionDataStream != null)
  -			{
  -				p.append("/Length "+(this.functionDataStream.length()+1)
  -					+ " \n");
  -			}
  -			
  -			//FILTER?
  -			if (this.filter != null)
  -			{//if there's a filter
  -				vectorSize= this.filter.size();
  -				p.append("/Filter ");
  -				if (vectorSize == 1)
  -				{
  -					p.append("/"+((String)this.filter.elementAt(0))+" \n");
  -				}
  -				else
  -				{
  -					p.append("[ ");
  -					for(tempInt=0; tempInt <vectorSize; tempInt++)
  -					{
  -						p.append("/"+((String)this.filter.elementAt(0))+" ");
  -					}
  -					p.append("] \n");
  -				}
  -			}
  -			p.append(">> \n");
  -			
  -			//stream representing the function
  -			if(this.functionDataStream != null)
  -			{
  -				p.append("stream\n"+this.functionDataStream +"\nendstream\n");
  -			}
  -			
  -			p.append("endobj\n");
  -			
  -		}//end of if FunctionType 0
  -		else if(this.functionType == 2)
  -		{
  -			//DOMAIN
  -			if(this.domain != null)
  -			{
  -				p.append("/Domain [ ");
  -				vectorSize = this.domain.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.domain.elementAt(tempInt)) +" ");
  -				}
  -				
  -				p.append("] \n");
  -			}
  -			else
  -			{
  -				p.append("/Domain [ 0 1 ] \n");
  -			}
  -
  -			
  -			//RANGE
  -			if(this.range != null)
  -			{
  -				p.append("/Range [ ");
  -				vectorSize = this.range.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.range.elementAt(tempInt)) +" ");
  -				}
  -				
  -				p.append("] \n");
  -			}
  -			
  -			//FunctionType, C0, C1, N are required in PDF
  -			
  -			//C0
  -			if(this.cZero != null)
  -			{
  -				p.append("/C0 [ ");
  -				vectorSize = this.cZero.size();
  -				for(tempInt = 0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.cZero.elementAt(tempInt))+" ");
  -				}
  -				p.append("] \n");				
  -			}
  -			
  -			//C1
  -			if(this.cOne != null)
  -			{
  -				p.append("/C1 [ ");
  -				vectorSize = this.cOne.size();
  -				for(tempInt = 0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.cOne.elementAt(tempInt))+" ");
  -				}
  -				p.append("] \n");
  -			}
  -			
  -			//N: The interpolation Exponent
  -			p.append("/N "
  -				+this.doubleOut(
  -					new Double(this.interpolationExponentN))
  -				+" \n");
  -			
  -			p.append(">> \nendobj\n");
  -
  -		}
  -		else if(this.functionType == 3)
  -		{//fix this up when my eyes uncross
  -			//DOMAIN
  -			if(this.domain != null)
  -			{
  -				p.append("/Domain [ ");
  -				vectorSize = this.domain.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.domain.elementAt(tempInt)) +" ");
  -				}
  -				p.append("] \n");
  -			}
  -			else
  -			{
  -				p.append("/Domain [ 0 1 ] \n");
  -			}
  -
  -			//RANGE
  -			if(this.range != null)
  -			{
  -				p.append("/Range [ ");
  -				vectorSize = this.range.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.range.elementAt(tempInt)) +" ");
  -				}
  -				
  -				p.append("] \n");
  -			}
  -		
  -			//FUNCTIONS
  -			if(this.functions != null)
  -			{
  -				p.append("/Functions [ ");
  -				numberOfFunctions = this.functions.size();
  -				for(tempInt =0;tempInt < numberOfFunctions; tempInt++)
  -				{
  -					p.append( ((PDFFunction)this.functions.elementAt(tempInt)).referencePDF()+" ");
  -					
  -				}
  -				p.append("] \n");
  -			}
  -			
  -			
  -			//ENCODE
  -			if(this.encode != null)
  -			{
  -				p.append("/Encode [ ");
  -				vectorSize = this.encode.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.encode.elementAt(tempInt)) +" ");
  -				}
  -								
  -				p.append("] \n");
  -			}
  -			else
  -			{
  -				p.append("/Encode [ ");
  -				vectorSize = this.functions.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append("0 1 ");
  -				}
  -				p.append("] \n");
  -				
  -			}
  -			
  -			
  -			//BOUNDS, required, but can be empty
  -			p.append("/Bounds [ ");
  -			if(this.bounds != null)
  -			{
  -				
  -				vectorSize= this.bounds.size();
  -				for(tempInt = 0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.bounds.elementAt(tempInt))+" ");
  -				}
  -			
  -			}
  -			else
  -			{
  -				if(this.functions != null)
  -				{ 
  -					//if there are n functions,
  -					// there must be n-1 bounds.
  -					// so let each function handle an equal portion
  -					// of the whole. e.g. if there are 4, then [ 0.25 0.25 0.25 ]
  -					
  -					String functionsFraction = 
  -						this.doubleOut(new Double(
  -							1.0 / ((double)numberOfFunctions)));
  -	
  -					for(tempInt =0;tempInt+1 < numberOfFunctions; tempInt++)
  -					{
  -						
  -						p.append( functionsFraction);
  -					}
  -					functionsFraction = null; //clean reference.
  -					
  -				}
  -				
  -			}
  -			p.append("] \n");
  -			
  -			
  -			p.append(">> \nendobj\n");
  -		}
  -		else if(this.functionType == 4)
  -		{//fix this up when my eyes uncross
  -			//DOMAIN
  -			if(this.domain != null)
  -			{
  -				p.append("/Domain [ ");
  -				vectorSize = this.domain.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.domain.elementAt(tempInt)) +" ");
  -				}
  -				
  -				p.append("] \n");
  -			}
  -			else
  -			{
  -				p.append("/Domain [ 0 1 ] \n");
  -			}
  -
  -			//RANGE
  -			if(this.range != null)
  -			{
  -				p.append("/Range [ ");
  -				vectorSize = this.range.size();
  -				for(tempInt=0; tempInt < vectorSize; tempInt++)
  -				{
  -					p.append(this.doubleOut(
  -					(Double)this.range.elementAt(tempInt)) +" ");
  -				}
  -				
  -				p.append("] \n");
  -			}
  -			
  -			//LENGTH		
  -			if(this.functionDataStream != null)
  -			{
  -				p.append("/Length "+(this.functionDataStream.length()+1)
  -					+ " \n");
  -			}
  -			
  -			p.append(">> \n");
  -			
  -			//stream representing the function
  -			if(this.functionDataStream != null)
  -			{
  -				p.append("stream\n{ "+this.functionDataStream +" } \nendstream\n");
  -			}
  -			
  -			p.append("endobj\n");
  -			
  -		}
  -		
  -		return (p.toString());
  -		
  -	}
  -}
  +/*-- $Id: PDFFunction.java,v 1.3 2000/05/15 13:00:18 gears Exp $ -- 
  +
  + ============================================================================
  +						 The Apache Software License, Version 1.1
  + ============================================================================
  + 
  +	 Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  + 
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  + 
  + 1. Redistributions of	source code must	retain the above copyright  notice,
  +	 this list of conditions and the following disclaimer.
  + 
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +	 this list of conditions and the following disclaimer in the documentation
  +	 and/or other materials provided with the distribution.
  + 
  + 3. The end-user documentation included with the redistribution, if any, must
  +	 include  the following  acknowledgment:	"This product includes	software
  +	 developed	by the  Apache Software Foundation	(http://www.apache.org/)."
  +	 Alternately, this  acknowledgment may  appear in the software itself,	if
  +	 and wherever such third-party acknowledgments normally appear.
  + 
  + 4. The names "Fop" and  "Apache Software Foundation"  must not be used to
  +	 endorse  or promote  products derived  from this	software without	prior
  +	 written permission. For written permission, please contact
  +	 apache@apache.org.
  + 
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +	 "Apache" appear	in their name,  without prior written permission  of the
  +	 Apache Software Foundation.
  + 
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.	IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE	FOUNDATION	OR ITS CONTRIBUTORS	BE LIABLE FOR	ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,	EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY	THEORY OF LIABILITY,  WHETHER  IN CONTRACT,	STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN	ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  + 
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software	Foundation and was  originally created by
  + James Tauber <jt...@jtauber.com>. For more  information on the Apache 
  + Software Foundation, please see <http://www.apache.org/>.
  + 
  + */
  +
  +package org.apache.fop.pdf;
  +
  +//Java... 
  +import java.util.Vector;
  +
  +/**
  + * class representing a PDF Function.
  + * 
  + * 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).
  + * 
  + * All PDF Functions have a FunctionType (0,2,3, or 4), a Domain, and a Range.
  + */
  +public class PDFFunction extends PDFObject {
  +	//Guts common to all function types
  +	/** Required: The Type of function (0,2,3,4) default is 0.*/
  +	protected int functionType =0; //Default
  +	
  +	/**
  +	 * Required: 2 * m Array of Double numbers which are possible inputs to the function
  +	 */
  +	protected Vector domain = null;
  +
  +	/**
  +	 * Required: 2 * n Array of Double numbers which are possible outputs to the function
  +	 */	 
  +	protected Vector range = null;
  +	
  +	/* ********************TYPE 0***************************** */
  +	//FunctionType 0 specific function guts
  +	/**
  +	 * Required: Array containing the Integer size of the Domain and Range, respectively.
  +	 * Note: This is really more like two seperate integers, sizeDomain, and sizeRange,
  +	 * but since they're expressed as an array in PDF, my implementation reflects that.
  +	 */ 
  +	protected Vector 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 */
  +	protected int bitsPerSample = 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.
  +	 * 
  +	 * 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 Vector 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.
  +	 */
  +	protected Vector decode = null;
  +	/** Optional For Type 0: A stream of sample values */
  +	/** 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.
  +	 * These are how the string is compressed. Flate, LZW, etc.
  +	 */
  +	protected Vector filter = null;
  +	/* *************************TYPE 2************************** */
  +	/**
  +	 * Required For Type 2: An Array of n Doubles defining the function result when x=0. Default is [0].
  +	 */
  +	protected Vector cZero = null;
  +	/**
  +	 * Required For Type 2: An Array of n Doubles defining the function result when x=1. Default is [1].
  +	 */
  +	protected Vector cOne = null;
  +	/**
  +	 * Required for Type 2: The interpolation exponent.
  +	 * Each value x will return n results.
  +	 * Must be greater than 0.
  +	 */
  +	protected double interpolationExponentN = 1;
  +
  +	/* *************************TYPE 3************************** */
  +	/** Required for Type 3: An vector of PDFFunctions which form an array of k single input functions making up the stitching function. */
  +	protected Vector 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.
  +	 * 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.
  +	 * It makes the gradient even.
  +	 */
  +	protected Vector bounds = null;
  +   // See encode above, as it's also part of Type 3 Functions.
  +   
  +	/* *************************TYPE 4************************** */
  +	//See 'data' above.
  +	private PDFNumber pdfNumber = new PDFNumber();
  +	
  +	/**
  +	 * create an complete Function object of Type 0, A Sampled function.
  +	 * 
  +	 * Use null for an optional object parameter if you choose not to use it.
  +	 * For optional int parameters, pass the default.
  +	 * 
  +	 * @param theDomain Vector objects of Double objects.
  +	 * This is the domain of the function.
  +	 * See page 264 of the PDF 1.3 Spec.
  +	 * @param theRange Vector objects of Double objects.
  +	 * This is the Range of the function.
  +	 * See page 264 of the PDF 1.3 Spec.
  +	 * @param theSize A Vector object of Integer objects.
  +	 * This is the number of samples in each input dimension.
  +	 * I can't imagine there being more or less than two input dimensions,
  +	 * 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.
  +	 * 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
  +	 * to 1 (one) or 3, which means linear or cubic-spline interpolation.
  +	 * 
  +	 * This attribute is optional.
  +	 * 
  +	 * See page 265 in the PDF 1.3 spec.
  +	 * @param theEncode Vector objects of Double objects.
  +	 * This is the linear mapping of input values intop the domain
  +	 * of the function's sample table. Default is hard to represent in
  +	 * ascii, but basically [0 (Size0 1) 0 (Size1 1)...].
  +	 * This attribute is optional.
  +	 * 
  +	 * See page 265 in the PDF 1.3 spec.
  +	 * @param theDecode Vector objects of Double objects.
  +	 * This is a linear mapping of sample values into the range.
  +	 * The default is just the range.
  +	 * 
  +	 * 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.
  +	 * 
  +	 * This is optional, but is almost always used.
  +	 * 
  +	 * Page 265 of the PDF 1.3 spec has more.
  +	 * @param theFilter This is a vector of String objects which are the various filters that
  +	 * have are to be applied to the stream to make sense of it. Order matters,
  +	 * so watch out.
  +	 * 
  +	 * 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.
  +	 */
  +	public PDFFunction(int theNumber, int theFunctionType,
  +			Vector theDomain, Vector theRange,
  +			Vector theSize,int theBitsPerSample,
  +			int theOrder,Vector theEncode,Vector theDecode,
  +			StringBuffer theFunctionDataStream, Vector theFilter)
  +	{
  +		super(theNumber);
  +		
  +		this.functionType = 0; //dang well better be 0;
  +		this.size = theSize;
  +		this.bitsPerSample = theBitsPerSample; 
  +		this.order = theOrder; //int
  +		this.encode = theEncode;//vector of int
  +		this.decode = theDecode; //vector of int
  +		this.functionDataStream = theFunctionDataStream;
  +		this.filter = theFilter;//vector of Strings
  +		
  +		//the domain and range are actually two dimensional arrays.
  +		//so if there's not an even number of items, bad stuff
  +		//happens.
  +		this.domain =  theDomain;
  +		this.range =  theRange;
  +	}
  +	
  +	/**
  +	 * create an complete Function object of Type 2, an Exponential Interpolation function.
  +	 * 
  +	 * Use null for an optional object parameter if you choose not to use it.
  +	 * For optional int parameters, pass the default.
  +	 * 
  +	 * @param theNumber the object's number
  +	 * @param theDomain Vector objects of Double objects.
  +	 * This is the domain of the function.
  +	 * See page 264 of the PDF 1.3 Spec.
  +	 * @param theRange Vector of Doubles that is the Range of the function.
  +	 * See page 264 of the PDF 1.3 Spec.
  +	 * @param theCZero This is a vector of Double objects which defines the function result
  +	 * when x=0.
  +	 * 
  +	 * This attribute is optional.
  +	 * It's described on page 268 of the PDF 1.3 spec.
  +	 * @param theCOne This is a vector of Double objects which defines the function result
  +	 * when x=1.
  +	 * 
  +	 * This attribute is optional.
  +	 * It's described on page 268 of the PDF 1.3 spec.
  +	 * @param theInterpolationExponentN This is the inerpolation exponent.
  +	 * 
  +	 * This attribute is required.
  +	 * PDF Spec page 268
  +	 * @param theFunctionType The type of the function, which should be 2.
  +	 */
  +	public PDFFunction(int theNumber, int theFunctionType,
  +						Vector theDomain, Vector theRange,
  +						Vector theCZero, Vector theCOne,
  +						double theInterpolationExponentN)
  +	{
  +		super(theNumber);
  +		
  +		this.functionType = 2; //dang well better be 2;
  +		
  +		this.cZero = theCZero;
  +		this.cOne = theCOne;
  +		this.interpolationExponentN = theInterpolationExponentN;
  +		
  +
  +		this.domain = theDomain;
  +		this.range = theRange;
  +		
  +	}
  +
  +	/**
  +	 * create an complete Function object of Type 3, a Stitching function.
  +	 * 
  +	 * Use null for an optional object parameter if you choose not to use it.
  +	 * For optional int parameters, pass the default.
  +	 * 
  +	 * @param theNumber the object's number
  +	 * @param theDomain Vector objects of Double objects.
  +	 * This is the domain of the function.
  +	 * See page 264 of the PDF 1.3 Spec.
  +	 * @param theRange Vector objects of Double objects.
  +	 * This is the Range of the function.
  +	 * See page 264 of the PDF 1.3 Spec.
  +	 * @param theFunctions A Vector of the PDFFunction objects that the stitching function stitches.
  +	 * 
  +	 * This attributed is required.
  +	 * It is described on page 269 of the PDF spec.
  +	 * @param theBounds This is a vector of Doubles representing the numbers that,
  +	 * in conjunction with Domain define the intervals to which each function from
  +	 * the 'functions' object applies. It must be in order of increasing magnitude,
  +	 * and each must be within Domain.
  +	 * 
  +	 * It basically sets how much of the gradient each function handles.
  +	 * 
  +	 * This attributed is required.
  +	 * It's described on page 269 of the PDF 1.3 spec.
  +	 * @param theEncode Vector objects of Double objects.
  +	 * This is the linear mapping of input values intop the domain
  +	 * of the function's sample table. Default is hard to represent in
  +	 * ascii, but basically [0 (Size0 1) 0 (Size1 1)...].
  +	 * This attribute is required.
  +	 * 
  +	 * See page 270 in the PDF 1.3 spec.
  +	 * @param theFunctionType This is the function type. It should be 3,
  +	 * for a stitching function.
  +	 */
  +	public PDFFunction(int theNumber, int theFunctionType,
  +			Vector theDomain, Vector theRange,
  +			Vector theFunctions, Vector theBounds,
  +			Vector theEncode)
  +	{
  +		super(theNumber);
  +		
  +		this.functionType = 3; //dang well better be 3;
  +				
  +		this.functions = theFunctions;
  +		this.bounds = theBounds;
  +		this.encode = theEncode;
  +		this.domain = theDomain;
  +		this.range =  theRange;
  +
  +	}
  +	
  +	/**
  +	 * create an complete Function object of Type 4, a postscript calculator function.
  +	 * 
  +	 * Use null for an optional object parameter if you choose not to use it.
  +	 * For optional int parameters, pass the default.
  +	 * 
  +	 * @param theDomain Vector object of Double objects.
  +	 * This is the domain of the function.
  +	 * See page 264 of the PDF 1.3 Spec.
  +	 * @param theRange Vector 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.
  +	 * I end up enclosing it in the '{' and '}' braces for you, so don't do it
  +	 * yourself.
  +	 * 
  +	 * This attribute is required.
  +	 * It's described on page 269 of the PDF 1.3 spec.
  +	 * @param theNumber The object number of this PDF object.
  +	 * @param theFunctionType The type of function which should be 4, as this is
  +	 * a Postscript calculator function
  +	 */
  +	public PDFFunction(int theNumber, int theFunctionType,
  +			Vector theDomain, Vector theRange,
  +			StringBuffer theFunctionDataStream)
  +	{
  +		super(theNumber);
  +		
  +		this.functionType = 4; //dang well better be 4;
  +		this.functionDataStream = theFunctionDataStream;
  +
  +		this.domain =  theDomain;
  +		
  +		this.range = theRange;
  +
  +	}
  +	
  +
  +	 /**
  +	  * represent as PDF. Whatever the FunctionType is, the correct
  +	  * representation spits out. The sets of required and optional
  +	  * attributes are different for each type, but if a required
  +	  * attribute's object was constructed as null, then no error
  +	  * is raised. Instead, the malformed PDF that was requested
  +	  * by the construction is dutifully output.
  +	  * This policy should be reviewed.
  +	  * 
  +	  * @return the PDF string.
  +	  */ 
  +	public String toPDF() {
  +		int vectorSize=0;
  +		int numberOfFunctions=0;
  +		int tempInt=0;
  +		StringBuffer p = new StringBuffer();
  +		p.append(this.number + " " +this.generation 
  +			+ " obj\n<< \n/FunctionType "+this.functionType+" \n");
  +
  +		//FunctionType 0
  +		if(this.functionType == 0)
  +		{
  +			if(this.domain != null)
  +			{
  +				//DOMAIN
  +				p.append("/Domain [ ");
  +				vectorSize = this.domain.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +						(Double)this.domain.elementAt(tempInt))
  +						+" ");
  +				}
  +				
  +				p.append("] \n");
  +			}			
  +			else
  +			{
  +				p.append("/Domain [ 0 1 ] \n");
  +			}
  +
  +			//SIZE
  +			if(this.size != null)
  +			{
  +				p.append("/Size [ ");
  +				vectorSize = this.size.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.size.elementAt(tempInt)) +" ");
  +				}
  +				p.append("] \n");
  +			}
  +			//ENCODE
  +			if(this.encode != null)
  +			{
  +				p.append("/Encode [ ");
  +				vectorSize = this.encode.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.encode.elementAt(tempInt)) +" ");
  +				}
  +				p.append("] \n");
  +			}
  +			else
  +			{
  +				p.append("/Encode [ ");
  +				vectorSize = this.functions.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append("0 1 ");
  +				}
  +				p.append("] \n");
  +				
  +			}
  +			
  +			//BITSPERSAMPLE
  +			p.append("/BitsPerSample "+this.bitsPerSample);
  +			
  +			//ORDER (optional)
  +			if(this.order ==1 || this.order == 3)
  +			{
  +				p.append(" \n/Order "+this.order+" \n");
  +			}
  +			
  +			//RANGE
  +			if(this.range != null)
  +			{
  +				p.append("/Range [ ");
  +				vectorSize = this.range.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.range.elementAt(tempInt)) +" ");
  +				}
  +				
  +				p.append("] \n");
  +			}
  +			
  +			//DECODE
  +			if(this.decode != null)
  +			{
  +				p.append("/Decode [ ");
  +				vectorSize = this.decode.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.decode.elementAt(tempInt)) +" ");
  +				}
  +				
  +				p.append("] \n");
  +			}
  +			
  +			//LENGTH		
  +			if(this.functionDataStream != null)
  +			{
  +				p.append("/Length "+(this.functionDataStream.length()+1)
  +					+ " \n");
  +			}
  +			
  +			//FILTER?
  +			if (this.filter != null)
  +			{//if there's a filter
  +				vectorSize= this.filter.size();
  +				p.append("/Filter ");
  +				if (vectorSize == 1)
  +				{
  +					p.append("/"+((String)this.filter.elementAt(0))+" \n");
  +				}
  +				else
  +				{
  +					p.append("[ ");
  +					for(tempInt=0; tempInt <vectorSize; tempInt++)
  +					{
  +						p.append("/"+((String)this.filter.elementAt(0))+" ");
  +					}
  +					p.append("] \n");
  +				}
  +			}
  +			p.append(">> \n");
  +			
  +			//stream representing the function
  +			if(this.functionDataStream != null)
  +			{
  +				p.append("stream\n"+this.functionDataStream +"\nendstream\n");
  +			}
  +			
  +			p.append("endobj\n");
  +			
  +		}//end of if FunctionType 0
  +		else if(this.functionType == 2)
  +		{
  +			//DOMAIN
  +			if(this.domain != null)
  +			{
  +				p.append("/Domain [ ");
  +				vectorSize = this.domain.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.domain.elementAt(tempInt)) +" ");
  +				}
  +				
  +				p.append("] \n");
  +			}
  +			else
  +			{
  +				p.append("/Domain [ 0 1 ] \n");
  +			}
  +
  +			
  +			//RANGE
  +			if(this.range != null)
  +			{
  +				p.append("/Range [ ");
  +				vectorSize = this.range.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.range.elementAt(tempInt)) +" ");
  +				}
  +				
  +				p.append("] \n");
  +			}
  +			
  +			//FunctionType, C0, C1, N are required in PDF
  +			
  +			//C0
  +			if(this.cZero != null)
  +			{
  +				p.append("/C0 [ ");
  +				vectorSize = this.cZero.size();
  +				for(tempInt = 0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.cZero.elementAt(tempInt))+" ");
  +				}
  +				p.append("] \n");				
  +			}
  +			
  +			//C1
  +			if(this.cOne != null)
  +			{
  +				p.append("/C1 [ ");
  +				vectorSize = this.cOne.size();
  +				for(tempInt = 0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.cOne.elementAt(tempInt))+" ");
  +				}
  +				p.append("] \n");
  +			}
  +			
  +			//N: The interpolation Exponent
  +			p.append("/N "
  +				+pdfNumber.doubleOut(
  +					new Double(this.interpolationExponentN))
  +				+" \n");
  +			
  +			p.append(">> \nendobj\n");
  +
  +		}
  +		else if(this.functionType == 3)
  +		{//fix this up when my eyes uncross
  +			//DOMAIN
  +			if(this.domain != null)
  +			{
  +				p.append("/Domain [ ");
  +				vectorSize = this.domain.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.domain.elementAt(tempInt)) +" ");
  +				}
  +				p.append("] \n");
  +			}
  +			else
  +			{
  +				p.append("/Domain [ 0 1 ] \n");
  +			}
  +
  +			//RANGE
  +			if(this.range != null)
  +			{
  +				p.append("/Range [ ");
  +				vectorSize = this.range.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.range.elementAt(tempInt)) +" ");
  +				}
  +				
  +				p.append("] \n");
  +			}
  +		
  +			//FUNCTIONS
  +			if(this.functions != null)
  +			{
  +				p.append("/Functions [ ");
  +				numberOfFunctions = this.functions.size();
  +				for(tempInt =0;tempInt < numberOfFunctions; tempInt++)
  +				{
  +					p.append( ((PDFFunction)this.functions.elementAt(tempInt)).referencePDF()+" ");
  +					
  +				}
  +				p.append("] \n");
  +			}
  +			
  +			
  +			//ENCODE
  +			if(this.encode != null)
  +			{
  +				p.append("/Encode [ ");
  +				vectorSize = this.encode.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.encode.elementAt(tempInt)) +" ");
  +				}
  +								
  +				p.append("] \n");
  +			}
  +			else
  +			{
  +				p.append("/Encode [ ");
  +				vectorSize = this.functions.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append("0 1 ");
  +				}
  +				p.append("] \n");
  +				
  +			}
  +			
  +			
  +			//BOUNDS, required, but can be empty
  +			p.append("/Bounds [ ");
  +			if(this.bounds != null)
  +			{
  +				
  +				vectorSize= this.bounds.size();
  +				for(tempInt = 0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.bounds.elementAt(tempInt))+" ");
  +				}
  +			
  +			}
  +			else
  +			{
  +				if(this.functions != null)
  +				{ 
  +					//if there are n functions,
  +					// there must be n-1 bounds.
  +					// so let each function handle an equal portion
  +					// of the whole. e.g. if there are 4, then [ 0.25 0.25 0.25 ]
  +					
  +					String functionsFraction = 
  +						pdfNumber.doubleOut(new Double(
  +							1.0 / ((double)numberOfFunctions)));
  +	
  +					for(tempInt =0;tempInt+1 < numberOfFunctions; tempInt++)
  +					{
  +						
  +						p.append( functionsFraction);
  +					}
  +					functionsFraction = null; //clean reference.
  +					
  +				}
  +				
  +			}
  +			p.append("] \n");
  +			
  +			
  +			p.append(">> \nendobj\n");
  +		}
  +		else if(this.functionType == 4)
  +		{//fix this up when my eyes uncross
  +			//DOMAIN
  +			if(this.domain != null)
  +			{
  +				p.append("/Domain [ ");
  +				vectorSize = this.domain.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.domain.elementAt(tempInt)) +" ");
  +				}
  +				
  +				p.append("] \n");
  +			}
  +			else
  +			{
  +				p.append("/Domain [ 0 1 ] \n");
  +			}
  +
  +			//RANGE
  +			if(this.range != null)
  +			{
  +				p.append("/Range [ ");
  +				vectorSize = this.range.size();
  +				for(tempInt=0; tempInt < vectorSize; tempInt++)
  +				{
  +					p.append(pdfNumber.doubleOut(
  +					(Double)this.range.elementAt(tempInt)) +" ");
  +				}
  +				
  +				p.append("] \n");
  +			}
  +			
  +			//LENGTH		
  +			if(this.functionDataStream != null)
  +			{
  +				p.append("/Length "+(this.functionDataStream.length()+1)
  +					+ " \n");
  +			}
  +			
  +			p.append(">> \n");
  +			
  +			//stream representing the function
  +			if(this.functionDataStream != null)
  +			{
  +				p.append("stream\n{ "+this.functionDataStream +" } \nendstream\n");
  +			}
  +			
  +			p.append("endobj\n");
  +			
  +		}
  +		
  +		return (p.toString());
  +		
  +	}
  +}
  
  
  
  1.3       +4 -2      xml-fop/src/org/apache/fop/pdf/PDFPathPaint.java
  
  Index: PDFPathPaint.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFPathPaint.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PDFPathPaint.java	2000/04/27 19:33:50	1.2
  +++ PDFPathPaint.java	2000/05/15 13:00:19	1.3
  @@ -1,4 +1,4 @@
  -/*-- $Id: PDFPathPaint.java,v 1.2 2000/04/27 19:33:50 gears Exp $ -- 
  +/*-- $Id: PDFPathPaint.java,v 1.3 2000/05/15 13:00:19 gears Exp $ -- 
   
    ============================================================================
   						 The Apache Software License, Version 1.1
  @@ -67,8 +67,10 @@
   		//do nothing
   	}
   	
  -	abstract String getColorSpaceOut(boolean fillNotStroke);
  -	
  +	public String getColorSpaceOut(boolean fillNotStroke)
  +	{
  +		return("");
  +	}
   	
   	public void setColorSpace(int theColorSpace)
   	{
  
  
  
  1.4       +8 -43     xml-fop/src/org/apache/fop/pdf/PDFPattern.java
  
  Index: PDFPattern.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFPattern.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PDFPattern.java	2000/04/27 19:33:50	1.3
  +++ PDFPattern.java	2000/05/15 13:00:19	1.4
  @@ -1,4 +1,4 @@
  -/*-- $Id: PDFPattern.java,v 1.3 2000/04/27 19:33:50 gears Exp $ --
  +/*-- $Id: PDFPattern.java,v 1.4 2000/05/15 13:00:19 gears Exp $ --
   
    ============================================================================
   						 The Apache Software License, Version 1.1
  @@ -68,7 +68,8 @@
    * All PDF Functions have a FunctionType (0,2,3, or 4), a Domain, and a Range.
    */
   public class PDFPattern extends PDFPathPaint {
  -
  +	private PDFNumber pdfNumber = new PDFNumber();
  +	
   	/**
   	 * The resources associated with this pattern
   	 */
  @@ -216,7 +217,6 @@
   		return (this.patternName);
   	}
   	
  -	
   	public String getColorSpaceOut(boolean fillNotStroke)
   	{
   		if(fillNotStroke)
  @@ -228,41 +228,6 @@
   			return("/Pattern CS /"+this.getName()+" SCN \n");
   		}
   	}
  -	/**
  -	 * Output a Double prettily as a string
  -	 * 
  -	 * @param doubleDown The Double to output.
  -	 * @return String representation of value passed.
  -	 */
  -	public String doubleOut(Double doubleDown)
  -	{
  -		StringBuffer p = new StringBuffer();
  -		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(".");
  -			p.append(doubleString.substring(0, decimal));
  -
  -			if ((doubleString.length() - decimal) > 6)
  -			{
  -				p.append(doubleString.substring(decimal,decimal+6));
  -			}
  -			else
  -			{
  -				p.append(doubleString.substring(decimal));
  -			}
  -		}
  -		return(p.toString());
  -	}
    
   	
   	 /**
  @@ -304,12 +269,12 @@
   				for (tempInt =0; tempInt < vectorSize; tempInt++)
   				{
   					p.append(
  -					this.doubleOut((Double)this.bBox.elementAt(tempInt)));				
  +					pdfNumber.doubleOut((Double)this.bBox.elementAt(tempInt)));				
   				}
   				p.append("] \n");
   			}
  -			p.append("/XStep "+this.doubleOut(new Double(this.xStep))+" \n");
  -			p.append("/YStep "+this.doubleOut(new Double(this.yStep))+" \n");
  +			p.append("/XStep "+pdfNumber.doubleOut(new Double(this.xStep))+" \n");
  +			p.append("/YStep "+pdfNumber.doubleOut(new Double(this.yStep))+" \n");
   			
   			if(this.matrix != null)
   			{
  @@ -317,7 +282,7 @@
   				p.append("/Matrix [ ");
   				for (tempInt =0; tempInt < vectorSize; tempInt++)
   				{
  -					p.append(this.doubleOut(
  +					p.append(pdfNumber.doubleOut(
   						(Double)this.matrix.elementAt(tempInt)));				
   				}
   				p.append("] \n");
  @@ -370,7 +335,7 @@
   				p.append("/Matrix [ ");
   				for (tempInt =0; tempInt < vectorSize; tempInt++)
   				{
  -					p.append(this.doubleOut(
  +					p.append(pdfNumber.doubleOut(
   					(Double)this.matrix.elementAt(tempInt)));				
   				}
   				p.append("] \n");
  
  
  
  1.4       +9 -37     xml-fop/src/org/apache/fop/pdf/PDFShading.java
  
  Index: PDFShading.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFShading.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PDFShading.java	2000/04/27 19:33:50	1.3
  +++ PDFShading.java	2000/05/15 13:00:20	1.4
  @@ -1,4 +1,4 @@
  -/*-- $Id: PDFShading.java,v 1.3 2000/04/27 19:33:50 gears Exp $ -- 
  +/*-- $Id: PDFShading.java,v 1.4 2000/05/15 13:00:20 gears Exp $ -- 
   
    ============================================================================
   						 The Apache Software License, Version 1.1
  @@ -160,6 +160,8 @@
   	 */
   	protected int verticesPerRow = 0;
   	
  +	private PDFNumber pdfNumber = new PDFNumber();
  +	
   	/**
   	 * Constructor for type function based shading
   	 * 
  @@ -336,36 +338,6 @@
   		return (this.shadingName);
      }
      
  -	public String doubleOut(Double doubleDown)
  -	{
  -		StringBuffer p = new StringBuffer();
  -		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(".");
  -			p.append(doubleString.substring(0, decimal));
  -
  -			if ((doubleString.length() - decimal) > 6)
  -			{
  -				p.append(doubleString.substring(decimal,decimal+6));
  -			}
  -			else
  -			{
  -				p.append(doubleString.substring(decimal));
  -			}
  -		}
  -		return(p.toString());
  -	}
  -   
   	 /**
   	  * represent as PDF. Whatever the shadingType is, the correct
   	  * representation spits out. The sets of required and optional
  @@ -395,7 +367,7 @@
   			vectorSize = this.background.size();
   			for(tempInt=0; tempInt < vectorSize; tempInt++)
   			{
  -				p.append(this.doubleOut(
  +				p.append(pdfNumber.doubleOut(
   				(Double)this.background.elementAt(tempInt)) +" ");
   			}
   			p.append("] \n");
  @@ -407,7 +379,7 @@
   			vectorSize = this.bBox.size();
   			for(tempInt=0; tempInt < vectorSize; tempInt++)
   			{
  -				p.append(this.doubleOut(
  +				p.append(pdfNumber.doubleOut(
   				(Double)this.bBox.elementAt(tempInt)) +" ");
   			}
   			p.append("] \n");
  @@ -427,7 +399,7 @@
   				vectorSize = this.domain.size();
   				for(tempInt=0; tempInt < vectorSize; tempInt++)
   				{
  -					p.append(this.doubleOut(
  +					p.append(pdfNumber.doubleOut(
   					(Double)this.domain.elementAt(tempInt)) +" ");
   				}
   				p.append("] \n");
  @@ -443,7 +415,7 @@
   				vectorSize = this.matrix.size();
   				for(tempInt=0; tempInt < vectorSize; tempInt++)
   				{
  -					p.append(this.doubleOut(
  +					p.append(pdfNumber.doubleOut(
   					(Double)this.matrix.elementAt(tempInt)) +" ");
   				}
   				p.append("] \n");
  @@ -465,7 +437,7 @@
   				vectorSize = this.coords.size();
   				for(tempInt=0; tempInt < vectorSize; tempInt++)
   				{
  -					p.append(this.doubleOut(
  +					p.append(pdfNumber.doubleOut(
   					(Double)this.coords.elementAt(tempInt)) +" ");
   				}
   				p.append("] \n");
  @@ -478,7 +450,7 @@
   				vectorSize = this.domain.size();
   				for(tempInt=0; tempInt < vectorSize; tempInt++)
   				{
  -					p.append(this.doubleOut(
  +					p.append(pdfNumber.doubleOut(
   					(Double)this.domain.elementAt(tempInt)) +" ");
   				}
   				p.append("] \n");
  
  
  
  1.1                  xml-fop/src/org/apache/fop/pdf/PDFNumber.java
  
  Index: PDFNumber.java
  ===================================================================
  /*-- $Id: PDFNumber.java,v 1.1 2000/05/15 13:00:19 gears Exp $ -- 
  
   ============================================================================
  				   The Apache Software License, Version 1.1
   ============================================================================
   
  	Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
   
   1. Redistributions of	source code must  retain the above copyright  notice,
  	this list of conditions and the following disclaimer.
   
   2. Redistributions in binary form must reproduce the above copyright notice,
  	this list of conditions and the following disclaimer in the documentation
  	and/or other materials provided with the distribution.
   
   3. The end-user documentation included with the redistribution, if any, must
  	include  the following	acknowledgment:  "This product includes  software
  	developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  	Alternately, this  acknowledgment may  appear in the software itself,  if
  	and wherever such third-party acknowledgments normally appear.
   
   4. The names "FOP" and  "Apache Software Foundation"  must not be used to
  	endorse  or promote  products derived  from this  software without	prior
  	written permission. For written permission, please contact
  	apache@apache.org.
   
   5. Products  derived from this software may not  be called "Apache", nor may
  	"Apache" appear  in their name,  without prior written permission  of the
  	Apache Software Foundation.
   
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR	PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT	OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)	HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,	WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR	OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
   This software	consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software	Foundation and was	originally created by
   James Tauber <jt...@jtauber.com>. For more  information on the Apache 
   Software Foundation, please see <http://www.apache.org/>.
   
   */
  
  package org.apache.fop.pdf;
  
  public class PDFNumber {
  
  	
  	public PDFNumber()
  	{
  		
  		//How can I allow people to use the method, without allowing construction?
  		
  	}
  	
  	public String doubleOut(Double doubleDown)
  	{
  		StringBuffer p = new StringBuffer();
  		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(".");
  			p.append(doubleString.substring(0, decimal));
  
  			if ((doubleString.length() - decimal) > 6)
  			{
  				p.append(doubleString.substring(decimal,decimal+6));
  			}
  			else
  			{
  				p.append(doubleString.substring(decimal));
  			}
  		}
  		return(p.toString());
  	}
  	
  	public String doubleOut(double doubleDown)
  	{
  		
  		StringBuffer p = new StringBuffer();
  		double trouble = doubleDown % 1;
  		
  		if(trouble > 0.950)
  		{
  			p.append((int)doubleDown+1);
  		}
  		else if (trouble < 0.050)
  		{
  			p.append((int)doubleDown);
  		}
  		else
  		{
  			String doubleString = new String(doubleDown+"");
  			int decimal = doubleString.indexOf(".");
  			p.append(doubleString.substring(0, decimal));
  
  			if ((doubleString.length() - decimal) > 6)
  			{
  				p.append(doubleString.substring(decimal,decimal+6));
  			}
  			else
  			{
  				p.append(doubleString.substring(decimal));
  			}
  		}
  		return(p.toString());
  	}
  } 
  
  
  
  1.15      +564 -570  xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
  
  Index: PDFRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- PDFRenderer.java	2000/04/21 21:11:29	1.14
  +++ PDFRenderer.java	2000/05/15 13:00:21	1.15
  @@ -1,570 +1,564 @@
  -/*-- $Id: PDFRenderer.java,v 1.14 2000/04/21 21:11:29 gears Exp $ -- 
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  - 
  -    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  - 
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  - 
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  - 
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  - 
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  - 
  - 4. The names "FOP" and  "Apache Software Foundation"  must not be used to
  -    endorse  or promote  products derived  from this  software without  prior
  -    written permission. For written permission, please contact
  -    apache@apache.org.
  - 
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  - 
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  - 
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation and was  originally created by
  - James Tauber <jt...@jtauber.com>. For more  information on the Apache 
  - Software Foundation, please see <http://www.apache.org/>.
  - 
  - */
  -
  -package org.apache.fop.render.pdf;
  -
  -// FOP
  -import org.apache.fop.render.Renderer;
  -import org.apache.fop.image.ImageArea;
  -import org.apache.fop.image.FopImage;
  -import org.apache.fop.fo.properties.*;
  -import org.apache.fop.layout.*;
  -import org.apache.fop.datatypes.*;
  -import org.apache.fop.svg.*;
  -import org.apache.fop.pdf.*;
  -
  -// Java
  -import java.io.IOException;
  -import java.io.PrintWriter;
  -import java.util.Enumeration;
  -import java.awt.Rectangle;
  -import java.util.Vector;
  -
  -/**
  - * Renderer that renders areas to PDF
  - */
  -public class PDFRenderer implements Renderer {
  -	
  -    /** the PDF Document being created */
  -    protected PDFDocument pdfDoc;
  -
  -    /** the /Resources object of the PDF document being created */
  -    protected PDFResources pdfResources;
  -
  -    /** the current stream to add PDF commands to */
  -    PDFStream currentStream;
  -
  -    /** the current annotation list to add annotations to */
  -    PDFAnnotList currentAnnotList;
  -
  -    /** the current page to add annotations to */
  -    PDFPage currentPage;
  -
  -    /** the current (internal) font name */
  -    protected String currentFontName;
  -
  -    /** the current font size in millipoints */
  -    protected int currentFontSize;
  -
  -    /** the current colour's red component */
  -    protected float currentRed = 0;
  -
  -    /** the current colour's green component */
  -    protected float currentGreen = 0;
  -
  -    /** the current colour's blue component */
  -    protected float currentBlue = 0;
  -	
  -    /** the current vertical position in millipoints from bottom */
  -    protected int currentYPosition = 0;
  -
  -    /** the current horizontal position in millipoints from left */
  -    protected int currentXPosition = 0;
  -
  -    /** the horizontal position of the current area container */
  -    private int currentAreaContainerXPosition = 0;
  -
  -    /**
  -     * create the PDF renderer
  -     */
  -    public PDFRenderer() {
  -	this.pdfDoc = new PDFDocument();
  -    }
  -
  -    /**
  -     * set the PDF document's producer
  -     *
  -     * @param producer string indicating application producing PDF
  -     */
  -    public void setProducer(String producer) {
  -	this.pdfDoc.setProducer(producer);
  -    }
  -
  -    /**
  -     * render the areas into PDF
  -     *
  -     * @param areaTree the laid-out area tree
  -     * @param writer the PrintWriter to write the PDF with
  -     */
  -    public void render(AreaTree areaTree, PrintWriter writer)
  -	throws IOException {
  -	System.err.println("rendering areas to PDF");
  -	this.pdfResources = this.pdfDoc.getResources();
  -	Enumeration e = areaTree.getPages().elements();
  -	while (e.hasMoreElements()) {
  -	    this.renderPage((Page) e.nextElement());
  -	}
  -	System.err.println("writing out PDF");
  -	this.pdfDoc.output(writer);
  -    }
  -
  -    /**
  -     * add a line to the current stream
  -     *
  -     * @param x1 the start x location in millipoints
  -     * @param y1 the start y location in millipoints
  -     * @param x2 the end x location in millipoints
  -     * @param y2 the end y location in millipoints
  -     * @param th the thickness in millipoints
  -     * @param r the red component
  -     * @param g the green component
  -     * @param b the blue component
  -     */
  -    protected void addLine(int x1, int y1, int x2, int y2, int th,
  -			float r, float g, float b) {
  -	currentStream.add(r + " " + g + " " + b + " RG\n"
  -			  + (x1/1000f) + " " + (y1/1000f) + " m "
  -			  + (x2/1000f) + " " + (y2/1000f) + " l "
  -			  + (th/1000f) + " w S\n"
  -			  + "0 0 0 RG\n");
  -    }
  -
  -    /**
  -     * add a rectangle to the current stream
  -     *
  -     * @param x the x position of left edge in millipoints
  -     * @param y the y position of top edge in millipoints
  -     * @param w the width in millipoints
  -     * @param h the height in millipoints
  -     * @param r the red component
  -     * @param g the green component
  -     * @param b the blue component
  -     */
  -    protected void addRect(int x, int y, int w, int h,
  -			   float r, float g, float b) { 
  -	currentStream.add(r + " " + g + " " + b + " RG\n"
  -			  + (x/1000f) + " " + (y/1000f) + " "
  -			  + (w/1000f) + " " + (h/1000f) + " re S\n"
  -			  + "0 0 0 RG\n");
  -    }
  -
  -    /**
  -     * add a filled rectangle to the current stream
  -     *
  -     * @param x the x position of left edge in millipoints
  -     * @param y the y position of top edge in millipoints
  -     * @param w the width in millipoints
  -     * @param h the height in millipoints
  -     * @param r the red component of edges
  -     * @param g the green component of edges
  -     * @param b the blue component of edges
  -     * @param fr the red component of the fill
  -     * @param fg the green component of the fill
  -     * @param fb the blue component of the fill
  -     */
  -    protected void addRect(int x, int y, int w, int h,
  -			   float r, float g, float b,
  -			   float fr, float fg, float fb) {
  -	currentStream.add(fr + " " + fg + " " + fb + " rg\n"
  -			  + r + " " + g + " " + b + " RG\n"
  -			  + (x/1000f) + " " + (y/1000f) + " "
  -			  + (w/1000f) + " " + (h/1000f) + " re S\n"
  -			  + (x/1000f) + " " + (y/1000f) + " "
  -			  + (w/1000f) + " " + (h/1000f) + " re f\n"
  -			  + "0 0 0 RG 0 0 0 rg\n");
  -    }
  -
  -    /**
  -     * render area container to PDF
  -     *
  -     * @param area the area container to render
  -     */
  -    public void renderAreaContainer(AreaContainer area) {
  -        
  -        int saveY = this.currentYPosition;
  -        int saveX = this.currentAreaContainerXPosition;
  -        
  -        if (area.getPosition() == Position.ABSOLUTE) {
  -            // Y position is computed assuming positive Y axis, adjust for negative postscript one
  - 	  this.currentYPosition = area.getYPosition() - 2 * area.getPaddingTop() - 2 * area.borderWidthTop;
  -	  this.currentAreaContainerXPosition = area.getXPosition();
  -        } else if (area.getPosition() == Position.RELATIVE) {
  -	  this.currentYPosition -= area.getYPosition();
  -    	  this.currentAreaContainerXPosition += area.getXPosition();
  -        } else if (area.getPosition() == Position.STATIC) {
  -	  this.currentYPosition -= area.getPaddingTop() + area.borderWidthTop;
  -    	  this.currentAreaContainerXPosition += area.getPaddingLeft() + area.borderWidthLeft;
  -        }
  -
  -        doFrame(area);
  -        
  -	Enumeration e = area.getChildren().elements();
  -	while (e.hasMoreElements()) {
  -	    Box b = (Box) e.nextElement();
  -	    b.render(this);
  -	}
  -        if (area.getPosition() != Position.STATIC) {
  -          this.currentYPosition = saveY;
  -          this.currentAreaContainerXPosition = saveX;
  -        } else 
  -          this.currentYPosition -= area.getHeight();
  -    }
  -    
  -    private void doFrame(Area area) {
  -        int w, h;
  -	int rx = this.currentAreaContainerXPosition;
  -	w = area.getContentWidth();
  -        if (area instanceof BlockArea)
  -	  rx += ((BlockArea)area).getStartIndent();
  -    	h = area.getContentHeight();
  -	int ry = this.currentYPosition;
  -	ColorType bg = area.getBackgroundColor();
  -        
  -        rx = rx - area.getPaddingLeft();
  -        ry = ry + area.getPaddingTop();
  -        w = w + area.getPaddingLeft() + area.getPaddingRight();
  -        h = h + area.getPaddingTop() + area.getPaddingBottom();
  -        
  -	// I'm not sure I should have to check for bg being null
  -	// but I do
  -	if ((bg != null) && (bg.alpha() == 0)) {
  -	    this.addRect(rx, ry, w, -h,
  -			 bg.red(), bg.green(), bg.blue(),
  -			 bg.red(), bg.green(), bg.blue());
  -	}
  -    
  -        rx = rx - area.borderWidthLeft;
  -        ry = ry + area.borderWidthTop;
  -        w = w + area.borderWidthLeft + area.borderWidthRight;
  -        h = h + area.borderWidthTop + area.borderWidthBottom;
  -        
  -        if (area.borderWidthTop != 0)
  -          addLine(rx, ry, rx + w, ry, 
  -                area.borderWidthTop,  
  -                area.borderColorTop.red(), area.borderColorTop.green(), area.borderColorTop.blue());
  -        if (area.borderWidthLeft != 0)
  -          addLine(rx, ry, rx, ry - h, 
  -                area.borderWidthLeft,  
  -                area.borderColorLeft.red(), area.borderColorLeft.green(), area.borderColorLeft.blue());
  -        if (area.borderWidthRight != 0)
  -          addLine(rx + w, ry, rx + w, ry - h, 
  -                area.borderWidthRight,  
  -                area.borderColorRight.red(), area.borderColorRight.green(), area.borderColorRight.blue());
  -        if (area.borderWidthBottom != 0)
  -          addLine(rx, ry - h, rx + w, ry - h, 
  -                area.borderWidthBottom,  
  -                area.borderColorBottom.red(), area.borderColorBottom.green(), area.borderColorBottom.blue());
  -
  -    } 
  -   
  -
  -    /**
  -     * render block area to PDF
  -     *
  -     * @param area the block area to render
  -     */
  -    public void renderBlockArea(BlockArea area) {
  -        doFrame(area);
  -	Enumeration e = area.getChildren().elements();
  -	while (e.hasMoreElements()) {
  -	    Box b = (Box) e.nextElement();
  -	    b.render(this);
  -	}
  -    }
  -
  -    /**
  -     * render display space to PDF
  -     *
  -     * @param space the display space to render
  -     */
  -    public void renderDisplaySpace(DisplaySpace space) {
  -	int d = space.getSize();
  -	this.currentYPosition -= d;
  -    }
  -
  -    /**
  -     * render image area to PDF
  -     *
  -     * @param area the image area to render
  -     */
  -    public void renderImageArea(ImageArea area) {
  -	// adapted from contribution by BoBoGi
  -	int x = this.currentAreaContainerXPosition +
  -	    area.getXOffset();
  -	int y = this.currentYPosition;
  -	int w = area.getContentWidth();
  -	int h = area.getHeight();
  -
  -	this.currentYPosition -= h;
  -
  -	FopImage img = area.getImage();
  -
  -	int xObjectNum = this.pdfDoc.addImage(img);
  -
  -	currentStream.add("ET\nq\n" + (img.getWidth()/1000f) + " 0 0 " +
  -			  (img.getHeight()/1000f) + " " + 
  -			  ((x + img.getX())/1000f) + " " + 
  -			  (((y - h) - img.getY())/1000f) + " cm\n" +
  -			  "/Im" + xObjectNum + " Do\nQ\nBT\n"); 
  -    }
  -    
  -    /**
  -     * render SVG area to PDF
  -     *
  -     * @param area the SVG area to render
  -     */
  -    public void renderSVGArea(SVGArea area) {
  -	int x = this.currentAreaContainerXPosition;
  -	int y = this.currentYPosition;
  -	int w = area.getContentWidth();
  -	int h = area.getHeight();
  -	this.currentYPosition -= h;
  -	Enumeration e = area.getChildren().elements();
  -	while (e.hasMoreElements()) {
  -	    Object o = e.nextElement();
  -	    if (o instanceof RectGraphic) {
  -		int rx = ((RectGraphic)o).x;
  -		int ry = ((RectGraphic)o).y;
  -		int rw = ((RectGraphic)o).width;
  -		int rh = ((RectGraphic)o).height;
  -		addRect(x+rx,y-ry,rw,-rh,0,0,0);
  -	    } else if (o instanceof LineGraphic) {
  -		int x1 = ((LineGraphic)o).x1;
  -		int y1 = ((LineGraphic)o).y1;
  -		int x2 = ((LineGraphic)o).x2;
  -		int y2 = ((LineGraphic)o).y2;
  -		addLine(x+x1,y-y1,x+x2,y-y2,0,0,0,0);
  -	    } else if (o instanceof TextGraphic) {
  -		int tx = ((TextGraphic)o).x;
  -		int ty = ((TextGraphic)o).y;
  -		String s = ((TextGraphic)o).s;
  -		currentStream.add("1 0 0 1 "
  -				  + ((x+tx)/1000f) + " "
  -				  + ((y-ty)/1000f) + " Tm " 
  -				  + "(" + s + ") Tj\n");
  -	    }
  -	}
  -    }
  -
  -    /**
  -     * render inline area to PDF
  -     *
  -     * @param area inline area to render
  -     */
  -    public void renderInlineArea(InlineArea area) {
  -	char ch;
  -	StringBuffer pdf = new StringBuffer();
  -		
  -	String name = area.getFontState().getFontName();
  -	int size = area.getFontState().getFontSize();
  -
  -	float red = area.getRed();
  -	float green = area.getGreen();
  -	float blue = area.getBlue();
  -		
  -	if ((!name.equals(this.currentFontName))
  -	    || (size != this.currentFontSize)) {
  -	    this.currentFontName = name;
  -	    this.currentFontSize = size;
  -	    pdf = pdf.append("/" + name + " " + (size/1000) + " Tf\n");
  -	}
  -
  -	if ((red != this.currentRed)
  -	    || (green != this.currentGreen)
  -	    || (blue != this.currentBlue)) {
  -	    this.currentRed = red;
  -	    this.currentGreen = green;
  -	    this.currentBlue = blue;
  -	    pdf = pdf.append(red + " " + green + " " + blue + " rg\n");
  -	}
  -		
  -	int rx = this.currentXPosition;
  -	int bl = this.currentYPosition;
  -
  -	pdf = pdf.append("1 0 0 1 "
  -			 +(rx/1000f) + " " + (bl/1000f)
  -			 + " Tm (");
  -
  -	String s = area.getText();
  -	int l = s.length();
  -
  -	for (int i=0; i < l; i++) {
  -	    ch = s.charAt(i);
  -	    if (ch > 127) {
  -		pdf = pdf.append("\\");
  -		pdf = pdf.append(Integer.toOctalString((int)ch));
  -	    } else {
  -		switch (ch) {
  -		case '('  : pdf = pdf.append("\\("); break;
  -		case ')'  : pdf = pdf.append("\\)"); break;
  -		case '\\' : pdf = pdf.append("\\\\"); break;
  -		default   : pdf = pdf.append(ch); break;
  -		}
  -	    }
  -	}
  -	pdf = pdf.append(") Tj\n");
  -
  -	currentStream.add(pdf.toString());
  -
  -	this.currentXPosition += area.getContentWidth();
  -    }
  -
  -    /**
  -     * render inline space to PDF
  -     *
  -     * @param space space to render
  -     */
  -    public void renderInlineSpace(InlineSpace space) {
  -	this.currentXPosition += space.getSize();
  -    }
  -
  -    /**
  -     * render line area to PDF
  -     *
  -     * @param area area to render
  -     */
  -    public void renderLineArea(LineArea area) {
  -	int rx = this.currentAreaContainerXPosition
  -	    + area.getStartIndent();
  -	int ry = this.currentYPosition;
  -	int w = area.getContentWidth();
  -	int h = area.getHeight();
  -
  -	this.currentYPosition -= area.getPlacementOffset();
  -	this.currentXPosition = rx;
  -
  -	int bl = this.currentYPosition;
  -
  -	Enumeration e = area.getChildren().elements();
  -	while (e.hasMoreElements()) {
  -	    Box b = (Box) e.nextElement();
  -	    b.render(this);
  -	}
  -
  -	this.currentYPosition = ry-h;
  -    }
  -
  -    /**
  -     * render page into PDF
  -     *
  -     * @param page page to render
  -     */
  -    public void renderPage(Page page) {
  -	AreaContainer body, before, after;
  -      
  -	currentStream = this.pdfDoc.makeStream();
  -	body = page.getBody();
  -	before = page.getBefore();
  -	after = page.getAfter();
  -
  -	this.currentFontName = "";
  -	this.currentFontSize = 0;
  -
  -	currentStream.add("BT\n");
  -	renderAreaContainer(body);
  -
  -	if (before != null) {
  -	    renderAreaContainer(before);
  -	}
  -
  -	if (after != null) {
  -	    renderAreaContainer(after);
  -	}
  -	
  -	currentStream.add("ET\n");
  -
  -	currentPage = this.pdfDoc.makePage(this.pdfResources, currentStream,
  -			     page.getWidth()/1000,
  -			     page.getHeight()/1000);
  -
  -	if (page.hasLinks()) {
  -	    currentAnnotList = this.pdfDoc.makeAnnotList();
  -	    currentPage.setAnnotList(currentAnnotList);
  -
  -	    Enumeration e = page.getLinkSets().elements();
  -	    while (e.hasMoreElements()) {
  -		LinkSet linkSet = (LinkSet) e.nextElement();
  -
  -		linkSet.align();
  -		String dest = linkSet.getDest();
  -		Enumeration f = linkSet.getRects().elements();
  -		while (f.hasMoreElements()) {
  -		    LinkedRectangle lrect = (LinkedRectangle) f.nextElement();
  -		    currentAnnotList.addLink(
  -		        this.pdfDoc.makeLink(lrect.getRectangle(), dest));
  -		}
  -	    }
  -	} else {
  -	    // just to be on the safe side
  -	    currentAnnotList = null;
  -	}
  -    }
  -
  -    /**
  -     * render rule area into PDF
  -     *
  -     * @param area area to render
  -     */
  -    public void renderRuleArea(RuleArea area) {
  -	int rx = this.currentAreaContainerXPosition
  -	    + area.getStartIndent();
  -	int ry = this.currentYPosition;
  -	int w = area.getContentWidth();
  -	int h = area.getHeight();
  -	int th = area.getRuleThickness();
  -	float r = area.getRed();
  -	float g = area.getGreen();
  -	float b = area.getBlue();
  -	
  -	addLine(rx, ry, rx+w, ry, th, r, g, b);
  -    }
  -
  -    /**
  -     * set up the font info
  -     *
  -     * @param fontInfo font info to set up
  -     */
  -    public void setupFontInfo(FontInfo fontInfo) {
  -	FontSetup.setup(fontInfo);
  -	FontSetup.addToResources(this.pdfDoc, fontInfo);
  -    }
  -}
  -
  +/*-- $Id: PDFRenderer.java,v 1.15 2000/05/15 13:00:21 gears Exp $ -- 
  +
  + ============================================================================
  +				   The Apache Software License, Version 1.1
  + ============================================================================
  + 
  +	Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  + 
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  + 
  + 1. Redistributions of	source code must  retain the above copyright  notice,
  +	this list of conditions and the following disclaimer.
  + 
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +	this list of conditions and the following disclaimer in the documentation
  +	and/or other materials provided with the distribution.
  + 
  + 3. The end-user documentation included with the redistribution, if any, must
  +	include  the following	acknowledgment:  "This product includes  software
  +	developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +	Alternately, this  acknowledgment may  appear in the software itself,  if
  +	and wherever such third-party acknowledgments normally appear.
  + 
  + 4. The names "FOP" and  "Apache Software Foundation"  must not be used to
  +	endorse  or promote  products derived  from this  software without	prior
  +	written permission. For written permission, please contact
  +	apache@apache.org.
  + 
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +	"Apache" appear  in their name,  without prior written permission  of the
  +	Apache Software Foundation.
  + 
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR	PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT	OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)	HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,	WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR	OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  + 
  + This software	consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software	Foundation and was	originally created by
  + James Tauber <jt...@jtauber.com>. For more  information on the Apache 
  + Software Foundation, please see <http://www.apache.org/>.
  + 
  + */
  +
  +package org.apache.fop.render.pdf;
  +
  +// FOP
  +import org.apache.fop.render.Renderer;
  +import org.apache.fop.image.ImageArea;
  +import org.apache.fop.image.FopImage;
  +import org.apache.fop.fo.properties.*;
  +import org.apache.fop.layout.*;
  +import org.apache.fop.datatypes.*;
  +import org.apache.fop.svg.*;
  +import org.apache.fop.pdf.*;
  +
  +// Java
  +import java.io.IOException;
  +import java.io.PrintWriter;
  +import java.util.Enumeration;
  +import java.awt.Rectangle;
  +import java.util.Vector;
  +
  +/**
  + * Renderer that renders areas to PDF
  + */
  +public class PDFRenderer implements Renderer {
  +	
  +	/** the PDF Document being created */
  +	protected PDFDocument pdfDoc;
  +
  +	/** the /Resources object of the PDF document being created */
  +	protected PDFResources pdfResources;
  +
  +	/** the current stream to add PDF commands to */
  +	PDFStream currentStream;
  +
  +	/** the current annotation list to add annotations to */
  +	PDFAnnotList currentAnnotList;
  +
  +	/** the current page to add annotations to */
  +	PDFPage currentPage;
  +
  +	/** the current (internal) font name */
  +	protected String currentFontName;
  +
  +	/** the current font size in millipoints */
  +	protected int currentFontSize;
  +
  +	/** the current color/gradient for borders, letters, etc. */
  +	protected PDFPathPaint currentStroke = null;
  +	
  +	/** the current color/gradient to fill shapes with */
  +	protected PDFPathPaint currentFill = null;
  +	
  +	/** the current colour's red component */
  +	protected float currentRed = 0;
  +
  +	/** the current colour's green component */
  +	protected float currentGreen = 0;
  +
  +	/** the current colour's blue component */
  +	protected float currentBlue = 0;
  +	
  +	/** the current vertical position in millipoints from bottom */
  +	protected int currentYPosition = 0;
  +
  +	/** the current horizontal position in millipoints from left */
  +	protected int currentXPosition = 0;
  +
  +	/** the horizontal position of the current area container */
  +	private int currentAreaContainerXPosition = 0;
  +
  +	/**
  +	 * create the PDF renderer
  +	 */
  +	public PDFRenderer() {
  +	this.pdfDoc = new PDFDocument();
  +	}
  +
  +	/**
  +	 * set the PDF document's producer
  +	 *
  +	 * @param producer string indicating application producing PDF
  +	 */
  +	public void setProducer(String producer) {
  +	this.pdfDoc.setProducer(producer);
  +	}
  +
  +	/**
  +	 * render the areas into PDF
  +	 *
  +	 * @param areaTree the laid-out area tree
  +	 * @param writer the PrintWriter to write the PDF with
  +	 */
  +	public void render(AreaTree areaTree, PrintWriter writer)
  +	throws IOException {
  +	System.err.println("rendering areas to PDF");
  +	this.pdfResources = this.pdfDoc.getResources();
  +	Enumeration e = areaTree.getPages().elements();
  +	while (e.hasMoreElements()) {
  +		this.renderPage((Page) e.nextElement());
  +	}
  +	System.err.println("writing out PDF");
  +	this.pdfDoc.output(writer);
  +	}
  +
  +	/**
  +	 * add a line to the current stream
  +	 *
  +	 * @param x1 the start x location in millipoints
  +	 * @param y1 the start y location in millipoints
  +	 * @param x2 the end x location in millipoints
  +	 * @param y2 the end y location in millipoints
  +	 * @param th the thickness in millipoints
  +	 * @param stroke the stroke color/gradient
  +	 */
  +	protected void addLine(int x1, int y1, int x2, int y2, int th,
  +			PDFPathPaint stroke) {
  +		
  +	currentStream.add(stroke.getColorSpaceOut(false)
  +			  + (x1/1000f) + " " + (y1/1000f) + " m "
  +			  + (x2/1000f) + " " + (y2/1000f) + " l "
  +			  + (th/1000f) + " w S\n"
  +			  + "0 0 0 RG\n");
  +	}
  +
  +	/**
  +	 * add a rectangle to the current stream
  +	 *
  +	 * @param x the x position of left edge in millipoints
  +	 * @param y the y position of top edge in millipoints
  +	 * @param w the width in millipoints
  +	 * @param h the height in millipoints
  +	 * @param stroke the stroke color/gradient
  +	 */
  +	protected void addRect(int x, int y, int w, int h,
  +			   PDFPathPaint stroke) { 
  +	currentStream.add(stroke.getColorSpaceOut(false)
  +			  + (x/1000f) + " " + (y/1000f) + " "
  +			  + (w/1000f) + " " + (h/1000f) + " re S\n"
  +			  + "0 0 0 RG\n");
  +	}
  +
  +	/**
  +	 * add a filled rectangle to the current stream
  +	 *
  +	 * @param x the x position of left edge in millipoints
  +	 * @param y the y position of top edge in millipoints
  +	 * @param w the width in millipoints
  +	 * @param h the height in millipoints
  +	 * @param fill the fill color/gradient
  +	 * @param stroke the stroke color/gradient
  +	 */
  +	protected void addRect(int x, int y, int w, int h,
  +			   PDFPathPaint stroke,
  +			   PDFPathPaint fill) {
  +	currentStream.add(fill.getColorSpaceOut(true)
  +			  + stroke.getColorSpaceOut(false)
  +			  + (x/1000f) + " " + (y/1000f) + " "
  +			  + (w/1000f) + " " + (h/1000f) + " re S\n"
  +			  + (x/1000f) + " " + (y/1000f) + " "
  +			  + (w/1000f) + " " + (h/1000f) + " re f\n"
  +			  + "0 0 0 RG 0 0 0 rg\n");
  +	}
  +
  +	/**
  +	 * render area container to PDF
  +	 *
  +	 * @param area the area container to render
  +	 */
  +	public void renderAreaContainer(AreaContainer area) {
  +		
  +		int saveY = this.currentYPosition;
  +		int saveX = this.currentAreaContainerXPosition;
  +		
  +		if (area.getPosition() == Position.ABSOLUTE) {
  +			// Y position is computed assuming positive Y axis, adjust for negative postscript one
  +	  this.currentYPosition = area.getYPosition() - 2 * area.getPaddingTop() - 2 * area.borderWidthTop;
  +	  this.currentAreaContainerXPosition = area.getXPosition();
  +		} else if (area.getPosition() == Position.RELATIVE) {
  +	  this.currentYPosition -= area.getYPosition();
  +		  this.currentAreaContainerXPosition += area.getXPosition();
  +		} else if (area.getPosition() == Position.STATIC) {
  +	  this.currentYPosition -= area.getPaddingTop() + area.borderWidthTop;
  +		  this.currentAreaContainerXPosition += area.getPaddingLeft() + area.borderWidthLeft;
  +		}
  +
  +		doFrame(area);
  +		
  +	Enumeration e = area.getChildren().elements();
  +	while (e.hasMoreElements()) {
  +		Box b = (Box) e.nextElement();
  +		b.render(this);
  +	}
  +		if (area.getPosition() != Position.STATIC) {
  +		  this.currentYPosition = saveY;
  +		  this.currentAreaContainerXPosition = saveX;
  +		} else 
  +		  this.currentYPosition -= area.getHeight();
  +	}
  +	
  +	private void doFrame(Area area) {
  +		int w, h;
  +	int rx = this.currentAreaContainerXPosition;
  +	w = area.getContentWidth();
  +		if (area instanceof BlockArea)
  +	  rx += ((BlockArea)area).getStartIndent();
  +		h = area.getContentHeight();
  +	int ry = this.currentYPosition;
  +	ColorType bg = area.getBackgroundColor();
  +		
  +		rx = rx - area.getPaddingLeft();
  +		ry = ry + area.getPaddingTop();
  +		w = w + area.getPaddingLeft() + area.getPaddingRight();
  +		h = h + area.getPaddingTop() + area.getPaddingBottom();
  +		
  +	// I'm not sure I should have to check for bg being null
  +	// but I do
  +	if ((bg != null) && (bg.alpha() == 0)) {
  +		this.addRect(rx, ry, w, -h,
  +			 new PDFColor(bg),
  +			 new PDFColor(bg));
  +	}
  +	
  +		rx = rx - area.borderWidthLeft;
  +		ry = ry + area.borderWidthTop;
  +		w = w + area.borderWidthLeft + area.borderWidthRight;
  +		h = h + area.borderWidthTop + area.borderWidthBottom;
  +		
  +		if (area.borderWidthTop != 0)
  +		  addLine(rx, ry, rx + w, ry, 
  +				area.borderWidthTop,  
  +				new PDFColor(area.borderColorTop));
  +		if (area.borderWidthLeft != 0)
  +		  addLine(rx, ry, rx, ry - h, 
  +				area.borderWidthLeft,  
  +				new PDFColor(area.borderColorLeft));
  +		if (area.borderWidthRight != 0)
  +		  addLine(rx + w, ry, rx + w, ry - h, 
  +				area.borderWidthRight,	
  +				new PDFColor(area.borderColorRight));
  +		if (area.borderWidthBottom != 0)
  +		  addLine(rx, ry - h, rx + w, ry - h, 
  +				area.borderWidthBottom,  
  +				new PDFColor(area.borderColorBottom));
  +
  +	} 
  +   
  +
  +	/**
  +	 * render block area to PDF
  +	 *
  +	 * @param area the block area to render
  +	 */
  +	public void renderBlockArea(BlockArea area) {
  +		doFrame(area);
  +	Enumeration e = area.getChildren().elements();
  +	while (e.hasMoreElements()) {
  +		Box b = (Box) e.nextElement();
  +		b.render(this);
  +	}
  +	}
  +
  +	/**
  +	 * render display space to PDF
  +	 *
  +	 * @param space the display space to render
  +	 */
  +	public void renderDisplaySpace(DisplaySpace space) {
  +	int d = space.getSize();
  +	this.currentYPosition -= d;
  +	}
  +
  +	/**
  +	 * render image area to PDF
  +	 *
  +	 * @param area the image area to render
  +	 */
  +	public void renderImageArea(ImageArea area) {
  +	// adapted from contribution by BoBoGi
  +	int x = this.currentAreaContainerXPosition +
  +		area.getXOffset();
  +	int y = this.currentYPosition;
  +	int w = area.getContentWidth();
  +	int h = area.getHeight();
  +
  +	this.currentYPosition -= h;
  +
  +	FopImage img = area.getImage();
  +
  +	int xObjectNum = this.pdfDoc.addImage(img);
  +
  +	currentStream.add("ET\nq\n" + (img.getWidth()/1000f) + " 0 0 " +
  +			  (img.getHeight()/1000f) + " " + 
  +			  ((x + img.getX())/1000f) + " " + 
  +			  (((y - h) - img.getY())/1000f) + " cm\n" +
  +			  "/Im" + xObjectNum + " Do\nQ\nBT\n"); 
  +	}
  +	
  +	/**
  +	 * render SVG area to PDF
  +	 *
  +	 * @param area the SVG area to render
  +	 */
  +	public void renderSVGArea(SVGArea area) {
  +	int x = this.currentAreaContainerXPosition;
  +	int y = this.currentYPosition;
  +	int w = area.getContentWidth();
  +	int h = area.getHeight();
  +	this.currentYPosition -= h;
  +	Enumeration e = area.getChildren().elements();
  +	while (e.hasMoreElements()) {
  +		Object o = e.nextElement();
  +		if (o instanceof RectGraphic) {
  +		int rx = ((RectGraphic)o).x;
  +		int ry = ((RectGraphic)o).y;
  +		int rw = ((RectGraphic)o).width;
  +		int rh = ((RectGraphic)o).height;
  +		addRect(x+rx,y-ry,rw,-rh,new PDFColor(0,0,0));
  +		} else if (o instanceof LineGraphic) {
  +		int x1 = ((LineGraphic)o).x1;
  +		int y1 = ((LineGraphic)o).y1;
  +		int x2 = ((LineGraphic)o).x2;
  +		int y2 = ((LineGraphic)o).y2;
  +		addLine(x+x1,y-y1,x+x2,y-y2,0,new PDFColor(0,0,0));
  +		} else if (o instanceof TextGraphic) {
  +		int tx = ((TextGraphic)o).x;
  +		int ty = ((TextGraphic)o).y;
  +		String s = ((TextGraphic)o).s;
  +		currentStream.add("1 0 0 1 "
  +				  + ((x+tx)/1000f) + " "
  +				  + ((y-ty)/1000f) + " Tm " 
  +				  + "(" + s + ") Tj\n");
  +		}
  +	}
  +	}
  +
  +	/**
  +	 * render inline area to PDF
  +	 *
  +	 * @param area inline area to render
  +	 */
  +	public void renderInlineArea(InlineArea area) {
  +	char ch;
  +	StringBuffer pdf = new StringBuffer();
  +		
  +	String name = area.getFontState().getFontName();
  +	int size = area.getFontState().getFontSize();
  +	
  +	PDFColor theAreaColor = new PDFColor(
  +				(double)area.getRed(),
  +				(double)area.getGreen(),
  +				(double)area.getBlue()  );
  +		
  +	if ((!name.equals(this.currentFontName))
  +		|| (size != this.currentFontSize)) {
  +		this.currentFontName = name;
  +		this.currentFontSize = size;
  +		pdf = pdf.append("/" + name + " " + (size/1000) + " Tf\n");
  +	}
  +
  +	//if (theAreaColor.isEquivalent(this.currentFill)) {
  +		this.currentFill = theAreaColor;
  +		
  +		pdf = pdf.append(this.currentFill.getColorSpaceOut(true));
  +	//}
  +		
  +	int rx = this.currentXPosition;
  +	int bl = this.currentYPosition;
  +
  +	pdf = pdf.append("1 0 0 1 "
  +			 +(rx/1000f) + " " + (bl/1000f)
  +			 + " Tm (");
  +
  +	String s = area.getText();
  +	int l = s.length();
  +
  +	for (int i=0; i < l; i++) {
  +		ch = s.charAt(i);
  +		if (ch > 127) {
  +		pdf = pdf.append("\\");
  +		pdf = pdf.append(Integer.toOctalString((int)ch));
  +		} else {
  +		switch (ch) {
  +		case '('  : pdf = pdf.append("\\("); break;
  +		case ')'  : pdf = pdf.append("\\)"); break;
  +		case '\\' : pdf = pdf.append("\\\\"); break;
  +		default   : pdf = pdf.append(ch); break;
  +		}
  +		}
  +	}
  +	pdf = pdf.append(") Tj\n");
  +
  +	currentStream.add(pdf.toString());
  +
  +	this.currentXPosition += area.getContentWidth();
  +	}
  +
  +	/**
  +	 * render inline space to PDF
  +	 *
  +	 * @param space space to render
  +	 */
  +	public void renderInlineSpace(InlineSpace space) {
  +	this.currentXPosition += space.getSize();
  +	}
  +
  +	/**
  +	 * render line area to PDF
  +	 *
  +	 * @param area area to render
  +	 */
  +	public void renderLineArea(LineArea area) {
  +	int rx = this.currentAreaContainerXPosition
  +		+ area.getStartIndent();
  +	int ry = this.currentYPosition;
  +	int w = area.getContentWidth();
  +	int h = area.getHeight();
  +
  +	this.currentYPosition -= area.getPlacementOffset();
  +	this.currentXPosition = rx;
  +
  +	int bl = this.currentYPosition;
  +
  +	Enumeration e = area.getChildren().elements();
  +	while (e.hasMoreElements()) {
  +		Box b = (Box) e.nextElement();
  +		b.render(this);
  +	}
  +
  +	this.currentYPosition = ry-h;
  +	}
  +
  +	/**
  +	 * render page into PDF
  +	 *
  +	 * @param page page to render
  +	 */
  +	public void renderPage(Page page) {
  +	AreaContainer body, before, after;
  +	  
  +	currentStream = this.pdfDoc.makeStream();
  +	body = page.getBody();
  +	before = page.getBefore();
  +	after = page.getAfter();
  +
  +	this.currentFontName = "";
  +	this.currentFontSize = 0;
  +
  +	currentStream.add("BT\n");
  +	renderAreaContainer(body);
  +
  +	if (before != null) {
  +		renderAreaContainer(before);
  +	}
  +
  +	if (after != null) {
  +		renderAreaContainer(after);
  +	}
  +	
  +	currentStream.add("ET\n");
  +
  +	currentPage = this.pdfDoc.makePage(this.pdfResources, currentStream,
  +				 page.getWidth()/1000,
  +				 page.getHeight()/1000);
  +
  +	if (page.hasLinks()) {
  +		currentAnnotList = this.pdfDoc.makeAnnotList();
  +		currentPage.setAnnotList(currentAnnotList);
  +
  +		Enumeration e = page.getLinkSets().elements();
  +		while (e.hasMoreElements()) {
  +		LinkSet linkSet = (LinkSet) e.nextElement();
  +
  +		linkSet.align();
  +		String dest = linkSet.getDest();
  +		Enumeration f = linkSet.getRects().elements();
  +		while (f.hasMoreElements()) {
  +			LinkedRectangle lrect = (LinkedRectangle) f.nextElement();
  +			currentAnnotList.addLink(
  +				this.pdfDoc.makeLink(lrect.getRectangle(), dest));
  +		}
  +		}
  +	} else {
  +		// just to be on the safe side
  +		currentAnnotList = null;
  +	}
  +	}
  +
  +	/**
  +	 * render rule area into PDF
  +	 *
  +	 * @param area area to render
  +	 */
  +	public void renderRuleArea(RuleArea area) {
  +	int rx = this.currentAreaContainerXPosition
  +		+ area.getStartIndent();
  +	int ry = this.currentYPosition;
  +	int w = area.getContentWidth();
  +	int h = area.getHeight();
  +	int th = area.getRuleThickness();
  +	
  +	addLine(rx, ry, rx+w, ry, th, new PDFColor(area.getRed(), area.getGreen(),area.getBlue()));
  +	}
  +
  +	/**
  +	 * set up the font info
  +	 *
  +	 * @param fontInfo font info to set up
  +	 */
  +	public void setupFontInfo(FontInfo fontInfo) {
  +	FontSetup.setup(fontInfo);
  +	FontSetup.addToResources(this.pdfDoc, fontInfo);
  +	}
  +}
  +