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 Summary

      Fields 
      Modifier and Type Field Description
      private int alpha
      The most recent alpha transparency value (in the range 0 to 255).
      private float alphaFactor  
      private java.io.ByteArrayOutputStream content
      The stream content.
      private java.awt.Font font
      The most recent font applied.
      private java.text.DecimalFormat geometryFormat
      The decimal formatter for coordinates of geometrical shapes.
      private Page page
      The page the graphics stream belongs to.
      private java.awt.geom.AffineTransform prevTransInv  
      private java.text.DecimalFormat transformFormat
      The decimal formatter for transform matrices.
    • Constructor Summary

      Constructors 
      Constructor Description
      GraphicsStream​(int number, Page page)
      Creates a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addContent​(java.lang.String s)  
      private void applyAlpha​(int alpha)
      Applies the alpha transparency.
      void applyClip​(java.awt.Shape clip)
      Applies the specified clip to the current clip.
      void applyComposite​(java.awt.AlphaComposite alphaComp)
      Applies the specified alpha composite.
      void applyFillColor​(java.awt.Color c)
      Applies a color for filling.
      void applyFillGradient​(java.awt.GradientPaint gp)
      Applies a GradientPaint for filling.
      void applyFillGradient​(java.awt.RadialGradientPaint rgp)
      Applies a RadialGradientPaint for filling.
      void applyFont​(java.awt.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)).
      void applyStroke​(java.awt.Stroke s)
      Applies a stroke.
      void applyStrokeColor​(java.awt.Color c)
      Applies a color for stroking.
      void applyStrokeGradient​(java.awt.GradientPaint gp)
      Applies a GradientPaint for stroking.
      void applyStrokeGradient​(java.awt.RadialGradientPaint rgp)
      Applies a RadialGradientPaint for stroking.
      private void applyTextTransform​(java.awt.geom.AffineTransform t)
      Applies a text transform.
      void applyTransform​(java.awt.geom.AffineTransform t)
      Applies a graphics transform.
      void drawImage​(java.awt.Image img, int x, int y, int w, int h)
      Draws the specified image into the rectangle (x, y, w, h).
      void drawLine​(java.awt.geom.Line2D line)
      Draws the specified line.
      void drawPath2D​(java.awt.geom.Path2D path)
      Draws the specified path.
      void drawString​(java.lang.String text, float x, float y)
      Draws a string at the specified location.
      void fillPath2D​(java.awt.geom.Path2D path)
      Fills the specified path.
      private java.lang.String geomDP​(double d)  
      private java.lang.String getPDFPath​(java.awt.geom.Path2D path)
      A utility method to convert a Path2D instance to a PDF path string.
      byte[] getRawStreamData()
      Returns the raw data for the stream.
      void popGraphicsState()
      Pops the graphics state that was previously pushed onto the stack.
      void pushGraphicsState()
      Pushes the current graphics state onto a stack for later retrieval.
      void setTransform​(java.awt.geom.AffineTransform t)
      Sets the transform.
      private java.lang.String transformDP​(double d)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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 java.io.ByteArrayOutputStream content
        The stream content.
      • font

        private java.awt.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 java.awt.geom.AffineTransform prevTransInv
      • geometryFormat

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

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

        private float alphaFactor
    • Constructor Detail

      • 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 Detail

      • addContent

        private void addContent​(java.lang.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​(java.awt.geom.AffineTransform t)
        Applies a graphics transform.
        Parameters:
        t - the transform (null not permitted).
      • setTransform

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

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

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

        public void applyStroke​(java.awt.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​(java.awt.Color c)
        Applies a color for stroking.
        Parameters:
        c - the color (null not permitted).
      • applyFillColor

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

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

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

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

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

        public void applyComposite​(java.awt.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 java.lang.String geomDP​(double d)
      • transformDP

        private java.lang.String transformDP​(double d)
      • drawLine

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

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

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

        public void applyFont​(java.awt.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​(java.lang.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​(java.awt.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 java.lang.String getPDFPath​(java.awt.geom.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.