gnujpdf reformat

This commit is contained in:
Jindra Petřík
2021-02-20 10:01:49 +01:00
parent 7eb151055b
commit df913281dc
24 changed files with 3587 additions and 3574 deletions

View File

@@ -30,148 +30,145 @@ import java.util.*;
* @author Eric Z. Beard, ericzbeard@hotmail.com
* @version $Revision: 1.3 $, $Date: 2007/09/22 12:48:16 $
*/
public abstract class PDFObject implements Serializable
{
public abstract class PDFObject implements Serializable {
/*
/*
* NOTE: The original class is the work of Peter T. Mount, who released it
* in the uk.org.retep.pdf package. It was modified by Eric Z. Beard as
* follows:
* The package name was changed to gnu.pdf.
* The formatting was changed a little bit.
* It is still licensed under the LGPL.
*/
*/
/**
* This is the object's PDF Type
*/
private String type;
/**
* This is the object's PDF Type
*/
private String type;
/**
* This is the unique serial number for this object.
*/
protected int objser;
/**
* This allows any PDF object to refer to the document being constructed.
*/
protected PDFDocument pdfDocument;
/**
* This is usually called by extensors to this class, and sets the
* PDF Object Type
* @param type the PDF Object Type
*/
public PDFObject(String type)
{
this.type = type;
}
/**
* Returns the PDF Type of this object
* @return The PDF Type of this object
*/
public String getType()
{
return type;
}
/**
* Returns the unique serial number of this object.
* @return Unique serial number of this object.
*/
public final int getSerialID()
{
return objser;
}
/**
* Returns the PDF document this object belongs to.
* @return PDF containing this object
*/
public final PDFDocument getPDFDocument()
{
return pdfDocument;
}
/**
* <p>Writes the object to the output stream.
* This method must be overidden.</p>
*
* <p><b>Note:</b> It should not write any other objects, even if they are
* it's Kids, as they will be written by the calling routine.</p>
*
* @param os OutputStream to send the object to
* @exception IOException on error
*/
public abstract void write(OutputStream os) throws IOException;
/**
* The write method should call this before writing anything to the
* OutputStream. This will send the standard header for each object.
*
* <p>Note: There are a few rare cases where this method is not called.
*
* @param os OutputStream to write to
* @exception IOException on error
*/
public final void writeStart(OutputStream os) throws IOException
{
os.write(Integer.toString(objser).getBytes());
os.write(" 0 obj\n<<\n".getBytes());
if(type!=null) {
os.write("/Type ".getBytes());
os.write(type.getBytes());
os.write("\n".getBytes());
/**
* This is the unique serial number for this object.
*/
protected int objser;
/**
* This allows any PDF object to refer to the document being constructed.
*/
protected PDFDocument pdfDocument;
/**
* This is usually called by extensors to this class, and sets the PDF
* Object Type
*
* @param type the PDF Object Type
*/
public PDFObject(String type) {
this.type = type;
}
}
/**
* The write method should call this after writing anything to the
* OutputStream. This will send the standard footer for each object.
*
* <p>Note: There are a few rare cases where this method is not called.
*
* @param os OutputStream to write to
* @exception IOException on error
*/
public final void writeEnd(OutputStream os) throws IOException
{
os.write(">>\nendobj\n".getBytes());
}
/**
* Returns the unique serial number in PDF format
* @return the serial number in PDF format
*/
public String toString()
{
return ""+objser+" 0 R";
}
/**
* This utility method returns a String containing an array definition
* based on a Vector containing PDFObjects
* @param v Vector containing PDFObjects
* @return String containing a PDF array
*/
public static String toArray(Vector<? extends PDFObject> v)
{
if(v.size()==0)
return "";
StringBuffer b = new StringBuffer();
String bs = "[";
for(PDFObject x : v) {
b.append(bs);
b.append(x.toString());
bs = " ";
/**
* Returns the PDF Type of this object
*
* @return The PDF Type of this object
*/
public String getType() {
return type;
}
/**
* Returns the unique serial number of this object.
*
* @return Unique serial number of this object.
*/
public final int getSerialID() {
return objser;
}
/**
* Returns the PDF document this object belongs to.
*
* @return PDF containing this object
*/
public final PDFDocument getPDFDocument() {
return pdfDocument;
}
/**
* <p>
* Writes the object to the output stream. This method must be
* overidden.</p>
*
* <p>
* <b>Note:</b> It should not write any other objects, even if they are it's
* Kids, as they will be written by the calling routine.</p>
*
* @param os OutputStream to send the object to
* @exception IOException on error
*/
public abstract void write(OutputStream os) throws IOException;
/**
* The write method should call this before writing anything to the
* OutputStream. This will send the standard header for each object.
*
* <p>
* Note: There are a few rare cases where this method is not called.
*
* @param os OutputStream to write to
* @exception IOException on error
*/
public final void writeStart(OutputStream os) throws IOException {
os.write(Integer.toString(objser).getBytes());
os.write(" 0 obj\n<<\n".getBytes());
if (type != null) {
os.write("/Type ".getBytes());
os.write(type.getBytes());
os.write("\n".getBytes());
}
}
/**
* The write method should call this after writing anything to the
* OutputStream. This will send the standard footer for each object.
*
* <p>
* Note: There are a few rare cases where this method is not called.
*
* @param os OutputStream to write to
* @exception IOException on error
*/
public final void writeEnd(OutputStream os) throws IOException {
os.write(">>\nendobj\n".getBytes());
}
/**
* Returns the unique serial number in PDF format
*
* @return the serial number in PDF format
*/
public String toString() {
return "" + objser + " 0 R";
}
/**
* This utility method returns a String containing an array definition based
* on a Vector containing PDFObjects
*
* @param v Vector containing PDFObjects
* @return String containing a PDF array
*/
public static String toArray(Vector<? extends PDFObject> v) {
if (v.size() == 0) {
return "";
}
StringBuffer b = new StringBuffer();
String bs = "[";
for (PDFObject x : v) {
b.append(bs);
b.append(x.toString());
bs = " ";
}
b.append("]");
return b.toString();
}
b.append("]");
return b.toString();
}
}