From f117ca325dcef12dd50c65b688273e8a2936273e Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Sat, 23 Apr 2016 15:16:01 +1000 Subject: [PATCH] Updates to #114 - Add tests - Add to README.md - Add to contributors - Update example to include widths - Update default to match initialised printer. --- CONTRIBUTORS.md | 3 +- README.md | 7 ++++ example/barcode.php | 32 ++++++++++++++--- src/Mike42/Escpos/Printer.php | 7 ++-- test/integration/resources/output/barcode.bin | Bin 2342 -> 2670 bytes test/unit/EscposTest.php | 33 +++++++++++++++++- 6 files changed, 73 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 1299709b..1212d0b2 100644 --- a/CONTRIBUTORS.md +++ b/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)) @@ -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): diff --git a/README.md b/README.md index c65ced3e..80c8adbb 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/example/barcode.php b/example/barcode.php index 80351458..7bc091c3 100644 --- a/example/barcode.php +++ b/example/barcode.php @@ -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"); diff --git a/src/Mike42/Escpos/Printer.php b/src/Mike42/Escpos/Printer.php index a8ecf27c..7b6ac470 100644 --- a/src/Mike42/Escpos/Printer.php +++ b/src/Mike42/Escpos/Printer.php @@ -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)); diff --git a/test/integration/resources/output/barcode.bin b/test/integration/resources/output/barcode.bin index 79a2daf803edde452d5e0e47aa7e2545bb108962..2ff58d9f21f27ea34298eb16337ddc85fbd1d45d 100644 GIT binary patch delta 344 zcmZ1`^iHH++Cf^;z#}y?J)=Y+F)u|SDX~bQJTs*vgG*YG!6h{H8L2gq3+FTB|86pH!RSvfpB4i8{Vn)>nbV@ngDL_^JK*LOdVyvjjfbJ+~LlrUy Z3bCUK0sT-8^aI2Tz;FRNU?Zy{CjdmyR_p)( delta 15 WcmaDSvP_6o+Cer$W3w-#A}0VPl>_qt diff --git a/test/unit/EscposTest.php b/test/unit/EscposTest.php index 6e39c94e..f79dfc57 100644 --- a/test/unit/EscposTest.php +++ b/test/unit/EscposTest.php @@ -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() {