⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 barcodepdf417.java

📁 iText是一个能够快速产生PDF文件的java类库。iText的java类对于那些要产生包含文本
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                }
            }
            tot = codeRows * codeColumns;
        }
        if (tot > MAX_DATA_CODEWORDS + 2) {
            tot = getMaxSquare();
        }
        errorLevel = maxPossibleErrorLevel(tot - lenCodewords);
        lenErr = 2 << errorLevel;
        pad = tot - lenErr - lenCodewords;
        cwPtr = lenCodewords;
        while (pad-- != 0)
            codewords[cwPtr++] = TEXT_MODE;
        codewords[0] = lenCodewords = cwPtr;
        calculateErrorCorrection(lenCodewords);
        lenCodewords = tot;
        outPaintCode();
    }

    /** Gets an <CODE>Image</CODE> with the barcode. The image will have to be
     * scaled in the Y direction by <CODE>yHeight</CODE>for the barcode
     * to have the right printing aspect.
     * @return the barcode <CODE>Image</CODE>
     * @throws BadElementException on error
     */    
    public Image getImage() throws BadElementException {
        paintCode();
        byte g4[] = CCITTG4Encoder.compress(outBits, bitColumns, codeRows);
        return Image.getInstance(bitColumns, codeRows, false, Image.CCITTG4, (options & PDF417_INVERT_BITMAP) == 0 ? 0 : Image.CCITT_BLACKIS1, g4, null);
    }

    /** Creates a <CODE>java.awt.Image</CODE>.
     * @param foreground the color of the bars
     * @param background the color of the background
     * @return the image
     */    
    public java.awt.Image createAwtImage(Color foreground, Color background) {
        int f = foreground.getRGB();
        int g = background.getRGB();
        Canvas canvas = new Canvas();

        paintCode();
        int h = (int)yHeight;
        int pix[] = new int[bitColumns * codeRows * h];
        int stride = (bitColumns + 7) / 8;
        int ptr = 0;
        for (int k = 0; k < codeRows; ++k) {
            int p = k * stride;
            for (int j = 0; j < bitColumns; ++j) {
                int b = outBits[p + (j / 8)] & 0xff;
                b <<= j % 8;
                pix[ptr++] = (b & 0x80) == 0 ? g : f;
            }
            for (int j = 1; j < h; ++j) {
                System.arraycopy(pix, ptr - bitColumns, pix, ptr + bitColumns * (j - 1), bitColumns);
            }
            ptr += bitColumns * (h - 1);
        }
        
        java.awt.Image img = canvas.createImage(new MemoryImageSource(bitColumns, codeRows * h, pix, 0, bitColumns));
        return img;
    }
    
    /** Gets the raw image bits of the barcode. The image will have to
     * be scaled in the Y direction by <CODE>yHeight</CODE>.
     * @return The raw barcode image
     */
    public byte[] getOutBits() {
        return this.outBits;
    }
    
    /** Gets the number of X pixels of <CODE>outBits</CODE>.
     * @return the number of X pixels of <CODE>outBits</CODE>
     */
    public int getBitColumns() {
        return this.bitColumns;
    }
    
    /** Gets the number of Y pixels of <CODE>outBits</CODE>.
     * It is also the number of rows in the barcode.
     * @return the number of Y pixels of <CODE>outBits</CODE>
     */
    public int getCodeRows() {
        return this.codeRows;
    }
    
    /** Sets the number of barcode rows. This number may be changed
     * to keep the barcode valid.
     * @param codeRows the number of barcode rows
     */
    public void setCodeRows(int codeRows) {
        this.codeRows = codeRows;
    }
    
    /** Gets the number of barcode data columns.
     * @return he number of barcode data columns
     */
    public int getCodeColumns() {
        return this.codeColumns;
    }
    
    /** Sets the number of barcode data columns.
     * This number may be changed to keep the barcode valid.
     * @param codeColumns the number of barcode data columns
     */
    public void setCodeColumns(int codeColumns) {
        this.codeColumns = codeColumns;
    }
    
    /** Gets the codeword array. This array is always 928 elements long.
     * It can be writen to if the option <CODE>PDF417_USE_RAW_CODEWORDS</CODE>
     * is set.
     * @return the codeword array
     */
    public int[] getCodewords() {
        return this.codewords;
    }
    
    /** Gets the length of the codewords.
     * @return the length of the codewords
     */
    public int getLenCodewords() {
        return this.lenCodewords;
    }
    
    /** Sets the length of the codewords.
     * @param lenCodewords the length of the codewords
     */
    public void setLenCodewords(int lenCodewords) {
        this.lenCodewords = lenCodewords;
    }
    
    /** Gets the error level correction used for the barcode. It may different
     * from the previously set value.
     * @return the error level correction used for the barcode
     */
    public int getErrorLevel() {
        return this.errorLevel;
    }
    
    /** Sets the error level correction for the barcode.
     * @param errorLevel the error level correction for the barcode
     */
    public void setErrorLevel(int errorLevel) {
        this.errorLevel = errorLevel;
    }
    
    /** Gets the bytes that form the barcode. This bytes should
     * be interpreted in the codepage Cp437.
     * @return the bytes that form the barcode
     */
    public byte[] getText() {
        return this.text;
    }
    
    /** Sets the bytes that form the barcode. This bytes should
     * be interpreted in the codepage Cp437.
     * @param text the bytes that form the barcode
     */
    public void setText(byte[] text) {
        this.text = text;
    }
    
    /** Sets the text that will form the barcode. This text is converted
     * to bytes using the encoding Cp437.
     * @param s the text that will form the barcode
     */    
    public void setText(String s) {
        this.text = PdfEncodings.convertToBytes(s, "cp437");
    }
    
    /** Gets the options to generate the barcode.
     * @return the options to generate the barcode
     */
    public int getOptions() {
        return this.options;
    }
    
    /** Sets the options to generate the barcode. This can be all
     * the <CODE>PDF417_*</CODE> constants.
     * @param options the options to generate the barcode
     */
    public void setOptions(int options) {
        this.options = options;
    }
    
    /** Gets the barcode aspect ratio.
     * @return the barcode aspect ratio
     */
    public float getAspectRatio() {
        return this.aspectRatio;
    }
    
    /** Sets the barcode aspect ratio. A ratio or 0.5 will make the
     * barcode width twice as large as the height.
     * @param aspectRatio the barcode aspect ratio
     */
    public void setAspectRatio(float aspectRatio) {
        this.aspectRatio = aspectRatio;
    }
    
    /** Gets the Y pixel height relative to X.
     * @return the Y pixel height relative to X
     */
    public float getYHeight() {
        return this.yHeight;
    }
    
    /** Sets the Y pixel height relative to X. It is usually 3.
     * @param yHeight the Y pixel height relative to X
     */
    public void setYHeight(float yHeight) {
        this.yHeight = yHeight;
    }
    
    protected static final int START_PATTERN = 0x1fea8;
    protected static final int STOP_PATTERN = 0x3fa29;
    protected static final int START_CODE_SIZE = 17;
    protected static final int STOP_SIZE = 18;
    protected static final int MOD = 929;
    protected static final int ALPHA = 0x10000;
    protected static final int LOWER = 0x20000;
    protected static final int MIXED = 0x40000;
    protected static final int PUNCTUATION = 0x80000;
    protected static final int ISBYTE = 0x100000;
    protected static final int BYTESHIFT = 913;
    protected static final int PL = 25;
    protected static final int LL = 27;
    protected static final int AS = 27;
    protected static final int ML = 28;
    protected static final int AL = 28;
    protected static final int PS = 29;
    protected static final int PAL = 29;
    protected static final int SPACE = 26;
    protected static final int TEXT_MODE = 900;
    protected static final int BYTE_MODE_6 = 924;
    protected static final int BYTE_MODE = 901;
    protected static final int NUMERIC_MODE = 902;
    protected static final int ABSOLUTE_MAX_TEXT_SIZE = 5420;
    protected static final int MAX_DATA_CODEWORDS = 926;
    protected static final int MACRO_SEGMENT_ID=928;
    protected static final int MACRO_SEGMENT_COUNT=923;
    protected static final int MACRO_LAST_SEGMENT=922;

    private static final String MIXED_SET = "0123456789&\r\t,:#-.$/+%*=^";
    private static final String PUNCTUATION_SET = ";<>@[\\]_`~!\r\t,:\n-.$/\"|*()?{}'";

    private static final int CLUSTERS[][] =
    {{
         0x1d5c0, 0x1eaf0, 0x1f57c, 0x1d4e0, 0x1ea78, 0x1f53e, 0x1a8c0, 0x1d470,
         0x1a860, 0x15040, 0x1a830, 0x15020, 0x1adc0, 0x1d6f0, 0x1eb7c, 0x1ace0,
         0x1d678, 0x1eb3e, 0x158c0, 0x1ac70, 0x15860, 0x15dc0, 0x1aef0, 0x1d77c,
         0x15ce0, 0x1ae78, 0x1d73e, 0x15c70, 0x1ae3c, 0x15ef0, 0x1af7c, 0x15e78,
         0x1af3e, 0x15f7c, 0x1f5fa, 0x1d2e0, 0x1e978, 0x1f4be, 0x1a4c0, 0x1d270,
         0x1e93c, 0x1a460, 0x1d238, 0x14840, 0x1a430, 0x1d21c, 0x14820, 0x1a418,
         0x14810, 0x1a6e0, 0x1d378, 0x1e9be, 0x14cc0, 0x1a670, 0x1d33c, 0x14c60,
         0x1a638, 0x1d31e, 0x14c30, 0x1a61c, 0x14ee0, 0x1a778, 0x1d3be, 0x14e70,
         0x1a73c, 0x14e38, 0x1a71e, 0x14f78, 0x1a7be, 0x14f3c, 0x14f1e, 0x1a2c0,
         0x1d170, 0x1e8bc, 0x1a260, 0x1d138, 0x1e89e, 0x14440, 0x1a230, 0x1d11c,
         0x14420, 0x1a218, 0x14410, 0x14408, 0x146c0, 0x1a370, 0x1d1bc, 0x14660,
         0x1a338, 0x1d19e, 0x14630, 0x1a31c, 0x14618, 0x1460c, 0x14770, 0x1a3bc,
         0x14738, 0x1a39e, 0x1471c, 0x147bc, 0x1a160, 0x1d0b8, 0x1e85e, 0x14240,
         0x1a130, 0x1d09c, 0x14220, 0x1a118, 0x1d08e, 0x14210, 0x1a10c, 0x14208,
         0x1a106, 0x14360, 0x1a1b8, 0x1d0de, 0x14330, 0x1a19c, 0x14318, 0x1a18e,
         0x1430c, 0x14306, 0x1a1de, 0x1438e, 0x14140, 0x1a0b0, 0x1d05c, 0x14120,
         0x1a098, 0x1d04e, 0x14110, 0x1a08c, 0x14108, 0x1a086, 0x14104, 0x141b0,
         0x14198, 0x1418c, 0x140a0, 0x1d02e, 0x1a04c, 0x1a046, 0x14082, 0x1cae0,
         0x1e578, 0x1f2be, 0x194c0, 0x1ca70, 0x1e53c, 0x19460, 0x1ca38, 0x1e51e,
         0x12840, 0x19430, 0x12820, 0x196e0, 0x1cb78, 0x1e5be, 0x12cc0, 0x19670,
         0x1cb3c, 0x12c60, 0x19638, 0x12c30, 0x12c18, 0x12ee0, 0x19778, 0x1cbbe,
         0x12e70, 0x1973c, 0x12e38, 0x12e1c, 0x12f78, 0x197be, 0x12f3c, 0x12fbe,
         0x1dac0, 0x1ed70, 0x1f6bc, 0x1da60, 0x1ed38, 0x1f69e, 0x1b440, 0x1da30,
         0x1ed1c, 0x1b420, 0x1da18, 0x1ed0e, 0x1b410, 0x1da0c, 0x192c0, 0x1c970,
         0x1e4bc, 0x1b6c0, 0x19260, 0x1c938, 0x1e49e, 0x1b660, 0x1db38, 0x1ed9e,
         0x16c40, 0x12420, 0x19218, 0x1c90e, 0x16c20, 0x1b618, 0x16c10, 0x126c0,
         0x19370, 0x1c9bc, 0x16ec0, 0x12660, 0x19338, 0x1c99e, 0x16e60, 0x1b738,
         0x1db9e, 0x16e30, 0x12618, 0x16e18, 0x12770, 0x193bc, 0x16f70, 0x12738,
         0x1939e, 0x16f38, 0x1b79e, 0x16f1c, 0x127bc, 0x16fbc, 0x1279e, 0x16f9e,
         0x1d960, 0x1ecb8, 0x1f65e, 0x1b240, 0x1d930, 0x1ec9c, 0x1b220, 0x1d918,
         0x1ec8e, 0x1b210, 0x1d90c, 0x1b208, 0x1b204, 0x19160, 0x1c8b8, 0x1e45e,
         0x1b360, 0x19130, 0x1c89c, 0x16640, 0x12220, 0x1d99c, 0x1c88e, 0x16620,
         0x12210, 0x1910c, 0x16610, 0x1b30c, 0x19106, 0x12204, 0x12360, 0x191b8,
         0x1c8de, 0x16760, 0x12330, 0x1919c, 0x16730, 0x1b39c, 0x1918e, 0x16718,
         0x1230c, 0x12306, 0x123b8, 0x191de, 0x167b8, 0x1239c, 0x1679c, 0x1238e,
         0x1678e, 0x167de, 0x1b140, 0x1d8b0, 0x1ec5c, 0x1b120, 0x1d898, 0x1ec4e,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -