📄 barcode.java
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2007-11-23 16:17:22
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: Barcode.java
package com.bokai.barcodes;
import com.bokai.drawing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.MemoryImageSource;
import java.io.*;
import java.util.Enumeration;
import java.util.NoSuchElementException;
// Referenced classes of package com.bokai.barcodes:
// BarcodeExtraTextPosition, BarcodeFileLicense, BarcodeLicense, BarcodeNotSupportedException,
// BarcodePainter, BarcodeSpec, BarcodeSymbol, BarcodeType,
// C2of5, CheckCharShowMode, Codabar, Code11,
// Code11Check, Code11DoubleCheck, Code128A, Code128Auto,
// Code128B, Code128C, Code39, Code39Check,
// Code39CheckExtended, Code39Extended, Code93, Code93Extended,
// EAN128A, EAN128Auto, EAN128B, EAN128C,
// EAN128CCheck10, EAN128CCheck10AI2, EAN128CCheck10AI3, EAN128CCheck10AI4,
// EAN13, EAN13_2, EAN13_5, EAN14,
// EAN8, EAN8_2, EAN8_5, ISBN,
// ISBN_5, ISSN, ISSN_2, ITF,
// ITF14, ITFMod10, ITFMod10Wt12, ITFMod10Wt21,
// Identcode, ImageEncoder, InvalidAddOnDataException, InvalidDataException,
// JpgEncoder, Leitcode, MSI, MsiCheck10,
// MsiCheck1010, MsiCheck11, MsiCheck1110, Planet,
// PngEncoder, Postnet, RM4SCCNoCheck, RoyalMail,
// SSCC18, Telepen, TelepenNumeric, UPCA,
// UPCA_2, UPCA_5, UPCE, UPCE_2,
// UPCE_5, BarEnumerator, Bar, Bars,
// CharDef
public class Barcode
{
class BarEnumerator1
implements BarEnumerator
{
public boolean nextBar(Bar bar)
{
int i = _symbol.getStyle();
if(_bEnumStart)
{
_bEnumStart = false;
_more = _bcenum.nextBars(_bars, _charDefBuffer);
int l = _bars.getCharDef().BCGETNUMSTRIPE();
_iBarInd = l - 1;
_nmWth = 0;
} else
{
if(!_more)
return false;
if(_iBarInd == -1)
{
_more = _bcenum.nextBars(_bars, _charDefBuffer);
if(!_more)
return false;
int i1 = _bars.getCharDef().BCGETNUMSTRIPE();
_iBarInd = i1 - 1;
_nmWth = 0;
}
}
do
{
int l1 = 0;
int k = -1;
int i2 = 0;
for(int k1 = _iBarInd; k1 >= 0; k1--)
{
int j = _bars.getCharDef().BCGETSTRIPE(k1);
if(CharDef.BCSTRIPEISBAR(j))
{
l1 = CharDef.BCSTRIPEWTHIND(j);
if(k == -1)
k = _nmWth;
if((i & 0x10000) != 0)
_nmWth += _anmBarWidth[0];
else
_nmWth += _anmBarWidth[l1];
if(k1 == 0)
i2 = _nmWth - k;
} else
{
if(k != -1)
i2 = _nmWth - k;
if((i & 0x10000) != 0)
_nmWth += _anmSpaceWidth[0];
else
_nmWth += _anmSpaceWidth[CharDef.BCSTRIPEWTHIND(j)];
}
if(i2 > 0)
{
int j2 = _bars.getStyle();
if((i & 0x10000) != 0)
if(getBarcodeType() == 22 || getBarcodeType() == 46)
{
if(l1 == 1)
j2 |= 0x10;
} else
if(getBarcodeType() == 31 || getBarcodeType() == 56)
if(l1 == 1)
j2 |= 0x20;
else
if(l1 == 2)
j2 |= 0x40;
else
if(l1 == 3)
j2 |= 0x10;
bar.setAll((_bars.getOffset() + k) * _iModuleWidth, i2 * _iModuleWidth, j2);
_iBarInd = k1 - 1;
return true;
}
}
_more = _bcenum.nextBars(_bars, _charDefBuffer);
if(!_more)
return false;
int j1 = _bars.getCharDef().BCGETNUMSTRIPE();
_iBarInd = j1 - 1;
_nmWth = 0;
} while(true);
}
int _iModuleWidth;
boolean _bEnumStart;
int _iBarInd;
int _nmWth;
Bars _bars;
CharDef _charDefBuffer;
boolean _more;
BarcodeSymbol.BarCharEnumerator _bcenum;
int _anmBarWidth[];
int _anmSpaceWidth[];
BarEnumerator1(int i)
{
_iModuleWidth = i;
_more = false;
_bEnumStart = true;
_bars = new Bars();
_charDefBuffer = new CharDef();
_bcenum = _symbol.enumerateBars();
_anmBarWidth = new int[5];
_anmSpaceWidth = new int[5];
_symbol.getBarExts(_anmBarWidth, 5);
_symbol.getSpaceExts(_anmSpaceWidth, 5);
}
}
public static class BarcodeTypeEnumerator
implements Enumeration
{
public boolean hasMoreElements()
{
return _current < 57;
}
public Object nextElement()
throws NoSuchElementException
{
if(_current >= 57)
throw new NoSuchElementException("BarcodeTypeEnumerator");
else
return Barcode._barcodeTypes[_current++];
}
int _current;
BarcodeTypeEnumerator()
{
_current = 0;
}
}
public Barcode()
throws ClassNotFoundException, InstantiationException, IllegalAccessException, BarcodeNotSupportedException
{
this(6, 0);
}
public Barcode(int i)
throws ClassNotFoundException, InstantiationException, IllegalAccessException, BarcodeNotSupportedException
{
this(i, 0);
}
public Barcode(int i, int j)
throws ClassNotFoundException, InstantiationException, IllegalAccessException, BarcodeNotSupportedException
{
_extraTextPrefix = "";
_defaultFont = new SimpleFont("SansSerif", 0, 11);
_style = j;
_symbol = null;
if(_static_invalidLicenseShortText != null)
_invalidLicenseShortText = _static_invalidLicenseShortText;
else
_invalidLicenseShortText = _license.getInvalidLicenseShortText();
_extraTextPrefix = _license.getBarcodeExtraText();
_bDataInvalid = false;
_bAddOnDataInvalid = false;
_invalidDataAction = 3;
_throwDataError = false;
_font = _defaultFont;
_orientation = 0;
_textAlign = 1;
_addOnTextAlign = 0;
_horzAlign = 0;
_vertAlign = 0;
_stretchText = true;
_uniBarHeight = false;
_showCode39StartStop = true;
_upcSmallFont = true;
_figureTransparent = false;
_retainAspectRatio = false;
_clrBack = SimpleColor.white;
_clrFore = SimpleColor.black;
_bPixelAlign = true;
_checkCharShowMode = 0;
_extraText = _extraTextPrefix;
_extraTextPosition = -1;
changeBarcodeType(i);
}
public static String ImageFormatToMimeType(int i)
{
if(i == 1)
return "image/png";
if(i == 3)
return "image/jpeg";
else
return "image/png";
}
private SimpleDimension calcSimpleTextSize(SimpleGraphics simplegraphics, String s, SimpleFont simplefont)
{
if(simplefont != null)
simplegraphics.setFont(simplefont);
SimpleDimension simpledimension = BarcodePainter.drawMultilineAlignedChars(simplegraphics, s.toCharArray(), 0, s.length(), 0, 0, simplegraphics.getFontMetrics(), 0, true);
return simpledimension;
}
private SimpleDimension calcTextSize(Graphics g, String s, SimpleFont simplefont)
{
SimpleGraphics simplegraphics = new SimpleGraphics(g);
if(simplefont != null)
simplegraphics.setFont(simplefont);
SimpleDimension simpledimension = BarcodePainter.drawMultilineAlignedChars(simplegraphics, s.toCharArray(), 0, s.length(), 0, 0, simplegraphics.getFontMetrics(), 0, true);
return simpledimension;
}
void changeBarcodeType(int i)
throws ClassNotFoundException, InstantiationException, IllegalAccessException, BarcodeNotSupportedException
{
if(_symbol != null && _symbol.getBarcodeType() == i)
return;
int j;
for(j = 0; j < _barcodeTypes.length; j++)
if(i == _barcodeTypes[j].getType())
break;
if(j >= _barcodeTypes.length)
{
throw new BarcodeNotSupportedException(i);
} else
{
_symbol = new BarcodeSymbol((BarcodeSpec)_barcodeTypes[j].getSpecClass().newInstance());
return;
}
}
static Class _mthclass$(String s)
{
try
{
return Class.forName(s);
}
catch(ClassNotFoundException classnotfoundexception)
{
throw new NoClassDefFoundError(classnotfoundexception.getMessage());
}
}
public void draw(SimpleGraphics simplegraphics, SimpleRectangle simplerectangle)
{
draw(simplegraphics, simplerectangle, getDrawingAttributes(), getBackSimpleColor());
}
public void draw(SimpleGraphics simplegraphics, SimpleRectangle simplerectangle, long l, SimpleColor simplecolor)
{
draw(simplegraphics, simplerectangle, l, simplecolor, null);
}
public void draw(SimpleGraphics simplegraphics, SimpleRectangle simplerectangle, long l, SimpleColor simplecolor, String s)
{
int i = simplerectangle.width;
int j = simplerectangle.height;
if(s != null && (i == 0 || j == 0))
{
SimpleDimension simpledimension = calcSimpleTextSize(simplegraphics, s, null);
if(i == 0)
i = simpledimension.width;
if(j == 0)
j = simpledimension.height;
simplerectangle.setSize(i, j);
}
drawHelper(simplegraphics, simplerectangle, l, simplecolor, s);
}
public void draw(SimpleGraphics simplegraphics, Rectangle rectangle, long l, Color color)
{
draw(simplegraphics, new SimpleRectangle(rectangle), l, new SimpleColor(color));
}
public void draw(Graphics g, Rectangle rectangle)
{
draw(g, rectangle, getDrawingAttributes(), getBackColor());
}
public void draw(Graphics g, Rectangle rectangle, long l, Color color)
{
draw(g, rectangle, l, color, null);
}
public void draw(Graphics g, Rectangle rectangle, long l, Color color, String s)
{
int i = rectangle.width;
int j = rectangle.height;
if(s != null && (i == 0 || j == 0))
{
SimpleDimension simpledimension = calcTextSize(g, s, null);
if(i == 0)
i = simpledimension.width;
if(j == 0)
j = simpledimension.height;
rectangle.setSize(i, j);
}
drawHelper(new SimpleGraphics(g), new SimpleRectangle(rectangle), l, new SimpleColor(color), s);
}
public void drawHelper(SimpleGraphics simplegraphics, SimpleRectangle simplerectangle, long l, SimpleColor simplecolor, String s)
{
SimpleColor simplecolor1 = simplegraphics.getColor();
SimpleFont simplefont = simplegraphics.getFont();
String s1 = null;
if(_invalidLicenseShortText != null)
s1 = _invalidLicenseShortText;
else
if((_bDataInvalid || _bAddOnDataInvalid) && _invalidDataAction == 3)
s1 = "Invalid Data";
if(s1 != null)
{
simplegraphics.setColor(simplecolor);
simplegraphics.drawRect(simplerectangle.x, simplerectangle.y, simplerectangle.width, simplerectangle.height);
simplegraphics.setColor(simplecolor1);
BarcodePainter.drawAlignedChars(simplegraphics, s1.toCharArray(), 0, s1.length(), simplerectangle.x + simplerectangle.width / 2, simplerectangle.y + simplerectangle.height / 2, simplegraphics.getFontMetrics(), 68);
} else
if(s != null)
{
simplegraphics.setColor(simplecolor);
simplegraphics.drawRect(simplerectangle.x, simplerectangle.y, simplerectangle.width, simplerectangle.height);
simplegraphics.setColor(simplecolor1);
BarcodePainter.drawMultilineAlignedChars(simplegraphics, s.toCharArray(), 0, s.length(), simplerectangle.x + simplerectangle.width / 2, simplerectangle.y + simplerectangle.height / 2, simplegraphics.getFontMetrics(), 68, false);
} else
{
BarcodePainter barcodepainter = new BarcodePainter(this, simplegraphics, simplerectangle, l, simplecolor);
barcodepainter.draw();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -