org.foray.pdf.object
Class PDFXObject

java.lang.Object
  extended by org.foray.pdf.object.PDFObject
      extended by org.foray.pdf.object.PDFStream
          extended by org.foray.pdf.object.PDFXObject
Direct Known Subclasses:
PDFXForm, PDFXImage

public abstract class PDFXObject
extends PDFStream

PDF XObject (external object), aka a "named resource". Used to represent 1) bitmap images, 2) form XObjects (reusable sequences of other graphical objects, not to be confused with an interactive form), and 3) PostScript XObjects (whose use is unnecessary and deprecated). An XObject has not only a dictionary but a stream of image data.


Field Summary
 
Fields inherited from class org.foray.pdf.object.PDFObject
EOL, MSG_EOL, XREF_EOL
 
Constructor Summary
protected PDFXObject(PDFDocument doc, org.axsl.graphic.Graphic graphic)
          Create an Xobject instance.
 
Method Summary
protected  void addStreamFilters()
          Adds the normal stream filters used for graphics.
protected  void finalizeStreamContent()
          This method is an explicit opportunity for subclasses to finish writing whatever content may still need to be written to the stream before the dictionary and stream contents are written.
abstract  org.axsl.graphic.Graphic getGraphic()
          Return the encapsulated graphic.
abstract  float getHorizontalScaling(Rectangle2D.Float contentRectangle)
          Returns the horizontal scaling factor that should be used for a specific "Do" for a specific content rectangle.
abstract  float getVerticalScaling(Rectangle2D.Float contentRectangle)
          Returns the vertical scaling factor that should be used for a specific "Do" for a specific content rectangle.
 String getXObjectName()
          Returns the XObject name for this object.
static PDFXObject makeXObject(PDFDocument pdfDoc, org.axsl.graphic.Graphic img, org.axsl.font.FontConsumer fontConsumer, boolean strokeText)
          Factory method that encapsulates a Graphic instance into an appropriate PDFXObject instance.
protected  String specialStreamDictEntries()
          Subclasses return any specialized dictionary entries here, so that they are included when writing the stream dictionary.
protected abstract  String specialXObjectDictEntries()
          Subclasses return any specialized dictionary entries here, so that they are included when writing the stream dictionary.
protected abstract  void xObjectContent()
          Add the content specific to this type of XObject to the content stream.
protected abstract  String xObjectSubtype()
          Returns the subtype for this XObject.
 
Methods inherited from class org.foray.pdf.object.PDFStream
add, addDefaultFilters, addEncryption, addFilter, addFilter, applyFilters, getDataLength, getOutputStream, output, outputStreamData, setData, setOutputStream, toPDF
 
Methods inherited from class org.foray.pdf.object.PDFObject
bufferToByteArray, byteArrayToStream, getCharsPerLine, getGeneration, getLogger, getNumber, getPDFDocument, pdfID, pdfReference, setNumber, stringToByteArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDFXObject

protected PDFXObject(PDFDocument doc,
                     org.axsl.graphic.Graphic graphic)
              throws org.axsl.graphic.GraphicException
Create an Xobject instance.

Parameters:
doc - The parent PDF document.
graphic - The graphic to be encapsulated.
Throws:
org.axsl.graphic.GraphicException - For errors getting the appropriate filter.
Method Detail

makeXObject

public static PDFXObject makeXObject(PDFDocument pdfDoc,
                                     org.axsl.graphic.Graphic img,
                                     org.axsl.font.FontConsumer fontConsumer,
                                     boolean strokeText)
                              throws org.axsl.graphic.GraphicException
Factory method that encapsulates a Graphic instance into an appropriate PDFXObject instance.

Parameters:
pdfDoc - The parent PDF document.
img - The graphic to be encapsulated.
fontConsumer - The font consumer to use for resolving fonts in the SVG.
strokeText - Set to true if text should be stroked, false if it
Returns:
An appropriate PDFXObject instance that encapsulates the input.
Throws:
org.axsl.graphic.GraphicException - For errors getting the appropriate filter.

getXObjectName

public String getXObjectName()
Returns the XObject name for this object.

Returns:
The name by which this XObject is recorded in the XObject subdictionary.

xObjectSubtype

protected abstract String xObjectSubtype()
Returns the subtype for this XObject.

Returns:
The subtype for this XObject.

xObjectContent

protected abstract void xObjectContent()
                                throws org.axsl.pdf.PdfException
Add the content specific to this type of XObject to the content stream.

Throws:
org.axsl.pdf.PdfException - For errors in the graphic or when writing to the stream.

specialXObjectDictEntries

protected abstract String specialXObjectDictEntries()
Subclasses return any specialized dictionary entries here, so that they are included when writing the stream dictionary.

Returns:
The dictonary entries specific to this type of XObject.

addStreamFilters

protected void addStreamFilters()
Adds the normal stream filters used for graphics.


getGraphic

public abstract org.axsl.graphic.Graphic getGraphic()
Return the encapsulated graphic.

Returns:
The graphic.

getHorizontalScaling

public abstract float getHorizontalScaling(Rectangle2D.Float contentRectangle)
Returns the horizontal scaling factor that should be used for a specific "Do" for a specific content rectangle. This is used in transformations that are outside the actual XObject definition, so that the XObject can be reused in other places, using different content rectangles. This abstraction is needed because bitmapped graphics are specified in image space, and XForm graphics (SVG and EPS) are specified in form space, which require radically different scaling mechanisms.

Parameters:
contentRectangle - The content rectangle into which the graphic will be scaled.
Returns:
The horizontal scaling factor that should be applied to this graphic when converting from its native space to user space.

getVerticalScaling

public abstract float getVerticalScaling(Rectangle2D.Float contentRectangle)
Returns the vertical scaling factor that should be used for a specific "Do" for a specific content rectangle. See getHorizontalScaling(java.awt.geom.Rectangle2D.Float) for an explanation of the need for this computation.

Parameters:
contentRectangle - The content rectangle into which the graphic will be scaled.
Returns:
The vertical scaling factor that should be applied to this graphic when converting from its native space to user space.

specialStreamDictEntries

protected String specialStreamDictEntries()
                                   throws org.axsl.pdf.PdfException
Description copied from class: PDFStream
Subclasses return any specialized dictionary entries here, so that they are included when writing the stream dictionary.

Specified by:
specialStreamDictEntries in class PDFStream
Returns:
Any specialized dictionary entries.
Throws:
org.axsl.pdf.PdfException - For errors creating the dictionary entries.

finalizeStreamContent

protected void finalizeStreamContent()
Description copied from class: PDFStream
This method is an explicit opportunity for subclasses to finish writing whatever content may still need to be written to the stream before the dictionary and stream contents are written.

Specified by:
finalizeStreamContent in class PDFStream


Copyright © 2017. All rights reserved.