Class Barcode1D

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ALIGN_CENTER
      Constant that defines center alignment.
      static int ALIGN_LEFT
      Constant that defines left alignment.
      static int ALIGN_RIGHT
      Constant that defines right alignment.
      protected java.lang.String altText
      The alternate text to be used, if present.
      protected float barHeight
      The height of the bars.
      protected float baseline
      If positive, the text distance under the bars.
      protected boolean checksumText
      Shows the generated checksum in the the text.
      protected java.lang.String code
      The code to generate.
      protected int codeType
      The code type.
      protected java.awt.Color DEFAULT_BAR_BACKGROUND_COLOR
      The default color to draw if a bar is not present.
      protected java.awt.Color DEFAULT_BAR_FOREGROUND_COLOR
      The default color to draw if a bar is present.
      protected PdfDocument document  
      protected boolean extended
      Generates extended barcode 39.
      protected PdfFont font
      The text font.
      protected boolean generateChecksum
      The optional checksum generation.
      protected boolean guardBars
      Show the guard bars for barcode EAN.
      protected float inkSpreading
      The ink spreading.
      protected float n
      The bar multiplier for wide bars or the distance between bars for Postnet and Planet.
      protected float size
      The size of the text or the height of the shorter bar in Postnet.
      protected boolean startStopText
      Show the start and stop character '*' in the text for the barcode 39 or 'ABCD' for codabar.
      protected int textAlignment
      The text alignment.
      protected float x
      The minimum bar width.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract java.awt.Image createAwtImage​(java.awt.Color foreground, java.awt.Color background)
      Creates a java.awt.Image.
      PdfFormXObject createFormXObject​(Color barColor, Color textColor, PdfDocument document)
      Creates a PdfFormXObject with the barcode.
      PdfFormXObject createFormXObject​(PdfDocument document)
      Creates a PdfFormXObject with the barcode.
      void fitWidth​(float width)
      Make the barcode occupy the specified width.
      java.lang.String getAltText()
      Gets the alternate text.
      abstract Rectangle getBarcodeSize()
      Gets the maximum area that the barcode and the text, if any, will occupy.
      float getBarHeight()
      Gets the height of the bars.
      float getBaseline()
      Gets the text baseline.
      java.lang.String getCode()
      Gets the code to generate.
      int getCodeType()
      Gets the code type.
      protected float getDescender()
      Gets the descender value of the font.
      PdfFont getFont()
      Gets the text font.
      float getInkSpreading()
      Gets the amount of ink spreading.
      float getN()
      Gets the bar multiplier for wide bars.
      float getSize()
      Gets the size of the text.
      int getTextAlignment()
      Gets the text alignment.
      float getX()
      Gets the minimum bar width.
      boolean isChecksumText()
      Gets the property to show the generated checksum in the the text.
      boolean isExtended()
      Gets the property to generate extended barcode 39.
      boolean isGenerateChecksum()
      Gets the optional checksum generation.
      boolean isGuardBars()
      Gets the property to show the guard bars for barcode EAN.
      boolean isStartStopText()
      Sets the property to show the start and stop character '*' in the text for the barcode 39.
      abstract Rectangle placeBarcode​(PdfCanvas canvas, Color barColor, Color textColor)
      Places the barcode in a PdfCanvas.
      void setAltText​(java.lang.String altText)
      Sets the alternate text.
      void setBarHeight​(float barHeight)
      Sets the height of the bars.
      void setBaseline​(float baseline)
      Sets the text baseline.
      void setChecksumText​(boolean checksumText)
      Sets the property to show the generated checksum in the the text.
      void setCode​(java.lang.String code)
      Sets the code to generate.
      void setCodeType​(int codeType)
      Sets the code type.
      void setExtended​(boolean extended)
      Sets the property to generate extended barcode 39.
      void setFont​(PdfFont font)
      Sets the text font.
      void setGenerateChecksum​(boolean generateChecksum)
      Setter for property generateChecksum.
      void setGuardBars​(boolean guardBars)
      Sets the property to show the guard bars for barcode EAN.
      void setInkSpreading​(float inkSpreading)
      Sets the amount of ink spreading.
      void setN​(float n)
      Sets the bar multiplier for wide bars.
      void setSize​(float size)
      Sets the size of the text.
      void setStartStopText​(boolean startStopText)
      Gets the property to show the start and stop character '*' in the text for the barcode 39.
      void setTextAlignment​(int textAlignment)
      Sets the text alignment.
      void setX​(float x)
      Sets the minimum bar width.
      • Methods inherited from class java.lang.Object

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

      • ALIGN_LEFT

        public static final int ALIGN_LEFT
        Constant that defines left alignment.
        See Also:
        Constant Field Values
      • ALIGN_RIGHT

        public static final int ALIGN_RIGHT
        Constant that defines right alignment.
        See Also:
        Constant Field Values
      • ALIGN_CENTER

        public static final int ALIGN_CENTER
        Constant that defines center alignment.
        See Also:
        Constant Field Values
      • DEFAULT_BAR_FOREGROUND_COLOR

        protected final java.awt.Color DEFAULT_BAR_FOREGROUND_COLOR
        The default color to draw if a bar is present.
      • DEFAULT_BAR_BACKGROUND_COLOR

        protected final java.awt.Color DEFAULT_BAR_BACKGROUND_COLOR
        The default color to draw if a bar is not present.
      • x

        protected float x
        The minimum bar width.
      • n

        protected float n
        The bar multiplier for wide bars or the distance between bars for Postnet and Planet.
      • font

        protected PdfFont font
        The text font. null if no text.
      • size

        protected float size
        The size of the text or the height of the shorter bar in Postnet.
      • baseline

        protected float baseline
        If positive, the text distance under the bars. If zero or negative, the text distance above the bars.
      • barHeight

        protected float barHeight
        The height of the bars.
      • textAlignment

        protected int textAlignment
        The text alignment.
      • generateChecksum

        protected boolean generateChecksum
        The optional checksum generation.
      • checksumText

        protected boolean checksumText
        Shows the generated checksum in the the text.
      • startStopText

        protected boolean startStopText
        Show the start and stop character '*' in the text for the barcode 39 or 'ABCD' for codabar.
      • extended

        protected boolean extended
        Generates extended barcode 39.
      • code

        protected java.lang.String code
        The code to generate.
      • guardBars

        protected boolean guardBars
        Show the guard bars for barcode EAN.
      • codeType

        protected int codeType
        The code type.
      • inkSpreading

        protected float inkSpreading
        The ink spreading.
      • altText

        protected java.lang.String altText
        The alternate text to be used, if present.
    • Constructor Detail

      • Barcode1D

        protected Barcode1D​(PdfDocument document)
        Creates new Barcode1D instance.
        Parameters:
        document - The document
    • Method Detail

      • getX

        public float getX()
        Gets the minimum bar width.
        Returns:
        the minimum bar width
      • setX

        public void setX​(float x)
        Sets the minimum bar width.
        Parameters:
        x - the minimum bar width
      • getN

        public float getN()
        Gets the bar multiplier for wide bars.
        Returns:
        the bar multiplier for wide bars
      • setN

        public void setN​(float n)
        Sets the bar multiplier for wide bars.
        Parameters:
        n - the bar multiplier for wide bars
      • getFont

        public PdfFont getFont()
        Gets the text font. null if no text.
        Returns:
        the text font. null if no text
      • setFont

        public void setFont​(PdfFont font)
        Sets the text font.
        Parameters:
        font - the text font. Set to null to suppress any text
      • getSize

        public float getSize()
        Gets the size of the text.
        Returns:
        the size
      • setSize

        public void setSize​(float size)
        Sets the size of the text.
        Parameters:
        size - the size of the text
      • getBaseline

        public float getBaseline()
        Gets the text baseline. If positive, the text distance under the bars. If zero or negative, the text distance above the bars.
        Returns:
        the baseline.
      • setBaseline

        public void setBaseline​(float baseline)
        Sets the text baseline. If positive, the text distance under the bars. If zero or negative, the text distance above the bars.
        Parameters:
        baseline - the baseline.
      • getBarHeight

        public float getBarHeight()
        Gets the height of the bars.
        Returns:
        the height of the bars
      • setBarHeight

        public void setBarHeight​(float barHeight)
        Sets the height of the bars.
        Parameters:
        barHeight - the height of the bars
      • getTextAlignment

        public int getTextAlignment()
        Gets the text alignment.
        Returns:
        the text alignment
      • setTextAlignment

        public void setTextAlignment​(int textAlignment)
        Sets the text alignment.
        Parameters:
        textAlignment - the text alignment
      • isGenerateChecksum

        public boolean isGenerateChecksum()
        Gets the optional checksum generation.
        Returns:
        the optional checksum generation
      • setGenerateChecksum

        public void setGenerateChecksum​(boolean generateChecksum)
        Setter for property generateChecksum.
        Parameters:
        generateChecksum - New value of property generateChecksum.
      • isChecksumText

        public boolean isChecksumText()
        Gets the property to show the generated checksum in the the text.
        Returns:
        value of property checksumText
      • setChecksumText

        public void setChecksumText​(boolean checksumText)
        Sets the property to show the generated checksum in the the text.
        Parameters:
        checksumText - new value of property checksumText
      • isStartStopText

        public boolean isStartStopText()
        Sets the property to show the start and stop character '*' in the text for the barcode 39.
        Returns:
        value of property startStopText
      • setStartStopText

        public void setStartStopText​(boolean startStopText)
        Gets the property to show the start and stop character '*' in the text for the barcode 39.
        Parameters:
        startStopText - new value of property startStopText
      • isExtended

        public boolean isExtended()
        Gets the property to generate extended barcode 39.
        Returns:
        value of property extended.
      • setExtended

        public void setExtended​(boolean extended)
        Sets the property to generate extended barcode 39.
        Parameters:
        extended - new value of property extended
      • getCode

        public java.lang.String getCode()
        Gets the code to generate.
        Returns:
        the code to generate
      • setCode

        public void setCode​(java.lang.String code)
        Sets the code to generate.
        Parameters:
        code - the code to generate
      • isGuardBars

        public boolean isGuardBars()
        Gets the property to show the guard bars for barcode EAN.
        Returns:
        value of property guardBars
      • setGuardBars

        public void setGuardBars​(boolean guardBars)
        Sets the property to show the guard bars for barcode EAN.
        Parameters:
        guardBars - new value of property guardBars
      • getCodeType

        public int getCodeType()
        Gets the code type.
        Returns:
        the code type
      • setCodeType

        public void setCodeType​(int codeType)
        Sets the code type.
        Parameters:
        codeType - the code type
      • getBarcodeSize

        public abstract Rectangle getBarcodeSize()
        Gets the maximum area that the barcode and the text, if any, will occupy. The lower left corner is always (0, 0).
        Returns:
        the size the barcode occupies.
      • placeBarcode

        public abstract Rectangle placeBarcode​(PdfCanvas canvas,
                                               Color barColor,
                                               Color textColor)
        Places the barcode in a PdfCanvas. The barcode is always placed at coordinates (0, 0). Use the translation matrix to move it elsewhere.

        The bars and text are written in the following colors:

        barColor textColor Result
        null null bars and text painted with current fill color
        barColor null bars and text painted with barColor
        null textColor bars painted with current color
        text painted with textColor
        barColor textColor bars painted with barColor
        text painted with textColor
        Parameters:
        canvas - the PdfCanvas where the barcode will be placed
        barColor - the color of the bars. It can be null
        textColor - the color of the text. It can be null
        Returns:
        the dimensions the barcode occupies
      • getInkSpreading

        public float getInkSpreading()
        Gets the amount of ink spreading.
        Returns:
        the ink spreading
      • setInkSpreading

        public void setInkSpreading​(float inkSpreading)
        Sets the amount of ink spreading. This value will be subtracted to the width of each bar. The actual value will depend on the ink and the printing medium.
        Parameters:
        inkSpreading - the ink spreading
      • getAltText

        public java.lang.String getAltText()
        Gets the alternate text.
        Returns:
        the alternate text
      • setAltText

        public void setAltText​(java.lang.String altText)
        Sets the alternate text. If present, this text will be used instead of the text derived from the supplied code.
        Parameters:
        altText - the alternate text
      • createAwtImage

        public abstract java.awt.Image createAwtImage​(java.awt.Color foreground,
                                                      java.awt.Color background)
        Creates a java.awt.Image. This image only contains the bars without any text.
        Parameters:
        foreground - the color of the bars. If null defaults to DEFAULT_BAR_FOREGROUND_COLOR
        background - the color of the background. If null defaults to DEFAULT_BAR_BACKGROUND_COLOR
        Returns:
        the image
      • fitWidth

        public void fitWidth​(float width)
        Make the barcode occupy the specified width. Usually this is achieved by adjusting bar widths.
        Parameters:
        width - The width
      • getDescender

        protected float getDescender()
        Gets the descender value of the font.
        Returns:
        the descender value of the font