/bs-cs-ufal-brazil/classes/systems-analysis-design/bibliweb/src/br/ufal/bibliweb/barcode/linear/BarCode.java
Java | 2100 lines | 1959 code | 141 blank | 0 comment | 638 complexity | 1028ff57535babdc7a822ecb20630fae MD5 | raw file
Possible License(s): LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- package br.ufal.bibliweb.barcode.linear;
-
- import java.awt.*;
- import java.awt.image.MemoryImageSource;
- import java.awt.image.PixelGrabber;
- import java.io.PrintStream;
- import java.io.Serializable;
-
- public class BarCode extends Canvas
- implements Serializable
- {
-
- public BarCode()
- {
- barType = 13;
- code = "";
- codeSup = "";
- checkCharacter = true;
- checkCharacterInText = true;
- postnetHeightTallBar = 0.29999999999999999D;
- postnetHeightShortBar = 0.125D;
- leftMarginCM = 0.20000000000000001D;
- topMarginCM = 0.5D;
- leftMarginPixels = 0;
- topMarginPixels = 0;
- leftGuardBar = 0;
- centerGuardBarStart = 0;
- centerGuardBarEnd = 0;
- rightGuardBar = 0;
- endOfCode = 0;
- supplement = "";
- guardBars = true;
- backColor = Color.white;
- codeText = "";
- narrowBarPixels = 0;
- widthBarPixels = 0;
- narrowBarCM = 0.0D;
- widthBarCM = 0.0D;
- resolution = (int)((double)getToolkit().getScreenResolution() / 2.54D);
- barHeightPixels = 0;
- barHeightCM = 0.0D;
- width = 170;
- height = 70;
- pWidth = width;
- pHeight = height;
- textFont = new Font("Arial", 0, 11);
- fontColor = Color.black;
- barColor = Color.black;
- extraHeight = 0;
- UPCESytem = '1';
- CODABARStartChar = 'A';
- CODABARStopChar = 'B';
- UPCEANSupplement2 = false;
- UPCEANSupplement5 = false;
- Code128Set = '0';
- X = 0.029999999999999999D;
- N = 2D;
- I = 1.0D;
- H = 0.45000000000000001D;
- L = 0.0D;
- rotate = 0;
- supSeparationCM = 0.5D;
- supHeight = 0.80000000000000004D;
- currentX = 0;
- currentY = 0;
- }
-
- public void setSymbologyID(int i)
- {
- barType = i;
- invalidate();
- }
-
- public int getSymbologyID()
- {
- return barType;
- }
-
- public void setDataToEncode(String s)
- {
- code = s;
- invalidate();
- }
-
- public String getDataToEncode()
- {
- return code;
- }
-
- public void setCheckCharacter(boolean flag)
- {
- checkCharacter = flag;
- invalidate();
- }
-
- public boolean getCheckCharacter()
- {
- return checkCharacter;
- }
-
- public void setCheckCharacterInText(boolean flag)
- {
- checkCharacterInText = flag;
- invalidate();
- }
-
- public boolean getCheckCharacterInText()
- {
- return checkCharacterInText;
- }
-
- public void setPostnetHeightTall(double d1)
- {
- postnetHeightTallBar = d1;
- invalidate();
- }
-
- public double getPostnetHeightTall()
- {
- return postnetHeightTallBar;
- }
-
- public void setPostnetHeightShort(double d1)
- {
- postnetHeightShortBar = d1;
- invalidate();
- }
-
- public double getPostnetHeightShort()
- {
- return postnetHeightShortBar;
- }
-
- public void setLeftMarginCM(double d1)
- {
- leftMarginCM = d1;
- invalidate();
- }
-
- public double getLeftMarginCM()
- {
- return leftMarginCM;
- }
-
- public void setTopMarginCM(double d1)
- {
- topMarginCM = d1;
- invalidate();
- }
-
- public double getTopMarginCM()
- {
- return topMarginCM;
- }
-
- public void setSupplementToEncode(String s)
- {
- supplement = s;
- invalidate();
- }
-
- public String getSupplementToEncode()
- {
- return supplement;
- }
-
- public void setBackground(Color color)
- {
- backColor = color;
- invalidate();
- }
-
- public Color getBackground()
- {
- return backColor;
- }
-
- public void setPixelsPerCM(int i)
- {
- resolution = i;
- invalidate();
- }
-
- public int getPixelsPerCM()
- {
- return resolution;
- }
-
- public void setBarHeightCM(double d1)
- {
- barHeightCM = d1;
- invalidate();
- }
-
- public double getBarHeightCM()
- {
- return barHeightCM;
- }
-
- public Dimension getPreferredSize()
- {
- return new Dimension(pWidth, pHeight);
- }
-
- public Dimension getMinimumSize()
- {
- Dimension dimension = new Dimension(10, 10);
- return dimension;
- }
-
- public void setFont(Font font)
- {
- textFont = font;
- invalidate();
- }
-
- public Font getFont()
- {
- return textFont;
- }
-
- public void setTextFontColor(Color color)
- {
- fontColor = color;
- invalidate();
- }
-
- public Color getTextFontColor()
- {
- return fontColor;
- }
-
- public void setForeground(Color color)
- {
- barColor = color;
- invalidate();
- }
-
- public Color getForeground()
- {
- return barColor;
- }
-
- public void setUPCESytem(String s)
- {
- if(s.equals("0"))
- UPCESytem = '0';
- if(s.equals("1"))
- UPCESytem = '1';
- invalidate();
- }
-
- public String getUPCESytem()
- {
- String s = "";
- if(UPCESytem == '0')
- s = "0";
- if(UPCESytem == '1')
- s = "1";
- return s;
- }
-
- public void setCODABARStartChar(String s)
- {
- if(s.equals("B"))
- CODABARStartChar = 'B';
- if(s.equals("A"))
- CODABARStartChar = 'A';
- if(s.equals("C"))
- CODABARStartChar = 'C';
- if(s.equals("D"))
- CODABARStartChar = 'D';
- invalidate();
- }
-
- public String getCODABARStartChar()
- {
- String s = "";
- if(CODABARStartChar == 'B')
- s = "B";
- if(CODABARStartChar == 'A')
- s = "A";
- if(CODABARStartChar == 'C')
- s = "C";
- if(CODABARStartChar == 'D')
- s = "D";
- return s;
- }
-
- public void setCODABARStopChar(String s)
- {
- if(s.equals("B"))
- CODABARStopChar = 'B';
- if(s.equals("A"))
- CODABARStopChar = 'A';
- if(s.equals("C"))
- CODABARStopChar = 'C';
- if(s.equals("D"))
- CODABARStopChar = 'D';
- invalidate();
- }
-
- public String getCODABARStopChar()
- {
- String s = "";
- if(CODABARStopChar == 'B')
- s = "B";
- if(CODABARStopChar == 'A')
- s = "A";
- if(CODABARStopChar == 'C')
- s = "C";
- if(CODABARStopChar == 'D')
- s = "D";
- return s;
- }
-
- public void setUPCEANSupplement2(boolean flag)
- {
- UPCEANSupplement2 = flag;
- invalidate();
- }
-
- public boolean getUPCEANSupplement2()
- {
- return UPCEANSupplement2;
- }
-
- public void setUPCEANSupplement5(boolean flag)
- {
- UPCEANSupplement5 = flag;
- invalidate();
- }
-
- public boolean getUPCEANSupplement5()
- {
- return UPCEANSupplement5;
- }
-
- public void setCode128Set(String s)
- {
- if(s.toUpperCase().equals("B"))
- Code128Set = 'B';
- if(s.toUpperCase().equals("A"))
- Code128Set = 'A';
- if(s.toUpperCase().equals("C"))
- Code128Set = 'C';
- if(s.toUpperCase().equals("AUTO"))
- Code128Set = '0';
- if(s.toUpperCase().equals("0"))
- Code128Set = '0';
- invalidate();
- }
-
- public String getCode128Set()
- {
- String s = "";
- if(Code128Set == 'B')
- s = "B";
- if(Code128Set == 'A')
- s = "A";
- if(Code128Set == 'C')
- s = "C";
- if(Code128Set == '0')
- s = "0";
- return s;
- }
-
- public void setXDimensionCM(double d1)
- {
- X = d1;
- invalidate();
- }
-
- public double getXDimensionCM()
- {
- return X;
- }
-
- public void setNarrowToWideRatio(double d1)
- {
- N = d1;
- invalidate();
- }
-
- public double getNarrowToWideRatio()
- {
- return N;
- }
-
- public void setRotationAngle(int i)
- {
- rotate = i;
- invalidate();
- }
-
- public int getRotationAngle()
- {
- return rotate;
- }
-
- protected void addBar(Graphics g, int i, boolean flag, int j)
- {
- if(flag)
- {
- g.setColor(barColor);
- g.fillRect(currentX, topMarginPixels + j, i, (barHeightPixels + extraHeight) - j);
- }
- currentX = currentX + i;
- }
-
- protected void paintPostNetChar(Graphics g, String s)
- {
- int i = (int)(postnetHeightTallBar * (double)resolution);
- int j = (int)(postnetHeightShortBar * (double)resolution);
- g.setColor(barColor);
- for(int k = 0; k < s.length(); k++)
- {
- char c = s.charAt(k);
- if(c == '0')
- g.fillRect(currentX, topMarginPixels, narrowBarPixels, j + extraHeight);
- if(c == '1')
- g.fillRect(currentX, topMarginPixels + (j - i), narrowBarPixels, i + extraHeight);
- currentX = currentX + narrowBarPixels;
- currentX = currentX + widthBarPixels;
- }
-
- }
-
- protected void paintPOSTNET(Graphics g)
- {
- boolean flag = false;
- int j = 0;
- String s2 = code;
- paintPostNetChar(g, "1");
- for(int k = code.length() - 1; k >= 0; k--)
- {
- String s = "" + code.charAt(k);
- j += findChar(setPOSTNET, s);
- }
-
- int l = (int)mod(j, 10D);
- if(l != 0)
- l = 10 - l;
- if(checkCharacter)
- s2 = s2 + (new Integer(l)).toString();
- for(int i1 = 0; i1 < s2.length(); i1++)
- {
- String s1 = "" + s2.charAt(i1);
- int i = findChar(setPOSTNET, s1);
- paintPostNetChar(g, setPOSTNET[i][1]);
- }
-
- paintPostNetChar(g, "1");
- }
-
- protected int findChar(String as[][], String s)
- {
- for(int i = 0; i < as.length; i++)
- if(s.compareTo(as[i][0]) == 0)
- return i;
-
- return -1;
- }
-
- protected void paintPLANET(Graphics g)
- {
- boolean flag = false;
- int j = 0;
- String s2 = code;
- paintPostNetChar(g, "1");
- for(int k = code.length() - 1; k >= 0; k--)
- {
- String s = "" + code.charAt(k);
- j += findChar(setPLANET, s);
- }
-
- int l = (int)mod(j, 10D);
- if(l != 0)
- l = 10 - l;
- if(checkCharacter)
- s2 = s2 + (new Integer(l)).toString();
- for(int i1 = 0; i1 < s2.length(); i1++)
- {
- String s1 = "" + s2.charAt(i1);
- int i = findChar(setPLANET, s1);
- paintPostNetChar(g, setPLANET[i][1]);
- }
-
- paintPostNetChar(g, "1");
- }
-
- protected void paintInterleaved25(Graphics g)
- {
- boolean flag = false;
- boolean flag1 = false;
- boolean flag2 = false;
- String s3 = code;
- paintChar(g, "bwbw", "nnnn");
- String s4 = "";
- if(mod(code.length(), 2D) == 0.0D && checkCharacter)
- s3 = "0" + code;
- if(mod(code.length(), 2D) == 1.0D && !checkCharacter)
- s3 = "0" + code;
- int k = 0;
- int l = 0;
- boolean flag3 = true;
- for(int i1 = s3.length() - 1; i1 >= 0; i1--)
- {
- String s = "" + s3.charAt(i1);
- if(flag3)
- k += findChar(set25, s);
- else
- l += findChar(set25, s);
- flag3 = !flag3;
- }
-
- int j1 = k * 3 + l;
- j1 = (int)mod(j1, 10D);
- if(j1 != 0)
- j1 = 10 - j1;
- if(checkCharacter)
- s3 = s3 + (new Integer(j1)).toString();
- for(int k1 = 0; k1 < s3.length(); k1 += 2)
- {
- String s1 = "" + s3.charAt(k1);
- String s2 = "" + s3.charAt(k1 + 1);
- int i = findChar(set25, s1);
- int j = findChar(set25, s2);
- for(int l1 = 0; l1 < 5; l1++)
- {
- paintChar(g, "b", "" + set25[i][1].charAt(l1));
- paintChar(g, "w", "" + set25[j][1].charAt(l1));
- }
-
- }
-
- paintChar(g, "bwb", "wnn");
- if(checkCharacterInText)
- codeText = s3;
- else
- codeText = code;
- }
-
- protected void paintIND25(Graphics g)
- {
- boolean flag = false;
- boolean flag1 = false;
- String s2 = code;
- paintChar(g, "bwbwbw", "wwwwnw");
- int j = 0;
- int k = 0;
- boolean flag2 = true;
- for(int l = s2.length() - 1; l >= 0; l--)
- {
- String s = "" + s2.charAt(l);
- if(flag2)
- j += findChar(set25, s);
- else
- k += findChar(set25, s);
- flag2 = !flag2;
- }
-
- int i1 = j * 3 + k;
- i1 = (int)mod(i1, 10D);
- if(i1 != 0)
- i1 = 10 - i1;
- if(checkCharacter)
- s2 = s2 + (new Integer(i1)).toString();
- for(int j1 = 0; j1 < s2.length(); j1++)
- {
- String s1 = "" + s2.charAt(j1);
- int i = findChar(set25, s1);
- if(i >= 0)
- {
- for(int k1 = 0; k1 < set25[i][1].length(); k1++)
- {
- paintChar(g, "b", "" + set25[i][1].charAt(k1));
- paintChar(g, "w", "w");
- }
-
- }
- }
-
- paintChar(g, "bwbwb", "wwnww");
- }
-
- protected String UPCEANCheck(String s)
- {
- boolean flag = true;
- int i = 0;
- int j = 0;
- int k = 0;
- for(int l = s.length() - 1; l >= 0; l--)
- {
- if(flag)
- i += (new Integer("" + s.charAt(l))).intValue();
- else
- j += (new Integer("" + s.charAt(l))).intValue();
- flag = !flag;
- }
-
- j = i * 3 + j;
- k = (int)mod(j, 10D);
- if(k != 0)
- k = 10 - k;
- return "" + k;
- }
-
- protected void paintUPCA(Graphics g)
- {
- boolean flag = false;
- boolean flag1 = false;
- if(code.length() == 13)
- {
- supplement = code.substring(11, 13);
- UPCEANSupplement2 = true;
- code = code.substring(0, 11);
- }
- if(code.length() == 14)
- {
- supplement = code.substring(12, 14);
- UPCEANSupplement2 = true;
- code = code.substring(0, 11);
- }
- if(code.length() == 16)
- {
- supplement = code.substring(11, 16);
- UPCEANSupplement5 = true;
- code = code.substring(0, 11);
- }
- if(code.length() == 17)
- {
- supplement = code.substring(12, 17);
- UPCEANSupplement5 = true;
- code = code.substring(0, 11);
- }
- code = code.substring(0, 11) + UPCEANCheck(code);
- paintGuardChar(g, "bwb", "nnn", 0);
- leftGuardBar = currentX;
- for(int k = 0; k < code.length(); k++)
- {
- String s = "" + code.charAt(k);
- byte byte0 = -1;
- if(k <= 5)
- {
- int i = findChar(setUPCALeft, s);
- paintChar(g, "wbwb", setUPCALeft[i][1]);
- } else
- {
- int j = findChar(setUPCARight, s);
- paintChar(g, "bwbw", setUPCARight[j][1]);
- }
- if(k == 5)
- {
- centerGuardBarStart = currentX;
- paintGuardChar(g, "wbwbw", "nnnnn", 0);
- centerGuardBarEnd = currentX;
- }
- }
-
- rightGuardBar = currentX;
- paintGuardChar(g, "bwb", "nnn", 0);
- endOfCode = currentX;
- if(UPCEANSupplement2)
- paintSup2(g, code.substring(1, 3));
- else
- if(UPCEANSupplement5)
- paintSup5(g, code.substring(1, 6));
- }
-
- protected void paintEAN13(Graphics g)
- {
- int i = 0;
- boolean flag = false;
- if(code.length() == 12 && checkCharacter)
- code = code + UPCEANCheck(code);
- if(code.length() < 13)
- return;
- paintGuardChar(g, "bwb", "nnn", 0);
- leftGuardBar = currentX;
- String s1 = setEANCode[(new Integer("" + code.charAt(0))).intValue()];
- i = findChar(setEANLeftA, "" + code.charAt(1));
- paintChar(g, "wbwb", setEANLeftA[i][1]);
- for(int j = 2; j < 12; j++)
- {
- String s = "" + code.charAt(j);
- i = -1;
- if(j <= 6)
- {
- String as[][] = setEANLeftA;
- if(s1.charAt(j - 2) == 'B')
- as = setEANLeftB;
- i = findChar(as, s);
- paintChar(g, "wbwb", as[i][1]);
- } else
- {
- i = findChar(setEANRight, s);
- paintChar(g, "bwbw", setEANRight[i][1]);
- }
- if(j == 6)
- {
- centerGuardBarStart = currentX;
- paintGuardChar(g, "wbwbw", "nnnnn", 0);
- centerGuardBarEnd = currentX;
- }
- }
-
- i = findChar(setEANRight, "" + code.charAt(12));
- paintChar(g, "bwbw", setEANRight[i][1]);
- rightGuardBar = currentX;
- paintGuardChar(g, "bwb", "nnn", 0);
- endOfCode = currentX;
- if(UPCEANSupplement2)
- paintSup2(g, code.substring(2, 4));
- else
- if(UPCEANSupplement5)
- paintSup5(g, code.substring(2, 7));
- }
-
- private int C0(String as[], String s)
- {
- for(int i = 0; i < as.length; i++)
- if(as[i].compareTo(s) == 0)
- return i;
-
- return -1;
- }
-
- protected void paintCode128(Graphics g)
- {
- boolean flag = false;
- boolean flag1 = false;
- String s2 = code;
- codeText = code;
- boolean flag2 = false;
- boolean flag3 = false;
- int k1 = code.length();
- String as[] = set128B;
- int l1 = 103;
- if(Code128Set != '0')
- {
- s2 = "";
- codeText = "";
- for(int i2 = 1; i2 <= k1; i2++)
- {
- int l = code.charAt(i2 - 1);
- if(l < 32 && l >= 0)
- {
- if(Code128Set == 'A')
- s2 = s2 + (char)(l + 96);
- if(Code128Set == 'B')
- if(code.charAt(i2) < ' ')
- {
- s2 = s2 + '\311' + (char)(l + 96) + (char)(code.charAt(i2) + 96) + '\310';
- i2++;
- } else
- {
- s2 = s2 + '\311' + (char)(l + 96) + '\310';
- }
- if(Code128Set == 'C')
- if(code.charAt(i2) < ' ')
- {
- s2 = s2 + '\311' + '\311' + (l + 64) + (code.charAt(i2) + 64) + "99";
- i2++;
- } else
- {
- s2 = s2 + '\311' + '\311' + (l + 64) + "99";
- }
- if(l == 13 || l == 9)
- codeText = codeText + " ";
- } else
- {
- codeText = codeText + (char)l;
- s2 = s2 + (char)l;
- }
- }
-
- }
- if(Code128Set == '0')
- {
- as = set128B;
- codeText = "";
- s2 = "";
- char c2 = '\314';
- byte byte0 = 66;
- char c = code.charAt(0);
- if(c < ' ')
- c2 = '\313';
- if(c > '\037' && c < '\177')
- c2 = '\314';
- if(k1 > 3 && c > '/' && c < ':' && code.charAt(1) > '/' && code.charAt(1) < ':' && code.charAt(2) > '/' && code.charAt(2) < ':' && code.charAt(3) > '/' && code.charAt(3) < ':')
- c2 = '\315';
- if(c == '\312')
- c2 = '\315';
- if(c2 == '\313')
- {
- byte0 = 65;
- l1 = 103;
- paintChar(g, "bwbwbw", "211412");
- }
- if(c2 == '\314')
- {
- byte0 = 66;
- l1 = 104;
- paintChar(g, "bwbwbw", "211214");
- }
- if(c2 == '\315')
- {
- byte0 = 67;
- l1 = 105;
- paintChar(g, "bwbwbw", "211232");
- }
- for(int l2 = 1; l2 <= k1; l2++)
- {
- int i1 = code.charAt(l2 - 1);
- if(l2 < k1 - 1 && i1 == 202)
- s2 = s2 + (char)i1;
- else
- if(l2 <= k1 - 3 && i1 > 47 && i1 < 58 && code.charAt(l2) > '/' && code.charAt(l2) < ':' && code.charAt(l2 + 1) > '/' && code.charAt(l2 + 1) < ':' && code.charAt(l2 + 2) > '/' && code.charAt(l2 + 2) < ':' || l2 <= k1 - 1 && i1 > 47 && i1 < 58 && code.charAt(l2) > '/' && code.charAt(l2) < ':' && byte0 == 67)
- {
- if(byte0 != 67)
- {
- s2 = s2 + '\307';
- byte0 = 67;
- }
- i1 = (code.charAt(l2 - 1) - 48) * 10 + (code.charAt(l2) - 48);
- if(i1 < 95 && i1 >= 0)
- s2 = s2 + (char)(i1 + 32);
- else
- if(i1 > 94)
- s2 = s2 + (char)(i1 + 100);
- l2++;
- } else
- if(l2 <= k1 && (i1 < 32 || byte0 == 65 && i1 < 96))
- {
- if(byte0 != 65)
- {
- s2 = s2 + '\311';
- byte0 = 65;
- }
- if(i1 < 32)
- s2 = s2 + (char)(i1 + 96);
- else
- if(i1 > 31)
- s2 = s2 + (char)i1;
- } else
- if(l2 <= k1 && i1 > 31 && i1 < 127)
- {
- if(byte0 != 66)
- {
- s2 = s2 + '\310';
- byte0 = 66;
- }
- s2 = s2 + (char)i1;
- }
- }
-
- }
- for(int j2 = 1; j2 <= k1; j2++)
- {
- char c1 = code.charAt(j2 - 1);
- if(j2 < k1 - 1 && c1 == '\312')
- {
- int j1 = (code.charAt(j2) - 48) * 10 + (code.charAt(j2 + 1) - 48);
- if(j2 < k1 - 3 && (j1 <= 81 && j1 >= 80 || j1 <= 34 && j1 >= 31))
- {
- codeText = codeText + " (" + code.charAt(j2) + code.charAt(j2 + 1) + code.charAt(j2 + 2) + code.charAt(j2 + 3) + ") ";
- j2 += 4;
- } else
- if(j2 < k1 - 2 && (j1 <= 49 && j1 >= 40 || j1 <= 25 && j1 >= 23))
- {
- codeText = codeText + " (" + code.charAt(j2) + code.charAt(j2 + 1) + code.charAt(j2 + 2) + ") ";
- j2 += 3;
- } else
- if(j1 <= 30 && j1 >= 0 || j1 <= 99 && j1 >= 90)
- {
- codeText = codeText + " (" + code.charAt(j2) + code.charAt(j2 + 1) + ") ";
- j2 += 2;
- }
- } else
- if(code.charAt(j2 - 1) < ' ')
- codeText = codeText + " ";
- else
- if(code.charAt(j2 - 1) > '\037' && code.charAt(j2 - 1) < '\200')
- codeText = codeText + code.charAt(j2 - 1);
- }
-
- if(Code128Set == 'B')
- {
- as = set128B;
- l1 = 104;
- }
- if(Code128Set == 'C')
- {
- as = set128C;
- l1 = 105;
- if(s2.length() % 2 == 1)
- {
- s2 = "0" + s2;
- codeText = s2;
- }
- }
- if(Code128Set == 'B')
- paintChar(g, "bwbwbw", "211214");
- if(Code128Set == 'C')
- paintChar(g, "bwbwbw", "211232");
- if(Code128Set == 'A')
- paintChar(g, "bwbwbw", "211412");
- int k2 = 1;
- for(int i3 = 0; i3 < s2.length(); i3++)
- {
- String s = "" + s2.charAt(i3);
- if(Code128Set == 'C')
- {
- String s1 = "" + s;
- if(++i3 < s2.length())
- s1 = s1 + s2.charAt(i3);
- int i = C0(set128C, s1);
- if(i >= 0)
- {
- paintChar(g, "bwbwbw", set128[i]);
- l1 += i * k2;
- }
- } else
- {
- int j = C0(as, s);
- if(j >= 0)
- {
- paintChar(g, "bwbwbw", set128[j]);
- l1 += j * k2;
- }
- }
- k2++;
- }
-
- if(checkCharacter)
- {
- int k = (int)mod(l1, 103D);
- paintChar(g, "bwbwbw", set128[k]);
- }
- paintChar(g, "bwbwbwb", "2331112");
- }
-
- protected void paintUCC128(Graphics g)
- {
- boolean flag = false;
- boolean flag1 = false;
- String s2 = code;
- codeText = code;
- boolean flag2 = false;
- String as[] = set128C;
- Code128Set = 'C';
- int l = 105;
- if(s2.length() % 2 == 1)
- {
- s2 = "0" + s2;
- codeText = s2;
- }
- if(s2.charAt(0) != '\312' && s2.charAt(1) != '\312')
- s2 = "\312\312" + s2;
- boolean flag3 = false;
- int j1 = s2.length();
- codeText = "";
- for(int k1 = 0; k1 < j1; k1++)
- {
- char c = s2.charAt(k1);
- if(k1 < j1 - 3 && s2.charAt(k1) == '\312' && s2.charAt(k1 + 1) == '\312')
- {
- int i1 = (s2.charAt(k1 + 2) - 48) * 10 + (s2.charAt(k1 + 3) - 48);
- if(k1 < j1 - 5 && (i1 <= 81 && i1 >= 80 || i1 <= 34 && i1 >= 31))
- {
- codeText = codeText + " (" + s2.charAt(k1 + 2) + s2.charAt(k1 + 3) + s2.charAt(k1 + 4) + s2.charAt(k1 + 5) + ") ";
- k1 += 5;
- } else
- if(k1 < j1 - 4 && (i1 <= 49 && i1 >= 40 || i1 <= 25 && i1 >= 23))
- {
- codeText = codeText + " (" + s2.charAt(k1 + 2) + s2.charAt(k1 + 3) + s2.charAt(k1 + 4) + ") ";
- k1 += 4;
- } else
- if(i1 <= 30 && i1 >= 0 || i1 <= 99 && i1 >= 90)
- {
- codeText = codeText + " (" + s2.charAt(k1 + 2) + s2.charAt(k1 + 3) + ") ";
- k1 += 3;
- }
- } else
- {
- codeText = codeText + s2.charAt(k1);
- }
- }
-
- paintChar(g, "bwbwbw", "211232");
- int l1 = 1;
- for(int i2 = 0; i2 < s2.length(); i2++)
- {
- String s = "" + s2.charAt(i2);
- if(Code128Set == 'C')
- {
- String s1 = "" + s;
- if(++i2 < s2.length())
- s1 = s1 + s2.charAt(i2);
- int i = C0(set128C, s1);
- if(i >= 0)
- {
- paintChar(g, "bwbwbw", set128[i]);
- l += i * l1;
- }
- } else
- {
- int j = C0(as, s);
- if(j >= 0)
- {
- paintChar(g, "bwbwbw", set128[j]);
- l += j * l1;
- }
- }
- l1++;
- }
-
- if(checkCharacter)
- {
- int k = (int)mod(l, 103D);
- paintChar(g, "bwbwbw", set128[k]);
- }
- paintChar(g, "bwbwbwb", "2331112");
- }
-
- protected void paintEAN8(Graphics g)
- {
- boolean flag = false;
- boolean flag1 = false;
- if(code.length() == 7 && checkCharacter)
- code = code + UPCEANCheck(code);
- if(code.length() < 8)
- return;
- paintGuardChar(g, "bwb", "nnn", 0);
- leftGuardBar = currentX;
- for(int k = 0; k < 8; k++)
- {
- String s = "" + code.charAt(k);
- byte byte0 = -1;
- if(k <= 3)
- {
- int i = findChar(setEANLeftA, s);
- paintChar(g, "wbwb", setEANLeftA[i][1]);
- } else
- {
- int j = findChar(setEANRight, s);
- paintChar(g, "bwbw", setEANRight[j][1]);
- }
- if(k == 3)
- {
- centerGuardBarStart = currentX;
- paintGuardChar(g, "wbwbw", "nnnnn", 0);
- centerGuardBarEnd = currentX;
- }
- }
-
- rightGuardBar = currentX;
- paintGuardChar(g, "bwb", "nnn", 0);
- endOfCode = currentX;
- if(UPCEANSupplement2)
- paintSup2(g, code.substring(2, 4));
- else
- if(UPCEANSupplement5)
- paintSup5(g, code.substring(2, 7));
- }
-
- protected void paintUPCE(Graphics g)
- {
- boolean flag = false;
- boolean flag1 = false;
- int j = 0;
- String s1 = "";
- if(code.length() == 11 && checkCharacter)
- code = code + UPCEANCheck(code);
- if(code.length() < 12)
- return;
- j = (new Integer("" + code.charAt(11))).intValue();
- if(code.substring(3, 6).compareTo("000") == 0 || code.substring(3, 6).compareTo("100") == 0 || code.substring(3, 6).compareTo("200") == 0)
- s1 = code.substring(1, 3) + code.substring(8, 11) + code.charAt(3);
- if(code.substring(3, 6).compareTo("300") == 0 || code.substring(3, 6).compareTo("400") == 0 || code.substring(3, 6).compareTo("500") == 0 || code.substring(3, 6).compareTo("600") == 0 || code.substring(3, 6).compareTo("700") == 0 || code.substring(3, 6).compareTo("800") == 0 || code.substring(3, 6).compareTo("900") == 0)
- s1 = code.substring(1, 4) + code.substring(9, 11) + "3";
- if(code.substring(4, 6).compareTo("10") == 0 || code.substring(4, 6).compareTo("20") == 0 || code.substring(4, 6).compareTo("30") == 0 || code.substring(4, 6).compareTo("40") == 0 || code.substring(4, 6).compareTo("50") == 0 || code.substring(4, 6).compareTo("60") == 0 || code.substring(4, 6).compareTo("70") == 0 || code.substring(4, 6).compareTo("80") == 0 || code.substring(4, 6).compareTo("90") == 0)
- s1 = code.substring(1, 5) + code.substring(10, 11) + "4";
- if(code.substring(5, 6).compareTo("0") != 0)
- s1 = code.substring(1, 6) + code.substring(10, 11);
- codeText = s1 + j;
- paintGuardChar(g, "bwb", "nnn", 0);
- leftGuardBar = currentX;
- String s2 = UPCESystem0[j];
- if(UPCESytem == '1')
- s2 = UPCESystem1[j];
- for(int k = 0; k < s1.length(); k++)
- {
- String s = "" + s1.charAt(k);
- int i = -1;
- String as[][] = setUPCEOdd;
- if(s2.charAt(k) == 'E')
- as = setUPCEEven;
- i = findChar(as, s);
- paintChar(g, "wbwb", as[i][1]);
- }
-
- rightGuardBar = currentX;
- paintGuardChar(g, "wbwbwb", "nnnnnn", 0);
- endOfCode = currentX;
- if(UPCEANSupplement2)
- paintSup2(g, s1.substring(0, 2));
- else
- if(UPCEANSupplement5)
- paintSup5(g, s1.substring(0, 5));
- }
-
- protected void paintSup2(Graphics g, String s)
- {
- if(supplement.length() > 0)
- s = supplement;
- suplementTopMargin = (int)((double)barHeightPixels * (1.0D - supHeight));
- codeSup = s;
- if(s.length() != 2)
- return;
- currentX = (int)((double)currentX + (double)resolution * supSeparationCM);
- startSuplement = currentX;
- int i;
- try
- {
- i = Integer.valueOf(s).intValue();
- }
- catch(Exception exception)
- {
- i = 0;
- }
- String s1 = "OO";
- if(mod(i, 4D) == 1.0D)
- s1 = "OE";
- if(mod(i, 4D) == 2D)
- s1 = "EO";
- if(mod(i, 4D) == 3D)
- s1 = "EE";
- paintGuardChar(g, "bwb", "112", suplementTopMargin);
- String as[][] = setUPCEOdd;
- if(s1.charAt(0) == 'E')
- as = setUPCEEven;
- int j = findChar(as, "" + s.charAt(0));
- paintGuardChar(g, "wbwb", as[j][1], suplementTopMargin);
- paintGuardChar(g, "wb", "11", suplementTopMargin);
- as = setUPCEOdd;
- if(s1.charAt(1) == 'E')
- as = setUPCEEven;
- j = findChar(as, "" + s.charAt(1));
- paintGuardChar(g, "wbwb", as[j][1], suplementTopMargin);
- endSuplement = currentX;
- }
-
- protected void paintSup5(Graphics g, String s)
- {
- if(supplement.length() > 0)
- s = supplement;
- suplementTopMargin = (int)((double)barHeightPixels * (1.0D - supHeight));
- codeSup = s;
- if(s.length() != 5)
- return;
- boolean flag = true;
- int i = 0;
- int j = 0;
- for(int l = s.length() - 1; l >= 0; l--)
- {
- if(flag)
- i += (new Integer("" + s.charAt(l))).intValue();
- else
- j += (new Integer("" + s.charAt(l))).intValue();
- flag = !flag;
- }
-
- j = i * 3 + j * 9;
- String s1 = "" + j;
- int k = (new Integer("" + s1.charAt(s1.length() - 1))).intValue();
- String s2 = fiveSuplement[k];
- currentX = (int)((double)currentX + (double)resolution * supSeparationCM);
- startSuplement = currentX;
- paintGuardChar(g, "bwb", "112", suplementTopMargin);
- Object obj = null;
- for(int j1 = 0; j1 < 5; j1++)
- {
- String as[][] = setUPCEOdd;
- if(s2.charAt(j1) == 'E')
- as = setUPCEEven;
- int i1 = findChar(as, "" + s.charAt(j1));
- paintGuardChar(g, "wbwb", as[i1][1], suplementTopMargin);
- if(j1 < 4)
- paintGuardChar(g, "wb", "11", suplementTopMargin);
- }
-
- endSuplement = currentX;
- }
-
- protected void paintMAT25(Graphics g)
- {
- boolean flag = false;
- boolean flag1 = false;
- String s1 = code;
- paintChar(g, "bwbwbw", "wnnnnn");
- for(int j = 0; j < s1.length(); j++)
- {
- String s = "" + code.charAt(j);
- int i = findChar(set25, s);
- if(i >= 0)
- paintChar(g, "bwbwbw", set25[i][1] + "n");
- }
-
- paintChar(g, "bwbwbw", "wnnnnn");
- }
-
- protected void paintCODE39(Graphics g)
- {
- boolean flag = false;
- int k = 0;
- code = code.toUpperCase();
- paintChar(g, "bwbwbwbwb", set39[findChar(set39, "*")][1]);
- currentX = currentX + narrowBarPixels;
- for(int l = 0; l < code.length(); l++)
- {
- String s = "" + code.charAt(l);
- int i = findChar(set39, s);
- if(i > -1)
- {
- k += i;
- paintChar(g, "bwbwbwbwb", set39[i][1]);
- currentX = currentX + narrowBarPixels;
- }
- }
-
- if(checkCharacter)
- {
- int j = (int)mod(k, 43D);
- paintChar(g, "bwbwbwbwb", set39[j][1]);
- currentX = currentX + narrowBarPixels;
- if(checkCharacterInText)
- codeText = code + "" + set39[j][0];
- else
- codeText = code;
- }
- paintChar(g, "bwbwbwbwb", set39[findChar(set39, "*")][1]);
- }
-
- protected void paintCODE11(Graphics g)
- {
- boolean flag = false;
- int l = 0;
- paintChar(g, "bwbwbw", "nnwwnn");
- int i1 = 1;
- l = 0;
- for(int j1 = code.length() - 1; j1 >= 0; j1--)
- {
- l += findChar(set11, "" + code.charAt(j1)) * i1;
- if(++i1 == 11)
- i1 = 1;
- }
-
- int j = (int)mod(l, 11D);
- i1 = 2;
- l = j;
- for(int k1 = code.length() - 1; k1 >= 0; k1--)
- {
- l += findChar(set11, "" + code.charAt(k1)) * i1;
- if(++i1 == 10)
- i1 = 1;
- }
-
- int k = (int)mod(l, 11D);
- for(int l1 = 0; l1 < code.length(); l1++)
- {
- String s = "" + code.charAt(l1);
- int i = findChar(set11, s);
- if(i > -1)
- paintChar(g, "bwbwbw", set11[i][1] + "n");
- }
-
- if(checkCharacter)
- {
- paintChar(g, "bwbwbw", set11[j][1] + "n");
- if(checkCharacterInText)
- codeText = code + set11[j][0];
- else
- codeText = code;
- if(code.length() > 10)
- {
- paintChar(g, "bwbwbw", set11[k][1] + "n");
- if(checkCharacterInText)
- codeText = codeText + set11[k][0];
- else
- codeText = code;
- }
- }
- paintChar(g, "bwbwbw", "nnwwnn");
- }
-
- protected void paintCODABAR(Graphics g)
- {
- boolean flag = false;
- int k = 0;
- paintChar(g, "bwbwbwbw", setCODABAR[findChar(setCODABAR, "" + CODABARStartChar)][1] + "n");
- k = findChar(setCODABAR, "" + CODABARStartChar) + findChar(setCODABAR, "" + CODABARStopChar);
- for(int l = code.length() - 1; l >= 0; l--)
- k += findChar(setCODABAR, "" + code.charAt(l));
-
- int j = (int)mod(k, 16D);
- if(j != 0)
- j = 16 - j;
- for(int i1 = 0; i1 < code.length(); i1++)
- {
- String s = "" + code.charAt(i1);
- int i = findChar(setCODABAR, s);
- if(i > -1)
- paintChar(g, "bwbwbwbw", setCODABAR[i][1] + "n");
- }
-
- if(checkCharacter)
- {
- if(checkCharacterInText)
- codeText = code + setCODABAR[j][0];
- else
- codeText = code;
- paintChar(g, "bwbwbwbw", setCODABAR[j][1] + "n");
- }
- paintChar(g, "bwbwbwb", setCODABAR[findChar(setCODABAR, "" + CODABARStopChar)][1]);
- }
-
- protected void paintMSI(Graphics g)
- {
- boolean flag = false;
- int k = 0;
- paintChar(g, "bw", "wn");
- k = 0;
- String s1 = "";
- boolean flag1 = true;
- for(int l = code.length() - 1; l >= 0; l--)
- {
- if(!flag1)
- k += findChar(setMSI, "" + code.charAt(l));
- if(flag1)
- s1 = findChar(setMSI, "" + code.charAt(l)) + s1;
- flag1 = !flag1;
- }
-
- s1 = "" + (new Long(s1)).longValue() * 2L;
- for(int i1 = s1.length() - 1; i1 >= 0; i1--)
- k += findChar(setMSI, "" + s1.charAt(i1));
-
- int j = (int)mod(k, 10D);
- if(j != 0)
- j = 10 - j;
- for(int j1 = 0; j1 < code.length(); j1++)
- {
- String s = "" + code.charAt(j1);
- int i = findChar(setMSI, s);
- if(i > -1)
- paintChar(g, "bwbwbwbw", setMSI[i][1]);
- }
-
- if(checkCharacter)
- {
- paintChar(g, "bwbwbwb", setMSI[j][1]);
- if(checkCharacterInText)
- codeText = code + setMSI[j][0];
- else
- codeText = code;
- }
- paintChar(g, "wbwb", "nnwn");
- }
-
- 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 paintCODE39Ext(Graphics g)
- {
- boolean flag = false;
- int k = 0;
- paintChar(g, "bwbwbwbwb", set39[findChar(set39, "*")][1]);
- currentX = currentX + narrowBarPixels;
- for(int l = 0; l < code.length(); l++)
- {
- byte byte0 = (byte)code.charAt(l);
- if(byte0 <= 128)
- {
- String s1 = set39Ext[byte0];
- for(int i1 = 0; i1 < s1.length(); i1++)
- {
- String s = "" + s1.charAt(i1);
- int i = findChar(set39, s);
- if(i > -1)
- {
- k += i;
- paintChar(g, "bwbwbwbwb", set39[i][1]);
- currentX = currentX + narrowBarPixels;
- }
- }
-
- }
- }
-
- codeText = "";
- boolean flag1 = false;
- for(int k1 = 1; k1 <= code.length(); k1++)
- {
- int j1 = code.charAt(k1 - 1);
- if(j1 < 32 && j1 >= 0)
- {
- if(j1 == 13 || j1 == 9)
- codeText = codeText + " ";
- } else
- {
- codeText = codeText + (char)j1;
- }
- }
-
- if(checkCharacter)
- {
- int j = (int)mod(k, 43D);
- paintChar(g, "bwbwbwbwb", set39[j][1]);
- currentX = currentX + narrowBarPixels;
- if(checkCharacterInText)
- codeText = codeText + "" + set39[j][0];
- }
- paintChar(g, "bwbwbwbwb", set39[findChar(set39, "*")][1]);
- }
-
- protected void paintBAR93(Graphics g)
- {
- boolean flag = false;
- int j = 0;
- int k = 0;
- int l = 0;
- paintChar(g, "bwbwbw", "111141");
- for(int i1 = 0; i1 < code.length(); i1++)
- {
- String s = "" + code.charAt(i1);
- int i = findChar(set93, s);
- if(i > -1)
- {
- j += i;
- paintChar(g, "bwbwbw", set93[i][1]);
- }
- }
-
- int j1 = 1;
- j = 0;
- for(int k1 = code.length() - 1; k1 >= 0; k1--)
- {
- j += findChar(set93, "" + code.charAt(k1)) * j1;
- if(++j1 == 21)
- j1 = 1;
- }
-
- l = (int)mod(j, 47D);
- j1 = 2;
- j = l;
- for(int l1 = code.length() - 1; l1 >= 0; l1--)
- {
- j += findChar(set93, "" + code.charAt(l1)) * j1;
- if(++j1 == 16)
- j1 = 1;
- }
-
- k = (int)mod(j, 47D);
- if(checkCharacter)
- {
- paintChar(g, "bwbwbw", set93[l][1]);
- paintChar(g, "bwbwbw", set93[k][1]);
- if(checkCharacterInText)
- codeText = code + set93[l][0].charAt(0) + set93[k][0].charAt(0);
- else
- codeText = code;
- }
- paintChar(g, "bwbwbwb", "1111411");
- }
-
- protected void paintBAR93Ext(Graphics g)
- {
- boolean flag = false;
- int k1 = 0;
- int l1 = 0;
- int i2 = 0;
- paintChar(g, "bwbwbw", "111141");
- for(int j2 = 0; j2 < code.length(); j2++)
- {
- byte byte0 = (byte)code.charAt(j2);
- if(byte0 <= 128)
- {
- String s5 = set93Ext[byte0];
- String s;
- if(s5.length() == 3)
- {
- s = "" + s5.charAt(0) + s5.charAt(1);
- int i = findChar(set93, s);
- paintChar(g, "bwbwbw", set93[i][1]);
- s = "" + s5.charAt(2);
- } else
- {
- s = "" + s5.charAt(0);
- }
- int j = findChar(set93, s);
- k1 += j;
- paintChar(g, "bwbwbw", set93[j][1]);
- }
- }
-
- int k2 = 1;
- k1 = 0;
- for(int l2 = code.length() - 1; l2 >= 0; l2--)
- {
- byte byte1 = (byte)code.charAt(l2);
- if(byte1 <= 128)
- {
- String s6 = set93Ext[byte1];
- if(s6.length() == 3)
- {
- String s1 = "" + s6.charAt(0) + s6.charAt(1);
- int k = findChar(set93, s1);
- k1 += k * (k2 + 1);
- s1 = "" + s6.charAt(2);
- k = findChar(set93, s1);
- k1 += k * k2;
- if(++k2 == 21)
- k2 = 1;
- if(++k2 == 21)
- k2 = 1;
- } else
- {
- String s2 = "" + s6.charAt(0);
- int l = findChar(set93, s2);
- k1 += l * k2;
- if(++k2 == 21)
- k2 = 1;
- }
- }
- }
-
- i2 = (int)mod(k1, 47D);
- k2 = 2;
- k1 = i2;
- for(int i3 = code.length() - 1; i3 >= 0; i3--)
- {
- byte byte2 = (byte)code.charAt(i3);
- if(byte2 <= 128)
- {
- String s7 = set93Ext[byte2];
- if(s7.length() == 3)
- {
- String s3 = "" + s7.charAt(0) + s7.charAt(1);
- int i1 = findChar(set93, s3);
- k1 += i1 * (k2 + 1);
- s3 = "" + s7.charAt(2);
- i1 = findChar(set93, s3);
- k1 += i1 * k2;
- if(++k2 == 16)
- k2 = 1;
- if(++k2 == 16)
- k2 = 1;
- } else
- {
- String s4 = "" + s7.charAt(0);
- int j1 = findChar(set93, s4);
- k1 += j1 * k2;
- if(++k2 == 16)
- k2 = 1;
- }
- }
- }
-
- l1 = (int)mod(k1, 47D);
- if(checkCharacter)
- {
- paintChar(g, "bwbwbw", set93[i2][1]);
- paintChar(g, "bwbwbw", set93[l1][1]);
- if(checkCharacterInText)
- codeText = code + set93[i2][0].charAt(0) + set93[l1][0].charAt(0);
- else
- codeText = code;
- }
- paintChar(g, "bwbwbwb", "1111411");
- }
-
- protected void paintChar(Graphics g, String s, String s1)
- {
- paintChar2(g, s, s1, 0);
- }
-
- protected void paintChar2(Graphics g, String s, String s1, int i)
- {
- for(int j = 0; j < s.length(); j++)
- {
- char c = s.charAt(j);
- char c1 = s1.charAt(j);
- if(c1 == 'n')
- addBar(g, narrowBarPixels, c == 'b', i);
- if(c1 == 'w')
- addBar(g, widthBarPixels, c == 'b', i);
- if(c1 == '1')
- addBar(g, narrowBarPixels, c == 'b', i);
- if(c1 == '2')
- addBar(g, narrowBarPixels * 2, c == 'b', i);
- if(c1 == '3')
- addBar(g, narrowBarPixels * 3, c == 'b', i);
- if(c1 == '4')
- addBar(g, narrowBarPixels * 4, c == 'b', i);
- }
-
- }
-
- protected void paintGuardChar(Graphics g, String s, String s1, int i)
- {
- if(textFont != null && guardBars)
- {
- g.setFont(textFont);
- extraHeight = g.getFontMetrics().getHeight();
- }
- paintChar2(g, s, s1, i);
- extraHeight = 0;
- }
-
- protected void calculateSizes()
- {
- int i = code.length();
- narrowBarCM = X;
- widthBarCM = X * N;
- if(barType == 2)
- {
- if(mod(i, 2D) == 0.0D && checkCharacter)
- i++;
- if(mod(i, 2D) == 1.0D && !checkCharacter)
- i++;
- if(checkCharacter)
- i++;
- L = (double)(i / 2) * (3D + 2D * N) * X + 7D * X;
- }
- if(barType == 6)
- {
- if(checkCharacter)
- i++;
- L = (double)(i * 7) * X + 11D * X;
- }
- if(barType == 10)
- L = (double)(i * 7) * X + 11D * X;
- if(barType == 11)
- L = (double)(i * 7) * X + 11D * X;
- if(barType == 13)
- {
- if(checkCharacter)
- i++;
- if(Code128Set == 'C')
- L = (double)(11 * i + 35) * X;
- else
- L = (5.5D * (double)i + 35D) * X;
- }
- if(barType == 12)
- L = 56D * X + 11D * X;
- if(barType == 7)
- {
- if(checkCharacter)
- i++;
- L = (double)i * (3D + 2D * N) * X + 7D * X;
- }
- if(barType == 8)
- {
- if(checkCharacter)
- i++;
- L = (double)i * (3D + 2D * N) * X + 7D * X;
- }
- if(barType == 5)
- {
- if(checkCharacter)
- i++;
- L = (double)i * (4D + 4D * N) * X + (1.0D + N) * X + (2D + N) *…
Large files files are truncated, but you can click here to view the full file