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

📄 pdf417.java

📁 著名IDAutomation公司的JAVA条码控件源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    private String C0(String s)
    {
        boolean flag = false;
        int k = s.length();
        String s1 = "";
        boolean flag1 = false;
        for(int i = 0; i < k; i++)
        {
            int j = s.charAt(i);
            if(j == 126)
            {
                if(i < k - 1)
                {
                    char c = s.charAt(i + 1);
                    if(c == '~')
                    {
                        s1 = s1 + '~';
                        i++;
                    } else
                    if(i < k - 3)
                    {
                        String s2 = s.substring(i + 1, i + 4);
                        int l = 0;
                        try
                        {
                            l = (new Integer(s2)).intValue();
                        }
                        catch(Exception exception)
                        {
                            l = 0;
                        }
                        if(l > 255)
                            l = 255;
                        s1 = s1 + (char)l;
                        i += 3;
                    }
                }
            } else
            {
                s1 = s1 + (char)j;
            }
        }

        return s1;
    }

    protected static double mod(double d1, double d2)
    {
        double d3 = d1 / d2;
        double d4 = Math.round(d3);
        if(d4 > d3)
            d4--;
        return d1 - d2 * d4;
    }

    protected void addBarWithHeight(Graphics g, int i, boolean flag, int j, int k)
    {
        if(flag)
        {
            g.setColor(barColor);
            g.fillRect(currentX, j, i, k);
        }
        currentX = currentX + i;
    }

    protected void paintCharWithHeight(Graphics g, String s, String s1, int i, int j)
    {
        for(int k = 0; k < s.length(); k++)
        {
            char c = s.charAt(k);
            char c1 = s1.charAt(k);
            if(c1 == 'n')
                addBarWithHeight(g, narrowBarPixels, c == 'b', i, j);
            if(c1 == 'w')
                addBarWithHeight(g, widthBarPixels, c == 'b', i, j);
            if(c1 == '1')
                addBarWithHeight(g, narrowBarPixels, c == 'b', i, j);
            if(c1 == '2')
                addBarWithHeight(g, narrowBarPixels * 2, c == 'b', i, j);
            if(c1 == '3')
                addBarWithHeight(g, narrowBarPixels * 3, c == 'b', i, j);
            if(c1 == '4')
                addBarWithHeight(g, narrowBarPixels * 4, c == 'b', i, j);
            if(c1 == '5')
                addBarWithHeight(g, narrowBarPixels * 5, c == 'b', i, j);
            if(c1 == '6')
                addBarWithHeight(g, narrowBarPixels * 6, c == 'b', i, j);
            if(c1 == '7')
                addBarWithHeight(g, narrowBarPixels * 7, c == 'b', i, j);
            if(c1 == '8')
                addBarWithHeight(g, narrowBarPixels * 8, c == 'b', i, j);
        }

    }

    protected String toXSecuence(int i)
    {
        int j = 0;
        int k = 1;
        int l = -1;
        String s = "";
        for(int j1 = 0; j1 < 17; j1++)
        {
            if(l == -1)
            {
                l = i & k;
                if(l > 0)
                    l = 1;
            }
            int i1 = i & k;
            if(i1 > 0)
                i1 = 1;
            if(l == i1)
            {
                j++;
            } else
            {
                s = j + s;
                l = i & k;
                if(l > 0)
                    l = 1;
                j = 1;
            }
            k *= 2;
        }

        s = j + s;
        return s;
    }

    protected void paintPDF417(Graphics g)
    {
        currentY = topMarginPixels;
        currentX = leftMarginPixels;
        if(barHeightPixels == 0)
            barHeightPixels = 1;
        int ai[] = null;
        if(PDFMode == 0 && binaryCode != null)
            ai = PDF417_compact_binary(binaryCode, PDFColumns);
        if(PDFMode == 0 && binaryCode == null)
            ai = PDF417_compact_binary(code.getBytes(), PDFColumns);
        if(PDFMode == 2)
            ai = PDF417_compact_numeric(code.getBytes(), PDFColumns);
        if(PDFMode == 1)
            ai = PDF417_compact_text(code.getBytes(), PDFColumns);
        if(ai == null)
            return;
        int i = 0;
        for(int j = 0; j < runtimeRows; j++)
        {
            currentX = leftMarginPixels;
            int l = PDFColumns - 1;
            int i1 = (int)mod(j, 3D);
            int j1 = j / 3;
            int k1 = (runtimeRows - 1) / 3;
            int l1 = (int)((double)(PDFECLevel * 3) + mod(runtimeRows - 1, 3D));
            paintCharWithHeight(g, "bwbwbwbw", toXSecuence(0x1fea8), currentY, barHeightPixels);
            switch(i1)
            {
            case 0: // '\0'
                paintCharWithHeight(g, "bwbwbwbw", toXSecuence(PDF417_BITS[i1][30 * j1 + k1]), currentY, barHeightPixels);
                break;

            case 1: // '\001'
                paintCharWithHeight(g, "bwbwbwbw", toXSecuence(PDF417_BITS[i1][30 * j1 + l1]), currentY, barHeightPixels);
                break;

            case 2: // '\002'
                paintCharWithHeight(g, "bwbwbwbw", toXSecuence(PDF417_BITS[i1][30 * j1 + l]), currentY, barHeightPixels);
                break;
            }
            for(int k = 0; k < PDFColumns; k++)
                paintCharWithHeight(g, "bwbwbwbw", toXSecuence(PDF417_BITS[i1][ai[i++]]), currentY, barHeightPixels);

            if(!truncated)
            {
                switch(i1)
                {
                case 0: // '\0'
                    paintCharWithHeight(g, "bwbwbwbw", toXSecuence(PDF417_BITS[i1][30 * j1 + l]), currentY, barHeightPixels);
                    break;

                case 1: // '\001'
                    paintCharWithHeight(g, "bwbwbwbw", toXSecuence(PDF417_BITS[i1][30 * j1 + k1]), currentY, barHeightPixels);
                    break;

                case 2: // '\002'
                    paintCharWithHeight(g, "bwbwbwbw", toXSecuence(PDF417_BITS[i1][30 * j1 + l1]), currentY, barHeightPixels);
                    break;
                }
                paintCharWithHeight(g, "bwbwbwbwb", "711311121", currentY, barHeightPixels);
            } else
            {
                paintCharWithHeight(g, "bw", "11", currentY, barHeightPixels);
            }
            currentY = currentY + barHeightPixels;
        }

    }

    protected void paintBasis(Graphics g)
    {
        codeText = "";
        if(getProcessTilde())
            code = C0(code);
        calculateSizes();
        topMarginPixels = (int)(topMarginCM * (double)resolution);
        leftMarginPixels = (int)(leftMarginCM * (double)resolution);
        currentX = leftMarginPixels;
        g.setColor(backColor);
        int i = getSize().width;
        int j = getSize().height;
        int k = i;
        if(j > k)
            k = j;
        g.fillRect(0, 0, k, k);
        paintPDF417(g);
        if(rotate == 0 || rotate == 180)
        {
            pHeight = currentY + topMarginPixels;
            pWidth = currentX + leftMarginPixels;
        } else
        {
            pWidth = currentY + topMarginPixels;
            pHeight = currentX + leftMarginPixels;
        }
        if(autoSize)
            setSize(pWidth, pHeight);
        Calendar calendar = Calendar.getInstance();
        int l = calendar.get(14);
        if(l < 400)
        {
            g.setFont(new Font("Arial", 0, 11));
            int i1 = g.getFontMetrics().getHeight();
            g.setColor(backColor);
            g.fillRect(leftMarginPixels + 6, 0, 125, i1 + 3);
            g.setColor(barColor);
            g.drawString("IDAutomation.com DEMO", leftMarginPixels + 10, i1 + 1);
        }
    }

    protected int[] PDF417_compact_binary(byte abyte0[], int i)
    {
        int j = (int)Math.pow(2D, PDFECLevel + 1);
        if(i < 1 || i > 30)
            i = 1;
        int k = (int)((double)(2 + (abyte0.length / 6) * 5) + mod(abyte0.length, 6D) + (double)j);
        int l = k / i;
        if(mod(k, i) != 0.0D)
            l++;
        if(l < 3)
            l = 3;
        if(l > 90)
            return null;
        if(l > PDFRows)
        {
            runtimeRows = l;
        } else
        {
            l = PDFRows;
            runtimeRows = PDFRows;
        }
        k = l * i;
        if(k > 928)
            return null;
        int ai[] = new int[k];
        ai[0] = k - j;
        if(mod(abyte0.length, 6D) != 0.0D)
            ai[1] = 901;
        else
            ai[1] = 924;
        int i1 = 0;
        int j1;
        for(j1 = 2; i1 + 5 < abyte0.length; j1 += 5)
        {
            BigInteger biginteger = new BigInteger("0");
            for(int k1 = 0; k1 < 6; k1++)
            {
                biginteger = biginteger.multiply(new BigInteger("256"));
                int i2 = abyte0[i1++];
                if(i2 < 0)
                    i2 = 256 + i2;
                biginteger = biginteger.add(new BigInteger("" + i2));
            }

            for(int l1 = 0; l1 < 5; l1++)
            {
                ai[(j1 + 4) - l1] = biginteger.mod(new BigInteger("900")).intValue();
                biginteger = biginteger.divide(new BigInteger("900"));
            }

        }

        while(i1 < abyte0.length)
        {
            ai[j1] = abyte0[i1++];
            if(ai[j1] < 0)
                ai[j1] = 256 + ai[j1];
            j1++;
        }
        while(j1 < k - j)
            ai[j1++] = 900;
        genEC(ai, j1);
        return ai;
    }

    protected int[] PDF417_compact_numeric(byte abyte0[], int i)
    {
        int j = (int)Math.pow(2D, PDFECLevel + 1);
        int k = 0;
        if(i < 1 || i > 30)
            i = 1;

⌨️ 快捷键说明

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