1 58 package org.krysalis.barcode.impl; 59 60 61 import org.apache.avalon.framework.configuration.Configurable; 62 import org.apache.avalon.framework.configuration.Configuration; 63 import org.apache.avalon.framework.configuration.ConfigurationException; 64 import org.krysalis.barcode.BarcodeDimension; 65 import org.krysalis.barcode.ClassicBarcodeLogicHandler; 66 import org.krysalis.barcode.output.Canvas; 67 import org.krysalis.barcode.output.CanvasProvider; 68 import org.krysalis.barcode.tools.Length; 69 70 75 public class Code128 extends GenericBarcodeImpl 76 implements Configurable { 77 78 81 public void configure(Configuration cfg) throws ConfigurationException { 82 Length mw = new Length(cfg.getChild("module-width").getValue("0.21mm"), "mm"); 84 this.moduleWidth = mw.getValueAsMillimeter(); 85 86 super.configure(cfg); 87 } 88 89 92 public double getBarWidth(int width) { 93 if ((width >= 1) && (width <= 4)) { 94 return width * moduleWidth; 95 } else { 96 throw new IllegalArgumentException ("Only widths 1 and 2 allowed"); 97 } 98 } 99 100 103 public BarcodeDimension calcDimensions(String msg) { 104 Code128LogicImpl impl = new Code128LogicImpl(); 105 int msgLen = impl.createEncodedMessage(msg).length + 1; 106 final double width = ((msgLen * 11) + 13) * getModuleWidth(); 107 final double qz = (hasQuietZone() ? quietZone : 0); 108 return new BarcodeDimension(width, getHeight(), 109 width + (2 * qz), getHeight(), 110 quietZone, 0.0); 111 } 112 113 116 public void generateBarcode(CanvasProvider canvas, String msg) { 117 if ((msg == null) || (msg.length() == 0)) { 118 throw new NullPointerException ("Parameter msg must not be empty"); 119 } 120 121 ClassicBarcodeLogicHandler handler = 122 new DefaultCanvasLogicHandler(this, new Canvas(canvas)); 123 125 Code128LogicImpl impl = new Code128LogicImpl(); 126 impl.generateBarcodeLogic(handler, msg); 127 } 128 129 130 } | Popular Tags |