Skip to content

Commit

Permalink
Merge pull request #1 from MatthiasVets/code128AndGraficBox
Browse files Browse the repository at this point in the history
Add Code128 and grafic box + small fixes
  • Loading branch information
w3blogfr committed Nov 3, 2014
2 parents cc92b1a + ca7e8d3 commit e81430f
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 4 deletions.
30 changes: 29 additions & 1 deletion src/main/java/fr/w3blog/zpl/model/element/ZebraBarCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class ZebraBarCode extends ZebraElement {
* Parameters used to print text( default on bellow)
*
*/
boolean showTextInterpretation;
boolean showTextInterpretation = true;

/**
* Parameters to set to true if you want textInterpretation above code (top)
Expand Down Expand Up @@ -82,6 +82,34 @@ public ZebraBarCode(int positionX, int positionY, String text, int barCodeHeigth
this.moduleWidth = moduleWidth;
this.wideBarRatio = wideBarRatio;
}

/**
* Default Constructor width position and text
*
* @param positionX
* left margin (explain in dots)
* @param positionY
* top margin (explain in dots)
* @param text
* code to write
* @param barCodeHeigth
* height of code bar
* @param showTextInterpretation
* true to print interpretation line
* @param moduleWidth
* width(optionnal) of code bar
* @param wideBarRatio
* wide bar to narrow bar width ratio
*/
public ZebraBarCode(int positionX, int positionY, String text, int barCodeHeigth, boolean showTextInterpretation, int moduleWidth, int wideBarRatio) {
this.positionX = positionX;
this.positionY = positionY;
this.barCodeHeigth = barCodeHeigth;
this.showTextInterpretation = showTextInterpretation;
this.text = text;
this.moduleWidth = moduleWidth;
this.wideBarRatio = wideBarRatio;
}

/**
* Constructeur used to print text (above or below) with code
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/fr/w3blog/zpl/model/element/ZebraBarCode128.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package fr.w3blog.zpl.model.element;

import fr.w3blog.zpl.model.PrinterOptions;
import fr.w3blog.zpl.utils.ZplUtils;

/**
* Element to create a bar code 128
*
* Zpl command : ^BC
*
* @author matthiasvets
*
*/
public class ZebraBarCode128 extends ZebraBarCode {

private boolean checkDigit43 = false;

public ZebraBarCode128(int positionX, int positionY, String text, int barCodeHeigth) {
super(positionX, positionY, text, barCodeHeigth);
}

public ZebraBarCode128(int positionX, int positionY, String text, int barCodeHeigth, int barCodeWidth, int wideBarRatio) {
super(positionX, positionY, text, barCodeHeigth, barCodeWidth, wideBarRatio);
}

public ZebraBarCode128(int positionX, int positionY, String text, int barCodeHeigth, boolean showTextInterpretation, int barCodeWidth, int wideBarRatio) {
super(positionX, positionY, text, barCodeHeigth, showTextInterpretation, barCodeWidth, wideBarRatio);
}

public ZebraBarCode128(int positionX, int positionY, String text, int barCodeHeigth, int barCodeWidth, int wideBarRatio, boolean checkDigit43) {
super(positionX, positionY, text, barCodeHeigth, barCodeWidth, wideBarRatio);
this.setCheckDigit43(checkDigit43);
}

public ZebraBarCode128(int positionX, int positionY, String text, int barCodeHeigth, boolean showTextInterpretation, boolean showTextInterpretationAbove) {
super(positionX, positionY, text, barCodeHeigth, showTextInterpretation, showTextInterpretationAbove);
}

@Override
public String getZplCode(PrinterOptions printerOptions) {
StringBuilder zpl = getStartZplCodeBuilder();
zpl.append(ZplUtils.zplCommandSautLigne("BC", zebraRotation.getLetter(), barCodeHeigth, checkDigit43, showTextInterpretation, showTextInterpretationAbove));
zpl.append("^FD");
zpl.append(text);
zpl.append(ZplUtils.zplCommandSautLigne("FS"));
return zpl.toString();
}

public boolean isCheckDigit43() {
return checkDigit43;
}

public ZebraBarCode128 setCheckDigit43(boolean checkDigit43) {
this.checkDigit43 = checkDigit43;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ZebraBarCode39(int positionX, int positionY, String text, int barCodeHeig
@Override
public String getZplCode(PrinterOptions printerOptions) {
StringBuilder zpl = getStartZplCodeBuilder();
zpl.append(ZplUtils.zplCommandSautLigne("B3", zebraRotation.getLetter(), checkDigit43, barCodeHeigth, showTextInterpretation, showTextInterpretationAbove));
zpl.append(ZplUtils.zplCommandSautLigne("B3", zebraRotation.getLetter(), barCodeHeigth, checkDigit43, showTextInterpretation, showTextInterpretationAbove));
zpl.append("^FD");
zpl.append(text);
zpl.append(ZplUtils.zplCommandSautLigne("FS"));
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/fr/w3blog/zpl/model/element/ZebraGraficBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package fr.w3blog.zpl.model.element;

import fr.w3blog.zpl.model.PrinterOptions;
import fr.w3blog.zpl.model.ZebraElement;
import fr.w3blog.zpl.utils.ZplUtils;

/**
* Zebra element to create a box (or line)
*
* Zpl command : ^GB
*
* @author matthiasvets
*
*/
public class ZebraGraficBox extends ZebraElement {

private Integer width;
private Integer height;
private Integer borderTickness;
private String lineColor;

public ZebraGraficBox(int positionX, int positionY,Integer width, Integer height, Integer borderTickness,String lineColor) {
this.positionX = positionX;
this.positionY = positionY;
this.width = width;
this.height = height;
this.borderTickness = borderTickness;
this.lineColor = lineColor;
}


/* (non-Javadoc)
* @see fr.w3blog.zpl.model.element.ZebraElement#getZplCode(fr.w3blog.zpl.model.PrinterOptions)
*/
@Override
public String getZplCode(PrinterOptions printerOptions) {
StringBuilder zpl = new StringBuilder();
zpl.append(getZplCodePosition());
zpl.append("\n");
zpl.append(ZplUtils.zplCommand("GB", width, height, borderTickness, lineColor));
zpl.append("^FS");
zpl.append("\n");
return zpl.toString();
}

protected String getZplCodePosition() {
StringBuffer zpl = new StringBuffer("");
if (positionX != null && positionY != null) {
zpl.append(ZplUtils.zplCommand("FO", positionX, positionY));
}
return zpl.toString();
}

}
4 changes: 2 additions & 2 deletions src/main/java/fr/w3blog/zpl/model/element/ZebraText.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ public String getZplCode(PrinterOptions printerOptions) {
if (fontSize != null && zebraFont != null) {
//This element has specified size and font
Integer[] dimension = ZplUtils.extractDotsFromFont(zebraFont, fontSize, printerOptions.getZebraPPP());
zpl.append(ZplUtils.zplCommand("A", zebraFont.getLetter(), zebraRotation.getLetter(), dimension[0], dimension[1]));
zpl.append(ZplUtils.zplCommand("A", zebraFont.getLetter() + zebraRotation.getLetter(), dimension[0], dimension[1]));
} else if (fontSize != null && printerOptions.getDefaultZebraFont() != null) {
//This element has specified size, but with default font
Integer[] dimension = ZplUtils.extractDotsFromFont(printerOptions.getDefaultZebraFont(), fontSize, printerOptions.getZebraPPP());
zpl.append(ZplUtils.zplCommand("A", printerOptions.getDefaultZebraFont().getLetter(), zebraRotation.getLetter(), dimension[0], dimension[1]));
zpl.append(ZplUtils.zplCommand("A", printerOptions.getDefaultZebraFont().getLetter() + zebraRotation.getLetter(), dimension[0], dimension[1]));
}

zpl.append("^FH\\^FD");//We allow hexadecimal and start element
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/fr/w3blog/zpl/model/element/ZebraBarCode128Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fr.w3blog.zpl.model.element;

import junit.framework.TestCase;
import fr.w3blog.zpl.model.element.ZebraBarCode128;

public class ZebraBarCode128Test extends TestCase {

public void testZplOutput() {
ZebraBarCode128 barcode = new ZebraBarCode128(70, 1000, "0235600703875191516022937128", 190, false, 4, 2);
assertEquals("^FT70,1000\n^BY4,2,190\n^BCN,190,N,N,N\n^FD0235600703875191516022937128^FS\n", barcode.getZplCode(null));
}
}
12 changes: 12 additions & 0 deletions src/test/java/fr/w3blog/zpl/model/element/ZebraGraficBoxTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fr.w3blog.zpl.model.element;

import junit.framework.TestCase;
import fr.w3blog.zpl.model.element.ZebraGraficBox;

public class ZebraGraficBoxTest extends TestCase {

public void testZplOutput() {
ZebraGraficBox zebraGraficBox = new ZebraGraficBox(10, 10, 50, 760, 3, "B");
assertEquals("^FO10,10\n^GB50,760,3,B^FS\n", zebraGraficBox.getZplCode(null));
}
}

0 comments on commit e81430f

Please sign in to comment.