Skip to content

Commit

Permalink
Updates to #114
Browse files Browse the repository at this point in the history
- Add tests
- Add to README.md
- Add to contributors
- Update example to include widths
- Update default to match initialised printer.
  • Loading branch information
mike42 committed Apr 23, 2016
1 parent 43c1cd0 commit f117ca3
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
@@ -1,7 +1,7 @@
# escpos-php contributors

This file contains a list of people who have made contributions of
code which to the public repository of escpos-php.
code which appear in the public repository of escpos-php.

Main repository: [mike42/escpos-php](https://github.com/mike42/escpos-php) ([online contributor list](https://github.com/mike42/escpos-php/graphs/contributors))

Expand All @@ -10,6 +10,7 @@ Main repository: [mike42/escpos-php](https://github.com/mike42/escpos-php) ([onl
- [Mareks Sudniks](https://github.com/marech)
- [matiasgaston](https://github.com/matiasgaston)
- [Mike Stivala](https://github.com/brndwgn)
- [Nicholas Long](https://github.com/longsview)

Via fork: [wdoyle/EpsonESCPOS-PHP](https://github.com/wdoyle/EpsonESCPOS-PHP):

Expand Down
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -354,6 +354,13 @@ Parameters:

- `int $height`: Height in dots. If not specified, 8 will be used.

### setBarcodeWidth($width)
Set barcode bar width.

Parameters:

- `int $width`: Bar width in dots. If not specified, 3 will be used. Values above 6 appear to have no effect.

### setColor($color)
Select print color - on printers that support multiple colors.

Expand Down
32 changes: 28 additions & 4 deletions example/barcode.php
Expand Up @@ -5,17 +5,41 @@

$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector);

/* Height and width */
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
$printer->text("Height and bar width\n");
$printer->selectPrintMode();
$heights = array(1, 2, 4, 8, 16, 32);
$widths = array(1, 2, 3, 4, 5, 6, 7, 8);
$printer -> text("Default look\n");
$printer->barcode("ABC", Printer::BARCODE_CODE39);

$printer->setBarcodeHeight(40);
foreach($heights as $height) {
$printer -> text("\nHeight $height\n");
$printer->setBarcodeHeight($height);
$printer->barcode("ABC", Printer::BARCODE_CODE39);
}
foreach($widths as $width) {
$printer -> text("\nWidth $width\n");
$printer->setBarcodeWidth($width);
$printer->barcode("ABC", Printer::BARCODE_CODE39);
}
$printer->feed();
// Set to something sensible for the rest of the examples
$printer->setBarcodeHeight(40);
$printer->setBarcodeWidth(2);

/* Text position */
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
$printer->text("Text position\n");
$printer->selectPrintMode();
$hri = array (
Printer::BARCODE_TEXT_NONE => "No text",
Printer::BARCODE_TEXT_ABOVE => "Above",
Printer::BARCODE_TEXT_BELOW => "Below",
Printer::BARCODE_TEXT_ABOVE | Printer::BARCODE_TEXT_BELOW => "Both"
Printer::BARCODE_TEXT_NONE => "No text",
Printer::BARCODE_TEXT_ABOVE => "Above",
Printer::BARCODE_TEXT_BELOW => "Below",
Printer::BARCODE_TEXT_ABOVE | Printer::BARCODE_TEXT_BELOW => "Both"
);
foreach ($hri as $position => $caption) {
$printer->text($caption . "\n");
Expand Down
7 changes: 4 additions & 3 deletions src/Mike42/Escpos/Printer.php
Expand Up @@ -627,11 +627,12 @@ public function setBarcodeHeight($height = 8)
}

/**
* Set barcode width.
* Set barcode bar width.
*
* @param int $width Width in dots. If not specified, 2 will be used.
* @param int $width Bar width in dots. If not specified, 3 will be used.
* Values above 6 appear to have no effect.
*/
public function setBarcodeWidth($width = 2)
public function setBarcodeWidth($width = 3)
{
self::validateInteger($width, 1, 255, __FUNCTION__);
$this -> connector -> write(self::GS . "w" . chr($width));
Expand Down
Binary file modified test/integration/resources/output/barcode.bin
Binary file not shown.
33 changes: 32 additions & 1 deletion test/unit/EscposTest.php
Expand Up @@ -390,12 +390,43 @@ public function testSetBarcodeHeightTooLarge()
$this -> printer -> setBarcodeHeight(256);
}

public function tesSetBarcodeHeightNonInteger()
public function testSetBarcodeHeightNonInteger()
{
$this -> setExpectedException('InvalidArgumentException');
$this -> printer -> setBarcodeHeight('hello');
}

/* Set barcode width */
public function testSetBarcodeWidthDefault()
{
$this -> printer -> setBarcodeWidth();
$this -> checkOutput("\x1b@\x1dw\x03");
}

public function testBarcodeWidth1()
{
$this -> printer -> setBarcodeWidth(1);
$this -> checkOutput("\x1b@\x1dw\x01");
}

public function testSetBarcodeWidthNegative()
{
$this -> setExpectedException('InvalidArgumentException');
$this -> printer -> setBarcodeWidth(-1);
}

public function testSetBarcodeWidthTooLarge()
{
$this -> setExpectedException('InvalidArgumentException');
$this -> printer -> setBarcodeWidth(256);
}

public function testSetBarcodeWidthNonInteger()
{
$this -> setExpectedException('InvalidArgumentException');
$this -> printer -> setBarcodeWidth('hello');
}

/* Barcode text position */
public function testSetBarcodeTextPositionDefault()
{
Expand Down

0 comments on commit f117ca3

Please sign in to comment.