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

📄 pdf417lib.java

📁 pdf417二维条码处理。包括显示和识别。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    continue;                }            }        }        //merge binary sections        for (k = 0; k < segmentList.size(); ++k) {            v = segmentList.get(k);            vp = segmentList.get(k - 1);            vn = segmentList.get(k + 1);;            if (checkSegmentType(v, 'B')) {                boolean redo = false;                if ((checkSegmentType(vp, 'T') && getSegmentLength(vp) < 5) || checkSegmentType(vp, 'B')) {                    redo = true;                    v.start = vp.start;                    segmentList.remove(k - 1);                    --k;                }                if ((checkSegmentType(vn, 'T') && getSegmentLength(vn) < 5) || checkSegmentType(vn, 'B')) {                    redo = true;                    v.end = vn.end;                    segmentList.remove(k + 1);                }                if (redo) {                    k = -1;                    continue;                }            }        }        // check if all numbers        if (segmentList.size() == 1 && (v = segmentList.get(0)).type == 'T' && getSegmentLength(v) >= 8) {            for (k = v.start; k < v.end; ++k) {                c = (char)(text[k] & 0xff);                if (c < '0' || c > '9')                    break;            }            if (k == v.end)                v.type = 'N';        }    }    protected void assemble() {        int k;        if (segmentList.size() == 0)            return;        cwPtr = 1;        for (k = 0; k < segmentList.size(); ++k) {            Segment v = segmentList.get(k);            switch (v.type) {            case 'T':                if (k != 0)                    codewords[cwPtr++] = TEXT_MODE;                textCompaction(v.start, getSegmentLength(v));                break;            case 'N':                codewords[cwPtr++] = NUMERIC_MODE;                numberCompaction(v.start, getSegmentLength(v));                break;            case 'B':                codewords[cwPtr++] = (getSegmentLength(v) % 6) != 0 ? BYTE_MODE : BYTE_MODE_6;                byteCompaction(v.start, getSegmentLength(v));                break;            }        }    }        protected static int maxPossibleErrorLevel(int remain) {        int level = 8;        int size = 512;        while (level > 0) {            if (remain >= size)                return level;            --level;            size >>= 1;        }        return 0;    }    protected void dumpList() {        if (segmentList.size() == 0)            return;        for (int k = 0; k < segmentList.size(); ++k) {            Segment v = segmentList.get(k);            int len = getSegmentLength(v);            char c[] = new char[len];            for (int j = 0; j < len; ++j) {                c[j] = (char)(text[v.start + j] & 0xff);                if (c[j] == '\r')                    c[j] = '\n';            }            System.out.println("" + v.type + new String(c));        }    }    protected int getMaxSquare() {        if (codeColumns > 21) {            codeColumns = 29;            codeRows = 32;        }        else {            codeColumns = 16;            codeRows = 58;        }        return MAX_DATA_CODEWORDS + 2;    }    /** Paints the barcode. If no exception was thrown a valid barcode is available. */        public void paintCode() {        int maxErr, lenErr, tot, pad;        if ((options & PDF417_USE_RAW_CODEWORDS) != 0) {            if (lenCodewords > MAX_DATA_CODEWORDS || lenCodewords < 1 || lenCodewords != codewords[0]) {                throw new IllegalArgumentException("Invalid codeword size.");            }        }        else {            if (text == null)                throw new NullPointerException("Text cannot be null.");            if (text.length > ABSOLUTE_MAX_TEXT_SIZE) {                throw new IndexOutOfBoundsException("The text is too big.");            }            segmentList = new SegmentList();            breakString();            //dumpList();            assemble();            segmentList = null;            codewords[0] = lenCodewords = cwPtr;        }        maxErr = maxPossibleErrorLevel(MAX_DATA_CODEWORDS + 2 - lenCodewords);        if ((options & PDF417_USE_ERROR_LEVEL) == 0) {            if (lenCodewords < 41)                errorLevel = 2;            else if (lenCodewords < 161)                errorLevel = 3;            else if (lenCodewords < 321)                errorLevel = 4;            else                errorLevel = 5;        }        if (errorLevel < 0)            errorLevel = 0;        else if (errorLevel > maxErr)            errorLevel = maxErr;        if (codeColumns < 1)            codeColumns = 1;        else if (codeColumns > 30)            codeColumns = 30;        if (codeRows < 3)            codeRows = 3;        else if (codeRows > 90)            codeRows = 90;        lenErr = 2 << errorLevel;        boolean fixedColumn = (options & PDF417_FIXED_ROWS) == 0;        boolean skipRowColAdjust = false;        tot = lenCodewords + lenErr;        if ((options & PDF417_FIXED_RECTANGLE) != 0) {            tot = codeColumns * codeRows;            if (tot > MAX_DATA_CODEWORDS + 2) {                tot = getMaxSquare();            }            if (tot < lenCodewords + lenErr)                tot = lenCodewords + lenErr;            else                skipRowColAdjust = true;        }        else if ((options & (PDF417_FIXED_COLUMNS | PDF417_FIXED_ROWS)) == 0) {            double c, b;            fixedColumn = true;            if (aspectRatio < 0.001)                aspectRatio = 0.001f;            else if (aspectRatio > 1000)                aspectRatio = 1000;            b = 73 * aspectRatio - 4;            c = (-b + Math.sqrt(b * b + 4 * 17 * aspectRatio * (lenCodewords + lenErr) * yHeight)) / (2 * 17 * aspectRatio);            codeColumns = (int)(c + 0.5);            if (codeColumns < 1)                codeColumns = 1;            else if (codeColumns > 30)                codeColumns = 30;        }        if (!skipRowColAdjust) {            if (fixedColumn) {                codeRows = (tot - 1) / codeColumns + 1;                if (codeRows < 3)                    codeRows = 3;                else if (codeRows > 90) {                    codeRows = 90;                    codeColumns = (tot - 1) / 90 + 1;                }            }            else {                codeColumns = (tot - 1) / codeRows + 1;                if (codeColumns > 30) {                    codeColumns = 30;                    codeRows = (tot - 1) / 30 + 1;                }            }            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 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() {

⌨️ 快捷键说明

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