diff --git a/htdocs/admin/receiptprinter.php b/htdocs/admin/receiptprinter.php index 6184bebd97f..42b0ecb9ea9 100644 --- a/htdocs/admin/receiptprinter.php +++ b/htdocs/admin/receiptprinter.php @@ -166,6 +166,24 @@ if ($action == 'testprinter' && $user->admin) { $action = ''; } +if ($action == 'testtemplate' && $user->admin) { + $error=0; + // if (empty($printerid)) { + // $error++; + // setEventMessages($langs->trans("PrinterIdEmpty"), null, 'errors'); + // } + + // if (! $error) { + // // test + // $ret = $printer->sendTestToPrinter($printerid); + // if ($ret == 0) { + setEventMessages($langs->trans("TestTemplateToPrinter", $printername), null); + // } else { + // setEventMessages($printer->error, $printer->errors, 'errors'); + // } + // } + $action = ''; +} if ($action == 'updatetemplate' && $user->admin) { $error=0; @@ -190,6 +208,29 @@ if ($action == 'updatetemplate' && $user->admin) { $action = ''; } +if ($action == 'addtemplate' && $user->admin) { + $error=0; + $db->begin(); + if (empty($templatename)) { + $error++; + setEventMessages($langs->trans("TemplateNameEmpty"), null, 'errors'); + } + + if (! $error) { + $result= $printer->addTemplate($templatename, $template); + if ($result > 0) $error++; + + if (! $error) { + $db->commit(); + setEventMessages($langs->trans("TemplateAdded", $templatename), null); + } else { + $db->rollback(); + dol_print_error($db); + } + } + $action = ''; +} + /* * View @@ -345,7 +386,7 @@ if ($mode == 'template' && $user->admin) { dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic'); print $langs->trans("ReceiptPrinterTemplateDesc")."

\n"; - print ''."\n"; + print '
'."\n"; print ''; print ''; print ''; @@ -359,8 +400,7 @@ if ($mode == 'template' && $user->admin) { setEventMessages($printer->error, $printer->errors, 'errors'); } else { $max = count($printer->listprinterstemplates); - for ($line=0; $line < $max; $line++) - { + for ($line=0; $line < $max; $line++) { print ''; if ($action=='edittemplate' && $printer->listprinterstemplates[$line]['rowid']==$templateid) { print ''; @@ -392,6 +432,14 @@ if ($mode == 'template' && $user->admin) { print '
'.$langs->trans("Name").''.$langs->trans("Template").'
'; if ($action!='edittemplate') { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; } else { print '
'; diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index ef529f39d9a..1f9ea78bf95 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2015-2019 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -91,13 +91,19 @@ * */ -require_once DOL_DOCUMENT_ROOT .'/includes/mike42/escpos-php/Escpos.php'; +require_once DOL_DOCUMENT_ROOT .'/includes/mike42/escpos-php/autoload.php'; +use Mike42\Escpos\PrintConnectors\FilePrintConnector; +use Mike42\Escpos\PrintConnectors\NetworkPrintConnector; +use Mike42\Escpos\PrintConnectors\WindowsPrintConnector; +use Mike42\Escpos\CapabilityProfile; +use Mike42\Escpos\Printer; +use Mike42\Escpos\EscposImage; /** * Class to manage Receipt Printers */ -class dolReceiptPrinter extends Escpos +class dolReceiptPrinter extends Printer { const CONNECTOR_DUMMY = 1; const CONNECTOR_FILE_PRINT = 2; @@ -423,6 +429,29 @@ class dolReceiptPrinter extends Escpos return $error; } + /** + * Function to add a printer template in db + * + * @param string $name Template name + * @param int $template Template + * @return int 0 if OK; >0 if KO + */ + public function addTemplate($name, $template) + { + global $conf; + $error = 0; + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'printer_receipt_template'; + $sql.= ' (name, template, entity) VALUES ("'.$this->db->escape($name).'"'; + $sql.= ', "'.$this->db->escape($template).'", '.$conf->entity.')'; + $resql = $this->db->query($sql); + if (! $resql) { + $error++; + $this->errors[] = $this->db->lasterror; + } + return $error; + } + + /** * Function to Update a printer template in db * @@ -458,16 +487,17 @@ class dolReceiptPrinter extends Escpos { global $conf; $error = 0; - $img = new EscposImage(DOL_DOCUMENT_ROOT .'/theme/common/dolibarr_logo_bw.png'); + $img = EscposImage::load(DOL_DOCUMENT_ROOT .'/theme/common/dolibarr_logo_bw.png'); + //$this->profile = CapabilityProfile::load("TM-T88IV"); $ret = $this->initPrinter($printerid); if ($ret>0) { setEventMessages($this->error, $this->errors, 'errors'); } else { try { - $this->printer->graphics($img); + $this->printer->bitImage($img); $this->printer->text("Hello World!\n"); - $testStr = "Testing 123"; - $this->printer->qrCode($testStr); + $testStr = "1234567890"; + $this->printer->barcode($testStr); $this->printer->text("Most simple example\n"); $this->printer->feed(); $this->printer->cut(); @@ -687,7 +717,7 @@ class dolReceiptPrinter extends Escpos $this->connector = 'CONNECTOR_UNKNOWN'; break; } - $this->printer = new Escpos($this->connector); + $this->printer = new Printer($this->connector, $this->profile); } catch (Exception $e) { $this->errors[] = $e->getMessage(); $error++; diff --git a/htdocs/includes/mike42/escpos-php/.coveralls.yml b/htdocs/includes/mike42/escpos-php/.coveralls.yml new file mode 100644 index 00000000000..b33373af905 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/.coveralls.yml @@ -0,0 +1,4 @@ +service_name: travis-ci +coverage_clover: build/logs/clover.xml +json_path: build/logs/coveralls-upload.json + diff --git a/htdocs/includes/mike42/escpos-php/.gitignore b/htdocs/includes/mike42/escpos-php/.gitignore index 0e8fc4a31ee..8632f891ad4 100644 --- a/htdocs/includes/mike42/escpos-php/.gitignore +++ b/htdocs/includes/mike42/escpos-php/.gitignore @@ -10,3 +10,7 @@ doc/doxygen_sqlite3.db # composer files vendor/ + +# other build files +build/* +*.phar diff --git a/htdocs/includes/mike42/escpos-php/.travis.yml b/htdocs/includes/mike42/escpos-php/.travis.yml new file mode 100644 index 00000000000..04ffb6523b6 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/.travis.yml @@ -0,0 +1,46 @@ +--- +dist: trusty +sudo: required + +language: php + +php: + - 5.4 + - 5.5 + - 5.6 + - 7.0 + - 7.1 + - 7.2 + - nightly + - hhvm-3.21 + - hhvm-nightly + +matrix: + allow_failures: + - php: nightly + - php: hhvm-nightly + +before_install: + - sudo apt-get -qq update + - sudo apt-get install -y imagemagick ghostscript + +install: + - composer install + +before_script: + # Install 'imagick' plugin + - bash -c 'if [[ $TRAVIS_PHP_VERSION != hhvm* ]]; then printf "\n" | pecl install imagick; fi' + # Directory for coverage report + - mkdir -p build/logs/ + +script: + # Check code style + - php vendor/bin/phpcs --standard=psr2 src/ -n + # Run tests + - php vendor/bin/phpunit --coverage-clover build/logs/clover.xml + +after_success: + # Upload coverage statistics to coveralls service after test + - wget -c -nc https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar + - php coveralls.phar -v +... diff --git a/htdocs/includes/mike42/escpos-php/CONTRIBUTING.md b/htdocs/includes/mike42/escpos-php/CONTRIBUTING.md new file mode 100644 index 00000000000..326e1d093ac --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/CONTRIBUTING.md @@ -0,0 +1,65 @@ +# How to contribute + +This project is open to many different types of contribution. You can help with improving the documentation and examples, sharing your insights on the issue tracker, adding fixes to the code, providing test cases, or just [writing about your hardware setup that you use](https://github.com/mike42/escpos-php/issues/new). + +## Issue tracker + +Open issues of all sorts are tracked on the [issue tracker](https://github.com/mike42/escpos-php/issues). Please check [the FAQ](https://github.com/mike42/escpos-php/blob/development/doc/FAQ.md) before you post, and practice good [bug tracker etiquette](https://bugzilla.mozilla.org/page.cgi?id=etiquette.html) to keep it running smoothly. + +Issues are [loosely categorised](https://github.com/mike42/escpos-php/labels), and will stay open while there is still something that can be resolved. + +Anybody may add to the discussion on the bug tracker. Just be sure to add new questions as separate issues, and to avoid commenting on closed issues. + +## Submitting changes + +Code changes may be submitted as a "[pull request](https://help.github.com/articles/about-pull-requests/)" at [mike42/escpos-php](https://github.com/mike42/escpos-php). The description should include some information about how the change improves the library. + +The project is MIT-licensed (see [LICENSE.md](https://github.com/mike42/escpos-php/blob/development/LICENSE.md) for details). You are not required to assign copyright in order to submit changes, but you do need to agree for your code to be distributed under this license in order for it to be accepted. + +### Documentation changes + +The official documentaton is also located in the main repository, under the [doc/](https://github.com/mike42/escpos-php/tree/development/doc) folder. + +You are welcome to post any suggested improvements as pull requests. + +### Release process + +Once a pull request is accepted, it usually appears in a release a few days later. + +Branches: + +- "development" is the most recent code, possibly containing unreleased fixes +- "master" contains the most recently released code (old versions are not maintained). + +The release process for your changes is: + +- Changes are submitted via pull request to the shared "development" branch. +- A new release is staged on the "master" branch via another pull request, and then tagged. + +## Code style + +This project uses the [PSR-2 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) for all PHP source code. + +## Testing and CI + +The tests are executed on [Travis CI](https://travis-ci.org/mike42/escpos-php) over PHP 5.4, 5.5, 5.6, 7.0, 7.1 and 7.2, plus the latest LTS version of HHVM, 3.21. Older versions of PHP are not supported in current releases. + +For development, it's suggested that you load `imagick`, `gd` and `Xdebug` PHP exensions, and install `composer`. + +Fetch a copy of this code and load dependencies with composer: + + git clone https://github.com/mike42/escpos-php + cd escpos-php/ + composer install + +Execute unit tests via `phpunit`: + + php vendor/bin/phpunit --coverage-text + +Code style can be checked via [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer): + + php vendor/bin/phpcs --standard=psr2 src/ -n + +The developer docs are built with [doxygen](https://github.com/doxygen/doxygen). Re-build them to check for documentation warnings: + + make -C doc clean && make -C doc diff --git a/htdocs/includes/mike42/escpos-php/CONTRIBUTORS.md b/htdocs/includes/mike42/escpos-php/CONTRIBUTORS.md new file mode 100644 index 00000000000..12f3acf95a5 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/CONTRIBUTORS.md @@ -0,0 +1,25 @@ +# escpos-php contributors + +This file contains a list of people who have made contributions of +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)) + +- [Michael Billington](https://github.com/mike42) +- [Alif Maulana El Fattah Nataly](https://github.com/alif25r) +- [Mareks Sudniks](https://github.com/marech) +- [matiasgaston](https://github.com/matiasgaston) +- [Mike Stivala](https://github.com/brndwgn) +- [Nicholas Long](https://github.com/longsview) +- [Evandro Araújo](https://github.com/evsar3) + +Via fork: [wdoyle/EpsonESCPOS-PHP](https://github.com/wdoyle/EpsonESCPOS-PHP): + +- [Warren Doyle](https://github.com/wdoyle) + +Via fork: [ronisaha/php-esc-pos](https://github.com/ronisaha/php-esc-pos): + +- [Roni Saha](https://github.com/ronisaha) +- [Gergely Radics](https://github.com/Gerifield) +- [vharo](https://github.com/vharo) + diff --git a/htdocs/includes/mike42/escpos-php/Escpos.php b/htdocs/includes/mike42/escpos-php/Escpos.php deleted file mode 100644 index b8568260738..00000000000 --- a/htdocs/includes/mike42/escpos-php/Escpos.php +++ /dev/null @@ -1,853 +0,0 @@ -, - * incorporating modifications by: - * - Roni Saha - * - Gergely Radics - * - Warren Doyle - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * This class generates ESC/POS printer control commands for compatible printers. - * See README.md for a summary of compatible printers and supported commands, and - * basic usage. - * - * See example/demo.php for a detailed print-out demonstrating the range of commands - * implemented in this project. - * - * Note that some functions have not been implemented: - * - Set paper sensors - * - Select print colour - * - * Please direct feature requests, bug reports and contributions to escpos-php - * on Github: - * - https://github.com/mike42/escpos-php - */ -require_once(dirname(__FILE__) . "/src/EscposImage.php"); -require_once(dirname(__FILE__) . "/src/PrintBuffer.php"); -require_once(dirname(__FILE__) . "/src/EscposPrintBuffer.php"); -require_once(dirname(__FILE__) . "/src/PrintConnector.php"); -require_once(dirname(__FILE__) . "/src/WindowsPrintConnector.php"); -require_once(dirname(__FILE__) . "/src/FilePrintConnector.php"); -require_once(dirname(__FILE__) . "/src/NetworkPrintConnector.php"); -require_once(dirname(__FILE__) . "/src/AbstractCapabilityProfile.php"); -require_once(dirname(__FILE__) . "/src/DefaultCapabilityProfile.php"); -require_once(dirname(__FILE__) . "/src/SimpleCapabilityProfile.php"); -require_once(dirname(__FILE__) . "/src/EposTepCapabilityProfile.php"); -require_once(dirname(__FILE__) . "/src/StarCapabilityProfile.php"); -require_once(dirname(__FILE__) . "/src/P822DCapabilityProfile.php"); -require_once(dirname(__FILE__) . "/src/CodePage.php"); -require_once(dirname(__FILE__) . "/src/ImagePrintBuffer.php"); - -class Escpos { - /* ASCII codes */ - const NUL = "\x00"; - const LF = "\x0a"; - const ESC = "\x1b"; - const FS = "\x1c"; - const FF = "\x0c"; - const GS = "\x1d"; - const DLE = "\x10"; - const EOT = "\x04"; - - /* Barcode types */ - const BARCODE_UPCA = 65; - const BARCODE_UPCE = 66; - const BARCODE_JAN13 = 67; - const BARCODE_JAN8 = 68; - const BARCODE_CODE39 = 69; - const BARCODE_ITF = 70; - const BARCODE_CODABAR = 71; - const BARCODE_CODE93 = 72; - const BARCODE_CODE128 = 73; - - /* Barcode HRI (human-readable interpretation) text position */ - const BARCODE_TEXT_NONE = 0; - const BARCODE_TEXT_ABOVE = 1; - const BARCODE_TEXT_BELOW = 2; - - /* Cut types */ - const CUT_FULL = 65; - const CUT_PARTIAL = 66; - - /* Fonts */ - const FONT_A = 0; - const FONT_B = 1; - const FONT_C = 2; - - /* Image sizing options */ - const IMG_DEFAULT = 0; - const IMG_DOUBLE_WIDTH = 1; - const IMG_DOUBLE_HEIGHT = 2; - - /* Justifications */ - const JUSTIFY_LEFT = 0; - const JUSTIFY_CENTER = 1; - const JUSTIFY_RIGHT = 2; - - /* Print mode constants */ - const MODE_FONT_A = 0; - const MODE_FONT_B = 1; - const MODE_EMPHASIZED = 8; - const MODE_DOUBLE_HEIGHT = 16; - const MODE_DOUBLE_WIDTH = 32; - const MODE_UNDERLINE = 128; - - /* QR code error correction levels */ - const QR_ECLEVEL_L = 0; - const QR_ECLEVEL_M = 1; - const QR_ECLEVEL_Q = 2; - const QR_ECLEVEL_H = 3; - - /* QR code models */ - const QR_MODEL_1 = 1; - const QR_MODEL_2 = 2; - const QR_MICRO = 3; - - /* Printer statuses */ - const STATUS_PRINTER = 1; - const STATUS_OFFLINE_CAUSE = 2; - const STATUS_ERROR_CAUSE = 3; - const STATUS_PAPER_ROLL = 4; - const STATUS_INK_A = 7; - const STATUS_INK_B = 6; - const STATUS_PEELER = 8; - - /* Underline */ - const UNDERLINE_NONE = 0; - const UNDERLINE_SINGLE = 1; - const UNDERLINE_DOUBLE = 2; - - /** - * @var PrintBuffer The printer's output buffer. - */ - private $buffer; - - /** - * @var PrintConnector - * @CHANGE - */ - protected $connector; - // private $connector; - - /** - * @var AbstractCapabilityProfile - */ - private $profile; - - /** - * @var int Current character code table - */ - private $characterTable; - - /** - * Construct a new print object - * - * @param PrintConnector $connector The PrintConnector to send data to. If not set, output is sent to standard output. - * @param AbstractCapabilityProfile $profile Supported features of this printer. If not set, the DefaultCapabilityProfile will be used, which is suitable for Epson printers. - * @throws InvalidArgumentException - */ - function __construct(PrintConnector $connector = null, AbstractCapabilityProfile $profile = null) { - if(is_null($connector)) { - if(php_sapi_name() == 'cli') { - $connector = new FilePrintConnector("php://stdout"); - } else { - throw new InvalidArgumentException("Argument passed to Escpos::__construct() must implement interface PrintConnector, null given."); - } - } - /* Set connector */ - $this -> connector = $connector; - - /* Set capability profile */ - if($profile === null) { - $profile = DefaultCapabilityProfile::getInstance(); - } - $this -> profile = $profile; - /* Set buffer */ - $buffer = new EscposPrintBuffer(); - $this -> buffer = null; - $this -> setPrintBuffer($buffer); - $this -> initialize(); - } - - /** - * Print a barcode. - * - * @param string $content The information to encode. - * @param int $type The barcode standard to output. If not specified, `Escpos::BARCODE_CODE39` will be used. Note that some barcode formats only support specific lengths or sets of characters. - * @throws InvalidArgumentException Where the length or characters used in $content is invalid for the requested barcode format. - */ - function barcode($content, $type = self::BARCODE_CODE39) { - /* Validate input */ - self::validateInteger($type, 65, 73, __FUNCTION__, "Barcode type"); - $len = strlen($content); - switch($type) { - case self::BARCODE_UPCA: - self::validateInteger($len, 11, 12, __FUNCTION__, "UPCA barcode content length"); - self::validateStringRegex($content, __FUNCTION__, "/^[0-9]{11,12}$/", "UPCA barcode content"); - break; - case self::BARCODE_UPCE: - self::validateIntegerMulti($len, array(array(6, 8), array(11, 12)), __FUNCTION__, "UPCE barcode content length"); - self::validateStringRegex($content, __FUNCTION__, "/^([0-9]{6,8}|[0-9]{11,12})$/", "UPCE barcode content"); - break; - case self::BARCODE_JAN13: - self::validateInteger($len, 12, 13, __FUNCTION__, "JAN13 barcode content length"); - self::validateStringRegex($content, __FUNCTION__, "/^[0-9]{12,13}$/", "JAN13 barcode content"); - break; - case self::BARCODE_JAN8: - self::validateInteger($len, 7, 8, __FUNCTION__, "JAN8 barcode content length"); - self::validateStringRegex($content, __FUNCTION__, "/^[0-9]{7,8}$/", "JAN8 barcode content"); - break; - case self::BARCODE_CODE39: - self::validateInteger($len, 1, 255, __FUNCTION__, "CODE39 barcode content length"); // 255 is a limitation of the "function b" command, not the barcode format. - self::validateStringRegex($content, __FUNCTION__, "/^([0-9A-Z \$\%\+\-\.\/]+|\*[0-9A-Z \$\%\+\-\.\/]+\*)$/", "CODE39 barcode content"); - break; - case self::BARCODE_ITF: - self::validateInteger($len, 2, 255, __FUNCTION__, "ITF barcode content length"); // 255 is a limitation of the "function b" command, not the barcode format. - self::validateStringRegex($content, __FUNCTION__, "/^([0-9]{2})+$/", "ITF barcode content"); - break; - case self::BARCODE_CODABAR: - self::validateInteger($len, 1, 255, __FUNCTION__, "Codabar barcode content length"); // 255 is a limitation of the "function b" command, not the barcode format. - self::validateStringRegex($content, __FUNCTION__, "/^[A-Da-d][0-9\$\+\-\.\/\:]+[A-Da-d]$/", "Codabar barcode content"); - break; - case self::BARCODE_CODE93: - self::validateInteger($len, 1, 255, __FUNCTION__, "Code93 barcode content length"); // 255 is a limitation of the "function b" command, not the barcode format. - self::validateStringRegex($content, __FUNCTION__, "/^[\\x00-\\x7F]+$/", "Code93 barcode content"); - break; - case self::BARCODE_CODE128: - self::validateInteger($len, 1, 255, __FUNCTION__, "Code128 barcode content length"); // 255 is a limitation of the "function b" command, not the barcode format. - // The CODE128 encoder is quite complex, so only a very basic header-check is applied here. - self::validateStringRegex($content, __FUNCTION__, "/^\{[A-C][\\x00-\\x7F]+$/", "Code128 barcode content"); - break; - } - if(!$this -> profile -> getSupportsBarcodeB()) { - // A simpler barcode command which supports fewer codes - self::validateInteger($type, 65, 71, __FUNCTION__); - $this -> connector -> write(self::GS . "k" . chr($type - 65) . $content . self::NUL); - return; - } - // More advanced function B, used in preference - $this -> connector -> write(self::GS . "k" . chr($type) . chr(strlen($content)) . $content); - } - - /** - * Print an image, using the older "bit image" command. This creates padding on the right of the image, - * if its width is not divisible by 8. - * - * Should only be used if your printer does not support the graphics() command. - * - * @param EscposImage $img The image to print - * @param EscposImage $size Size modifier for the image. - */ - function bitImage(EscposImage $img, $size = self::IMG_DEFAULT) { - self::validateInteger($size, 0, 3, __FUNCTION__); - $header = self::dataHeader(array($img -> getWidthBytes(), $img -> getHeight()), true); - $this -> connector -> write(self::GS . "v0" . chr($size) . $header); - $this -> connector -> write($img -> toRasterFormat()); - } - - /** - * Close the underlying buffer. With some connectors, the - * job will not actually be sent to the printer until this is called. - */ - function close() { - $this -> connector -> finalize(); - } - - /** - * Cut the paper. - * - * @param int $mode Cut mode, either Escpos::CUT_FULL or Escpos::CUT_PARTIAL. If not specified, `Escpos::CUT_FULL` will be used. - * @param int $lines Number of lines to feed - */ - function cut($mode = self::CUT_FULL, $lines = 3) { - // TODO validation on cut() inputs - $this -> connector -> write(self::GS . "V" . chr($mode) . chr($lines)); - } - - /** - * Print and feed line / Print and feed n lines. - * - * @param int $lines Number of lines to feed - */ - function feed($lines = 1) { - self::validateInteger($lines, 1, 255, __FUNCTION__); - if($lines <= 1) { - $this -> connector -> write(self::LF); - } else { - $this -> connector -> write(self::ESC . "d" . chr($lines)); - } - } - - /** - * Some printers require a form feed to release the paper. On most printers, this - * command is only useful in page mode, which is not implemented in this driver. - */ - function feedForm() { - $this -> connector -> write(self::FF); - } - - /** - * Print and reverse feed n lines. - * - * @param int $lines number of lines to feed. If not specified, 1 line will be fed. - */ - function feedReverse($lines = 1) { - self::validateInteger($lines, 1, 255, __FUNCTION__); - $this -> connector -> write(self::ESC . "e" . chr($lines)); - } - - /** - * @return number - */ - function getCharacterTable() { - return $this -> characterTable; - } - - /** - * @return PrintBuffer - */ - function getPrintBuffer() { - return $this -> buffer; - } - - /** - * @return PrintConnector - */ - function getPrintConnector() { - return $this -> connector; - } - - /** - * @return AbstractCapabilityProfile - */ - function getPrinterCapabilityProfile() { - return $this -> profile; - } - - /** - * @param int $type The type of status to request - * @return stdClass Class containing requested status, or null if either no status was received, or your print connector is unable to read from the printer. - */ - function getPrinterStatus($type = self::STATUS_PRINTER) { - self::validateIntegerMulti($type, array(array(1, 4), array(6, 8)), __FUNCTION__); - // Determine which flags we are looking for - $statusFlags = array( - self::STATUS_PRINTER => array( - 4 => "pulseHigh", // connector pin 3, see pulse(). - 8 => "offline", - 32 => "waitingForOnlineRecovery", - 64 => "feedButtonPressed" - ), - self::STATUS_OFFLINE_CAUSE => array( - 4 => "coverOpen", - 8 => "paperManualFeed", - 32 => "paperEnd", - 64 => "errorOccurred" - ), - self::STATUS_ERROR_CAUSE => array( - 4 => "recoverableError", - 8 => "autocutterError", - 32 => "unrecoverableError", - 64 => "autorecoverableError" - ), - self::STATUS_PAPER_ROLL => array( - 4 => "paperNearEnd", - 32 => "paperNotPresent" - ), - self::STATUS_INK_A => array( - 4 => "inkNearEnd", - 8 => "inkEnd", - 32 => "inkNotPresent", - 64 => "cleaning" - ), - self::STATUS_INK_B => array( - 4 => "inkNearEnd", - 8 => "inkEnd", - 32 => "inkNotPresent" - ), - self::STATUS_PEELER => array( - 4 => "labelWaitingForRemoval", - 32 => "labelPaperNotDetected" - ) - ); - $flags = $statusFlags[$type]; - // Clear any previous statuses which haven't been read yet - $f = $this -> connector -> read(1); - // Make request - $reqC = chr($type); - switch($type) { - // Special cases: These are two-character requests - case self::STATUS_INK_A: - $reqC = chr(7) . chr(1); - break; - case self::STATUS_INK_B: - $reqC = chr(7) . chr(2); - break; - case self::STATUS_PEELER: - $reqC = chr(8) . chr(3); - break; - } - $this -> connector -> write(self::DLE . self::EOT . $reqC); - // Wait for single-character response - $f = $this -> connector -> read(1); - $i = 0; - while($f === false && $i < 50000) { - usleep(100); - $f = $this -> connector -> read(1); - $i++; - } - if($f === false) { - // Timeout - return null; - } - $ret = new stdClass(); - foreach($flags as $num => $name) { - $ret -> $name = (ord($f) & $num) != 0; - } - return $ret; - } - - /** - * Print an image to the printer. - * - * Size modifiers are: - * - IMG_DEFAULT (leave image at original size) - * - IMG_DOUBLE_WIDTH - * - IMG_DOUBLE_HEIGHT - * - * See the example/ folder for detailed examples. - * - * The function bitImage() takes the same parameters, and can be used if - * your printer doesn't support the newer graphics commands. - * - * @param EscposImage $img The image to print. - * @param int $size Output size modifier for the image. - */ - function graphics(EscposImage $img, $size = self::IMG_DEFAULT) { - self::validateInteger($size, 0, 3, __FUNCTION__); - $imgHeader = self::dataHeader(array($img -> getWidth(), $img -> getHeight()), true); - $tone = '0'; - $colors = '1'; - $xm = (($size & self::IMG_DOUBLE_WIDTH) == self::IMG_DOUBLE_WIDTH) ? chr(2) : chr(1); - $ym = (($size & self::IMG_DOUBLE_HEIGHT) == self::IMG_DOUBLE_HEIGHT) ? chr(2) : chr(1); - $header = $tone . $xm . $ym . $colors . $imgHeader; - $this -> wrapperSendGraphicsData('0', 'p', $header . $img -> toRasterFormat()); - $this -> wrapperSendGraphicsData('0', '2'); - } - - /** - * Initialize printer. This resets formatting back to the defaults. - */ - function initialize() { - $this -> connector -> write(self::ESC . "@"); - $this -> characterTable = 0; - } - - /** - * Generate a pulse, for opening a cash drawer if one is connected. - * The default settings should open an Epson drawer. - * - * @param int $pin 0 or 1, for pin 2 or pin 5 kick-out connector respectively. - * @param int $on_ms pulse ON time, in milliseconds. - * @param int $off_ms pulse OFF time, in milliseconds. - */ - function pulse($pin = 0, $on_ms = 120, $off_ms = 240) { - self::validateInteger($pin, 0, 1, __FUNCTION__); - self::validateInteger($on_ms, 1, 511, __FUNCTION__); - self::validateInteger($off_ms, 1, 511, __FUNCTION__); - $this -> connector -> write(self::ESC . "p" . chr($pin + 48) . chr($on_ms / 2) . chr($off_ms / 2)); - } - - /** - * Print the given data as a QR code on the printer. - * - * @param string $content The content of the code. Numeric data will be more efficiently compacted. - * @param int $ec Error-correction level to use. One of Escpos::QR_ECLEVEL_L (default), Escpos::QR_ECLEVEL_M, Escpos::QR_ECLEVEL_Q or Escpos::QR_ECLEVEL_H. Higher error correction results in a less compact code. - * @param int $size Pixel size to use. Must be 1-16 (default 3) - * @param int $model QR code model to use. Must be one of Escpos::QR_MODEL_1, Escpos::QR_MODEL_2 (default) or Escpos::QR_MICRO (not supported by all printers). - */ - function qrCode($content, $ec = self::QR_ECLEVEL_L, $size = 3, $model = self::QR_MODEL_2) { - self::validateString($content, __FUNCTION__); - self::validateInteger($ec, 0, 3, __FUNCTION__); - self::validateInteger($size, 1, 16, __FUNCTION__); - self::validateInteger($model, 1, 3, __FUNCTION__); - if($content == "") { - return; - } - if(!$this -> profile -> getSupportsQrCode()) { - // TODO use software rendering via phpqrcode instead - throw new Exception("QR codes are not supported on your printer."); - } - $cn = '1'; // Code type for QR code - // Select model: 1, 2 or micro. - $this -> wrapperSend2dCodeData(chr(65), $cn, chr(48 + $model) . chr(0)); - // Set dot size. - $this -> wrapperSend2dCodeData(chr(67), $cn, chr($size)); - // Set error correction level: L, M, Q, or H - $this -> wrapperSend2dCodeData(chr(69), $cn, chr(48 + $ec)); - // Send content & print - $this -> wrapperSend2dCodeData(chr(80), $cn, $content, '0'); - $this -> wrapperSend2dCodeData(chr(81), $cn, '', '0'); - } - - /** - * Switch character table (code page) manually. Used in conjunction with textRaw() to - * print special characters which can't be encoded automatically. - * - * @param int $table The table to select. Available code tables are model-specific. - */ - function selectCharacterTable($table = 0) { - self::validateInteger($table, 0, 255, __FUNCTION__); - $supported = $this -> profile -> getSupportedCodePages(); - if(!isset($supported[$table])) { - throw new InvalidArgumentException("There is no code table $table allowed by this printer's capability profile."); - } - $this -> characterTable = $table; - if($this -> profile -> getSupportsStarCommands()) { - /* Not an ESC/POS command: STAR printers stash all the extra code pages under a different command. */ - $this -> connector -> write(self::ESC . self::GS . "t" . chr($table)); - return; - } - $this -> connector -> write(self::ESC . "t" . chr($table)); - } - - /** - * Select print mode(s). - * - * Several MODE_* constants can be OR'd together passed to this function's `$mode` argument. The valid modes are: - * - MODE_FONT_A - * - MODE_FONT_B - * - MODE_EMPHASIZED - * - MODE_DOUBLE_HEIGHT - * - MODE_DOUBLE_WIDTH - * - MODE_UNDERLINE - * - * @param int $mode The mode to use. Default is Escpos::MODE_FONT_A, with no special formatting. This has a similar effect to running initialize(). - */ - function selectPrintMode($mode = self::MODE_FONT_A) { - $allModes = self::MODE_FONT_B | self::MODE_EMPHASIZED | self::MODE_DOUBLE_HEIGHT | self::MODE_DOUBLE_WIDTH | self::MODE_UNDERLINE; - if(!is_integer($mode) || $mode < 0 || ($mode & $allModes) != $mode) { - throw new InvalidArgumentException("Invalid mode"); - } - - $this -> connector -> write(self::ESC . "!" . chr($mode)); - } - - /** - * Set barcode height. - * - * @param int $height Height in dots. If not specified, 8 will be used. - */ - function setBarcodeHeight($height = 8) { - self::validateInteger($height, 1, 255, __FUNCTION__); - $this -> connector -> write(self::GS . "h" . chr($height)); - } - - - /** - * Set the position for the Human Readable Interpretation (HRI) of barcode characters. - * - * @param position $position. Use Escpos::BARCODE_TEXT_NONE to hide the text (default), or any combination of Escpos::BARCODE_TEXT_TOP and Escpos::BARCODE_TEXT_BOTTOM flags to display the text. - */ - function setBarcodeTextPosition($position = self::BARCODE_TEXT_NONE) { - self::validateInteger($position, 0, 3, __FUNCTION__, "Barcode text position"); - $this -> connector -> write(self::GS . "H" . chr($position)); - } - - /** - * Turn double-strike mode on/off. - * - * @param boolean $on true for double strike, false for no double strike - */ - function setDoubleStrike($on = true) { - self::validateBoolean($on, __FUNCTION__); - $this -> connector -> write(self::ESC . "G". ($on ? chr(1) : chr(0))); - } - - /** - * Turn emphasized mode on/off. - * - * @param boolean $on true for emphasis, false for no emphasis - */ - function setEmphasis($on = true) { - self::validateBoolean($on, __FUNCTION__); - $this -> connector -> write(self::ESC . "E". ($on ? chr(1) : chr(0))); - } - - /** - * Select font. Most printers have two fonts (Fonts A and B), and some have a third (Font C). - * - * @param int $font The font to use. Must be either Escpos::FONT_A, Escpos::FONT_B, or Escpos::FONT_C. - */ - function setFont($font = self::FONT_A) { - self::validateInteger($font, 0, 2, __FUNCTION__); - $this -> connector -> write(self::ESC . "M" . chr($font)); - } - - /** - * Select justification. - * - * @param int $justification One of Escpos::JUSTIFY_LEFT, Escpos::JUSTIFY_CENTER, or Escpos::JUSTIFY_RIGHT. - */ - function setJustification($justification = self::JUSTIFY_LEFT) { - self::validateInteger($justification, 0, 2, __FUNCTION__); - $this -> connector -> write(self::ESC . "a" . chr($justification)); - } - - /** - * Attach a different print buffer to the printer. Buffers are responsible for handling text output to the printer. - * - * @param PrintBuffer $buffer The buffer to use. - * @throws InvalidArgumentException Where the buffer is already attached to a different printer. - */ - function setPrintBuffer(PrintBuffer $buffer) { - if($buffer === $this -> buffer) { - return; - } - if($buffer -> getPrinter() != null) { - throw new InvalidArgumentException("This buffer is already attached to a printer."); - } - if($this -> buffer !== null) { - $this -> buffer -> setPrinter(null); - } - $this -> buffer = $buffer; - $this -> buffer -> setPrinter($this); - } - - /** - * Set black/white reverse mode on or off. In this mode, text is printed white on a black background. - * - * @param boolean $on True to enable, false to disable. - */ - function setReverseColors($on = true) { - self::validateBoolean($on, __FUNCTION__); - $this -> connector -> write(self::GS . "B" . ($on ? chr(1) : chr(0))); - } - - /** - * Set the size of text, as a multiple of the normal size. - * - * @param int $widthMultiplier Multiple of the regular height to use (range 1 - 8) - * @param int $heightMultiplier Multiple of the regular height to use (range 1 - 8) - */ - function setTextSize($widthMultiplier, $heightMultiplier) { - self::validateInteger($widthMultiplier, 1, 8, __FUNCTION__); - self::validateInteger($heightMultiplier, 1, 8, __FUNCTION__); - $c = pow(2,4) * ($widthMultiplier - 1) + ($heightMultiplier - 1); - $this -> connector -> write(self::GS . "!" . chr($c)); - } - - /** - * Set underline for printed text. - * - * Argument can be true/false, or one of UNDERLINE_NONE, - * UNDERLINE_SINGLE or UNDERLINE_DOUBLE. - * - * @param int $underline Either true/false, or one of Escpos::UNDERLINE_NONE, Escpos::UNDERLINE_SINGLE or Escpos::UNDERLINE_DOUBLE. Defaults to Escpos::UNDERLINE_SINGLE. - */ - function setUnderline($underline = self::UNDERLINE_SINGLE) { - /* Map true/false to underline constants */ - if($underline === true) { - $underline = self::UNDERLINE_SINGLE; - } else if($underline === false) { - $underline = self::UNDERLINE_NONE; - } - /* Set the underline */ - self::validateInteger($underline, 0, 2, __FUNCTION__); - $this -> connector -> write(self::ESC . "-". chr($underline)); - } - - /** - * Add text to the buffer. - * - * Text should either be followed by a line-break, or feed() should be called - * after this to clear the print buffer. - * - * @param string $str Text to print - */ - function text($str = "") { - self::validateString($str, __FUNCTION__); - $this -> buffer -> writeText((string)$str); - } - - /** - * Add text to the buffer without attempting to interpret chararacter codes. - * - * Text should either be followed by a line-break, or feed() should be called - * after this to clear the print buffer. - * - * @param string $str Text to print - */ - function textRaw($str = "") { - self::validateString($str, __FUNCTION__); - $this -> buffer -> writeTextRaw((string)$str); - } - - /** - * Wrapper for GS ( k, to calculate and send correct data length. - * - * @param string $fn Function to use - * @param string $cn Output code type. Affects available data - * @param string $data Data to send. - * @param string $m Modifier/variant for function. Often '0' where used. - * @throws InvalidArgumentException Where the input lengths are bad. - */ - private function wrapperSend2dCodeData($fn, $cn, $data = '', $m = '') { - if(strlen($m) > 1 || strlen($cn) != 1 || strlen($fn) != 1) { - throw new InvalidArgumentException("wrapperSend2dCodeData: cn and fn must be one character each."); - } - $header = $this -> intLowHigh(strlen($data) + strlen($m) + 2, 2); - $this -> connector -> write(self::GS . "(k" . $header . $cn . $fn . $m . $data); - } - - /** - * Wrapper for GS ( L, to calculate and send correct data length. - * - * @param string $m Modifier/variant for function. Usually '0'. - * @param string $fn Function number to use, as character. - * @param string $data Data to send. - * @throws InvalidArgumentException Where the input lengths are bad. - */ - private function wrapperSendGraphicsData($m, $fn, $data = '') { - if(strlen($m) != 1 || strlen($fn) != 1) { - throw new InvalidArgumentException("wrapperSendGraphicsData: m and fn must be one character each."); - } - $header = $this -> intLowHigh(strlen($data) + 2, 2); - $this -> connector -> write(self::GS . "(L" . $header . $m . $fn . $data); - } - - /** - * Convert widths and heights to characters. Used before sending graphics to set the size. - * - * @param array $inputs - * @param boolean $long True to use 4 bytes, false to use 2 - * @return string - */ - private static function dataHeader(array $inputs, $long = true) { - $outp = array(); - foreach($inputs as $input) { - if($long) { - $outp[] = Escpos::intLowHigh($input, 2); - } else { - self::validateInteger($input, 0 , 255, __FUNCTION__); - $outp[] = chr($input); - } - } - return implode("", $outp); - } - - /** - * Generate two characters for a number: In lower and higher parts, or more parts as needed. - * @param int $int Input number - * @param int $length The number of bytes to output (1 - 4). - */ - private static function intLowHigh($input, $length) { - $maxInput = (256 << ($length * 8) - 1); - self::validateInteger($length, 1, 4, __FUNCTION__); - self::validateInteger($input, 0, $maxInput, __FUNCTION__); - $outp = ""; - for($i = 0; $i < $length; $i++) { - $outp .= chr($input % 256); - $input = (int)($input / 256); - } - return $outp; - } - - /** - * Throw an exception if the argument given is not a boolean - * - * @param boolean $test the input to test - * @param string $source the name of the function calling this - */ - protected static function validateBoolean($test, $source) { - if(!($test === true || $test === false)) { - throw new InvalidArgumentException("Argument to $source must be a boolean"); - } - } - - /** - * Throw an exception if the argument given is not an integer within the specified range - * - * @param int $test the input to test - * @param int $min the minimum allowable value (inclusive) - * @param int $max the maximum allowable value (inclusive) - * @param string $source the name of the function calling this - * @param string $argument the name of the invalid parameter - */ - protected static function validateInteger($test, $min, $max, $source, $argument = "Argument") { - self::validateIntegerMulti($test, array(array($min, $max)), $source, $argument); - } - - /** - * Throw an exception if the argument given is not an integer within one of the specified ranges - * - * @param int $test the input to test - * @param arrray $ranges array of two-item min/max ranges. - * @param string $source the name of the function calling this - * @param string $source the name of the function calling this - * @param string $argument the name of the invalid parameter - */ - protected static function validateIntegerMulti($test, array $ranges, $source, $argument = "Argument") { - if(!is_integer($test)) { - throw new InvalidArgumentException("$argument given to $source must be a number, but '$test' was given."); - } - $match = false; - foreach($ranges as $range) { - $match |= $test >= $range[0] && $test <= $range[1]; - } - if(!$match) { - // Put together a good error "range 1-2 or 4-6" - $rangeStr = "range "; - for($i = 0; $i < count($ranges); $i++) { - $rangeStr .= $ranges[$i][0] . "-" . $ranges[$i][1]; - if($i == count($ranges) - 1) { - continue; - } else if($i == count($ranges) - 2) { - $rangeStr .= " or "; - } else { - $rangeStr .= ", "; - } - } - throw new InvalidArgumentException("$argument given to $source must be in $rangeStr, but $test was given."); - } - } - - /** - * Throw an exception if the argument given can't be cast to a string - * - * @param string $test the input to test - * @param string $source the name of the function calling this - * @param string $argument the name of the invalid parameter - */ - protected static function validateString($test, $source, $argument = "Argument") { - if (is_object($test) && !method_exists($test, '__toString')) { - throw new InvalidArgumentException("$argument to $source must be a string"); - } - } - - protected static function validateStringRegex($test, $source, $regex, $argument = "Argument") { - if(preg_match($regex, $test) === 0) { - throw new InvalidArgumentException("$argument given to $source is invalid. It should match regex '$regex', but '$test' was given."); - } - } -} diff --git a/htdocs/includes/mike42/escpos-php/LICENSE.md b/htdocs/includes/mike42/escpos-php/LICENSE.md index a0bebf6920b..0e04f34f84f 100644 --- a/htdocs/includes/mike42/escpos-php/LICENSE.md +++ b/htdocs/includes/mike42/escpos-php/LICENSE.md @@ -1,11 +1,7 @@ -escpos-php, a Thermal receipt printer library, for use with -ESC/POS compatible printers. +MIT License -Copyright (c) 2014-15 Michael Billington , -incorporating modifications by: -- Roni Saha -- Gergely Radics -- Warren Doyle +Copyright (c) 2014-2016 Michael Billington, incorporating modifications by others. +See CONTRIBUTORS.md for a full list. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -13,10 +9,10 @@ in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,4 +20,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/htdocs/includes/mike42/escpos-php/README.md b/htdocs/includes/mike42/escpos-php/README.md index 43798bb0852..c5bb5c91337 100644 --- a/htdocs/includes/mike42/escpos-php/README.md +++ b/htdocs/includes/mike42/escpos-php/README.md @@ -1,73 +1,14 @@ -ESC/POS Print Driver for PHP -============================ +# ESC/POS Print Driver for PHP +[![Build Status](https://travis-ci.org/mike42/escpos-php.svg?branch=master)](https://travis-ci.org/mike42/escpos-php) [![Latest Stable Version](https://poser.pugx.org/mike42/escpos-php/v/stable)](https://packagist.org/packages/mike42/escpos-php) +[![Total Downloads](https://poser.pugx.org/mike42/escpos-php/downloads)](https://packagist.org/packages/mike42/escpos-php) +[![License](https://poser.pugx.org/mike42/escpos-php/license)](https://packagist.org/packages/mike42/escpos-php) +[![Coverage Status](https://coveralls.io/repos/github/mike42/escpos-php/badge.svg?branch=development)](https://coveralls.io/github/mike42/escpos-php?branch=development) + This project implements a subset of Epson's ESC/POS protocol for thermal receipt printers. It allows you to generate and print receipts with basic formatting, cutting, and barcodes on a compatible printer. The library was developed to add drop-in support for receipt printing to any PHP app, including web-based point-of-sale (POS) applications. -Basic usage ------------ -A "hello world" receipt can be generated easily (Call this `hello-world.php`): -```php - text("Hello World!\n"); -$printer -> cut(); -$printer -> close(); -``` -This would be printed as: -``` -# Networked printer -php hello-world.php | nc 10.x.x.x. 9100 -# Local printer -php hello-world.php > /dev/... -# Windows local printer -php hello-world.php > foo.txt -net use LPT1 \\server\printer -copy foo.txt LPT1 -del foo.txt -``` - -From your web app, you could pass the output directly to a socket if your printer is networked: -```php - text("Hello World!\n"); -$printer -> cut(); -$printer -> close(); -``` - -Or to a local printer: -```php - text("Hello World!\n"); -$printer -> cut(); -$printer -> close(); -``` - -### Basic workflow -The library should be initialised with a PrintConnector, which will pass on the data to your printer. -Use the table under "Compatibility", or the examples below to choose the appropriate connector for your -platform & interface. If no connector is specified, then standard output is used. - -When you have finished using the print object, call `close()` to finalize any data transfers. - -### Tips & examples -On Linux, your printer device file will be somewhere like `/dev/lp0` (parallel), `/dev/usb/lp1` (USB), `/dev/ttyUSB0` (USB-Serial), `/dev/ttyS0` (serial). - -On Windows, the device files will be along the lines of `LPT1` (parallel) or `COM1` (serial). Use the `WindowsPrintConnector` to tap into system printing on Windows (eg. [Windows USB](https://github.com/mike42/escpos-php/tree/master/example/interface/windows-usb.php), [SMB](https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php) or [Windows LPT](https://github.com/mike42/escpos-php/tree/master/example/interface/windows-lpt.php)) - this submits print jobs via a queue rather than communicating directly with the printer. - -A complete real-world receipt can be found in the code of [Auth](https://github.com/mike42/Auth) in [ReceiptPrinter.php](https://github.com/mike42/Auth/blob/master/lib/misc/ReceiptPrinter.php). It includes justification, boldness, and a barcode. - -Other examples are located in the [example/](https://github.com/mike42/escpos-php/blob/master/example/) directory. - -Compatibility -------------- +## Compatibility ### Interfaces and operating systems This driver is known to work with the following OS/interface combinations: @@ -115,43 +56,276 @@ This driver is known to work with the following OS/interface combinations: No Yes + +CUPS hosted +Yes +Yes +No + ### Printers Many thermal receipt printers support ESC/POS to some degree. This driver has been known to work with: +- 3nStar RPT-008 +- Approx APPPOS80AM +- AURES ODP-333 +- AURES ODP-500 +- Bematech-4200-TH +- Bematech LR2000E +- Birch PRP-085III +- Bixolon SRP-350III +- Bixolon SRP-350Plus +- Black Copper BC-85AC +- CHD TH-305N +- Citizen CBM1000-II +- Citizen CT-S310II +- Dapper-Geyi Q583P +- Daruma DR800 +- DR-MP200 (manufacturer unknown) - EPOS TEP 220M +- Elgin i9 +- Epson EU-T332C +- Epson FX-890 (requires `feedForm()` to release paper). +- Epson TM-T20 +- Epson TM-T20II +- Epson TM-T70 +- Epson TM-T70II +- Epson TM-T81 +- Epson TM-T82II +- Epson TM-T88II - Epson TM-T88III - Epson TM-T88IV -- Epson TM-T70 -- Epson TM-T82II -- Epson TM-T20 -- Epson TM-T70II +- Epson TM-T88V - Epson TM-U220 -- Epson FX-890 (requires `feedForm()` to release paper). -- Okipos 80 Plus III +- Epson TM-U295 (requires `release()` to release slip). +- Epson TM-U590 and TM-U590P +- Equal (EQ-IT-001) POS-58 +- Everycom EC-58 +- Excelvan HOP-E200 +- Excelvan HOP-E58 +- Excelvan HOP-E801 +- Gainscha GP-2120TF +- Gainscha GP-5890x (Also marketed as EC Line 5890x) +- Gainscha GP-U80300I (Also marketed as gprinter GP-U80300I) +- gprinter GP-U80160I +- HOIN HOP-H58 +- Ithaca iTherm 28 +- Hasar HTP 250 +- Metapace T-1 +- Metapace T-25 +- Nexa PX700 +- Nyear NP100 +- OKI RT322 +- OKI 80 Plus III +- Orient BTP-R580 - P-822D +- P85A-401 (make unknown) +- Partner Tech RP320 +- POSLIGNE ODP200H-III-G +- QPOS Q58M +- Rongta RP326US +- Rongta RP58-U +- Rongta RP80USE +- SAM4S GIANT-100DB +- Senor TP-100 +- Sewoo SLK-TS400 +- SEYPOS PRP-96 - SEYPOS PRP-300 (Also marketed as TYSSO PRP-300) +- SNBC BTP-R880NPIII +- Solux SX-TP-88300 +- Sicar POS-80 +- Silicon SP-201 / RP80USE +- SPRT SP-POS88V +- Star BSC10 +- Star TSP100 ECO +- Star TSP100III FuturePRNT - Star TSP-650 - Star TUP-592 +- TVS RP45 Shoppe +- Venus V248T +- Xeumior SM-8330 +- Xprinter F-900 +- Xprinter XP-365B +- Xprinter XP-58 Series +- Xprinter XP-80C +- Xprinter XP-90 +- XPrinter XP-Q20011 - Xprinter XP-Q800 -- Zijang NT-58H -- Zijang ZJ-5870 -- Zijang ZJ-5890T (Marketed as POS 5890T) +- Zjiang NT-58H +- Zjiang ZJ-5870 +- Zjiang ZJ-5890 (Also sold as POS-5890 by many vendors; ZJ-5890K, ZJ-5890T also work). +- Zjiang ZJ-8220 (Also marketed as Excelvan ZJ-8220) +- Zjiang ZJ-8250 -If you use any other printer with this code, please let me know so I can add it to the list. +If you use any other printer with this code, please [let us know](https://github.com/mike42/escpos-php/issues/new) so that it can be added to the list. -Available methods ------------------ +## Basic usage -### __construct(PrintConnector $connector, AbstractCapabilityProfile $profile) +### Include the library + +#### Composer +If you are using composer, then add `mike42/escpos-php` as a dependency: + +```bash +composer require mike42/escpos-php +``` + +In this case, you would include composer's auto-loader at the top of your source files: + +```php + text("Hello World!\n"); +$printer -> cut(); +$printer -> close(); +``` + +Some examples are below for common interfaces. + +Communicate with a printer with an Ethernet interface using `netcat`: + +```bash +php hello-world.php | nc 10.x.x.x. 9100 +``` + +A USB local printer connected with `usblp` on Linux has a device file (Includes USB-parallel interfaces): + +```bash +php hello-world.php > /dev/usb/lp0 +``` + +A computer installed into the local `cups` server is accessed through `lp` or `lpr`: + +```bash +php hello-world.php > foo.txt +lpr -o raw -H localhost -P printer foo.txt +``` + +A local or networked printer on a Windows computer is mapped in to a file, and generally requires you to share the printer first: + +``` +php hello-world.php > foo.txt +net use LPT1 \\server\printer +copy foo.txt LPT1 +del foo.txt +``` + +If you have troubles at this point, then you should consult your OS and printer system documentation to try to find a working print command. + +### Using a PrintConnector + +To print receipts from PHP, use the most applicable [PrintConnector](https://github.com/mike42/escpos-php/tree/master/src/Mike42/Escpos/PrintConnectors) for your setup. The connector simply provides the plumbing to get data to the printer. + +For example, a `NetworkPrintConnector` accepts an IP address and port: + +```php +use Mike42\Escpos\PrintConnectors\NetworkPrintConnector; +use Mike42\Escpos\Printer; +$connector = new NetworkPrintConnector("10.x.x.x", 9100); +$printer = new Printer($connector); +try { + // ... Print stuff +} finally { + $printer -> close(); +} +``` + +While a serial printer might use: +```php +use Mike42\Escpos\PrintConnectors\FilePrintConnector; +use Mike42\Escpos\Printer; +$connector = new FilePrintConnector("/dev/ttyS0"); +$printer = new Printer($connector); +``` + +For each OS/interface combination that's supported, there are examples in the compatibility section of how a `PrintConnector` would be constructed. If you can't get a `PrintConnector` to work, then be sure to include the working print command in bug. + +### Using a CapabilityProfile + +Support for commands and code pages varies between printer vendors and models. By default, the driver will accept UTF-8, and output commands that are suitable for Epson TM-series printers. + +When trying out a new brand of printer, it's a good idea to use the "simple" `CapabilityProfile`, which instructs the driver to avoid the use of advanced features (generally simpler image handling, ASCII-only text). + +```php +use Mike42\Escpos\PrintConnectors\WindowsPrintConnector; +use Mike42\Escpos\CapabilityProfile; +$profile = CapabilityProfile::load("simple"); +$connector = new WindowsPrintConnector("smb://computer/printer"); +$printer = new Printer($connector, $profile); +``` + +As another example, Star-branded printers use different commands: + +```php +use Mike42\Escpos\PrintConnectors\WindowsPrintConnector; +use Mike42\Escpos\CapabilityProfile; +$profile = CapabilityProfile::load("SP2000") +$connector = new WindowsPrintConnector("smb://computer/printer"); +$printer = new Printer($connector, $profile); +``` + +For a list of available profiles, or to have support for your printer improved, please see the upstream [receipt-print-hq/escpos-printer-db](https://github.com/receipt-print-hq/escpos-printer-db) project. + +### Tips & examples +On Linux, your printer device file will be somewhere like `/dev/lp0` (parallel), `/dev/usb/lp1` (USB), `/dev/ttyUSB0` (USB-Serial), `/dev/ttyS0` (serial). + +On Windows, the device files will be along the lines of `LPT1` (parallel) or `COM1` (serial). Use the `WindowsPrintConnector` to tap into system printing on Windows (eg. [Windows USB](https://github.com/mike42/escpos-php/tree/master/example/interface/windows-usb.php), [SMB](https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php) or [Windows LPT](https://github.com/mike42/escpos-php/tree/master/example/interface/windows-lpt.php)) - this submits print jobs via a queue rather than communicating directly with the printer. + +A complete real-world receipt can be found in the code of [Auth](https://github.com/mike42/Auth) in [ReceiptPrinter.php](https://github.com/mike42/Auth/blob/master/lib/misc/ReceiptPrinter.php). It includes justification, boldness, and a barcode. + +Other examples are located in the [example/](https://github.com/mike42/escpos-php/blob/master/example/) directory. + +## Available methods + +### __construct(PrintConnector $connector, CapabilityProfile $profile) Construct new print object. Parameters: -- `PrintConnector $connector`: The PrintConnector to send data to. If not set, output is sent to standard output. -- `AbstractCapabilityProfile $profile` Supported features of this printer. If not set, the DefaultCapabilityProfile will be used, which is suitable for Epson printers. +- `PrintConnector $connector`: The PrintConnector to send data to. +- `CapabilityProfile $profile` Supported features of this printer. If not set, the "default" CapabilityProfile will be used, which is suitable for Epson printers. -See [example/interface/]("https://github.com/mike42/escpos-php/tree/master/example/interface/) for ways to open connections for different platforms and interfaces. +See [example/interface/](https://github.com/mike42/escpos-php/tree/master/example/interface/) for ways to open connections for different platforms and interfaces. ### barcode($content, $type) Print a barcode. @@ -159,7 +333,7 @@ Print a barcode. Parameters: - `string $content`: The information to encode. -- `int $type`: The barcode standard to output. If not specified, `Escpos::BARCODE_CODE39` will be used. +- `int $type`: The barcode standard to output. If not specified, `Printer::BARCODE_CODE39` will be used. Currently supported barcode standards are (depending on your printer): @@ -181,7 +355,7 @@ Cut the paper. Parameters: -- `int $mode`: Cut mode, either `Escpos::CUT_FULL` or `Escpos::CUT_PARTIAL`. If not specified, `Escpos::CUT_FULL` will be used. +- `int $mode`: Cut mode, either `Printer::CUT_FULL` or `Printer::CUT_PARTIAL`. If not specified, `Printer::CUT_FULL` will be used. - `int $lines`: Number of lines to feed before cutting. If not specified, 3 will be used. ### feed($lines) @@ -219,17 +393,29 @@ A minimal example: ```php graphics($img); ``` See the [example/](https://github.com/mike42/escpos-php/blob/master/example/) folder for detailed examples. -The function [bitImage()](#bitimageescposimage-image-size) takes the same parameters, and can be used if your printer doesn't support the newer graphics commands. +The function [bitImage()](#bitimageescposimage-image-size) takes the same parameters, and can be used if your printer doesn't support the newer graphics commands. As an additional fallback, the `bitImageColumnFormat()` function is also provided. ### initialize() Initialize printer. This resets formatting back to the defaults. +### pdf417Code($content, $width, $heightMultiplier, $dataColumnCount, $ec, $options) +Print a two-dimensional data code using the PDF417 standard. + +Parameters: + +- `string $content`: Text or numbers to store in the code +- `number $width`: Width of a module (pixel) in the printed code. Default is 3 dots. +- `number $heightMultiplier`: Multiplier for height of a module. Default is 3 times the width. +- `number $dataColumnCount`: Number of data columns to use. 0 (default) is to auto-calculate. Smaller numbers will result in a narrower code, making larger pixel sizes possible. Larger numbers require smaller pixel sizes. +- `real $ec`: Error correction ratio, from 0.01 to 4.00. Default is 0.10 (10%). +- `number $options`: Standard code `Printer::PDF417_STANDARD` with start/end bars, or truncated code `Printer::PDF417_TRUNCATED` with start bars only. + ### pulse($pin, $on_ms, $off_ms) Generate a pulse, for opening a cash drawer if one is connected. The default settings (0, 120, 240) should open an Epson drawer. @@ -243,16 +429,16 @@ Parameters: Print the given data as a QR code on the printer. - `string $content`: The content of the code. Numeric data will be more efficiently compacted. -- `int $ec` Error-correction level to use. One of `Escpos::QR_ECLEVEL_L` (default), `Escpos::QR_ECLEVEL_M`, `Escpos::QR_ECLEVEL_Q` or `Escpos::QR_ECLEVEL_H`. Higher error correction results in a less compact code. +- `int $ec` Error-correction level to use. One of `Printer::QR_ECLEVEL_L` (default), `Printer::QR_ECLEVEL_M`, `Printer::QR_ECLEVEL_Q` or `Printer::QR_ECLEVEL_H`. Higher error correction results in a less compact code. - `int $size`: Pixel size to use. Must be 1-16 (default 3) -- `int $model`: QR code model to use. Must be one of `Escpos::QR_MODEL_1`, `Escpos::QR_MODEL_2` (default) or `Escpos::QR_MICRO` (not supported by all printers). +- `int $model`: QR code model to use. Must be one of `Printer::QR_MODEL_1`, `Printer::QR_MODEL_2` (default) or `Printer::QR_MICRO` (not supported by all printers). ### selectPrintMode($mode) Select print mode(s). Parameters: -- `int $mode`: The mode to use. Default is `Escpos::MODE_FONT_A`, with no special formatting. This has a similar effect to running `initialize()`. +- `int $mode`: The mode to use. Default is `Printer::MODE_FONT_A`, with no special formatting. This has a similar effect to running `initialize()`. Several MODE_* constants can be OR'd together passed to this function's `$mode` argument. The valid modes are: @@ -270,6 +456,20 @@ 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. + +Parameters: + +- `int $color`: Color to use. Must be either `Printer::COLOR_1` (default), or `Printer::COLOR_2` + ### setDoubleStrike($on) Turn double-strike mode on/off. @@ -289,14 +489,40 @@ Select font. Most printers have two fonts (Fonts A and B), and some have a third Parameters: -- `int $font`: The font to use. Must be either `Escpos::FONT_A`, `Escpos::FONT_B`, or `Escpos::FONT_C`. +- `int $font`: The font to use. Must be either `Printer::FONT_A`, `Printer::FONT_B`, or `Printer::FONT_C`. ### setJustification($justification) Select justification. Parameters: -- `int $justification`: One of `Escpos::JUSTIFY_LEFT`, `Escpos::JUSTIFY_CENTER`, or `Escpos::JUSTIFY_RIGHT`. +- `int $justification`: One of `Printer::JUSTIFY_LEFT`, `Printer::JUSTIFY_CENTER`, or `Printer::JUSTIFY_RIGHT`. + +### setLineSpacing($height) + +Set the height of the line. + +Some printers will allow you to overlap lines with a smaller line feed. + +Parameters: + +- `int $height`: The height of each line, in dots. If not set, the printer will reset to its default line spacing. + +### setPrintLeftMargin($margin) + +Set print area left margin. Reset to default with `Printer::initialize()`. + +Parameters: + +- `int $margin`: The left margin to set on to the print area, in dots. + +### setPrintWidth($width) + +Set print area width. This can be used to add a right margin to the print area. Reset to default with `Printer::initialize()`. + +Parameters: + +- `int $width`: The width of the page print area, in dots. ### setReverseColors($on) Set black/white reverse mode on or off. In this mode, text is printed white on a black background. @@ -318,7 +544,7 @@ Set underline for printed text. Parameters: -- `int $underline`: Either `true`/`false`, or one of `Escpos::UNDERLINE_NONE`, `Escpos::UNDERLINE_SINGLE` or `Escpos::UNDERLINE_DOUBLE`. Defaults to `Escpos::UNDERLINE_SINGLE`. +- `int $underline`: Either `true`/`false`, or one of `Printer::UNDERLINE_NONE`, `Printer::UNDERLINE_SINGLE` or `Printer::UNDERLINE_DOUBLE`. Defaults to `Printer::UNDERLINE_SINGLE`. ### text($str) Add text to the buffer. Text should either be followed by a line-break, or `feed()` should be called after this. @@ -327,26 +553,37 @@ Parameters: - `string $str`: The string to print. -Further notes -------------- +# Further notes Posts I've written up for people who are learning how to use receipt printers: -* [What is ESC/POS, and how do I use it?](http://mike.bitrevision.com/blog/what-is-escpos-and-how-do-i-use-it), which documents the output of test.php. -* [Setting up an Epson receipt printer](http://mike.bitrevision.com/blog/2014-20-26-setting-up-an-epson-receipt-printer) -* [Getting a USB receipt printer working on Linux](http://mike.bitrevision.com/blog/2015-03-getting-a-usb-receipt-printer-working-on-linux) +* [What is ESC/POS, and how do I use it?](https://mike42.me/blog/what-is-escpos-and-how-do-i-use-it), which documents the output of `example/demo.php`. +* [Setting up an Epson receipt printer](https://mike42.me/blog/2014-20-26-setting-up-an-epson-receipt-printer) +* [Getting a USB receipt printer working on Linux](https://mike42.me/blog/2015-03-getting-a-usb-receipt-printer-working-on-linux) -Other versions --------------- -Some forks of this project have been developed by others for specific use cases. Improvements from the following projects have been incorporated into escpos-php: +# Development -- [wdoyle/EpsonESCPOS-PHP](https://github.com/wdoyle/EpsonESCPOS-PHP) -- [ronisaha/php-esc-pos](https://github.com/ronisaha/php-esc-pos) +This code is MIT licensed, and you are encouraged to contribute any modifications back to the project. -Vendor documentation --------------------- -Epson notes that not all of its printers support all ESC/POS features, and includes a table in their documentation: +For development, it's suggested that you load `imagick`, `gd` and `Xdebug` PHP exensions, and install `composer`. -* [FAQ about ESC/POS from Epson](http://content.epson.de/fileadmin/content/files/RSD/downloads/escpos.pdf) +The tests are executed on [Travis CI](https://travis-ci.org/mike42/escpos-php) over PHP 5.4, 5.5, 5.6, 7.0, 7.1 and 7.2, plus the latest LTS version of HHVM, 3.21. Older versions of PHP are not supported in current releases. -Note that many printers produced by other vendors use the same standard, and are compatible by varying degrees. +Fetch a copy of this code and load dependencies with composer: + git clone https://github.com/mike42/escpos-php + cd escpos-php/ + composer install + +Execute unit tests via `phpunit`: + + php vendor/bin/phpunit --coverage-text + +This project uses the PSR-2 standard, which can be checked via [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer): + + php vendor/bin/phpcs --standard=psr2 src/ -n + +The developer docs are build with [doxygen](https://github.com/doxygen/doxygen). Re-build them to check for documentation warnings: + + make -C doc clean && make -C doc + +Pull requests and bug reports welcome. diff --git a/htdocs/includes/mike42/escpos-php/autoload.php b/htdocs/includes/mike42/escpos-php/autoload.php new file mode 100644 index 00000000000..7779486b824 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/autoload.php @@ -0,0 +1,26 @@ +=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "4.5.*" - } + "name": "mike42/escpos-php", + "type": "library", + "description": "PHP receipt printer library for use with ESC/POS-compatible thermal and impact printers", + "homepage": "https://github.com/mike42/escpos-php", + "keywords": ["receipt", "print", "escpos", "ESC-POS", "driver"], + "license": "MIT", + "authors": [ + { + "name": "Michael Billington", + "email": "michael.billington@gmail.com" + } + ], + "config": { + "platform": { + "php": "5.4.0" + } + }, + "require": { + "php": ">=5.4.0", + "ext-mbstring": "*" + }, + "suggest": { + "guzzlehttp/guzzle": "Allows the use of the ApiConnector to send print jobs over HTTP.", + "ext-imagick": "Will be used for image printing if present. Required for PDF printing or use of custom fonts.", + "ext-gd": "Used for image printing if present." + }, + "require-dev": { + "phpunit/phpunit": "^4.8", + "squizlabs/php_codesniffer": "^3.2", + "guzzlehttp/guzzle": "^5.3" + }, + "autoload": { + "psr-4": { + "Mike42\\": "src/Mike42" + } + } } diff --git a/htdocs/includes/mike42/escpos-php/composer.lock b/htdocs/includes/mike42/escpos-php/composer.lock index ab6911c281d..d46bbc79312 100644 --- a/htdocs/includes/mike42/escpos-php/composer.lock +++ b/htdocs/includes/mike42/escpos-php/composer.lock @@ -1,24 +1,24 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "fd25f2b816df83dabf03fe7259ad4018", + "content-hash": "0094775b67f67bc65c1ff4aebb0fd065", "packages": [], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.0.4", + "version": "1.0.5", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", - "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", "shasum": "" }, "require": { @@ -29,7 +29,7 @@ "ext-pdo": "*", "ext-phar": "*", "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "2.0.*@ALPHA" + "squizlabs/php_codesniffer": "~2.0" }, "type": "library", "extra": { @@ -38,8 +38,8 @@ } }, "autoload": { - "psr-0": { - "Doctrine\\Instantiator\\": "src" + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" } }, "notification-url": "https://packagist.org/downloads/", @@ -59,7 +59,161 @@ "constructor", "instantiate" ], - "time": "2014-10-13 12:58:55" + "time": "2015-06-14T21:17:01+00:00" + }, + { + "name": "guzzlehttp/guzzle", + "version": "5.3.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "f9acb4761844317e626a32259205bec1f1bc60d2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f9acb4761844317e626a32259205bec1f1bc60d2", + "reference": "f9acb4761844317e626a32259205bec1f1bc60d2", + "shasum": "" + }, + "require": { + "guzzlehttp/ringphp": "^1.1", + "php": ">=5.4.0", + "react/promise": "^2.2" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2018-01-15T07:18:01+00:00" + }, + { + "name": "guzzlehttp/ringphp", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/RingPHP.git", + "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/dbbb91d7f6c191e5e405e900e3102ac7f261bc0b", + "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b", + "shasum": "" + }, + "require": { + "guzzlehttp/streams": "~3.0", + "php": ">=5.4.0", + "react/promise": "~2.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "ext-curl": "Guzzle will use specific adapters if cURL is present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Ring\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.", + "time": "2015-05-20T03:37:09+00:00" + }, + { + "name": "guzzlehttp/streams", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/streams.git", + "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Stream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple abstraction over streams of data", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "stream" + ], + "time": "2014-10-12T19:18:40+00:00" }, { "name": "phpdocumentor/reflection-docblock", @@ -108,34 +262,37 @@ "email": "mike.vanriel@naenius.com" } ], - "time": "2015-02-03 12:10:50" + "time": "2015-02-03T12:10:50+00:00" }, { "name": "phpspec/prophecy", - "version": "1.4.0", + "version": "v1.7.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5" + "reference": "93d39f1f7f9326d746203c7c056f300f7f126073" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5", - "reference": "8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/93d39f1f7f9326d746203c7c056f300f7f126073", + "reference": "93d39f1f7f9326d746203c7c056f300f7f126073", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", - "phpdocumentor/reflection-docblock": "~2.0", - "sebastian/comparator": "~1.1" + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", + "sebastian/comparator": "^1.1|^2.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, "require-dev": { - "phpspec/phpspec": "~2.0" + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8 || ^5.6.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "1.6.x-dev" } }, "autoload": { @@ -168,20 +325,20 @@ "spy", "stub" ], - "time": "2015-03-27 19:31:25" + "time": "2017-03-02T20:05:34+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "2.0.15", + "version": "2.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "34cc484af1ca149188d0d9e91412191e398e0b67" + "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/34cc484af1ca149188d0d9e91412191e398e0b67", - "reference": "34cc484af1ca149188d0d9e91412191e398e0b67", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", + "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", "shasum": "" }, "require": { @@ -189,7 +346,7 @@ "phpunit/php-file-iterator": "~1.3", "phpunit/php-text-template": "~1.2", "phpunit/php-token-stream": "~1.3", - "sebastian/environment": "~1.0", + "sebastian/environment": "^1.3.2", "sebastian/version": "~1.0" }, "require-dev": { @@ -204,7 +361,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "2.2.x-dev" } }, "autoload": { @@ -230,35 +387,37 @@ "testing", "xunit" ], - "time": "2015-01-24 10:06:35" + "time": "2015-10-06T15:47:00+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.3.4", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", - "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", "shasum": "" }, "require": { "php": ">=5.3.3" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, "autoload": { "classmap": [ - "File/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], @@ -275,20 +434,20 @@ "filesystem", "iterator" ], - "time": "2013-10-10 15:34:57" + "time": "2016-10-03T07:40:28+00:00" }, { "name": "phpunit/php-text-template", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", "shasum": "" }, "require": { @@ -297,20 +456,17 @@ "type": "library", "autoload": { "classmap": [ - "Text/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -319,35 +475,40 @@ "keywords": [ "template" ], - "time": "2014-01-30 17:20:04" + "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", - "version": "1.0.5", + "version": "1.0.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, "autoload": { "classmap": [ - "PHP/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], @@ -363,20 +524,20 @@ "keywords": [ "timer" ], - "time": "2013-08-02 07:42:54" + "time": "2017-02-26T11:10:40+00:00" }, { "name": "phpunit/php-token-stream", - "version": "1.4.0", + "version": "1.4.11", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74" + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/db32c18eba00b121c145575fcbcd4d4d24e6db74", - "reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7", + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7", "shasum": "" }, "require": { @@ -412,20 +573,20 @@ "keywords": [ "tokenizer" ], - "time": "2015-01-17 09:51:32" + "time": "2017-02-27T10:12:30+00:00" }, { "name": "phpunit/phpunit", - "version": "4.5.1", + "version": "4.8.36", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "d6429b0995b24a2d9dfe5587ee3a7071c1161af4" + "reference": "46023de9a91eec7dfb06cc56cb4e260017298517" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d6429b0995b24a2d9dfe5587ee3a7071c1161af4", - "reference": "d6429b0995b24a2d9dfe5587ee3a7071c1161af4", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/46023de9a91eec7dfb06cc56cb4e260017298517", + "reference": "46023de9a91eec7dfb06cc56cb4e260017298517", "shasum": "" }, "require": { @@ -435,19 +596,19 @@ "ext-reflection": "*", "ext-spl": "*", "php": ">=5.3.3", - "phpspec/prophecy": "~1.3,>=1.3.1", - "phpunit/php-code-coverage": "~2.0,>=2.0.11", - "phpunit/php-file-iterator": "~1.3.2", + "phpspec/prophecy": "^1.3.1", + "phpunit/php-code-coverage": "~2.1", + "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "~1.0.2", + "phpunit/php-timer": "^1.0.6", "phpunit/phpunit-mock-objects": "~2.3", - "sebastian/comparator": "~1.1", - "sebastian/diff": "~1.1", - "sebastian/environment": "~1.2", + "sebastian/comparator": "~1.2.2", + "sebastian/diff": "~1.2", + "sebastian/environment": "~1.3", "sebastian/exporter": "~1.2", "sebastian/global-state": "~1.0", "sebastian/version": "~1.0", - "symfony/yaml": "~2.0" + "symfony/yaml": "~2.1|~3.0" }, "suggest": { "phpunit/php-invoker": "~1.1" @@ -458,7 +619,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.5.x-dev" + "dev-master": "4.8.x-dev" } }, "autoload": { @@ -484,26 +645,27 @@ "testing", "xunit" ], - "time": "2015-03-29 09:24:05" + "time": "2017-06-21T08:07:12+00:00" }, { "name": "phpunit/phpunit-mock-objects", - "version": "2.3.1", + "version": "2.3.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "74ffb87f527f24616f72460e54b595f508dccb5c" + "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/74ffb87f527f24616f72460e54b595f508dccb5c", - "reference": "74ffb87f527f24616f72460e54b595f508dccb5c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983", + "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983", "shasum": "" }, "require": { - "doctrine/instantiator": "~1.0,>=1.0.2", + "doctrine/instantiator": "^1.0.2", "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2" + "phpunit/php-text-template": "~1.2", + "sebastian/exporter": "~1.2" }, "require-dev": { "phpunit/phpunit": "~4.4" @@ -539,26 +701,72 @@ "mock", "xunit" ], - "time": "2015-04-02 05:36:41" + "time": "2015-10-02T06:51:40+00:00" }, { - "name": "sebastian/comparator", - "version": "1.1.1", + "name": "react/promise", + "version": "v2.5.1", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + "url": "https://github.com/reactphp/promise.git", + "reference": "62785ae604c8d69725d693eb370e1d67e94c4053" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", - "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "url": "https://api.github.com/repos/reactphp/promise/zipball/62785ae604c8d69725d693eb370e1d67e94c4053", + "reference": "62785ae604c8d69725d693eb370e1d67e94c4053", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "keywords": [ + "promise", + "promises" + ], + "time": "2017-03-25T12:08:31+00:00" + }, + { + "name": "sebastian/comparator", + "version": "1.2.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", "shasum": "" }, "require": { "php": ">=5.3.3", "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2" + "sebastian/exporter": "~1.2 || ~2.0" }, "require-dev": { "phpunit/phpunit": "~4.4" @@ -566,7 +774,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "1.2.x-dev" } }, "autoload": { @@ -603,32 +811,32 @@ "compare", "equality" ], - "time": "2015-01-29 16:28:08" + "time": "2017-01-29T09:50:25+00:00" }, { "name": "sebastian/diff", - "version": "1.3.0", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", + "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", "shasum": "" }, "require": { "php": ">=5.3.3" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "~4.8" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "1.4-dev" } }, "autoload": { @@ -651,31 +859,31 @@ } ], "description": "Diff implementation", - "homepage": "http://www.github.com/sebastianbergmann/diff", + "homepage": "https://github.com/sebastianbergmann/diff", "keywords": [ "diff" ], - "time": "2015-02-22 15:13:53" + "time": "2015-12-08T07:14:41+00:00" }, { "name": "sebastian/environment", - "version": "1.2.2", + "version": "1.3.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", - "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea", + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^4.8 || ^5.0" }, "type": "library", "extra": { @@ -705,20 +913,20 @@ "environment", "hhvm" ], - "time": "2015-01-01 10:01:08" + "time": "2016-08-18T05:49:44+00:00" }, { "name": "sebastian/exporter", - "version": "1.2.0", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "84839970d05254c73cde183a721c7af13aede943" + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", - "reference": "84839970d05254c73cde183a721c7af13aede943", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", "shasum": "" }, "require": { @@ -726,12 +934,13 @@ "sebastian/recursion-context": "~1.0" }, "require-dev": { + "ext-mbstring": "*", "phpunit/phpunit": "~4.4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "1.3.x-dev" } }, "autoload": { @@ -771,20 +980,20 @@ "export", "exporter" ], - "time": "2015-01-27 07:23:06" + "time": "2016-06-17T09:04:28+00:00" }, { "name": "sebastian/global-state", - "version": "1.0.0", + "version": "1.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", - "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", "shasum": "" }, "require": { @@ -822,20 +1031,20 @@ "keywords": [ "global state" ], - "time": "2014-10-06 09:23:50" + "time": "2015-10-12T03:26:01+00:00" }, { "name": "sebastian/recursion-context", - "version": "1.0.0", + "version": "1.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/b19cc3298482a335a95f3016d2f8a6950f0fbcd7", + "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7", "shasum": "" }, "require": { @@ -875,20 +1084,20 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-01-24 09:48:32" + "time": "2016-10-03T07:41:43+00:00" }, { "name": "sebastian/version", - "version": "1.0.5", + "version": "1.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4" + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", - "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", "shasum": "" }, "type": "library", @@ -910,39 +1119,100 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-02-24 06:35:25" + "time": "2015-06-21T13:59:46+00:00" }, { - "name": "symfony/yaml", - "version": "v2.6.6", - "target-dir": "Symfony/Component/Yaml", + "name": "squizlabs/php_codesniffer", + "version": "3.2.3", "source": { "type": "git", - "url": "https://github.com/symfony/Yaml.git", - "reference": "174f009ed36379a801109955fc5a71a49fe62dd4" + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "4842476c434e375f9d3182ff7b89059583aa8b27" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/174f009ed36379a801109955fc5a71a49fe62dd4", - "reference": "174f009ed36379a801109955fc5a71a49fe62dd4", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/4842476c434e375f9d3182ff7b89059583aa8b27", + "reference": "4842476c434e375f9d3182ff7b89059583aa8b27", "shasum": "" }, "require": { - "php": ">=5.3.3" + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" }, "require-dev": { - "symfony/phpunit-bridge": "~2.7" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2018-02-20T21:35:23+00:00" + }, + { + "name": "symfony/event-dispatcher", + "version": "v2.8.18", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "bb4ec47e8e109c1c1172145732d0aa468d967cd0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/bb4ec47e8e109c1c1172145732d0aa468d967cd0", + "reference": "bb4ec47e8e109c1c1172145732d0aa468d967cd0", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "^2.0.5|~3.0.0", + "symfony/dependency-injection": "~2.6|~3.0.0", + "symfony/expression-language": "~2.6|~3.0.0", + "symfony/stopwatch": "~2.3|~3.0.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "2.8-dev" } }, "autoload": { - "psr-0": { - "Symfony\\Component\\Yaml\\": "" - } + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -950,17 +1220,66 @@ ], "authors": [ { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2017-02-21T08:33:48+00:00" + }, + { + "name": "symfony/yaml", + "version": "v2.8.18", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "2a7bab3c16f6f452c47818fdd08f3b1e49ffcf7d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/2a7bab3c16f6f452c47818fdd08f3b1e49ffcf7d", + "reference": "2a7bab3c16f6f452c47818fdd08f3b1e49ffcf7d", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ { "name": "Fabien Potencier", "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "time": "2015-03-30 15:54:10" + "homepage": "https://symfony.com", + "time": "2017-03-01T18:13:50+00:00" } ], "aliases": [], @@ -969,7 +1288,11 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.3.0" + "php": ">=5.4.0", + "ext-mbstring": "*" }, - "platform-dev": [] + "platform-dev": [], + "platform-overrides": { + "php": "5.4.0" + } } diff --git a/htdocs/includes/mike42/escpos-php/doc/FAQ.md b/htdocs/includes/mike42/escpos-php/doc/FAQ.md new file mode 100644 index 00000000000..6b7a6247bca --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/doc/FAQ.md @@ -0,0 +1,142 @@ +# Frequently Asked Questions (FAQ) + +## Can I print to File Format X with this? + +If you are trying to generate XPS, PDF or DOCX or HTML files from PHP, then you are most likely in the wrong place. + +The purpose of this driver it to generate binary ESC/POS code, which is understood by many embedded thermal receipt and impact printers. + +## I have Printer X. Can I use this driver? + +If the printer understands ESC/POS, and you know how to get raw binary data to it, then yes. Otherwise, no. + +The [list of printers that are known to work](https://github.com/mike42/escpos-php/blob/development/README.md#printers) is crowd-sourced. We appreciate it when developers try out the driver, then [file information on the bug tracker](https://github.com/mike42/escpos-php/issues/new) with some information about which features worked on their model of printer. + +To see how well your printer works, first check that it supports ESC/POS, then begin by attempting to send the text "Hello World" to your printer on the command-line, from the computer that will run PHP. + +Once you solve this, [try to do the same from PHP](https://github.com/mike42/escpos-php/blob/development/README.md#basic-usage) using the default profile. Further details are in the [README](https://github.com/mike42/escpos-php/blob/development/README.md) file. + +## Can you add support for Printer X? + +Features vary between printers, so we collaborate on an ESC/POS printer compatibility database to collect known differences: [receipt-print-hq/escpos-printer-db](https://github.com/receipt-print-hq/escpos-printer-db). + +If you encounter garbage output when you try to print images or special characters, then please submit a test page and a link to vendor documentation to the `escpos-printer-db` project, so that support can be improved for future versions. + +## I have a printer that does not understand ESC/POS. Can I use this driver? + +No. The purpose of this driver it to generate binary ESC/POS code. If your printer doesn't understand that, then this code wont be much use to you. + +Some printers do have an emulation mode for ESC/POS. The vendor docs will tell if this is the case, and how to enable it. + +## Why do I get this error when I try to print? + +Start by testing that you can send text to your printer outside of escpos-php. The examples linked to in the README are commented with some commands to get you started. + +Generally, initial setup problems seem to have one of these causes: + +1. You are writing to the wrong place. Writing to `LPT1` does not output to parallel port on Linux, and `/dev/ttyS0` is not a serial printer on Windows. +2. The printer has not been set up to accept printing the way you expect. This means permissions on Linux, network printers being configured, and shared printers having user accounts and firewalls set up correctly on the print server. +3. Your printer actually doesn't work (rare but possible). + +To be clear, these are not escpos-php issues: No amount of PHP code can set up your printer for you. Instead, the driver relies on developers determining how their setup is going to work before using a connector to transport data to their printer. + +Once you have a working command to send text to your printer (from the PHP server), you are ready to use escpos-php. You can try to use a PrintConnector now, based on your operating system and printer interface. A table is located in the README to help you select the right one. + +The connectors are- + +- `FilePrintConnector` and `NetworkPrintConnector` directly use files or network sockets. +- `WindowsPrintConnector` and `CupsPrintConnector` tie in with Windows and Unix system printing. +- `DummyPrintConnector` does not connect to a real printer, and can be used to save ESC/POS receipts to a database, for example. + +At this point, you might find that the way you would like to print is not supported by escpos-php. You can post your printing command as a feature request on the issue tracker. + +Lastly, you may run in to the final common trap: + +4. Your PHP is not running with the same sort of permissions as your login account. Again, no amount of PHP code can fix this. For example, on LAMP, your `www-data` user needs to be in the `lp` group, while on WAMP, `Local Service` account may run in to problems. SELinux and firewalls are also worth a look. + +When printing fails, you can expect a PHP Exception that explains what went wrong. They are all clues: + +- `Warning: copy(\\pc\printer): failed to open stream: Permission denied` +- `/dev/usb/lp0: Permission denied` +- `User name or password is incorrect` + +Ensure that while you are developing, you configure PHP to show error messages, so that you can see these problems. + +Please file a bug if you think that there is a specific situation which escpos-php could provide better error messages for. + +## Can I print over the network? + +Certainly, as long as your printer is available over the network. + +- `NetworkPrintConnector` will speak directly to an Ethernet-connected printer on port 9100. + +For USB or Serial printers, you need to install the printer on a computer and then share it, so that it becomes network-accessible. + +- `WindowsPrintConnector` will connect to Windows shared printers from Windows or Linux (Linux users will need Samba). +- `CupsPrintConnector` will connect to CUPS-shared printers from Linux or Mac. + +Always start by testing your shared printer setup outside of escpos-php. The examples linked to in the README are commented with some example commands to get you started. Typically, networks, firewalls and permissions need to be set up. + +Once you have a working command to send text to your printer (from the PHP server), you are ready to use escpos-php. + +If you have any issues at this stage, please ask on the issue tracker, and include the commands that you used to verify your setup. + +## Can I print from my server on the Internet? + +Since PHP is a server-side language, escpos-php is a server-side print library. The driver is able to transport data between a server and a printer in a few different ways, all of them server-side. For example, you may print to a USB printer *connected to the server running PHP*, or an Ethernet printer *on a network accessible to the server*. + +Many developers dream of having an application that is hosted on the public Internet, with POS terminals accessing it, and printing via a web browser. Because the webserver cannot see the printer in this sort of setup, a server-side print driver is not much use. + +Because of this, there are no cut-and-paste recipes available, but here are two top-level approaches you could take: + +1. Architect your application so that the server can see your printer +2. Use an application which runs client-side to deliver print data instead + +### Option 1: Allow the server to print + +Server-side printing is viable if the server can get to the printer. Here are some ways it could work: + +- Run your server on the LAN instead, and read the section above about printing over the network +- Set up a VPN so that your cloud-hosted server can also access the LAN +- Expose the printer via some other secure tunnel to the server, via SSH or TLS + +Please do your own research to determine how these may apply to your setup- the escpos-php issue tracker is not a place where you should be requesting network support. + +### Option 2: Use client software to print + +If you aren't able to set up some network infrastructure to implement the above, then you cannot use a server-side print driver. + +Here are some browser-based printing tools which you may like to consider instead. + +- Use system printing with a vendor driver, and some good `@media print` CSS +- [Chrome Raw Print](https://github.com/receipt-print-hq/chrome-raw-print) app +- [qz](https://qz.io/) +- [ePOS-Device SDK for JavaScript](https://reference.epson-biz.com/modules/ref_epos_device_js_en/index.php?content_id=139). Requires network interface card that supports ePOS (UB-E04/R04) + +Please direct queries about client-side printing products to the appropriate project. + +## Why is image printing slow? + +Three things tend to slow down the image processing: + +1. Slow PHP code +2. Data link +3. The printer itself + +First, ensure you have the Imagick plugin loaded. The driver will avoid a slower image processing implementation once you've got it. + +Next, connect over a faster interface. Serial printers have a low bit-rate, and the printer spends a lot of time waiting for data. If you have USB or Ethernet, then use it (note: storing graphics to the printer memory is not currently implemented). + +Lastly, the printer will go faster if you use less pixels. Since images are two-dimensional, scaling down by 50% removes 75% of the pixels. The driver can then print at a half the density, so that your lower resolution image appears the same size when printed. + +## How can I get the status of the printer? + +This feature is not implemented, but a solution for some Epson printers is planned. + +Only `FilePrintConnector` or `NetworkPrintConnector` will support reading from the printer, ensure that you migrate to those if you would like these features. + +## How do I produce this complex layout? + +ESC/POS "page mode" is not currently supported, which would allow some printers to render some more complex layouts natively + +Since the output is raster anyway, it is suggested that you render your output to an image and print that instead. The driver supports PDF printing via Imagick, and an example that uses `wkhtmltoimage` is available in the repository. diff --git a/htdocs/includes/mike42/escpos-php/doc/Makefile b/htdocs/includes/mike42/escpos-php/doc/Makefile index fed323f0cff..4e01c2ac0a1 100644 --- a/htdocs/includes/mike42/escpos-php/doc/Makefile +++ b/htdocs/includes/mike42/escpos-php/doc/Makefile @@ -1,9 +1,20 @@ -html: ../Escpos.php escpos.conf - doxygen escpos.conf +html: escpos.doxyfile + # Compile + doxygen escpos.doxyfile + # Filter out warnings on README.md- doxygen cannot handle image links that + # are used there: [![Caption](https://example.com/target)](https://example.com/image) + sed -i '/README.md\:/d' warnings.log + # Show warnings log + cat warnings.log + # Return failure if there were any doc warnings + [ ! -s warnings.log ] latex: html # Do nothing -clean: - rm --preserve-root -Rf html latex doxygen_sqlite3.db +xml: html + xsltproc xml/combine.xslt xml/index.xml > all.xml + +clean: + rm --preserve-root -Rf html latex xml doxygen_sqlite3.db all.xml warnings.log diff --git a/htdocs/includes/mike42/escpos-php/doc/escpos.conf b/htdocs/includes/mike42/escpos-php/doc/escpos.doxyfile similarity index 99% rename from htdocs/includes/mike42/escpos-php/doc/escpos.conf rename to htdocs/includes/mike42/escpos-php/doc/escpos.doxyfile index 54ea2874aa5..0c48656e15b 100644 --- a/htdocs/includes/mike42/escpos-php/doc/escpos.conf +++ b/htdocs/includes/mike42/escpos-php/doc/escpos.doxyfile @@ -20,7 +20,7 @@ # This tag specifies the encoding used for all characters in the config file # that follow. The default is UTF-8 which is also the encoding used for all text # before the first occurrence of this tag. Doxygen uses libiconv (or the iconv -# built into libc) for the transcoding. See https://www.gnu.org/software/libiconv +# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv # for the list of possible encodings. # The default value is: UTF-8. @@ -51,7 +51,7 @@ PROJECT_BRIEF = # and the maximum width should not exceed 200 pixels. Doxygen will copy the logo # to the output directory. -PROJECT_LOGO = ../example/images/escpos-php-small.png +PROJECT_LOGO = ../example/resources/escpos-php-small.png # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path # into which the generated documentation will be written. If a relative path is @@ -741,7 +741,7 @@ WARN_FORMAT = "$file:$line: $text" # messages should be written. If left blank the output is written to standard # error (stderr). -WARN_LOGFILE = +WARN_LOGFILE = warnings.log #--------------------------------------------------------------------------- # Configuration options related to the input files @@ -753,12 +753,12 @@ WARN_LOGFILE = # spaces. # Note: If this tag is empty the current directory is searched. -INPUT = ../Escpos.php ../src/ ../README.md +INPUT = ../src ../README.md ./ # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses # libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: https://www.gnu.org/software/libiconv) for the list of +# documentation (see: http://www.gnu.org/software/libiconv) for the list of # possible encodings. # The default value is: UTF-8. @@ -773,13 +773,13 @@ INPUT_ENCODING = UTF-8 # *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, # *.qsf, *.as and *.js. -FILE_PATTERNS = +FILE_PATTERNS = *.php *.md # The RECURSIVE tag can be used to specify whether or not subdirectories should # be searched for input files as well. # The default value is: NO. -RECURSIVE = NO +RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should be # excluded from the INPUT source files. This way you can easily exclude a @@ -950,7 +950,7 @@ SOURCE_TOOLTIPS = YES # If the USE_HTAGS tag is set to YES then the references to source code will # point to the HTML generated by the htags(1) tool instead of doxygen built-in # source browser. The htags tool is part of GNU's global source tagging system -# (see https://www.gnu.org/software/global/global.html). You will need version +# (see http://www.gnu.org/software/global/global.html). You will need version # 4.8.6 or higher. # # To use it do the following: @@ -1820,7 +1820,7 @@ MAN_LINKS = NO # captures the structure of the code including all documentation. # The default value is: NO. -GENERATE_XML = NO +GENERATE_XML = YES # The XML_OUTPUT tag is used to specify where the XML pages will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of diff --git a/htdocs/includes/mike42/escpos-php/example/README.md b/htdocs/includes/mike42/escpos-php/example/README.md index 68b0dc77e7c..e59e6c095e4 100644 --- a/htdocs/includes/mike42/escpos-php/example/README.md +++ b/htdocs/includes/mike42/escpos-php/example/README.md @@ -23,4 +23,4 @@ Each example prints to standard output, so either edit the print connector, or r - `print-from-html.php` - Runs `wkhtmltoimage` to convert HTML to an image, and then prints the image. (This is very slow) - `character-tables.php` - Prints a compact character code table for each available character set. Used to debug incorrect output from `character-encodings.php`. - `print-from-pdf.php` - Loads a PDF and prints each page in a few different ways (very slow as well) - +- `rawbt-receipt` (.php & .html) - Demonstration of Back and Front for integration between the site and the Android application “RawBT - Printer Driver for Android” diff --git a/htdocs/includes/mike42/escpos-php/example/barcode.php b/htdocs/includes/mike42/escpos-php/example/barcode.php index 5475b76c19d..d3ef9f2f44a 100644 --- a/htdocs/includes/mike42/escpos-php/example/barcode.php +++ b/htdocs/includes/mike42/escpos-php/example/barcode.php @@ -1,181 +1,207 @@ setBarcodeHeight ( 40 ); +require __DIR__ . '/../autoload.php'; +use Mike42\Escpos\Printer; +use Mike42\Escpos\PrintConnectors\FilePrintConnector; + +$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); + +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 ( Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_DOUBLE_WIDTH ); -$printer->text ( "Text position\n" ); -$printer->selectPrintMode (); +$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH); +$printer->text("Text position\n"); +$printer->selectPrintMode(); $hri = array ( - Escpos::BARCODE_TEXT_NONE => "No text", - Escpos::BARCODE_TEXT_ABOVE => "Above", - Escpos::BARCODE_TEXT_BELOW => "Below", - Escpos::BARCODE_TEXT_ABOVE | Escpos::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" ); - $printer->setBarcodeTextPosition ( $position ); - $printer->barcode ( "012345678901", Escpos::BARCODE_JAN13 ); - $printer->feed (); +foreach ($hri as $position => $caption) { + $printer->text($caption . "\n"); + $printer->setBarcodeTextPosition($position); + $printer->barcode("012345678901", Printer::BARCODE_JAN13); + $printer->feed(); } /* Barcode types */ $standards = array ( - Escpos::BARCODE_UPCA => array ( - "title" => "UPC-A", - "caption" => "Fixed-length numeric product barcodes.", - "example" => array ( - array ( - "caption" => "12 char numeric including (wrong) check digit.", - "content" => "012345678901" - ), - array ( - "caption" => "Send 11 chars to add check digit automatically.", - "content" => "01234567890" - ) - ) - ), - Escpos::BARCODE_UPCE => array ( - "title" => "UPC-E", - "caption" => "Fixed-length numeric compact product barcodes.", - "example" => array ( - array ( - "caption" => "6 char numeric - auto check digit & NSC", - "content" => "123456" - ), - array ( - "caption" => "7 char numeric - auto check digit", - "content" => "0123456" - ), - array ( - "caption" => "8 char numeric", - "content" => "01234567" - ), - array ( - "caption" => "11 char numeric - auto check digit", - "content" => "01234567890" - ), - array ( - "caption" => "12 char numeric including (wrong) check digit", - "content" => "012345678901" - ) - ) - ), - Escpos::BARCODE_JAN13 => array ( - "title" => "JAN13/EAN13", - "caption" => "Fixed-length numeric barcodes.", - "example" => array ( - array ( - "caption" => "12 char numeric - auto check digit", - "content" => "012345678901" - ), - array ( - "caption" => "13 char numeric including (wrong) check digit", - "content" => "0123456789012" - ) - ) - ), - Escpos::BARCODE_JAN8 => array ( - "title" => "JAN8/EAN8", - "caption" => "Fixed-length numeric barcodes.", - "example" => array ( - array ( - "caption" => "7 char numeric - auto check digit", - "content" => "0123456" - ), - array ( - "caption" => "8 char numeric including (wrong) check digit", - "content" => "01234567" - ) - ) - ), - Escpos::BARCODE_CODE39 => array ( - "title" => "Code39", - "caption" => "Variable length alphanumeric w/ some special chars.", - "example" => array ( - array ( - "caption" => "Text, numbers, spaces", - "content" => "ABC 012" - ), - array ( - "caption" => "Special characters", - "content" => "$%+-./" - ), - array ( - "caption" => "Extra char (*) Used as start/stop", - "content" => "*TEXT*" - ) - ) - ), - Escpos::BARCODE_ITF => array ( - "title" => "ITF", - "caption" => "Variable length numeric w/even number of digits,\nas they are encoded in pairs.", - "example" => array ( - array ( - "caption" => "Numeric- even number of digits", - "content" => "0123456789" - ) - ) - ), - Escpos::BARCODE_CODABAR => array ( - "title" => "Codabar", - "caption" => "Varaible length numeric with some allowable\nextra characters. ABCD/abcd must be used as\nstart/stop characters (one at the start, one\nat the end) to distinguish between barcode\napplications.", - "example" => array ( - array ( - "caption" => "Numeric w/ A A start/stop. ", - "content" => "A012345A" - ), - array ( - "caption" => "Extra allowable characters", - "content" => "A012$+-./:A" - ) - ) - ), - Escpos::BARCODE_CODE93 => array ( - "title" => "Code93", - "caption" => "Variable length- any ASCII is available", - "example" => array ( - array ( - "caption" => "Text", - "content" => "012abcd" - ) - ) - ), - Escpos::BARCODE_CODE128 => array ( - "title" => "Code128", - "caption" => "Variable length- any ASCII is available", - "example" => array ( - array ( - "caption" => "Code set A uppercase & symbols", - "content" => "{A" . "012ABCD" - ), - array ( - "caption" => "Code set B general text", - "content" => "{B" . "012ABCDabcd" - ), - array ( - "caption" => "Code set C compact numbers\n Sending chr(21) chr(32) chr(43)", - "content" => "{C" . chr ( 21 ) . chr ( 32 ) . chr ( 43 ) - ) - ) - ) + Printer::BARCODE_UPCA => array ( + "title" => "UPC-A", + "caption" => "Fixed-length numeric product barcodes.", + "example" => array ( + array ( + "caption" => "12 char numeric including (wrong) check digit.", + "content" => "012345678901" + ), + array ( + "caption" => "Send 11 chars to add check digit automatically.", + "content" => "01234567890" + ) + ) + ), + Printer::BARCODE_UPCE => array ( + "title" => "UPC-E", + "caption" => "Fixed-length numeric compact product barcodes.", + "example" => array ( + array ( + "caption" => "6 char numeric - auto check digit & NSC", + "content" => "123456" + ), + array ( + "caption" => "7 char numeric - auto check digit", + "content" => "0123456" + ), + array ( + "caption" => "8 char numeric", + "content" => "01234567" + ), + array ( + "caption" => "11 char numeric - auto check digit", + "content" => "01234567890" + ), + array ( + "caption" => "12 char numeric including (wrong) check digit", + "content" => "012345678901" + ) + ) + ), + Printer::BARCODE_JAN13 => array ( + "title" => "JAN13/EAN13", + "caption" => "Fixed-length numeric barcodes.", + "example" => array ( + array ( + "caption" => "12 char numeric - auto check digit", + "content" => "012345678901" + ), + array ( + "caption" => "13 char numeric including (wrong) check digit", + "content" => "0123456789012" + ) + ) + ), + Printer::BARCODE_JAN8 => array ( + "title" => "JAN8/EAN8", + "caption" => "Fixed-length numeric barcodes.", + "example" => array ( + array ( + "caption" => "7 char numeric - auto check digit", + "content" => "0123456" + ), + array ( + "caption" => "8 char numeric including (wrong) check digit", + "content" => "01234567" + ) + ) + ), + Printer::BARCODE_CODE39 => array ( + "title" => "Code39", + "caption" => "Variable length alphanumeric w/ some special chars.", + "example" => array ( + array ( + "caption" => "Text, numbers, spaces", + "content" => "ABC 012" + ), + array ( + "caption" => "Special characters", + "content" => "$%+-./" + ), + array ( + "caption" => "Extra char (*) Used as start/stop", + "content" => "*TEXT*" + ) + ) + ), + Printer::BARCODE_ITF => array ( + "title" => "ITF", + "caption" => "Variable length numeric w/even number of digits,\nas they are encoded in pairs.", + "example" => array ( + array ( + "caption" => "Numeric- even number of digits", + "content" => "0123456789" + ) + ) + ), + Printer::BARCODE_CODABAR => array ( + "title" => "Codabar", + "caption" => "Varaible length numeric with some allowable\nextra characters. ABCD/abcd must be used as\nstart/stop characters (one at the start, one\nat the end) to distinguish between barcode\napplications.", + "example" => array ( + array ( + "caption" => "Numeric w/ A A start/stop. ", + "content" => "A012345A" + ), + array ( + "caption" => "Extra allowable characters", + "content" => "A012$+-./:A" + ) + ) + ), + Printer::BARCODE_CODE93 => array ( + "title" => "Code93", + "caption" => "Variable length- any ASCII is available", + "example" => array ( + array ( + "caption" => "Text", + "content" => "012abcd" + ) + ) + ), + Printer::BARCODE_CODE128 => array ( + "title" => "Code128", + "caption" => "Variable length- any ASCII is available", + "example" => array ( + array ( + "caption" => "Code set A uppercase & symbols", + "content" => "{A" . "012ABCD" + ), + array ( + "caption" => "Code set B general text", + "content" => "{B" . "012ABCDabcd" + ), + array ( + "caption" => "Code set C compact numbers\n Sending chr(21) chr(32) chr(43)", + "content" => "{C" . chr(21) . chr(32) . chr(43) + ) + ) + ) ); -$printer->setBarcodeTextPosition ( Escpos::BARCODE_TEXT_BELOW ); -foreach ( $standards as $type => $standard ) { - $printer->selectPrintMode ( Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_DOUBLE_WIDTH ); - $printer->text ( $standard ["title"] . "\n" ); - $printer->selectPrintMode (); - $printer->text ( $standard ["caption"] . "\n\n" ); - foreach ( $standard ["example"] as $id => $barcode ) { - $printer->setEmphasis ( true ); - $printer->text ( $barcode ["caption"] . "\n" ); - $printer->setEmphasis ( false ); - $printer->text ( "Content: " . $barcode ["content"] . "\n" ); - $printer->barcode ( $barcode ["content"], $type ); - $printer->feed (); - } +$printer->setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW); +foreach ($standards as $type => $standard) { + $printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH); + $printer->text($standard ["title"] . "\n"); + $printer->selectPrintMode(); + $printer->text($standard ["caption"] . "\n\n"); + foreach ($standard ["example"] as $id => $barcode) { + $printer->setEmphasis(true); + $printer->text($barcode ["caption"] . "\n"); + $printer->setEmphasis(false); + $printer->text("Content: " . $barcode ["content"] . "\n"); + $printer->barcode($barcode ["content"], $type); + $printer->feed(); + } } -$printer->cut (); -$printer->close (); - +$printer->cut(); +$printer->close(); diff --git a/htdocs/includes/mike42/escpos-php/example/bit-image.php b/htdocs/includes/mike42/escpos-php/example/bit-image.php index f3a4054d98f..befebf80b9f 100644 --- a/htdocs/includes/mike42/escpos-php/example/bit-image.php +++ b/htdocs/includes/mike42/escpos-php/example/bit-image.php @@ -1,32 +1,36 @@ text("These example images are printed with the older\nbit image print command. You should only use\n\$p -> bitImage() if \$p -> graphics() does not\nwork on your printer.\n\n"); - - $printer -> bitImage($tux); - $printer -> text("Regular Tux (bit image).\n"); - $printer -> feed(); - - $printer -> bitImage($tux, Escpos::IMG_DOUBLE_WIDTH); - $printer -> text("Wide Tux (bit image).\n"); - $printer -> feed(); - - $printer -> bitImage($tux, Escpos::IMG_DOUBLE_HEIGHT); - $printer -> text("Tall Tux (bit image).\n"); - $printer -> feed(); - - $printer -> bitImage($tux, Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT); - $printer -> text("Large Tux in correct proportion (bit image).\n"); -} catch(Exception $e) { - /* Images not supported on your PHP, or image file not found */ - $printer -> text($e -> getMessage() . "\n"); + $printer -> text("These example images are printed with the older\nbit image print command. You should only use\n\$p -> bitImage() if \$p -> graphics() does not\nwork on your printer.\n\n"); + + $printer -> bitImage($tux); + $printer -> text("Regular Tux (bit image).\n"); + $printer -> feed(); + + $printer -> bitImage($tux, Printer::IMG_DOUBLE_WIDTH); + $printer -> text("Wide Tux (bit image).\n"); + $printer -> feed(); + + $printer -> bitImage($tux, Printer::IMG_DOUBLE_HEIGHT); + $printer -> text("Tall Tux (bit image).\n"); + $printer -> feed(); + + $printer -> bitImage($tux, Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT); + $printer -> text("Large Tux in correct proportion (bit image).\n"); +} catch (Exception $e) { + /* Images not supported on your PHP, or image file not found */ + $printer -> text($e -> getMessage() . "\n"); } $printer -> cut(); $printer -> close(); -?> diff --git a/htdocs/includes/mike42/escpos-php/example/character-encodings-with-images.php b/htdocs/includes/mike42/escpos-php/example/character-encodings-with-images.php index a98bdbc96ae..bc99c2f1872 100644 --- a/htdocs/includes/mike42/escpos-php/example/character-encodings-with-images.php +++ b/htdocs/includes/mike42/escpos-php/example/character-encodings-with-images.php @@ -1,12 +1,17 @@ selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_EMPHASIZED | Escpos::MODE_DOUBLE_WIDTH); - $printer -> text("Implemented languages\n"); - $printer -> selectPrintMode(); - foreach($inputsOk as $label => $str) { - $printer -> setEmphasis(true); - $printer -> text($label . ":\n"); - $printer -> setEmphasis(false); - foreach($buffers as $buffer) { - $printer -> setPrintBuffer($buffer); - $printer -> text($str); - } - $printer -> setPrintBuffer($buffers[0]); - } - $printer -> feed(); - - $printer -> selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_EMPHASIZED | Escpos::MODE_DOUBLE_WIDTH); - $printer -> text("Works in progress\n"); - $printer -> selectPrintMode(); - foreach($inputsNotOk as $label => $str) { - $printer -> setEmphasis(true); - $printer -> text($label . ":\n"); - $printer -> setEmphasis(false); - foreach($buffers as $buffer) { - $printer -> setPrintBuffer($buffer); - $printer -> text($str); - } - $printer -> setPrintBuffer($buffers[0]); - } - $printer -> cut(); + /* Print a series of receipts containing i18n example strings */ + $printer = new Printer($connector, $profile); + $printer -> selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_EMPHASIZED | Printer::MODE_DOUBLE_WIDTH); + $printer -> text("Implemented languages\n"); + $printer -> selectPrintMode(); + foreach ($inputsOk as $label => $str) { + $printer -> setEmphasis(true); + $printer -> text($label . ":\n"); + $printer -> setEmphasis(false); + foreach ($buffers as $buffer) { + $printer -> setPrintBuffer($buffer); + $printer -> text($str); + } + $printer -> setPrintBuffer($buffers[0]); + } + $printer -> feed(); + + $printer -> selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_EMPHASIZED | Printer::MODE_DOUBLE_WIDTH); + $printer -> text("Works in progress\n"); + $printer -> selectPrintMode(); + foreach ($inputsNotOk as $label => $str) { + $printer -> setEmphasis(true); + $printer -> text($label . ":\n"); + $printer -> setEmphasis(false); + foreach ($buffers as $buffer) { + $printer -> setPrintBuffer($buffer); + $printer -> text($str); + } + $printer -> setPrintBuffer($buffers[0]); + } + $printer -> cut(); - /* Close printer */ - $printer -> close(); -} catch(Exception $e) { - echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; + /* Close printer */ + $printer -> close(); +} catch (Exception $e) { + echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; } - diff --git a/htdocs/includes/mike42/escpos-php/example/character-encodings.php b/htdocs/includes/mike42/escpos-php/example/character-encodings.php index 8a42ecd0847..a38e99fb9ea 100644 --- a/htdocs/includes/mike42/escpos-php/example/character-encodings.php +++ b/htdocs/includes/mike42/escpos-php/example/character-encodings.php @@ -1,58 +1,60 @@ selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_EMPHASIZED | Escpos::MODE_DOUBLE_WIDTH); - $printer -> text("Implemented languages\n"); - $printer -> selectPrintMode(); - foreach($inputsOk as $label => $str) { - $printer -> setEmphasis(true); - $printer -> text($label . ":\n"); - $printer -> setEmphasis(false); - $printer -> text($str); - } - $printer -> feed(); - - $printer -> selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_EMPHASIZED | Escpos::MODE_DOUBLE_WIDTH); - $printer -> text("Works in progress\n"); - $printer -> selectPrintMode(); - foreach($inputsNotOk as $label => $str) { - $printer -> setEmphasis(true); - $printer -> text($label . ":\n"); - $printer -> setEmphasis(false); - $printer -> text($str); - } - $printer -> cut(); + // Enter connector and capability profile (to match your printer) + $connector = new FilePrintConnector("php://stdout"); + $profile = CapabilityProfile::load("default"); + + /* Print a series of receipts containing i18n example strings */ + $printer = new Printer($connector, $profile); + $printer -> selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_EMPHASIZED | Printer::MODE_DOUBLE_WIDTH); + $printer -> text("Implemented languages\n"); + $printer -> selectPrintMode(); + foreach ($inputsOk as $label => $str) { + $printer -> setEmphasis(true); + $printer -> text($label . ":\n"); + $printer -> setEmphasis(false); + $printer -> text($str); + } + $printer -> feed(); + + $printer -> selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_EMPHASIZED | Printer::MODE_DOUBLE_WIDTH); + $printer -> text("Works in progress\n"); + $printer -> selectPrintMode(); + foreach ($inputsNotOk as $label => $str) { + $printer -> setEmphasis(true); + $printer -> text($label . ":\n"); + $printer -> setEmphasis(false); + $printer -> text($str); + } + $printer -> cut(); - /* Close printer */ - $printer -> close(); -} catch(Exception $e) { - echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; + /* Close printer */ + $printer -> close(); +} catch (Exception $e) { + echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; } - diff --git a/htdocs/includes/mike42/escpos-php/example/character-tables.php b/htdocs/includes/mike42/escpos-php/example/character-tables.php index 1ce2c5c9f1e..d2ab8bbcfa1 100644 --- a/htdocs/includes/mike42/escpos-php/example/character-tables.php +++ b/htdocs/includes/mike42/escpos-php/example/character-tables.php @@ -4,68 +4,72 @@ * for debugging character-encoding issues: If your printer does not work with * a built-in capability profile, you need to check its documentation for * supported code pages. - * + * * These are then loaded into a capability profile, which maps code page * numbers to iconv encoding names on your particular printer. This script * will print all configured code pages, so that you can check that the chosen * iconv encoding name matches the actual code page contents. - * + * * If this is correctly set up for your printer, then the driver will try its * best to map UTF-8 text into these code pages for you, allowing you to accept * arbitrary input from a database, without worrying about encoding it for the printer. */ -require_once(dirname(__FILE__) . "/../Escpos.php"); +require __DIR__ . '/../autoload.php'; +use Mike42\Escpos\Printer; +use Mike42\Escpos\PrintConnectors\FilePrintConnector; +use Mike42\Escpos\CapabilityProfile; // Enter connector and capability profile (to match your printer) $connector = new FilePrintConnector("php://stdout"); -$profile = DefaultCapabilityProfile::getInstance(); +$profile = CapabilityProfile::load("default"); $verbose = false; // Skip tables which iconv wont convert to (ie, only print characters available with UTF-8 input) /* Print a series of receipts containing i18n example strings - Code below shouldn't need changing */ -$printer = new Escpos($connector, $profile); -$codePages = $profile -> getSupportedCodePages(); +$printer = new Mike42\Escpos\Printer($connector, $profile); +$codePages = $profile -> getCodePages(); $first = true; // Print larger table for first code-page. -foreach($codePages as $table => $name) { - /* Change printer code page */ - $printer -> selectCharacterTable(255); - $printer -> selectCharacterTable($table); - /* Select & print a label for it */ - $label = $name; - if($name === false) { - $label= " (not matched to iconv table)"; - } - $printer -> setEmphasis(true); - $printer -> textRaw("Table $table: $label\n"); - $printer -> setEmphasis(false); - if($name === false && !$verbose) { - continue; // Skip non-recognised - } - /* Print a table of available characters (first table is larger than subsequent ones */ - if($first) { - $first = false; - compactCharTable($printer, 1, true); - } else { - compactCharTable($printer); - } +foreach ($codePages as $table => $page) { + /* Change printer code page */ + $printer -> selectCharacterTable(255); + $printer -> selectCharacterTable($table); + /* Select & print a label for it */ + $label = $page -> getId(); + if (!$page -> isEncodable()) { + $label= " (not supported)"; + } + $printer -> setEmphasis(true); + $printer -> textRaw("Table $table: $label\n"); + $printer -> setEmphasis(false); + if (!$page -> isEncodable() && !$verbose) { + continue; // Skip non-recognised + } + /* Print a table of available characters (first table is larger than subsequent ones */ + if ($first) { + $first = false; + compactCharTable($printer, 1, true); + } else { + compactCharTable($printer); + } } $printer -> cut(); $printer -> close(); -function compactCharTable($printer, $start = 4, $header = false) { - /* Output a compact character table for the current encoding */ - $chars = str_repeat(' ', 256); - for($i = 0; $i < 255; $i++) { - $chars[$i] = ($i > 32 && $i != 127) ? chr($i) : ' '; - } - if($header) { - $printer -> setEmphasis(true); - $printer -> textRaw(" 0123456789ABCDEF0123456789ABCDEF\n"); - $printer -> setEmphasis(false); - } - for($y = $start; $y < 8; $y++) { - $printer -> setEmphasis(true); - $printer -> textRaw(strtoupper(dechex($y * 2)) . " "); - $printer -> setEmphasis(false); - $printer -> textRaw(substr($chars, $y * 32, 32) . "\n"); - } +function compactCharTable($printer, $start = 4, $header = false) +{ + /* Output a compact character table for the current encoding */ + $chars = str_repeat(' ', 256); + for ($i = 0; $i < 255; $i++) { + $chars[$i] = ($i > 32 && $i != 127) ? chr($i) : ' '; + } + if ($header) { + $printer -> setEmphasis(true); + $printer -> textRaw(" 0123456789ABCDEF0123456789ABCDEF\n"); + $printer -> setEmphasis(false); + } + for ($y = $start; $y < 8; $y++) { + $printer -> setEmphasis(true); + $printer -> textRaw(strtoupper(dechex($y * 2)) . " "); + $printer -> setEmphasis(false); + $printer -> textRaw(substr($chars, $y * 32, 32) . "\n"); + } } diff --git a/htdocs/includes/mike42/escpos-php/example/customer-display.php b/htdocs/includes/mike42/escpos-php/example/customer-display.php new file mode 100644 index 00000000000..47947789540 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/customer-display.php @@ -0,0 +1,51 @@ + feed(); + $display -> text($line); + usleep(500000); +} + +// Finish by showing "Hello World" +$display -> clear(); +$display -> text("Hello World\n"); + +// Dont forget to close the device +$display -> close(); diff --git a/htdocs/includes/mike42/escpos-php/example/demo.php b/htdocs/includes/mike42/escpos-php/example/demo.php index 1c99e5cc880..f0e357ed431 100644 --- a/htdocs/includes/mike42/escpos-php/example/demo.php +++ b/htdocs/includes/mike42/escpos-php/example/demo.php @@ -8,8 +8,13 @@ * * @author Michael Billington */ -require_once(dirname(__FILE__) . "/../Escpos.php"); -$printer = new Escpos(); +require __DIR__ . '/../autoload.php'; +use Mike42\Escpos\Printer; +use Mike42\Escpos\PrintConnectors\FilePrintConnector; +use Mike42\Escpos\EscposImage; + +$connector = new FilePrintConnector("php://stdout"); +$printer = new Printer($connector); /* Initialize */ $printer -> initialize(); @@ -29,132 +34,132 @@ $printer -> cut(); /* Font modes */ $modes = array( - Escpos::MODE_FONT_B, - Escpos::MODE_EMPHASIZED, - Escpos::MODE_DOUBLE_HEIGHT, - Escpos::MODE_DOUBLE_WIDTH, - Escpos::MODE_UNDERLINE); -for($i = 0; $i < pow(2, count($modes)); $i++) { - $bits = str_pad(decbin($i), count($modes), "0", STR_PAD_LEFT); - $mode = 0; - for($j = 0; $j < strlen($bits); $j++) { - if(substr($bits, $j, 1) == "1") { - $mode |= $modes[$j]; - } - } - $printer -> selectPrintMode($mode); - $printer -> text("ABCDEFGHIJabcdefghijk\n"); + Printer::MODE_FONT_B, + Printer::MODE_EMPHASIZED, + Printer::MODE_DOUBLE_HEIGHT, + Printer::MODE_DOUBLE_WIDTH, + Printer::MODE_UNDERLINE); +for ($i = 0; $i < pow(2, count($modes)); $i++) { + $bits = str_pad(decbin($i), count($modes), "0", STR_PAD_LEFT); + $mode = 0; + for ($j = 0; $j < strlen($bits); $j++) { + if (substr($bits, $j, 1) == "1") { + $mode |= $modes[$j]; + } + } + $printer -> selectPrintMode($mode); + $printer -> text("ABCDEFGHIJabcdefghijk\n"); } $printer -> selectPrintMode(); // Reset $printer -> cut(); /* Underline */ -for($i = 0; $i < 3; $i++) { - $printer -> setUnderline($i); - $printer -> text("The quick brown fox jumps over the lazy dog\n"); +for ($i = 0; $i < 3; $i++) { + $printer -> setUnderline($i); + $printer -> text("The quick brown fox jumps over the lazy dog\n"); } $printer -> setUnderline(0); // Reset $printer -> cut(); /* Cuts */ $printer -> text("Partial cut\n(not available on all printers)\n"); -$printer -> cut(Escpos::CUT_PARTIAL); +$printer -> cut(Printer::CUT_PARTIAL); $printer -> text("Full cut\n"); -$printer -> cut(Escpos::CUT_FULL); +$printer -> cut(Printer::CUT_FULL); /* Emphasis */ -for($i = 0; $i < 2; $i++) { - $printer -> setEmphasis($i == 1); - $printer -> text("The quick brown fox jumps over the lazy dog\n"); +for ($i = 0; $i < 2; $i++) { + $printer -> setEmphasis($i == 1); + $printer -> text("The quick brown fox jumps over the lazy dog\n"); } $printer -> setEmphasis(false); // Reset $printer -> cut(); /* Double-strike (looks basically the same as emphasis) */ -for($i = 0; $i < 2; $i++) { - $printer -> setDoubleStrike($i == 1); - $printer -> text("The quick brown fox jumps over the lazy dog\n"); +for ($i = 0; $i < 2; $i++) { + $printer -> setDoubleStrike($i == 1); + $printer -> text("The quick brown fox jumps over the lazy dog\n"); } $printer -> setDoubleStrike(false); $printer -> cut(); /* Fonts (many printers do not have a 'Font C') */ $fonts = array( - Escpos::FONT_A, - Escpos::FONT_B, - Escpos::FONT_C); -for($i = 0; $i < count($fonts); $i++) { - $printer -> setFont($fonts[$i]); - $printer -> text("The quick brown fox jumps over the lazy dog\n"); + Printer::FONT_A, + Printer::FONT_B, + Printer::FONT_C); +for ($i = 0; $i < count($fonts); $i++) { + $printer -> setFont($fonts[$i]); + $printer -> text("The quick brown fox jumps over the lazy dog\n"); } $printer -> setFont(); // Reset $printer -> cut(); /* Justification */ $justification = array( - Escpos::JUSTIFY_LEFT, - Escpos::JUSTIFY_CENTER, - Escpos::JUSTIFY_RIGHT); -for($i = 0; $i < count($justification); $i++) { - $printer -> setJustification($justification[$i]); - $printer -> text("A man a plan a canal panama\n"); + Printer::JUSTIFY_LEFT, + Printer::JUSTIFY_CENTER, + Printer::JUSTIFY_RIGHT); +for ($i = 0; $i < count($justification); $i++) { + $printer -> setJustification($justification[$i]); + $printer -> text("A man a plan a canal panama\n"); } $printer -> setJustification(); // Reset $printer -> cut(); /* Barcodes - see barcode.php for more detail */ $printer -> setBarcodeHeight(80); -$printer->setBarcodeTextPosition ( Escpos::BARCODE_TEXT_BELOW ); +$printer->setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW); $printer -> barcode("9876"); $printer -> feed(); $printer -> cut(); /* Graphics - this demo will not work on some non-Epson printers */ try { - $logo = new EscposImage("resources/escpos-php.png"); - $imgModes = array( - Escpos::IMG_DEFAULT, - Escpos::IMG_DOUBLE_WIDTH, - Escpos::IMG_DOUBLE_HEIGHT, - Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT - ); - foreach($imgModes as $mode) { - $printer -> graphics($logo, $mode); - } -} catch(Exception $e) { - /* Images not supported on your PHP, or image file not found */ - $printer -> text($e -> getMessage() . "\n"); + $logo = EscposImage::load("resources/escpos-php.png", false); + $imgModes = array( + Printer::IMG_DEFAULT, + Printer::IMG_DOUBLE_WIDTH, + Printer::IMG_DOUBLE_HEIGHT, + Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT + ); + foreach ($imgModes as $mode) { + $printer -> graphics($logo, $mode); + } +} catch (Exception $e) { + /* Images not supported on your PHP, or image file not found */ + $printer -> text($e -> getMessage() . "\n"); } $printer -> cut(); /* Bit image */ try { - $logo = new EscposImage("resources/escpos-php.png"); - $imgModes = array( - Escpos::IMG_DEFAULT, - Escpos::IMG_DOUBLE_WIDTH, - Escpos::IMG_DOUBLE_HEIGHT, - Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT - ); - foreach($imgModes as $mode) { - $printer -> bitImage($logo, $mode); - } -} catch(Exception $e) { - /* Images not supported on your PHP, or image file not found */ - $printer -> text($e -> getMessage() . "\n"); + $logo = EscposImage::load("resources/escpos-php.png", false); + $imgModes = array( + Printer::IMG_DEFAULT, + Printer::IMG_DOUBLE_WIDTH, + Printer::IMG_DOUBLE_HEIGHT, + Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT + ); + foreach ($imgModes as $mode) { + $printer -> bitImage($logo, $mode); + } +} catch (Exception $e) { + /* Images not supported on your PHP, or image file not found */ + $printer -> text($e -> getMessage() . "\n"); } $printer -> cut(); /* QR Code - see also the more in-depth demo at qr-code.php */ $testStr = "Testing 123"; $models = array( - Escpos::QR_MODEL_1 => "QR Model 1", - Escpos::QR_MODEL_2 => "QR Model 2 (default)", - Escpos::QR_MICRO => "Micro QR code\n(not supported on all printers)"); -foreach($models as $model => $name) { - $printer -> qrCode($testStr, Escpos::QR_ECLEVEL_L, 3, $model); - $printer -> text("$name\n"); - $printer -> feed(); + Printer::QR_MODEL_1 => "QR Model 1", + Printer::QR_MODEL_2 => "QR Model 2 (default)", + Printer::QR_MICRO => "Micro QR code\n(not supported on all printers)"); +foreach ($models as $model => $name) { + $printer -> qrCode($testStr, Printer::QR_ECLEVEL_L, 3, $model); + $printer -> text("$name\n"); + $printer -> feed(); } $printer -> cut(); @@ -164,4 +169,3 @@ $printer -> pulse(); /* Always close the printer! On some PrintConnectors, no actual * data is sent until the printer is closed. */ $printer -> close(); -?> diff --git a/htdocs/includes/mike42/escpos-php/example/graphics.php b/htdocs/includes/mike42/escpos-php/example/graphics.php index 7650b6b9a08..49b02b9b0d9 100644 --- a/htdocs/includes/mike42/escpos-php/example/graphics.php +++ b/htdocs/includes/mike42/escpos-php/example/graphics.php @@ -1,32 +1,36 @@ graphics($tux); - $printer -> text("Regular Tux.\n"); - $printer -> feed(); - - $printer -> graphics($tux, Escpos::IMG_DOUBLE_WIDTH); - $printer -> text("Wide Tux.\n"); - $printer -> feed(); - - $printer -> graphics($tux, Escpos::IMG_DOUBLE_HEIGHT); - $printer -> text("Tall Tux.\n"); - $printer -> feed(); - - $printer -> graphics($tux, Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT); - $printer -> text("Large Tux in correct proportion.\n"); - - $printer -> cut(); -} catch(Exception $e) { - /* Images not supported on your PHP, or image file not found */ - $printer -> text($e -> getMessage() . "\n"); + $tux = EscposImage::load("resources/tux.png", false); + + $printer -> graphics($tux); + $printer -> text("Regular Tux.\n"); + $printer -> feed(); + + $printer -> graphics($tux, Printer::IMG_DOUBLE_WIDTH); + $printer -> text("Wide Tux.\n"); + $printer -> feed(); + + $printer -> graphics($tux, Printer::IMG_DOUBLE_HEIGHT); + $printer -> text("Tall Tux.\n"); + $printer -> feed(); + + $printer -> graphics($tux, Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT); + $printer -> text("Large Tux in correct proportion.\n"); + + $printer -> cut(); +} catch (Exception $e) { + /* Images not supported on your PHP, or image file not found */ + $printer -> text($e -> getMessage() . "\n"); } $printer -> close(); -?> diff --git a/htdocs/includes/mike42/escpos-php/example/interface/cups.php b/htdocs/includes/mike42/escpos-php/example/interface/cups.php new file mode 100644 index 00000000000..8b65ab3d4d9 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/interface/cups.php @@ -0,0 +1,19 @@ + text("Hello World!\n"); + $printer -> cut(); + + /* Close printer */ + $printer -> close(); +} catch (Exception $e) { + echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; +} diff --git a/htdocs/includes/mike42/escpos-php/example/interface/ethernet.php b/htdocs/includes/mike42/escpos-php/example/interface/ethernet.php index bfea443903c..129af5ce3aa 100644 --- a/htdocs/includes/mike42/escpos-php/example/interface/ethernet.php +++ b/htdocs/includes/mike42/escpos-php/example/interface/ethernet.php @@ -1,22 +1,22 @@ text("Hello World!\n"); - $printer -> cut(); - - /* Close printer */ - $printer -> close(); -} catch(Exception $e) { - echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; + $connector = new NetworkPrintConnector("10.x.x.x", 9100); + + /* Print a "Hello world" receipt" */ + $printer = new Printer($connector); + $printer -> text("Hello World!\n"); + $printer -> cut(); + + /* Close printer */ + $printer -> close(); +} catch (Exception $e) { + echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; } - diff --git a/htdocs/includes/mike42/escpos-php/example/interface/linux-usb.php b/htdocs/includes/mike42/escpos-php/example/interface/linux-usb.php index 9e1d96b91c0..2b390f658b2 100644 --- a/htdocs/includes/mike42/escpos-php/example/interface/linux-usb.php +++ b/htdocs/includes/mike42/escpos-php/example/interface/linux-usb.php @@ -1,6 +1,8 @@ text("Hello World!\n"); - $printer -> cut(); - - /* Close printer */ - $printer -> close(); -} catch(Exception $e) { - echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; + /* Print a "Hello world" receipt" */ + $printer = new Printer($connector); + $printer -> text("Hello World!\n"); + $printer -> cut(); + + /* Close printer */ + $printer -> close(); +} catch (Exception $e) { + echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; } - diff --git a/htdocs/includes/mike42/escpos-php/example/interface/smb.php b/htdocs/includes/mike42/escpos-php/example/interface/smb.php index 40988f553ee..fac54b342d1 100644 --- a/htdocs/includes/mike42/escpos-php/example/interface/smb.php +++ b/htdocs/includes/mike42/escpos-php/example/interface/smb.php @@ -1,51 +1,52 @@ testfile + * echo "Hello World" > testfile * ## If you need authentication, use "net use" to hook up the printer: - * # net use "\\computername\Receipt Printer" /user:Guest - * # net use "\\computername\Receipt Printer" /user:Bob secret - * # net use "\\computername\Receipt Printer" /user:workgroup\Bob secret - * copy testfile "\\computername\Receipt Printer" - * del testfile - * + * # net use "\\computername\Receipt Printer" /user:Guest + * # net use "\\computername\Receipt Printer" /user:Bob secret + * # net use "\\computername\Receipt Printer" /user:workgroup\Bob secret + * copy testfile "\\computername\Receipt Printer" + * del testfile + * * GNU/Linux: - * # No authentication - * echo "Hello World" | smbclient "//computername/Receipt Printer" -c "print -" -N - * # Guest login - * echo "Hello World" | smbclient "//computername/Receipt Printer" -U Guest -c "print -" -N + * # No authentication + * echo "Hello World" | smbclient "//computername/Receipt Printer" -c "print -" -N + * # Guest login + * echo "Hello World" | smbclient "//computername/Receipt Printer" -U Guest -c "print -" -N * # Basic username/password - * echo "Hello World" | smbclient "//computername/Receipt Printer" secret -U "Bob" -c "print -" - * # Including domain name - * echo "Hello World" | smbclient "//computername/Receipt Printer" secret -U "workgroup\\Bob" -c "print -" + * echo "Hello World" | smbclient "//computername/Receipt Printer" secret -U "Bob" -c "print -" + * # Including domain name + * echo "Hello World" | smbclient "//computername/Receipt Printer" secret -U "workgroup\\Bob" -c "print -" */ try { - // Enter the share name for your printer here, as a smb:// url format - $connector = null; - //$connector = new WindowsPrintConnector("smb://computername/Receipt Printer"); - //$connector = new WindowsPrintConnector("smb://Guest@computername/Receipt Printer"); - //$connector = new WindowsPrintConnector("smb://FooUser:secret@computername/workgroup/Receipt Printer"); - //$connector = new WindowsPrintConnector("smb://User:secret@computername/Receipt Printer"); - - /* Print a "Hello world" receipt" */ - $printer = new Escpos($connector); - $printer -> text("Hello World!\n"); - $printer -> cut(); - - /* Close printer */ - $printer -> close(); -} catch(Exception $e) { - echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; + // Enter the share name for your printer here, as a smb:// url format + $connector = new WindowsPrintConnector("smb://computername/Receipt Printer"); + //$connector = new WindowsPrintConnector("smb://Guest@computername/Receipt Printer"); + //$connector = new WindowsPrintConnector("smb://FooUser:secret@computername/workgroup/Receipt Printer"); + //$connector = new WindowsPrintConnector("smb://User:secret@computername/Receipt Printer"); + + /* Print a "Hello world" receipt" */ + $printer = new Printer($connector); + $printer -> text("Hello World!\n"); + $printer -> cut(); + + /* Close printer */ + $printer -> close(); +} catch (Exception $e) { + echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; } diff --git a/htdocs/includes/mike42/escpos-php/example/interface/windows-lpt.php b/htdocs/includes/mike42/escpos-php/example/interface/windows-lpt.php index 76294425cdc..e8fef286bd8 100644 --- a/htdocs/includes/mike42/escpos-php/example/interface/windows-lpt.php +++ b/htdocs/includes/mike42/escpos-php/example/interface/windows-lpt.php @@ -1,30 +1,31 @@ LPT1 + * echo "Hello World" > LPT1 */ try { - $connector = null; - //$connector = new WindowsPrintConnector("LPT1"); - - // A FilePrintConnector will also work, but on non-Windows systems, writes - // to an actual file called 'LPT1' rather than giving a useful error. - // $connector = new FilePrintConnector("LPT1"); + $connector = new WindowsPrintConnector("LPT1"); + + // A FilePrintConnector will also work, but on non-Windows systems, writes + // to an actual file called 'LPT1' rather than giving a useful error. + // $connector = new FilePrintConnector("LPT1"); - /* Print a "Hello world" receipt" */ - $printer = new Escpos($connector); - $printer -> text("Hello World!\n"); - $printer -> cut(); + /* Print a "Hello world" receipt" */ + $printer = new Printer($connector); + $printer -> text("Hello World!\n"); + $printer -> cut(); - /* Close printer */ - $printer -> close(); -} catch(Exception $e) { - echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; + /* Close printer */ + $printer -> close(); +} catch (Exception $e) { + echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; } diff --git a/htdocs/includes/mike42/escpos-php/example/interface/windows-usb.php b/htdocs/includes/mike42/escpos-php/example/interface/windows-usb.php index d4b550e2f93..79776994231 100644 --- a/htdocs/includes/mike42/escpos-php/example/interface/windows-usb.php +++ b/htdocs/includes/mike42/escpos-php/example/interface/windows-usb.php @@ -1,32 +1,34 @@ testfile - * copy testfile "\\%COMPUTERNAME%\Receipt Printer" - * del testfile + * + * echo "Hello World" > testfile + * copy testfile "\\%COMPUTERNAME%\Receipt Printer" + * del testfile */ try { - // Enter the share name for your USB printer here - $connector = null; - //$connector = new WindowsPrintConnector("Receipt Printer"); + // Enter the share name for your USB printer here + $connector = null; + //$connector = new WindowsPrintConnector("Receipt Printer"); - /* Print a "Hello world" receipt" */ - $printer = new Escpos($connector); - $printer -> text("Hello World!\n"); - $printer -> cut(); - - /* Close printer */ - $printer -> close(); -} catch(Exception $e) { - echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; + /* Print a "Hello world" receipt" */ + $printer = new Printer($connector); + $printer -> text("Hello World!\n"); + $printer -> cut(); + + /* Close printer */ + $printer -> close(); +} catch (Exception $e) { + echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; } diff --git a/htdocs/includes/mike42/escpos-php/example/margins-and-spacing.php b/htdocs/includes/mike42/escpos-php/example/margins-and-spacing.php new file mode 100644 index 00000000000..296a7b0bc73 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/margins-and-spacing.php @@ -0,0 +1,48 @@ + setEmphasis(true); +$printer -> text("Line spacing\n"); +$printer -> setEmphasis(false); +foreach(array(16, 32, 64, 128, 255) as $spacing) { + $printer -> setLineSpacing($spacing); + $printer -> text("Spacing $spacing: The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.\n"); +} +$printer -> setLineSpacing(); // Back to default +*/ + +/* Stuff around with left margin */ +$printer -> setEmphasis(true); +$printer -> text("Left margin\n"); +$printer -> setEmphasis(false); +$printer -> text("Default left\n"); +foreach(array(1, 2, 4, 8, 16, 32, 64, 128, 256, 512) as $margin) { + $printer -> setPrintLeftMargin($margin); + $printer -> text("left margin $margin\n"); +} +/* Reset left */ +$printer -> setPrintLeftMargin(0); + +/* Stuff around with page width */ +$printer -> setEmphasis(true); +$printer -> text("Page width\n"); +$printer -> setEmphasis(false); +$printer -> setJustification(Printer::JUSTIFY_RIGHT); +$printer -> text("Default width\n"); +foreach(array(512, 256, 128, 64) as $width) { + $printer -> setPrintWidth($width); + $printer -> text("page width $width\n"); +} + +/* Printer shutdown */ +$printer -> cut(); +$printer -> close(); + diff --git a/htdocs/includes/mike42/escpos-php/example/pdf417-code.php b/htdocs/includes/mike42/escpos-php/example/pdf417-code.php new file mode 100644 index 00000000000..6735ae6ee4d --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/pdf417-code.php @@ -0,0 +1,95 @@ + pdf417Code($testStr); +$printer -> text("Most simple example\n"); +$printer -> feed(); + +// Demo that alignment is the same as text +$printer -> setJustification(Printer::JUSTIFY_CENTER); +$printer -> pdf417Code($testStr, 3, 3, 2); +$printer -> text("Same content, narrow and centred\n"); +$printer -> setJustification(); +$printer -> feed(); + +// Demo of error correction +title($printer, "Error correction\n"); +$ec = array(0.1, 0.5, 1.0, 2.0, 4.0); +foreach ($ec as $level) { + $printer -> pdf417Code($testStr, 3, 3, 0, $level); + $printer -> text("Error correction ratio $level\n"); + $printer -> feed(); +} + +// Change size +title($printer, "Pixel size\n"); +$sizes = array( + 2 => "(minimum)", + 3 => "(default)", + 4 => "", + 8 => "(maximum)"); +foreach ($sizes as $size => $label) { + $printer -> pdf417Code($testStr, $size); + $printer -> text("Module width $size dots $label\n"); + $printer -> feed(); +} + +// Change height +title($printer, "Height multiplier\n"); +$sizes = array( + 2 => "(minimum)", + 3 => "(default)", + 4 => "", + 8 => "(maximum)"); +foreach ($sizes as $size => $label) { + $printer -> pdf417Code($testStr, 3, $size); + $printer -> text("Height multiplier $size $label\n"); + $printer -> feed(); +} + +// Chage data column count +title($printer, "Data column count\n"); +$columnCounts = array( + 0 => "(auto, default)", + 1 => "", + 2 => "", + 3 => "", + 4 => "", + 5 => "", + 30 => "(maximum, doesnt fit!)"); +foreach ($columnCounts as $columnCount => $label) { + $printer -> pdf417Code($testStr, 3, 3, $columnCount); + $printer -> text("Column count $columnCount $label\n"); + $printer -> feed(); +} + +// Change options +title($printer, "Options\n"); +$models = array( + Printer::PDF417_STANDARD => "Standard", + Printer::PDF417_TRUNCATED => "Truncated"); +foreach ($models as $model => $name) { + $printer -> pdf417Code($testStr, 3, 3, 0, 0.10, $model); + $printer -> text("$name\n"); + $printer -> feed(); +} + +// Cut & close +$printer -> cut(); +$printer -> close(); + +function title(Printer $printer, $str) +{ + $printer -> selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH); + $printer -> text($str); + $printer -> selectPrintMode(); +} diff --git a/htdocs/includes/mike42/escpos-php/example/print-from-html.php b/htdocs/includes/mike42/escpos-php/example/print-from-html.php index f0751d7a4ae..640132e11b0 100644 --- a/htdocs/includes/mike42/escpos-php/example/print-from-html.php +++ b/htdocs/includes/mike42/escpos-php/example/print-from-html.php @@ -1,11 +1,20 @@ 225 below) and printing w/ Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT */ try { - /* Set up command */ - $source = "http://en.m.wikipedia.org/wiki/ESC/P"; - $width = 550; - $dest = tempnam(sys_get_temp_dir(), 'escpos') . ".png"; - $cmd = sprintf("wkhtmltoimage -n -q --width %s %s %s", - escapeshellarg($width), - escapeshellarg($source), - escapeshellarg($dest)); - - /* Run wkhtmltoimage */ - ob_start(); - system($cmd); // Can also use popen() for better control of process - $outp = ob_get_contents(); - ob_end_clean(); - if(!file_exists($dest)) { - throw new Exception("Command $cmd failed: $outp"); - } + /* Set up command */ + $source = __DIR__ . "/resources/document.html"; + $width = 550; + $dest = tempnam(sys_get_temp_dir(), 'escpos') . ".png"; + $command = sprintf( + "xvfb-run wkhtmltoimage -n -q --width %s %s %s", + escapeshellarg($width), + escapeshellarg($source), + escapeshellarg($dest) + ); - /* Load up the image */ - try { - $img = new EscposImage($dest); - } catch(Exception $e) { - unlink($dest); - throw $e; - } - unlink($dest); + /* Test for dependencies */ + foreach (array("xvfb-run", "wkhtmltoimage") as $cmd) { + $testCmd = sprintf("which %s", escapeshellarg($cmd)); + exec($testCmd, $testOut, $testStatus); + if ($testStatus != 0) { + throw new Exception("You require $cmd but it could not be found"); + } + } - /* Print it */ - $printer = new Escpos(); // Add connector for your printer here. - $printer -> bitImage($img); // bitImage() seems to allow larger images than graphics() on the TM-T20. - $printer -> cut(); - $printer -> close(); -} catch(Exception $e) { - echo $e -> getMessage(); + + /* Run wkhtmltoimage */ + $descriptors = array( + 1 => array("pipe", "w"), + 2 => array("pipe", "w"), + ); + $process = proc_open($command, $descriptors, $fd); + if (is_resource($process)) { + /* Read stdout */ + $outputStr = stream_get_contents($fd[1]); + fclose($fd[1]); + /* Read stderr */ + $errorStr = stream_get_contents($fd[2]); + fclose($fd[2]); + /* Finish up */ + $retval = proc_close($process); + if ($retval != 0) { + throw new Exception("Command $cmd failed: $outputStr $errorStr"); + } + } else { + throw new Exception("Command '$cmd' failed to start."); + } + + /* Load up the image */ + try { + $img = EscposImage::load($dest); + } catch (Exception $e) { + unlink($dest); + throw $e; + } + unlink($dest); + + /* Print it */ + $printer -> bitImage($img); // bitImage() seems to allow larger images than graphics() on the TM-T20. bitImageColumnFormat() is another option. + $printer -> cut(); +} catch (Exception $e) { + echo $e -> getMessage(); +} finally { + $printer -> close(); } - diff --git a/htdocs/includes/mike42/escpos-php/example/print-from-pdf.php b/htdocs/includes/mike42/escpos-php/example/print-from-pdf.php index ba6a4c67a96..23469e8a00f 100644 --- a/htdocs/includes/mike42/escpos-php/example/print-from-pdf.php +++ b/htdocs/includes/mike42/escpos-php/example/print-from-pdf.php @@ -1,5 +1,9 @@ graphics($page); - } - $printer -> cut(); - $printer -> close(); -} catch(Exception $e) { - /* + $pages = ImagickEscposImage::loadPdf($pdf); + foreach ($pages as $page) { + $printer -> graphics($page); + } + $printer -> cut(); +} catch (Exception $e) { + /* * loadPdf() throws exceptions if files or not found, or you don't have the * imagick extension to read PDF's */ - echo $e -> getMessage() . "\n"; - exit(0); + echo $e -> getMessage() . "\n"; +} finally { + $printer -> close(); } @@ -33,11 +38,12 @@ try { * * Reduce the page width further if necessary: if it extends past the printing area, your prints will be very slow. */ -$printer = new Escpos(); +$connector = new FilePrintConnector("php://stdout"); +$printer = new Printer($connector); $pdf = 'resources/document.pdf'; -$pages = EscposImage::loadPdf($pdf, 260); -foreach($pages as $page) { - $printer -> graphics($page, Escpos::IMG_DOUBLE_HEIGHT | Escpos::IMG_DOUBLE_WIDTH); +$pages = ImagickEscposImage::loadPdf($pdf, 260); +foreach ($pages as $page) { + $printer -> graphics($page, Printer::IMG_DOUBLE_HEIGHT | Printer::IMG_DOUBLE_WIDTH); } $printer -> cut(); $printer -> close(); @@ -51,21 +57,22 @@ $printer -> close(); * * [1]After printing, the pixels are loaded and formatted for the print command you used, so even a raspberry pi can print complex PDF's quickly. */ -$printer = new Escpos(); +$connector = new FilePrintConnector("php://stdout"); +$printer = new Printer($connector); $pdf = 'resources/document.pdf'; $ser = 'resources/document.z'; -if(!file_exists($ser)) { - $pages = EscposImage::loadPdf($pdf); +if (!file_exists($ser)) { + $pages = ImagickEscposImage::loadPdf($pdf); } else { - $pages = unserialize(gzuncompress(file_get_contents($ser))); + $pages = unserialize(gzuncompress(file_get_contents($ser))); } -foreach($pages as $page) { - $printer -> graphics($page); +foreach ($pages as $page) { + $printer -> graphics($page); } $printer -> cut(); $printer -> close(); -if(!file_exists($ser)) { - file_put_contents($ser, gzcompress(serialize($pages))); +if (!file_exists($ser)) { + file_put_contents($ser, gzcompress(serialize($pages))); } diff --git a/htdocs/includes/mike42/escpos-php/example/qr-code.php b/htdocs/includes/mike42/escpos-php/example/qr-code.php index dbf21aaedf4..f57c2b8270d 100644 --- a/htdocs/includes/mike42/escpos-php/example/qr-code.php +++ b/htdocs/includes/mike42/escpos-php/example/qr-code.php @@ -1,7 +1,11 @@ text("Most simple example\n"); $printer -> feed(); // Demo that alignment is the same as text -$printer -> setJustification(Escpos::JUSTIFY_CENTER); +$printer -> setJustification(Printer::JUSTIFY_CENTER); $printer -> qrCode($testStr); $printer -> text("Same example, centred\n"); $printer -> setJustification(); $printer -> feed(); - + // Demo of numeric data being packed more densly title($printer, "Data encoding\n"); $test = array( - "Numeric" => "0123456789012345678901234567890123456789", - "Alphanumeric" => "abcdefghijklmnopqrstuvwxyzabcdefghijklmn", - "Binary" => str_repeat("\0", 40)); -foreach($test as $type => $data) { - $printer -> qrCode($data); - $printer -> text("$type\n"); - $printer -> feed(); + "Numeric" => "0123456789012345678901234567890123456789", + "Alphanumeric" => "abcdefghijklmnopqrstuvwxyzabcdefghijklmn", + "Binary" => str_repeat("\0", 40)); +foreach ($test as $type => $data) { + $printer -> qrCode($data); + $printer -> text("$type\n"); + $printer -> feed(); } // Demo of error correction title($printer, "Error correction\n"); $ec = array( - Escpos::QR_ECLEVEL_L => "L", - Escpos::QR_ECLEVEL_M => "M", - Escpos::QR_ECLEVEL_Q => "Q", - Escpos::QR_ECLEVEL_H => "H"); -foreach($ec as $level => $name) { - $printer -> qrCode($testStr, $level); - $printer -> text("Error correction $name\n"); - $printer -> feed(); + Printer::QR_ECLEVEL_L => "L", + Printer::QR_ECLEVEL_M => "M", + Printer::QR_ECLEVEL_Q => "Q", + Printer::QR_ECLEVEL_H => "H"); +foreach ($ec as $level => $name) { + $printer -> qrCode($testStr, $level); + $printer -> text("Error correction $name\n"); + $printer -> feed(); } // Change size title($printer, "Pixel size\n"); $sizes = array( - 1 => "(minimum)", - 2 => "", - 3 => "(default)", - 4 => "", - 5 => "", - 10 => "", - 16 => "(maximum)"); -foreach($sizes as $size => $label) { - $printer -> qrCode($testStr, Escpos::QR_ECLEVEL_L, $size); - $printer -> text("Pixel size $size $label\n"); - $printer -> feed(); + 1 => "(minimum)", + 2 => "", + 3 => "(default)", + 4 => "", + 5 => "", + 10 => "", + 16 => "(maximum)"); +foreach ($sizes as $size => $label) { + $printer -> qrCode($testStr, Printer::QR_ECLEVEL_L, $size); + $printer -> text("Pixel size $size $label\n"); + $printer -> feed(); } // Change model title($printer, "QR model\n"); $models = array( - Escpos::QR_MODEL_1 => "QR Model 1", - Escpos::QR_MODEL_2 => "QR Model 2 (default)", - Escpos::QR_MICRO => "Micro QR code\n(not supported on all printers)"); -foreach($models as $model => $name) { - $printer -> qrCode($testStr, Escpos::QR_ECLEVEL_L, 3, $model); - $printer -> text("$name\n"); - $printer -> feed(); + Printer::QR_MODEL_1 => "QR Model 1", + Printer::QR_MODEL_2 => "QR Model 2 (default)", + Printer::QR_MICRO => "Micro QR code\n(not supported on all printers)"); +foreach ($models as $model => $name) { + $printer -> qrCode($testStr, Printer::QR_ECLEVEL_L, 3, $model); + $printer -> text("$name\n"); + $printer -> feed(); } // Cut & close $printer -> cut(); $printer -> close(); -function title(Escpos $printer, $str) { - $printer -> selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_DOUBLE_WIDTH); - $printer -> text($str); - $printer -> selectPrintMode(); +function title(Printer $printer, $str) +{ + $printer -> selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH); + $printer -> text($str); + $printer -> selectPrintMode(); } diff --git a/htdocs/includes/mike42/escpos-php/example/rawbt-receipt.html b/htdocs/includes/mike42/escpos-php/example/rawbt-receipt.html new file mode 100644 index 00000000000..c3d307a94d1 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/rawbt-receipt.html @@ -0,0 +1,76 @@ + + + + + RawBT Integration Demo + + + + + + + +black & white picture +

RawBT Integration Demo

+
+
+    window.location.href = ajax_backend_data;
+
+
+
+ + +

Visit RawBT site

+ + diff --git a/htdocs/includes/mike42/escpos-php/example/rawbt-receipt.php b/htdocs/includes/mike42/escpos-php/example/rawbt-receipt.php new file mode 100644 index 00000000000..45a4e8fcde2 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/rawbt-receipt.php @@ -0,0 +1,145 @@ +getSupportsGraphics()) { + $printer->graphics($logo); + } + if ($profile->getSupportsBitImageRaster() && !$profile->getSupportsGraphics()) { + $printer->bitImage($logo); + } + + /* Name of shop */ + $printer->setJustification(Printer::JUSTIFY_CENTER); + $printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH); + $printer->text("ExampleMart Ltd.\n"); + $printer->selectPrintMode(); + $printer->text("Shop No. 42.\n"); + $printer->feed(); + + + /* Title of receipt */ + $printer->setEmphasis(true); + $printer->text("SALES INVOICE\n"); + $printer->setEmphasis(false); + + /* Items */ + $printer->setJustification(Printer::JUSTIFY_LEFT); + $printer->setEmphasis(true); + $printer->text(new item('', '$')); + $printer->setEmphasis(false); + foreach ($items as $item) { + $printer->text($item->getAsString(32)); // for 58mm Font A + } + $printer->setEmphasis(true); + $printer->text($subtotal->getAsString(32)); + $printer->setEmphasis(false); + $printer->feed(); + + /* Tax and total */ + $printer->text($tax->getAsString(32)); + $printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH); + $printer->text($total->getAsString(32)); + $printer->selectPrintMode(); + + /* Footer */ + $printer->feed(2); + $printer->setJustification(Printer::JUSTIFY_CENTER); + $printer->text("Thank you for shopping\n"); + $printer->text("at ExampleMart\n"); + $printer->text("For trading hours,\n"); + $printer->text("please visit example.com\n"); + $printer->feed(2); + $printer->text($date . "\n"); + + /* Barcode Default look */ + + $printer->barcode("ABC", Printer::BARCODE_CODE39); + $printer->feed(); + $printer->feed(); + + +// Demo that alignment QRcode is the same as text + $printer2 = new Printer($connector); // dirty printer profile hack !! + $printer2->setJustification(Printer::JUSTIFY_CENTER); + $printer2->qrCode("https://rawbt.ru/mike42", Printer::QR_ECLEVEL_M, 8); + $printer2->text("rawbt.ru/mike42\n"); + $printer2->setJustification(); + $printer2->feed(); + + + /* Cut the receipt and open the cash drawer */ + $printer->cut(); + $printer->pulse(); + +} catch (Exception $e) { + echo $e->getMessage(); +} finally { + $printer->close(); +} + +/* A wrapper to do organise item names & prices into columns */ + +class item +{ + private $name; + private $price; + private $dollarSign; + + public function __construct($name = '', $price = '', $dollarSign = false) + { + $this->name = $name; + $this->price = $price; + $this->dollarSign = $dollarSign; + } + + public function getAsString($width = 48) + { + $rightCols = 10; + $leftCols = $width - $rightCols; + if ($this->dollarSign) { + $leftCols = $leftCols / 2 - $rightCols / 2; + } + $left = str_pad($this->name, $leftCols); + + $sign = ($this->dollarSign ? '$ ' : ''); + $right = str_pad($sign . $this->price, $rightCols, ' ', STR_PAD_LEFT); + return "$left$right\n"; + } + + public function __toString() + { + return $this->getAsString(); + } + +} diff --git a/htdocs/includes/mike42/escpos-php/example/receipt-with-logo.php b/htdocs/includes/mike42/escpos-php/example/receipt-with-logo.php index 8322c09c750..b094e9f2b2a 100644 --- a/htdocs/includes/mike42/escpos-php/example/receipt-with-logo.php +++ b/htdocs/includes/mike42/escpos-php/example/receipt-with-logo.php @@ -1,12 +1,18 @@ setJustification(Escpos::JUSTIFY_CENTER); +$printer -> setJustification(Printer::JUSTIFY_CENTER); $printer -> graphics($logo); /* Name of shop */ -$printer -> selectPrintMode(Escpos::MODE_DOUBLE_WIDTH); +$printer -> selectPrintMode(Printer::MODE_DOUBLE_WIDTH); $printer -> text("ExampleMart Ltd.\n"); $printer -> selectPrintMode(); $printer -> text("Shop No. 42.\n"); @@ -36,12 +42,12 @@ $printer -> text("SALES INVOICE\n"); $printer -> setEmphasis(false); /* Items */ -$printer -> setJustification(Escpos::JUSTIFY_LEFT); +$printer -> setJustification(Printer::JUSTIFY_LEFT); $printer -> setEmphasis(true); $printer -> text(new item('', '$')); $printer -> setEmphasis(false); -foreach($items as $item) { - $printer -> text($item); +foreach ($items as $item) { + $printer -> text($item); } $printer -> setEmphasis(true); $printer -> text($subtotal); @@ -50,13 +56,13 @@ $printer -> feed(); /* Tax and total */ $printer -> text($tax); -$printer -> selectPrintMode(Escpos::MODE_DOUBLE_WIDTH); +$printer -> selectPrintMode(Printer::MODE_DOUBLE_WIDTH); $printer -> text($total); $printer -> selectPrintMode(); /* Footer */ $printer -> feed(2); -$printer -> setJustification(Escpos::JUSTIFY_CENTER); +$printer -> setJustification(Printer::JUSTIFY_CENTER); $printer -> text("Thank you for shopping at ExampleMart\n"); $printer -> text("For trading hours, please visit example.com\n"); $printer -> feed(2); @@ -69,28 +75,30 @@ $printer -> pulse(); $printer -> close(); /* A wrapper to do organise item names & prices into columns */ -class item { - private $name; - private $price; - private $dollarSign; +class item +{ + private $name; + private $price; + private $dollarSign; - public function __construct($name = '', $price = '', $dollarSign = false) { - $this -> name = $name; - $this -> price = $price; - $this -> dollarSign = $dollarSign; - } - - public function __toString() { - $rightCols = 10; - $leftCols = 38; - if($this -> dollarSign) { - $leftCols = $leftCols / 2 - $rightCols / 2; - } - $left = str_pad($this -> name, $leftCols) ; - - $sign = ($this -> dollarSign ? '$ ' : ''); - $right = str_pad($sign . $this -> price, $rightCols, ' ', STR_PAD_LEFT); - return "$left$right\n"; - } + public function __construct($name = '', $price = '', $dollarSign = false) + { + $this -> name = $name; + $this -> price = $price; + $this -> dollarSign = $dollarSign; + } + + public function __toString() + { + $rightCols = 10; + $leftCols = 38; + if ($this -> dollarSign) { + $leftCols = $leftCols / 2 - $rightCols / 2; + } + $left = str_pad($this -> name, $leftCols) ; + + $sign = ($this -> dollarSign ? '$ ' : ''); + $right = str_pad($sign . $this -> price, $rightCols, ' ', STR_PAD_LEFT); + return "$left$right\n"; + } } -?> diff --git a/htdocs/includes/mike42/escpos-php/example/resources/character-encoding-test-strings.inc b/htdocs/includes/mike42/escpos-php/example/resources/character-encoding-test-strings.inc index caca76c4479..000b3bd59a2 100644 --- a/htdocs/includes/mike42/escpos-php/example/resources/character-encoding-test-strings.inc +++ b/htdocs/includes/mike42/escpos-php/example/resources/character-encoding-test-strings.inc @@ -3,21 +3,22 @@ * on the default profile, so you can use them to test modified profiles (using the wrong * profile for a printer produces mojibake) */ $inputsOk = array( - "Danish" => "Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon.\n", - "German" => "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.\n", - "Greek" => "Ξεσκεπάζω την ψυχοφθόρα βδελυγμία\n", - "English" => "The quick brown fox jumps over the lazy dog.\n", - "Spanish" => "El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.\n", - "French" => "Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälström où brûlent les novæ.\n", - "Irish Gaelic" => "D'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh.\n", - "Hungarian" => "Árvíztűrő tükörfúrógép.\n", - "Icelandic" => "Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa.\n", - "Latvian" => "Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus.\n", - "Polish" => "Pchnąć w tę łódź jeża lub ośm skrzyń fig.\n", - "Russian" => "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!\n", - "Turkish" => "Pijamalı hasta, yağız şoföre çabucak güvendi.\n", - "Japanese (Katakana half-width)" => implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウイノオクヤマ ケフコエテ アサキユメミシ エヒモセスン")) . "\n" - ); + "Danish" => "Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon.\n", + "German" => "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.\n", + "Greek" => "Ξεσκεπάζω την ψυχοφθόρα βδελυγμία\n", + "English" => "The quick brown fox jumps over the lazy dog.\n", + "Spanish" => "El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.\n", + "French" => "Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälström où brûlent les novæ.\n", + "Irish Gaelic" => "D'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh.\n", + "Hungarian" => "Árvíztűrő tükörfúrógép.\n", + "Icelandic" => "Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa.\n", + "Latvian" => "Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus.\n", + "Polish" => "Pchnąć w tę łódź jeża lub ośm skrzyń fig.\n", + "Russian" => "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!\n", + "Turkish" => "Pijamalı hasta, yağız şoföre çabucak güvendi.\n", + "Japanese (Katakana half-width)" => implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウイノオクヤマ ケフコエテ アサキユメミシ エヒモセスン")) . "\n", + "Vietnamese" => "Tiếng Việt, còn gọi tiếng Việt Nam hay Việt ngữ, là ngôn ngữ của người Việt (người Kinh) và là ngôn ngữ chính thức tại Việt Nam.\n" + ); /* * These strings are not expected to print correctly, if at all, even on an Epson printer. This is due to a mix of @@ -26,10 +27,9 @@ $inputsOk = array( * They are included here as a collection of things not yet implemented. */ $inputsNotOk = array( - "Thai (No character encoder available)" => "นายสังฆภัณฑ์ เฮงพิทักษ์ฝั่ง ผู้เฒ่าซึ่งมีอาชีพเป็นฅนขายฃวด ถูกตำรวจปฏิบัติการจับฟ้องศาล ฐานลักนาฬิกาคุณหญิงฉัตรชฎา ฌานสมาธิ\n", - "Japanese (Hiragana)" => implode("\n", array("いろはにほへとちりぬるを", " わかよたれそつねならむ", "うゐのおくやまけふこえて", "あさきゆめみしゑひもせす")) . "\n", - "Japanese (Katakana full-width)" => implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン")) . "\n", - "Arabic (RTL not supported, encoding issues)" => "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ" . "\n", - "Hebrew (RTL not supported, line break issues)" => "דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה" . "\n" - ); - + "Thai (No character encoder available)" => "นายสังฆภัณฑ์ เฮงพิทักษ์ฝั่ง ผู้เฒ่าซึ่งมีอาชีพเป็นฅนขายฃวด ถูกตำรวจปฏิบัติการจับฟ้องศาล ฐานลักนาฬิกาคุณหญิงฉัตรชฎา ฌานสมาธิ\n", + "Japanese (Hiragana)" => implode("\n", array("いろはにほへとちりぬるを", " わかよたれそつねならむ", "うゐのおくやまけふこえて", "あさきゆめみしゑひもせす")) . "\n", + "Japanese (Katakana full-width)" => implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン")) . "\n", + "Arabic (RTL not supported, encoding issues)" => "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ" . "\n", + "Hebrew (RTL not supported, line break issues)" => "דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה" . "\n" + ); diff --git a/htdocs/includes/mike42/escpos-php/example/resources/document.html b/htdocs/includes/mike42/escpos-php/example/resources/document.html new file mode 100644 index 00000000000..bb413aa1d3d --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/resources/document.html @@ -0,0 +1,40 @@ + + + + + + + + + + + + + +

+ + This is a simple document. For receipts involving complex formatting, + non-monospace fonts, advanced character encodings, or vector graphics, + you can always create and render HTML instead. +

+

+ The printing will be a lot slower, but you have full access to things like unicode and SVG. +

+

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod tempor incididunt ut labore et dolore magna aliqua.

+

Ut enim ad minim veniam, quis nostrud exercitation ullamco + laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor + in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla + pariatur.

+

Excepteur sint occaecat cupidatat non proident, sunt in culpa + qui officia deserunt mollit anim id est laborum.

+ + diff --git a/htdocs/includes/mike42/escpos-php/example/resources/document.z b/htdocs/includes/mike42/escpos-php/example/resources/document.z index cb047387558..c19e213227a 100644 Binary files a/htdocs/includes/mike42/escpos-php/example/resources/document.z and b/htdocs/includes/mike42/escpos-php/example/resources/document.z differ diff --git a/htdocs/includes/mike42/escpos-php/example/resources/rawbtlogo.png b/htdocs/includes/mike42/escpos-php/example/resources/rawbtlogo.png new file mode 100644 index 00000000000..999abab33e2 Binary files /dev/null and b/htdocs/includes/mike42/escpos-php/example/resources/rawbtlogo.png differ diff --git a/htdocs/includes/mike42/escpos-php/example/resources/tulips.png b/htdocs/includes/mike42/escpos-php/example/resources/tulips.png new file mode 100644 index 00000000000..a0e681cf0ff Binary files /dev/null and b/htdocs/includes/mike42/escpos-php/example/resources/tulips.png differ diff --git a/htdocs/includes/mike42/escpos-php/example/specific/123-code128-barcode.php b/htdocs/includes/mike42/escpos-php/example/specific/123-code128-barcode.php new file mode 100644 index 00000000000..b87e44981e0 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/specific/123-code128-barcode.php @@ -0,0 +1,21 @@ + setJustification(Printer::JUSTIFY_CENTER); +$printer -> setBarcodeHeight(48); +$printer->setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW); +foreach(array($a, $b, $c) as $item) { + $printer -> barcode($item, Printer::BARCODE_CODE128); + $printer -> feed(1); +} +$printer -> cut(); +$printer -> close(); + diff --git a/htdocs/includes/mike42/escpos-php/example/specific/141-custom-command.php b/htdocs/includes/mike42/escpos-php/example/specific/141-custom-command.php new file mode 100644 index 00000000000..6e3bed70d0b --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/specific/141-custom-command.php @@ -0,0 +1,55 @@ +getPrintConnector()->write($barcodeCommand); +$printer->cut(); +$printer->close(); + +/** + * Generate two characters for a number: In lower and higher parts, or more parts as needed. + * + * @param int $input + * Input number + * @param int $length + * The number of bytes to output (1 - 4). + */ +function intLowHigh($input, $length) +{ + $outp = ""; + for ($i = 0; $i < $length; $i ++) { + $outp .= chr($input % 256); + $input = (int) ($input / 256); + } + return $outp; +} +?> \ No newline at end of file diff --git a/htdocs/includes/mike42/escpos-php/example/specific/148-data-uri.php b/htdocs/includes/mike42/escpos-php/example/specific/148-data-uri.php new file mode 100644 index 00000000000..74759146712 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/specific/148-data-uri.php @@ -0,0 +1,35 @@ + setResourceLimit(6, 1); // Prevent libgomp1 segfaults, grumble grumble. +$imagick -> readImageBlob($imageBlob, "input.png"); + +// Load Imagick straight into an EscposImage object +$im = new ImagickEscposImage(); +$im -> readImageFromImagick($imagick); + +// Do a test print to make sure that this EscposImage object has the right data +// (should see a tiny bullet point) +$connector = new FilePrintConnector("php://output"); +$printer = new Printer($connector); +$printer -> bitImage($im); +$printer -> cut(); +$printer -> close(); diff --git a/htdocs/includes/mike42/escpos-php/example/specific/235-get-data.php b/htdocs/includes/mike42/escpos-php/example/specific/235-get-data.php new file mode 100644 index 00000000000..c3607c868b3 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/specific/235-get-data.php @@ -0,0 +1,28 @@ + text("Hello world!\n"); +$printer -> cut(); + +// Get the data out as a string +$data = $connector -> getData(); + +// Return it, check the manual for specifics. +header('Content-type: application/octet-stream'); +header('Content-Length: '.strlen($data)); +echo $data; + +// Close the printer when done. +$printer -> close(); diff --git a/htdocs/includes/mike42/escpos-php/example/specific/29-latvian-star-tup592.php b/htdocs/includes/mike42/escpos-php/example/specific/29-latvian-star-tup592.php index 72dc7c8f2ed..73613100abb 100644 --- a/htdocs/includes/mike42/escpos-php/example/specific/29-latvian-star-tup592.php +++ b/htdocs/includes/mike42/escpos-php/example/specific/29-latvian-star-tup592.php @@ -1,11 +1,16 @@ - text("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus\n"); $printer -> cut(); $printer -> close(); @@ -13,9 +18,8 @@ $printer -> close(); /* Option 2: Image-based output (formatting not available using this output) */ $buffer = new ImagePrintBuffer(); $connector = new FilePrintConnector("php://stdout"); -$printer = new Escpos($connector, $profile); +$printer = new Printer($connector, $profile); $printer -> setPrintBuffer($buffer); $printer -> text("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus\n"); $printer -> cut(); $printer -> close(); -?> \ No newline at end of file diff --git a/htdocs/includes/mike42/escpos-php/example/specific/32-german-tm-t20-ii-custom-command.php b/htdocs/includes/mike42/escpos-php/example/specific/32-german-tm-t20-ii-custom-command.php index 49eca235091..29b6b3fc638 100644 --- a/htdocs/includes/mike42/escpos-php/example/specific/32-german-tm-t20-ii-custom-command.php +++ b/htdocs/includes/mike42/escpos-php/example/specific/32-german-tm-t20-ii-custom-command.php @@ -1,5 +1,9 @@ getPrintConnector() -> write($cmd); $printer -> text("Beispieltext in Deutsch\n"); $printer -> cut(); $printer -> close(); - /* * Hex-dump of output confirms that ESC V 1 being sent: * * 0000000 033 @ 033 V 001 B e i s p i e l t e x * 0000010 t i n D e u t s c h \n 035 V A * 0000020 003 - */ \ No newline at end of file + */ diff --git a/htdocs/includes/mike42/escpos-php/example/specific/33-spanish-seypos-prp-300.php b/htdocs/includes/mike42/escpos-php/example/specific/33-spanish-seypos-prp-300.php index 7314ad21bf0..90bdc63fb5c 100644 --- a/htdocs/includes/mike42/escpos-php/example/specific/33-spanish-seypos-prp-300.php +++ b/htdocs/includes/mike42/escpos-php/example/specific/33-spanish-seypos-prp-300.php @@ -6,11 +6,14 @@ * * Use the hardware switch to activate "Two-byte Character Code" */ -require_once(dirname(__FILE__) . "/../../Escpos.php"); +require __DIR__ . '/../../autoload.php'; +use Mike42\Escpos\CapabilityProfile; +use Mike42\Escpos\Printer; +use Mike42\Escpos\PrintConnectors\FilePrintConnector; + $connector = new FilePrintConnector("php://output"); -$profile = SimpleCapabilityProfile::getInstance(); -$printer = new Escpos($connector); +$profile = CapabilityProfile::load("simple"); // Works for Epson printers +$printer = new Printer($connector); $printer -> text("El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.\n"); $printer -> cut(); $printer -> close(); - diff --git a/htdocs/includes/mike42/escpos-php/example/specific/37-chinese.php b/htdocs/includes/mike42/escpos-php/example/specific/37-chinese.php new file mode 100644 index 00000000000..d14790f47d5 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/specific/37-chinese.php @@ -0,0 +1,24 @@ + textChinese("艾德蒙 AOC E2450SWH 23.6吋 LED液晶寬螢幕特價$ 19900\n\n"); + +// Note that on the printer tested (ZJ5890), the font only contained simplified characters. +$printer -> textChinese("示例文本打印机!\n\n"); +$printer -> close(); diff --git a/htdocs/includes/mike42/escpos-php/example/specific/39-currency-symbols.php b/htdocs/includes/mike42/escpos-php/example/specific/39-currency-symbols.php index b3d4b29edd1..b960ee681c3 100644 --- a/htdocs/includes/mike42/escpos-php/example/specific/39-currency-symbols.php +++ b/htdocs/includes/mike42/escpos-php/example/specific/39-currency-symbols.php @@ -1,11 +1,16 @@ - text("€ 9,95\n"); $printer -> text("£ 9.95\n"); $printer -> text("$ 9.95\n"); @@ -16,7 +21,7 @@ $printer -> close(); /* Option 2: Image-based output (formatting not available using this output). */ $buffer = new ImagePrintBuffer(); $connector = new FilePrintConnector("php://stdout"); -$printer = new Escpos($connector, $profile); +$printer = new Printer($connector, $profile); $printer -> setPrintBuffer($buffer); $printer -> text("€ 9,95\n"); $printer -> text("£ 9.95\n"); @@ -34,32 +39,35 @@ $printer -> close(); are not available in CP437. CP858 has good printer support, but is not included in all iconv builds. */ -class CustomCapabilityProfile extends SimpleCapabilityProfile { - function getCustomCodePages() { - /* +class CustomCapabilityProfile extends CapabilityProfile +{ + function getCustomCodePages() + { + /* * Example to print in a specific, user-defined character set * on a printer which has been configured to use i */ - return array( - 'CP858' => "ÇüéâäàåçêëèïîìÄÅ" . - "ÉæÆôöòûùÿÖÜø£Ø×ƒ" . - "áíóúñѪº¿®¬½¼¡«»" . - "░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐" . - "└┴┬├─┼ãÃ╚╔╩╦╠═╬¤" . - "ðÐÊËÈ€ÍÎÏ┘┌█▄¦Ì▀" . - "ÓßÔÒõÕµþÞÚÛÙýݯ´" . - " ±‗¾¶§÷¸°¨·¹³²■ "); - } - - function getSupportedCodePages() { - return array( - 0 => 'custom:CP858'); - } + return array( + 'CP858' => "ÇüéâäàåçêëèïîìÄÅ" . + "ÉæÆôöòûùÿÖÜø£Ø×ƒ" . + "áíóúñѪº¿®¬½¼¡«»" . + "░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐" . + "└┴┬├─┼ãÃ╚╔╩╦╠═╬¤" . + "ðÐÊËÈ€ÍÎÏ┘┌█▄¦Ì▀" . + "ÓßÔÒõÕµþÞÚÛÙýݯ´" . + " ±‗¾¶§÷¸°¨·¹³²■ "); + } + + function getSupportedCodePages() + { + return array( + 0 => 'custom:CP858'); + } } $connector = new FilePrintConnector("php://stdout"); $profile = CustomCapabilityProfile::getInstance(); -$printer = new Escpos($connector, $profile); +$printer = new Printer($connector, $profile); $printer -> text("€ 9,95\n"); $printer -> text("£ 9.95\n"); $printer -> text("$ 9.95\n"); diff --git a/htdocs/includes/mike42/escpos-php/example/specific/44-pound-symbol-star-tsp650.php b/htdocs/includes/mike42/escpos-php/example/specific/44-pound-symbol-star-tsp650.php index 4ef1a9575c2..3e7e6a2e48b 100644 --- a/htdocs/includes/mike42/escpos-php/example/specific/44-pound-symbol-star-tsp650.php +++ b/htdocs/includes/mike42/escpos-php/example/specific/44-pound-symbol-star-tsp650.php @@ -7,12 +7,16 @@ */ // Adjust these to your environment -require_once(dirname(__FILE__) . "/../../Escpos.php"); +require __DIR__ . '/../../autoload.php'; +use Mike42\Escpos\CapabilityProfile; +use Mike42\Escpos\Printer; +use Mike42\Escpos\PrintConnectors\FilePrintConnector; + $connector = new FilePrintConnector("php://stdout"); // Start printer -$profile = SimpleCapabilityProfile::getInstance(); -$printer = new Escpos($connector, $profile); +$profile = CapabilityProfile::load("simple"); +$printer = new Printer($connector, $profile); // A) Raw pound symbol // This is the most likely thing to work, and bypasses all the fancy stuff. diff --git a/htdocs/includes/mike42/escpos-php/example/specific/50-P-822D-greek.php b/htdocs/includes/mike42/escpos-php/example/specific/50-P-822D-greek.php index 2d88cf1a2a8..1651f44a7fa 100644 --- a/htdocs/includes/mike42/escpos-php/example/specific/50-P-822D-greek.php +++ b/htdocs/includes/mike42/escpos-php/example/specific/50-P-822D-greek.php @@ -1,11 +1,14 @@ setJustification(Escpos::JUSTIFY_CENTER); - $printer -> graphics($img); - $printer -> cut(); - } finally { - // Always close the connection - $printer -> close(); - } + // Run the actual print + $printer = new Printer($connector, $profile); + try { + $printer -> setJustification(Printer::JUSTIFY_CENTER); + $printer -> graphics($img); + $printer -> cut(); + } finally { + // Always close the connection + $printer -> close(); + } } catch (Exception $e) { - // Print out any errors: Eg. printer connection, image loading & external image manipulation. - echo $e -> getMessage() . "\n"; - echo $e -> getTraceAsString(); + // Print out any errors: Eg. printer connection, image loading & external image manipulation. + echo $e -> getMessage() . "\n"; + echo $e -> getTraceAsString(); } finally { - unlink ( $imgCombined_path ); - unlink ( $tmpf_path ); + unlink($imgCombined_path); + unlink($tmpf_path); } diff --git a/htdocs/includes/mike42/escpos-php/example/specific/6-arabic-epos-tep-220m.php b/htdocs/includes/mike42/escpos-php/example/specific/6-arabic-epos-tep-220m.php index c2b0fb5aa57..5994b7a81c7 100644 --- a/htdocs/includes/mike42/escpos-php/example/specific/6-arabic-epos-tep-220m.php +++ b/htdocs/includes/mike42/escpos-php/example/specific/6-arabic-epos-tep-220m.php @@ -10,14 +10,30 @@ * Requirements are: * - imagick extension (For the ImagePrintBuffer, which does not * support gd at the time of writing) - * - Ar-PHP library, available from sourceforge, for the first - * part of this example. Drop it in the folder listed below: + * - ArPHP 4.0 (release date: Jan 8, 2016), available from SourceForge, for + * handling the layout for this example. */ -require_once(dirname(__FILE__) . "/../../Escpos.php"); -require_once(dirname(__FILE__) . "/../../vendor/I18N/Arabic.php"); +require __DIR__ . '/../../autoload.php'; +use Mike42\Escpos\CapabilityProfile; +use Mike42\Escpos\Printer; +use Mike42\Escpos\PrintConnectors\FilePrintConnector; +use Mike42\Escpos\PrintBuffers\ImagePrintBuffer; /* - * First, convert the text into LTR byte order with joined letters, + * Drop Ar-php into the folder listed below: + */ +require_once(dirname(__FILE__) . "/../../I18N/Arabic.php"); +$fontPath = dirname(__FILE__) . "/../../I18N/Arabic/Examples/GD/ae_AlHor.ttf"; + +/* + * Inputs are some text, line wrapping options, and a font size. + */ +$textUtf8 = "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ"; +$maxChars = 50; +$fontSize = 28; + +/* + * First, convert the text into LTR byte order with line wrapping, * Using the Ar-PHP library. * * The Ar-PHP library uses the default internal encoding, and can print @@ -29,19 +45,30 @@ require_once(dirname(__FILE__) . "/../../vendor/I18N/Arabic.php"); */ mb_internal_encoding("UTF-8"); $Arabic = new I18N_Arabic('Glyphs'); -$text = "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ"; -$text = $Arabic -> utf8Glyphs($text); +$textLtr = $Arabic -> utf8Glyphs($textUtf8, $maxChars); +$textLine = explode("\n", $textLtr); /* - * Set up and use the printer + * Set up and use an image print buffer with a suitable font */ $buffer = new ImagePrintBuffer(); -$profile = EposTepCapabilityProfile::getInstance(); -$connector = new FilePrintConnector("php://output"); - // = WindowsPrintConnector("LPT2"); - // Windows LPT2 was used in the bug tracker +$buffer -> setFont($fontPath); +$buffer -> setFontSize($fontSize); -$printer = new Escpos($connector, $profile); +$profile = CapabilityProfile::load("TEP-200M"); +$connector = new FilePrintConnector("php://output"); + // = new WindowsPrintConnector("LPT2"); + // Windows LPT2 was used in the bug tracker + +$printer = new Printer($connector, $profile); $printer -> setPrintBuffer($buffer); -$printer -> text($text . "\n"); + +$printer -> setJustification(Printer::JUSTIFY_RIGHT); +foreach($textLine as $text) { + // Print each line separately. We need to do this since Imagick thinks + // text is left-to-right + $printer -> text($text . "\n"); +} + +$printer -> cut(); $printer -> close(); diff --git a/htdocs/includes/mike42/escpos-php/example/specific/62-greek-symbol-swap.php b/htdocs/includes/mike42/escpos-php/example/specific/62-greek-symbol-swap.php new file mode 100644 index 00000000000..5ea995e5aed --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/specific/62-greek-symbol-swap.php @@ -0,0 +1,15 @@ + text("Μιχάλης Νίκος\n"); +$printer -> cut(); +$printer -> close(); + +?> diff --git a/htdocs/includes/mike42/escpos-php/example/specific/68-redblack.php b/htdocs/includes/mike42/escpos-php/example/specific/68-redblack.php new file mode 100644 index 00000000000..142a83ab3e7 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/specific/68-redblack.php @@ -0,0 +1,21 @@ + text("Hello World!\n"); + $printer -> setColor(Printer::COLOR_2); + $printer -> text("Red?!\n"); + $printer -> setColor(Printer::COLOR_1); + $printer -> text("Default color again?!\n"); + $printer -> cut(); +} finally { + /* Always close the printer! */ + $printer -> close(); +} diff --git a/htdocs/includes/mike42/escpos-php/example/specific/97-dithering.php b/htdocs/includes/mike42/escpos-php/example/specific/97-dithering.php new file mode 100644 index 00000000000..312df749eb1 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/example/specific/97-dithering.php @@ -0,0 +1,28 @@ + bitImage($img1); + + /* Load with optimisations disabled, forcing the use of PHP to convert the + pixels, which uses a threshold and is much slower. + */ + $img2 = EscposImage::load(__DIR__ . '/../resources/tulips.png', false); + $printer -> bitImage($img2); + $printer -> cut(); +} finally { + /* Always close the printer! */ + $printer -> close(); +} diff --git a/htdocs/includes/mike42/escpos-php/example/text-size.php b/htdocs/includes/mike42/escpos-php/example/text-size.php index 2f9272e434b..01bf33dd699 100644 --- a/htdocs/includes/mike42/escpos-php/example/text-size.php +++ b/htdocs/includes/mike42/escpos-php/example/text-size.php @@ -5,33 +5,37 @@ * * @author Michael Billington */ -require_once(dirname(__FILE__) . "/../Escpos.php"); -$printer = new Escpos(); +require __DIR__ . '/../autoload.php'; +use Mike42\Escpos\Printer; +use Mike42\Escpos\PrintConnectors\FilePrintConnector; + +$connector = new FilePrintConnector("php://stdout"); +$printer = new Printer($connector); /* Initialize */ $printer -> initialize(); /* Text of various (in-proportion) sizes */ title($printer, "Change height & width\n"); -for($i = 1; $i <= 8; $i++) { - $printer -> setTextSize($i, $i); - $printer -> text($i); +for ($i = 1; $i <= 8; $i++) { + $printer -> setTextSize($i, $i); + $printer -> text($i); } $printer -> text("\n"); /* Width changing only */ title($printer, "Change width only (height=4):\n"); -for($i = 1; $i <= 8; $i++) { - $printer -> setTextSize($i, 4); - $printer -> text($i); +for ($i = 1; $i <= 8; $i++) { + $printer -> setTextSize($i, 4); + $printer -> text($i); } $printer -> text("\n"); /* Height changing only */ title($printer, "Change height only (width=4):\n"); -for($i = 1; $i <= 8; $i++) { - $printer -> setTextSize(4, $i); - $printer -> text($i); +for ($i = 1; $i <= 8; $i++) { + $printer -> setTextSize(4, $i); + $printer -> text($i); } $printer -> text("\n"); @@ -47,16 +51,15 @@ $printer -> text("Hello world!\n"); /* Very large text */ title($printer, "Largest possible text:\n"); -$printer -> setTextSize(8,8); +$printer -> setTextSize(8, 8); $printer -> text("Hello\nworld!\n"); $printer -> cut(); $printer -> close(); -function title(Escpos $printer, $text) { - $printer -> selectPrintMode(Escpos::MODE_EMPHASIZED); - $printer -> text("\n" . $text); - $printer -> selectPrintMode(); // Reset +function title(Printer $printer, $text) +{ + $printer -> selectPrintMode(Printer::MODE_EMPHASIZED); + $printer -> text("\n" . $text); + $printer -> selectPrintMode(); // Reset } - -?> diff --git a/htdocs/includes/mike42/escpos-php/phpunit.xml b/htdocs/includes/mike42/escpos-php/phpunit.xml new file mode 100644 index 00000000000..158b7e0775b --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/phpunit.xml @@ -0,0 +1,21 @@ + + + + test/unit + + + test/integration + + + + + src + + + diff --git a/htdocs/includes/mike42/escpos-php/src/AbstractCapabilityProfile.php b/htdocs/includes/mike42/escpos-php/src/AbstractCapabilityProfile.php deleted file mode 100644 index db2e8e01f58..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/AbstractCapabilityProfile.php +++ /dev/null @@ -1,61 +0,0 @@ - CodePage::CP437, - 1 => CodePage::CP932, - 2 => CodePage::CP850, - 3 => CodePage::CP860, - 4 => CodePage::CP863, - 5 => CodePage::CP865, - 6 => false, // Hiragana - 7 => false, // One-pass printing Kanji characters - 8 => false, // Page 8 [One-pass printing Kanji characters] - 11 => CodePage::CP851, - 12 => CodePage::CP853, - 13 => CodePage::CP857, - 14 => CodePage::CP737, - 15 => CodePage::ISO8859_7, - 16 => CodePage::CP1252, - 17 => CodePage::CP866, - 18 => CodePage::CP852, - 19 => CodePage::CP858, - 20 => false, // Thai Character Code 42 - 21 => CodePage::CP874, // Thai Character Code 11 - 22 => false, // Thai Character Code 13 - 23 => false, // Thai Character Code 14 - 24 => false, // Thai Character Code 16 - 25 => false, // Thai Character Code 17 - 26 => false, // Thai Character Code 18 - 30 => false, // TCVN-3: Vietnamese - 31 => false, // TCVN-3: Vietnamese - 32 => CodePage::CP720, - 33 => CodePage::CP775, - 34 => CodePage::CP855, - 35 => CodePage::CP861, - 36 => CodePage::CP862, - 37 => CodePage::CP864, - 38 => CodePage::CP869, - 39 => CodePage::ISO8859_2, - 40 => CodePage::ISO8859_15, - 41 => CodePage::CP1098, // PC1098: Farsi - 42 => CodePage::CP774, - 43 => CodePage::CP772, - 44 => CodePage::CP1125, - 45 => CodePage::CP1250, - 46 => CodePage::CP1251, - 47 => CodePage::CP1253, - 48 => CodePage::CP1254, - 49 => CodePage::CP1255, - 50 => CodePage::CP1256, - 51 => CodePage::CP1257, - 52 => CodePage::CP1258, - 53 => CodePage::RK1048, - 66 => false, // Devanagari - 67 => false, // Bengali - 68 => false, // Tamil - 69 => false, // Telugu - 70 => false, // Assamese - 71 => false, // Oriya - 72 => false, // Kannada - 73 => false, // Malayalam - 74 => false, // Gujarati - 75 => false, // Punjabi - 82 => false, // Marathi - 254 => false, - 255 => false); - } - - function getSupportsBarcodeB() { - return true; - } - - function getSupportsBitImage() { - return true; - } - - function getSupportsGraphics() { - return true; - } - - function getSupportsStarCommands() { - return false; - } - - function getSupportsQrCode() { - return true; - } -} diff --git a/htdocs/includes/mike42/escpos-php/src/DummyPrintConnector.php b/htdocs/includes/mike42/escpos-php/src/DummyPrintConnector.php deleted file mode 100644 index e1a197b7c7b..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/DummyPrintConnector.php +++ /dev/null @@ -1,78 +0,0 @@ -, - * incorporating modifications by: - * - Roni Saha - * - Gergely Radics - * - Warren Doyle - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Print connector that writes to nowhere, but allows the user to retrieve the - * buffered data. Used for testing. - */ -final class DummyPrintConnector implements PrintConnector { - /** - * @var array Buffer of accumilated data. - */ - private $buffer; - - /** - * @var string data which the printer will provide on next read - */ - private $readData; - - /** - * Create new print connector - */ - public function __construct() { - $this -> buffer = array(); - } - - public function __destruct() { - if($this -> buffer !== null) { - trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE); - } - } - - public function finalize() { - $this -> buffer = null; - } - - /** - * @return string Get the accumulated data that has been sent to this buffer. - */ - public function getData() { - return implode($this -> buffer); - } - - /* (non-PHPdoc) - * @see PrintConnector::read() - */ - public function read($len) { - return $len >= strlen($this -> readData) ? $this -> readData : substr($this -> readData, 0, $len); - } - - public function write($data) { - $this -> buffer[] = $data; - } -} diff --git a/htdocs/includes/mike42/escpos-php/src/EposTepCapabilityProfile.php b/htdocs/includes/mike42/escpos-php/src/EposTepCapabilityProfile.php deleted file mode 100644 index 2803fe3f69c..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/EposTepCapabilityProfile.php +++ /dev/null @@ -1,4 +0,0 @@ -, - * incorporating modifications by: - * - Roni Saha - * - Gergely Radics - * - Warren Doyle - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * This class deals with images in raster formats, and converts them into formats - * which are suitable for use on thermal receipt printers. Currently, only PNG - * images (in) and ESC/POS raster format (out) are implemeted. - * - * Input formats: - * - Currently, only PNG is supported. - * - Other easily read raster formats (jpg, gif) will be added at a later date, as this is not complex. - * - The BMP format can be directly read by some commands, but this has not yet been implemented. - * - * Output formats: - * - Currently, only ESC/POS raster format is supported - * - ESC/POS 'column format' support is partially implemented, but is not yet used by Escpos.php library. - * - Output as multiple rows of column format image is not yet in the works. - * - * Libraries: - * - Currently, php-gd is used to read the input. Support for imagemagick where gd is not installed is - * also not complex to add, and is a likely future feature. - * - Support for native use of the BMP format is a goal, for maximum compatibility with target environments. - */ -class EscposImage { - /** - * @var string The image's bitmap data (if it is a Windows BMP). - */ - protected $imgBmpData; - - /** - * @var string image data in rows: 1 for black, 0 for white. - */ - protected $imgData; - - /** - * @var string cached raster format data to avoid re-computation - */ - protected $imgRasterData; - - /** - * @var int height of the image - */ - protected $imgHeight; - - /** - * @var int width of the image - */ - protected $imgWidth; - - /** - * Load up an image from a filename - * - * @param string $imgPath The path to the image to load, or null to skip - * loading the image (some other functions are available for - * populating the data). Supported graphics types depend on your PHP configuration. - */ - public function __construct($imgPath = null) { - /* Can't use bitmaps yet */ - $this -> imgBmpData = null; - $this -> imgRasterData = null; - if($imgPath === null) { - // Blank image - $this -> imgHeight = 0; - $this -> imgWidth = 0; - $this -> imgData = ""; - return; - } - - /* Load up using GD */ - if(!file_exists($imgPath)) { - throw new Exception("File '$imgPath' does not exist."); - } - $ext = pathinfo($imgPath, PATHINFO_EXTENSION); - if($ext == "bmp") { - // The plan is to implement BMP handling directly in - // PHP, as some printers understand this format themselves. - // TODO implement PHP bitmap handling - throw new Exception("Native bitmaps not yet supported. Please convert the file to a supported raster format."); - } - if($this -> isGdSupported()) { - // Prefer to use gd. It is installed by default, so - // most systems will have it, giving a consistent UX. - switch($ext) { - case "png": - $im = @imagecreatefrompng($imgPath); - $this -> readImageFromGdResource($im); - return; - case "jpg": - $im = @imagecreatefromjpeg($imgPath); - $this -> readImageFromGdResource($im); - return; - case "gif": - $im = @imagecreatefromgif($imgPath); - $this -> readImageFromGdResource($im); - return; - } - } - if($this -> isImagickSupported()) { - $im = new Imagick(); - try { - // Throws an ImagickException if the format is not supported or file is not found - $im -> readImage($imgPath); - } catch(ImagickException $e) { - // Wrap in normal exception, so that classes which call this do not themselves require imagick as a dependency. - throw new Exception($e); - } - /* Flatten by doing a composite over white, in case of transparency */ - $flat = new Imagick(); - $flat -> newImage($im -> getimagewidth(), $im -> getimageheight(), "white"); - $flat -> compositeimage($im, Imagick::COMPOSITE_OVER, 0, 0); - $this -> readImageFromImagick($flat); - return; - } - throw new Exception("Images are not supported on your PHP. Please install either the gd or imagick extension."); - } - - /** - * @return int height of the image in pixels - */ - public function getHeight() { - return $this -> imgHeight; - } - - /** - * @return int Number of bytes to represent a row of this image - */ - public function getHeightBytes() { - return (int)(($this -> imgHeight + 7) / 8); - } - - /** - * @return int Width of the image - */ - public function getWidth() { - return $this -> imgWidth; - } - - /** - * @return int Number of bytes to represent a row of this image - */ - public function getWidthBytes() { - return (int)(($this -> imgWidth + 7) / 8); - } - - /** - * @return string binary data of the original file, for function which accept bitmaps. - */ - public function getWindowsBMPData() { - return $this -> imgBmpData; - } - - /** - * @return boolean True if the image was a windows bitmap, false otherwise - */ - public function isWindowsBMP() { - return $this -> imgBmpData != null; - } - - /** - * Load actual image pixels from GD resource. - * - * @param resouce $im GD resource to use - * @throws Exception Where the image can't be read. - */ - public function readImageFromGdResource($im) { - if(!is_resource($im)) { - throw new Exception("Failed to load image."); - } else if(!$this -> isGdSupported()) { - throw new Exception(__FUNCTION__ . " requires 'gd' extension."); - } - /* Make a string of 1's and 0's */ - $this -> imgHeight = imagesy($im); - $this -> imgWidth = imagesx($im); - $this -> imgData = str_repeat("\0", $this -> imgHeight * $this -> imgWidth); - for($y = 0; $y < $this -> imgHeight; $y++) { - for($x = 0; $x < $this -> imgWidth; $x++) { - /* Faster to average channels, blend alpha and negate the image here than via filters (tested!) */ - $cols = imagecolorsforindex($im, imagecolorat($im, $x, $y)); - $greyness = (int)(($cols['red'] + $cols['green'] + $cols['blue']) / 3) >> 7; // 1 for white, 0 for black - $black = (1 - $greyness) >> ($cols['alpha'] >> 6); // 1 for black, 0 for white, taking into account transparency - $this -> imgData[$y * $this -> imgWidth + $x] = $black; - } - } - } - - /** - * Load actual image pixels from Imagick object - * - * @param Imagick $im Image to load from - */ - public function readImageFromImagick(Imagick $im) { - /* Threshold */ - $im -> setImageType(Imagick::IMGTYPE_TRUECOLOR); // Remove transparency (good for PDF's) - $max = $im->getQuantumRange(); - $max = $max["quantumRangeLong"]; - $im -> thresholdImage(0.5 * $max); - /* Make a string of 1's and 0's */ - $geometry = $im -> getimagegeometry(); - $this -> imgHeight = $im -> getimageheight(); - $this -> imgWidth = $im -> getimagewidth(); - $this -> imgData = str_repeat("\0", $this -> imgHeight * $this -> imgWidth); - - for($y = 0; $y < $this -> imgHeight; $y++) { - for($x = 0; $x < $this -> imgWidth; $x++) { - /* Faster to average channels, blend alpha and negate the image here than via filters (tested!) */ - $cols = $im -> getImagePixelColor($x, $y); - $cols = $cols -> getcolor(); - $greyness = (int)(($cols['r'] + $cols['g'] + $cols['b']) / 3) >> 7; // 1 for white, 0 for black - $this -> imgData[$y * $this -> imgWidth + $x] = (1 - $greyness); // 1 for black, 0 for white - } - } - - } - - /** - * Output the image in raster (row) format. This can result in padding on the right of the image, if its width is not divisible by 8. - * - * @throws Exception Where the generated data is unsuitable for the printer (indicates a bug or oversized image). - * @return string The image in raster format. - */ - public function toRasterFormat() { - if($this -> imgRasterData != null) { - /* Use previous calculation */ - return $this -> imgRasterData; - } - /* Loop through and convert format */ - $widthPixels = $this -> getWidth(); - $heightPixels = $this -> getHeight(); - $widthBytes = $this -> getWidthBytes(); - $heightBytes = $this -> getHeightBytes(); - $x = $y = $bit = $byte = $byteVal = 0; - $data = str_repeat("\0", $widthBytes * $heightPixels); - if(strlen($data) == 0) { - return $data; - } - do { - $byteVal |= (int)$this -> imgData[$y * $widthPixels + $x] << (7 - $bit); - $x++; - $bit++; - if($x >= $widthPixels) { - $x = 0; - $y++; - $bit = 8; - if($y >= $heightPixels) { - $data[$byte] = chr($byteVal); - break; - } - } - if($bit >= 8) { - $data[$byte] = chr($byteVal); - $byteVal = 0; - $bit = 0; - $byte++; - } - } while(true); - if(strlen($data) != ($this -> getWidthBytes() * $this -> getHeight())) { - throw new Exception("Bug in " . __FUNCTION__ . ", wrong number of bytes."); - } - $this -> imgRasterData = $data; - return $this -> imgRasterData; - } - - /** - * Output image in column format. This format results in padding at the base and right of the image, if its height and width are not divisible by 8. - */ - private function toColumnFormat() { - /* Note: This function is marked private, as it is not yet used/tested and may be buggy. */ - $widthPixels = $this -> getWidth(); - $heightPixels = $this -> getHeight(); - $widthBytes = $this -> getWidthBytes(); - $heightBytes = $this -> getHeightBytes(); - $x = $y = $bit = $byte = $byteVal = 0; - $data = str_repeat("\0", $widthBytes * $heightBytes * 8); - do { - $byteVal |= (int)$this -> imgData[$y * $widthPixels + $x] << (8 - $bit); - $y++; - $bit++; - if($y >= $heightPixels) { - $y = 0; - $x++; - $bit = 8; - if($x >= $widthPixels) { - $data[$byte] = chr($byteVal); - break; - } - } - if($bit >= 8) { - $data[$byte] = chr($byteVal); - $byteVal = 0; - $bit = 0; - $byte++; - } - } while(true); - if(strlen($data) != ($widthBytes * $heightBytes * 8)) { - throw new Exception("Bug in " . __FUNCTION__ . ", wrong number of bytes. Should be " . ($widthBytes * $heightBytes * 8) . " but was " . strlen($data)); - } - return $data; - } - - /** - * @return boolean True if GD is supported, false otherwise (a wrapper for the static version, for mocking in tests) - */ - protected function isGdSupported() { - return self::isGdLoaded(); - } - - /** - * @return boolean True if Imagick is supported, false otherwise (a wrapper for the static version, for mocking in tests) - */ - protected function isImagickSupported() { - return self::isImagickLoaded(); - } - - - /** - * @return boolean True if GD is loaded, false otherwise - */ - public static function isGdLoaded() { - return extension_loaded('gd'); - } - - /** - * @return boolean True if Imagick is loaded, false otherwise - */ - public static function isImagickLoaded() { - return extension_loaded('imagick'); - } - - /** - * Load a PDF for use on the printer - * - * @param string $pdfFile The file to load - * @param string $pageWidth The width, in pixels, of the printer's output. The first page of the PDF will be scaled to approximately fit in this area. - * @param array $range array indicating the first and last page (starting from 0) to load. If not set, the entire document is loaded. - * @throws Exception Where Imagick is not loaded, or where a missing file or invalid page number is requested. - * @return multitype:EscposImage Array of images, retrieved from the PDF file. - */ - public static function loadPdf($pdfFile, $pageWidth = 550, array $range = null) { - if(!extension_loaded('imagick')) { - throw new Exception(__FUNCTION__ . " requires imagick extension."); - } - /* - * Load first page at very low density (resolution), to figure out what - * density to use to achieve $pageWidth - */ - try { - $image = new Imagick(); - $testRes = 2; // Test resolution - $image -> setresolution($testRes, $testRes); - $image -> readimage($pdfFile."[0]"); - $geo = $image -> getimagegeometry(); - $image -> destroy(); - $width = $geo['width']; - $newRes = $pageWidth / $width * $testRes; - /* Load actual document (can be very slow!) */ - $rangeStr = ""; // Set to [0] [0-1] page range if $range is set - if($range != null) { - if(count($range) != 2 || !isset($range[0]) || !is_integer($range[0]) || !isset($range[1]) || !is_integer($range[1]) || $range[0] > $range[1]) { - throw new Exception("Invalid range. Must be two numbers in the array: The start and finish page indexes, starting from 0."); - } - $rangeStr = "[" . ($range[0] == $range[1] ? $range[0] : implode($range, "-")) . "]"; - } - $image -> setresolution($newRes, $newRes); - $image -> readImage($pdfFile."$rangeStr"); - $pages = $image -> getNumberImages(); - /* Convert images to Escpos objects */ - $ret = array(); - for($i = 0;$i < $pages; $i++) { - $image -> setIteratorIndex($i); - $ep = new EscposImage(); - $ep -> readImageFromImagick($image); - $ret[] = $ep; - } - return $ret; - } catch(ImagickException $e) { - // Wrap in normal exception, so that classes which call this do not themselves require imagick as a dependency. - throw new Exception($e); - } - } -} diff --git a/htdocs/includes/mike42/escpos-php/src/EscposPrintBuffer.php b/htdocs/includes/mike42/escpos-php/src/EscposPrintBuffer.php deleted file mode 100644 index 703bc0a57c0..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/EscposPrintBuffer.php +++ /dev/null @@ -1,304 +0,0 @@ -, - * incorporating modifications by: - * - Roni Saha - * - Gergely Radics - * - Warren Doyle - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * This class manages newlines and character encoding for the target printer, and - * can be interchanged for an image-bassed buffer (ImagePrintBuffer) if you can't - * get it operating properly on your machine. - */ -class EscposPrintBuffer implements PrintBuffer { - /** - * @var boolean True to cache output as .gz, false to leave un-compressed (useful for debugging) - */ - const COMPRESS_CACHE = true; - - /** - * @var string The input encoding of the buffer. - */ - const INPUT_ENCODING = "UTF-8"; - - /** - * @var string Un-recorgnised characters will be replaced with this. - */ - const REPLACEMENT_CHAR = "?"; - - /** - * This array Maps ESC/POS character tables to names iconv encodings - */ - private $available = null; - - /** - * @var array Maps of UTF-8 to code-pages - */ - private $encode = null; - - /** - * @var Escpos Printer for output - */ - private $printer; - - /** - * Empty print buffer. - */ - function __construct() { - $this -> printer = null; - } - - public function flush() { - if($this -> printer == null) { - throw new LogicException("Not attached to a printer."); - } - // TODO Not yet implemented for this buffer: This indicates that the printer needs the current line to be ended. - } - - public function getPrinter() { - return $this -> printer; - } - - public function setPrinter(Escpos $printer = null) { - $this -> printer = $printer; - if($printer != null) { - $this -> loadAvailableCharacters(); - } - } - - public function writeText($text) { - if($this -> printer == null) { - throw new LogicException("Not attached to a printer."); - } - if($text == null) { - return; - } - if(!mb_detect_encoding($text, self::INPUT_ENCODING, true)) { - // Assume that the user has already put non-UTF8 into the target encoding. - return $this -> writeTextRaw($text); - } - $i = 0; - $j = 0; - $len = mb_strlen($text, self::INPUT_ENCODING); - while($i < $len) { - $matching = true; - if(($encoding = $this -> identifyText(mb_substr($text, $i, 1, self::INPUT_ENCODING))) === false) { - // Un-encodeable text - $encoding = $this -> getPrinter() -> getCharacterTable(); - } - $i++; - $j = 1; - do { - $char = mb_substr($text, $i, 1, self::INPUT_ENCODING); - $matching = !isset($this -> available[$char]) || isset($this -> available[$char][$encoding]); - if($matching) { - $i++; - $j++; - } - } while($matching && $i < $len); - $this -> writeTextUsingEncoding(mb_substr($text, $i - $j, $j, self::INPUT_ENCODING), $encoding); - } - } - - public function writeTextRaw($text) { - if($this -> printer == null) { - throw new LogicException("Not attached to a printer."); - } - if(strlen($text) == 0) { - return; - } - // Pass only printable characters - for($i = 0; $i < strlen($text); $i++) { - $c = substr($text, $i, 1); - if(!self::asciiCheck($c, true)) { - $text[$i] = self::REPLACEMENT_CHAR; - } - } - $this -> write($text); - } - - /** - * Return an encoding which we can start to use for outputting this text. Later parts of the text need not be included in the returned code page. - * - * @param string $text Input text to check. - * @return boolean|integer Code page number, or FALSE if the text is not printable on any supported encoding. - */ - private function identifyText($text) { - // TODO Replace this with an algorithm to choose the encoding which will encode the farthest into the string, to minimise code page changes. - $char = mb_substr($text, 0, 1, self::INPUT_ENCODING); - if(!isset($this -> available[$char])) { - /* Character not available anywhere */ - return false; - } - foreach($this -> available[$char] as $encodingNo => $true) { - /* Return first code-page where it is available */ - return $encodingNo; - } - return false; - } - - /** - * Based on the printer's connector, compute (or load a cached copy of) maps of UTF character to unicode characters for later use. - */ - private function loadAvailableCharacters() { - $supportedCodePages = $this -> printer -> getPrinterCapabilityProfile() -> getSupportedCodePages(); - $capabilityClassName = get_class($this -> printer -> getPrinterCapabilityProfile()); - $cacheFile = dirname(__FILE__) . "/cache/Characters-" . $capabilityClassName . ".ser" . (self::COMPRESS_CACHE ? ".gz" : ""); - $cacheKey = md5(serialize($supportedCodePages)); - /* Check for pre-generated file */ - if(file_exists($cacheFile)) { - $cacheData = file_get_contents($cacheFile); - if(self::COMPRESS_CACHE) { - $cacheData = gzdecode($cacheData); - } - if($cacheData) { - $dataArray = unserialize($cacheData); - if(isset($dataArray["key"]) && isset($dataArray["available"]) && isset($dataArray["encode"]) && $dataArray["key"] == $cacheKey) { - $this -> available = $dataArray["available"]; - $this -> encode = $dataArray["encode"]; - return; - } - } - } - /* Generate conversion tables */ - $encode = array(); - $available = array(); - $custom = $this -> printer -> getPrinterCapabilityProfile() -> getCustomCodePages(); - - foreach($supportedCodePages as $num => $characterMap) { - $encode[$num] = array(); - if($characterMap === false) { - continue; - } else if(strpos($characterMap, ":") !== false) { - /* Load a pre-defined custom map (vendor-specific code pages) */ - $i = strpos($characterMap, ":"); - if(substr($characterMap, 0, $i) !== "custom") { - continue; - } - $i++; - $mapName = substr($characterMap, $i, strlen($characterMap) - $i); - if(!isset($custom[$mapName]) || mb_strlen($custom[$mapName], self::INPUT_ENCODING) != 128) { - throw new Exception("Capability profile referenced invalid custom map '$mapName'."); - } - $map = $custom[$mapName]; - for($char = 128; $char <= 255; $char++) { - $utf8 = mb_substr($map, $char - 128, 1, self::INPUT_ENCODING); - if($utf8 == " ") { // Skip placeholders - continue; - } - if(!isset($available[$utf8])) { - $available[$utf8] = array(); - } - $available[$utf8][$num] = true; - $encode[$num][$utf8] = chr($char); - } - } else { - /* Generate map using iconv */ - for($char = 128; $char <= 255; $char++) { - $utf8 = @iconv($characterMap, self::INPUT_ENCODING, chr($char)); - if($utf8 == '') { - continue; - } - if(iconv(self::INPUT_ENCODING, $characterMap, $utf8) != chr($char)) { - // Avoid non-canonical conversions - continue; - } - if(!isset($available[$utf8])) { - $available[$utf8] = array(); - } - $available[$utf8][$num] = true; - $encode[$num][$utf8] = chr($char); - } - } - } - /* Use generated data */ - $dataArray = array("available" => $available, "encode" => $encode, "key" => $cacheKey); - $this -> available = $dataArray["available"]; - $this -> encode = $dataArray["encode"]; - $cacheData = serialize($dataArray); - if(self::COMPRESS_CACHE) { - $cacheData = gzencode($cacheData); - } - /* Attempt to cache, but don't worry if we can't */ - @file_put_contents($cacheFile, $cacheData); - } - - /** - * Encode a block of text using the specified map, and write it to the printer. - * - * @param string $text Text to print, UTF-8 format. - * @param integer $encodingNo Encoding number to use- assumed to exist. - */ - private function writeTextUsingEncoding($text, $encodingNo) { - $encodeMap = $this -> encode[$encodingNo]; - $len = mb_strlen($text, self::INPUT_ENCODING); - $rawText = str_repeat(self::REPLACEMENT_CHAR, $len); - for($i = 0; $i < $len; $i++) { - $char = mb_substr($text, $i, 1, self::INPUT_ENCODING); - if(isset($encodeMap[$char])) { - $rawText[$i] = $encodeMap[$char]; - } else if(self::asciiCheck($char)) { - $rawText[$i] = $char; - } - } - if($this -> printer -> getCharacterTable() != $encodingNo) { - $this -> printer -> selectCharacterTable($encodingNo); - } - $this -> writeTextRaw($rawText); - } - - /** - * Write data to the underlying printer. - * - * @param string $data - */ - private function write($data) { - $this -> printer -> getPrintConnector() -> write($data); - } - - /** - * Return true if a character is an ASCII printable character. - * - * @param string $char Character to check - * @param boolean $extended True to allow 128-256 values also (excluded by default) - * @return boolean True if the character is printable, false if it is not. - */ - private static function asciiCheck($char, $extended = false) { - if(strlen($char) != 1) { - // Multi-byte string - return false; - } - $num = ord($char); - if($num > 31 && $num < 127) { // Printable - return true; - } - if($num == 10) { // New-line (printer will take these) - return true; - } - if($extended && $num > 127) { - return true; - } - return false; - } -} diff --git a/htdocs/includes/mike42/escpos-php/src/FilePrintConnector.php b/htdocs/includes/mike42/escpos-php/src/FilePrintConnector.php deleted file mode 100644 index 8d87f0a527a..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/FilePrintConnector.php +++ /dev/null @@ -1,80 +0,0 @@ -, - * incorporating modifications by: - * - Roni Saha - * - Gergely Radics - * - Warren Doyle - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * PrintConnector for passing print data to a file. - */ -class FilePrintConnector implements PrintConnector { - /** - * @var resource The file pointer to send data to. - */ - protected $fp; - - /** - * Construct new connector, given a filename - * - * @param string $filename - */ - public function __construct($filename) { - $this -> fp = fopen($filename, "wb+"); - if($this -> fp === false) { - throw new Exception("Cannot initialise FilePrintConnector."); - } - } - - public function __destruct() { - if($this -> fp !== false) { - trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE); - } - } - - /** - * Close file pointer - */ - public function finalize() { - fclose($this -> fp); - $this -> fp = false; - } - - /* (non-PHPdoc) - * @see PrintConnector::read() - */ - public function read($len) { - rewind($this -> fp); - return fgets($this -> fp, $len + 1); - } - - /** - * Write data to the file - * - * @param string $data - */ - public function write($data) { - fwrite($this -> fp, $data); - } -} diff --git a/htdocs/includes/mike42/escpos-php/src/ImagePrintBuffer.php b/htdocs/includes/mike42/escpos-php/src/ImagePrintBuffer.php deleted file mode 100644 index 08ca64ac43e..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/ImagePrintBuffer.php +++ /dev/null @@ -1,99 +0,0 @@ -, - * incorporating modifications by: - * - Roni Saha - * - Gergely Radics - * - Warren Doyle - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * This class renders text to small images on-the-fly. It attempts to mimic the - * behaviour of text output, whilst supporting any fonts & character encodings - * which your system can handle. This class currently requires Imagick. - */ -class ImagePrintBuffer implements PrintBuffer { - private $printer; - - function __construct() { - if(!EscposImage::isImagickLoaded()) { - throw new Exception("ImagePrintBuffer requires the imagick extension"); - } - } - - function flush() { - if($this -> printer == null) { - throw new LogicException("Not attached to a printer."); - } - } - - function getPrinter() { - return $this -> printer; - } - - function setPrinter(Escpos $printer = null) { - $this -> printer = $printer; - } - - function writeText($text) { - if($this -> printer == null) { - throw new LogicException("Not attached to a printer."); - } - if($text == null) { - return; - } - $text = trim($text, "\n"); - /* Create Imagick objects */ - $image = new Imagick(); - $draw = new ImagickDraw(); - $color = new ImagickPixel('#000000'); - $background = new ImagickPixel('white'); - - /* Create annotation */ - //$draw -> setFont('Arial');// (not necessary?) - $draw -> setFontSize(24); // Size 21 looks good for FONT B - $draw -> setFillColor($color); - $draw -> setStrokeAntialias(true); - $draw -> setTextAntialias(true); - $metrics = $image -> queryFontMetrics($draw, $text); - $draw -> annotation(0, $metrics['ascender'], $text); - - /* Create image & draw annotation on it */ - $image -> newImage($metrics['textWidth'], $metrics['textHeight'], $background); - $image -> setImageFormat('png'); - $image -> drawImage($draw); - //$image -> writeImage("test.png"); - - /* Save image */ - $escposImage = new EscposImage(); - $escposImage -> readImageFromImagick($image); - $size = Escpos::IMG_DEFAULT; - $this -> printer -> bitImage($escposImage, $size); - } - - function writeTextRaw($text) { - if($this -> printer == null) { - throw new LogicException("Not attached to a printer."); - } - $this -> printer -> getPrintConnector() -> write($data); - } -} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfile.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfile.php new file mode 100644 index 00000000000..9a91390594e --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfile.php @@ -0,0 +1,348 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos; + +use \InvalidArgumentException; + +/** + * Store compatibility information about one printer. + */ +class CapabilityProfile +{ + + /** + * + * @var string $codePageCacheKey + * Hash of the code page data structure, to identify it for caching. + */ + protected $codePageCacheKey; + + /** + * + * @var array $codePages + * Associtive array of CodePage objects, indicating which encodings the printer supports. + */ + protected $codePages; + + /** + * + * @var array $colors + * Not used. + */ + protected $colors; + + /** + * + * @var array $features + * Feature values. + */ + protected $features; + + /** + * + * @var array $fonts + * Not used + */ + protected $fonts; + + /** + * + * @var array $media + * Not used + */ + protected $media; + + /** + * + * @var string $name + * Name of the profile, including model number. + */ + protected $name; + + /** + * + * @var string $notes + * Notes on the profile, null if not set. + */ + protected $notes; + + /** + * + * @var string $profileId + * ID of the profile. + */ + protected $profileId; + + + /** + * @var string $vendor + * Name of manufacturer. + */ + protected $vendor; + + /** + * + * @var array $encodings + * Data structure containing encodings loaded from disk, null if not loaded yet. + */ + protected static $encodings = null; + + /** + * + * @var array $profiles + * Data structure containing profiles loaded from disk, null if not loaded yet. + */ + protected static $profiles = null; + + /** + * Construct new CapabilityProfile. + * The encoding data must be loaded from disk before calling. + * + * @param string $profileId + * ID of the profile + * @param array $profileData + * Profile data from disk. + */ + protected function __construct($profileId, array $profileData) + { + // Basic primitive fields + $this->profileId = $profileId; + $this->name = $profileData['name']; + $this->notes = $profileData['notes']; + $this->vendor = $profileData['vendor']; + // More complex fields that are not currently loaded into custom objects + $this->features = $profileData['features']; + $this->colors = $profileData['colors']; + $this->fonts = $profileData['fonts']; + $this->media = $profileData['media']; + // More complex fields that are loaded into custom objects + $this->codePages = []; + $this->codePageCacheKey = md5(json_encode($profileData['codePages'])); + foreach ($profileData['codePages'] as $k => $v) { + $this->codePages[$k] = new CodePage($v, self::$encodings[$v]); + } + } + + /** + * + * @return string Hash of the code page data structure, to identify it for caching. + */ + public function getCodePageCacheKey() + { + return $this->codePageCacheKey; + } + + /** + * + * @return array Associtive array of CodePage objects, indicating which encodings the printer supports. + */ + public function getCodePages() + { + return $this->codePages; + } + + /** + * + * @param string $featureName + * Name of the feature to retrieve. + * @throws \InvalidArgumentException Where the feature does not exist. + * The exception will contain suggestions for the closest-named features. + * @return mixed feature value. + */ + public function getFeature($featureName) + { + if (isset($this->features[$featureName])) { + return $this->features[$featureName]; + } + $suggestionsArr = $this->suggestFeatureName($featureName); + $suggestionsStr = implode(", ", $suggestionsArr); + $str = "The feature '$featureName' does not exist. Try one that does exist, such as $suggestionsStr"; + throw new \InvalidArgumentException($str); + } + + /** + * + * @return string ID of the profile. + */ + public function getId() + { + return $this->profileId; + } + + /** + * + * @return string Name of the printer. + */ + public function getName() + { + return $this->name; + } + + /** + * + * @return boolean True if Barcode B command is supported, false otherwise + */ + public function getSupportsBarcodeB() + { + return $this->getFeature('barcodeB') === true; + } + + /** + * + * @return boolean True if Bit Image Raster command is supported, false otherwise + */ + public function getSupportsBitImageRaster() + { + return $this->getFeature('bitImageRaster') === true; + } + + /** + * + * @return boolean True if Graphics command is supported, false otherwise + */ + public function getSupportsGraphics() + { + return $this->getFeature('graphics') === true; + } + + /** + * + * @return boolean True if PDF417 code command is supported, false otherwise + */ + public function getSupportsPdf417Code() + { + // TODO submit 'pdf417Code' as a new feature to be tracked in upstream profiles + return $this->getFeature('qrCode') === true; + } + + /** + * + * @return boolean True if QR code command is supported, false otherwise + */ + public function getSupportsQrCode() + { + return $this->getFeature('qrCode') === true; + } + + /** + * + * @return boolean True if Star mode commands are supported, false otherwise + */ + public function getSupportsStarCommands() + { + return $this->getFeature('starCommands') === true; + } + + /** + * + * @return string Vendor of this printer. + */ + public function getVendor() + { + return $this->vendor; + } + + /** + * + * @param string $featureName + * Feature that does not exist + * @return array Three most similar feature names that do exist. + */ + protected function suggestFeatureName($featureName) + { + return self::suggestNearest($featureName, array_keys($this->features), 3); + } + + /** + * + * @return array Names of all profiles that exist. + */ + public static function getProfileNames() + { + self::loadCapabilitiesDataFile(); + return array_keys(self::$profiles); + } + + /** + * Retrieve the CapabilityProfile with the given ID. + * + * @param string $profileName + * The ID of the profile to load. + * @throws InvalidArgumentException Where the ID does not exist. Some similarly-named profiles will be suggested in the Exception text. + * @return CapabilityProfile The CapabilityProfile that was requested. + */ + public static function load($profileName) + { + self::loadCapabilitiesDataFile(); + if (! isset(self::$profiles[$profileName])) { + $suggestionsArray = self::suggestProfileName($profileName); + $suggestionsStr = implode(", ", $suggestionsArray); + throw new InvalidArgumentException("The CapabilityProfile '$profileName' does not exist. Try one that does exist, such as $suggestionsStr."); + } + return new CapabilityProfile($profileName, self::$profiles[$profileName]); + } + + /** + * Ensure that the capabilities.json data file has been loaded. + */ + protected static function loadCapabilitiesDataFile() + { + if (self::$profiles === null) { + $filename = dirname(__FILE__) . "/resources/capabilities.json"; + $capabilitiesData = json_decode(file_get_contents($filename), true); + self::$profiles = $capabilitiesData['profiles']; + self::$encodings = $capabilitiesData['encodings']; + } + } + + /** + * Return choices with smallest edit distance to an invalid input. + * + * @param string $input + * Input that is not a valid choice + * @param array $choices + * Array of valid choices. + * @param int $num + * Number of suggestions to return + */ + public static function suggestNearest($input, array $choices, $num) + { + $distances = array_fill_keys($choices, PHP_INT_MAX); + foreach ($distances as $word => $_) { + $distances[$word] = levenshtein($input, $word); + } + asort($distances); + return array_slice(array_keys($distances), 0, min($num, count($choices))); + } + + /** + * + * @param string $profileName + * profile name that does not exist + * @return array Three similar profile names that do exist, plus 'simple' and 'default' for good measure. + */ + protected static function suggestProfileName($profileName) + { + $suggestions = self::suggestNearest($profileName, array_keys(self::$profiles), 3); + $alwaysSuggest = [ + 'simple', + 'default' + ]; + foreach ($alwaysSuggest as $item) { + if (array_search($item, $suggestions) === false) { + array_push($suggestions, $item); + } + } + return $suggestions; + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/DefaultCapabilityProfile.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/DefaultCapabilityProfile.php new file mode 100644 index 00000000000..c574aed178b --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/DefaultCapabilityProfile.php @@ -0,0 +1,22 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ +namespace Mike42\Escpos\CapabilityProfiles; + +use Mike42\Escpos\CapabilityProfile; + +class DefaultCapabilityProfile +{ + public static function getInstance() + { + return CapabilityProfile::load('default'); + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/EposTepCapabilityProfile.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/EposTepCapabilityProfile.php new file mode 100644 index 00000000000..cc8e3ec5f3b --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/EposTepCapabilityProfile.php @@ -0,0 +1,22 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ +namespace Mike42\Escpos\CapabilityProfiles; + +use Mike42\Escpos\CapabilityProfile; + +class EposTepCapabilityProfile +{ + public static function getInstance() + { + return CapabilityProfile::load('TEP-200M'); + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/P822DCapabilityProfile.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/P822DCapabilityProfile.php new file mode 100644 index 00000000000..42ee3a0b4fa --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/P822DCapabilityProfile.php @@ -0,0 +1,22 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ +namespace Mike42\Escpos\CapabilityProfiles; + +use Mike42\Escpos\CapabilityProfile; + +class P822DCapabilityProfile +{ + public static function getInstance() + { + return CapabilityProfile::load('P822D'); + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/SimpleCapabilityProfile.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/SimpleCapabilityProfile.php new file mode 100644 index 00000000000..cb141b8b9b8 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/SimpleCapabilityProfile.php @@ -0,0 +1,22 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ +namespace Mike42\Escpos\CapabilityProfiles; + +use Mike42\Escpos\CapabilityProfile; + +class SimpleCapabilityProfile +{ + public static function getInstance() + { + return CapabilityProfile::load('simple'); + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/StarCapabilityProfile.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/StarCapabilityProfile.php new file mode 100644 index 00000000000..6e2f64c2c93 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CapabilityProfiles/StarCapabilityProfile.php @@ -0,0 +1,22 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ +namespace Mike42\Escpos\CapabilityProfiles; + +use Mike42\Escpos\CapabilityProfile; + +class StarCapabilityProfile +{ + public static function getInstance() + { + return CapabilityProfile::load('SP2000'); + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CodePage.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CodePage.php new file mode 100644 index 00000000000..25f58b95369 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/CodePage.php @@ -0,0 +1,181 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos; + +use \InvalidArgumentException; + +/** + * Class to handle data about a particular CodePage, as loaded from the receipt print + * database. + * + * Also computes map between UTF-8 and this encoding if necessary, using the iconv library. + */ +class CodePage +{ + /** + * The input encoding for generating character maps with iconv. + */ + const INPUT_ENCODING = "UTF-8"; + + /** + * @var string $data + * Data string, null if not known (can be computed with iconv) + */ + protected $data; + + /** + * @var string $iconv + * Iconv encoding name, null if not known + */ + protected $iconv; + + /** + * @var string $id + * Internal ID of the CodePage + */ + protected $id; + + /** + * @var string $name + * Name of the code page. Substituted with the ID if not set. + */ + protected $name; + + /** + * @var string $notes + * Notes on this code page, or null if not set. + */ + protected $notes; + + /** + * + * @param string $id + * Unique internal identifier for the CodePage. + * @param array $codePageData + * Associative array of CodePage data, as + * specified by the upstream receipt-print-hq/escpos-printer-db database. + * May contain 'name', 'data', 'iconv', and 'notes' fields. + */ + public function __construct($id, array $codePageData) + { + $this->id = $id; + $this->name = isset($codePageData['name']) ? $codePageData['name'] : $id; + $this->data = isset($codePageData['data']) ? implode("", $codePageData['data']) : null; + $this->iconv = isset($codePageData['iconv']) ? $codePageData['iconv'] : null; + $this->notes = isset($codePageData['notes']) ? $codePageData['notes'] : null; + } + + /** + * Get a 128-character data string representing this encoding. + * It will be + * calculated and cached if it was not previously known. + * + * @throws InvalidArgumentException Where the data is now known or computable. + * @return string Data for this encoding. + */ + public function getData() + { + if ($this->data !== null) { + // Return data if known + return $this->data; + } + if ($this->iconv !== null) { + // Calculate with iconv if we know the encoding name + $this->data = self::generateEncodingMap($this->iconv); + return $this->data; + } + // Can't encode.. + throw new InvalidArgumentException("Cannot encode this code page"); + } + + /** + * + * @return string Iconv encoding name, or blank if not set. + */ + public function getIconv() + { + return $this->iconv; + } + + /** + * + * @return string Unique identifier of the code page. + */ + public function getId() + { + return $this->id; + } + + /** + * Name of the code page. + */ + public function getName() + { + return $this->name; + } + + /** + * The notes may explain quirks about a code-page, such as a source if it's non-standard or un-encodeable. + * + * @return string Notes on the code page, or null if not set. + */ + public function getNotes() + { + return $this->notes; + } + + /** + * + * @return boolean True if we can encode with this code page (ie, we know what data it holds). + * + * Many printers contain vendor-specific code pages, which are named but have not been identified or + * typed out. For our purposes, this is an "un-encodeable" code page. + */ + public function isEncodable() + { + return $this->iconv !== null || $this->data !== null; + } + + /** + * Given an iconv encoding name, generate a 128-character UTF-8 string, containing code points 128-255. + * + * This string is used to map UTF-8 characters to their location in this code page. + * + * @param string $iconvName + * Name of the encoding + * @return string 128-character string in UTF-8. + */ + protected static function generateEncodingMap($iconvName) + { + // Start with array of blanks (" " indicates unknown character). + $charMap = array_fill(0, 128, " "); + // Loop through 128 code points + for ($char = 128; $char <= 255; $char ++) { + // Try to identify the UTF-8 character that would go here + $utf8 = @iconv($iconvName, self::INPUT_ENCODING, chr($char)); + if ($utf8 == '') { + continue; + } + if (iconv(self::INPUT_ENCODING, $iconvName, $utf8) != chr($char)) { + // Avoid non-canonical conversions (no known examples) + continue; + } + // Replace the ' ' with the correct character if we found it + $charMap[$char - 128] = $utf8; + } + // Join into a 128-character string and return. + $charMapStr = implode("", $charMap); + assert(mb_strlen($charMapStr, self::INPUT_ENCODING) == 128); + return $charMapStr; + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/Devices/AuresCustomerDisplay.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/Devices/AuresCustomerDisplay.php new file mode 100644 index 00000000000..3bf9101a4cf --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/Devices/AuresCustomerDisplay.php @@ -0,0 +1,150 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos\Devices; + +use Mike42\Escpos\Printer; + +/** + * A class for sending ESC/POS-like code to an Aures customer display. + * The display has some features that printers do not, such as an ability to "clear" the screen. + */ +class AuresCustomerDisplay extends Printer +{ + + /** + * Indicates that the text should wrap and type over + * existing text on the screen, rather than scroll. + */ + const TEXT_OVERWRITE = 1; + + /** + * Indicates that overflowing text should cause the + * display to scroll vertically, like a computer terminal. + */ + const TEXT_VERTICAL_SCROLL = 2; + + /** + * Indicates that overflowing text should cause the + * display to scroll horizontally, like a news ticker. + */ + const TEXT_HORIZONTAL_SCROLL = 3; + + /** + * + * {@inheritdoc} + * + * @see \Mike42\Escpos\Printer::initialize() + */ + public function initialize() + { + // Select ESC/POS mode first + $this->selectEscposMode(); + parent::initialize(); + // ESC @ does not reset character table on this printer + $this->selectCharacterTable(0); + // Default to horizontal scroll mode. Behaves most like a printer. + $this->selectTextScrollMode(AuresCustomerDisplay::TEXT_VERTICAL_SCROLL); + } + + /** + * Selects ESC/POS mode. + * + * This device supports other modes, which are not used. + */ + protected function selectEscposMode() + { + $this->connector->write("\x02\x05\x43\x31\x03"); + } + + /** + * + * @param int $mode + * The text scroll mode to use. One of + * AuresCustomerDisplay::TEXT_OVERWRITE, + * AuresCustomerDisplay::TEXT_VERTICAL_SCROLL or + * AuresCustomerDisplay::TEXT_HORIZONTAL_SCROLL + */ + public function selectTextScrollMode($mode = AuresCustomerDisplay::TEXT_VERTICAL_SCROLL) + { + self::validateInteger($mode, 1, 3, __FUNCTION__); + $this->connector->write("\x1F" . chr($mode)); + } + + /** + * Clear the display. + */ + public function clear() + { + $this->connector->write("\x0c"); + } + + /** + * Instruct the display to show the firmware version. + */ + public function showFirmwareVersion() + { + $this->connector->write("\x02\x05\x56\x01\x03"); + } + + /** + * Instruct the display to begin a self-test/demo sequence. + */ + public function selfTest() + { + $this->connector->write("\x02\x05\x44\x08\x03"); + } + + /** + * Instruct the display to show a pre-loaded logo. + * + * Note that this driver is not capable of uploading a + * logo, but that the vendor supplies software + * which has this function. + */ + public function showLogo() + { + $this->connector->write("\x02\xFC\x55\xAA\x55\xAA"); + } + + /** + * + * {@inheritdoc} + * + * @see \Mike42\Escpos\Printer::text() + */ + public function text($str = "") + { + self::validateString($str, __FUNCTION__); + // Need to intercept line-feeds, since "\n" is insufficient on this device. + foreach (explode("\n", $str) as $id => $line) { + if ($id > 0) { + $this->feed(); + } + parent::text($line); + } + } + + /** + * + * {@inheritdoc} + * + * @see \Mike42\Escpos\Printer::feed() + */ + public function feed($lines = 1) + { + self::validateInteger($lines, 1, 255, __FUNCTION__); + for ($i = 0; $i < $lines; $i ++) { + $this->connector->write("\r\n"); + } + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/EscposImage.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/EscposImage.php new file mode 100644 index 00000000000..9a625acb47c --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/EscposImage.php @@ -0,0 +1,460 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos; + +use Exception; +use InvalidArgumentException; + +/** + * This class deals with images in raster formats, and converts them into formats + * which are suitable for use on thermal receipt printers. Currently, only PNG + * images (in) and ESC/POS raster format (out) are implemeted. + * + * Input formats: + * - Currently, only PNG is supported. + * - Other easily read raster formats (jpg, gif) will be added at a later date, as this is not complex. + * - The BMP format can be directly read by some commands, but this has not yet been implemented. + * + * Output formats: + * - Currently, only ESC/POS raster format is supported + * - ESC/POS 'column format' support is partially implemented, but is not yet used by Escpos.php library. + * - Output as multiple rows of column format image is not yet in the works. + * + * Libraries: + * - Currently, php-gd is used to read the input. Support for imagemagick where gd is not installed is + * also not complex to add, and is a likely future feature. + * - Support for native use of the BMP format is a goal, for maximum compatibility with target environments. + */ +abstract class EscposImage +{ + /** + * @var int $imgHeight + * height of the image. + */ + protected $imgHeight = 0; + + /** + * @var int $imgWidth + * width of the image + */ + protected $imgWidth = 0; + + /** + * @var string $imgData + * Image data in rows: 1 for black, 0 for white. + */ + private $imgData = null; + + /** + * @var array:string $imgColumnData + * Cached column-format data to avoid re-computation + */ + private $imgColumnData = []; + + /** + * @var string $imgRasterData + * Cached raster format data to avoid re-computation + */ + private $imgRasterData = null; + + /** + * @var string $filename + * Filename of image on disk - null if not loaded from disk. + */ + private $filename = null; + + /** + * @var boolean $allowOptimisations + * True to allow faster library-specific rendering shortcuts, false to always just use + * image libraries to read pixels (more reproducible between systems). + */ + private $allowOptimisations = true; + + /** + * Construct a new EscposImage. + * + * @param string $filename Path to image filename, or null to create an empty image. + * @param boolean $allowOptimisations True (default) to use any library-specific tricks + * to speed up rendering, false to force the image to be read in pixel-by-pixel, + * which is easier to unit test and more reproducible between systems, but slower. + */ + public function __construct($filename = null, $allowOptimisations = true) + { + $this -> filename = $filename; + $this -> allowOptimisations = $allowOptimisations; + } + + /** + * @return int height of the image in pixels + */ + public function getHeight() + { + return $this -> imgHeight; + } + + /** + * @return int Number of bytes to represent a row of this image + */ + public function getHeightBytes() + { + return (int)(($this -> imgHeight + 7) / 8); + } + + /** + * @return int Width of the image + */ + public function getWidth() + { + return $this -> imgWidth; + } + + /** + * @return int Number of bytes to represent a row of this image + */ + public function getWidthBytes() + { + return (int)(($this -> imgWidth + 7) / 8); + } + + /** + * Output the image in raster (row) format. This can result in padding on the + * right of the image, if its width is not divisible by 8. + * + * @throws Exception Where the generated data is unsuitable for the printer + * (indicates a bug or oversized image). + * @return string The image in raster format. + */ + public function toRasterFormat() + { + // Just wraps implementations for caching & lazy loading + if ($this -> imgRasterData !== null) { + /* Return cached value */ + return $this -> imgRasterData; + } + if ($this -> allowOptimisations) { + /* Use optimised code if allowed */ + $this -> imgRasterData = $this -> getRasterFormatFromFile($this -> filename); + } + if ($this -> imgRasterData === null) { + /* Load in full image and render the slow way if no faster implementation + is available, or if we've been asked not to use it */ + if ($this -> imgData === null) { + $this -> loadImageData($this -> filename); + } + $this -> imgRasterData = $this -> getRasterFormat(); + } + return $this -> imgRasterData; + } + + /** + * Output the image in column format. + * + * @param boolean $doubleDensity True for double density (24px) lines, false for single-density (8px) lines. + * @return string[] an array, one item per line of output. All lines will be of equal size. + */ + public function toColumnFormat($doubleDensity = false) + { + $densityIdx = $doubleDensity ? 1 : 0; + // Just wraps implementations for caching and lazy loading + if (isset($this -> imgColumnData[$densityIdx])) { + /* Return cached value */ + return $this -> imgColumnData[$densityIdx]; + } + $this -> imgColumnData[$densityIdx] = null; + if ($this -> allowOptimisations) { + /* Use optimised code if allowed */ + $data = $this -> getColumnFormatFromFile($this -> filename, $doubleDensity); + $this -> imgColumnData[$densityIdx] = $data; + } + if ($this -> imgColumnData[$densityIdx] === null) { + /* Load in full image and render the slow way if no faster implementation + is available, or if we've been asked not to use it */ + if ($this -> imgData === null) { + $this -> loadImageData($this -> filename); + } + $this -> imgColumnData[$densityIdx] = $this -> getColumnFormat($doubleDensity); + } + return $this -> imgColumnData[$densityIdx]; + } + + /** + * Load an image from disk. This default implementation always gives a zero-sized image. + * + * @param string|null $filename Filename to load from. + */ + protected function loadImageData($filename = null) + { + // Load image in to string of 1's and 0's, also set width & height + $this -> setImgWidth(0); + $this -> setImgHeight(0); + $this -> setImgData(""); + } + + /** + * Set image data. + * + * @param string $data Image data to use, string of 1's (black) and 0's (white) in row-major order. + */ + protected function setImgData($data) + { + $this -> imgData = $data; + } + + /** + * Set image width. + * + * @param int $width width of the image + */ + protected function setImgWidth($width) + { + $this -> imgWidth = $width; + } + + /** + * Set image height. + * + * @param int $height height of the image. + */ + protected function setImgHeight($height) + { + $this -> imgHeight = $height; + } + + /** + * @param string $filename + * Filename to load from + * @return string|NULL + * Raster format data, or NULL if no optimised renderer is available in + * this implementation. + */ + protected function getRasterFormatFromFile($filename = null) + { + // No optimised implementation to provide + return null; + } + + /** + * @param string $filename + * Filename to load from + * @param boolean $highDensityVertical + * True for high density output (24px lines), false for regular density (8px) + * @return string[]|NULL + * Column format data as array, or NULL if optimised renderer isn't + * available in this implementation. + */ + protected function getColumnFormatFromFile($filename = null, $highDensityVertical = true) + { + // No optimised implementation to provide + return null; + } + + /** + * Get column fromat from loaded image pixels, line by line. + * + * @throws Exception + * Where wrong number of bytes has been generated. + * @return string + * Raster format data + */ + private function getRasterFormat() + { + /* Loop through and convert format */ + $widthPixels = $this -> getWidth(); + $heightPixels = $this -> getHeight(); + $widthBytes = $this -> getWidthBytes(); + $heightBytes = $this -> getHeightBytes(); + $x = $y = $bit = $byte = $byteVal = 0; + $data = str_repeat("\0", $widthBytes * $heightPixels); + if (strlen($data) == 0) { + return $data; + } + do { + $byteVal |= (int)$this -> imgData[$y * $widthPixels + $x] << (7 - $bit); + $x++; + $bit++; + if ($x >= $widthPixels) { + $x = 0; + $y++; + $bit = 8; + if ($y >= $heightPixels) { + $data[$byte] = chr($byteVal); + break; + } + } + if ($bit >= 8) { + $data[$byte] = chr($byteVal); + $byteVal = 0; + $bit = 0; + $byte++; + } + } while (true); + if (strlen($data) != ($this -> getWidthBytes() * $this -> getHeight())) { + throw new Exception("Bug in " . __FUNCTION__ . ", wrong number of bytes."); + } + return $data; + } + + /** + * Get column fromat from loaded image pixels, line by line. + * + * @param boolean $highDensity + * True for high density output (24px lines), false for regular density (8px) + * @return string[] + * Array of column format data, one item per row. + */ + private function getColumnFormat($highDensity) + { + $out = []; + $i = 0; + while (($line = $this -> getColumnFormatLine($i, $highDensity)) !== null) { + $out[] = $line; + $i++; + } + return $out; + } + + /** + * Output image in column format. Must be called once for each line of output. + * + * @param int $lineNo + * Line number to retrieve + * @param bool $highDensity + * True for high density output (24px lines), false for regular density (8px) + * @throws Exception + * Where wrong number of bytes has been generated. + * @return NULL|string + * Column format data, or null if there is no more data (when iterating) + */ + private function getColumnFormatLine($lineNo, $highDensity) + { + // Currently double density in both directions, very experimental + $widthPixels = $this -> getWidth(); + $heightPixels = $this -> getHeight(); + $widthBytes = $this -> getWidthBytes(); + $heightBytes = $this -> getHeightBytes(); + $lineHeight = $highDensity ? 3 : 1; // Vertical density. 1 or 3 (for 8 and 24 pixel lines) + // Initialise to zero + $x = $y = $bit = $byte = $byteVal = 0; + $data = str_repeat("\x00", $widthPixels * $lineHeight); + $yStart = $lineHeight * 8 * $lineNo; + if ($yStart >= $heightPixels) { + return null; + } + if (strlen($data) == 0) { + return $data; + } + do { + $yReal = $y + $yStart; + if ($yReal < $heightPixels) { + $byteVal |= (int)$this -> imgData[$yReal * $widthPixels + $x] << (7 - $bit); + } + $y++; + $bit++; + if ($y >= $lineHeight * 8) { + $y = 0; + $x++; + $bit = 8; + if ($x >= $widthPixels) { + $data[$byte] = chr($byteVal); + break; + } + } + if ($bit >= 8) { + $data[$byte] = chr($byteVal); + $byteVal = 0; + $bit = 0; + $byte++; + } + } while (true); + if (strlen($data) != $widthPixels * $lineHeight) { + throw new Exception("Bug in " . __FUNCTION__ . ", wrong number of bytes."); + } + return $data; + } + + /** + * @return boolean True if GD is loaded, false otherwise + */ + public static function isGdLoaded() + { + return extension_loaded('gd'); + } + + /** + * @return boolean True if Imagick is loaded, false otherwise + */ + public static function isImagickLoaded() + { + return extension_loaded('imagick'); + } + + + /** + * This is a convinience method to load an image from file, auto-selecting + * an EscposImage implementation which uses an available library. + * + * The sub-classes can be constructed directly if you know that you will + * have Imagick or GD on the print server. + * + * @param string $filename + * File to load from + * @param bool $allowOptimisations + * True to allow the fastest rendering shortcuts, false to force the library + * to read the image into an internal raster format and use PHP to render + * the image (slower but less fragile). + * @param array $preferred + * Order to try to load libraries in- escpos-php supports pluggable image + * libraries. Items can be 'imagick', 'gd', 'native'. + * @throws Exception + * Where no suitable library could be found for the type of file being loaded. + * @return EscposImage + * + */ + public static function load( + $filename, + $allowOptimisations = true, + array $preferred = ['imagick', 'gd', 'native'] + ) { + /* Fail early if file is not readble */ + if (!file_exists($filename) || !is_readable($filename)) { + throw new Exception("File '$filename' does not exist, or is not readable."); + } + $ext = pathinfo($filename, PATHINFO_EXTENSION); + /* Choose the first implementation which can handle this format */ + foreach ($preferred as $implemetnation) { + if ($implemetnation === 'imagick') { + if (!self::isImagickLoaded()) { + // Skip option if Imagick is not loaded + continue; + } + return new \Mike42\Escpos\ImagickEscposImage($filename, $allowOptimisations); + } elseif ($implemetnation === 'gd') { + if (!self::isGdLoaded()) { + // Skip option if GD not loaded + continue; + } + return new \Mike42\Escpos\GdEscposImage($filename, $allowOptimisations); + } elseif ($implemetnation === 'native') { + if (!in_array($ext, ['wbmp', 'pbm', 'bmp'])) { + // Pure PHP is fastest way to generate raster output from wbmp and pbm formats. + continue; + } + return new \Mike42\Escpos\NativeEscposImage($filename, $allowOptimisations); + } else { + // Something else on the 'preferred' list. + throw new InvalidArgumentException("'$implemetnation' is not a known EscposImage implementation"); + } + } + throw new InvalidArgumentException("No suitable EscposImage implementation found for '$filename'."); + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/GdEscposImage.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/GdEscposImage.php new file mode 100644 index 00000000000..32edf76ef7c --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/GdEscposImage.php @@ -0,0 +1,86 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos; + +use Mike42\Escpos\EscposImage; +use Exception; + +/** + * Implementation of EscposImage using the GD PHP plugin. + */ +class GdEscposImage extends EscposImage +{ + /** + * Load an image from disk, into memory, using GD. + * + * @param string|null $filename The filename to load from + * @throws Exception if the image format is not supported, + * or the file cannot be opened. + */ + protected function loadImageData($filename = null) + { + if ($filename === null) { + /* Set to blank image */ + return parent::loadImageData($filename); + } + + $ext = pathinfo($filename, PATHINFO_EXTENSION); + switch ($ext) { + case "png": + $im = @imagecreatefrompng($filename); + break; + case "jpg": + $im = @imagecreatefromjpeg($filename); + break; + case "gif": + $im = @imagecreatefromgif($filename); + break; + default: + throw new Exception("Image format not supported in GD"); + } + $this -> readImageFromGdResource($im); + } + + /** + * Load actual image pixels from GD resource. + * + * @param resource $im GD resource to use + * @throws Exception Where the image can't be read. + */ + public function readImageFromGdResource($im) + { + if (!is_resource($im)) { + throw new Exception("Failed to load image."); + } elseif (!EscposImage::isGdLoaded()) { + throw new Exception(__FUNCTION__ . " requires 'gd' extension."); + } + /* Make a string of 1's and 0's */ + $imgHeight = imagesy($im); + $imgWidth = imagesx($im); + $imgData = str_repeat("\0", $imgHeight * $imgWidth); + for ($y = 0; $y < $imgHeight; $y++) { + for ($x = 0; $x < $imgWidth; $x++) { + /* Faster to average channels, blend alpha and negate the image here than via filters (tested!) */ + $cols = imagecolorsforindex($im, imagecolorat($im, $x, $y)); + // 1 for white, 0 for black, ignoring transparency + $greyness = (int)(($cols['red'] + $cols['green'] + $cols['blue']) / 3) >> 7; + // 1 for black, 0 for white, taking into account transparency + $black = (1 - $greyness) >> ($cols['alpha'] >> 6); + $imgData[$y * $imgWidth + $x] = $black; + } + } + $this -> setImgWidth($imgWidth); + $this -> setImgHeight($imgHeight); + $this -> setImgData($imgData); + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/ImagickEscposImage.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/ImagickEscposImage.php new file mode 100644 index 00000000000..13851a4d034 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/ImagickEscposImage.php @@ -0,0 +1,273 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos; + +use Exception; +use Imagick; +use Mike42\Escpos\EscposImage; + +/** + * Implementation of EscposImage using the Imagick PHP plugin. + */ +class ImagickEscposImage extends EscposImage +{ + /** + * Load actual image pixels from Imagick object + * + * @param Imagick $im Image to load from + */ + public function readImageFromImagick(\Imagick $im) + { + /* Strip transparency */ + $im = self::alphaRemove($im); + /* Threshold */ + $im -> setImageType(\Imagick::IMGTYPE_TRUECOLOR); // Remove transparency (good for PDF's) + $max = $im->getQuantumRange(); + $max = $max["quantumRangeLong"]; + $im -> thresholdImage(0.5 * $max); + /* Make a string of 1's and 0's */ + $imgHeight = $im -> getimageheight(); + $imgWidth = $im -> getimagewidth(); + $imgData = str_repeat("\0", $imgHeight * $imgWidth); + for ($y = 0; $y < $imgHeight; $y++) { + for ($x = 0; $x < $imgWidth; $x++) { + /* Faster to average channels, blend alpha and negate the image here than via filters (tested!) */ + $cols = $im -> getImagePixelColor($x, $y); + $cols = $cols -> getcolor(); + $greyness = (int)(($cols['r'] + $cols['g'] + $cols['b']) / 3) >> 7; // 1 for white, 0 for black + $imgData[$y * $imgWidth + $x] = (1 - $greyness); // 1 for black, 0 for white + } + } + $this -> setImgWidth($imgWidth); + $this -> setImgHeight($imgHeight); + $this -> setImgData($imgData); + } + + /** + * @param string $filename + * Filename to load from + * @param boolean $highDensityVertical + * True for high density output (24px lines), false for regular density (8px) + * @return string[]|NULL + * Column format data as array, or NULL if optimised renderer isn't + * available in this implementation. + */ + protected function getColumnFormatFromFile($filename = null, $highDensityVertical = true) + { + if ($filename === null) { + return null; + } + $im = $this -> getImageFromFile($filename); + $this -> setImgWidth($im -> getimagewidth()); + $this -> setImgHeight($im -> getimageheight()); + + /* Strip transparency */ + $im = self::alphaRemove($im); + $im -> setformat('pbm'); + $im -> getimageblob(); // Forces 1-bit rendering now, so that subsequent operations are faster + $im -> rotateImage('#fff', 90.0); + $im -> flopImage(); + $lineHeight = $highDensityVertical ? 3 : 1; + $blobs = $this -> getColumnFormatFromImage($im, $lineHeight * 8); + return $blobs; + } + + /** + * Load an image from disk, into memory, using Imagick. + * + * @param string|null $filename The filename to load from + * @throws Exception if the image format is not supported, + * or the file cannot be opened. + */ + protected function loadImageData($filename = null) + { + if ($filename === null) { + /* Set to blank image */ + return parent::loadImageData($filename); + } + + $im = $this -> getImageFromFile($filename); + $this -> readImageFromImagick($im); + } + + /** + * Return data in column format as array of slices. + * Operates recursively to save cloning larger image many times. + * + * @param Imagick $im + * @param int $lineHeight + * Height of printed line in dots. 8 or 24. + * @return string[] + */ + private function getColumnFormatFromImage(Imagick $im, $lineHeight) + { + $imgWidth = $im->getimagewidth(); + if ($imgWidth == $lineHeight) { + // Return glob of this panel + return [$this -> getRasterBlobFromImage($im)]; + } elseif ($imgWidth > $lineHeight) { + // Calculations + $slicesLeft = ceil($imgWidth / $lineHeight / 2); + $widthLeft = $slicesLeft * $lineHeight; + $widthRight = $imgWidth - $widthLeft; + // Slice up (left) + $left = clone $im; + $left -> extentimage($widthLeft, $left -> getimageheight(), 0, 0); + // Slice up (right - ensure width is divisible by lineHeight also) + $right = clone $im; + $widthRightRounded = $widthRight < $lineHeight ? $lineHeight : $widthRight; + $right -> extentimage($widthRightRounded, $right -> getimageheight(), $widthLeft, 0); + // Recurse + $leftBlobs = $this -> getColumnFormatFromImage($left, $lineHeight); + $rightBlobs = $this -> getColumnFormatFromImage($right, $lineHeight); + return array_merge($leftBlobs, $rightBlobs); + } else { + /* Image is smaller than full width */ + $im -> extentimage($lineHeight, $im -> getimageheight(), 0, 0); + return [$this -> getRasterBlobFromImage($im)]; + } + } + + /** + * Load Imagick file from image + * + * @param string $filename Filename to load + * @throws Exception Wrapped Imagick error if image can't be loaded + * @return Imagick Loaded image + */ + private function getImageFromFile($filename) + { + $im = new Imagick(); + try { + $im->setResourceLimit(6, 1); // Prevent libgomp1 segfaults, grumble grumble. + $im -> readimage($filename); + } catch (\ImagickException $e) { + /* Re-throw as normal exception */ + throw new Exception($e); + } + return $im; + } + + /** + * Pull blob (from PBM-formatted image only!), and spit out a blob or raster data. + * Will crash out on anything which is not a valid 'P4' file. + * + * @param Imagick $im Image which has format PBM. + * @return string raster data from the image + */ + private function getRasterBlobFromImage(Imagick $im) + { + $blob = $im -> getimageblob(); + /* Find where header ends */ + $i = strpos($blob, "P4\n") + 2; + while ($blob[$i + 1] == '#') { + $i = strpos($blob, "\n", $i + 1); + } + $i = strpos($blob, "\n", $i + 1); + /* Return raster data only */ + $subBlob = substr($blob, $i + 1); + return $subBlob; + } + + /** + * @param string $filename + * Filename to load from + * @return string|NULL + * Raster format data, or NULL if no optimised renderer is available in + * this implementation. + */ + protected function getRasterFormatFromFile($filename = null) + { + if ($filename === null) { + return null; + } + $im = $this -> getImageFromFile($filename); + $this -> setImgWidth($im -> getimagewidth()); + $this -> setImgHeight($im -> getimageheight()); + /* Convert to PBM and extract raster portion */ + $im = self::alphaRemove($im); + $im -> setFormat('pbm'); + return $this -> getRasterBlobFromImage($im); + } + + /** + * Load a PDF for use on the printer + * + * @param string $pdfFile + * The file to load + * @param int $pageWidth + * The width, in pixels, of the printer's output. The first page of the + * PDF will be scaled to approximately fit in this area. + * @throws Exception Where Imagick is not loaded, or where a missing file + * or invalid page number is requested. + * @return array Array of images, retrieved from the PDF file. + */ + public static function loadPdf($pdfFile, $pageWidth = 550) + { + if (!EscposImage::isImagickLoaded()) { + throw new Exception(__FUNCTION__ . " requires imagick extension."); + } + /* + * Load first page at very low density (resolution), to figure out what + * density to use to achieve $pageWidth + */ + try { + $image = new \Imagick(); + $testRes = 2; // Test resolution + $image -> setresolution($testRes, $testRes); + /* Load document just to measure geometry */ + $image -> readimage($pdfFile); + $geo = $image -> getimagegeometry(); + $image -> destroy(); + $width = $geo['width']; + $newRes = $pageWidth / $width * $testRes; + /* Load entire document in */ + $image -> setresolution($newRes, $newRes); + $image -> readImage($pdfFile); + $pages = $image -> getNumberImages(); + /* Convert images to Escpos objects */ + $ret = []; + for ($i = 0; $i < $pages; $i++) { + $image -> setIteratorIndex($i); + $ep = new ImagickEscposImage(); + $ep -> readImageFromImagick($image); + $ret[] = $ep; + } + return $ret; + } catch (\ImagickException $e) { + /* Wrap in normal exception, so that classes which call this do not + * themselves require imagick as a dependency. */ + throw new Exception($e); + } + } + + /** + * Paste image over white canvas to stip transparency reliably on different + * versions of ImageMagick. + * + * There are other methods for this: + * - flattenImages() is deprecated + * - setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE) is not available on + * ImageMagick < 6.8. + * + * @param Imagick $im Image to flatten + * @return Imagick Flattened image + */ + private static function alphaRemove(Imagick $im) + { + $flat = new \Imagick(); + $flat -> newImage($im -> getimagewidth(), $im -> getimageheight(), "white", $im -> getimageformat()); + $flat -> compositeimage($im, \Imagick::COMPOSITE_OVER, 0, 0); + return $flat; + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/NativeEscposImage.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/NativeEscposImage.php new file mode 100644 index 00000000000..e85c942b2c3 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/NativeEscposImage.php @@ -0,0 +1,24 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos; + +use Mike42\Escpos\EscposImage; + +/** + * Implementation of EscposImage using only native PHP. + * TODO: wbmp, pbm, bmp files. + */ +class NativeEscposImage extends EscposImage +{ + +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/EscposPrintBuffer.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/EscposPrintBuffer.php new file mode 100644 index 00000000000..4e04176521e --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/EscposPrintBuffer.php @@ -0,0 +1,300 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos\PrintBuffers; + +use LogicException; +use Mike42\Escpos\Printer; + +/** + * This class manages newlines and character encoding for the target printer, and + * can be interchanged for an image-bassed buffer (ImagePrintBuffer) if you can't + * get it operating properly on your machine. + */ +class EscposPrintBuffer implements PrintBuffer +{ + /** + * True to cache output as .z, false to leave un-compressed (useful for debugging) + */ + const COMPRESS_CACHE = true; + + /** + * The input encoding of the buffer. + */ + const INPUT_ENCODING = "UTF-8"; + + /** + * Un-recognised characters will be replaced with this. + */ + const REPLACEMENT_CHAR = "?"; + + /** + * @var array $available + * This array Maps ESC/POS character tables to names iconv encodings + */ + private $available = null; + + /** + * @var array $encode + * Maps of UTF-8 to code-pages + */ + private $encode = null; + + /** + * @var Printer|null $printer + * Printer for output + */ + private $printer; + + /** + * Empty print buffer. + */ + public function __construct() + { + $this -> printer = null; + } + + public function flush() + { + if ($this -> printer == null) { + throw new LogicException("Not attached to a printer."); + } + // TODO Not yet implemented for this buffer: This indicates that the printer needs the current line to be ended. + } + + public function getPrinter() + { + return $this -> printer; + } + + public function setPrinter(Printer $printer = null) + { + $this -> printer = $printer; + if ($printer != null) { + $this -> loadAvailableCharacters(); + } + } + + public function writeText($text) + { + if ($this -> printer == null) { + throw new LogicException("Not attached to a printer."); + } + if ($text == null) { + return; + } + if (!mb_detect_encoding($text, self::INPUT_ENCODING, true)) { + // Assume that the user has already put non-UTF8 into the target encoding. + return $this -> writeTextRaw($text); + } + $i = 0; + $j = 0; + $len = mb_strlen($text, self::INPUT_ENCODING); + while ($i < $len) { + $matching = true; + if (($encoding = $this -> identifyText(mb_substr($text, $i, 1, self::INPUT_ENCODING))) === false) { + // Un-encodeable text + $encoding = $this -> getPrinter() -> getCharacterTable(); + } + $i++; + $j = 1; + do { + $char = mb_substr($text, $i, 1, self::INPUT_ENCODING); + $matching = !isset($this -> available[$char]) || isset($this -> available[$char][$encoding]); + if ($matching) { + $i++; + $j++; + } + } while ($matching && $i < $len); + $this -> writeTextUsingEncoding(mb_substr($text, $i - $j, $j, self::INPUT_ENCODING), $encoding); + } + } + + public function writeTextRaw($text) + { + if ($this -> printer == null) { + throw new LogicException("Not attached to a printer."); + } + if (strlen($text) == 0) { + return; + } + // Pass only printable characters + $j = 0; + $l = strlen($text); + $outp = str_repeat(self::REPLACEMENT_CHAR, $l); + for ($i = 0; $i < $l; $i++) { + $c = substr($text, $i, 1); + if ($c == "\r") { + /* Skip past Windows line endings (raw usage). */ + continue; + } else if (self::asciiCheck($c, true)) { + $outp[$j] = $c; + } + $j++; + } + $this -> write(substr($outp, 0, $j)); + } + + /** + * Return an encoding which we can start to use for outputting this text. + * Later parts of the text need not be included in the returned code page. + * + * @param string $text Input text to check. + * @return boolean|integer Code page number, or FALSE if the text is not + * printable on any supported encoding. + */ + private function identifyText($text) + { + // TODO Replace this with an algorithm to choose the encoding which will + // encode the farthest into the string, to minimise code page changes. + $char = mb_substr($text, 0, 1, self::INPUT_ENCODING); + if (!isset($this -> available[$char])) { + /* Character not available anywhere */ + return false; + } + foreach ($this -> available[$char] as $encodingNo => $true) { + /* Return first code-page where it is available */ + return $encodingNo; + } + return false; + } + + /** + * Based on the printer's connector, compute (or load a cached copy of) maps + * of UTF character to unicode characters for later use. + */ + private function loadAvailableCharacters() + { + $profile = $this -> printer -> getPrinterCapabilityProfile(); + $supportedCodePages = $profile -> getCodePages(); + $profileName = $profile -> getId(); + $cacheFile = dirname(__FILE__) . "/cache/Characters-" . $profileName . ".ser" . + (self::COMPRESS_CACHE ? ".z" : ""); + $cacheKey = $profile -> getCodePageCacheKey(); + /* Check for pre-generated file */ + if (file_exists($cacheFile)) { + $cacheData = file_get_contents($cacheFile); + if (self::COMPRESS_CACHE) { + $cacheData = gzuncompress($cacheData); + } + if ($cacheData) { + $dataArray = unserialize($cacheData); + if (isset($dataArray["key"]) && isset($dataArray["available"]) && + isset($dataArray["encode"]) && $dataArray["key"] == $cacheKey) { + $this -> available = $dataArray["available"]; + $this -> encode = $dataArray["encode"]; + return; + } + } + } + + /* Generate conversion tables */ + $encode = []; + $available = []; + + foreach ($supportedCodePages as $num => $codePage) { + $encode[$num] = []; + if (!$codePage -> isEncodable()) { + continue; + } + $map = $codePage -> getData(); + for ($char = 128; $char <= 255; $char++) { + $utf8 = mb_substr($map, $char - 128, 1, self::INPUT_ENCODING); + if ($utf8 == " ") { // Skip placeholders + continue; + } + if (!isset($available[$utf8])) { + $available[$utf8] = []; + } + $available[$utf8][$num] = true; + $encode[$num][$utf8] = chr($char); + } + } + + /* Use generated data */ + $dataArray = ["available" => $available, "encode" => $encode, "key" => $cacheKey]; + $this -> available = $dataArray["available"]; + $this -> encode = $dataArray["encode"]; + $cacheData = serialize($dataArray); + if (self::COMPRESS_CACHE) { + $cacheData = gzcompress($cacheData); + } + /* Attempt to cache, but don't worry if we can't */ + @file_put_contents($cacheFile, $cacheData); + } + + /** + * Encode a block of text using the specified map, and write it to the printer. + * + * @param string $text Text to print, UTF-8 format. + * @param integer $encodingNo Encoding number to use- assumed to exist. + */ + private function writeTextUsingEncoding($text, $encodingNo) + { + $encodeMap = $this -> encode[$encodingNo]; + $len = mb_strlen($text, self::INPUT_ENCODING); + $rawText = str_repeat(self::REPLACEMENT_CHAR, $len); + $j = 0; + for ($i = 0; $i < $len; $i++) { + $char = mb_substr($text, $i, 1, self::INPUT_ENCODING); + if (isset($encodeMap[$char])) { + $rawText[$j] = $encodeMap[$char]; + } elseif (self::asciiCheck($char)) { + $rawText[$j] = $char; + } elseif ($char === "\r") { + /* Skip past Windows line endings (UTF-8 usage) */ + continue; + } + $j++; + } + if ($this -> printer -> getCharacterTable() != $encodingNo) { + $this -> printer -> selectCharacterTable($encodingNo); + } + $this -> writeTextRaw(substr($rawText, 0, $j)); + } + + /** + * Write data to the underlying printer. + * + * @param string $data + */ + private function write($data) + { + $this -> printer -> getPrintConnector() -> write($data); + } + + /** + * Return true if a character is an ASCII printable character. + * + * @param string $char Character to check + * @param boolean $extended True to allow 128-256 values also (excluded by default) + * @return boolean True if the character is printable, false if it is not. + */ + private static function asciiCheck($char, $extended = false) + { + if (strlen($char) != 1) { + // Multi-byte string + return false; + } + $num = ord($char); + if ($num > 31 && $num < 127) { // Printable + return true; + } + if ($num == 10) { // New-line (printer will take these) + return true; + } + if ($extended && $num > 127) { + return true; + } + return false; + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/ImagePrintBuffer.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/ImagePrintBuffer.php new file mode 100644 index 00000000000..d4fdefaf130 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/ImagePrintBuffer.php @@ -0,0 +1,135 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos\PrintBuffers; + +use Exception; +use LogicException; +use Mike42\Escpos\Printer; +use Mike42\Escpos\EscposImage; +use Mike42\Escpos\ImagickEscposImage; + +/** + * This class renders text to small images on-the-fly. It attempts to mimic the + * behaviour of text output, whilst supporting any fonts & character encodings + * which your system can handle. This class currently requires Imagick. + */ +class ImagePrintBuffer implements PrintBuffer +{ + private $printer; + + /** + * @var string|null font to use + */ + private $font; + + private $fontSize; + + public function __construct() + { + if (!EscposImage::isImagickLoaded()) { + throw new Exception("ImagePrintBuffer requires the imagick extension"); + } + $this -> font = null; + $this -> fontSize = 24; + } + + public function flush() + { + if ($this -> printer == null) { + throw new LogicException("Not attached to a printer."); + } + } + + public function getPrinter() + { + return $this -> printer; + } + + public function setPrinter(Printer $printer = null) + { + $this -> printer = $printer; + } + + public function writeText($text) + { + if ($this -> printer == null) { + throw new LogicException("Not attached to a printer."); + } + if ($text == null) { + return; + } + $text = trim($text, "\n"); + /* Create Imagick objects */ + $image = new \Imagick(); + $draw = new \ImagickDraw(); + $color = new \ImagickPixel('#000000'); + $background = new \ImagickPixel('white'); + + /* Create annotation */ + if ($this->font !== null) { + // Allow fallback on defaults as necessary + $draw->setFont($this->font); + } + /* In Arial, size 21 looks good as a substitute for FONT_B, 24 for FONT_A */ + $draw -> setFontSize($this -> fontSize); + $draw -> setFillColor($color); + $draw -> setStrokeAntialias(true); + $draw -> setTextAntialias(true); + $metrics = $image -> queryFontMetrics($draw, $text); + $draw -> annotation(0, $metrics['ascender'], $text); + + /* Create image & draw annotation on it */ + $image -> newImage($metrics['textWidth'], $metrics['textHeight'], $background); + $image -> setImageFormat('png'); + $image -> drawImage($draw); + // debugging if you want to view the images yourself + //$image -> writeImage("test.png"); + + /* Save image */ + $escposImage = new ImagickEscposImage(); + $escposImage -> readImageFromImagick($image); + $size = Printer::IMG_DEFAULT; + $this -> printer -> bitImage($escposImage, $size); + } + + public function writeTextRaw($text) + { + if ($this -> printer == null) { + throw new LogicException("Not attached to a printer."); + } + $this -> printer -> getPrintConnector() -> write($text); + } + + /** + * Set path on disk to TTF font that will be used to render text to image, + * or 'null' to use a default. + * + * ImageMagick will also accept a font name, but this will not port as well + * between systems. + * + * @param string $font + * Font name or a filename + */ + public function setFont($font) + { + $this->font = $font; + } + + /** + * Numeric font size for rendering text to image + */ + public function setFontSize($fontSize) + { + $this->fontSize = $fontSize; + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/PrintBuffer.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/PrintBuffer.php new file mode 100644 index 00000000000..fcad6e9e0bb --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/PrintBuffer.php @@ -0,0 +1,63 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos\PrintBuffers; + +use Mike42\Escpos\Printer; + +/** + * Print buffers manage newlines and character encoding for the target printer. + * They are used as a swappable component: text or image-based output. + * + * - Text output (EscposPrintBuffer) is the fast default, and is recommended for + * most people, as the text output can be more directly manipulated by ESC/POS + * commands. + * - Image output (ImagePrintBuffer) is designed to accept more encodings than the + * physical printer supports, by rendering the text to small images on-the-fly. + * This takes a lot more CPU than sending text, but is necessary for some users. + * - If your use case fits outside these, then a further speed/flexibility trade-off + * can be made by printing directly from generated HTML or PDF. + */ +interface PrintBuffer +{ + /** + * Cause the buffer to send any partial input and wait on a newline. + * If the printer is already on a new line, this does nothing. + */ + public function flush(); + + /** + * Used by Escpos to check if a printer is set. + */ + public function getPrinter(); + + /** + * Used by Escpos to hook up one-to-one link between buffers and printers. + * + * @param Printer|null $printer New printer + */ + public function setPrinter(Printer $printer = null); + + /** + * Accept UTF-8 text for printing. + * + * @param string $text Text to print + */ + public function writeText($text); + + /** + * Accept 8-bit text in the current encoding and add it to the buffer. + * + * @param string $text Text to print, already the target encoding. + */ + public function writeTextRaw($text); +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-OCD-300.ser.z b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-OCD-300.ser.z new file mode 100644 index 00000000000..c0b9adb9d97 Binary files /dev/null and b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-OCD-300.ser.z differ diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-P822D.ser.z b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-P822D.ser.z new file mode 100644 index 00000000000..800630b6d4b Binary files /dev/null and b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-P822D.ser.z differ diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-POS-5890.ser.z b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-POS-5890.ser.z new file mode 100644 index 00000000000..948e135c9b9 Binary files /dev/null and b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-POS-5890.ser.z differ diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-SP2000.ser.z b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-SP2000.ser.z new file mode 100644 index 00000000000..c5ac146d0b5 Binary files /dev/null and b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-SP2000.ser.z differ diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-TEP-200M.ser.z b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-TEP-200M.ser.z new file mode 100644 index 00000000000..3e6b190290e Binary files /dev/null and b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-TEP-200M.ser.z differ diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-default.ser.z b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-default.ser.z new file mode 100644 index 00000000000..3e6b190290e Binary files /dev/null and b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-default.ser.z differ diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-simple.ser.z b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-simple.ser.z new file mode 100644 index 00000000000..ca1c7bcab3a Binary files /dev/null and b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintBuffers/cache/Characters-simple.ser.z differ diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/ApiPrintConnector.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/ApiPrintConnector.php new file mode 100644 index 00000000000..893a4858c8e --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/ApiPrintConnector.php @@ -0,0 +1,102 @@ +httpClient = new Client(['base_uri' => $host]); + $this->printerId = $printerId; + $this->apiToken = $apiToken; + + $this->stream = ''; + } + + /** + * Print connectors should cause a NOTICE if they are deconstructed + * when they have not been finalized. + */ + public function __destruct() + { + if (! empty($this->stream)) { + trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE); + } + } + + /** + * Finish using this print connector (close file, socket, send + * accumulated output, etc). + */ + public function finalize() + { + /** @var Request $request */ + $request = $this->httpClient->post( + 'printers/'.$this->printerId.'/print?api_token='.$this->apiToken, + null, + $this->stream + ); + + /** @var Response $response */ + $response = $request->send(); + + if (! $response->isSuccessful()) { + throw new Exception( + sprintf('Failed to print. API returned "%s: %s"', $response->getStatusCode(), $response->getReasonPhrase()) + ); + } + + $this->stream = ''; + } + + /** + * Read data from the printer. + * + * @param string $len Length of data to read. + * @return string Data read from the printer. + */ + public function read($len) + { + return $this->stream; + } + + /** + * Write data to the print connector. + * + * @param string $data The data to write + */ + public function write($data) + { + $this->stream .= $data; + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/CupsPrintConnector.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/CupsPrintConnector.php new file mode 100644 index 00000000000..497887f37cd --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/CupsPrintConnector.php @@ -0,0 +1,182 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos\PrintConnectors; + +use Exception; +use BadMethodCallException; + +/** + * Print connector that passes print data to CUPS print commands. + * Your printer mut be installed on the local CUPS instance to use this connector. + */ +class CupsPrintConnector implements PrintConnector +{ + + /** + * @var array $buffer + * Buffer of accumilated data. + */ + private $buffer; + + /** + * + * @var string $printerName + * The name of the target printer. + */ + private $printerName; + + /** + * Construct new CUPS print connector. + * + * @param string $dest + * The CUPS printer name to print to. This must be loaded using a raw driver. + * @throws BadMethodCallException + */ + public function __construct($dest) + { + $valid = $this->getLocalPrinters(); + if (count($valid) == 0) { + throw new BadMethodCallException("You do not have any printers installed on " . + "this system via CUPS. Check 'lpr -a'."); + } + + if (array_search($dest, $valid, true) === false) { + throw new BadMethodCallException("'$dest' is not a printer on this system. " . + "Printers are: [" . implode(", ", $valid) . "]"); + } + $this->buffer = array (); + $this->printerName = $dest; + } + + /** + * Cause a NOTICE if deconstructed before the job was printed. + */ + public function __destruct() + { + if ($this->buffer !== null) { + trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE); + } + } + + /** + * Send job to printer. + */ + public function finalize() + { + $data = implode($this->buffer); + $this->buffer = null; + + // Build command to work on data + $tmpfname = tempnam(sys_get_temp_dir(), 'print-'); + file_put_contents($tmpfname, $data); + $cmd = sprintf( + "lp -d %s %s", + escapeshellarg($this->printerName), + escapeshellarg($tmpfname) + ); + try { + $this->getCmdOutput($cmd); + } catch (Exception $e) { + unlink($tmpfname); + throw $e; + } + unlink($tmpfname); + } + + /** + * Run a command and throw an exception if it fails, or return the output if it works. + * (Basically exec() with good error handling) + * + * @param string $cmd + * Command to run + */ + protected function getCmdOutput($cmd) + { + $descriptors = array ( + 1 => array ( + "pipe", + "w" + ), + 2 => array ( + "pipe", + "w" + ) + ); + $process = proc_open($cmd, $descriptors, $fd); + if (! is_resource($process)) { + throw new Exception("Command '$cmd' failed to start."); + } + /* Read stdout */ + $outputStr = stream_get_contents($fd [1]); + fclose($fd [1]); + /* Read stderr */ + $errorStr = stream_get_contents($fd [2]); + fclose($fd [2]); + /* Finish up */ + $retval = proc_close($process); + if ($retval != 0) { + throw new Exception("Command $cmd failed: $errorStr"); + } + return $outputStr; + } + + /** + * Read data from the printer. + * + * @param string $len Length of data to read. + * @return Data read from the printer, or false where reading is not possible. + */ + public function read($len) + { + return false; + } + + /** + * @param string $data + */ + public function write($data) + { + $this->buffer [] = $data; + } + + /** + * Load a list of CUPS printers. + * + * @return array A list of printer names installed on this system. Any item + * on this list is valid for constructing a printer. + */ + protected function getLocalPrinters() + { + $outpStr = $this->getCmdOutput("lpstat -a"); + $outpLines = explode("\n", trim($outpStr)); + foreach ($outpLines as $line) { + $ret [] = $this->chopLpstatLine($line); + } + return $ret; + } + + /** + * Get the item before the first space in a string + * + * @param string $line + * @return string the string, up to the first space, or the whole string if it contains no spaces. + */ + private function chopLpstatLine($line) + { + if (($pos = strpos($line, " ")) === false) { + return $line; + } else { + return substr($line, 0, $pos); + } + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php new file mode 100644 index 00000000000..b376cd87d83 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php @@ -0,0 +1,78 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos\PrintConnectors; + +/** + * Print connector that writes to nowhere, but allows the user to retrieve the + * buffered data. Used for testing. + */ +final class DummyPrintConnector implements PrintConnector +{ + /** + * @var array $buffer + * Buffer of accumilated data. + */ + private $buffer; + + /** + * @var string data which the printer will provide on next read + */ + private $readData; + + /** + * Create new print connector + */ + public function __construct() + { + $this -> buffer = []; + } + + public function clear() + { + $this -> buffer = []; + } + + public function __destruct() + { + if ($this -> buffer !== null) { + trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE); + } + } + + public function finalize() + { + $this -> buffer = null; + } + + /** + * @return string Get the accumulated data that has been sent to this buffer. + */ + public function getData() + { + return implode($this -> buffer); + } + + /** + * {@inheritDoc} + * @see PrintConnector::read() + */ + public function read($len) + { + return $len >= strlen($this -> readData) ? $this -> readData : substr($this -> readData, 0, $len); + } + + public function write($data) + { + $this -> buffer[] = $data; + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/FilePrintConnector.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/FilePrintConnector.php new file mode 100644 index 00000000000..ca44ad0ad7e --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/FilePrintConnector.php @@ -0,0 +1,82 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos\PrintConnectors; + +use Exception; + +/** + * PrintConnector for passing print data to a file. + */ +class FilePrintConnector implements PrintConnector +{ + /** + * @var resource $fp + * The file pointer to send data to. + */ + protected $fp; + + /** + * Construct new connector, given a filename + * + * @param string $filename + */ + public function __construct($filename) + { + $this -> fp = fopen($filename, "wb+"); + if ($this -> fp === false) { + throw new Exception("Cannot initialise FilePrintConnector."); + } + } + + public function __destruct() + { + if ($this -> fp !== false) { + trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE); + } + } + + /** + * Close file pointer + */ + public function finalize() + { + if ($this -> fp !== false) { + fclose($this -> fp); + $this -> fp = false; + } + } + + /* (non-PHPdoc) + * @see PrintConnector::read() + */ + public function read($len) + { + if ($this -> fp === false) { + throw new Exception("PrintConnector has been closed, cannot read input."); + } + return fread($this -> fp, $len); + } + + /** + * Write data to the file + * + * @param string $data + */ + public function write($data) + { + if ($this -> fp === false) { + throw new Exception("PrintConnector has been closed, cannot send output."); + } + fwrite($this -> fp, $data); + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/NetworkPrintConnector.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/NetworkPrintConnector.php new file mode 100644 index 00000000000..10aa6640a01 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/NetworkPrintConnector.php @@ -0,0 +1,41 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos\PrintConnectors; + +use Exception; + +/** + * PrintConnector for directly opening a network socket to a printer to send it commands. + */ +class NetworkPrintConnector extends FilePrintConnector +{ + /** + * Construct a new NetworkPrintConnector + * + * @param string $ip IP address or hostname to use. + * @param string $port The port number to connect on. + * @param string $timeout The connection timeout, in seconds. + * @throws Exception Where the socket cannot be opened. + */ + public function __construct($ip, $port = "9100", $timeout = false) + { + // Default to 60 if default_socket_timeout isn't defined in the ini + $defaultSocketTimeout = ini_get("default_socket_timeout") ?: 60; + $timeout = $timeout ?: $defaultSocketTimeout; + + $this -> fp = @fsockopen($ip, $port, $errno, $errstr, $timeout); + if ($this -> fp === false) { + throw new Exception("Cannot initialise NetworkPrintConnector: " . $errstr); + } + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/PrintConnector.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/PrintConnector.php new file mode 100644 index 00000000000..4198dbc133b --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/PrintConnector.php @@ -0,0 +1,47 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos\PrintConnectors; + +/** + * Interface passed to Escpos class for receiving print data. Print connectors + * are responsible for transporting this to the actual printer. + */ +interface PrintConnector +{ + /** + * Print connectors should cause a NOTICE if they are deconstructed + * when they have not been finalized. + */ + public function __destruct(); + + /** + * Finish using this print connector (close file, socket, send + * accumulated output, etc). + */ + public function finalize(); + + /** + * Read data from the printer. + * + * @param string $len Length of data to read. + * @return Data read from the printer, or false where reading is not possible. + */ + public function read($len); + + /** + * Write data to the print connector. + * + * @param string $data The data to write + */ + public function write($data); +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/RawbtPrintConnector.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/RawbtPrintConnector.php new file mode 100644 index 00000000000..622f7263d9e --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/RawbtPrintConnector.php @@ -0,0 +1,81 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos\PrintConnectors; + +/** + * Print connector for android RawBT application + * https://play.google.com/store/apps/details?id=ru.a402d.rawbtprinter + */ +final class RawbtPrintConnector implements PrintConnector +{ + /** + * @var array $buffer + * Buffer of accumilated data. + */ + private $buffer; + + /** + * @var string data which the printer will provide on next read + */ + private $readData; + + /** + * Create new print connector + */ + public function __construct() + { + ob_start(); + $this->buffer = []; + } + + public function clear() + { + $this->buffer = []; + } + + public function __destruct() + { + if ($this->buffer !== null) { + trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE); + } + } + + public function finalize() + { + ob_end_clean(); + echo "intent:base64," . base64_encode($this->getData()) . "#Intent;scheme=rawbt;package=ru.a402d.rawbtprinter;end;"; + $this->buffer = null; + } + + /** + * @return string Get the accumulated data that has been sent to this buffer. + */ + public function getData() + { + return implode($this->buffer); + } + + /** + * {@inheritDoc} + * @see PrintConnector::read() + */ + public function read($len) + { + return $len >= strlen($this->readData) ? $this->readData : substr($this->readData, 0, $len); + } + + public function write($data) + { + $this->buffer[] = $data; + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/UriPrintConnector.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/UriPrintConnector.php new file mode 100644 index 00000000000..c51d2bf3350 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/UriPrintConnector.php @@ -0,0 +1,44 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos\PrintConnectors; + +class UriPrintConnector +{ + const URI_ASSEMBLER_PATTERN = "~^(.+):/{2}(.+?)(?::(\d{1,4}))?$~"; + + public static function get($uri) + { + // Parse URI + $is_uri = preg_match(self::URI_ASSEMBLER_PATTERN, $uri, $uri_parts); + if ($is_uri !== 1) { + throw new \InvalidArgumentException("Malformed connector URI: {$uri}"); + } + // Extract parts + $protocol = $uri_parts[1]; + $printer = $uri_parts[2]; + $port = isset($uri_parts[3]) ? $uri_parts[3] : 9100; + // Initialise the most applicable print connector + switch ($protocol) { + case "file": + return new FilePrintConnector($printer); + case "tcp": + return new NetworkPrintConnector($printer, $port); + case "smb": + return new WindowsPrintConnector($uri); + } + // Fallthrough + throw new \InvalidArgumentException("URI sheme is not supported: {$protocol}://"); + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php new file mode 100644 index 00000000000..9bab87cddb8 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php @@ -0,0 +1,391 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos\PrintConnectors; + +use Exception; +use BadMethodCallException; + +/** + * Connector for sending print jobs to + * - local ports on windows (COM1, LPT1, etc) + * - shared (SMB) printers from any platform (smb://server/foo) + * For USB printers or other ports, the trick is to share the printer with a + * generic text driver, then connect to the shared printer locally. + */ +class WindowsPrintConnector implements PrintConnector +{ + /** + * @var array $buffer + * Accumulated lines of output for later use. + */ + private $buffer; + + /** + * @var string $hostname + * The hostname of the target machine, or null if this is a local connection. + */ + private $hostname; + + /** + * @var boolean $isLocal + * True if a port is being used directly (must be Windows), false if network shares will be used. + */ + private $isLocal; + + /** + * @var int $platform + * Platform we're running on, for selecting different commands. See PLATFORM_* constants. + */ + private $platform; + + /** + * @var string $printerName + * The name of the target printer (eg "Foo Printer") or port ("COM1", "LPT1"). + */ + private $printerName; + + /** + * @var string $userName + * Login name for network printer, or null if not using authentication. + */ + private $userName; + + /** + * @var string $userPassword + * Password for network printer, or null if no password is required. + */ + private $userPassword; + + /** + * @var string $workgroup + * Workgroup that the printer is located on + */ + private $workgroup; + + /** + * Represents Linux + */ + const PLATFORM_LINUX = 0; + + /** + * Represents Mac + */ + const PLATFORM_MAC = 1; + + /** + * Represents Windows + */ + const PLATFORM_WIN = 2; + + /** + * Valid local ports. + */ + const REGEX_LOCAL = "/^(LPT\d|COM\d)$/"; + + /** + * Valid printer name. + */ + const REGEX_PRINTERNAME = "/^[\d\w-]+(\s[\d\w-]+)*$/"; + + /** + * Valid smb:// URI containing hostname & printer with optional user & optional password only. + */ + const REGEX_SMB = "/^smb:\/\/([\s\d\w-]+(:[\s\d\w+-]+)?@)?([\d\w-]+\.)*[\d\w-]+\/([\d\w-]+\/)?[\d\w-]+(\s[\d\w-]+)*$/"; + + /** + * @param string $dest + * @throws BadMethodCallException + */ + public function __construct($dest) + { + $this -> platform = $this -> getCurrentPlatform(); + $this -> isLocal = false; + $this -> buffer = null; + $this -> userName = null; + $this -> userPassword = null; + $this -> workgroup = null; + if (preg_match(self::REGEX_LOCAL, $dest) == 1) { + // Straight to LPT1, COM1 or other local port. Allowed only if we are actually on windows. + if ($this -> platform !== self::PLATFORM_WIN) { + throw new BadMethodCallException("WindowsPrintConnector can only be " . + "used to print to a local printer ('".$dest."') on a Windows computer."); + } + $this -> isLocal = true; + $this -> hostname = null; + $this -> printerName = $dest; + } elseif (preg_match(self::REGEX_SMB, $dest) == 1) { + // Connect to samba share, eg smb://host/printer + $part = parse_url($dest); + $this -> hostname = $part['host']; + /* Printer name and optional workgroup */ + $path = ltrim($part['path'], '/'); + if (strpos($path, "/") !== false) { + $pathPart = explode("/", $path); + $this -> workgroup = $pathPart[0]; + $this -> printerName = $pathPart[1]; + } else { + $this -> printerName = $path; + } + /* Username and password if set */ + if (isset($part['user'])) { + $this -> userName = $part['user']; + if (isset($part['pass'])) { + $this -> userPassword = $part['pass']; + } + } + } elseif (preg_match(self::REGEX_PRINTERNAME, $dest) == 1) { + // Just got a printer name. Assume it's on the current computer. + $hostname = gethostname(); + if (!$hostname) { + $hostname = "localhost"; + } + $this -> hostname = $hostname; + $this -> printerName = $dest; + } else { + throw new BadMethodCallException("Printer '" . $dest . "' is not a valid " . + "printer name. Use local port (LPT1, COM1, etc) or smb://computer/printer notation."); + } + $this -> buffer = []; + } + + public function __destruct() + { + if ($this -> buffer !== null) { + trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE); + } + } + + public function finalize() + { + $data = implode($this -> buffer); + $this -> buffer = null; + if ($this -> platform == self::PLATFORM_WIN) { + $this -> finalizeWin($data); + } elseif ($this -> platform == self::PLATFORM_LINUX) { + $this -> finalizeLinux($data); + } else { + $this -> finalizeMac($data); + } + } + + /** + * Send job to printer -- platform-specific Linux code. + * + * @param string $data Print data + * @throws Exception + */ + protected function finalizeLinux($data) + { + /* Non-Windows samba printing */ + $device = "//" . $this -> hostname . "/" . $this -> printerName; + if ($this -> userName !== null) { + $user = ($this -> workgroup != null ? ($this -> workgroup . "\\") : "") . $this -> userName; + if ($this -> userPassword == null) { + // No password + $command = sprintf( + "smbclient %s -U %s -c %s -N -m SMB2", + escapeshellarg($device), + escapeshellarg($user), + escapeshellarg("print -") + ); + $redactedCommand = $command; + } else { + // With password + $command = sprintf( + "smbclient %s %s -U %s -c %s -m SMB2", + escapeshellarg($device), + escapeshellarg($this -> userPassword), + escapeshellarg($user), + escapeshellarg("print -") + ); + $redactedCommand = sprintf( + "smbclient %s %s -U %s -c %s -m SMB2", + escapeshellarg($device), + escapeshellarg("*****"), + escapeshellarg($user), + escapeshellarg("print -") + ); + } + } else { + // No authentication information at all + $command = sprintf( + "smbclient %s -c %s -N -m SMB2", + escapeshellarg($device), + escapeshellarg("print -") + ); + $redactedCommand = $command; + } + $retval = $this -> runCommand($command, $outputStr, $errorStr, $data); + if ($retval != 0) { + throw new Exception("Failed to print. Command \"$redactedCommand\" " . + "failed with exit code $retval: " . trim($errorStr) . trim($outputStr)); + } + } + + /** + * Send job to printer -- platform-specific Mac code. + * + * @param string $data Print data + * @throws Exception + */ + protected function finalizeMac($data) + { + throw new Exception("Mac printing not implemented."); + } + + /** + * Send data to printer -- platform-specific Windows code. + * + * @param string $data + */ + protected function finalizeWin($data) + { + /* Windows-friendly printing of all sorts */ + if (!$this -> isLocal) { + /* Networked printing */ + $device = "\\\\" . $this -> hostname . "\\" . $this -> printerName; + if ($this -> userName !== null) { + /* Log in */ + $user = "/user:" . ($this -> workgroup != null ? ($this -> workgroup . "\\") : "") . $this -> userName; + if ($this -> userPassword == null) { + $command = sprintf( + "net use %s %s", + escapeshellarg($device), + escapeshellarg($user) + ); + $redactedCommand = $command; + } else { + $command = sprintf( + "net use %s %s %s", + escapeshellarg($device), + escapeshellarg($user), + escapeshellarg($this -> userPassword) + ); + $redactedCommand = sprintf( + "net use %s %s %s", + escapeshellarg($device), + escapeshellarg($user), + escapeshellarg("*****") + ); + } + $retval = $this -> runCommand($command, $outputStr, $errorStr); + if ($retval != 0) { + throw new Exception("Failed to print. Command \"$redactedCommand\" " . + "failed with exit code $retval: " . trim($errorStr)); + } + } + /* Final print-out */ + $filename = tempnam(sys_get_temp_dir(), "escpos"); + file_put_contents($filename, $data); + if (!$this -> runCopy($filename, $device)) { + throw new Exception("Failed to copy file to printer"); + } + unlink($filename); + } else { + /* Drop data straight on the printer */ + if (!$this -> runWrite($data, $this -> printerName)) { + throw new Exception("Failed to write file to printer at " . $this -> printerName); + } + } + } + + /** + * @return string Current platform. Separated out for testing purposes. + */ + protected function getCurrentPlatform() + { + if (PHP_OS == "WINNT") { + return self::PLATFORM_WIN; + } + if (PHP_OS == "Darwin") { + return self::PLATFORM_MAC; + } + return self::PLATFORM_LINUX; + } + + /* (non-PHPdoc) + * @see PrintConnector::read() + */ + public function read($len) + { + /* Two-way communication is not supported */ + return false; + } + + /** + * Run a command, pass it data, and retrieve its return value, standard output, and standard error. + * + * @param string $command the command to run. + * @param string $outputStr variable to fill with standard output. + * @param string $errorStr variable to fill with standard error. + * @param string $inputStr text to pass to the command's standard input (optional). + * @return number + */ + protected function runCommand($command, &$outputStr, &$errorStr, $inputStr = null) + { + $descriptors = [ + 0 => ["pipe", "r"], + 1 => ["pipe", "w"], + 2 => ["pipe", "w"], + ]; + $process = proc_open($command, $descriptors, $fd); + if (is_resource($process)) { + /* Write to input */ + if ($inputStr !== null) { + fwrite($fd[0], $inputStr); + } + fclose($fd[0]); + /* Read stdout */ + $outputStr = stream_get_contents($fd[1]); + fclose($fd[1]); + /* Read stderr */ + $errorStr = stream_get_contents($fd[2]); + fclose($fd[2]); + /* Finish up */ + $retval = proc_close($process); + return $retval; + } else { + /* Method calling this should notice a non-zero exit and print an error */ + return -1; + } + } + + /** + * Copy a file. Separated out so that nothing is actually printed during test runs. + * + * @param string $from Source file + * @param string $to Destination file + * @return boolean True if copy was successful, false otherwise + */ + protected function runCopy($from, $to) + { + return copy($from, $to); + } + + /** + * Write data to a file. Separated out so that nothing is actually printed during test runs. + * + * @param string $data Data to print + * @param string $filename Destination file + * @return boolean True if write was successful, false otherwise + */ + protected function runWrite($data, $filename) + { + return file_put_contents($filename, $data) !== false; + } + + public function write($data) + { + $this -> buffer[] = $data; + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/Printer.php b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/Printer.php new file mode 100644 index 00000000000..753d2ea8ad3 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/Printer.php @@ -0,0 +1,1217 @@ +, + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + +namespace Mike42\Escpos; + +use Exception; +use InvalidArgumentException; +use Mike42\Escpos\PrintBuffers\PrintBuffer; +use Mike42\Escpos\PrintBuffers\EscposPrintBuffer; +use Mike42\Escpos\PrintConnectors\PrintConnector; +use Mike42\Escpos\CapabilityProfile; + +/** + * Main class for ESC/POS code generation + */ +class Printer +{ + /** + * ASCII null control character + */ + const NUL = "\x00"; + + /** + * ASCII linefeed control character + */ + const LF = "\x0a"; + + /** + * ASCII escape control character + */ + const ESC = "\x1b"; + + /** + * ASCII form separator control character + */ + const FS = "\x1c"; + + /** + * ASCII form feed control character + */ + const FF = "\x0c"; + + /** + * ASCII group separator control character + */ + const GS = "\x1d"; + + /** + * ASCII data link escape control character + */ + const DLE = "\x10"; + + /** + * ASCII end of transmission control character + */ + const EOT = "\x04"; + + /** + * Indicates UPC-A barcode when used with Printer::barcode + */ + const BARCODE_UPCA = 65; + + /** + * Indicates UPC-E barcode when used with Printer::barcode + */ + const BARCODE_UPCE = 66; + + /** + * Indicates JAN13 barcode when used with Printer::barcode + */ + const BARCODE_JAN13 = 67; + + /** + * Indicates JAN8 barcode when used with Printer::barcode + */ + const BARCODE_JAN8 = 68; + + /** + * Indicates CODE39 barcode when used with Printer::barcode + */ + const BARCODE_CODE39 = 69; + + /** + * Indicates ITF barcode when used with Printer::barcode + */ + const BARCODE_ITF = 70; + + /** + * Indicates CODABAR barcode when used with Printer::barcode + */ + const BARCODE_CODABAR = 71; + + /** + * Indicates CODE93 barcode when used with Printer::barcode + */ + const BARCODE_CODE93 = 72; + + /** + * Indicates CODE128 barcode when used with Printer::barcode + */ + const BARCODE_CODE128 = 73; + + /** + * Indicates that HRI (human-readable interpretation) text should not be + * printed, when used with Printer::setBarcodeTextPosition + */ + const BARCODE_TEXT_NONE = 0; + + /** + * Indicates that HRI (human-readable interpretation) text should be printed + * above a barcode, when used with Printer::setBarcodeTextPosition + */ + const BARCODE_TEXT_ABOVE = 1; + + /** + * Indicates that HRI (human-readable interpretation) text should be printed + * below a barcode, when used with Printer::setBarcodeTextPosition + */ + const BARCODE_TEXT_BELOW = 2; + + /** + * Use the first color (usually black), when used with Printer::setColor + */ + const COLOR_1 = 0; + + /** + * Use the second color (usually red or blue), when used with Printer::setColor + */ + const COLOR_2 = 1; + + /** + * Make a full cut, when used with Printer::cut + */ + const CUT_FULL = 65; + + /** + * Make a partial cut, when used with Printer::cut + */ + const CUT_PARTIAL = 66; + + /** + * Use Font A, when used with Printer::setFont + */ + const FONT_A = 0; + + /** + * Use Font B, when used with Printer::setFont + */ + const FONT_B = 1; + + /** + * Use Font C, when used with Printer::setFont + */ + const FONT_C = 2; + + /** + * Use default (high density) image size, when used with Printer::graphics, + * Printer::bitImage or Printer::bitImageColumnFormat + */ + const IMG_DEFAULT = 0; + + /** + * Use lower horizontal density for image printing, when used with Printer::graphics, + * Printer::bitImage or Printer::bitImageColumnFormat + */ + const IMG_DOUBLE_WIDTH = 1; + + /** + * Use lower vertical density for image printing, when used with Printer::graphics, + * Printer::bitImage or Printer::bitImageColumnFormat + */ + const IMG_DOUBLE_HEIGHT = 2; + + /** + * Align text to the left, when used with Printer::setJustification + */ + const JUSTIFY_LEFT = 0; + + /** + * Center text, when used with Printer::setJustification + */ + const JUSTIFY_CENTER = 1; + + /** + * Align text to the right, when used with Printer::setJustification + */ + const JUSTIFY_RIGHT = 2; + + /** + * Use Font A, when used with Printer::selectPrintMode + */ + const MODE_FONT_A = 0; + + /** + * Use Font B, when used with Printer::selectPrintMode + */ + const MODE_FONT_B = 1; + + /** + * Use text emphasis, when used with Printer::selectPrintMode + */ + const MODE_EMPHASIZED = 8; + + /** + * Use double height text, when used with Printer::selectPrintMode + */ + const MODE_DOUBLE_HEIGHT = 16; + + /** + * Use double width text, when used with Printer::selectPrintMode + */ + const MODE_DOUBLE_WIDTH = 32; + + /** + * Underline text, when used with Printer::selectPrintMode + */ + const MODE_UNDERLINE = 128; + + /** + * Indicates standard PDF417 code + */ + const PDF417_STANDARD = 0; + + /** + * Indicates truncated PDF417 code + */ + const PDF417_TRUNCATED = 1; + + /** + * Indicates error correction level L when used with Printer::qrCode + */ + const QR_ECLEVEL_L = 0; + + /** + * Indicates error correction level M when used with Printer::qrCode + */ + const QR_ECLEVEL_M = 1; + + /** + * Indicates error correction level Q when used with Printer::qrCode + */ + const QR_ECLEVEL_Q = 2; + + /** + * Indicates error correction level H when used with Printer::qrCode + */ + const QR_ECLEVEL_H = 3; + + /** + * Indicates QR model 1 when used with Printer::qrCode + */ + const QR_MODEL_1 = 1; + + /** + * Indicates QR model 2 when used with Printer::qrCode + */ + const QR_MODEL_2 = 2; + + /** + * Indicates micro QR code when used with Printer::qrCode + */ + const QR_MICRO = 3; + + /** + * Indicates a request for printer status when used with + * Printer::getPrinterStatus (experimental) + */ + const STATUS_PRINTER = 1; + + /** + * Indicates a request for printer offline cause when used with + * Printer::getPrinterStatus (experimental) + */ + const STATUS_OFFLINE_CAUSE = 2; + + /** + * Indicates a request for error cause when used with Printer::getPrinterStatus + * (experimental) + */ + const STATUS_ERROR_CAUSE = 3; + + /** + * Indicates a request for error cause when used with Printer::getPrinterStatus + * (experimental) + */ + const STATUS_PAPER_ROLL = 4; + + /** + * Indicates a request for ink A status when used with Printer::getPrinterStatus + * (experimental) + */ + const STATUS_INK_A = 7; + + /** + * Indicates a request for ink B status when used with Printer::getPrinterStatus + * (experimental) + */ + const STATUS_INK_B = 6; + + /** + * Indicates a request for peeler status when used with Printer::getPrinterStatus + * (experimental) + */ + const STATUS_PEELER = 8; + + /** + * Indicates no underline when used with Printer::setUnderline + */ + const UNDERLINE_NONE = 0; + + /** + * Indicates single underline when used with Printer::setUnderline + */ + const UNDERLINE_SINGLE = 1; + + /** + * Indicates double underline when used with Printer::setUnderline + */ + const UNDERLINE_DOUBLE = 2; + + /** + * @var PrintBuffer|null $buffer + * The printer's output buffer. + */ + protected $buffer; + + /** + * @var PrintConnector $connector + * Connector showing how to print to this printer + */ + protected $connector; + + /** + * @var CapabilityProfile $profile + * Profile showing supported features for this printer + */ + protected $profile; + + /** + * @var int $characterTable + * Current character code table + */ + protected $characterTable; + + /** + * Construct a new print object + * + * @param PrintConnector $connector The PrintConnector to send data to. If not set, output is sent to standard output. + * @param CapabilityProfile|null $profile Supported features of this printer. If not set, the "default" CapabilityProfile will be used, which is suitable for Epson printers. + * @throws InvalidArgumentException + */ + public function __construct(PrintConnector $connector, CapabilityProfile $profile = null) + { + /* Set connector */ + $this -> connector = $connector; + + /* Set capability profile */ + if ($profile === null) { + $profile = CapabilityProfile::load('default'); + } + $this -> profile = $profile; + /* Set buffer */ + $buffer = new EscposPrintBuffer(); + $this -> buffer = null; + $this -> setPrintBuffer($buffer); + $this -> initialize(); + } + + /** + * Print a barcode. + * + * @param string $content The information to encode. + * @param int $type The barcode standard to output. Supported values are + * `Printer::BARCODE_UPCA`, `Printer::BARCODE_UPCE`, `Printer::BARCODE_JAN13`, + * `Printer::BARCODE_JAN8`, `Printer::BARCODE_CODE39`, `Printer::BARCODE_ITF`, + * `Printer::BARCODE_CODABAR`, `Printer::BARCODE_CODE93`, and `Printer::BARCODE_CODE128`. + * If not specified, `Printer::BARCODE_CODE39` will be used. Note that some + * barcode formats only support specific lengths or sets of characters, and that + * available barcode types vary between printers. + * @throws InvalidArgumentException Where the length or characters used in $content is invalid for the requested barcode format. + */ + public function barcode($content, $type = Printer::BARCODE_CODE39) + { + /* Validate input */ + self::validateInteger($type, 65, 73, __FUNCTION__, "Barcode type"); + $len = strlen($content); + switch ($type) { + case self::BARCODE_UPCA: + self::validateInteger($len, 11, 12, __FUNCTION__, "UPCA barcode content length"); + self::validateStringRegex($content, __FUNCTION__, "/^[0-9]{11,12}$/", "UPCA barcode content"); + break; + case self::BARCODE_UPCE: + self::validateIntegerMulti($len, [[6, 8], [11, 12]], __FUNCTION__, "UPCE barcode content length"); + self::validateStringRegex($content, __FUNCTION__, "/^([0-9]{6,8}|[0-9]{11,12})$/", "UPCE barcode content"); + break; + case self::BARCODE_JAN13: + self::validateInteger($len, 12, 13, __FUNCTION__, "JAN13 barcode content length"); + self::validateStringRegex($content, __FUNCTION__, "/^[0-9]{12,13}$/", "JAN13 barcode content"); + break; + case self::BARCODE_JAN8: + self::validateInteger($len, 7, 8, __FUNCTION__, "JAN8 barcode content length"); + self::validateStringRegex($content, __FUNCTION__, "/^[0-9]{7,8}$/", "JAN8 barcode content"); + break; + case self::BARCODE_CODE39: + self::validateInteger($len, 1, 255, __FUNCTION__, "CODE39 barcode content length"); // 255 is a limitation of the "function b" command, not the barcode format. + self::validateStringRegex($content, __FUNCTION__, "/^([0-9A-Z \$\%\+\-\.\/]+|\*[0-9A-Z \$\%\+\-\.\/]+\*)$/", "CODE39 barcode content"); + break; + case self::BARCODE_ITF: + self::validateInteger($len, 2, 255, __FUNCTION__, "ITF barcode content length"); // 255 is a limitation of the "function b" command, not the barcode format. + self::validateStringRegex($content, __FUNCTION__, "/^([0-9]{2})+$/", "ITF barcode content"); + break; + case self::BARCODE_CODABAR: + self::validateInteger($len, 1, 255, __FUNCTION__, "Codabar barcode content length"); // 255 is a limitation of the "function b" command, not the barcode format. + self::validateStringRegex($content, __FUNCTION__, "/^[A-Da-d][0-9\$\+\-\.\/\:]+[A-Da-d]$/", "Codabar barcode content"); + break; + case self::BARCODE_CODE93: + self::validateInteger($len, 1, 255, __FUNCTION__, "Code93 barcode content length"); // 255 is a limitation of the "function b" command, not the barcode format. + self::validateStringRegex($content, __FUNCTION__, "/^[\\x00-\\x7F]+$/", "Code93 barcode content"); + break; + case self::BARCODE_CODE128: + self::validateInteger($len, 1, 255, __FUNCTION__, "Code128 barcode content length"); // 255 is a limitation of the "function b" command, not the barcode format. + // The CODE128 encoder is quite complex, so only a very basic header-check is applied here. + self::validateStringRegex($content, __FUNCTION__, "/^\{[A-C][\\x00-\\x7F]+$/", "Code128 barcode content"); + break; + } + if (!$this -> profile -> getSupportsBarcodeB()) { + // A simpler barcode command which supports fewer codes + self::validateInteger($type, 65, 71, __FUNCTION__); + $this -> connector -> write(self::GS . "k" . chr($type - 65) . $content . self::NUL); + return; + } + // More advanced function B, used in preference + $this -> connector -> write(self::GS . "k" . chr($type) . chr(strlen($content)) . $content); + } + + /** + * Print an image, using the older "bit image" command. This creates padding on the right of the image, + * if its width is not divisible by 8. + * + * Should only be used if your printer does not support the graphics() command. + * See also bitImageColumnFormat(). + * + * @param EscposImage $img The image to print + * @param int $size Size modifier for the image. Must be either `Printer::IMG_DEFAULT` + * (default), or any combination of the `Printer::IMG_DOUBLE_HEIGHT` and + * `Printer::IMG_DOUBLE_WIDTH` flags. + */ + public function bitImage(EscposImage $img, $size = Printer::IMG_DEFAULT) + { + self::validateInteger($size, 0, 3, __FUNCTION__); + $rasterData = $img -> toRasterFormat(); + $header = Printer::dataHeader([$img -> getWidthBytes(), $img -> getHeight()], true); + $this -> connector -> write(self::GS . "v0" . chr($size) . $header); + $this -> connector -> write($rasterData); + } + + /** + * Print an image, using the older "bit image" command in column format. + * + * Should only be used if your printer does not support the graphics() or + * bitImage() commands. + * + * @param EscposImage $img The image to print + * @param int $size Size modifier for the image. Must be either `Printer::IMG_DEFAULT` + * (default), or any combination of the `Printer::IMG_DOUBLE_HEIGHT` and + * `Printer::IMG_DOUBLE_WIDTH` flags. + */ + public function bitImageColumnFormat(EscposImage $img, $size = Printer::IMG_DEFAULT) + { + $highDensityVertical = ! (($size & self::IMG_DOUBLE_HEIGHT) == Printer::IMG_DOUBLE_HEIGHT); + $highDensityHorizontal = ! (($size & self::IMG_DOUBLE_WIDTH) == Printer::IMG_DOUBLE_WIDTH); + // Experimental column format printing + // This feature is not yet complete and may produce unpredictable results. + $this -> setLineSpacing(16); // 16-dot line spacing. This is the correct value on both TM-T20 and TM-U220 + // Header and density code (0, 1, 32, 33) re-used for every line + $densityCode = ($highDensityHorizontal ? 1 : 0) + ($highDensityVertical ? 32 : 0); + $colFormatData = $img -> toColumnFormat($highDensityVertical); + $header = Printer::dataHeader([$img -> getWidth()], true); + foreach ($colFormatData as $line) { + // Print each line, double density etc for printing are set here also + $this -> connector -> write(self::ESC . "*" . chr($densityCode) . $header . $line); + $this -> feed(); + // sleep(0.1); // Reduces the amount of trouble that a TM-U220 has keeping up with large images + } + $this -> setLineSpacing(); // Revert to default line spacing + } + + /** + * Close the underlying buffer. With some connectors, the + * job will not actually be sent to the printer until this is called. + */ + public function close() + { + $this -> connector -> finalize(); + } + + /** + * Cut the paper. + * + * @param int $mode Cut mode, either Printer::CUT_FULL or Printer::CUT_PARTIAL. If not specified, `Printer::CUT_FULL` will be used. + * @param int $lines Number of lines to feed + */ + public function cut($mode = Printer::CUT_FULL, $lines = 3) + { + // TODO validation on cut() inputs + $this -> connector -> write(self::GS . "V" . chr($mode) . chr($lines)); + } + + /** + * Print and feed line / Print and feed n lines. + * + * @param int $lines Number of lines to feed + */ + public function feed($lines = 1) + { + self::validateInteger($lines, 1, 255, __FUNCTION__); + if ($lines <= 1) { + $this -> connector -> write(self::LF); + } else { + $this -> connector -> write(self::ESC . "d" . chr($lines)); + } + } + + /** + * Some printers require a form feed to release the paper. On most printers, this + * command is only useful in page mode, which is not implemented in this driver. + */ + public function feedForm() + { + $this -> connector -> write(self::FF); + } + + /** + * Some slip printers require `ESC q` sequence to release the paper. + */ + public function release() + { + $this -> connector -> write(self::ESC . chr(113)); + } + + /** + * Print and reverse feed n lines. + * + * @param int $lines number of lines to feed. If not specified, 1 line will be fed. + */ + public function feedReverse($lines = 1) + { + self::validateInteger($lines, 1, 255, __FUNCTION__); + $this -> connector -> write(self::ESC . "e" . chr($lines)); + } + + /** + * @return number + */ + public function getCharacterTable() + { + return $this -> characterTable; + } + + /** + * @return PrintBuffer + */ + public function getPrintBuffer() + { + return $this -> buffer; + } + + /** + * @return PrintConnector + */ + public function getPrintConnector() + { + return $this -> connector; + } + + /** + * @return CapabilityProfile + */ + public function getPrinterCapabilityProfile() + { + return $this -> profile; + } + + /** + * Print an image to the printer. + * + * Size modifiers are: + * - Printer::IMG_DEFAULT (leave image at original size) + * - Printer::IMG_DOUBLE_WIDTH + * - Printer::IMG_DOUBLE_HEIGHT + * + * See the example/ folder for detailed examples. + * + * The functions bitImage() and bitImageColumnFormat() take the same + * parameters, and can be used if your printer doesn't support the newer + * graphics commands. + * + * @param EscposImage $img The image to print. + * @param int $size Size modifier for the image. Must be either `Printer::IMG_DEFAULT` + * (default), or any combination of the `Printer::IMG_DOUBLE_HEIGHT` and + * `Printer::IMG_DOUBLE_WIDTH` flags. + */ + public function graphics(EscposImage $img, $size = Printer::IMG_DEFAULT) + { + self::validateInteger($size, 0, 3, __FUNCTION__); + $rasterData = $img -> toRasterFormat(); + $imgHeader = Printer::dataHeader([$img -> getWidth(), $img -> getHeight()], true); + $tone = '0'; + $colors = '1'; + $xm = (($size & self::IMG_DOUBLE_WIDTH) == Printer::IMG_DOUBLE_WIDTH) ? chr(2) : chr(1); + $ym = (($size & self::IMG_DOUBLE_HEIGHT) == Printer::IMG_DOUBLE_HEIGHT) ? chr(2) : chr(1); + $header = $tone . $xm . $ym . $colors . $imgHeader; + $this -> wrapperSendGraphicsData('0', 'p', $header . $rasterData); + $this -> wrapperSendGraphicsData('0', '2'); + } + + /** + * Initialize printer. This resets formatting back to the defaults. + */ + public function initialize() + { + $this -> connector -> write(self::ESC . "@"); + $this -> characterTable = 0; + } + + /** + * Print a two-dimensional data code using the PDF417 standard. + * + * @param string $content Text or numbers to store in the code + * @param int $width Width of a module (pixel) in the printed code. + * Default is 3 dots. + * @param int $heightMultiplier Multiplier for height of a module. + * Default is 3 times the width. + * @param int $dataColumnCount Number of data columns to use. 0 (default) + * is to auto-calculate. Smaller numbers will result in a narrower code, + * making larger pixel sizes possible. Larger numbers require smaller pixel sizes. + * @param float $ec Error correction ratio, from 0.01 to 4.00. Default is 0.10 (10%). + * @param int $options Standard code Printer::PDF417_STANDARD with + * start/end bars, or truncated code Printer::PDF417_TRUNCATED with start bars only. + * @throws Exception If this profile indicates that PDF417 code is not supported + */ + public function pdf417Code($content, $width = 3, $heightMultiplier = 3, $dataColumnCount = 0, $ec = 0.10, $options = Printer::PDF417_STANDARD) + { + self::validateString($content, __FUNCTION__, 'content'); + self::validateInteger($width, 2, 8, __FUNCTION__, 'width'); + self::validateInteger($heightMultiplier, 2, 8, __FUNCTION__, 'heightMultiplier'); + self::validateInteger($dataColumnCount, 0, 30, __FUNCTION__, 'dataColumnCount'); + self::validateFloat($ec, 0.01, 4.00, __FUNCTION__, 'ec'); + self::validateInteger($options, 0, 1, __FUNCTION__, 'options'); + if ($content == "") { + return; + } + if (!$this -> profile -> getSupportsPdf417Code()) { + // TODO use software rendering via a library instead + throw new Exception("PDF417 codes are not supported on your printer."); + } + $cn = '0'; // Code type for pdf417 code + // Select model: standard or truncated + $this -> wrapperSend2dCodeData(chr(70), $cn, chr($options)); + // Column count + $this -> wrapperSend2dCodeData(chr(65), $cn, chr($dataColumnCount)); + // Set dot sizes + $this -> wrapperSend2dCodeData(chr(67), $cn, chr($width)); + $this -> wrapperSend2dCodeData(chr(68), $cn, chr($heightMultiplier)); + // Set error correction ratio: 1% to 400% + $ec_int = (int)ceil(floatval($ec) * 10); + $this -> wrapperSend2dCodeData(chr(69), $cn, chr($ec_int), '1'); + // Send content & print + $this -> wrapperSend2dCodeData(chr(80), $cn, $content, '0'); + $this -> wrapperSend2dCodeData(chr(81), $cn, '', '0'); + } + + /** + * Generate a pulse, for opening a cash drawer if one is connected. + * The default settings should open an Epson drawer. + * + * @param int $pin 0 or 1, for pin 2 or pin 5 kick-out connector respectively. + * @param int $on_ms pulse ON time, in milliseconds. + * @param int $off_ms pulse OFF time, in milliseconds. + */ + public function pulse($pin = 0, $on_ms = 120, $off_ms = 240) + { + self::validateInteger($pin, 0, 1, __FUNCTION__); + self::validateInteger($on_ms, 1, 511, __FUNCTION__); + self::validateInteger($off_ms, 1, 511, __FUNCTION__); + $this -> connector -> write(self::ESC . "p" . chr($pin + 48) . chr($on_ms / 2) . chr($off_ms / 2)); + } + + /** + * Print the given data as a QR code on the printer. + * + * @param string $content The content of the code. Numeric data will be more efficiently compacted. + * @param int $ec Error-correction level to use. One of Printer::QR_ECLEVEL_L (default), Printer::QR_ECLEVEL_M, Printer::QR_ECLEVEL_Q or Printer::QR_ECLEVEL_H. Higher error correction results in a less compact code. + * @param int $size Pixel size to use. Must be 1-16 (default 3) + * @param int $model QR code model to use. Must be one of Printer::QR_MODEL_1, Printer::QR_MODEL_2 (default) or Printer::QR_MICRO (not supported by all printers). + */ + public function qrCode($content, $ec = Printer::QR_ECLEVEL_L, $size = 3, $model = Printer::QR_MODEL_2) + { + self::validateString($content, __FUNCTION__); + self::validateInteger($ec, 0, 3, __FUNCTION__); + self::validateInteger($size, 1, 16, __FUNCTION__); + self::validateInteger($model, 1, 3, __FUNCTION__); + if ($content == "") { + return; + } + if (!$this -> profile -> getSupportsQrCode()) { + // TODO use software rendering via phpqrcode instead + throw new Exception("QR codes are not supported on your printer."); + } + $cn = '1'; // Code type for QR code + // Select model: 1, 2 or micro. + $this -> wrapperSend2dCodeData(chr(65), $cn, chr(48 + $model) . chr(0)); + // Set dot size. + $this -> wrapperSend2dCodeData(chr(67), $cn, chr($size)); + // Set error correction level: L, M, Q, or H + $this -> wrapperSend2dCodeData(chr(69), $cn, chr(48 + $ec)); + // Send content & print + $this -> wrapperSend2dCodeData(chr(80), $cn, $content, '0'); + $this -> wrapperSend2dCodeData(chr(81), $cn, '', '0'); + } + + /** + * Switch character table (code page) manually. Used in conjunction with textRaw() to + * print special characters which can't be encoded automatically. + * + * @param int $table The table to select. Available code tables are model-specific. + */ + public function selectCharacterTable($table = 0) + { + self::validateInteger($table, 0, 255, __FUNCTION__); + $supported = $this -> profile -> getCodePages(); + if (!isset($supported[$table])) { + throw new InvalidArgumentException("There is no code table $table allowed by this printer's capability profile."); + } + $this -> characterTable = $table; + if ($this -> profile -> getSupportsStarCommands()) { + /* Not an ESC/POS command: STAR printers stash all the extra code pages under a different command. */ + $this -> connector -> write(self::ESC . self::GS . "t" . chr($table)); + return; + } + $this -> connector -> write(self::ESC . "t" . chr($table)); + } + + /** + * Select print mode(s). + * + * Several MODE_* constants can be OR'd together passed to this function's `$mode` argument. The valid modes are: + * - Printer::MODE_FONT_A + * - Printer::MODE_FONT_B + * - Printer::MODE_EMPHASIZED + * - Printer::MODE_DOUBLE_HEIGHT + * - Printer::MODE_DOUBLE_WIDTH + * - Printer::MODE_UNDERLINE + * + * @param int $mode The mode to use. Default is Printer::MODE_FONT_A, with no special formatting. This has a similar effect to running initialize(). + */ + public function selectPrintMode($mode = Printer::MODE_FONT_A) + { + $allModes = Printer::MODE_FONT_B | self::MODE_EMPHASIZED | self::MODE_DOUBLE_HEIGHT | self::MODE_DOUBLE_WIDTH | self::MODE_UNDERLINE; + if (!is_integer($mode) || $mode < 0 || ($mode & $allModes) != $mode) { + throw new InvalidArgumentException("Invalid mode"); + } + + $this -> connector -> write(self::ESC . "!" . chr($mode)); + } + + /** + * Set barcode height. + * + * @param int $height Height in dots. If not specified, 8 will be used. + */ + public function setBarcodeHeight($height = 8) + { + self::validateInteger($height, 1, 255, __FUNCTION__); + $this -> connector -> write(self::GS . "h" . chr($height)); + } + + /** + * Set barcode bar width. + * + * @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 = 3) + { + self::validateInteger($width, 1, 255, __FUNCTION__); + $this -> connector -> write(self::GS . "w" . chr($width)); + } + + /** + * Set the position for the Human Readable Interpretation (HRI) of barcode characters. + * + * @param int $position. Use Printer::BARCODE_TEXT_NONE to hide the text (default), + * or any combination of Printer::BARCODE_TEXT_ABOVE and Printer::BARCODE_TEXT_BELOW + * flags to display the text. + */ + public function setBarcodeTextPosition($position = Printer::BARCODE_TEXT_NONE) + { + self::validateInteger($position, 0, 3, __FUNCTION__, "Barcode text position"); + $this -> connector -> write(self::GS . "H" . chr($position)); + } + + /** + * Turn double-strike mode on/off. + * + * @param boolean $on true for double strike, false for no double strike + */ + public function setDoubleStrike($on = true) + { + self::validateBoolean($on, __FUNCTION__); + $this -> connector -> write(self::ESC . "G". ($on ? chr(1) : chr(0))); + } + + /** + * Select print color on printers that support multiple colors. + * + * @param int $color Color to use. Must be either Printer::COLOR_1 (default), or Printer::COLOR_2. + */ + public function setColor($color = Printer::COLOR_1) + { + self::validateInteger($color, 0, 1, __FUNCTION__, "Color"); + $this -> connector -> write(self::ESC . "r" . chr($color)); + } + + /** + * Turn emphasized mode on/off. + * + * @param boolean $on true for emphasis, false for no emphasis + */ + public function setEmphasis($on = true) + { + self::validateBoolean($on, __FUNCTION__); + $this -> connector -> write(self::ESC . "E". ($on ? chr(1) : chr(0))); + } + + /** + * Select font. Most printers have two fonts (Fonts A and B), and some have a third (Font C). + * + * @param int $font The font to use. Must be either Printer::FONT_A, Printer::FONT_B, or Printer::FONT_C. + */ + public function setFont($font = Printer::FONT_A) + { + self::validateInteger($font, 0, 2, __FUNCTION__); + $this -> connector -> write(self::ESC . "M" . chr($font)); + } + + /** + * Select justification. + * + * @param int $justification One of Printer::JUSTIFY_LEFT, Printer::JUSTIFY_CENTER, or Printer::JUSTIFY_RIGHT. + */ + public function setJustification($justification = Printer::JUSTIFY_LEFT) + { + self::validateInteger($justification, 0, 2, __FUNCTION__); + $this -> connector -> write(self::ESC . "a" . chr($justification)); + } + + /** + * Set the height of the line. + * + * Some printers will allow you to overlap lines with a smaller line feed. + * + * @param int|null $height The height of each line, in dots. If not set, the printer + * will reset to its default line spacing. + */ + public function setLineSpacing($height = null) + { + if ($height === null) { + // Reset to default + $this -> connector -> write(self::ESC . "2"); // Revert to default line spacing + return; + } + self::validateInteger($height, 1, 255, __FUNCTION__); + $this -> connector -> write(self::ESC . "3" . chr($height)); + } + + /** + * Set print area left margin. Reset to default with Printer::initialize() + * + * @param int $margin The left margin to set on to the print area, in dots. + */ + public function setPrintLeftMargin($margin = 0) + { + self::validateInteger($margin, 0, 65535, __FUNCTION__); + $this -> connector -> write(Printer::GS . 'L' . self::intLowHigh($margin, 2)); + } + + /** + * Set print area width. This can be used to add a right margin to the print area. + * Reset to default with Printer::initialize() + * + * @param int $width The width of the page print area, in dots. + */ + public function setPrintWidth($width = 512) + { + self::validateInteger($width, 1, 65535, __FUNCTION__); + $this -> connector -> write(Printer::GS . 'W' . self::intLowHigh($width, 2)); + } + + /** + * Attach a different print buffer to the printer. Buffers are responsible for handling text output to the printer. + * + * @param PrintBuffer $buffer The buffer to use. + * @throws InvalidArgumentException Where the buffer is already attached to a different printer. + */ + public function setPrintBuffer(PrintBuffer $buffer) + { + if ($buffer === $this -> buffer) { + return; + } + if ($buffer -> getPrinter() != null) { + throw new InvalidArgumentException("This buffer is already attached to a printer."); + } + if ($this -> buffer !== null) { + $this -> buffer -> setPrinter(null); + } + $this -> buffer = $buffer; + $this -> buffer -> setPrinter($this); + } + + /** + * Set black/white reverse mode on or off. In this mode, text is printed white on a black background. + * + * @param boolean $on True to enable, false to disable. + */ + public function setReverseColors($on = true) + { + self::validateBoolean($on, __FUNCTION__); + $this -> connector -> write(self::GS . "B" . ($on ? chr(1) : chr(0))); + } + + /** + * Set the size of text, as a multiple of the normal size. + * + * @param int $widthMultiplier Multiple of the regular height to use (range 1 - 8) + * @param int $heightMultiplier Multiple of the regular height to use (range 1 - 8) + */ + public function setTextSize($widthMultiplier, $heightMultiplier) + { + self::validateInteger($widthMultiplier, 1, 8, __FUNCTION__); + self::validateInteger($heightMultiplier, 1, 8, __FUNCTION__); + $c = pow(2, 4) * ($widthMultiplier - 1) + ($heightMultiplier - 1); + $this -> connector -> write(self::GS . "!" . chr($c)); + } + + /** + * Set underline for printed text. + * + * Argument can be true/false, or one of UNDERLINE_NONE, + * UNDERLINE_SINGLE or UNDERLINE_DOUBLE. + * + * @param int $underline Either true/false, or one of Printer::UNDERLINE_NONE, Printer::UNDERLINE_SINGLE or Printer::UNDERLINE_DOUBLE. Defaults to Printer::UNDERLINE_SINGLE. + */ + public function setUnderline($underline = Printer::UNDERLINE_SINGLE) + { + /* Map true/false to underline constants */ + if ($underline === true) { + $underline = Printer::UNDERLINE_SINGLE; + } elseif ($underline === false) { + $underline = Printer::UNDERLINE_NONE; + } + /* Set the underline */ + self::validateInteger($underline, 0, 2, __FUNCTION__); + $this -> connector -> write(self::ESC . "-" . chr($underline)); + } + + /** + * Print each line upside-down (180 degrees rotated). + * + * @param boolean $on True to enable, false to disable. + */ + public function setUpsideDown($on = true) + { + self::validateBoolean($on, __FUNCTION__); + $this -> connector -> write(self::ESC . "{" . ($on ? chr(1) : chr(0))); + } + + /** + * Add text to the buffer. + * + * Text should either be followed by a line-break, or feed() should be called + * after this to clear the print buffer. + * + * @param string $str Text to print + */ + public function text($str = "") + { + self::validateString($str, __FUNCTION__); + $this -> buffer -> writeText((string)$str); + } + + /** + * Add Chinese text to the buffer. This is a specific workaround for the common Zijang printer- The printer will be switched to a two-byte mode and sent GBK-encoded text. + * + * Support for this will be merged into a print buffer. + * + * @param string $str Text to print, as UTF-8 + */ + public function textChinese($str = "") + { + self::validateString($str, __FUNCTION__); + $this -> connector -> write(self::FS . "&"); + $str = iconv("UTF-8", "GBK//IGNORE", $str); + $this -> buffer -> writeTextRaw((string)$str); + $this -> connector -> write(self::FS . "."); + } + + /** + * Add text to the buffer without attempting to interpret chararacter codes. + * + * Text should either be followed by a line-break, or feed() should be called + * after this to clear the print buffer. + * + * @param string $str Text to print + */ + public function textRaw($str = "") + { + self::validateString($str, __FUNCTION__); + $this -> buffer -> writeTextRaw((string)$str); + } + + /** + * Wrapper for GS ( k, to calculate and send correct data length. + * + * @param string $fn Function to use + * @param string $cn Output code type. Affects available data + * @param string $data Data to send. + * @param string $m Modifier/variant for function. Often '0' where used. + * @throws InvalidArgumentException Where the input lengths are bad. + */ + protected function wrapperSend2dCodeData($fn, $cn, $data = '', $m = '') + { + if (strlen($m) > 1 || strlen($cn) != 1 || strlen($fn) != 1) { + throw new InvalidArgumentException("wrapperSend2dCodeData: cn and fn must be one character each."); + } + $header = $this -> intLowHigh(strlen($data) + strlen($m) + 2, 2); + $this -> connector -> write(self::GS . "(k" . $header . $cn . $fn . $m . $data); + } + + /** + * Wrapper for GS ( L, to calculate and send correct data length. + * + * @param string $m Modifier/variant for function. Usually '0'. + * @param string $fn Function number to use, as character. + * @param string $data Data to send. + * @throws InvalidArgumentException Where the input lengths are bad. + */ + protected function wrapperSendGraphicsData($m, $fn, $data = '') + { + if (strlen($m) != 1 || strlen($fn) != 1) { + throw new InvalidArgumentException("wrapperSendGraphicsData: m and fn must be one character each."); + } + $header = $this -> intLowHigh(strlen($data) + 2, 2); + $this -> connector -> write(self::GS . "(L" . $header . $m . $fn . $data); + } + + /** + * Convert widths and heights to characters. Used before sending graphics to set the size. + * + * @param array $inputs + * @param boolean $long True to use 4 bytes, false to use 2 + * @return string + */ + protected static function dataHeader(array $inputs, $long = true) + { + $outp = []; + foreach ($inputs as $input) { + if ($long) { + $outp[] = Printer::intLowHigh($input, 2); + } else { + self::validateInteger($input, 0, 255, __FUNCTION__); + $outp[] = chr($input); + } + } + return implode("", $outp); + } + + /** + * Generate two characters for a number: In lower and higher parts, or more parts as needed. + * + * @param int $input Input number + * @param int $length The number of bytes to output (1 - 4). + */ + protected static function intLowHigh($input, $length) + { + $maxInput = (256 << ($length * 8) - 1); + self::validateInteger($length, 1, 4, __FUNCTION__); + self::validateInteger($input, 0, $maxInput, __FUNCTION__); + $outp = ""; + for ($i = 0; $i < $length; $i++) { + $outp .= chr($input % 256); + $input = (int)($input / 256); + } + return $outp; + } + + /** + * Throw an exception if the argument given is not a boolean + * + * @param boolean $test the input to test + * @param string $source the name of the function calling this + */ + protected static function validateBoolean($test, $source) + { + if (!($test === true || $test === false)) { + throw new InvalidArgumentException("Argument to $source must be a boolean"); + } + } + + /** + * Throw an exception if the argument given is not a float within the specified range + * + * @param float $test the input to test + * @param float $min the minimum allowable value (inclusive) + * @param float $max the maximum allowable value (inclusive) + * @param string $source the name of the function calling this + * @param string $argument the name of the invalid parameter + */ + protected static function validateFloat($test, $min, $max, $source, $argument = "Argument") + { + if (!is_numeric($test)) { + throw new InvalidArgumentException("$argument given to $source must be a float, but '$test' was given."); + } + if ($test < $min || $test > $max) { + throw new InvalidArgumentException("$argument given to $source must be in range $min to $max, but $test was given."); + } + } + + /** + * Throw an exception if the argument given is not an integer within the specified range + * + * @param int $test the input to test + * @param int $min the minimum allowable value (inclusive) + * @param int $max the maximum allowable value (inclusive) + * @param string $source the name of the function calling this + * @param string $argument the name of the invalid parameter + */ + protected static function validateInteger($test, $min, $max, $source, $argument = "Argument") + { + self::validateIntegerMulti($test, [[$min, $max]], $source, $argument); + } + + /** + * Throw an exception if the argument given is not an integer within one of the specified ranges + * + * @param int $test the input to test + * @param array $ranges array of two-item min/max ranges. + * @param string $source the name of the function calling this + * @param string $source the name of the function calling this + * @param string $argument the name of the invalid parameter + */ + protected static function validateIntegerMulti($test, array $ranges, $source, $argument = "Argument") + { + if (!is_integer($test)) { + throw new InvalidArgumentException("$argument given to $source must be a number, but '$test' was given."); + } + $match = false; + foreach ($ranges as $range) { + $match |= $test >= $range[0] && $test <= $range[1]; + } + if (!$match) { + // Put together a good error "range 1-2 or 4-6" + $rangeStr = "range "; + for ($i = 0; $i < count($ranges); $i++) { + $rangeStr .= $ranges[$i][0] . "-" . $ranges[$i][1]; + if ($i == count($ranges) - 1) { + continue; + } elseif ($i == count($ranges) - 2) { + $rangeStr .= " or "; + } else { + $rangeStr .= ", "; + } + } + throw new InvalidArgumentException("$argument given to $source must be in $rangeStr, but $test was given."); + } + } + + /** + * Throw an exception if the argument given can't be cast to a string + * + * @param string $test the input to test + * @param string $source the name of the function calling this + * @param string $argument the name of the parameter being validated + * @throws InvalidArgumentException Where the argument is not valid + */ + protected static function validateString($test, $source, $argument = "Argument") + { + if (is_object($test) && !method_exists($test, '__toString')) { + throw new InvalidArgumentException("$argument to $source must be a string"); + } + } + + /** + * Throw an exception if the argument doesn't match the given regex. + * + * @param string $test the input to test + * @param string $source the name of the function calling this + * @param string $regex valid values for this attribute, as a regex + * @param string $argument the name of the parameter being validated + * @throws InvalidArgumentException Where the argument is not valid + */ + protected static function validateStringRegex($test, $source, $regex, $argument = "Argument") + { + if (preg_match($regex, $test) === 0) { + throw new InvalidArgumentException("$argument given to $source is invalid. It should match regex '$regex', but '$test' was given."); + } + } +} diff --git a/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/resources/capabilities.json b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/resources/capabilities.json new file mode 100644 index 00000000000..c60cac0deb7 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/src/Mike42/Escpos/resources/capabilities.json @@ -0,0 +1,1760 @@ +{ + "encodings": { + "CP1001": { + "name": "Unimplemented Star-specific CP1001" + }, + "CP1098": { + "name": "CP1098" + }, + "CP1125": { + "iconv": "CP1125", + "name": "CP1125", + "python_encode": "cp1125" + }, + "CP1250": { + "iconv": "CP1250", + "name": "CP1250", + "python_encode": "cp1250" + }, + "CP1251": { + "iconv": "CP1251", + "name": "CP1251", + "python_encode": "cp1251" + }, + "CP1252": { + "iconv": "CP1252", + "name": "CP1252", + "python_encode": "cp1252" + }, + "CP1253": { + "iconv": "CP1253", + "name": "CP1253", + "python_encode": "cp1253" + }, + "CP1254": { + "iconv": "CP1254", + "name": "CP1254", + "python_encode": "cp1254" + }, + "CP1255": { + "iconv": "CP1255", + "name": "CP1255", + "python_encode": "cp1255" + }, + "CP1256": { + "iconv": "CP1256", + "name": "CP1256", + "python_encode": "cp1256" + }, + "CP1257": { + "iconv": "CP1257", + "name": "CP1257", + "python_encode": "cp1257" + }, + "CP1258": { + "iconv": "CP1258", + "name": "CP1258", + "python_encode": "cp1258" + }, + "CP2001": { + "name": "Unimplemented Star-specific CP2001" + }, + "CP3001": { + "name": "Unimplemented Star-specific CP3001" + }, + "CP3002": { + "name": "Unimplemented Star-specific CP3002" + }, + "CP3011": { + "data": [ + "\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5", + "\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00a2\u00a3\u00a5\u20a7\u0192", + "\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u2310\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb", + "\u2591\u2592\u2593\u2502\u2524\u0100\u2562\u0146\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510", + "\u2514\u2534\u252c\u251c\u2500\u253c\u0101\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567", + "\u0160\u2564\u010d\u010c\u2558\u2552\u0123\u012a\u012b\u2518\u250c\u2588\u2584\u016b\u016a\u2580", + "\u03b1\u00df\u0393\u03c0\u03a3\u03c3\u00b5\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u03c6\u03b5\u2229", + "\u0112\u0113\u0122\u0137\u0136\u013c\u013b\u017e\u017d\u2219\u00b7\u221a\u0145\u0161\u25a0 " + ], + "name": "CP3011 Latvian" + }, + "CP3012": { + "data": [ + "\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041a\u041b\u041c\u041d\u041e\u041f", + "\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042a\u042b\u042c\u042d\u042e\u042f", + "\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043a\u043b\u043c\u043d\u043e\u043f", + "\u2591\u2592\u2593\u2502\u2524\u0100\u2562\u0146\u2555\u2563\u2551\u2557\u255d\u014c\u255b\u2510", + "\u2514\u2534\u252c\u251c\u2500\u253c\u0101\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567", + "\u0160\u2564\u010d\u010c\u2558\u2552\u0123\u012a\u012b\u2518\u250c\u2588\u2584\u016b\u016a\u2580", + "\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044a\u044b\u044c\u044d\u044e\u044f", + "\u0112\u0113\u0122\u0137\u0136\u013c\u013b\u017e\u017d\u2219\u00b7\u221a\u0145\u0161\u25a0 " + ], + "name": "CP3012 Cyrillic" + }, + "CP3021": { + "name": "Unimplemented Star-specific CP3021" + }, + "CP3041": { + "name": "Unimplemented Star-specific CP3041" + }, + "CP3840": { + "name": "Unimplemented Star-specific CP3840" + }, + "CP3841": { + "name": "Unimplemented Star-specific CP3841" + }, + "CP3843": { + "name": "Unimplemented Star-specific CP3843" + }, + "CP3844": { + "name": "Unimplemented Star-specific CP3844" + }, + "CP3845": { + "name": "Unimplemented Star-specific CP3845" + }, + "CP3846": { + "name": "Unimplemented Star-specific CP3846" + }, + "CP3847": { + "name": "Unimplemented Star-specific CP3847" + }, + "CP3848": { + "name": "Unimplemented Star-specific CP3848" + }, + "CP437": { + "iconv": "CP437", + "name": "CP437", + "python_encode": "cp437" + }, + "CP720": { + "name": "CP720", + "python_encode": "cp720" + }, + "CP737": { + "iconv": "CP737", + "name": "CP737", + "python_encode": "cp737" + }, + "CP747": { + "name": "CP747" + }, + "CP772": { + "iconv": "CP772", + "name": "CP772" + }, + "CP774": { + "iconv": "CP774", + "name": "CP774" + }, + "CP775": { + "iconv": "CP775", + "name": "CP775", + "python_encode": "cp775" + }, + "CP850": { + "iconv": "CP850", + "name": "CP850", + "python_encode": "cp850" + }, + "CP851": { + "name": "Greek CP851", + "notes": "Not used, due to inconsistencies between implementations." + }, + "CP852": { + "iconv": "CP852", + "name": "CP852", + "python_encode": "cp852" + }, + "CP853": { + "name": "CP853" + }, + "CP855": { + "iconv": "CP855", + "name": "CP855", + "python_encode": "cp855" + }, + "CP857": { + "iconv": "CP857", + "name": "CP857", + "python_encode": "cp857" + }, + "CP858": { + "name": "CP858", + "python_encode": "cp858" + }, + "CP860": { + "iconv": "CP860", + "name": "CP860", + "python_encode": "cp860" + }, + "CP861": { + "iconv": "CP861", + "name": "CP861", + "python_encode": "cp861" + }, + "CP862": { + "iconv": "CP862", + "name": "CP862", + "python_encode": "cp862" + }, + "CP863": { + "iconv": "CP863", + "name": "CP863", + "python_encode": "cp863" + }, + "CP864": { + "iconv": "CP864", + "name": "CP864", + "python_encode": "cp864" + }, + "CP865": { + "iconv": "CP865", + "name": "CP865", + "python_encode": "cp865" + }, + "CP866": { + "iconv": "CP866", + "name": "CP866", + "python_encode": "cp866" + }, + "CP869": { + "iconv": "CP869", + "name": "CP869", + "python_encode": "cp869" + }, + "CP874": { + "iconv": "CP874", + "name": "CP874", + "python_encode": "cp874" + }, + "CP928": { + "name": "CP928" + }, + "CP932": { + "iconv": "CP932", + "name": "CP932", + "python_encode": "cp932" + }, + "ISO_8859-15": { + "iconv": "ISO_8859-15", + "name": "ISO_8859-15", + "python_encode": "iso8859-15" + }, + "ISO_8859-2": { + "iconv": "ISO_8859-2", + "name": "ISO_8859-2", + "python_encode": "iso8859_2" + }, + "ISO_8859-7": { + "iconv": "ISO_8859-7", + "name": "ISO_8859-7", + "python_encode": "iso8859_7" + }, + "OXHOO-EUROPEAN": { + "data": [ + "\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5", + "\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f1\u00d1\u00aa\u00ba\u00bf", + "\u00e1\u00ed\u00f3\u00fa\u00a2\u00a3\u00a5\u20a7\u0192\u00a1\u00c3\u00e3\u00d5\u00f5\u00d8\u00f8", + "\u00b7\u00a8\u00b0`\u00b4\u00bd\u00bc\u00d7\u00f7\u2264\u2265\u00ab\u00bb\u2260\u221a\u00af", + "\u2320\u2321\u221e\u25e4\u21b5\u2191\u2193\u2192\u2190\u250c\u2510\u2514\u2518\u2022\u00ae\u00a9", + "\u2122\u2020\u00a7\u00b6\u0393\u25e2\u0398 ", + "\u00df \u03b5 ", + "\u03c4 " + ], + "name": "Oxhoo-specific European" + }, + "RK1048": { + "iconv": "RK1048", + "name": "RK1048" + }, + "TCVN-3-1": { + "data": [ + " ", + " ", + " \u0103\u00e2\u00ea\u00f4\u01a1\u01b0\u0111 ", + " \u00e0\u1ea3\u00e3\u00e1\u1ea1 \u1eb1\u1eb3\u1eb5\u1eaf ", + " \u1eb7\u1ea7\u1ea9\u1eab\u1ea5\u1ead\u00e8 \u1ebb\u1ebd", + "\u00e9\u1eb9\u1ec1\u1ec3\u1ec5\u1ebf\u1ec7\u00ec\u1ec9 \u0129\u00ed\u1ecb\u00f2", + " \u1ecf\u00f5\u00f3\u1ecd\u1ed3\u1ed5\u1ed7\u1ed1\u1ed9\u1edd\u1edf\u1ee1\u1edb\u1ee3\u00f9", + " \u1ee7\u0169\u00fa\u1ee5\u1eeb\u1eed\u1eef\u1ee9\u1ef1\u1ef3\u1ef7\u1ef9\u00fd\u1ef5 " + ], + "name": "Vietnamese TCVN-3 1" + }, + "TCVN-3-2": { + "data": [ + " ", + " ", + " \u0102\u00c2 \u00d0 \u00ca\u00d4\u01a0\u01af ", + " \u00c0\u1ea2\u00c3\u00c1\u1ea0 \u1eb0\u1eb2\u1eb4\u1eae ", + " \u1eb6\u1ea6\u1ea8\u1eaa\u1ea4\u1eac\u00c8 \u1eba\u1ebc", + "\u00c9\u1eb8\u1ec0\u1ec2\u1ec4\u1ebe\u1ec6\u00cc\u1ec8 \u0128\u00cd\u1eca\u00d2", + " \u1ece\u00d5\u00d3\u1ecc\u1ed2\u1ed4\u1ed6\u1ed0\u1ed8\u1edc\u1ede\u1ee0\u1eda\u1ee2\u00d9", + " \u1ee6\u0168\u00da\u1ee4\u1eea\u1eec\u1eee\u1ee8\u1ef0\u1ef2\u1ef6\u1ef8\u00dd\u1ef4 " + ], + "name": "Vietnamese TCVN-3 1" + }, + "Unknown": { + "name": "Unknown", + "notes": "Code page that has not yet been identified." + } + }, + "profiles": { + "AF-240": { + "codePages": { + "0": "OXHOO-EUROPEAN" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": false, + "barcodeB": false, + "bitImageColumn": false, + "bitImageRaster": false, + "graphics": false, + "highDensity": false, + "paperFullCut": false, + "paperPartCut": false, + "pdf417Code": false, + "pulseBel": false, + "pulseStandard": false, + "qrCode": false, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 20, + "name": "Font A" + } + }, + "media": { + "width": { + "mm": 120, + "pixels": 100 + } + }, + "name": "AF-240 Customer Display", + "notes": "This is a two-line, ESC/POS-aware customer display from Oxhoo. The ESC/POS command mode can be activated persistently by sending:\n\n echo -ne \"\\n\\x02\\x05\\x43\\x31\\x03\" > /dev/ttyUSB0\n", + "vendor": "Oxhoo" + }, + "NT-5890K": { + "codePages": { + "0": "CP437", + "1": "CP932", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "6": "Unknown", + "7": "Unknown", + "8": "Unknown", + "9": "Unknown", + "10": "Unknown", + "16": "CP1252", + "17": "CP866", + "18": "CP852", + "19": "CP858", + "20": "Unknown", + "21": "Unknown", + "22": "Unknown", + "23": "Unknown", + "24": "CP747", + "25": "CP1257", + "27": "CP1258", + "28": "CP864", + "31": "Unknown", + "32": "CP1255", + "50": "CP437", + "52": "CP437", + "53": "CP858", + "54": "CP852", + "55": "CP860", + "56": "CP861", + "57": "CP863", + "58": "CP865", + "59": "CP866", + "60": "CP855", + "61": "CP857", + "62": "CP862", + "63": "CP864", + "64": "CP737", + "65": "CP851", + "66": "CP869", + "68": "CP772", + "69": "CP774", + "71": "CP1252", + "72": "CP1250", + "73": "CP1251", + "74": "CP3840", + "76": "CP3843", + "77": "CP3844", + "78": "CP3845", + "79": "CP3846", + "80": "CP3847", + "81": "CP3848", + "83": "CP2001", + "84": "CP3001", + "85": "CP3002", + "86": "CP3011", + "87": "CP3012", + "88": "CP3021", + "89": "CP3041", + "90": "CP1253", + "91": "CP1254", + "92": "CP1256", + "93": "CP720", + "94": "CP1258", + "95": "CP775", + "96": "Unknown", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": false, + "barcodeB": false, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": false, + "highDensity": true, + "paperFullCut": false, + "paperPartCut": false, + "pdf417Code": false, + "pulseBel": false, + "pulseStandard": true, + "qrCode": false, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 32, + "name": "Font A" + }, + "1": { + "columns": 42, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": 57.5, + "pixels": 384 + } + }, + "name": "NT-5890K", + "notes": "", + "vendor": "Netum" + }, + "OCD-100": { + "codePages": { + "0": "CP437", + "1": "CP932", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "6": "Unknown", + "7": "Unknown", + "8": "Unknown", + "9": "CP852", + "10": "CP862", + "11": "CP866", + "12": "CP1251", + "13": "CP1254", + "14": "CP1255", + "15": "CP1257", + "16": "CP1252", + "17": "CP1253", + "19": "CP858" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": false, + "barcodeB": false, + "bitImageColumn": false, + "bitImageRaster": false, + "graphics": false, + "highDensity": false, + "paperFullCut": false, + "paperPartCut": false, + "pdf417Code": false, + "pulseBel": false, + "pulseStandard": false, + "qrCode": false, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 20, + "name": "Font A" + } + }, + "media": { + "width": { + "mm": 180, + "pixels": 100 + } + }, + "name": "OCD-100 Customer Display", + "notes": "This is a two-line, ESC/POS-aware customer display from Aures. It has some graphics support via custom fonts, but is otherwise text-only. This profile is also suitable for the OCD-150 pole-mounted display.\n", + "vendor": "Aures" + }, + "OCD-300": { + "codePages": { + "0": "CP437", + "1": "CP932", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "6": "Unknown", + "7": "Unknown", + "8": "Unknown", + "9": "CP852", + "10": "CP862", + "11": "CP866", + "12": "CP1251", + "13": "CP1254", + "14": "CP1255", + "15": "CP1257", + "16": "CP1252", + "17": "CP1253", + "18": "CP1250", + "19": "CP858", + "20": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": false, + "barcodeB": false, + "bitImageColumn": false, + "bitImageRaster": false, + "graphics": false, + "highDensity": false, + "paperFullCut": false, + "paperPartCut": false, + "pdf417Code": false, + "pulseBel": false, + "pulseStandard": false, + "qrCode": false, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 20, + "name": "Font A" + } + }, + "media": { + "width": { + "mm": 130.2, + "pixels": 240 + } + }, + "name": "OCD-300 Customer Display", + "notes": "This is a two-line, ESC/POS-aware customer display from Aures. It has some graphics support via vendor-provided tools, but is otherwise text-only.\n", + "vendor": "Aures" + }, + "P822D": { + "codePages": { + "0": "CP437", + "1": "Unknown", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "6": "Unknown", + "7": "Unknown", + "8": "Unknown", + "9": "Unknown", + "10": "Unknown", + "16": "CP1252", + "17": "CP866", + "18": "CP852", + "19": "CP858", + "20": "Unknown", + "21": "Unknown", + "22": "Unknown", + "23": "Unknown", + "24": "CP747", + "25": "CP1257", + "27": "Unknown", + "28": "CP864", + "29": "CP1001", + "30": "Unknown", + "31": "Unknown", + "32": "CP1255", + "33": "CP720", + "34": "CP1256", + "35": "CP1257", + "50": "CP437", + "51": "Unknown", + "52": "CP437", + "53": "CP858", + "54": "CP852", + "55": "CP860", + "56": "CP861", + "57": "CP863", + "58": "CP865", + "59": "CP866", + "60": "CP855", + "61": "CP857", + "62": "CP862", + "63": "CP864", + "64": "CP737", + "65": "CP851", + "66": "CP869", + "67": "CP928", + "68": "CP772", + "69": "CP774", + "70": "CP874", + "71": "CP1252", + "72": "CP1250", + "73": "CP1251", + "74": "CP3840", + "75": "CP3841", + "76": "CP3843", + "77": "CP3844", + "78": "CP3845", + "79": "CP3846", + "80": "CP3847", + "81": "CP3848", + "82": "CP1001", + "83": "CP2001", + "84": "CP3001", + "85": "CP3002", + "86": "CP3011", + "87": "CP3012", + "88": "CP3021", + "89": "CP3041", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": true, + "barcodeB": true, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": false, + "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, + "pdf417Code": true, + "pulseBel": false, + "pulseStandard": true, + "qrCode": true, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": "Unknown", + "pixels": "Unknown" + } + }, + "name": "P822D", + "notes": "", + "vendor": "PBM" + }, + "POS-5890": { + "codePages": { + "0": "CP437", + "1": "CP932", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "6": "Unknown", + "7": "Unknown", + "8": "Unknown", + "9": "Unknown", + "10": "Unknown", + "16": "CP1252", + "17": "CP866", + "18": "CP852", + "19": "CP858", + "20": "Unknown", + "21": "Unknown", + "22": "Unknown", + "23": "Unknown", + "24": "CP747", + "25": "CP1257", + "27": "CP1258", + "28": "CP864", + "31": "Unknown", + "32": "CP1255", + "50": "CP437", + "52": "CP437", + "53": "CP858", + "54": "CP852", + "55": "CP860", + "56": "CP861", + "57": "CP863", + "58": "CP865", + "59": "CP866", + "60": "CP855", + "61": "CP857", + "62": "CP862", + "63": "CP864", + "64": "CP737", + "65": "CP851", + "66": "CP869", + "68": "CP772", + "69": "CP774", + "71": "CP1252", + "72": "CP1250", + "73": "CP1251", + "74": "CP3840", + "76": "CP3843", + "77": "CP3844", + "78": "CP3845", + "79": "CP3846", + "80": "CP3847", + "81": "CP3848", + "83": "CP2001", + "84": "CP3001", + "85": "CP3002", + "86": "CP3011", + "87": "CP3012", + "88": "CP3021", + "89": "CP3041", + "90": "CP1253", + "91": "CP1254", + "92": "CP1256", + "93": "CP720", + "94": "CP1258", + "95": "CP775", + "96": "Unknown", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": false, + "barcodeB": false, + "bitImageColumn": false, + "bitImageRaster": true, + "graphics": false, + "highDensity": true, + "paperFullCut": false, + "paperPartCut": false, + "pdf417Code": false, + "pulseBel": false, + "pulseStandard": true, + "qrCode": false, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 32, + "name": "Font A" + }, + "1": { + "columns": 42, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": 57.5, + "pixels": 384 + } + }, + "name": "POS5890 Series", + "notes": "POS-5890 thermal printer series, also marketed under various other names.\n", + "vendor": "Zjiang" + }, + "SP2000": { + "codePages": { + "0": "CP437", + "1": "CP437", + "2": "CP932", + "3": "CP437", + "4": "CP858", + "5": "CP852", + "6": "CP860", + "7": "CP861", + "8": "CP863", + "9": "CP865", + "10": "CP866", + "11": "CP855", + "12": "CP857", + "13": "CP862", + "14": "CP864", + "15": "CP737", + "16": "CP851", + "17": "CP869", + "18": "CP928", + "19": "CP772", + "20": "CP774", + "21": "CP874", + "32": "CP1252", + "33": "CP1250", + "34": "CP1251", + "64": "CP3840", + "65": "CP3841", + "66": "CP3843", + "67": "CP3844", + "68": "CP3845", + "69": "CP3846", + "70": "CP3847", + "71": "CP3848", + "72": "CP1001", + "73": "CP2001", + "74": "CP3001", + "75": "CP3002", + "76": "CP3011", + "77": "CP3012", + "78": "CP3021", + "79": "CP3041", + "96": "Unknown", + "97": "Unknown", + "98": "Unknown", + "99": "Unknown", + "100": "Unknown", + "101": "Unknown", + "102": "Unknown", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": true, + "barcodeB": true, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": true, + "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, + "pdf417Code": true, + "pulseBel": false, + "pulseStandard": true, + "qrCode": true, + "starCommands": true + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": "Unknown", + "pixels": "Unknown" + } + }, + "name": "SP2000 Series", + "notes": "Star SP2000 impact printer series with ESC/POS emulation enabled", + "vendor": "Star Micronics" + }, + "TEP-200M": { + "codePages": { + "0": "CP437", + "1": "CP932", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "6": "Unknown", + "7": "Unknown", + "8": "Unknown", + "11": "CP851", + "12": "CP853", + "13": "CP857", + "14": "CP737", + "15": "ISO_8859-7", + "16": "CP1252", + "17": "CP866", + "18": "CP852", + "19": "CP858", + "20": "Unknown", + "21": "CP874", + "22": "Unknown", + "23": "Unknown", + "24": "Unknown", + "25": "Unknown", + "26": "Unknown", + "30": "TCVN-3-1", + "31": "TCVN-3-2", + "32": "CP720", + "33": "CP775", + "34": "CP855", + "35": "CP861", + "36": "CP862", + "37": "CP864", + "38": "CP869", + "39": "ISO_8859-2", + "40": "ISO_8859-15", + "41": "CP1098", + "42": "CP774", + "43": "CP772", + "44": "CP1125", + "45": "CP1250", + "46": "CP1251", + "47": "CP1253", + "48": "CP1254", + "49": "CP1255", + "50": "CP1256", + "51": "CP1257", + "52": "CP1258", + "53": "RK1048", + "66": "Unknown", + "67": "Unknown", + "68": "Unknown", + "69": "Unknown", + "70": "Unknown", + "71": "Unknown", + "72": "Unknown", + "73": "Unknown", + "74": "Unknown", + "75": "Unknown", + "82": "Unknown", + "254": "Unknown", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": true, + "barcodeB": true, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": true, + "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, + "pdf417Code": true, + "pulseBel": false, + "pulseStandard": true, + "qrCode": true, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": "Unknown", + "pixels": "Unknown" + } + }, + "name": "TEP200M Series", + "notes": "", + "vendor": "EPOS" + }, + "TM-P80": { + "codePages": { + "0": "CP437", + "1": "CP932", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "6": "Unknown", + "7": "Unknown", + "8": "Unknown", + "11": "CP851", + "12": "CP853", + "13": "CP857", + "14": "CP737", + "15": "ISO_8859-7", + "16": "CP1252", + "17": "CP866", + "18": "CP852", + "19": "CP858", + "20": "Unknown", + "21": "CP874", + "22": "Unknown", + "23": "Unknown", + "24": "Unknown", + "25": "Unknown", + "26": "Unknown", + "30": "TCVN-3-1", + "31": "TCVN-3-2", + "32": "CP720", + "33": "CP775", + "34": "CP855", + "35": "CP861", + "36": "CP862", + "37": "CP864", + "38": "CP869", + "39": "ISO_8859-2", + "40": "ISO_8859-15", + "41": "CP1098", + "42": "CP774", + "43": "CP772", + "44": "CP1125", + "45": "CP1250", + "46": "CP1251", + "47": "CP1253", + "48": "CP1254", + "49": "CP1255", + "50": "CP1256", + "51": "CP1257", + "52": "CP1258", + "53": "RK1048", + "66": "Unknown", + "67": "Unknown", + "68": "Unknown", + "69": "Unknown", + "70": "Unknown", + "71": "Unknown", + "72": "Unknown", + "73": "Unknown", + "74": "Unknown", + "75": "Unknown", + "82": "Unknown", + "254": "Unknown", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": true, + "barcodeB": true, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": true, + "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, + "pdf417Code": true, + "pulseBel": false, + "pulseStandard": true, + "qrCode": true, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + }, + "2": { + "columns": 24, + "name": "Kanji" + } + }, + "media": { + "width": { + "mm": 72, + "pixels": 576 + } + }, + "name": "TM-P80", + "notes": "Portable printer (48-column mode)", + "vendor": "Epson" + }, + "TM-P80-42col": { + "codePages": { + "0": "CP437", + "1": "CP932", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "6": "Unknown", + "7": "Unknown", + "8": "Unknown", + "11": "CP851", + "12": "CP853", + "13": "CP857", + "14": "CP737", + "15": "ISO_8859-7", + "16": "CP1252", + "17": "CP866", + "18": "CP852", + "19": "CP858", + "20": "Unknown", + "21": "CP874", + "22": "Unknown", + "23": "Unknown", + "24": "Unknown", + "25": "Unknown", + "26": "Unknown", + "30": "TCVN-3-1", + "31": "TCVN-3-2", + "32": "CP720", + "33": "CP775", + "34": "CP855", + "35": "CP861", + "36": "CP862", + "37": "CP864", + "38": "CP869", + "39": "ISO_8859-2", + "40": "ISO_8859-15", + "41": "CP1098", + "42": "CP774", + "43": "CP772", + "44": "CP1125", + "45": "CP1250", + "46": "CP1251", + "47": "CP1253", + "48": "CP1254", + "49": "CP1255", + "50": "CP1256", + "51": "CP1257", + "52": "CP1258", + "53": "RK1048", + "66": "Unknown", + "67": "Unknown", + "68": "Unknown", + "69": "Unknown", + "70": "Unknown", + "71": "Unknown", + "72": "Unknown", + "73": "Unknown", + "74": "Unknown", + "75": "Unknown", + "82": "Unknown", + "254": "Unknown", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": true, + "barcodeB": true, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": true, + "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, + "pdf417Code": true, + "pulseBel": false, + "pulseStandard": true, + "qrCode": true, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 60, + "name": "Font B" + }, + "2": { + "columns": 21, + "name": "Kanji" + } + }, + "media": { + "width": { + "mm": 63.6, + "pixels": 546 + } + }, + "name": "TM-P80 (42 column mode)", + "notes": "Portable printer (42-column mode)", + "vendor": "Epson" + }, + "TM-T88II": { + "codePages": { + "0": "CP437", + "1": "CP932", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "19": "CP858", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": true, + "barcodeB": true, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": true, + "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, + "pdf417Code": true, + "pulseBel": false, + "pulseStandard": true, + "qrCode": true, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": "Unknown", + "pixels": "Unknown" + } + }, + "name": "TM-T88II", + "notes": "Epson TM-T88II profile. This printer is discontinued by the Vendor, and has similar feature support to the TM-T88III. The code page mapping is documented in the \"TM-T88II/T88III Technical Reference Guide\".\n", + "vendor": "Epson" + }, + "TM-T88III": { + "codePages": { + "0": "CP437", + "1": "CP932", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "16": "CP1252", + "17": "CP866", + "18": "CP862", + "19": "CP858", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": true, + "barcodeB": true, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": true, + "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, + "pdf417Code": true, + "pulseBel": false, + "pulseStandard": true, + "qrCode": true, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": "Unknown", + "pixels": "Unknown" + } + }, + "name": "TM-T88III", + "notes": "Epson TM-T88III profile. This printer has similar feature support to the TM-T88II. The code page mapping is documented in the \"TM-T88II/T88III Technical Reference Guide\".\n", + "vendor": "Epson" + }, + "TM-T88IV": { + "codePages": { + "0": "CP437", + "1": "CP932", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "16": "CP1252", + "17": "CP866", + "18": "CP852", + "19": "CP858", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": true, + "barcodeB": true, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": true, + "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, + "pdf417Code": true, + "pulseBel": false, + "pulseStandard": true, + "qrCode": true, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": "Unknown", + "pixels": "Unknown" + } + }, + "name": "TM-T88IV", + "notes": "Epson TM-T88IV profile\n", + "vendor": "Epson" + }, + "TM-T88IV-SA": { + "codePages": { + "0": "CP437", + "20": "Unknown", + "21": "CP874", + "26": "Unknown", + "30": "TCVN-3-1", + "31": "TCVN-3-2" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": true, + "barcodeB": true, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": true, + "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, + "pdf417Code": true, + "pulseBel": false, + "pulseStandard": true, + "qrCode": true, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": "Unknown", + "pixels": "Unknown" + } + }, + "name": "TM-T88IV South Asia", + "notes": "Epson TM-T88IV profile (South Asia models)\n", + "vendor": "Epson" + }, + "TM-U220": { + "codePages": { + "0": "CP437" + }, + "colors": { + "0": "black", + "1": "alternate" + }, + "features": { + "barcodeA": false, + "barcodeB": false, + "bitImageColumn": true, + "bitImageRaster": false, + "graphics": false, + "highDensity": false, + "paperFullCut": false, + "paperPartCut": false, + "pdf417Code": false, + "pulseBel": false, + "pulseStandard": true, + "qrCode": false, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": 80, + "pixels": "Unknown" + } + }, + "name": "TM-U220", + "notes": "Two-color impact printer with 80mm output", + "vendor": "Epson" + }, + "TSP600": { + "codePages": { + "0": "CP437", + "1": "CP437", + "2": "CP932", + "3": "CP437", + "4": "CP858", + "5": "CP852", + "6": "CP860", + "7": "CP861", + "8": "CP863", + "9": "CP865", + "10": "CP866", + "11": "CP855", + "12": "CP857", + "13": "CP862", + "14": "CP864", + "15": "CP737", + "16": "CP851", + "17": "CP869", + "18": "CP928", + "19": "CP772", + "20": "CP774", + "21": "CP874", + "32": "CP1252", + "33": "CP1250", + "34": "CP1251", + "64": "CP3840", + "65": "CP3841", + "66": "CP3843", + "67": "CP3844", + "68": "CP3845", + "69": "CP3846", + "70": "CP3847", + "71": "CP3848", + "72": "CP1001", + "73": "CP2001", + "74": "CP3001", + "75": "CP3002", + "76": "CP3011", + "77": "CP3012", + "78": "CP3021", + "79": "CP3041", + "96": "Unknown", + "97": "Unknown", + "98": "Unknown", + "99": "Unknown", + "100": "Unknown", + "101": "Unknown", + "102": "Unknown", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": true, + "barcodeB": true, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": true, + "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, + "pdf417Code": true, + "pulseBel": false, + "pulseStandard": true, + "qrCode": true, + "starCommands": true + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": "Unknown", + "pixels": "Unknown" + } + }, + "name": "TSP600 Series", + "notes": "Star TSP600 thermal printer series with ESC/POS emulation enabled", + "vendor": "Star Micronics" + }, + "TUP500": { + "codePages": { + "0": "CP437", + "1": "CP437", + "2": "CP932", + "3": "CP437", + "4": "CP858", + "5": "CP852", + "6": "CP860", + "7": "CP861", + "8": "CP863", + "9": "CP865", + "10": "CP866", + "11": "CP855", + "12": "CP857", + "13": "CP862", + "14": "CP864", + "15": "CP737", + "16": "CP851", + "17": "CP869", + "18": "CP928", + "19": "CP772", + "20": "CP774", + "21": "CP874", + "32": "CP1252", + "33": "CP1250", + "34": "CP1251", + "64": "CP3840", + "65": "CP3841", + "66": "CP3843", + "67": "CP3844", + "68": "CP3845", + "69": "CP3846", + "70": "CP3847", + "71": "CP3848", + "72": "CP1001", + "73": "CP2001", + "74": "CP3001", + "75": "CP3002", + "76": "CP3011", + "77": "CP3012", + "78": "CP3021", + "79": "CP3041", + "96": "Unknown", + "97": "Unknown", + "98": "Unknown", + "99": "Unknown", + "100": "Unknown", + "101": "Unknown", + "102": "Unknown", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": true, + "barcodeB": true, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": true, + "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, + "pdf417Code": true, + "pulseBel": false, + "pulseStandard": true, + "qrCode": true, + "starCommands": true + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": "Unknown", + "pixels": "Unknown" + } + }, + "name": "TUP500 Series", + "notes": "Star TUP500 thermal printer series with ESC/POS emulation enabled", + "vendor": "Star Micronics" + }, + "default": { + "codePages": { + "0": "CP437", + "1": "CP932", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "6": "Unknown", + "7": "Unknown", + "8": "Unknown", + "11": "CP851", + "12": "CP853", + "13": "CP857", + "14": "CP737", + "15": "ISO_8859-7", + "16": "CP1252", + "17": "CP866", + "18": "CP852", + "19": "CP858", + "20": "Unknown", + "21": "CP874", + "22": "Unknown", + "23": "Unknown", + "24": "Unknown", + "25": "Unknown", + "26": "Unknown", + "30": "TCVN-3-1", + "31": "TCVN-3-2", + "32": "CP720", + "33": "CP775", + "34": "CP855", + "35": "CP861", + "36": "CP862", + "37": "CP864", + "38": "CP869", + "39": "ISO_8859-2", + "40": "ISO_8859-15", + "41": "CP1098", + "42": "CP774", + "43": "CP772", + "44": "CP1125", + "45": "CP1250", + "46": "CP1251", + "47": "CP1253", + "48": "CP1254", + "49": "CP1255", + "50": "CP1256", + "51": "CP1257", + "52": "CP1258", + "53": "RK1048", + "66": "Unknown", + "67": "Unknown", + "68": "Unknown", + "69": "Unknown", + "70": "Unknown", + "71": "Unknown", + "72": "Unknown", + "73": "Unknown", + "74": "Unknown", + "75": "Unknown", + "82": "Unknown", + "254": "Unknown", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": true, + "barcodeB": true, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": true, + "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, + "pdf417Code": true, + "pulseBel": false, + "pulseStandard": true, + "qrCode": true, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": "Unknown", + "pixels": "Unknown" + } + }, + "name": "Default", + "notes": "Default ESC/POS profile, suitable for standards-compliant or Epson-branded printers. This profile allows the use of standard ESC/POS features, and can encode a variety of code pages.\n", + "vendor": "Generic" + }, + "simple": { + "codePages": { + "0": "CP437" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": false, + "barcodeB": false, + "bitImageColumn": false, + "bitImageRaster": true, + "graphics": false, + "highDensity": true, + "paperFullCut": false, + "paperPartCut": false, + "pdf417Code": false, + "pulseBel": false, + "pulseStandard": true, + "qrCode": false, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 42, + "name": "Font A" + }, + "1": { + "columns": 56, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": "Unknown", + "pixels": "Unknown" + } + }, + "name": "Simple", + "notes": "A profile for use in printers with unknown or poor compatibility. This profile indicates that a small number of features are supported, so that commands are not sent a printer that is unlikely to understand them.\n", + "vendor": "Generic" + } + } +} \ No newline at end of file diff --git a/htdocs/includes/mike42/escpos-php/src/NetworkPrintConnector.php b/htdocs/includes/mike42/escpos-php/src/NetworkPrintConnector.php deleted file mode 100644 index 4dd2c39f115..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/NetworkPrintConnector.php +++ /dev/null @@ -1,39 +0,0 @@ -, - * incorporating modifications by: - * - Roni Saha - * - Gergely Radics - * - Warren Doyle - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * PrintConnector for directly opening a network socket to a printer to send it commands. - */ -class NetworkPrintConnector extends FilePrintConnector { - public function __construct($ip, $port = "9100") { - $this -> fp = @fsockopen($ip, $port, $errno, $errstr); - if($this -> fp === false) { - throw new Exception("Cannot initialise NetworkPrintConnector: " . $errstr); - } - } -} diff --git a/htdocs/includes/mike42/escpos-php/src/P822DCapabilityProfile.php b/htdocs/includes/mike42/escpos-php/src/P822DCapabilityProfile.php deleted file mode 100644 index 7c3b5abe6dd..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/P822DCapabilityProfile.php +++ /dev/null @@ -1,90 +0,0 @@ - CodePage::CP437, - 1 => false, // Katakana - 2 => CodePage::CP850, - 3 => CodePage::CP860, - 4 => CodePage::CP863, - 5 => CodePage::CP865, - 6 => false, // Western Europe - 7 => false, // Greek - 8 => false, // Hebrew - 9 => false, // Eastern europe - 10 => false, // Iran - 16 => CodePage::CP1252 , - 17 => CodePage::CP866 , - 18 => CodePage::CP852 , - 19 => CodePage::CP858, - 20 => false, // Iran II - 21 => false, // latvian - 22 => false, //Arabic - 23 => false, // PT151, 1251 - 24 => CodePage::CP747, - 25 => CodePage::CP1257, - 27 => false, // Vietnam, - 28 => CodePage::CP864, - 29 => CodePage::CP1001, - 30 => false, // Uigur - 31 => false, // Hebrew - 32 => CodePage::CP1255, - 33 => CodePage::CP720, - 34 => CodePage::CP1256, - 35 => CodePage::CP1257, - 255 => false, // Thai - - 50 => CodePage::CP437, - 51 => false, // Jatakana, - 52 => CodePage::CP437, - 53 => CodePage::CP858, - 54 => CodePage::CP852, - 55 => CodePage::CP860, - 56 => CodePage::CP861, - 57 => CodePage::CP863, - 58 => CodePage::CP865, - 59 => CodePage::CP866, - 60 => CodePage::CP855, - 61 => CodePage::CP857, - 62 => CodePage::CP862, - 63 => CodePage::CP864, - 64 => CodePage::CP737, - 65 => CodePage::CP851, - 66 => CodePage::CP869, - 67 => CodePage::CP928, - 68 => CodePage::CP772, - 69 => CodePage::CP774, - 70 => CodePage::CP874, - 71 => CodePage::CP1252, - 72 => CodePage::CP1250, - 73 => CodePage::CP1251, - 74 => CodePage::CP3840, - 75 => CodePage::CP3841, - 76 => CodePage::CP3843, - 77 => CodePage::CP3844, - 78 => CodePage::CP3845, - 79 => CodePage::CP3846, - 80 => CodePage::CP3847, - 81 => CodePage::CP3848, - 82 => CodePage::CP1001, - 83 => CodePage::CP2001, - 84 => CodePage::CP3001, - 85 => CodePage::CP3002, - 86 => CodePage::CP3011, - 87 => CodePage::CP3012, - 88 => CodePage::CP3021, - 89 => CodePage::CP3041 - ); - } - - public function getSupportsGraphics() { - /* Ask the driver to use bitImage wherever possible instead of graphics */ - return false; - } -} diff --git a/htdocs/includes/mike42/escpos-php/src/PrintBuffer.php b/htdocs/includes/mike42/escpos-php/src/PrintBuffer.php deleted file mode 100644 index 9e3b110085f..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/PrintBuffer.php +++ /dev/null @@ -1,75 +0,0 @@ -, - * incorporating modifications by: - * - Roni Saha - * - Gergely Radics - * - Warren Doyle - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Print buffers manage newlines and character encoding for the target printer. - * They are used as a swappable component: text or image-based output. - * - * - Text output (EscposPrintBuffer) is the fast default, and is recommended for - * most people, as the text output can be more directly manipulated by ESC/POS - * commands. - * - Image output (ImagePrintBuffer) is designed to accept more encodings than the - * physical printer supports, by rendering the text to small images on-the-fly. - * This takes a lot more CPU than sending text, but is necessary for some users. - * - If your use case fits outside these, then a further speed/flexibility trade-off - * can be made by printing directly from generated HTML or PDF. - */ -interface PrintBuffer { - /** - * Cause the buffer to send any partial input and wait on a newline. - * If the printer is already on a new line, this does nothing. - */ - function flush(); - - /** - * Used by Escpos to check if a printer is set. - */ - function getPrinter(); - - /** - * Used by Escpos to hook up one-to-one link between buffers and printers. - * - * @param Escpos $printer New printer - */ - function setPrinter(Escpos $printer = null); - - /** - * Accept UTF-8 text for printing. - * - * @param string $text Text to print - */ - function writeText($text); - - /** - * Accept 8-bit text in the current encoding and add it to the buffer. - * - * @param string $text Text to print, already the target encoding. - */ - function writeTextRaw($text); -} -?> \ No newline at end of file diff --git a/htdocs/includes/mike42/escpos-php/src/PrintConnector.php b/htdocs/includes/mike42/escpos-php/src/PrintConnector.php deleted file mode 100644 index f1d37be9c55..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/PrintConnector.php +++ /dev/null @@ -1,56 +0,0 @@ -, - * incorporating modifications by: - * - Roni Saha - * - Gergely Radics - * - Warren Doyle - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Interface passed to Escpos class for receiving print data. Print connectors - * are responsible for transporting this to the actual printer. - */ -interface PrintConnector { - /** - * Print connectors should cause a NOTICE if they are deconstructed - * when they have not been finalized. - */ - public function __destruct(); - - /** - * Finish using this print connector (close file, socket, send - * accumulated output, etc). - */ - public function finalize(); - - /** - * @param string $data - * @return Data read from the printer, or false where reading is not possible. - */ - public function read($len); - - /** - * @param string $data - */ - public function write($data); -} diff --git a/htdocs/includes/mike42/escpos-php/src/SimpleCapabilityProfile.php b/htdocs/includes/mike42/escpos-php/src/SimpleCapabilityProfile.php deleted file mode 100644 index 7076b5e16cb..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/SimpleCapabilityProfile.php +++ /dev/null @@ -1,17 +0,0 @@ - CodePage::CP437); - } - - public function getSupportsGraphics() { - /* Ask the driver to use bitImage wherever possible instead of graphics */ - return false; - } -} diff --git a/htdocs/includes/mike42/escpos-php/src/StarCapabilityProfile.php b/htdocs/includes/mike42/escpos-php/src/StarCapabilityProfile.php deleted file mode 100644 index f61774a5e30..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/StarCapabilityProfile.php +++ /dev/null @@ -1,82 +0,0 @@ - "ÇüéâäàåçêëèïîìÄÅ" . - "ÉæÆôöòûùÿÖÜ¢£¥₧ƒ" . - "áíóúñѪº¿⌐¬½¼¡«»" . - "░▒▓│┤Ā╢ņ╕╣║╗╝╜╛┐" . - "└┴┬├─┼ā╟╚╔╩╦╠═╬╧" . - "Š╤čČ╘╒ģĪī┘┌█▄ūŪ▀" . - "αßΓπΣσµτΦΘΩδ∞φε∩" . - "ĒēĢķĶļĻžŽ∙·√Ņš■ ", - 'CP3012' => "АБВГДЕЖЗИЙКЛМНОП" . - "РСТУФХЦЧШЩЪЫЬЭЮЯ" . - "абвгдежзийклмноп" . - "░▒▓│┤Ā╢ņ╕╣║╗╝Ō╛┐" . - "└┴┬├─┼ā╟╚╔╩╦╠═╬╧" . - "Š╤čČ╘╒ģĪī┘┌█▄ūŪ▀" . - "рстуфхцчшщъыьэюя" . - "ĒēĢķĶļĻžŽ∙·√Ņš■ " - ); - } - - function getSupportedCodePages() { - return array( - 0 => CodePage::CP437, // "Normal" - 1 => CodePage::CP437, - 2 => CodePage::CP932, - 3 => CodePage::CP437, - 4 => CodePage::CP858, - 5 => CodePage::CP852, - 6 => CodePage::CP860, - 7 => CodePage::CP861, - 8 => CodePage::CP863, - 9 => CodePage::CP865, - 10 => CodePage::CP866, - 11 => CodePage::CP855, - 12 => CodePage::CP857, - 13 => CodePage::CP862, - 14 => CodePage::CP864, - 15 => CodePage::CP737, - 16 => CodePage::CP851, - 17 => CodePage::CP869, - 18 => CodePage::CP928, - 19 => CodePage::CP772, - 20 => CodePage::CP774, - 21 => CodePage::CP874, - 32 => CodePage::CP1252, - 33 => CodePage::CP1250, - 34 => CodePage::CP1251, - 64 => CodePage::CP3840, - 65 => CodePage::CP3841, - 66 => CodePage::CP3843, - 67 => CodePage::CP3844, - 68 => CodePage::CP3845, - 69 => CodePage::CP3846, - 70 => CodePage::CP3847, - 71 => CodePage::CP3848, - 72 => CodePage::CP1001, - 73 => CodePage::CP2001, - 74 => CodePage::CP3001, - 75 => CodePage::CP3002, - 76 => 'custom:CP3011', - 77 => 'custom:CP3012', - 78 => CodePage::CP3021, - 79 => CodePage::CP3041, - 96 => false, // Thai Character Code 42 - 97 => false, // Thai Character Code 11 - 98 => false, // Thai Character Code 13 - 99 => false, // Thai Character Code 14 - 100 => false, // Thai Character Code 16 - 101 => false, // Thai Character Code 17 - 102 => false, // Thai Character Code 18 - 255 => false); - } - - function getSupportsStarCommands() { - /* Allows Escpos.php to substitute emulated ESC/POS commands with native ones for this printer. */ - return true; - } -} \ No newline at end of file diff --git a/htdocs/includes/mike42/escpos-php/src/WindowsPrintConnector.php b/htdocs/includes/mike42/escpos-php/src/WindowsPrintConnector.php deleted file mode 100644 index 717e9c1a572..00000000000 --- a/htdocs/includes/mike42/escpos-php/src/WindowsPrintConnector.php +++ /dev/null @@ -1,356 +0,0 @@ -, - * incorporating modifications by: - * - Roni Saha - * - Gergely Radics - * - Warren Doyle - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Connector for sending print jobs to - * - local ports on windows (COM1, LPT1, etc) - * - shared (SMB) printers from any platform (\\server\foo) - * For USB printers or other ports, the trick is to share the printer with a generic text driver, then access it locally. - */ -class WindowsPrintConnector implements PrintConnector { - /** - * @var array Accumulated lines of output for later use. - */ - private $buffer; - - /** - * @var string The hostname of the target machine, or null if this is a local connection. - */ - private $hostname; - - /** - * @var boolean True if a port is being used directly (must be Windows), false if network shares will be used. - */ - private $isLocal; - - /** - * @var int Platform we're running on, for selecting different commands. See PLATFORM_* constants. - */ - private $platform; - - /** - * @var string The name of the target printer (eg "Foo Printer") or port ("COM1", "LPT1"). - */ - private $printerName; - - /** - * @var string Login name for network printer, or null if not using authentication. - */ - private $userName; - - /** - * @var string Password for network printer, or null if no password is required. - */ - private $userPassword; - - /** - * @var string Workgroup that the printer is located on - */ - private $workgroup; - - /** - * @var int represents Linux - */ - const PLATFORM_LINUX = 0; - - /** - * @var int represents Mac - */ - const PLATFORM_MAC = 1; - - /** - * @var int represents Windows - */ - const PLATFORM_WIN = 2; - - /** - * @var string Valid local ports. - */ - const REGEX_LOCAL = "/^(LPT\d|COM\d)$/"; - - /** - * @var string Valid printer name. - */ - const REGEX_PRINTERNAME = "/^[\w-]+(\s[\w-]+)*$/"; - - /** - * @var string Valid smb:// URI containing hostname & printer with optional user & optional password only. - */ - const REGEX_SMB = "/^smb:\/\/([\s\w-]+(:[\s\w-]+)?@)?[\w-]+\/([\w-]+\/)?[\w-]+(\s[\w-]+)*$/"; - - /** - * @param string $dest - * @throws BadMethodCallException - */ - public function __construct($dest) { - $this -> platform = $this -> getCurrentPlatform(); - $this -> isLocal = false; - $this -> buffer = null; - $this -> userName = null; - $this -> userPassword = null; - $this -> workgroup = null; - if(preg_match(self::REGEX_LOCAL, $dest) == 1) { - // Straight to LPT1, COM1 or other local port. Allowed only if we are actually on windows. - if($this -> platform !== self::PLATFORM_WIN) { - throw new BadMethodCallException("WindowsPrintConnector can only be used to print to a local printer ('".$dest."') on a Windows computer."); - } - $this -> isLocal = true; - $this -> hostname = null; - $this -> printerName = $dest; - } else if(preg_match(self::REGEX_SMB, $dest) == 1) { - // Connect to samba share, eg smb://host/printer - $part = parse_url($dest); - $this -> hostname = $part['host']; - /* Printer name and optional workgroup */ - $path = ltrim($part['path'], '/'); - if(strpos($path, "/") !== false) { - $pathPart = explode("/", $path); - $this -> workgroup = $pathPart[0]; - $this -> printerName = $pathPart[1]; - } else { - $this -> printerName = $path; - } - /* Username and password if set */ - if(isset($part['user'])) { - $this -> userName = $part['user']; - if(isset($part['pass'])) { - $this -> userPassword = $part['pass']; - } - } - } else if(preg_match(self::REGEX_PRINTERNAME, $dest) == 1) { - // Just got a printer name. Assume it's on the current computer. - $hostname = gethostname(); - if(!$hostname) { - $hostname = "localhost"; - } - $this -> hostname = $hostname; - $this -> printerName = $dest; - } else { - throw new BadMethodCallException("Printer '" . $dest . "' is not a valid printer name. Use local port (LPT1, COM1, etc) or smb://computer/printer notation."); - } - $this -> buffer = array(); - } - - public function __destruct() { - if($this -> buffer !== null) { - trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE); - } - } - - public function finalize() { - $data = implode($this -> buffer); - $this -> buffer = null; - if($this -> platform == self::PLATFORM_WIN) { - $this -> finalizeWin($data); - } else if($this -> platform == self::PLATFORM_LINUX) { - $this -> finalizeLinux($data); - } else { - $this -> finalizeMac($data); - } - } - - /** - * Send job to printer -- platform-specific Linux code. - * - * @param string $data Print data - * @throws Exception - */ - protected function finalizeLinux($data) { - /* Non-Windows samba printing */ - $device = "//" . $this -> hostname . "/" . $this -> printerName; - if($this -> userName !== null) { - $user = ($this -> workgroup != null ? ($this -> workgroup . "\\") : "") . $this -> userName; - if($this -> userPassword == null) { - // No password - $command = sprintf("smbclient %s -U %s -c %s -N", - escapeshellarg($device), - escapeshellarg($user), - escapeshellarg("print -")); - $redactedCommand = $command; - } else { - // With password - $command = sprintf("smbclient %s %s -U %s -c %s", - escapeshellarg($device), - escapeshellarg($this -> userPassword), - escapeshellarg($user), - escapeshellarg("print -")); - $redactedCommand = sprintf("smbclient %s %s -U %s -c %s", - escapeshellarg($device), - escapeshellarg("*****"), - escapeshellarg($user), - escapeshellarg("print -")); - } - } else { - // No authentication information at all - $command = sprintf("smbclient %s -c %s -N", - escapeshellarg($device), - escapeshellarg("print -")); - $redactedCommand = $command; - } - $retval = $this -> runCommand($command, $outputStr, $errorStr, $data); - if($retval != 0) { - throw new Exception("Failed to print. Command \"$redactedCommand\" failed with exit code $retval: " . trim($outputStr)); - } - } - - protected function finalizeMac($data) { - throw new Exception("Mac printing not implemented."); - } - - /** - * Send data to printer -- platform-specific Windows code. - * - * @param string $data - */ - protected function finalizeWin($data) { - /* Windows-friendly printing of all sorts */ - if(!$this -> isLocal) { - /* Networked printing */ - $device = "\\\\" . $this -> hostname . "\\" . $this -> printerName; - if($this -> userName !== null) { - /* Log in */ - $user = "/user:" . ($this -> workgroup != null ? ($this -> workgroup . "\\") : "") . $this -> userName; - if($this -> userPassword == null) { - $command = sprintf("net use %s %s", - escapeshellarg($device), - escapeshellarg($user)); - $redactedCommand = $command; - } else { - $command = sprintf("net use %s %s %s", - escapeshellarg($device), - escapeshellarg($user), - escapeshellarg($this -> userPassword)); - $redactedCommand = sprintf("net use %s %s %s", - escapeshellarg($device), - escapeshellarg($user), - escapeshellarg("*****")); - } - $retval = $this -> runCommand($command, $outputStr, $errorStr); - if($retval != 0) { - throw new Exception("Failed to print. Command \"$redactedCommand\" failed with exit code $retval: " . trim($errorStr)); - } - } - /* Final print-out */ - $filename = tempnam(sys_get_temp_dir(), "escpos"); - file_put_contents($filename, $data); - if(!$this -> runCopy($filename, $device)){ - throw new Exception("Failed to copy file to printer"); - } - unlink($filename); - } else { - /* Drop data straight on the printer */ - if(!$this -> runWrite($data, $this -> printerName)) { - throw new Exception("Failed to write file to printer at " . $this -> printerName); - } - } - } - - /** - * @return string Current platform. Separated out for testing purposes. - */ - protected function getCurrentPlatform() { - if(PHP_OS == "WINNT") { - return self::PLATFORM_WIN; - } - if(PHP_OS == "Darwin") { - return self::PLATFORM_MAC; - } - return self::PLATFORM_LINUX; - } - - /* (non-PHPdoc) - * @see PrintConnector::read() - */ - public function read($len) { - /* Two-way communication is not supported */ - return false; - } - - /** - * Run a command, pass it data, and retrieve its return value, standard output, and standard error. - * - * @param string $command the command to run. - * @param string $outputStr variable to fill with standard output. - * @param string $errorStr variable to fill with standard error. - * @param string $inputStr text to pass to the command's standard input (optional). - * @return number - */ - protected function runCommand($command, &$outputStr, &$errorStr, $inputStr = null) { - $descriptors = array( - 0 => array("pipe", "r"), - 1 => array("pipe", "w"), - 2 => array("pipe", "w"), - ); - $process = proc_open($command, $descriptors, $fd); - if (is_resource($process)) { - /* Write to input */ - if($inputStr !== null) { - fwrite($fd[0], $inputStr); - } - fclose($fd[0]); - /* Read stdout */ - $outputStr = stream_get_contents($fd[1]); - fclose($fd[1]); - /* Read stderr */ - $errorStr = stream_get_contents($fd[2]); - fclose($fd[2]); - /* Finish up */ - $retval = proc_close($process); - return $retval; - } else { - /* Method calling this should notice a non-zero exit and print an error */ - return -1; - } - } - - /** - * Copy a file. Separated out so that nothing is actually printed during test runs. - * - * @param string $from Source file - * @param string $to Destination file - * @return boolean True if copy was successful, false otherwise - */ - protected function runCopy($from, $to) { - return copy($from, $to); - } - - /** - * Write data to a file. Separated out so that nothing is actually printed during test runs. - * - * @param string $data Data to print - * @param string $to Destination file - * @return boolean True if write was successful, false otherwise - */ - protected function runWrite($data, $to) { - return file_put_contents($data, $to) !== false; - } - - public function write($data) { - $this -> buffer[] = $data; - } -} diff --git a/htdocs/includes/mike42/escpos-php/src/cache/Characters-DefaultCapabilityProfile.ser.gz b/htdocs/includes/mike42/escpos-php/src/cache/Characters-DefaultCapabilityProfile.ser.gz deleted file mode 100644 index 43ad39d2295..00000000000 Binary files a/htdocs/includes/mike42/escpos-php/src/cache/Characters-DefaultCapabilityProfile.ser.gz and /dev/null differ diff --git a/htdocs/includes/mike42/escpos-php/src/cache/Characters-SimpleCapabilityProfile.ser.gz b/htdocs/includes/mike42/escpos-php/src/cache/Characters-SimpleCapabilityProfile.ser.gz deleted file mode 100644 index 288b7d37407..00000000000 Binary files a/htdocs/includes/mike42/escpos-php/src/cache/Characters-SimpleCapabilityProfile.ser.gz and /dev/null differ diff --git a/htdocs/includes/mike42/escpos-php/src/cache/Characters-StarCapabilityProfile.ser.gz b/htdocs/includes/mike42/escpos-php/src/cache/Characters-StarCapabilityProfile.ser.gz deleted file mode 100644 index e0bb0e5fec5..00000000000 Binary files a/htdocs/includes/mike42/escpos-php/src/cache/Characters-StarCapabilityProfile.ser.gz and /dev/null differ diff --git a/htdocs/includes/mike42/escpos-php/test/bootstrap.php b/htdocs/includes/mike42/escpos-php/test/bootstrap.php index 41b04f5ca6b..749629ac4af 100644 --- a/htdocs/includes/mike42/escpos-php/test/bootstrap.php +++ b/htdocs/includes/mike42/escpos-php/test/bootstrap.php @@ -2,26 +2,39 @@ error_reporting(E_ALL); ini_set('display_errors', 1); -require_once(dirname(__FILE__) . "/../vendor/autoload.php"); -require_once(dirname(__FILE__) . "/../Escpos.php"); -require_once(dirname(__FILE__) . "/../src/DummyPrintConnector.php"); +$composer_autoload = __DIR__ . "/../vendor/autoload.php"; +$standalone_autoload = __DIR__ . "/../autoload.php"; + +if (file_exists($composer_autoload)) { + require_once($composer_autoload); +} else { + require_once($standalone_autoload); +} /** * Used in many of the tests to to output known-correct - * strings for use in tests. + * strings for use in tests. */ -function friendlyBinary($in) { - if(strlen($in) == 0) { - return $in; - } - /* Print out binary data with PHP \x00 escape codes, +function friendlyBinary($in) +{ + if (is_array($in)) { + $out = array(); + foreach ($in as $line) { + $out[] = friendlyBinary($line); + } + return "[" . implode(", ", $out) . "]"; + } + if (strlen($in) == 0) { + return $in; + } + /* Print out binary data with PHP \x00 escape codes, for builting test cases. */ - $chars = str_split($in); - foreach($chars as $i => $c) { - $code = ord($c); - if($code < 32 || $code > 126) { - $chars[$i] = "\\x" . bin2hex($c); - } - } - return implode($chars); + $chars = str_split($in); + foreach ($chars as $i => $c) { + $code = ord($c); + if ($code < 32 || $code > 126) { + $chars[$i] = "\\x" . bin2hex($c); + } + } + return implode($chars); } diff --git a/htdocs/includes/mike42/escpos-php/test/integration/ExampleTest.php b/htdocs/includes/mike42/escpos-php/test/integration/ExampleTest.php index 689891e2432..6ba8e23e59e 100644 --- a/htdocs/includes/mike42/escpos-php/test/integration/ExampleTest.php +++ b/htdocs/includes/mike42/escpos-php/test/integration/ExampleTest.php @@ -1,126 +1,187 @@ exampleDir = dirname(__FILE__) . "/../../example/"; - } - - public function testBitImage() { - $this -> requireGraphicsLibrary(); - $outp = $this -> runExample("bit-image.php"); - $this -> outpTest($outp, "bit-image.bin"); - } - - public function testCharacterEncodings() { - $outp = $this -> runExample("character-encodings.php"); - $this -> outpTest($outp, "character-encodings.bin"); - } - - public function testCharacterTables() { - $outp = $this -> runExample("character-tables.php"); - $this -> outpTest($outp, "character-tables.bin"); - } - - private function outpTest($outp, $fn) { - $file = dirname(__FILE__) . "/resources/output/".$fn; - if(!file_exists($file)) { - file_put_contents($file, $outp); - } - $this -> assertEquals($outp, file_get_contents($file)); - } - - public function testDemo() { - $this -> requireGraphicsLibrary(); - $outp = $this -> runExample("demo.php"); - $this -> outpTest($outp, "demo.bin"); - } - - public function testGraphics() { - $this -> requireGraphicsLibrary(); - $outp = $this -> runExample("graphics.php"); - $this -> outpTest($outp, "graphics.bin"); - } - - public function testReceiptWithLogo() { - $this -> requireGraphicsLibrary(); - $outp = $this -> runExample("receipt-with-logo.php"); - $this -> outpTest($outp, "receipt-with-logo.bin"); - } - - public function testQrCode() { - $outp = $this -> runExample("qr-code.php"); - $this -> outpTest($outp, "qr-code.bin"); - } +use Mike42\Escpos\EscposImage; - public function testBarcode() { - $outp = $this -> runExample("barcode.php"); - $this -> outpTest($outp, "barcode.bin"); - } - - public function testTextSize() { - $outp = $this -> runExample("text-size.php"); - $this -> outpTest($outp, "text-size.bin"); - } +class ExampleTest extends PHPUnit_Framework_TestCase +{ + /* Verify that the examples don't fizzle out with fatal errors */ + private $exampleDir; + + public function setup() + { + $this -> exampleDir = dirname(__FILE__) . "/../../example/"; + } + + /** + * @medium + */ + public function testBitImage() + { + $this->markTestSkipped('Not repeatable on Travis CI.'); + $this -> requireGraphicsLibrary(); + $outp = $this -> runExample("bit-image.php"); + $this -> outpTest($outp, "bit-image.bin"); + } + + /** + * @medium + */ + public function testCharacterEncodings() + { + $outp = $this -> runExample("character-encodings.php"); + $this -> outpTest($outp, "character-encodings.bin"); + } + + /** + * @medium + */ + public function testCharacterTables() + { + $outp = $this -> runExample("character-tables.php"); + $this -> outpTest($outp, "character-tables.bin"); + } + + private function outpTest($outp, $fn) + { + $file = dirname(__FILE__) . "/resources/output/".$fn; + if (!file_exists($file)) { + file_put_contents($file, $outp); + } + $this -> assertEquals($outp, file_get_contents($file)); + } + + /** + * @medium + */ + public function testDemo() + { + $this->markTestSkipped('Not repeatable on Travis CI.'); + $this -> requireGraphicsLibrary(); + $outp = $this -> runExample("demo.php"); + $this -> outpTest($outp, "demo.bin"); + } + + /** + * @medium + */ + public function testGraphics() + { + $this->markTestSkipped('Not repeatable on Travis CI.'); + $this -> requireGraphicsLibrary(); + $outp = $this -> runExample("graphics.php"); + $this -> outpTest($outp, "graphics.bin"); + } + + /** + * @medium + */ + public function testReceiptWithLogo() + { + $this->markTestSkipped('Not repeatable on Travis CI.'); + $this -> requireGraphicsLibrary(); + $outp = $this -> runExample("receipt-with-logo.php"); + $this -> outpTest($outp, "receipt-with-logo.bin"); + } + + /** + * @medium + */ + public function testQrCode() + { + $outp = $this -> runExample("qr-code.php"); + $this -> outpTest($outp, "qr-code.bin"); + } - /** - * @large - */ - public function testPrintFromPdf() { - if(!EscposImage::isImagickLoaded()) { - $this -> markTestSkipped("imagick plugin required for this test"); - } - $outp = $this -> runExample("print-from-pdf.php"); - $this -> outpTest(gzcompress($outp, 9), "print-from-pdf.bin.z"); // Compressing output because it's ~1MB - } + /** + * @medium + */ + public function testBarcode() + { + $outp = $this -> runExample("barcode.php"); + $this -> outpTest($outp, "barcode.bin"); + } + + /** + * @medium + */ + public function testTextSize() + { + $outp = $this -> runExample("text-size.php"); + $this -> outpTest($outp, "text-size.bin"); + } - public function testInterfaceEthernet() { - // Test attempts DNS lookup on some machine - $outp = $this -> runExample("interface/ethernet.php"); - $this -> outpTest($outp, "interface.bin"); - } - - public function testInterfaceLinuxUSB() { - $outp = $this -> runExample("interface/linux-usb.php"); - $this -> outpTest($outp, "interface.bin"); - } - - public function testInterfaceWindowsUSB() { - // Output varies between platforms, not checking. - $outp = $this -> runExample("interface/windows-usb.php"); - $this -> outpTest($outp, "interface.bin"); - } - - public function testInterfaceSMB() { - // Output varies between platforms, not checking. - $outp = $this -> runExample("interface/smb.php"); - $this -> outpTest($outp, "interface.bin"); - } - - public function testInterfaceWindowsLPT() { - // Output varies between platforms, not checking. - $outp = $this -> runExample("interface/windows-lpt.php"); - $this -> outpTest($outp, "interface.bin"); - } - - private function runExample($fn) { - // Change directory and check script - chdir($this -> exampleDir); - $this -> assertTrue(file_exists($fn), "Script $fn not found."); - // Run command and save output - ob_start(); - passthru("php " . escapeshellarg($fn), $retval); - $outp = ob_get_contents(); - ob_end_clean(); - // Check return value - $this -> assertEquals(0, $retval, "Example $fn exited with status $retval"); - return $outp; - } - - protected function requireGraphicsLibrary() { - if(!EscposImage::isGdLoaded() && !EscposImage::isImagickLoaded()) { - $this -> markTestSkipped("This test requires a graphics library."); - } - } + /** + * @medium + */ + public function testMarginsAndSpacing() + { + $outp = $this -> runExample("margins-and-spacing.php"); + $this -> outpTest($outp, "margins-and-spacing.bin"); + } + + /** + * @medium + */ + public function testPdf417Code() + { + $outp = $this -> runExample("pdf417-code.php"); + $this -> outpTest($outp, "pdf417-code.bin"); + } + + public function testInterfaceCups() + { + $outp = $this -> runSyntaxCheck("interface/cups.php"); + } + + public function testInterfaceEthernet() + { + $outp = $this -> runSyntaxCheck("interface/ethernet.php"); + } + + public function testInterfaceLinuxUSB() + { + $outp = $this -> runSyntaxCheck("interface/linux-usb.php"); + } + + public function testInterfaceWindowsUSB() + { + $outp = $this -> runSyntaxCheck("interface/windows-usb.php"); + } + + public function testInterfaceSMB() + { + $outp = $this -> runSyntaxCheck("interface/smb.php"); + } + + public function testInterfaceWindowsLPT() + { + $outp = $this -> runSyntaxCheck("interface/windows-lpt.php"); + } + + private function runSyntaxCheck($fn) + { + $this -> runExample($fn, true); + } + + private function runExample($fn, $syntaxCheck = false) + { + // Change directory and check script + chdir($this -> exampleDir); + $this -> assertTrue(file_exists($fn), "Script $fn not found."); + // Run command and save output + $php = "php" . ($syntaxCheck ? " -l" : ""); + ob_start(); + passthru($php . " " . escapeshellarg($fn), $retval); + $outp = ob_get_contents(); + ob_end_clean(); + // Check return value + $this -> assertEquals(0, $retval, "Example $fn exited with status $retval"); + return $outp; + } + + protected function requireGraphicsLibrary() + { + if (!EscposImage::isGdLoaded() && !EscposImage::isImagickLoaded()) { + $this -> markTestSkipped("This test requires a graphics library."); + } + } } diff --git a/htdocs/includes/mike42/escpos-php/test/integration/resources/output/barcode.bin b/htdocs/includes/mike42/escpos-php/test/integration/resources/output/barcode.bin index 79a2daf803e..ae4070d70a0 100644 Binary files a/htdocs/includes/mike42/escpos-php/test/integration/resources/output/barcode.bin and b/htdocs/includes/mike42/escpos-php/test/integration/resources/output/barcode.bin differ diff --git a/htdocs/includes/mike42/escpos-php/test/integration/resources/output/character-encodings.bin b/htdocs/includes/mike42/escpos-php/test/integration/resources/output/character-encodings.bin index 0a762c8c160..f93ea377722 100644 Binary files a/htdocs/includes/mike42/escpos-php/test/integration/resources/output/character-encodings.bin and b/htdocs/includes/mike42/escpos-php/test/integration/resources/output/character-encodings.bin differ diff --git a/htdocs/includes/mike42/escpos-php/test/integration/resources/output/character-tables.bin b/htdocs/includes/mike42/escpos-php/test/integration/resources/output/character-tables.bin index f3fb990cea3..9979e46bdd5 100644 Binary files a/htdocs/includes/mike42/escpos-php/test/integration/resources/output/character-tables.bin and b/htdocs/includes/mike42/escpos-php/test/integration/resources/output/character-tables.bin differ diff --git a/htdocs/includes/mike42/escpos-php/test/integration/resources/output/interface.bin b/htdocs/includes/mike42/escpos-php/test/integration/resources/output/interface.bin deleted file mode 100644 index 729d4f4481b..00000000000 --- a/htdocs/includes/mike42/escpos-php/test/integration/resources/output/interface.bin +++ /dev/null @@ -1,2 +0,0 @@ -@Hello World! -VA \ No newline at end of file diff --git a/htdocs/includes/mike42/escpos-php/test/integration/resources/output/margins-and-spacing.bin b/htdocs/includes/mike42/escpos-php/test/integration/resources/output/margins-and-spacing.bin new file mode 100644 index 00000000000..0b3a4676033 Binary files /dev/null and b/htdocs/includes/mike42/escpos-php/test/integration/resources/output/margins-and-spacing.bin differ diff --git a/htdocs/includes/mike42/escpos-php/test/integration/resources/output/pdf417-code.bin b/htdocs/includes/mike42/escpos-php/test/integration/resources/output/pdf417-code.bin new file mode 100644 index 00000000000..ab2d7c54958 Binary files /dev/null and b/htdocs/includes/mike42/escpos-php/test/integration/resources/output/pdf417-code.bin differ diff --git a/htdocs/includes/mike42/escpos-php/test/integration/resources/output/print-from-pdf.bin.z b/htdocs/includes/mike42/escpos-php/test/integration/resources/output/print-from-pdf.bin.z deleted file mode 100644 index f89eb5d2115..00000000000 Binary files a/htdocs/includes/mike42/escpos-php/test/integration/resources/output/print-from-pdf.bin.z and /dev/null differ diff --git a/htdocs/includes/mike42/escpos-php/test/phpunit.xml b/htdocs/includes/mike42/escpos-php/test/phpunit.xml deleted file mode 100644 index f9a6579cf45..00000000000 --- a/htdocs/includes/mike42/escpos-php/test/phpunit.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - unit - - - integration - - - \ No newline at end of file diff --git a/htdocs/includes/mike42/escpos-php/test/unit/AbstractCapabilityProfileTest.php b/htdocs/includes/mike42/escpos-php/test/unit/AbstractCapabilityProfileTest.php deleted file mode 100644 index b3e72452a9f..00000000000 --- a/htdocs/includes/mike42/escpos-php/test/unit/AbstractCapabilityProfileTest.php +++ /dev/null @@ -1,69 +0,0 @@ - profiles = array('DefaultCapabilityProfile', 'EposTepCapabilityProfile', 'SimpleCapabilityProfile', 'StarCapabilityProfile', 'P822DCapabilityProfile'); - $this -> checklist = array(); - foreach($this -> profiles as $profile) { - $this-> checklist[] = $profile::getInstance(); - } - } - - function testSupportedCodePages() { - foreach($this -> checklist as $obj) { - $check = $obj -> getSupportedCodePages(); - $this -> assertTrue(is_array($check) && isset($check[0]) && $check[0] == 'CP437'); - $custom = $obj -> getCustomCodePages(); - foreach($check as $num => $page) { - $this -> assertTrue(is_numeric($num) && ($page === false || is_string($page))); - if($page === false || strpos($page, ":") === false) { - continue; - } - $part = explode(":", $page); - if(!array_shift($part) == "custom") { - continue; - } - $this -> assertTrue(isset($custom[implode(":", $part)])); - } - } - } - - function testCustomCodePages() { - foreach($this -> checklist as $obj) { - $check = $obj -> getCustomCodePages(); - $this -> assertTrue(is_array($check)); - foreach($check as $name => $customMap) { - $this -> assertTrue(is_string($name)); - $this -> assertTrue(is_string($customMap) && mb_strlen($customMap, 'UTF-8') == 128); - } - } - } - - function testSupportsBitImage() { - foreach($this -> checklist as $obj) { - $check = $obj -> getSupportsBitImage(); - $this -> assertTrue(is_bool($check)); - } - } - - function testSupportsGraphics() { - foreach($this -> checklist as $obj) { - $check = $obj -> getSupportsGraphics(); - $this -> assertTrue(is_bool($check)); - } - } - - function testSupportsQrCode() { - foreach($this -> checklist as $obj) { - $check = $obj -> getSupportsQrCode(); - $this -> assertTrue(is_bool($check)); - } - } -} -?> \ No newline at end of file diff --git a/htdocs/includes/mike42/escpos-php/test/unit/AuresCustomerDisplayTest.php b/htdocs/includes/mike42/escpos-php/test/unit/AuresCustomerDisplayTest.php new file mode 100644 index 00000000000..c0f803afa97 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/test/unit/AuresCustomerDisplayTest.php @@ -0,0 +1,76 @@ + outputConnector = new DummyPrintConnector(); + $profile = CapabilityProfile::load('OCD-300'); + $this -> printer = new AuresCustomerDisplay($this -> outputConnector, $profile); + } + + protected function checkOutput($expected = null) + { + /* Check those output strings */ + $outp = $this -> outputConnector -> getData(); + if ($expected === null) { + echo "\nOutput was:\n\"" . friendlyBinary($outp) . "\"\n"; + } + $this -> assertEquals($expected, $outp); + } + + protected function tearDown() + { + $this -> outputConnector -> finalize(); + } + + public function testInitializeOutput() + { + $this -> checkOutput("\x02\x05C1\x03\x1b@\x1bt\x00\x1f\x02"); + } + + public function testselectTextScrollMode() { + $this -> outputConnector -> clear(); + $this -> printer -> selectTextScrollMode(AuresCustomerDisplay::TEXT_OVERWRITE); + $this -> checkOutput("\x1f\x01"); + } + + public function testClear() { + $this -> outputConnector -> clear(); + $this -> printer -> clear(); + $this -> checkOutput("\x0c"); + } + + public function testShowFirmwareVersion() { + $this -> outputConnector -> clear(); + $this -> printer -> showFirmwareVersion(); + $this -> checkOutput("\x02\x05V\x01\x03"); + } + + public function testSelfTest() { + $this -> outputConnector -> clear(); + $this -> printer -> selfTest(); + $this -> checkOutput("\x02\x05D\x08\x03"); + } + + public function testShowLogo() { + $this -> outputConnector -> clear(); + $this -> printer -> showLogo(); + $this -> checkOutput("\x02\xfcU\xaaU\xaa"); + } + + public function testTest() { + $this -> outputConnector -> clear(); + // Handling of line-endings differs to regular printers, need to use \r\n + $this -> printer -> text("Hello\nWorld\n"); + $this -> checkOutput("Hello\x0d\x0aWorld\x0d\x0a"); + } +} \ No newline at end of file diff --git a/htdocs/includes/mike42/escpos-php/test/unit/CapabilityProfileTest.php b/htdocs/includes/mike42/escpos-php/test/unit/CapabilityProfileTest.php new file mode 100644 index 00000000000..923811e7042 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/test/unit/CapabilityProfileTest.php @@ -0,0 +1,59 @@ +assertFalse(array_search('simple', $names) === false); + $this->assertFalse(array_search('default', $names) === false); + $this->assertTrue(array_search('lalalalala', $names) === false); + } + + public function testLoadDefault() + { + // Just load the default profile and check it out + $profile = CapabilityProfile::load('default'); + $this->assertEquals("default", $profile->getId()); + $this->assertEquals("Default", $profile->getName()); + $this->assertTrue($profile->getSupportsBarcodeB()); + $this->assertTrue($profile->getSupportsBitImageRaster()); + $this->assertTrue($profile->getSupportsGraphics()); + $this->assertTrue($profile->getSupportsQrCode()); + $this->assertTrue($profile->getSupportsPdf417Code()); + $this->assertFalse($profile->getSupportsStarCommands()); + $this->assertArrayHasKey('0', $profile->getCodePages()); + } + + public function testCodePageCacheKey() + { + $default = CapabilityProfile::load('default'); + $simple = CapabilityProfile::load('simple'); + $this->assertNotEquals($default->getCodePageCacheKey(), $simple->getCodePageCacheKey()); + } + + public function testBadProfileNameSuggestion() + { + $this->setExpectedException('\InvalidArgumentException', 'simple'); + $profile = CapabilityProfile::load('simpel'); + } + + public function testBadFeatureNameSuggestion() + { + $this->setExpectedException('\InvalidArgumentException', 'graphics'); + $profile = CapabilityProfile::load('default'); + $profile->getFeature('graphicx'); + } + + public function testSuggestions() + { + $input = "orangee"; + $choices = array("apple", "orange", "pear"); + $suggestions = CapabilityProfile::suggestNearest($input, $choices, 1); + $this->assertEquals(1, count($suggestions)); + $this->assertEquals("orange", $suggestions[0]); + } +} \ No newline at end of file diff --git a/htdocs/includes/mike42/escpos-php/test/unit/CodePageTest.php b/htdocs/includes/mike42/escpos-php/test/unit/CodePageTest.php new file mode 100644 index 00000000000..0e7b661f94d --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/test/unit/CodePageTest.php @@ -0,0 +1,63 @@ +markTestSkipped("Requires iconv"); + } + } + + public function testDataIconv() + { + // Set up CP437 + $this->requiresIconv(); + $cp = new CodePage("CP437", array( + "name" => "CP437", + "iconv" => "CP437" + )); + $this->assertTrue($cp->isEncodable()); + $this->assertEquals($cp->getIconv(), "CP437"); + $this->assertEquals($cp->getName(), "CP437"); + $this->assertEquals($cp->getId(), "CP437"); + $this->assertEquals($cp->getNotes(), null); + // Get data and see if it's right + $data = $cp->getData(); + $expected = "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ "; + $this->assertEquals($expected, $data); + } + + public function testDataIconvBogus() + { + // No errors raised, you just get an empty list of supported characters if you try to compute a fake code page + $this->requiresIconv(); + $cp = new CodePage("foo", array( + "name" => "foo", + "iconv" => "foo" + )); + $this->assertTrue($cp->isEncodable()); + $this->assertEquals($cp->getIconv(), "foo"); + $this->assertEquals($cp->getName(), "foo"); + $this->assertEquals($cp->getId(), "foo"); + $this->assertEquals($cp->getNotes(), null); + $data = $cp->getData(); + $expected = str_repeat(" ", 128); + $this->assertEquals($expected, $data); + // Do this twice (caching behaviour) + $data = $cp->getData(); + $this->assertEquals($expected, $data); + } + + public function testDataCannotEncode() + { + $this->setExpectedException('\InvalidArgumentException'); + $cp = new CodePage("foo", array( + "name" => "foo" + )); + $this->assertFalse($cp->isEncodable()); + $cp->getData(); + } +} \ No newline at end of file diff --git a/htdocs/includes/mike42/escpos-php/test/unit/CupsPrintConnectorTest.php b/htdocs/includes/mike42/escpos-php/test/unit/CupsPrintConnectorTest.php new file mode 100644 index 00000000000..41499ee4b27 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/test/unit/CupsPrintConnectorTest.php @@ -0,0 +1,36 @@ +getMockConnector("FooPrinter", array("FooPrinter")); + $connector->expects($this->once())->method('getCmdOutput')->with($this->stringContains("lp -d 'FooPrinter' ")); + $connector->finalize(); + } + public function testPrinterDoesntExist() + { + $this -> setExpectedException('BadMethodCallException'); + $connector = $this->getMockConnector("FooPrinter", array("OtherPrinter")); + $connector->expects($this->once())->method('getCmdOutput')->with($this->stringContains("lp -d 'FooPrinter' ")); + $connector->finalize(); + } + public function testNoPrinter() + { + $this -> setExpectedException('BadMethodCallException'); + $connector = $this->getMockConnector("FooPrinter", array("")); + } + private function getMockConnector($path, array $printers) + { + $stub = $this->getMockBuilder('Mike42\Escpos\PrintConnectors\CupsPrintConnector')->setMethods(array ( + 'getCmdOutput', + 'getLocalPrinters' + ))->disableOriginalConstructor()->getMock(); + $stub->method('getCmdOutput')->willReturn(""); + $stub->method('getLocalPrinters')->willReturn($printers); + $stub->__construct($path); + return $stub; + } +} diff --git a/htdocs/includes/mike42/escpos-php/test/unit/EscposImageTest.php b/htdocs/includes/mike42/escpos-php/test/unit/EscposImageTest.php index f152f400a2f..08e1be91c50 100644 --- a/htdocs/includes/mike42/escpos-php/test/unit/EscposImageTest.php +++ b/htdocs/includes/mike42/escpos-php/test/unit/EscposImageTest.php @@ -1,235 +1,16 @@ loadAndCheckImg(null, false, false, 0, 0, ""); - } +use Mike42\Escpos\EscposImage; - /** - * BMP handling not yet implemented, but these will use - * a native PHP bitmap reader. - * This just tests that they are not being passed on to another library. - */ - public function testBmpBadFilename() { - $this -> setExpectedException('Exception'); - $this -> loadAndCheckImg('not a real file.bmp', false, false, 1, 1, "\x80"); - } - - public function testBmpBlack() { - $this -> setExpectedException('Exception'); - $this -> loadAndCheckImg("canvas_black.bmp", false, false, 0, 0, "\x80"); - } - - public function testBmpBlackWhite() { - $this -> setExpectedException('Exception'); - $this -> loadAndCheckImg("black_white.bmp", false, false, 0, 0, "\xc0\x00"); - } - - public function testBmpWhite() { - $this -> setExpectedException('Exception'); - $this -> loadAndCheckImg("canvas_white.bmp", false, false, 0, 0, "\x00"); - } - - /** - * GD tests - Load tiny images and check how they are printed. - * These are skipped if you don't have gd. - */ - public function testGdBadFilename() { - $this -> setExpectedException('Exception'); - $this -> loadAndCheckImg('not a real file.png', true, false, 1, 1, "\x80"); - } - - public function testGdBlack() { - foreach(array('png', 'jpg', 'gif') as $format) { - $this -> loadAndCheckImg('canvas_black.' . $format, true, false, 1, 1, "\x80"); - } - } - - public function testGdBlackTransparent() { - foreach(array('png', 'gif') as $format) { - $this -> loadAndCheckImg('black_transparent.' . $format, true, false, 2, 2, "\xc0\x00"); - } - } - - public function testGdBlackWhite() { - foreach(array('png', 'jpg', 'gif') as $format) { - $this -> loadAndCheckImg('black_white.' . $format, true, false, 2, 2, "\xc0\x00"); - } - } - - public function testGdWhite() { - foreach(array('png', 'jpg', 'gif') as $format) { - $this -> loadAndCheckImg('canvas_white.' . $format, true, false, 1, 1, "\x00"); - } - } - - /** - * Imagick tests - Load tiny images and check how they are printed - * These are skipped if you don't have imagick - */ - public function testImagickBadFilename() { - $this -> setExpectedException('Exception'); - $this -> loadAndCheckImg('not a real file.png', false, true, 1, 1, "\x80"); - } - - public function testImagickBlack() { - foreach(array('png', 'jpg', 'gif') as $format) { - $this -> loadAndCheckImg('canvas_black.' . $format, false, true, 1, 1, "\x80"); - } - } - - public function testImagickBlackTransparent() { - foreach(array('png', 'gif') as $format) { - $this -> loadAndCheckImg('black_transparent.' . $format, false, true, 2, 2, "\xc0\x00"); - } - } - - public function testImagickBlackWhite() { - foreach(array('png', 'jpg', 'gif') as $format) { - $this -> loadAndCheckImg('black_white.' . $format, false, true, 2, 2, "\xc0\x00"); - } - } - - public function testImagickWhite() { - foreach(array('png', 'jpg', 'gif') as $format) { - $this -> loadAndCheckImg('canvas_white.' . $format, false, true, 1, 1, "\x00"); - } - } - - /** - * Mixed test - Same as above, but confirms that each tiny image can be loaded - * under any supported library configuration with the same results. - * These are skipped if you don't have gd AND imagick - */ - public function testLibraryDifferences() { - if(!EscposImage::isGdLoaded() || !EscposImage::isImagickLoaded()) { - $this -> markTestSkipped("both gd and imagick plugin are required for this test"); - } - $inFile = array('black_white.png', 'canvas_black.png', 'canvas_white.png'); - foreach($inFile as $fn) { - // Default check - $im = new EscposImage(dirname(__FILE__) . "/resources/$fn"); - $width = $im -> getWidth(); - $height = $im -> getHeight(); - $data = $im -> toRasterFormat(); - // Gd check - $this -> loadAndCheckImg($fn, true, false, $width, $height, $data); - // Imagick check - $this -> loadAndCheckImg($fn, false, true, $width, $height, $data); - } - } - - /** - * PDF tests - load tiny PDF and check for well-formedness - * These are also skipped if you don't have imagick - * @medium - */ - public function testPdfAllPages() { - $this -> loadAndCheckPdf('doc.pdf', null, 1, 1, array("\x00", "\x80")); - } - - public function testPdfBadFilename() { - $this -> setExpectedException('Exception'); - $this -> loadAndCheckPdf('not a real file', null, 1, 1, array()); - } - - /** - * @medium - */ - public function testPdfBadRange() { - // Start page is after end page. - $this -> setExpectedException('Exception'); - $this -> loadAndCheckPdf('doc.pdf', array(1, 0), 1, 1, array("\x00", "\x80")); - } - - /** - * @medium - */ - public function testPdfFirstPage() { - $this -> loadAndCheckPdf('doc.pdf', array(0, 0), 1, 1, array("\x00")); - } - - /** - * @medium - */ - public function testPdfMorePages() { - $this -> loadAndCheckPdf('doc.pdf', array(1, 20), 1, 1, array("\x80")); - } - - /** - * @medium - */ - public function testPdfSecondPage() { - $this -> loadAndCheckPdf('doc.pdf', array(1, 1), 1, 1, array("\x80")); - } - - /** - * @medium - */ - public function testPdfStartPastEndOfDoc() { - // Doc only has pages 0 and 1, can't start reading from 2. - $this -> markTestIncomplete("Test needs revising- produces output due to apparent imagick bug."); - $this -> setExpectedException('ImagickException'); - $this -> loadAndCheckPdf('doc.pdf', array(2, 3), 1, 1, array()); - } - - /** - * Load an EscposImage with (optionally) certain libraries disabled and run a check. - */ - private function loadAndCheckImg($fn, $gd, $imagick, $width, $height, $rasterFormat = null) { - $img = $this -> getMockImage($fn === null ? null : dirname(__FILE__) . "/resources/$fn", $gd, $imagick); - $this -> checkImg($img, $width, $height, $rasterFormat); - } - - /** - * Same as above, loading document and checking pages against some expected values. - */ - private function loadAndCheckPdf($fn, array $range = null, $width, $height, array $rasterFormat = null) { - if(!EscposImage::isImagickLoaded()) { - $this -> markTestSkipped("imagick plugin required for this test"); - } - $pdfPages = EscposImage::loadPdf(dirname(__FILE__) . "/resources/$fn", $width, $range); - $this -> assertTrue(count($pdfPages) == count($rasterFormat), "Got back wrong number of pages"); - foreach($pdfPages as $id => $img) { - $this -> checkImg($img, $width, $height, $rasterFormat[$id]); - } - } - - /** - * Check image against known width, height, output. - */ - private function checkImg(EscposImage $img, $width, $height, $rasterFormat = null) { - if($rasterFormat === null) { - echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", data \"" . friendlyBinary($img -> toRasterFormat()) . "\""; - } - $this -> assertTrue($img -> getHeight() == $height); - $this -> assertTrue($img -> getWidth() == $width); - $this -> assertTrue($img -> toRasterFormat() == $rasterFormat); - } - - /** - * Load up an EsposImage with given libraries disabled or enabled. Marks the test - * as skipped if you ask for a library which is not loaded. - */ - private function getMockImage($path, $gd, $imagick) { - /* Sanity checks */ - if($gd && !EscposImage::isGdLoaded()) { - $this -> markTestSkipped("gd plugin required for this test"); - } - if($imagick && !EscposImage::isImagickLoaded()) { - $this -> markTestSkipped("imagick plugin required for this test"); - } - $stub = $this -> getMockBuilder('EscposImage') - -> setMethods(array('isGdSupported', 'isImagickSupported')) - -> disableOriginalConstructor() - -> getMock(); - $stub -> method('isGdSupported') - -> willReturn($gd); - $stub -> method('isImagickSupported') - -> willReturn($imagick); - $stub -> __construct($path); - return $stub; - } +class EscposImageTest extends PHPUnit_Framework_TestCase +{ + public function testImageMissingException() + { + $this -> setExpectedException('Exception'); + $img = EscposImage::load('not-a-real-file.png'); + } + public function testImageNotSupportedException() + { + $this -> setExpectedException('InvalidArgumentException'); + $img = EscposImage::load('/dev/null', false, array()); + } } \ No newline at end of file diff --git a/htdocs/includes/mike42/escpos-php/test/unit/EscposPrintBufferTest.php b/htdocs/includes/mike42/escpos-php/test/unit/EscposPrintBufferTest.php index 2bbdb34c20c..af0ee2b9b73 100644 --- a/htdocs/includes/mike42/escpos-php/test/unit/EscposPrintBufferTest.php +++ b/htdocs/includes/mike42/escpos-php/test/unit/EscposPrintBufferTest.php @@ -2,149 +2,191 @@ /** * Example strings are pangrams using different character sets, and are * testing correct code-table switching. - * + * * When printed, they should appear the same as in this source file. - * + * * Many of these test strings are from: * - http://www.cl.cam.ac.uk/~mgk25/ucs/examples/quickbrown.txt * - http://clagnut.com/blog/2380/ (mirrored from the English Wikipedia) */ -class EscposPrintBufferTest extends PHPUnit_Framework_TestCase { - protected $buffer; - protected $outputConnector; - - protected function setup() { - $this -> outputConnector = new DummyPrintConnector(); - $printer = new Escpos($this -> outputConnector); - $this -> buffer = $printer -> getPrintBuffer(); - } - - protected function checkOutput($expected = null) { - /* Check those output strings */ - $outp = $this -> outputConnector -> getData(); - if($expected === null) { - echo "\nOutput was:\n\"" . friendlyBinary($outp) . "\"\n"; - } - $this -> assertEquals($expected, $outp); - } +use Mike42\Escpos\Printer; +use Mike42\Escpos\PrintConnectors\DummyPrintConnector; - protected function tearDown() { - $this -> outputConnector -> finalize(); - } +class EscposPrintBufferTest extends PHPUnit_Framework_TestCase +{ + protected $buffer; + protected $outputConnector; + + protected function setup() + { + $this -> outputConnector = new DummyPrintConnector(); + $printer = new Printer($this -> outputConnector); + $this -> buffer = $printer -> getPrintBuffer(); + } + + protected function checkOutput($expected = null) + { + /* Check those output strings */ + $outp = $this -> outputConnector -> getData(); + if ($expected === null) { + echo "\nOutput was:\n\"" . friendlyBinary($outp) . "\"\n"; + } + $this -> assertEquals($expected, $outp); + } - public function testRawTextNonprintable() { - $this -> buffer -> writeTextRaw("Test" . Escpos::ESC . "v1\n"); - $this -> checkOutput("\x1b@Test?v1\x0a"); // ASCII ESC character is substituted for '?' - } + protected function tearDown() + { + $this -> outputConnector -> finalize(); + } - public function testDanish() { - $this -> buffer -> writeText("Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon.\n"); - $this -> checkOutput("\x1b@Quizdeltagerne spiste jordb\x91r med fl\x1bt\x02\x9bde, mens cirkusklovnen Wolther spillede p\x86 xylofon.\x0a"); - } + public function testRawTextNonprintable() + { + $this -> buffer -> writeTextRaw("Test" . Printer::ESC . "v1\n"); + $this -> checkOutput("\x1b@Test?v1\x0a"); // ASCII ESC character is substituted for '?' + } - public function testGerman() { - $this -> buffer -> writeText("Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.\n"); - $this -> checkOutput("\x1b@Falsches \x9aben von Xylophonmusik qu\x84lt jeden gr\x94\xe1eren Zwerg.\x0a"); - } + public function testDanish() + { + $this -> buffer -> writeText("Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon.\n"); + $this -> checkOutput("\x1b@Quizdeltagerne spiste jordb\x91r med fl\x1bt\x02\x9bde, mens cirkusklovnen Wolther spillede p\x86 xylofon.\x0a"); + } - public function testGreek() { - $this -> buffer -> writeText("Ξεσκεπάζω την ψυχοφθόρα βδελυγμία"); - $this -> checkOutput("\x1b@\x1bt\x0b\xbd\xde\xec\xe4\xde\xea\x9b\xe0\xfa \xee\xe1\xe7 \xf6\xf2\xf4\xe9\xf3\xe2\xa2\xeb\xd6 \xd7\xdd\xde\xe5\xf2\xd8\xe6\x9f\xd6"); - } - - public function testGreekWithDiacritics() { - // This is a string which is known to be un-printable in ESC/POS (the grave-accented letters are not in any code page), - // so we are checking the substitution '?' for unknown characters. - $this -> buffer -> writeText("Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο.\n"); - $this -> checkOutput("\x1b@\xe2\xe0\x1bt\x0b\xe0\x9d\xde\xed \xe4\xd6? \xe6\xf2\xeb\xee\xe3?\xed \xdd?\xe7 \xe2? \xd7\xeb? \xea\xe3? \xec\xee? \xf4\xeb\xf2\xec\xd6\xf3? \xe8\x9d\xf3\xfa\xee\xe9.\x0a"); - } + public function testGerman() + { + $this -> buffer -> writeText("Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.\n"); + $this -> checkOutput("\x1b@Falsches \x9aben von Xylophonmusik qu\x84lt jeden gr\x94\xe1eren Zwerg.\x0a"); + } - public function testEnglish() { - $this -> buffer -> writeText("The quick brown fox jumps over the lazy dog.\n"); - $this -> checkOutput("\x1b@The quick brown fox jumps over the lazy dog.\n"); - } + public function testGreek() + { + $this -> buffer -> writeText("Ξεσκεπάζω την ψυχοφθόρα βδελυγμία"); + $this -> checkOutput("\x1b@\x1bt\x0e\x8d\x9c\xa9\xa1\x9c\xa7\xe1\x9d\xe0 \xab\x9e\xa4 \xaf\xac\xae\xa6\xad\x9f\xe6\xa8\x98 \x99\x9b\x9c\xa2\xac\x9a\xa3\xe5\x98"); + } - public function testSpanish() { - // This one does not require changing code-pages at all, so characters are just converted from Unicode to CP437. - $this -> buffer -> writeText("El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.\n"); - $this -> checkOutput("\x1b@El ping\x81ino Wenceslao hizo kil\xa2metros bajo exhaustiva lluvia y fr\xa1o, a\xa4oraba a su querido cachorro.\x0a"); - } + public function testGreekWithDiacritics() + { + // This is a string which is known to be un-printable in ESC/POS (the grave-accented letters are not in any code page), + // so we are checking the substitution '?' for unknown characters. + $this -> buffer -> writeText("Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο.\n"); + $this -> checkOutput("\x1b@\xe2\xe0\x1bt\x0e\x9d\xe2\x9c\xaa \xa1\x98? \xa3\xac\xa8\xab\xa0?\xaa \x9b?\xa4 \x9f? \x99\xa8? \xa7\xa0? \xa9\xab? \xae\xa8\xac\xa9\x98\xad? \xa5\xe2\xad\xe0\xab\xa6.\x0a"); + } - public function testFrench() { - $this -> buffer -> writeText("Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälström où brûlent les novæ.\n"); - $this -> checkOutput("\x1b@Le c\x1bt\x10\x9cur d\xe9\xe7u mais l'\xe2me plut\xf4t na\xefve, Lou\xffs r\xeava de crapa\xfcter en cano\xeb au del\xe0 des \xeeles, pr\xe8s du m\xe4lstr\xf6m o\xf9 br\xfblent les nov\xe6.\x0a"); - } + public function testEnglish() + { + $this -> buffer -> writeText("The quick brown fox jumps over the lazy dog.\n"); + $this -> checkOutput("\x1b@The quick brown fox jumps over the lazy dog.\n"); + } - public function testIrishGaelic() { - // Note that some letters with diacritics cannot be printed for Irish Gaelic text, so text may need to be simplified. - $this -> buffer -> writeText("D'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh.\n"); - $this -> checkOutput("\x1b@D'fhuascail \x1bt\x02\xd6osa, \xe9rmhac na h\xe0ighe Beannaithe, p\xa2r \x90ava agus \xb5dhaimh.\x0a"); - } + public function testSpanish() + { + // This one does not require changing code-pages at all, so characters are just converted from Unicode to CP437. + $this -> buffer -> writeText("El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.\n"); + $this -> checkOutput("\x1b@El ping\x81ino Wenceslao hizo kil\xa2metros bajo exhaustiva lluvia y fr\xa1o, a\xa4oraba a su querido cachorro.\x0a"); + } - public function testHungarian() { - $this -> buffer -> writeText("Árvíztűrő tükörfúrógép.\n"); - $this -> checkOutput("\x1b@\x1bt\x02\xb5rv\xa1zt\x1bt\x12\xfbr\x8b t\x81k\x94rf\xa3r\xa2g\x82p.\x0a"); - } - - public function testIcelandic() { - $this -> buffer -> writeText("Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa."); - $this -> checkOutput("\x1b@K\x91mi n\x1bt\x02\xec \x94xi h\x82r ykist \xe7j\xa2fum n\xa3 b\x91\xd0i v\xa1l og \xa0drepa."); - } + public function testFrench() + { + $this -> buffer -> writeText("Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälström où brûlent les novæ.\n"); + $this -> checkOutput("\x1b@Le c\x1bt\x10\x9cur d\xe9\xe7u mais l'\xe2me plut\xf4t na\xefve, Lou\xffs r\xeava de crapa\xfcter en cano\xeb au del\xe0 des \xeeles, pr\xe8s du m\xe4lstr\xf6m o\xf9 br\xfblent les nov\xe6.\x0a"); + } - public function testJapaneseHiragana() { - $this -> markTestIncomplete("Non-ASCII character sets not yet supported."); - $this -> buffer -> writeText(implode("\n", array("いろはにほへとちりぬるを", " わかよたれそつねならむ", "うゐのおくやまけふこえて", "あさきゆめみしゑひもせす")) . "\n"); - $this -> checkOutput(); - } + public function testIrishGaelic() + { + // Note that some letters with diacritics cannot be printed for Irish Gaelic text, so text may need to be simplified. + $this -> buffer -> writeText("D'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh.\n"); + $this -> checkOutput("\x1b@D'fhuascail \x1bt\x02\xd6osa, \xe9rmhac na h\xe0ighe Beannaithe, p\xa2r \x90ava agus \xb5dhaimh.\x0a"); + } - public function testJapaneseKatakana() { - $this -> markTestIncomplete("Non-ASCII character sets not yet supported."); - $this -> buffer -> writeText(implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン")) . "\n"); - $this -> checkOutput("\x1b@\x1bt\x01\xb2\xdb\xca\xc6\xce\xcd\xc4 \xc1\xd8\xc7\xd9\xa6 \xdc\xb6\xd6\xc0\xda\xbf \xc2\xc8\xc5\xd7\xd1\x0a\xb3\xb2\xc9\xb5\xb8\xd4\xcf \xb9\xcc\xba\xb4\xc3 \xb1\xbb\xb7\xd5\xd2\xd0\xbc \xb4\xcb\xd3\xbe\xbd\xdd\x0a"); - } + public function testHungarian() + { + $this -> buffer -> writeText("Árvíztűrő tükörfúrógép.\n"); + $this -> checkOutput("\x1b@\x1bt\x02\xb5rv\xa1zt\x1bt\x12\xfbr\x8b t\x81k\x94rf\xa3r\xa2g\x82p.\x0a"); + } + + public function testIcelandic() + { + $this -> buffer -> writeText("Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa."); + $this -> checkOutput("\x1b@K\x91mi n\x1bt\x02\xec \x94xi h\x82r ykist \xe7j\xa2fum n\xa3 b\x91\xd0i v\xa1l og \xa0drepa."); + } - public function testJapaneseKataKanaHalfWidth() { - $this -> buffer -> writeText(implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウイノオクヤマ ケフコエテ アサキユメミシ エヒモセスン")) . "\n"); - $this -> checkOutput("\x1b@\x1bt\x01\xb2\xdb\xca\xc6\xce\xcd\xc4 \xc1\xd8\xc7\xd9\xa6 \xdc\xb6\xd6\xc0\xda\xbf \xc2\xc8\xc5\xd7\xd1\x0a\xb3\xb2\xc9\xb5\xb8\xd4\xcf \xb9\xcc\xba\xb4\xc3 \xb1\xbb\xb7\xd5\xd2\xd0\xbc \xb4\xcb\xd3\xbe\xbd\xdd\x0a"); - } - - public function testLatvian() { - $this -> buffer -> writeText("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus.\n"); - $this -> checkOutput("\x1b@Gl\x1bt!\x83\xd8\xd5\xe9\xd7\xeca r\xd7\xe9\x8c\xd5i dz\x89rum\x83 \xd1iepj Baha koncertfl\x8c\x85e\xebu v\x83kus.\x0a"); - } + public function testJapaneseHiragana() + { + $this -> markTestIncomplete("Non-ASCII character sets not yet supported."); + $this -> buffer -> writeText(implode("\n", array("いろはにほへとちりぬるを", " わかよたれそつねならむ", "うゐのおくやまけふこえて", "あさきゆめみしゑひもせす")) . "\n"); + $this -> checkOutput(); + } - public function testPolish() { - $this -> buffer -> writeText("Pchnąć w tę łódź jeża lub ośm skrzyń fig.\n"); - $this -> checkOutput("\x1b@Pchn\x1bt\x12\xa5\x86 w t\xa9 \x88\xa2d\xab je\xbea lub o\x98m skrzy\xe4 fig.\x0a"); - } + public function testJapaneseKatakana() + { + $this -> markTestIncomplete("Non-ASCII character sets not yet supported."); + $this -> buffer -> writeText(implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン")) . "\n"); + $this -> checkOutput("\x1b@\x1bt\x01\xb2\xdb\xca\xc6\xce\xcd\xc4 \xc1\xd8\xc7\xd9\xa6 \xdc\xb6\xd6\xc0\xda\xbf \xc2\xc8\xc5\xd7\xd1\x0a\xb3\xb2\xc9\xb5\xb8\xd4\xcf \xb9\xcc\xba\xb4\xc3 \xb1\xbb\xb7\xd5\xd2\xd0\xbc \xb4\xcb\xd3\xbe\xbd\xdd\x0a"); + } - public function testRussian() { - $this -> buffer -> writeText("В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!\n"); - $this -> checkOutput("\x1b@\x1bt\x11\x82 \xe7\xa0\xe9\xa0\xe5 \xee\xa3\xa0 \xa6\xa8\xab \xa1\xeb \xe6\xa8\xe2\xe0\xe3\xe1? \x84\xa0, \xad\xae \xe4\xa0\xab\xec\xe8\xa8\xa2\xeb\xa9 \xed\xaa\xa7\xa5\xac\xaf\xab\xef\xe0!\x0a"); - } + public function testJapaneseKataKanaHalfWidth() + { + $this -> buffer -> writeText(implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウイノオクヤマ ケフコエテ アサキユメミシ エヒモセスン")) . "\n"); + $this -> checkOutput("\x1b@\x1bt\x01\xb2\xdb\xca\xc6\xce\xcd\xc4 \xc1\xd8\xc7\xd9\xa6 \xdc\xb6\xd6\xc0\xda\xbf \xc2\xc8\xc5\xd7\xd1\x0a\xb3\xb2\xc9\xb5\xb8\xd4\xcf \xb9\xcc\xba\xb4\xc3 \xb1\xbb\xb7\xd5\xd2\xd0\xbc \xb4\xcb\xd3\xbe\xbd\xdd\x0a"); + } + + public function testLatvian() + { + $this -> buffer -> writeText("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus.\n"); + $this -> checkOutput("\x1b@Gl\x1bt!\x83\xd8\xd5\xe9\xd7\xeca r\xd7\xe9\x8c\xd5i dz\x89rum\x83 \xd1iepj Baha koncertfl\x8c\x85e\xebu v\x83kus.\x0a"); + } - public function testThai() { - $this -> markTestIncomplete("Non-ASCII character sets not yet supported."); - $this -> buffer -> writeText("นายสังฆภัณฑ์ เฮงพิทักษ์ฝั่ง ผู้เฒ่าซึ่งมีอาชีพเป็นฅนขายฃวด ถูกตำรวจปฏิบัติการจับฟ้องศาล ฐานลักนาฬิกาคุณหญิงฉัตรชฎา ฌานสมาธิ\n"); // Quotation from Wikipedia - $this -> checkOutput(); - } + public function testPolish() + { + $this -> buffer -> writeText("Pchnąć w tę łódź jeża lub ośm skrzyń fig.\n"); + $this -> checkOutput("\x1b@Pchn\x1bt\x12\xa5\x86 w t\xa9 \x88\xa2d\xab je\xbea lub o\x98m skrzy\xe4 fig.\x0a"); + } - public function testTurkish() { - $this -> buffer -> writeText("Pijamalı hasta, yağız şoföre çabucak güvendi.\n"); - $this -> checkOutput("\x1b@Pijamal\x1bt\x02\xd5 hasta, ya\x1bt\x0d\xa7\x8dz \x9fof\x94re \x87abucak g\x81vendi.\x0a"); - } - - public function testArabic() { - $this -> markTestIncomplete("Right-to-left text not yet supported."); - $this -> buffer -> writeText("صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ" . "\n"); // Quotation from Wikipedia - $this -> checkOutput(); - } - - public function testHebrew() { - // RTL text is more complex than the above. - $this -> markTestIncomplete("Right-to-left text not yet supported."); - $this -> buffer -> writeText("דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה" . "\n"); - $this -> checkOutput(); - } + public function testRussian() + { + $this -> buffer -> writeText("В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!\n"); + $this -> checkOutput("\x1b@\x1bt\x11\x82 \xe7\xa0\xe9\xa0\xe5 \xee\xa3\xa0 \xa6\xa8\xab \xa1\xeb \xe6\xa8\xe2\xe0\xe3\xe1? \x84\xa0, \xad\xae \xe4\xa0\xab\xec\xe8\xa8\xa2\xeb\xa9 \xed\xaa\xa7\xa5\xac\xaf\xab\xef\xe0!\x0a"); + } + + public function testThai() + { + $this -> markTestIncomplete("Non-ASCII character sets not yet supported."); + $this -> buffer -> writeText("นายสังฆภัณฑ์ เฮงพิทักษ์ฝั่ง ผู้เฒ่าซึ่งมีอาชีพเป็นฅนขายฃวด ถูกตำรวจปฏิบัติการจับฟ้องศาล ฐานลักนาฬิกาคุณหญิงฉัตรชฎา ฌานสมาธิ\n"); // Quotation from Wikipedia + $this -> checkOutput(); + } + + public function testTurkish() + { + $this -> buffer -> writeText("Pijamalı hasta, yağız şoföre çabucak güvendi.\n"); + $this -> checkOutput("\x1b@Pijamal\x1bt\x02\xd5 hasta, ya\x1bt\x0d\xa7\x8dz \x9fof\x94re \x87abucak g\x81vendi.\x0a"); + } + + public function testArabic() + { + $this -> markTestIncomplete("Right-to-left text not yet supported."); + $this -> buffer -> writeText("صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ" . "\n"); // Quotation from Wikipedia + $this -> checkOutput(); + } + + public function testHebrew() + { + // RTL text is more complex than the above. + $this -> markTestIncomplete("Right-to-left text not yet supported."); + $this -> buffer -> writeText("דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה" . "\n"); + $this -> checkOutput(); + } + + public function testVietnamese() { + $this -> buffer -> writeText("Tiếng Việt, còn gọi tiếng Việt Nam hay Việt ngữ, là ngôn ngữ của người Việt (người Kinh) và là ngôn ngữ chính thức tại Việt Nam.\n"); + $this -> checkOutput("\x1b@Ti\x1bt\x1e\xd5ng Vi\xd6t, c\xdfn g\xe4i ti\xd5ng Vi\xd6t Nam hay Vi\xd6t ng\xf7, l\xb5 ng\xabn ng\xf7 c\xf1a ng\xad\xeai Vi\xd6t (ng\xad\xeai Kinh) v\xb5 l\xb5 ng\xabn ng\xf7 ch\xddnh th\xf8c t\xb9i Vi\xd6t Nam.\x0a"); + } + + public function testWindowsLineEndings() { + $this -> buffer -> writeText("Hello World!\r\n"); + $this -> checkOutput("\x1b@Hello World!\x0a"); + } + + public function testWindowsLineEndingsRaw() { + $this -> buffer -> writeTextRaw("Hello World!\r\n"); + $this -> checkOutput("\x1b@Hello World!\x0a"); + } } - diff --git a/htdocs/includes/mike42/escpos-php/test/unit/EscposTest.php b/htdocs/includes/mike42/escpos-php/test/unit/EscposTest.php index 6fd0bd7d204..0b70e96b370 100644 --- a/htdocs/includes/mike42/escpos-php/test/unit/EscposTest.php +++ b/htdocs/includes/mike42/escpos-php/test/unit/EscposTest.php @@ -1,765 +1,1127 @@ outputConnector = new DummyPrintConnector(); - $this -> printer = new Escpos($this -> outputConnector); - } +class EscposTest extends PHPUnit_Framework_TestCase +{ + protected $printer; + protected $outputConnector; - protected function checkOutput($expected = null) { - /* Check those output strings */ - $outp = $this -> outputConnector -> getData(); - if($expected === null) { - echo "\nOutput was:\n\"" . friendlyBinary($outp) . "\"\n"; - } - $this -> assertEquals($expected, $outp); - } - - protected function tearDown() { - $this -> outputConnector -> finalize(); - } - - protected function requireGraphicsLibrary() { - if(!EscposImage::isGdLoaded() && !EscposImage::isImagickLoaded()) { - // If the test is about to do something which requires a library, - // something must throw an exception. - $this -> setExpectedException('Exception'); - } - } - - public function testInitializeOutput() { - $this -> checkOutput("\x1b\x40"); + protected function setup() + { + /* Print to nowhere- for testing which inputs are accepted */ + $this -> outputConnector = new DummyPrintConnector(); + $this -> printer = new Printer($this -> outputConnector); } - public function testTextStringOutput() { - $this -> printer -> text("The quick brown fox jumps over the lazy dog\n"); - $this -> checkOutput("\x1b@The quick brown fox jumps over the lazy dog\n"); + protected function checkOutput($expected = null) + { + /* Check those output strings */ + $outp = $this -> outputConnector -> getData(); + if ($expected === null) { + echo "\nOutput was:\n\"" . friendlyBinary($outp) . "\"\n"; + } + $this -> assertEquals($expected, $outp); } - public function testTextDefault() { - $this -> printer -> text(); - $this -> checkOutput("\x1b@"); + protected function tearDown() + { + $this -> outputConnector -> finalize(); } - public function testTextString() { - $this -> printer -> text("String"); - $this -> printer -> text(123); - $this -> printer -> text(); - $this -> printer -> text(null); - $this -> printer -> text(1.2); - $this -> printer -> text(new FooBar("FooBar")); - $this -> checkOutput("\x1b@String1231.2FooBar"); + protected function requireGraphicsLibrary() + { + if (!EscposImage::isGdLoaded() && !EscposImage::isImagickLoaded()) { + // If the test is about to do something which requires a library, + // something must throw an exception. + $this -> setExpectedException('Exception'); + } } - public function testTextObject() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> text(new DateTime()); - } - - public function testFeedDefault() { - $this -> printer -> feed(); - $this -> checkOutput("\x1b@\x0a"); + public function testInitializeOutput() + { + $this -> checkOutput("\x1b\x40"); } - public function testFeed3Lines() { - $this -> printer -> feed(3); - $this -> checkOutput("\x1b@\x1bd\x03"); + public function testTextStringOutput() + { + $this -> printer -> text("The quick brown fox jumps over the lazy dog\n"); + $this -> checkOutput("\x1b@The quick brown fox jumps over the lazy dog\n"); } - public function testFeedZero() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> feed(0); + public function testTextDefault() + { + $this -> printer -> text(); + $this -> checkOutput("\x1b@"); + } + + public function testTextChinese() + { + // Switch to chinese print mode, GBK output, switch back to alphanumeric. + $this -> printer -> textChinese("示例文本打印机!\n"); + $this -> checkOutput("\x1b@\x1c&\xca\xbe\xc0\xfd\xce\xc4\xb1\xbe\xb4\xf2\xd3\xa1\xbb\xfa!\x0a\x1c."); + } + + public function testTextRaw() + { + // Under raw output, the raw bytes are sent to the printer, so typing a UTF-8 euro literally causes \xE2 \x82 \xAC to be sent. + // Under text(), this would cause a code-page change (to a page that contains a Euro symbol), and single byte. + $this -> printer -> textRaw("€\n"); + $this -> checkOutput("\x1b@\xe2\x82\xac\x0a"); } - public function testFeedNonInteger() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> feed("ab"); + public function testTextString() + { + $this -> printer -> text("String"); + $this -> printer -> text(123); + $this -> printer -> text(); + $this -> printer -> text(null); + $this -> printer -> text(1.2); + $this -> printer -> text(new FooBar("FooBar")); + $this -> checkOutput("\x1b@String1231.2FooBar"); } - public function testFeedTooLarge() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> feed(256); - } - - /* Print mode */ - public function testSelectPrintModeDefault() { - $this -> printer -> selectPrintMode(); - $this -> checkOutput("\x1b@\x1b!\x00"); + public function testTextObject() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> text(new DateTime()); } - public function testSelectPrintModeAcceptedValues() { - /* This iterates over a bunch of numbers, figures out which + public function testFeedDefault() + { + $this -> printer -> feed(); + $this -> checkOutput("\x1b@\x0a"); + } + + public function testFeed3Lines() + { + $this -> printer -> feed(3); + $this -> checkOutput("\x1b@\x1bd\x03"); + } + + public function testFeedZero() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> feed(0); + } + + public function testFeedNonInteger() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> feed("ab"); + } + + public function testFeedTooLarge() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> feed(256); + } + + /* Print mode */ + public function testSelectPrintModeDefault() + { + $this -> printer -> selectPrintMode(); + $this -> checkOutput("\x1b@\x1b!\x00"); + } + + public function testSelectPrintModeAcceptedValues() + { + /* This iterates over a bunch of numbers, figures out which ones contain invalid flags, and checks that the driver rejects those, but accepts the good inputs */ - - for($i = -1; $i <= 256; $i++) { - $invalid = ($i < 0) || ($i > 255) || (($i & 2) == 2) || (($i & 4) == 4) || (($i & 64) == 64); - $failed = false; - try { - $this -> printer -> selectPrintMode($i); - } catch(Exception $e) { - $failed = true; - } - $this -> assertEquals($failed, $invalid); - } + + for ($i = -1; $i <= 256; $i++) { + $invalid = ($i < 0) || ($i > 255) || (($i & 2) == 2) || (($i & 4) == 4) || (($i & 64) == 64); + $failed = false; + try { + $this -> printer -> selectPrintMode($i); + } catch (Exception $e) { + $failed = true; + } + $this -> assertEquals($failed, $invalid); + } } - /* Underline */ - public function testSetUnderlineDefault() { - $this -> printer -> setUnderline(); - $this -> checkOutput("\x1b@\x1b-\x01"); + /* Underline */ + public function testSetUnderlineDefault() + { + $this -> printer -> setUnderline(); + $this -> checkOutput("\x1b@\x1b-\x01"); } - public function testSetUnderlineOff() { - $this -> printer -> setUnderline(Escpos::UNDERLINE_NONE); - $this -> checkOutput("\x1b@\x1b-\x00"); + public function testSetUnderlineOff() + { + $this -> printer -> setUnderline(Printer::UNDERLINE_NONE); + $this -> checkOutput("\x1b@\x1b-\x00"); } - public function testSetUnderlineOn() { - $this -> printer -> setUnderline(Escpos::UNDERLINE_SINGLE); - $this -> checkOutput("\x1b@\x1b-\x01"); + public function testSetUnderlineOn() + { + $this -> printer -> setUnderline(Printer::UNDERLINE_SINGLE); + $this -> checkOutput("\x1b@\x1b-\x01"); } - public function testSetUnderlineDbl() { - $this -> printer -> setUnderline(Escpos::UNDERLINE_DOUBLE); - $this -> checkOutput("\x1b@\x1b-\x02"); + public function testSetUnderlineDbl() + { + $this -> printer -> setUnderline(Printer::UNDERLINE_DOUBLE); + $this -> checkOutput("\x1b@\x1b-\x02"); } - public function testSetUnderlineAcceptedValues() { - $this -> printer -> setUnderline(0); - $this -> printer -> setUnderline(1); - $this -> printer -> setUnderline(2); - /* These map to 0 & 1 for interchangeability with setEmphasis */ - $this -> printer -> setUnderline(true); - $this -> printer -> setUnderline(false); - $this -> checkOutput("\x1b@\x1b-\x00\x1b-\x01\x1b-\x02\x1b-\x01\x1b-\x00"); - } - - public function testSetUnderlineTooLarge() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setUnderline(3); - } - - public function testSetUnderlineNegative() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setUnderline(-1); - } - - public function testSetUnderlineNonInteger() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setUnderline("Hello"); - } - - /* Emphasis */ - public function testSetEmphasisDefault() { - $this -> printer -> setEmphasis(); - $this -> checkOutput("\x1b@\x1bE\x01"); + public function testSetUnderlineAcceptedValues() + { + $this -> printer -> setUnderline(0); + $this -> printer -> setUnderline(1); + $this -> printer -> setUnderline(2); + /* These map to 0 & 1 for interchangeability with setEmphasis */ + $this -> printer -> setUnderline(true); + $this -> printer -> setUnderline(false); + $this -> checkOutput("\x1b@\x1b-\x00\x1b-\x01\x1b-\x02\x1b-\x01\x1b-\x00"); } - public function testSetEmphasisOn() { - $this -> printer -> setEmphasis(true); - $this -> checkOutput("\x1b@\x1bE\x01"); + public function testSetUnderlineTooLarge() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setUnderline(3); } - public function testSetEmphasisOff() { - $this -> printer -> setEmphasis(false); - $this -> checkOutput("\x1b@\x1bE\x00"); + public function testSetUnderlineNegative() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setUnderline(-1); } - public function testSetEmphasisNonBoolean() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setEmphasis(7); - } - - /* Double strike */ - public function testSetDoubleStrikeDefault() { - $this -> printer -> setDoubleStrike(); - $this -> checkOutput("\x1b@\x1bG\x01"); + public function testSetUnderlineNonInteger() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setUnderline("Hello"); } - public function testSetDoubleStrikeOn() { - $this -> printer -> setDoubleStrike(true); - $this -> checkOutput("\x1b@\x1bG\x01"); + /* Emphasis */ + public function testSetEmphasisDefault() + { + $this -> printer -> setEmphasis(); + $this -> checkOutput("\x1b@\x1bE\x01"); } - public function testSetDoubleStrikeOff() { - $this -> printer -> setDoubleStrike(false); - $this -> checkOutput("\x1b@\x1bG\x00"); + public function testSetEmphasisOn() + { + $this -> printer -> setEmphasis(true); + $this -> checkOutput("\x1b@\x1bE\x01"); } - public function testSetDoubleStrikeNonBoolean() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setDoubleStrike(4); - } - - /* Font */ - public function testSetFontDefault() { - $this -> printer -> setFont(); - $this -> checkOutput("\x1b@\x1bM\x00"); - } - - public function testSetFontAcceptedValues() { - $this -> printer -> setFont(Escpos::FONT_A); - $this -> printer -> setFont(Escpos::FONT_B); - $this -> printer -> setFont(Escpos::FONT_C); - $this -> checkOutput("\x1b@\x1bM\x00\x1bM\x01\x1bM\x02"); - } - - public function testSetFontNegative() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setFont(-1); - } - - - public function testSetFontTooLarge() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setFont(3); - } - - public function testSetFontNonInteger() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setFont('hello'); - } - - /* Justification */ - public function testSetJustificationDefault() { - $this -> printer -> setJustification(); - $this -> checkOutput("\x1b@\x1ba\x00"); - } - - public function testSetJustificationLeft() { - $this -> printer -> setJustification(Escpos::JUSTIFY_LEFT); - $this -> checkOutput("\x1b@\x1ba\x00"); - } - - public function testSetJustificationRight() { - $this -> printer -> setJustification(Escpos::JUSTIFY_RIGHT); - $this -> checkOutput("\x1b@\x1ba\x02"); - } - - public function testSetJustificationCenter() { - $this -> printer -> setJustification(Escpos::JUSTIFY_CENTER); - $this -> checkOutput("\x1b@\x1ba\x01"); - } - - public function testSetJustificationNegative() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setJustification(-1); - } - - - public function testSetJustificationTooLarge() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setFont(3); - } - - public function testSetJustificationNonInteger() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setJustification('hello'); - } - - /* Reverse feed */ - public function testFeedReverseDefault() { - $this -> printer -> feedReverse(); - $this -> checkOutput("\x1b@\x1be\x01"); - } - - public function testFeedReverse3() { - $this -> printer -> feedReverse(3); - $this -> checkOutput("\x1b@\x1be\x03"); - } - - public function testFeedReverseNegative() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> feedReverse(-1); - } - - public function testFeedReverseTooLarge() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> feedReverse(256); - } - - public function testFeedReverseNonInteger() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> feedReverse('hello'); - } - - /* Cut */ - public function testCutDefault() { - // TODO check what the accepted range of values should be for $line - // cut($mode = self::CUT_FULL, $lines = 3) - $this -> printer -> cut(); - $this -> checkOutput("\x1b@\x1dVA\x03"); - } - - /* Set barcode height */ - public function testSetBarcodeHeightDefault() { - $this -> printer -> setBarcodeHeight(); - $this -> checkOutput("\x1b@\x1dh\x08"); - } - - public function testBarcodeHeight10() { - $this -> printer -> setBarcodeHeight(10); - $this -> checkOutput("\x1b@\x1dh\x0a"); - } - - public function testSetBarcodeHeightNegative() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setBarcodeHeight(-1); - } - - public function testSetBarcodeHeightTooLarge() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setBarcodeHeight(256); - } - - public function tesSetBarcodeHeightNonInteger() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setBarcodeHeight('hello'); - } - - /* Barcode text position */ - public function testSetBarcodeTextPositionDefault() { - $this -> printer -> setBarcodeTextPosition(); - $this -> checkOutput("\x1b@\x1dH\x00"); - } - - public function testSetBarcodeTextPositionBelow() { - $this -> printer -> setBarcodeTextPosition(Escpos::BARCODE_TEXT_BELOW); - $this -> checkOutput("\x1b@\x1dH\x02"); - } - - public function testSetBarcodeTextPositionBoth() { - $this -> printer -> setBarcodeTextPosition(Escpos::BARCODE_TEXT_BELOW | Escpos::BARCODE_TEXT_ABOVE); - $this -> checkOutput("\x1b@\x1dH\x03"); - } - - public function testSetBarcodeTextPositionNegative() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setBarcodeTextPosition(-1); - } - - public function testSetBarcodeTextPositionTooLarge() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setBarcodeTextPosition(4); - } - - public function tesSetBarcodeTextPositionNonInteger() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setBarcodeTextPosition('hello'); - } - - /* Barcode - UPC-A */ - public function testBarcodeUpcaNumeric11Char() { - $this -> printer -> barcode("01234567890", Escpos::BARCODE_UPCA); - $this -> checkOutput("\x1b@\x1dkA\x0b01234567890"); - } - - public function testBarcodeUpcaNumeric12Char() { - $this -> printer -> barcode("012345678901", Escpos::BARCODE_UPCA); - $this -> checkOutput("\x1b@\x1dkA\x0c012345678901"); - } - - public function testBarcodeUpcaNumeric13Char() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("0123456789012", Escpos::BARCODE_UPCA); - } - - public function testBarcodeUpcaNonNumeric12Char() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("A12345678901", Escpos::BARCODE_UPCA); - } - - /* Barcode - UPC-E */ - public function testBarcodeUpceNumeric6Char() { - $this -> printer -> barcode("123456", Escpos::BARCODE_UPCE); - $this -> checkOutput("\x1b@\x1dkB\x06123456"); - } - - public function testBarcodeUpceNumeric7Char() { - $this -> printer -> barcode("0123456", Escpos::BARCODE_UPCE); - $this -> checkOutput("\x1b@\x1dkB\x070123456"); - } - - public function testBarcodeUpceNumeric8Char() { - $this -> printer -> barcode("01234567", Escpos::BARCODE_UPCE); - $this -> checkOutput("\x1b@\x1dkB\x0801234567"); - } - - public function testBarcodeUpceNumeric11Char() { - $this -> printer -> barcode("01234567890", Escpos::BARCODE_UPCE); - $this -> checkOutput("\x1b@\x1dkB\x0b01234567890"); - } - - public function testBarcodeUpceNumeric12Char() { - $this -> printer -> barcode("012345678901", Escpos::BARCODE_UPCE); - $this -> checkOutput("\x1b@\x1dkB\x0c012345678901"); - } - - public function testBarcodeUpceNumeric9Char() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("012345678", Escpos::BARCODE_UPCE); - } - - public function testBarcodeUpceNonNumeric12Char() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("A12345678901", Escpos::BARCODE_UPCE); - } - - /* Barcode - JAN13 */ - public function testBarcodeJan13Numeric12Char() { - $this -> printer -> barcode("012345678901", Escpos::BARCODE_JAN13); - $this -> checkOutput("\x1b@\x1dkC\x0c012345678901"); - } - - public function testBarcodeJan13Numeric13Char() { - $this -> printer -> barcode("0123456789012", Escpos::BARCODE_JAN13); - $this -> checkOutput("\x1b@\x1dkC\x0d0123456789012"); - } - - public function testBarcodeJan13Numeric11Char() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("01234567890", Escpos::BARCODE_JAN13); - } - - public function testBarcodeJan13NonNumeric13Char() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("A123456789012", Escpos::BARCODE_JAN13); - } - - /* Barcode - JAN8 */ - public function testBarcodeJan8Numeric7Char() { - $this -> printer -> barcode("0123456", Escpos::BARCODE_JAN8); - $this -> checkOutput("\x1b@\x1dkD\x070123456"); - } - - public function testBarcodeJan8Numeric8Char() { - $this -> printer -> barcode("01234567", Escpos::BARCODE_JAN8); - $this -> checkOutput("\x1b@\x1dkD\x0801234567"); - } - - public function testBarcodeJan8Numeric9Char() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("012345678", Escpos::BARCODE_JAN8); - } - - public function testBarcodeJan8NonNumeric8Char() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("A1234567", Escpos::BARCODE_JAN8); - } - - /* Barcode - Code39 */ - public function testBarcodeCode39AsDefault() { - $this -> printer -> barcode("1234"); - $this -> checkOutput("\x1b@\x1dkE\x041234"); - } - - public function testBarcodeCode39Text() { - $this -> printer -> barcode("ABC 012", Escpos::BARCODE_CODE39); - $this -> checkOutput("\x1b@\x1dkE\x07ABC 012"); - } - - public function testBarcodeCode39SpecialChars() { - $this -> printer -> barcode("$%+-./", Escpos::BARCODE_CODE39); - $this -> checkOutput("\x1b@\x1dkE\x06$%+-./"); - } - - public function testBarcodeCode39Asterisks() { - $this -> printer -> barcode("*TEXT*", Escpos::BARCODE_CODE39); - $this -> checkOutput("\x1b@\x1dkE\x06*TEXT*"); - } - - public function testBarcodeCode39AsterisksUnmatched() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("*TEXT", Escpos::BARCODE_CODE39); - } - - public function testBarcodeCode39AsteriskInText() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("12*34", Escpos::BARCODE_CODE39); - } - - public function testBarcodeCode39Lowercase() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("abcd", Escpos::BARCODE_CODE39); - } - - public function testBarcodeCode39Empty() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("**", Escpos::BARCODE_CODE39); - } - - /* Barcode - ITF */ - public function testBarcodeItfNumericEven() { - $this -> printer -> barcode("1234", Escpos::BARCODE_ITF); - $this -> checkOutput("\x1b@\x1dkF\x041234"); - } - - public function testBarcodeItfNumericOdd() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("123", Escpos::BARCODE_ITF); - } - - public function testBarcodeItfNonNumericEven() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("A234", Escpos::BARCODE_ITF); - } - - /* Barcode - Codabar */ - public function testBarcodeCodabarNumeric() { - $this -> printer -> barcode("A012345A", Escpos::BARCODE_CODABAR); - $this -> checkOutput("\x1b@\x1dkG\x08A012345A"); - } - - public function testBarcodeCodabarSpecialChars() { - $this -> printer -> barcode("A012$+-./:A", Escpos::BARCODE_CODABAR); - $this -> checkOutput("\x1b@\x1dkG\x0bA012$+-./:A"); - } - - public function testBarcodeCodabarNotWrapped() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("012345", Escpos::BARCODE_CODABAR); - } - - public function testBarcodeCodabarStartStopWrongPlace() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("012A45", Escpos::BARCODE_CODABAR); - } - - /* Barcode - Code93 */ - public function testBarcodeCode93Valid() { - $this -> printer -> barcode("012abcd", Escpos::BARCODE_CODE93); - $this -> checkOutput("\x1b@\x1dkH\x07012abcd"); - } - - public function testBarcodeCode93Empty() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("", Escpos::BARCODE_CODE93); - } - - /* Barcode - Code128 */ - public function testBarcodeCode128ValidA() { - $this -> printer -> barcode("{A" . "012ABCD", Escpos::BARCODE_CODE128); - $this -> checkOutput("\x1b@\x1dkI\x09{A012ABCD"); - } - - public function testBarcodeCode128ValidB() { - $this -> printer -> barcode("{B" . "012ABCDabcd", Escpos::BARCODE_CODE128); - $this -> checkOutput("\x1b@\x1dkI\x0d{B012ABCDabcd"); - } - - public function testBarcodeCode128ValidC() { - $this -> printer -> barcode("{C" . chr ( 21 ) . chr ( 32 ) . chr ( 43 ), Escpos::BARCODE_CODE128); - $this -> checkOutput("\x1b@\x1dkI\x05{C\x15 +"); - } - - public function testBarcodeCode128NoCodeSet() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> barcode("ABCD", Escpos::BARCODE_CODE128); - } - - /* Pulse */ - function testPulseDefault() { - $this -> printer -> pulse(); - $this -> checkOutput("\x1b@\x1bp0 printer -> pulse(1); - $this -> checkOutput("\x1b@\x1bp1 printer -> pulse(0, 2, 2); - $this -> checkOutput("\x1b@\x1bp0\x01\x01"); - } - - function testPulseOddMs() { - $this -> printer -> pulse(0, 3, 3); // Should be rounded down and give same output - $this -> checkOutput("\x1b@\x1bp0\x01\x01"); - } - - function testPulseTooHigh() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> pulse(0, 512, 2); - } - - function testPulseTooLow() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> pulse(0, 0, 2); - } - - function testPulseNotANumber() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> pulse("fish"); - } - - /* Set reverse */ - public function testSetReverseColorsDefault() { - $this -> printer -> setReverseColors(); - $this -> checkOutput("\x1b@\x1dB\x01"); + public function testSetEmphasisOff() + { + $this -> printer -> setEmphasis(false); + $this -> checkOutput("\x1b@\x1bE\x00"); } - public function testSetReverseColorsOn() { - $this -> printer -> setReverseColors(true); - $this -> checkOutput("\x1b@\x1dB\x01"); + public function testSetEmphasisNonBoolean() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setEmphasis(7); } - public function testSetReverseColorsOff() { - $this -> printer -> setReverseColors(false); - $this -> checkOutput("\x1b@\x1dB\x00"); + /* Double strike */ + public function testSetDoubleStrikeDefault() + { + $this -> printer -> setDoubleStrike(); + $this -> checkOutput("\x1b@\x1bG\x01"); } - public function testSetReverseColorsNonBoolean() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setReverseColors(7); - } + public function testSetDoubleStrikeOn() + { + $this -> printer -> setDoubleStrike(true); + $this -> checkOutput("\x1b@\x1bG\x01"); + } - /* Bit image print */ - public function testBitImageBlack() { - $this -> requireGraphicsLibrary(); - $img = new EscposImage(dirname(__FILE__)."/resources/canvas_black.png"); - $this -> printer -> bitImage($img); - $this -> checkOutput("\x1b@\x1dv0\x00\x01\x00\x01\x00\x80"); - } + public function testSetDoubleStrikeOff() + { + $this -> printer -> setDoubleStrike(false); + $this -> checkOutput("\x1b@\x1bG\x00"); + } - public function testBitImageWhite() { - $this -> requireGraphicsLibrary(); - $img = new EscposImage(dirname(__FILE__)."/resources/canvas_white.png"); - $this -> printer -> bitImage($img); - $this -> checkOutput("\x1b@\x1dv0\x00\x01\x00\x01\x00\x00"); - } - - public function testBitImageBoth() { - $this -> requireGraphicsLibrary(); - $img = new EscposImage(dirname(__FILE__)."/resources/black_white.png"); - $this -> printer -> bitImage($img); - $this -> checkOutput("\x1b@\x1dv0\x00\x01\x00\x02\x00\xc0\x00"); - } - - public function testBitImageTransparent() { - $this -> requireGraphicsLibrary(); - $img = new EscposImage(dirname(__FILE__)."/resources/black_transparent.png"); - $this -> printer -> bitImage($img); - $this -> checkOutput("\x1b@\x1dv0\x00\x01\x00\x02\x00\xc0\x00"); - } - - /* Graphics print */ - public function testGraphicsWhite() { - $this -> requireGraphicsLibrary(); - $img = new EscposImage(dirname(__FILE__)."/resources/canvas_white.png"); - $this -> printer -> graphics($img); - $this -> checkOutput("\x1b@\x1d(L\x0b\x000p0\x01\x011\x01\x00\x01\x00\x00\x1d(L\x02\x0002"); - } - - public function testGraphicsBlack() { - $this -> requireGraphicsLibrary(); - $img = new EscposImage(dirname(__FILE__)."/resources/canvas_black.png"); - $this -> printer -> graphics($img); - $this -> checkOutput("\x1b@\x1d(L\x0b\x000p0\x01\x011\x01\x00\x01\x00\x80\x1d(L\x02\x0002"); - } - - public function testGraphicsBoth() { - $this -> requireGraphicsLibrary(); - $img = new EscposImage(dirname(__FILE__)."/resources/black_white.png"); - $this -> printer -> graphics($img); - $this -> checkOutput("\x1b@\x1d(L\x0c\x000p0\x01\x011\x02\x00\x02\x00\xc0\x00\x1d(L\x02\x0002"); - } - - public function testGraphicsTransparent() { - $this -> requireGraphicsLibrary(); - $img = new EscposImage(dirname(__FILE__)."/resources/black_transparent.png"); - $this -> printer -> graphics($img); - $this -> checkOutput("\x1b@\x1d(L\x0c\x000p0\x01\x011\x02\x00\x02\x00\xc0\x00\x1d(L\x02\x0002"); - } + public function testSetDoubleStrikeNonBoolean() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setDoubleStrike(4); + } - /* QR code */ - public function testQRCodeDefaults() { - // Test will fail if default values change - $this -> printer -> qrCode("1234"); - $this -> checkOutput("\x1b@\x1d(k\x04\x001A2\x00\x1d(k\x03\x001C\x03\x1d(k\x03\x001E0\x1d(k\x07\x001P01234\x1d(k\x03\x001Q0"); - } - - public function testQRCodeDefaultsAreCorrect() { - // Below tests assume that defaults are as written here (output string should be same as above) - $this -> printer -> qrCode("1234", Escpos::QR_ECLEVEL_L, 3, Escpos::QR_MODEL_2); - $this -> checkOutput("\x1b@\x1d(k\x04\x001A2\x00\x1d(k\x03\x001C\x03\x1d(k\x03\x001E0\x1d(k\x07\x001P01234\x1d(k\x03\x001Q0"); - } - - public function testQRCodeEmpty() { - $this -> printer -> qrCode(''); - $this -> checkOutput("\x1b@"); // No commands actually sent - } - - public function testQRCodeChangeEC() { - $this -> printer -> qrCode("1234", Escpos::QR_ECLEVEL_H); - $this -> checkOutput("\x1b@\x1d(k\x04\x001A2\x00\x1d(k\x03\x001C\x03\x1d(k\x03\x001E3\x1d(k\x07\x001P01234\x1d(k\x03\x001Q0"); - } - - public function testQRCodeChangeSize() { - $this -> printer -> qrCode("1234", Escpos::QR_ECLEVEL_L, 7); - $this -> checkOutput("\x1b@\x1d(k\x04\x001A2\x00\x1d(k\x03\x001C\x07\x1d(k\x03\x001E0\x1d(k\x07\x001P01234\x1d(k\x03\x001Q0"); - } - - public function testQRCodeChangeModel() { - $this -> printer -> qrCode("1234", Escpos::QR_ECLEVEL_L, 3, Escpos::QR_MODEL_1); - $this -> checkOutput("\x1b@\x1d(k\x04\x001A1\x00\x1d(k\x03\x001C\x03\x1d(k\x03\x001E0\x1d(k\x07\x001P01234\x1d(k\x03\x001Q0"); - } + /* Font */ + public function testSetFontDefault() + { + $this -> printer -> setFont(); + $this -> checkOutput("\x1b@\x1bM\x00"); + } - /* Feed form - Required on page-mode only printers */ - public function testFeedForm() { - $this -> printer -> feedForm(); - $this -> checkOutput("\x1b@\x0c"); - } - - /* Get status */ - public function testGetStatus() { - $this -> markTestIncomplete("Status check test code not implemented."); - // TODO some unit testing here on statuses - // $a = $this -> printer -> getPrinterStatus(Escpos::STATUS_PRINTER); - } + public function testSetFontAcceptedValues() + { + $this -> printer -> setFont(Printer::FONT_A); + $this -> printer -> setFont(Printer::FONT_B); + $this -> printer -> setFont(Printer::FONT_C); + $this -> checkOutput("\x1b@\x1bM\x00\x1bM\x01\x1bM\x02"); + } - /* Set text size */ - public function testSetTextSizeNormal() { - $this -> printer -> setTextSize(1, 1); - $this -> checkOutput("\x1b@\x1d!\x00"); - } + public function testSetFontNegative() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setFont(-1); + } - public function testSetTextSizeWide() { - $this -> printer -> setTextSize(4, 1); - $this -> checkOutput("\x1b@\x1d!0"); - } - public function testSetTextSizeNarrow() { - $this -> printer -> setTextSize(1, 4); - $this -> checkOutput("\x1b@\x1d!\x03"); - } + public function testSetFontTooLarge() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setFont(3); + } - public function testSetTextSizeLarge() { - $this -> printer -> setTextSize(4, 4); - $this -> checkOutput("\x1b@\x1d!3"); - } + public function testSetFontNonInteger() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setFont('hello'); + } - public function testSetTextSizeInvalid() { - $this -> setExpectedException('InvalidArgumentException'); - $this -> printer -> setTextSize(0, 9); - } + /* Justification */ + public function testSetJustificationDefault() + { + $this -> printer -> setJustification(); + $this -> checkOutput("\x1b@\x1ba\x00"); + } + + public function testSetJustificationLeft() + { + $this -> printer -> setJustification(Printer::JUSTIFY_LEFT); + $this -> checkOutput("\x1b@\x1ba\x00"); + } + + public function testSetJustificationRight() + { + $this -> printer -> setJustification(Printer::JUSTIFY_RIGHT); + $this -> checkOutput("\x1b@\x1ba\x02"); + } + + public function testSetJustificationCenter() + { + $this -> printer -> setJustification(Printer::JUSTIFY_CENTER); + $this -> checkOutput("\x1b@\x1ba\x01"); + } + + public function testSetJustificationNegative() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setJustification(-1); + } + + + public function testSetJustificationTooLarge() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setFont(3); + } + + public function testSetJustificationNonInteger() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setJustification('hello'); + } + + /* Reverse feed */ + public function testFeedReverseDefault() + { + $this -> printer -> feedReverse(); + $this -> checkOutput("\x1b@\x1be\x01"); + } + + public function testFeedReverse3() + { + $this -> printer -> feedReverse(3); + $this -> checkOutput("\x1b@\x1be\x03"); + } + + public function testFeedReverseNegative() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> feedReverse(-1); + } + + public function testFeedReverseTooLarge() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> feedReverse(256); + } + + public function testFeedReverseNonInteger() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> feedReverse('hello'); + } + + /* Cut */ + public function testCutDefault() + { + // TODO check what the accepted range of values should be for $line + // cut($mode = self::CUT_FULL, $lines = 3) + $this -> printer -> cut(); + $this -> checkOutput("\x1b@\x1dVA\x03"); + } + + /* Set barcode height */ + public function testSetBarcodeHeightDefault() + { + $this -> printer -> setBarcodeHeight(); + $this -> checkOutput("\x1b@\x1dh\x08"); + } + + public function testBarcodeHeight10() + { + $this -> printer -> setBarcodeHeight(10); + $this -> checkOutput("\x1b@\x1dh\x0a"); + } + + public function testSetBarcodeHeightNegative() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setBarcodeHeight(-1); + } + + public function testSetBarcodeHeightTooLarge() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setBarcodeHeight(256); + } + + 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() + { + $this -> printer -> setBarcodeTextPosition(); + $this -> checkOutput("\x1b@\x1dH\x00"); + } + + public function testSetBarcodeTextPositionBelow() + { + $this -> printer -> setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW); + $this -> checkOutput("\x1b@\x1dH\x02"); + } + + public function testSetBarcodeTextPositionBoth() + { + $this -> printer -> setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW | Printer::BARCODE_TEXT_ABOVE); + $this -> checkOutput("\x1b@\x1dH\x03"); + } + + public function testSetBarcodeTextPositionNegative() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setBarcodeTextPosition(-1); + } + + public function testSetBarcodeTextPositionTooLarge() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setBarcodeTextPosition(4); + } + + public function tesSetBarcodeTextPositionNonInteger() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setBarcodeTextPosition('hello'); + } + + /* Barcode - UPC-A */ + public function testBarcodeUpcaNumeric11Char() + { + $this -> printer -> barcode("01234567890", Printer::BARCODE_UPCA); + $this -> checkOutput("\x1b@\x1dkA\x0b01234567890"); + } + + public function testBarcodeUpcaNumeric12Char() + { + $this -> printer -> barcode("012345678901", Printer::BARCODE_UPCA); + $this -> checkOutput("\x1b@\x1dkA\x0c012345678901"); + } + + public function testBarcodeUpcaNumeric13Char() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("0123456789012", Printer::BARCODE_UPCA); + } + + public function testBarcodeUpcaNonNumeric12Char() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("A12345678901", Printer::BARCODE_UPCA); + } + + /* Barcode - UPC-E */ + public function testBarcodeUpceNumeric6Char() + { + $this -> printer -> barcode("123456", Printer::BARCODE_UPCE); + $this -> checkOutput("\x1b@\x1dkB\x06123456"); + } + + public function testBarcodeUpceNumeric7Char() + { + $this -> printer -> barcode("0123456", Printer::BARCODE_UPCE); + $this -> checkOutput("\x1b@\x1dkB\x070123456"); + } + + public function testBarcodeUpceNumeric8Char() + { + $this -> printer -> barcode("01234567", Printer::BARCODE_UPCE); + $this -> checkOutput("\x1b@\x1dkB\x0801234567"); + } + + public function testBarcodeUpceNumeric11Char() + { + $this -> printer -> barcode("01234567890", Printer::BARCODE_UPCE); + $this -> checkOutput("\x1b@\x1dkB\x0b01234567890"); + } + + public function testBarcodeUpceNumeric12Char() + { + $this -> printer -> barcode("012345678901", Printer::BARCODE_UPCE); + $this -> checkOutput("\x1b@\x1dkB\x0c012345678901"); + } + + public function testBarcodeUpceNumeric9Char() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("012345678", Printer::BARCODE_UPCE); + } + + public function testBarcodeUpceNonNumeric12Char() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("A12345678901", Printer::BARCODE_UPCE); + } + + /* Barcode - JAN13 */ + public function testBarcodeJan13Numeric12Char() + { + $this -> printer -> barcode("012345678901", Printer::BARCODE_JAN13); + $this -> checkOutput("\x1b@\x1dkC\x0c012345678901"); + } + + public function testBarcodeJan13Numeric13Char() + { + $this -> printer -> barcode("0123456789012", Printer::BARCODE_JAN13); + $this -> checkOutput("\x1b@\x1dkC\x0d0123456789012"); + } + + public function testBarcodeJan13Numeric11Char() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("01234567890", Printer::BARCODE_JAN13); + } + + public function testBarcodeJan13NonNumeric13Char() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("A123456789012", Printer::BARCODE_JAN13); + } + + /* Barcode - JAN8 */ + public function testBarcodeJan8Numeric7Char() + { + $this -> printer -> barcode("0123456", Printer::BARCODE_JAN8); + $this -> checkOutput("\x1b@\x1dkD\x070123456"); + } + + public function testBarcodeJan8Numeric8Char() + { + $this -> printer -> barcode("01234567", Printer::BARCODE_JAN8); + $this -> checkOutput("\x1b@\x1dkD\x0801234567"); + } + + public function testBarcodeJan8Numeric9Char() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("012345678", Printer::BARCODE_JAN8); + } + + public function testBarcodeJan8NonNumeric8Char() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("A1234567", Printer::BARCODE_JAN8); + } + + /* Barcode - Code39 */ + public function testBarcodeCode39AsDefault() + { + $this -> printer -> barcode("1234"); + $this -> checkOutput("\x1b@\x1dkE\x041234"); + } + + public function testBarcodeCode39Text() + { + $this -> printer -> barcode("ABC 012", Printer::BARCODE_CODE39); + $this -> checkOutput("\x1b@\x1dkE\x07ABC 012"); + } + + public function testBarcodeCode39SpecialChars() + { + $this -> printer -> barcode("$%+-./", Printer::BARCODE_CODE39); + $this -> checkOutput("\x1b@\x1dkE\x06$%+-./"); + } + + public function testBarcodeCode39Asterisks() + { + $this -> printer -> barcode("*TEXT*", Printer::BARCODE_CODE39); + $this -> checkOutput("\x1b@\x1dkE\x06*TEXT*"); + } + + public function testBarcodeCode39AsterisksUnmatched() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("*TEXT", Printer::BARCODE_CODE39); + } + + public function testBarcodeCode39AsteriskInText() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("12*34", Printer::BARCODE_CODE39); + } + + public function testBarcodeCode39Lowercase() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("abcd", Printer::BARCODE_CODE39); + } + + public function testBarcodeCode39Empty() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("**", Printer::BARCODE_CODE39); + } + + /* Barcode - ITF */ + public function testBarcodeItfNumericEven() + { + $this -> printer -> barcode("1234", Printer::BARCODE_ITF); + $this -> checkOutput("\x1b@\x1dkF\x041234"); + } + + public function testBarcodeItfNumericOdd() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("123", Printer::BARCODE_ITF); + } + + public function testBarcodeItfNonNumericEven() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("A234", Printer::BARCODE_ITF); + } + + /* Barcode - Codabar */ + public function testBarcodeCodabarNumeric() + { + $this -> printer -> barcode("A012345A", Printer::BARCODE_CODABAR); + $this -> checkOutput("\x1b@\x1dkG\x08A012345A"); + } + + public function testBarcodeCodabarSpecialChars() + { + $this -> printer -> barcode("A012$+-./:A", Printer::BARCODE_CODABAR); + $this -> checkOutput("\x1b@\x1dkG\x0bA012$+-./:A"); + } + + public function testBarcodeCodabarNotWrapped() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("012345", Printer::BARCODE_CODABAR); + } + + public function testBarcodeCodabarStartStopWrongPlace() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("012A45", Printer::BARCODE_CODABAR); + } + + /* Barcode - Code93 */ + public function testBarcodeCode93Valid() + { + $this -> printer -> barcode("012abcd", Printer::BARCODE_CODE93); + $this -> checkOutput("\x1b@\x1dkH\x07012abcd"); + } + + public function testBarcodeCode93Empty() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("", Printer::BARCODE_CODE93); + } + + /* Barcode - Code128 */ + public function testBarcodeCode128ValidA() + { + $this -> printer -> barcode("{A" . "012ABCD", Printer::BARCODE_CODE128); + $this -> checkOutput("\x1b@\x1dkI\x09{A012ABCD"); + } + + public function testBarcodeCode128ValidB() + { + $this -> printer -> barcode("{B" . "012ABCDabcd", Printer::BARCODE_CODE128); + $this -> checkOutput("\x1b@\x1dkI\x0d{B012ABCDabcd"); + } + + public function testBarcodeCode128ValidC() + { + $this -> printer -> barcode("{C" . chr(21) . chr(32) . chr(43), Printer::BARCODE_CODE128); + $this -> checkOutput("\x1b@\x1dkI\x05{C\x15 +"); + } + + public function testBarcodeCode128NoCodeSet() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> barcode("ABCD", Printer::BARCODE_CODE128); + } + + /* Pulse */ + function testPulseDefault() + { + $this -> printer -> pulse(); + $this -> checkOutput("\x1b@\x1bp0 printer -> pulse(1); + $this -> checkOutput("\x1b@\x1bp1 printer -> pulse(0, 2, 2); + $this -> checkOutput("\x1b@\x1bp0\x01\x01"); + } + + function testPulseOddMs() + { + $this -> printer -> pulse(0, 3, 3); // Should be rounded down and give same output + $this -> checkOutput("\x1b@\x1bp0\x01\x01"); + } + + function testPulseTooHigh() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> pulse(0, 512, 2); + } + + function testPulseTooLow() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> pulse(0, 0, 2); + } + + function testPulseNotANumber() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> pulse("fish"); + } + + /* Set reverse */ + public function testSetReverseColorsDefault() + { + $this -> printer -> setReverseColors(); + $this -> checkOutput("\x1b@\x1dB\x01"); + } + + public function testSetReverseColorsOn() + { + $this -> printer -> setReverseColors(true); + $this -> checkOutput("\x1b@\x1dB\x01"); + } + + public function testSetReverseColorsOff() + { + $this -> printer -> setReverseColors(false); + $this -> checkOutput("\x1b@\x1dB\x00"); + } + + public function testSetReverseColorsNonBoolean() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setReverseColors(7); + } + + /* Bit image print */ + public function testBitImageBlack() + { + $this -> requireGraphicsLibrary(); + $img = EscposImage::load(dirname(__FILE__)."/resources/canvas_black.png"); + $this -> printer -> bitImage($img); + $this -> checkOutput("\x1b@\x1dv0\x00\x01\x00\x01\x00\x80"); + } + + public function testBitImageWhite() + { + $this -> requireGraphicsLibrary(); + $img = EscposImage::load(dirname(__FILE__)."/resources/canvas_white.png"); + $this -> printer -> bitImage($img); + $this -> checkOutput("\x1b@\x1dv0\x00\x01\x00\x01\x00\x00"); + } + + public function testBitImageBoth() + { + $this -> requireGraphicsLibrary(); + $img = EscposImage::load(dirname(__FILE__)."/resources/black_white.png"); + $this -> printer -> bitImage($img); + $this -> checkOutput("\x1b@\x1dv0\x00\x01\x00\x02\x00\xc0\x00"); + } + + public function testBitImageTransparent() + { + $this -> requireGraphicsLibrary(); + $img = EscposImage::load(dirname(__FILE__)."/resources/black_transparent.png"); + $this -> printer -> bitImage($img); + $this -> checkOutput("\x1b@\x1dv0\x00\x01\x00\x02\x00\xc0\x00"); + } + + /* Bit image column format */ + public function testBitImageColumnFormatBlack() + { + $this -> requireGraphicsLibrary(); + $img = EscposImage::load(dirname(__FILE__)."/resources/canvas_black.png"); + $this -> printer -> bitImageColumnFormat($img); + $this -> checkOutput("\x1b@\x1b3\x10\x1b*!\x01\x00\x80\x00\x00\x0a\x1b2"); + } + + public function testBitImageColumnFormatWhite() + { + $this -> requireGraphicsLibrary(); + $img = EscposImage::load(dirname(__FILE__)."/resources/canvas_white.png"); + $this -> printer -> bitImageColumnFormat($img); + $this -> checkOutput("\x1b@\x1b3\x10\x1b*!\x01\x00\x00\x00\x00\x0a\x1b2"); + } + + public function testBitImageColumnFormatBoth() + { + $this -> requireGraphicsLibrary(); + $img = EscposImage::load(dirname(__FILE__)."/resources/black_white.png"); + $this -> printer -> bitImageColumnFormat($img); + $this -> checkOutput("\x1b@\x1b3\x10\x1b*!\x02\x00\x80\x00\x00\x80\x00\x00\x0a\x1b2"); + } + + public function testBitImageColumnFormatTransparent() + { + $this -> requireGraphicsLibrary(); + $img = EscposImage::load(dirname(__FILE__)."/resources/black_transparent.png"); + $this -> printer -> bitImageColumnFormat($img); + $this -> checkOutput("\x1b@\x1b3\x10\x1b*!\x02\x00\x80\x00\x00\x80\x00\x00\x0a\x1b2"); + } + + /* Graphics print */ + public function testGraphicsWhite() + { + $this -> requireGraphicsLibrary(); + $img = EscposImage::load(dirname(__FILE__)."/resources/canvas_white.png"); + $this -> printer -> graphics($img); + $this -> checkOutput("\x1b@\x1d(L\x0b\x000p0\x01\x011\x01\x00\x01\x00\x00\x1d(L\x02\x0002"); + } + + public function testGraphicsBlack() + { + $this -> requireGraphicsLibrary(); + $img = EscposImage::load(dirname(__FILE__)."/resources/canvas_black.png"); + $this -> printer -> graphics($img); + $this -> checkOutput("\x1b@\x1d(L\x0b\x000p0\x01\x011\x01\x00\x01\x00\x80\x1d(L\x02\x0002"); + } + + public function testGraphicsBoth() + { + $this -> requireGraphicsLibrary(); + $img = EscposImage::load(dirname(__FILE__)."/resources/black_white.png"); + $this -> printer -> graphics($img); + $this -> checkOutput("\x1b@\x1d(L\x0c\x000p0\x01\x011\x02\x00\x02\x00\xc0\x00\x1d(L\x02\x0002"); + } + + public function testGraphicsTransparent() + { + $this -> requireGraphicsLibrary(); + $img = EscposImage::load(dirname(__FILE__)."/resources/black_transparent.png"); + $this -> printer -> graphics($img); + $this -> checkOutput("\x1b@\x1d(L\x0c\x000p0\x01\x011\x02\x00\x02\x00\xc0\x00\x1d(L\x02\x0002"); + } + + /* PDF417 code */ + public function testPdf417CodeDefaults() + { + $this -> printer -> pdf417Code("1234"); + $this -> checkOutput("\x1b@\x1d(k\x03\x000F\x00\x1d(k\x03\x000A\x00\x1d(k\x03\x000C\x03\x1d(k\x03\x000D\x03\x1d(k\x04\x000E1\x01\x1d(k\x07\x000P01234\x1d(k\x03\x000Q0"); + } + + public function testPdf417CodeEmpty() + { + $this -> printer -> pdf417Code(''); + $this -> checkOutput("\x1b@"); // No commands actually sent + } + + public function testPdf417CodeNotSupported() + { + $this -> setExpectedException('Exception'); + $profile = SimpleCapabilityProfile::getInstance(); + $this -> printer = new Printer($this -> outputConnector, $profile); + $this -> printer -> pdf417Code("1234"); + } + + public function testPdf417CodeChangeGeometry() + { + // 7-dot wide, 4-times height, 4 data columns + $this -> printer -> pdf417Code("1234", 7, 4, 4); + $this -> checkOutput("\x1b@\x1d(k\x03\x000F\x00\x1d(k\x03\x000A\x04\x1d(k\x03\x000C\x07\x1d(k\x03\x000D\x04\x1d(k\x04\x000E1\x01\x1d(k\x07\x000P01234\x1d(k\x03\x000Q0"); + } + + public function testPdf417CodeChangeErrorCorrection() + { + $this -> printer -> pdf417Code("1234", 3, 3, 0, 0.5); + $this -> checkOutput("\x1b@\x1d(k\x03\x000F\x00\x1d(k\x03\x000A\x00\x1d(k\x03\x000C\x03\x1d(k\x03\x000D\x03\x1d(k\x04\x000E1\x05\x1d(k\x07\x000P01234\x1d(k\x03\x000Q0"); + } + + public function testPdf417CodeChangeErrorCorrectionOutOfRange() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> pdf417Code("1234", 3, 3, 0, 5.0); + } + + public function testPdf417CodeChangeErrorCorrectionInvalid() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> pdf417Code("1234", 3, 3, 0, "Foobar"); + } + + public function testPdf417CodeChangeOption() + { + // Use the alternate truncated format + $this -> printer -> pdf417Code("1234", 3, 3, 0, 0.1, Printer::PDF417_TRUNCATED); + $this -> checkOutput("\x1b@\x1d(k\x03\x000F\x01\x1d(k\x03\x000A\x00\x1d(k\x03\x000C\x03\x1d(k\x03\x000D\x03\x1d(k\x04\x000E1\x01\x1d(k\x07\x000P01234\x1d(k\x03\x000Q0"); + } + + /* QR code */ + public function testQRCodeDefaults() + { + // Test will fail if default values change + $this -> printer -> qrCode("1234"); + $this -> checkOutput("\x1b@\x1d(k\x04\x001A2\x00\x1d(k\x03\x001C\x03\x1d(k\x03\x001E0\x1d(k\x07\x001P01234\x1d(k\x03\x001Q0"); + } + + public function testQRCodeDefaultsAreCorrect() + { + // Below tests assume that defaults are as written here (output string should be same as above) + $this -> printer -> qrCode("1234", Printer::QR_ECLEVEL_L, 3, Printer::QR_MODEL_2); + $this -> checkOutput("\x1b@\x1d(k\x04\x001A2\x00\x1d(k\x03\x001C\x03\x1d(k\x03\x001E0\x1d(k\x07\x001P01234\x1d(k\x03\x001Q0"); + } + + public function testQRCodeEmpty() + { + $this -> printer -> qrCode(''); + $this -> checkOutput("\x1b@"); // No commands actually sent + } + + public function testQRCodeChangeEC() + { + $this -> printer -> qrCode("1234", Printer::QR_ECLEVEL_H); + $this -> checkOutput("\x1b@\x1d(k\x04\x001A2\x00\x1d(k\x03\x001C\x03\x1d(k\x03\x001E3\x1d(k\x07\x001P01234\x1d(k\x03\x001Q0"); + } + + public function testQRCodeChangeSize() + { + $this -> printer -> qrCode("1234", Printer::QR_ECLEVEL_L, 7); + $this -> checkOutput("\x1b@\x1d(k\x04\x001A2\x00\x1d(k\x03\x001C\x07\x1d(k\x03\x001E0\x1d(k\x07\x001P01234\x1d(k\x03\x001Q0"); + } + + public function testQRCodeChangeModel() + { + $this -> printer -> qrCode("1234", Printer::QR_ECLEVEL_L, 3, Printer::QR_MODEL_1); + $this -> checkOutput("\x1b@\x1d(k\x04\x001A1\x00\x1d(k\x03\x001C\x03\x1d(k\x03\x001E0\x1d(k\x07\x001P01234\x1d(k\x03\x001Q0"); + } + + /* Feed form - Required on page-mode only printers */ + public function testFeedForm() + { + $this -> printer -> feedForm(); + $this -> checkOutput("\x1b@\x0c"); + } + + /* Release */ + public function testRelease() + { + $this -> printer -> release(); + $this -> checkOutput("\x1b@\x1b\x71"); + } + + /* Set text size */ + public function testSetTextSizeNormal() + { + $this -> printer -> setTextSize(1, 1); + $this -> checkOutput("\x1b@\x1d!\x00"); + } + + public function testSetTextSizeWide() + { + $this -> printer -> setTextSize(4, 1); + $this -> checkOutput("\x1b@\x1d!0"); + } + + public function testSetTextSizeNarrow() + { + $this -> printer -> setTextSize(1, 4); + $this -> checkOutput("\x1b@\x1d!\x03"); + } + + public function testSetTextSizeLarge() + { + $this -> printer -> setTextSize(4, 4); + $this -> checkOutput("\x1b@\x1d!3"); + } + + public function testSetTextSizeInvalid() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setTextSize(0, 9); + } + + /* Set color */ + public function testSetColorDefault() + { + $this -> printer -> setColor(Printer::COLOR_1); + $this -> checkOutput("\x1b@\x1br\x00"); + } + + public function testSetColorAlternative() + { + $this -> printer -> setColor(Printer::COLOR_2); + $this -> checkOutput("\x1b@\x1br\x01"); + } + + public function testSetColorInvalid() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setColor(3); + } + + /* Set line spacing */ + public function testSetLineSpacingDefault() + { + $this -> printer -> setLineSpacing(); + $this -> checkOutput("\x1b@\x1b2"); + } + + public function testSetLineSpacingInvalid() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setLineSpacing(300); + } + + public function testSetLineSpacingSmaller() + { + $this -> printer -> setLineSpacing(16); + $this -> checkOutput("\x1b@\x1b3\x10"); + } + + public function testSetLineSpacingLarger() + { + $this -> printer -> setLineSpacing(32); + $this -> checkOutput("\x1b@\x1b3\x20"); + } + + /* Set print width */ + public function testSetPrintWidthDefault() + { + $this -> printer -> setPrintWidth(); + $this -> checkOutput("\x1b@\x1dW\x00\x02"); + } + + public function testSetPrintWidthNarrow() + { + $this -> printer -> setPrintWidth(400); + $this -> checkOutput("\x1b@\x1dW\x90\x01"); + } + + public function testSetPrintWidthInvalid() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setPrintWidth(0); + } + + /* Set print left margin */ + public function testSetPrintLeftMarginDefault() + { + $this -> printer -> setPrintLeftMargin(); + $this -> checkOutput("\x1b@\x1dL\x00\x00"); + } + + public function testSetPrintLeftMarginWide() + { + $this -> printer -> setPrintLeftMargin(32); + $this -> checkOutput("\x1b@\x1dL\x20\x00"); + } + + public function testPrintLeftMarginInvalid() + { + $this -> setExpectedException('InvalidArgumentException'); + $this -> printer -> setPrintLeftMargin(70000); + $this -> checkOutput(); + } + + /* Upside-down print */ + public function testSetUpsideDown() + { + $this -> printer -> setUpsideDown(true); + $this -> checkOutput("\x1b@\x1b{\x01"); + } } /* * For testing that string-castable objects are handled */ -class FooBar { - private $foo; - public function __construct($foo) { - $this -> foo = $foo; - } - - public function __toString() { - return $this -> foo; - } +class FooBar +{ + private $foo; + public function __construct($foo) + { + $this -> foo = $foo; + } + + public function __toString() + { + return $this -> foo; + } } -?> diff --git a/htdocs/includes/mike42/escpos-php/test/unit/FilePrintConnectorTest.php b/htdocs/includes/mike42/escpos-php/test/unit/FilePrintConnectorTest.php new file mode 100644 index 00000000000..63728717017 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/test/unit/FilePrintConnectorTest.php @@ -0,0 +1,26 @@ + finalize(); + $connector -> finalize(); // Silently do nothing if printer already closed + unlink($tmpfname); + } + + public function testReadAfterClose() + { + // Should attempt to send data to the local printer by writing to it + $this -> setExpectedException('Exception'); + $tmpfname = tempnam("/tmp", "php"); + $connector = new FilePrintConnector($tmpfname); + $connector -> finalize(); + $connector -> write("Test"); + unlink($tmpfname); + } +} diff --git a/htdocs/includes/mike42/escpos-php/test/unit/GdEscposImageTest.php b/htdocs/includes/mike42/escpos-php/test/unit/GdEscposImageTest.php new file mode 100644 index 00000000000..da755f7b9ee --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/test/unit/GdEscposImageTest.php @@ -0,0 +1,101 @@ + setExpectedException('Exception'); + $this -> loadAndCheckImg('not a real file.png', 1, 1, null, null); + } + + /** + * @medium + */ + public function testGdEmpty() + { + $this -> loadAndCheckImg(null, 0, 0, "", array()); + } + + /** + * @medium + */ + public function testGdBlack() + { + foreach (array('png', 'jpg', 'gif') as $format) { + $this -> loadAndCheckImg('canvas_black.' . $format, 1, 1, "\x80", array("\x80")); + } + } + + /** + * @medium + */ + public function testGdBlackTransparent() + { + foreach (array('png', 'gif') as $format) { + $this -> loadAndCheckImg('black_transparent.' . $format, 2, 2, "\xc0\x00", array("\x80\x80")); + } + } + + /** + * @medium + */ + public function testGdBlackWhite() + { + foreach (array('png', 'jpg', 'gif') as $format) { + $this -> loadAndCheckImg('black_white.' . $format, 2, 2, "\xc0\x00", array("\x80\x80")); + } + } + + /** + * @medium + */ + public function testGdWhite() + { + foreach (array('png', 'jpg', 'gif') as $format) { + $this -> loadAndCheckImg('canvas_white.' . $format, 1, 1, "\x00", array("\x00")); + } + } + + /** + * Load an EscposImage with (optionally) certain libraries disabled and run a check. + */ + private function loadAndCheckImg($fn, $width, $height, $rasterFormat = null, $columnFormat = null) + { + if (!EscposImage::isGdLoaded()) { + $this -> markTestSkipped("imagick plugin is required for this test"); + } + $onDisk = ($fn === null ? null : (dirname(__FILE__) . "/resources/$fn")); + // With optimisations + $imgOptimised = new GdEscposImage($onDisk, true); + $this -> checkImg($imgOptimised, $width, $height, $rasterFormat, $columnFormat); + // ... and without + $imgUnoptimised = new GdEscposImage($onDisk, false); + $this -> checkImg($imgUnoptimised, $width, $height, $rasterFormat, $columnFormat); + } + + /** + * Check image against known width, height, output. + */ + private function checkImg(EscposImage $img, $width, $height, $rasterFormatExpected = null, $columnFormatExpected = null) + { + $rasterFormatActual = $img -> toRasterFormat(); + $columnFormatActual = $img -> toColumnFormat(); + if ($rasterFormatExpected === null) { + echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", raster data \"" . friendlyBinary($rasterFormatActual) . "\""; + } + if ($columnFormatExpected === null) { + echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", column data \"" . friendlyBinary($columnFormatActual) . "\""; + } + $this -> assertTrue($img -> getHeight() == $height); + $this -> assertTrue($img -> getWidth() == $width); + $this -> assertTrue($rasterFormatExpected === $rasterFormatActual); + $this -> assertTrue($columnFormatExpected === $columnFormatActual); + } +} diff --git a/htdocs/includes/mike42/escpos-php/test/unit/ImagickEscposImageTest.php b/htdocs/includes/mike42/escpos-php/test/unit/ImagickEscposImageTest.php new file mode 100644 index 00000000000..76831f761c6 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/test/unit/ImagickEscposImageTest.php @@ -0,0 +1,142 @@ + setExpectedException('Exception'); + $this -> loadAndCheckImg('not a real file.png', 1, 1, null, null); + } + + /** + * @medium + */ + public function testImagickEmpty() + { + $this -> loadAndCheckImg(null, 0, 0, "", array()); + } + + /** + * @medium + */ + public function testImagickBlack() + { + foreach (array('png', 'jpg', 'gif') as $format) { + $this -> loadAndCheckImg('canvas_black.' . $format, 1, 1, "\x80", array("\x80")); + } + } + + /** + * @medium + */ + public function testImagickBlackTransparent() + { + foreach (array('png', 'gif') as $format) { + $this -> loadAndCheckImg('black_transparent.' . $format, 2, 2, "\xc0\x00", array("\x80\x80")); + } + } + + /** + * @medium + */ + public function testImagickBlackWhite() + { + foreach (array('png', 'jpg', 'gif') as $format) { + $this -> loadAndCheckImg('black_white.' . $format, 2, 2, "\xc0\x00", array("\x80\x80")); + } + } + + /** + * @medium + */ + public function testImagickBlackWhiteTall() + { + // We're very interested in correct column format chopping here at 8 pixels + $this -> loadAndCheckImg('black_white_tall.png', 2, 16, + "\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\x00\x00\x00\x00\x00\x00\x00\x00", array("\xff\xff", "\x00\x00")); + } + + /** + * @medium + */ + public function testImagickWhite() + { + foreach (array('png', 'jpg', 'gif') as $format) { + $this -> loadAndCheckImg('canvas_white.' . $format, 1, 1, "\x00", array("\x00")); + } + } + + /** + * PDF test - load tiny PDF and check for well-formedness + * These are also skipped if you don't have imagick + * @medium + */ + public function testPdfAllPages() + { + $this -> loadAndCheckPdf('doc.pdf', 1, 1, array("\x00", "\x80"), array(array("\x00"), array("\x80"))); + } + + public function testPdfBadFilename() + { + $this -> setExpectedException('Exception'); + $this -> loadAndCheckPdf('not a real file', 1, 1, array(), array()); + } + + /** + * Load an EscposImage and run a check. + */ + private function loadAndCheckImg($fn, $width, $height, $rasterFormat = null, $columnFormat = null) + { + if (!EscposImage::isImagickLoaded()) { + $this -> markTestSkipped("imagick plugin is required for this test"); + } + $onDisk = ($fn === null ? null : (dirname(__FILE__) . "/resources/$fn")); + // With optimisations + $imgOptimised = new ImagickEscposImage($onDisk, true); + $this -> checkImg($imgOptimised, $width, $height, $rasterFormat, $columnFormat); + // ... and without + $imgUnoptimised = new ImagickEscposImage($onDisk, false); + $this -> checkImg($imgUnoptimised, $width, $height, $rasterFormat, $columnFormat); + } + + /** + * Same as above, loading document and checking pages against some expected values. + */ + private function loadAndCheckPdf($fn, $width, $height, array $rasterFormat = null, array $columnFormat = null) + { + if (!EscposImage::isImagickLoaded()) { + $this -> markTestSkipped("imagick plugin required for this test"); + } + $pdfPages = ImagickEscposImage::loadPdf(dirname(__FILE__) . "/resources/$fn", $width); + $this -> assertTrue(count($pdfPages) == count($rasterFormat), "Got back wrong number of pages"); + foreach ($pdfPages as $id => $img) { + $this -> checkImg($img, $width, $height, $rasterFormat[$id], $columnFormat[$id]); + } + } + + /** + * Check image against known width, height, output. + */ + private function checkImg(EscposImage $img, $width, $height, $rasterFormatExpected = null, $columnFormatExpected = null) + { + $rasterFormatActual = $img -> toRasterFormat(); + $columnFormatActual = $img -> toColumnFormat(); + if ($rasterFormatExpected === null) { + echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", raster data \"" . friendlyBinary($rasterFormatActual) . "\""; + } + if ($columnFormatExpected === null) { + echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", column data \"" . friendlyBinary($columnFormatActual) . "\""; + } + $this -> assertEquals($height , $img -> getHeight()); + $this -> assertEquals($width, $img -> getWidth()); + $this -> assertEquals($rasterFormatExpected, $rasterFormatActual, "Raster format did not match expected"); + $this -> assertEquals($columnFormatExpected, $columnFormatActual, "Column format did not match expected"); + } +} diff --git a/htdocs/includes/mike42/escpos-php/test/unit/LegacyCapabilityProfileTest.php b/htdocs/includes/mike42/escpos-php/test/unit/LegacyCapabilityProfileTest.php new file mode 100644 index 00000000000..360dee90fe7 --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/test/unit/LegacyCapabilityProfileTest.php @@ -0,0 +1,79 @@ + profiles = array( + 'Mike42\Escpos\CapabilityProfiles\DefaultCapabilityProfile', + 'Mike42\Escpos\CapabilityProfiles\EposTepCapabilityProfile', + 'Mike42\Escpos\CapabilityProfiles\SimpleCapabilityProfile', + 'Mike42\Escpos\CapabilityProfiles\StarCapabilityProfile', + 'Mike42\Escpos\CapabilityProfiles\P822DCapabilityProfile'); + $this -> checklist = array(); + foreach ($this -> profiles as $profile) { + $this-> checklist[] = $profile::getInstance(); + } + } + + function testSupportedCodePages() + { + foreach ($this -> checklist as $obj) { + $check = $obj -> getCodePages(); + $this -> assertTrue(is_array($check) && isset($check[0])); + foreach ($check as $num => $page) { + $this -> assertTrue(is_numeric($num)); + } + } + } + + function testText() { + /* Smoke test over text rendering with each profile. + * Just makes sure we can attempt to print 'hello world' and a non-ASCII + * char without anything blowing up */ + foreach ($this -> checklist as $obj) { + $connector = new DummyPrintConnector(); + $printer = new Printer($connector, $obj); + $printer -> text("Hello world €\n"); + $printer -> close(); + // Check for character cache + $profileName = $obj -> getId(); + $expected = "Characters-$profileName.ser.z"; + $filename = __DIR__ . "/../../src/Mike42/Escpos/PrintBuffers/cache/$expected"; + $this -> assertFileExists($filename); + } + } + + function testSupportsBitImageRaster() + { + foreach ($this -> checklist as $obj) { + $check = $obj -> getSupportsBitImageRaster(); + $this -> assertTrue(is_bool($check)); + } + } + + function testSupportsGraphics() + { + foreach ($this -> checklist as $obj) { + $check = $obj -> getSupportsGraphics(); + $this -> assertTrue(is_bool($check)); + } + } + + function testSupportsQrCode() + { + foreach ($this -> checklist as $obj) { + $check = $obj -> getSupportsQrCode(); + $this -> assertTrue(is_bool($check)); + } + } +} diff --git a/htdocs/includes/mike42/escpos-php/test/unit/UriPrintConnectorTest.php b/htdocs/includes/mike42/escpos-php/test/unit/UriPrintConnectorTest.php new file mode 100644 index 00000000000..715dd8d77de --- /dev/null +++ b/htdocs/includes/mike42/escpos-php/test/unit/UriPrintConnectorTest.php @@ -0,0 +1,59 @@ + write("AAA"); + $connector -> finalize(); + $this -> assertEquals("AAA", file_get_contents($filename)); + $this -> assertEquals('Mike42\Escpos\PrintConnectors\FilePrintConnector', get_class($connector)); + unlink($filename); + } + + /** + * @expectedException PHPUnit_Framework_Error + * @expectedExceptionMessage not finalized + */ + public function testSmb() + { + $connector = UriPrintConnector::get("smb://windows/printer"); + $this -> assertEquals('Mike42\Escpos\PrintConnectors\WindowsPrintConnector', get_class($connector)); + // We expect that this will throw an exception, we can't + // realistically print to a real printer in this test though... :) + $connector -> __destruct(); + } + + /** + * @expectedException InvalidArgumentException + * @expectedExceptionMessage Malformed connector URI + */ + public function testBadUri() + { + $connector = UriPrintConnector::get("foooooo"); + } + + /** + * @expectedException Exception + * @expectedExceptionMessage Connection refused + */ + public function testNetwork() + { + // Port should be closed so we can catch an error and move on + $connector = UriPrintConnector::get("tcp://localhost:45987/"); + } + + /** + * @expectedException InvalidArgumentException + * @expectedExceptionMessage URI sheme is not supported: ldap:// + */ + public function testUnsupportedUri() + { + // Try to print to something silly + $connector = UriPrintConnector::get("ldap://host:1234/"); + } +} diff --git a/htdocs/includes/mike42/escpos-php/test/unit/WindowsPrintConnectorTest.php b/htdocs/includes/mike42/escpos-php/test/unit/WindowsPrintConnectorTest.php index 392775d3277..f6e10fae5f5 100644 --- a/htdocs/includes/mike42/escpos-php/test/unit/WindowsPrintConnectorTest.php +++ b/htdocs/includes/mike42/escpos-php/test/unit/WindowsPrintConnectorTest.php @@ -1,278 +1,304 @@ getMockConnector("LPT1", WindowsPrintConnector::PLATFORM_WIN); - $connector -> expects($this -> once()) - -> method('runWrite') - -> with($this -> equalTo(''), $this -> equalTo("LPT1")); - $connector -> expects($this -> exactly(0)) - -> method('runCommand'); - $connector -> expects($this -> exactly(0)) - -> method('runCopy'); - $connector -> finalize(); - } +class WindowsPrintConnectorTest extends PHPUnit_Framework_TestCase +{ + private $connector; - public function testLptMac() { - // Cannot print to local printer on Mac with this connector - $this -> setExpectedException('BadMethodCallException'); - $connector = $this -> getMockConnector("LPT1", WindowsPrintConnector::PLATFORM_MAC); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> expects($this -> exactly(0)) - -> method('runCommand'); - $connector -> expects($this -> exactly(0)) - -> method('runCopy'); - $connector -> finalize(); - } + public function testLptWindows() + { + // Should attempt to send data to the local printer by writing to it + $connector = $this -> getMockConnector("LPT1", WindowsPrintConnector::PLATFORM_WIN); + $connector -> expects($this -> once()) + -> method('runWrite') + -> with($this -> equalTo(''), $this -> equalTo("LPT1")); + $connector -> expects($this -> exactly(0)) + -> method('runCommand'); + $connector -> expects($this -> exactly(0)) + -> method('runCopy'); + $connector -> finalize(); + } - public function testLptLinux() { - // Cannot print to local printer on Linux with this connector - $this -> setExpectedException('BadMethodCallException'); - $connector = $this -> getMockConnector("LPT1", WindowsPrintConnector::PLATFORM_LINUX); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> expects($this -> exactly(0)) - -> method('runCommand'); - $connector -> expects($this -> exactly(0)) - -> method('runCopy'); - $connector -> finalize(); - } + public function testLptMac() + { + // Cannot print to local printer on Mac with this connector + $this -> setExpectedException('BadMethodCallException'); + $connector = $this -> getMockConnector("LPT1", WindowsPrintConnector::PLATFORM_MAC); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> expects($this -> exactly(0)) + -> method('runCommand'); + $connector -> expects($this -> exactly(0)) + -> method('runCopy'); + $connector -> finalize(); + } - public function testComWindows() { - // Simple file write - $connector = $this -> getMockConnector("COM1", WindowsPrintConnector::PLATFORM_WIN); - $connector -> expects($this -> once()) - -> method('runWrite') - -> with($this -> equalTo(''), $this -> equalTo("COM1")); - $connector -> expects($this -> exactly(0)) - -> method('runCommand'); - $connector -> expects($this -> exactly(0)) - -> method('runCopy'); - $connector -> finalize(); - } + public function testLptLinux() + { + // Cannot print to local printer on Linux with this connector + $this -> setExpectedException('BadMethodCallException'); + $connector = $this -> getMockConnector("LPT1", WindowsPrintConnector::PLATFORM_LINUX); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> expects($this -> exactly(0)) + -> method('runCommand'); + $connector -> expects($this -> exactly(0)) + -> method('runCopy'); + $connector -> finalize(); + } - public function testComMac() { - // Cannot print to local printer on Mac with this connector - $this -> setExpectedException('BadMethodCallException'); - $connector = $this -> getMockConnector("COM1", WindowsPrintConnector::PLATFORM_MAC); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> expects($this -> exactly(0)) - -> method('runCommand'); - $connector -> expects($this -> exactly(0)) - -> method('runCopy'); - $connector -> finalize(); - } + public function testComWindows() + { + // Simple file write + $connector = $this -> getMockConnector("COM1", WindowsPrintConnector::PLATFORM_WIN); + $connector -> expects($this -> once()) + -> method('runWrite') + -> with($this -> equalTo(''), $this -> equalTo("COM1")); + $connector -> expects($this -> exactly(0)) + -> method('runCommand'); + $connector -> expects($this -> exactly(0)) + -> method('runCopy'); + $connector -> finalize(); + } - public function testComLinux() { - // Cannot print to local printer on Linux with this connector - $this -> setExpectedException('BadMethodCallException'); - $connector = $this -> getMockConnector("COM1", WindowsPrintConnector::PLATFORM_LINUX); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> expects($this -> exactly(0)) - -> method('runCommand'); - $connector -> expects($this -> exactly(0)) - -> method('runCopy'); - $connector -> finalize(); - } + public function testComMac() + { + // Cannot print to local printer on Mac with this connector + $this -> setExpectedException('BadMethodCallException'); + $connector = $this -> getMockConnector("COM1", WindowsPrintConnector::PLATFORM_MAC); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> expects($this -> exactly(0)) + -> method('runCommand'); + $connector -> expects($this -> exactly(0)) + -> method('runCopy'); + $connector -> finalize(); + } - public function testLocalShareWindows() { - $connector = $this -> getMockConnector("Printer", WindowsPrintConnector::PLATFORM_WIN); - $connector -> expects($this -> exactly(0)) - -> method('runCommand'); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> expects($this -> once()) - -> method('runCopy') - -> with($this -> anything(), $this -> stringContains('\\Printer')); - $connector -> finalize(); - } + public function testComLinux() + { + // Cannot print to local printer on Linux with this connector + $this -> setExpectedException('BadMethodCallException'); + $connector = $this -> getMockConnector("COM1", WindowsPrintConnector::PLATFORM_LINUX); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> expects($this -> exactly(0)) + -> method('runCommand'); + $connector -> expects($this -> exactly(0)) + -> method('runCopy'); + $connector -> finalize(); + } - public function testSharedPrinterWindows() { - $connector = $this -> getMockConnector("smb://example-pc/Printer", WindowsPrintConnector::PLATFORM_WIN); - $connector -> expects($this -> exactly(0)) - -> method('runCommand'); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> expects($this -> once()) - -> method('runCopy') - -> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer')); - $connector -> finalize(); - } + public function testLocalShareWindows() + { + $connector = $this -> getMockConnector("Printer", WindowsPrintConnector::PLATFORM_WIN); + $connector -> expects($this -> exactly(0)) + -> method('runCommand'); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> expects($this -> once()) + -> method('runCopy') + -> with($this -> anything(), $this -> stringContains('\\Printer')); + $connector -> finalize(); + } - public function testSharedPrinterWindowsUsername() { - $connector = $this -> getMockConnector("smb://bob@example-pc/Printer", WindowsPrintConnector::PLATFORM_WIN); - $connector -> expects($this -> once()) - -> method('runCommand') - -> with($this -> equalTo('net use \'\\\\example-pc\\Printer\' \'/user:bob\'')); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> expects($this -> once()) - -> method('runCopy') - -> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer')); - $connector -> finalize(); - } + public function testSharedPrinterWindows() + { + $connector = $this -> getMockConnector("smb://example-pc/Printer", WindowsPrintConnector::PLATFORM_WIN); + $connector -> expects($this -> exactly(0)) + -> method('runCommand'); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> expects($this -> once()) + -> method('runCopy') + -> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer')); + $connector -> finalize(); + } - public function testSharedPrinterWindowsUsernameDomain() { - $connector = $this -> getMockConnector("smb://bob@example-pc/home/Printer", WindowsPrintConnector::PLATFORM_WIN); - $connector -> expects($this -> once()) - -> method('runCommand') - -> with($this -> equalTo('net use \'\\\\example-pc\\Printer\' \'/user:home\\bob\'')); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> expects($this -> once()) - -> method('runCopy') - -> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer')); - $connector -> finalize(); - } + public function testSharedPrinterWindowsUsername() + { + $connector = $this -> getMockConnector("smb://bob@example-pc/Printer", WindowsPrintConnector::PLATFORM_WIN); + $connector -> expects($this -> once()) + -> method('runCommand') + -> with($this -> equalTo('net use \'\\\\example-pc\\Printer\' \'/user:bob\'')); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> expects($this -> once()) + -> method('runCopy') + -> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer')); + $connector -> finalize(); + } - public function testSharedPrinterWindowsUsernamePassword() { - $connector = $this -> getMockConnector("smb://bob:secret@example-pc/Printer", WindowsPrintConnector::PLATFORM_WIN); - $connector -> expects($this -> once()) - -> method('runCommand') - -> with($this -> equalTo('net use \'\\\\example-pc\\Printer\' \'/user:bob\' \'secret\'')); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> expects($this -> once()) - -> method('runCopy') - -> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer')); - $connector -> finalize(); - } + public function testSharedPrinterWindowsUsernameDomain() + { + $connector = $this -> getMockConnector("smb://bob@example-pc/home/Printer", WindowsPrintConnector::PLATFORM_WIN); + $connector -> expects($this -> once()) + -> method('runCommand') + -> with($this -> equalTo('net use \'\\\\example-pc\\Printer\' \'/user:home\\bob\'')); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> expects($this -> once()) + -> method('runCopy') + -> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer')); + $connector -> finalize(); + } - public function testSharedPrinterMac() { - // Not implemented - $this -> setExpectedException('Exception'); - $connector = $this -> getMockConnector("smb://Guest@example-pc/Printer", WindowsPrintConnector::PLATFORM_MAC); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> expects($this -> exactly(0)) - -> method('runCommand'); - $connector -> expects($this -> exactly(0)) - -> method('runCopy'); - $connector -> finalize(); - } + public function testSharedPrinterWindowsUsernamePassword() + { + $connector = $this -> getMockConnector("smb://bob:secret@example-pc/Printer", WindowsPrintConnector::PLATFORM_WIN); + $connector -> expects($this -> once()) + -> method('runCommand') + -> with($this -> equalTo('net use \'\\\\example-pc\\Printer\' \'/user:bob\' \'secret\'')); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> expects($this -> once()) + -> method('runCopy') + -> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer')); + $connector -> finalize(); + } - public function testSharedPrinterLinux() { - $connector = $this -> getMockConnector("smb://example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX); - $connector -> expects($this -> once()) - -> method('runCommand') - -> with($this -> equalTo('smbclient \'//example-pc/Printer\' -c \'print -\' -N')); - $connector -> expects($this -> exactly(0)) - -> method('runCopy'); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> finalize(); - } + public function testSharedPrinterMac() + { + // Not implemented + $this -> setExpectedException('Exception'); + $connector = $this -> getMockConnector("smb://Guest@example-pc/Printer", WindowsPrintConnector::PLATFORM_MAC); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> expects($this -> exactly(0)) + -> method('runCommand'); + $connector -> expects($this -> exactly(0)) + -> method('runCopy'); + $connector -> finalize(); + } - public function testSharedPrinterLinuxUsername() { - $connector = $this -> getMockConnector("smb://bob@example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX); - $connector -> expects($this -> once()) - -> method('runCommand') - -> with($this -> equalTo('smbclient \'//example-pc/Printer\' -U \'bob\' -c \'print -\' -N')); - $connector -> expects($this -> exactly(0)) - -> method('runCopy'); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> finalize(); - } + public function testSharedPrinterLinux() + { + $connector = $this -> getMockConnector("smb://example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX); + $connector -> expects($this -> once()) + -> method('runCommand') + -> with($this -> equalTo('smbclient \'//example-pc/Printer\' -c \'print -\' -N -m SMB2')); + $connector -> expects($this -> exactly(0)) + -> method('runCopy'); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> finalize(); + } - public function testSharedPrinterLinuxUsernameDomain() { - $connector = $this -> getMockConnector("smb://bob@example-pc/home/Printer", WindowsPrintConnector::PLATFORM_LINUX); - $connector -> expects($this -> once()) - -> method('runCommand') - -> with($this -> equalTo('smbclient \'//example-pc/Printer\' -U \'home\\bob\' -c \'print -\' -N')); - $connector -> expects($this -> exactly(0)) - -> method('runCopy'); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> finalize(); - } + public function testSharedPrinterLinuxUsername() + { + $connector = $this -> getMockConnector("smb://bob@example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX); + $connector -> expects($this -> once()) + -> method('runCommand') + -> with($this -> equalTo('smbclient \'//example-pc/Printer\' -U \'bob\' -c \'print -\' -N -m SMB2')); + $connector -> expects($this -> exactly(0)) + -> method('runCopy'); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> finalize(); + } - public function testSharedPrinterLinuxUsernamePassword() { - $connector = $this -> getMockConnector("smb://bob:secret@example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX); - $connector -> expects($this -> once()) - -> method('runCommand') - -> with($this -> equalTo('smbclient \'//example-pc/Printer\' \'secret\' -U \'bob\' -c \'print -\'')); - $connector -> expects($this -> exactly(0)) - -> method('runCopy'); - $connector -> expects($this -> exactly(0)) - -> method('runWrite'); - $connector -> finalize(); - } + public function testSharedPrinterLinuxUsernameDomain() + { + $connector = $this -> getMockConnector("smb://bob@example-pc/home/Printer", WindowsPrintConnector::PLATFORM_LINUX); + $connector -> expects($this -> once()) + -> method('runCommand') + -> with($this -> equalTo('smbclient \'//example-pc/Printer\' -U \'home\\bob\' -c \'print -\' -N -m SMB2')); + $connector -> expects($this -> exactly(0)) + -> method('runCopy'); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> finalize(); + } - private function getMockConnector($path, $platform) { - $stub = $this -> getMockBuilder('WindowsPrintConnector') - -> setMethods(array('runCopy', 'runCommand', 'getCurrentPlatform', 'runWrite')) - -> disableOriginalConstructor() - -> getMock(); - $stub -> method('runCommand') - -> willReturn(0); - $stub -> method('runCopy') - -> willReturn(true); - $stub -> method('runWrite') - -> willReturn(true); - $stub -> method('getCurrentPlatform') - -> willReturn($platform); - $stub -> __construct($path); - return $stub; - } + public function testSharedPrinterLinuxUsernamePassword() + { + $connector = $this -> getMockConnector("smb://bob:secret@example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX); + $connector -> expects($this -> once()) + -> method('runCommand') + -> with($this -> equalTo('smbclient \'//example-pc/Printer\' \'secret\' -U \'bob\' -c \'print -\' -m SMB2')); + $connector -> expects($this -> exactly(0)) + -> method('runCopy'); + $connector -> expects($this -> exactly(0)) + -> method('runWrite'); + $connector -> finalize(); + } - /** - * Test for correct identification of bogus or non-supported Samba strings. - */ - public function testSambaRegex() { - $good = array("smb://foo/bar", - "smb://foo/bar baz", - "smb://bob@foo/bar", - "smb://bob:secret@foo/bar", - "smb://foo-computer/FooPrinter", - "smb://foo-computer/workgroup/FooPrinter", - "smb://foo-computer/Foo-Printer", - "smb://foo-computer/workgroup/Foo-Printer", - "smb://foo-computer/Foo Printer"); - $bad = array("", - "http://google.com", - "smb:/foo/bar", - "smb://", - "smb:///bar", - "smb://@foo/bar", - "smb://bob:@foo/bar", - "smb://:secret@foo/bar", - "smb://foo/bar/baz/quux", - "smb://foo-computer//FooPrinter"); - foreach($good as $item) { - $this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_SMB, $item) == 1, "Windows samba regex should pass '$item'."); - } - foreach($bad as $item) { - $this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_SMB, $item) != 1, "Windows samba regex should fail '$item'."); - } - } - - public function testPrinterNameRegex() { - $good = array("a", - "ab", - "a b", - "a-b", - "Abcd Efg-", - "-a" - ); - $bad = array("", - " ", - "a ", - " a", - " a ", - "a/B", - "A:b" - ); - foreach($good as $item) { - $this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_PRINTERNAME, $item) == 1, "Windows printer name regex should pass '$item'."); - } - foreach($bad as $item) { - $this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_PRINTERNAME, $item) != 1, "Windows printer name regex should fail '$item'."); - } - } + private function getMockConnector($path, $platform) + { + $stub = $this -> getMockBuilder('Mike42\Escpos\PrintConnectors\WindowsPrintConnector') + -> setMethods(array('runCopy', 'runCommand', 'getCurrentPlatform', 'runWrite')) + -> disableOriginalConstructor() + -> getMock(); + $stub -> method('runCommand') + -> willReturn(0); + $stub -> method('runCopy') + -> willReturn(true); + $stub -> method('runWrite') + -> willReturn(true); + $stub -> method('getCurrentPlatform') + -> willReturn($platform); + $stub -> __construct($path); + return $stub; + } + + /** + * Test for correct identification of bogus or non-supported Samba strings. + */ + public function testSambaRegex() + { + $good = array("smb://foo/bar", + "smb://foo/bar baz", + "smb://bob@foo/bar", + "smb://bob:secret@foo/bar", + "smb://foo-computer/FooPrinter", + "smb://foo-computer/workgroup/FooPrinter", + "smb://foo-computer/Foo-Printer", + "smb://foo-computer/workgroup/Foo-Printer", + "smb://foo-computer/Foo Printer", + "smb://foo-computer.local/Foo Printer", + "smb://127.0.0.1/abcd" + ); + $bad = array("", + "http://google.com", + "smb:/foo/bar", + "smb://", + "smb:///bar", + "smb://@foo/bar", + "smb://bob:@foo/bar", + "smb://:secret@foo/bar", + "smb://foo/bar/baz/quux", + "smb://foo-computer//FooPrinter"); + foreach ($good as $item) { + $this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_SMB, $item) == 1, "Windows samba regex should pass '$item'."); + } + foreach ($bad as $item) { + $this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_SMB, $item) != 1, "Windows samba regex should fail '$item'."); + } + } + + public function testPrinterNameRegex() + { + $good = array("a", + "ab", + "a b", + "a-b", + "Abcd Efg-", + "-a", + "OK1" + ); + $bad = array("", + " ", + "a ", + " a", + " a ", + "a/B", + "A:b" + ); + foreach ($good as $item) { + $this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_PRINTERNAME, $item) == 1, "Windows printer name regex should pass '$item'."); + } + foreach ($bad as $item) { + $this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_PRINTERNAME, $item) != 1, "Windows printer name regex should fail '$item'."); + } + } } diff --git a/htdocs/includes/mike42/escpos-php/test/unit/resources/black_white_tall.png b/htdocs/includes/mike42/escpos-php/test/unit/resources/black_white_tall.png new file mode 100644 index 00000000000..7e0869dcbed Binary files /dev/null and b/htdocs/includes/mike42/escpos-php/test/unit/resources/black_white_tall.png differ diff --git a/htdocs/includes/mike42/escpos-php/test/unit/resources/demo.php b/htdocs/includes/mike42/escpos-php/test/unit/resources/demo.php index 67ea53c1bfd..3751d60d903 100644 --- a/htdocs/includes/mike42/escpos-php/test/unit/resources/demo.php +++ b/htdocs/includes/mike42/escpos-php/test/unit/resources/demo.php @@ -1,19 +1,18 @@ readImage("doc.pdf[5]"); - $im -> destroy(); -} catch(ImagickException $e) { - echo "Error: " . $e -> getMessage() . "\n"; + $im -> readImage("doc.pdf[5]"); + $im -> destroy(); +} catch (ImagickException $e) { + echo "Error: " . $e -> getMessage() . "\n"; } $im = new Imagick(); try { - ob_start(); - @$im -> readImage("doc.pdf[5]"); - ob_end_clean(); - $im -> destroy(); -} catch(ImagickException $e) { - echo "Error: " . $e -> getMessage() . "\n"; + ob_start(); + @$im -> readImage("doc.pdf[5]"); + ob_end_clean(); + $im -> destroy(); +} catch (ImagickException $e) { + echo "Error: " . $e -> getMessage() . "\n"; } -