-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MatthiasVets/code128AndGraficBox
Add Code128 and grafic box + small fixes
- Loading branch information
Showing
7 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/fr/w3blog/zpl/model/element/ZebraBarCode128.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/fr/w3blog/zpl/model/element/ZebraGraficBox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/test/java/fr/w3blog/zpl/model/element/ZebraBarCode128Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
src/test/java/fr/w3blog/zpl/model/element/ZebraGraficBoxTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |