Class GraphicsStream


public class GraphicsStream extends Stream
A Stream that contains graphics for the PDF document that can be generated via the PDFGraphics2D class. The Page class will create a GraphicsStream instance to represent its content. You won't normally interact directly with this class, it is intended that the PDFGraphics2D class drives the calls to the methods of this class.
  • Field Details

    • page

      private Page page
      The page the graphics stream belongs to. We need this reference to our "parent" so that we can access fonts in the document.
    • content

      private ByteArrayOutputStream content
      The stream content.
    • font

      private Font font
      The most recent font applied.
    • alpha

      private int alpha
      The most recent alpha transparency value (in the range 0 to 255).
    • prevTransInv

      private AffineTransform prevTransInv
    • geometryFormat

      private DecimalFormat geometryFormat
      The decimal formatter for coordinates of geometrical shapes.
    • transformFormat

      private DecimalFormat transformFormat
      The decimal formatter for transform matrices.
    • alphaFactor

      private float alphaFactor
  • Constructor Details

    • GraphicsStream

      public GraphicsStream(int number, Page page)
      Creates a new instance.
      Parameters:
      number - the PDF object number.
      page - the parent page (null not permitted).
  • Method Details

    • addContent

      private void addContent(String s)
    • pushGraphicsState

      public void pushGraphicsState()
      Pushes the current graphics state onto a stack for later retrieval.
    • popGraphicsState

      public void popGraphicsState()
      Pops the graphics state that was previously pushed onto the stack.
    • applyTransform

      public void applyTransform(AffineTransform t)
      Applies a graphics transform.
      Parameters:
      t - the transform (null not permitted).
    • setTransform

      public void setTransform(AffineTransform t)
      Sets the transform.
      Parameters:
      t - the transform (null not permitted).
    • applyTextTransform

      private void applyTextTransform(AffineTransform t)
      Applies a text transform.
      Parameters:
      t - the transform (null not permitted).
    • applyClip

      public void applyClip(Shape clip)
      Applies the specified clip to the current clip.
      Parameters:
      clip - the clip (null not permitted).
    • applyStroke

      public void applyStroke(Stroke s)
      Applies a stroke. If the stroke is not an instance of BasicStroke this method will do nothing.
      Parameters:
      s - the stroke.
    • applyStrokeColor

      public void applyStrokeColor(Color c)
      Applies a color for stroking.
      Parameters:
      c - the color (null not permitted).
    • applyFillColor

      public void applyFillColor(Color c)
      Applies a color for filling.
      Parameters:
      c - the color (null not permitted).
    • applyStrokeGradient

      public void applyStrokeGradient(GradientPaint gp)
      Applies a GradientPaint for stroking.
      Parameters:
      gp - the gradient paint (null not permitted).
    • applyStrokeGradient

      public void applyStrokeGradient(RadialGradientPaint rgp)
      Applies a RadialGradientPaint for stroking.
      Parameters:
      rgp - the gradient paint (null not permitted).
    • applyFillGradient

      public void applyFillGradient(GradientPaint gp)
      Applies a GradientPaint for filling.
      Parameters:
      gp - the gradient paint (null not permitted).
    • applyFillGradient

      public void applyFillGradient(RadialGradientPaint rgp)
      Applies a RadialGradientPaint for filling.
      Parameters:
      rgp - the gradient paint (null not permitted).
    • applyComposite

      public void applyComposite(AlphaComposite alphaComp)
      Applies the specified alpha composite.
      Parameters:
      alphaComp - the alpha composite (null permitted).
    • applyAlpha

      private void applyAlpha(int alpha)
      Applies the alpha transparency.
      Parameters:
      alpha - the new alpha value (in the range 0 to 255).
    • geomDP

      private String geomDP(double d)
    • transformDP

      private String transformDP(double d)
    • drawLine

      public void drawLine(Line2D line)
      Draws the specified line.
      Parameters:
      line - the line (null not permitted).
    • drawPath2D

      public void drawPath2D(Path2D path)
      Draws the specified path.
      Parameters:
      path - the path (null not permitted).
    • fillPath2D

      public void fillPath2D(Path2D path)
      Fills the specified path.
      Parameters:
      path - the path (null not permitted).
    • applyFont

      public void applyFont(Font font)
      Applies the specified font (in fact, no change is made to the stream until the next call to drawString(java.lang.String, float, float)).
      Parameters:
      font - the font.
    • drawString

      public void drawString(String text, float x, float y)
      Draws a string at the specified location.
      Parameters:
      text - the text.
      x - the x-coordinate.
      y - the y-coordinate.
    • drawImage

      public void drawImage(Image img, int x, int y, int w, int h)
      Draws the specified image into the rectangle (x, y, w, h).
      Parameters:
      img - the image.
      x - the x-coordinate of the destination.
      y - the y-coordinate of the destination.
      w - the width of the destination.
      h - the height of the destination.
    • getPDFPath

      private String getPDFPath(Path2D path)
      A utility method to convert a Path2D instance to a PDF path string.
      Parameters:
      path - the path (null not permitted).
      Returns:
      The string.
    • getRawStreamData

      public byte[] getRawStreamData()
      Description copied from class: Stream
      Returns the raw data for the stream.
      Specified by:
      getRawStreamData in class Stream
      Returns:
      The raw data for the stream.