OneDimensionalCodeWriter (ZXing 3.4.0 API)

com.google.zxing.oned

## Class OneDimensionalCodeWriter

- java.lang.Object
- - com.google.zxing.oned.OneDimensionalCodeWriter

- All Implemented Interfaces:
    Writer
  Direct Known Subclasses:
    CodaBarWriter, Code128Writer, Code39Writer, Code93Writer, ITFWriter, UPCEANWriter

      public abstract class OneDimensionalCodeWriter
      extends Object
      implements Writer

  Encapsulates functionality and implementation that is common to one-dimensional barcodes.

  Author:
    dsbnatut@gmail.com (Kazuki Nishiura)

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `OneDimensionalCodeWriter()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected static int` | `appendPattern(boolean[] target, int pos, int[] pattern, boolean startColor)`
    `protected static void` | `checkNumeric(String contents)`
    `abstract boolean[]` | `encode(String contents)` Encode the contents to boolean array expression of one-dimensional barcode.
    `BitMatrix` | `encode(String contents, BarcodeFormat format, int width, int height)` Encode a barcode using the default settings.
    `BitMatrix` | `encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType,?> hints)` Encode the contents following specified format.
    `int` | `getDefaultMargin()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### OneDimensionalCodeWriter

          public OneDimensionalCodeWriter()

  - ### Method Detail

    - #### encode

          public final BitMatrix encode(String contents,
                                        BarcodeFormat format,
                                        int width,
                                        int height)
                                 throws WriterException

      Description copied from interface: `Writer`
      Encode a barcode using the default settings.
      Specified by:
        `encode` in interface `Writer`
      Parameters:
        `contents` - The contents to encode in the barcode
        `format` - The barcode format to generate
        `width` - The preferred width in pixels
        `height` - The preferred height in pixels
      Returns:
        `BitMatrix` representing encoded barcode image
      Throws:
        `WriterException` - if contents cannot be encoded legally in a format

    - #### encode

          public BitMatrix encode(String contents,
                                  BarcodeFormat format,
                                  int width,
                                  int height,
                                  Map<EncodeHintType,?> hints)
                           throws WriterException

      Encode the contents following specified format. `width` and `height` are required size. This method may return bigger size `BitMatrix` when specified size is too small. The user can set both `width` and `height` to zero to get minimum size barcode. If negative value is set to `width` or `height`, `IllegalArgumentException` is thrown.
      Specified by:
        `encode` in interface `Writer`
      Parameters:
        `contents` - The contents to encode in the barcode
        `format` - The barcode format to generate
        `width` - The preferred width in pixels
        `height` - The preferred height in pixels
        `hints` - Additional parameters to supply to the encoder
      Returns:
        `BitMatrix` representing encoded barcode image
      Throws:
        `WriterException` - if contents cannot be encoded legally in a format

    - #### checkNumeric

          protected static void checkNumeric(String contents)

      Parameters:
        `contents` - string to check for numeric characters
      Throws:
        `IllegalArgumentException` - if input contains characters other than digits 0-9.

    - #### appendPattern

          protected static int appendPattern(boolean[] target,
                                             int pos,
                                             int[] pattern,
                                             boolean startColor)

      Parameters:
        `target` - encode black/white pattern into this array
        `pos` - position to start encoding at in `target`
        `pattern` - lengths of black/white runs to encode
        `startColor` - starting color - false for white, true for black
      Returns:
        the number of elements added to target.

    - #### getDefaultMargin

          public int getDefaultMargin()

    - #### encode

          public abstract boolean[] encode(String contents)

      Encode the contents to boolean array expression of one-dimensional barcode. Start code and end code should be included in result, and side margins should not be included.
      Parameters:
        `contents` - barcode contents to encode
      Returns:
        a `boolean[]` of horizontal pixels (false = white, true = black)

Copyright © 2007–2019. All rights reserved.