All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.printer.zpl2.labelCmd.barcode.ZplCode128BarCode Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.printer.zpl2.labelCmd.barcode;

import com.hfg.graphics.units.GfxContext;
import com.hfg.graphics.units.GfxSize;
import com.hfg.graphics.units.Millimeters;
import com.hfg.graphics.units.Points;
import com.hfg.printer.zpl2.ZplDocument;
import com.hfg.printer.zpl2.ZplOrientation;
import com.hfg.printer.zpl2.labelCmd.ZplLabelCmdImpl;

import java.io.IOException;
import java.io.Writer;

//------------------------------------------------------------------------------

/**
 ZPL Code 128 bar code label command.
 
@author J. Alex Taylor, hairyfatguy.com, Jessica Hvozdovich
*/ //------------------------------------------------------------------------------ // com.hfg XML/HTML Coding Library // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com // [email protected] //------------------------------------------------------------------------------ public class ZplCode128BarCode extends ZplLabelCmdImpl { // MUD command to switch to DPI private static final String CMD_MUD = "^MUD"; // BY global barcode wrapper for sizing private static final String CMD_BY = "^BY"; // BC for 128 barcode private static final String CMD_BC = "^BC"; // MUD command to return to mm private static final String CMD_MUM = "^MUM"; private ZplOrientation mOrientation; private GfxSize mWidth = sDefaultWidth; private Float mRatio = sDefaultRatio; private GfxSize mHeight = sDefaultHeight; private Boolean mPrintInterpretationLine; private Boolean mPrintInterpretationLineAboveCode; private Boolean mPrintCheckDigit; private static GfxSize sDefaultWidth = new Points(4); private static Float sDefaultRatio = 3.0f; private static GfxSize sDefaultHeight = new Points(105); //########################################################################### // CONSTRUCTORS //########################################################################### //-------------------------------------------------------------------------- public ZplCode128BarCode() { } //-------------------------------------------------------------------------- public ZplCode128BarCode(ZplOrientation inOrientation, GfxSize inHeight) { setOrientation(inOrientation); mHeight = inHeight; } //-------------------------------------------------------------------------- public ZplCode128BarCode(GfxSize inHeight) { mHeight = inHeight; } //########################################################################### // PUBLIC METHODS //########################################################################### //-------------------------------------------------------------------------- public ZplCode128BarCode setOrientation(ZplOrientation inValue) { mOrientation = inValue; return this; } //-------------------------------------------------------------------------- public ZplOrientation getOrientation() { return mOrientation; } //-------------------------------------------------------------------------- public ZplCode128BarCode setHeight(GfxSize inValue) { mHeight = inValue; if (getDoc() != null) { mHeight.setGfxContext(new GfxContext(getDoc().getResolution())); } return this; } //-------------------------------------------------------------------------- public GfxSize getHeight() { return mHeight; } //-------------------------------------------------------------------------- public ZplCode128BarCode setWidth(GfxSize inValue) { mWidth = inValue; if (getDoc() != null) { mWidth.setGfxContext(new GfxContext(getDoc().getResolution())); } return this; } //-------------------------------------------------------------------------- public GfxSize getWidth() { return mWidth; } //-------------------------------------------------------------------------- public ZplCode128BarCode setRatio(Float inValue) { mRatio = inValue; return this; } //-------------------------------------------------------------------------- public Float getRatio() { return mRatio; } //-------------------------------------------------------------------------- public ZplCode128BarCode setPrintInterpretationLine(Boolean inValue) { mPrintInterpretationLine = inValue; return this; } //-------------------------------------------------------------------------- public ZplCode128BarCode setPrintInterpretationLineAboveCode(Boolean inValue) { mPrintInterpretationLineAboveCode = inValue; // In order to print above, general printing of the interpretation line also need to be enabled if (inValue) { setPrintInterpretationLine(inValue); } return this; } //-------------------------------------------------------------------------- public ZplCode128BarCode setPrintCheckDigit(Boolean inValue) { mPrintCheckDigit = inValue; return this; } //-------------------------------------------------------------------------- @Override public ZplLabelCmdImpl setDoc(ZplDocument inValue) { super.setDoc(inValue); GfxContext gfxContext = new GfxContext(inValue.getResolution()); if (mHeight != null) { mHeight.setGfxContext(gfxContext); } return this; } //-------------------------------------------------------------------------- @Override public void toZPL(Writer inWriter) throws IOException { //Example - barcode defaults leveraged for width dimensions //^BY4,3,105 ^BA,,N^FDP-20180507-71 // ^BYl,m,n // l = width default bar code module width in dots 1-100 [2 (default)] // m = ratio between wide bars and narrow bars between 2 and 3, larger for fewer scan failures [3 (default)] // n = height default bar code height in dots [10 (default)] // ^BXo,h,f,g,e // o = orientation (N (no rotation), R (90 degrees clockwise), I(180 degrees clockwise, B (270 degrees clockwise)) // h = bar code height // f = print interpretation line [Y or N (default)] // g = print interpretation line above code [Y (default) or N] // e = print check digit [Y (default) or N] inWriter.write(CMD_MUD); inWriter.write(CMD_BY); inWriter.write(buildZplParamList(mWidth, mRatio, mHeight)); inWriter.write(CMD_BC); inWriter.write(buildZplParamList(mOrientation != null ? mOrientation.getAbbrev() : null, mHeight, mPrintInterpretationLine, mPrintInterpretationLineAboveCode, mPrintCheckDigit)); inWriter.write(CMD_MUM); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy