Skip to content

Commit

Permalink
Merge branch 'testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
mike42 committed Apr 25, 2016
2 parents 1707943 + 05bc125 commit cfea4c4
Show file tree
Hide file tree
Showing 33 changed files with 1,289 additions and 183 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# escpos-php contributors

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

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

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

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

Expand Down
56 changes: 35 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,28 @@ If you use any other printer with this code, please [let us know](https://github
#### 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
```php
<?php
require __DIR__ . '/vendor/autoload.php';
````
```

#### Manually
If you don't have composer available, then simply download the code and include `autoload.php`:

````
```bash
git clone https://github.com/mike42/escpos-php vendor/mike42/escpos-php
````
```

````php
```php
<?php
require __DIR__ . '/vendor/mike42/escpos-php/autoload.php');
````
```

### The 'Hello World' receipt

Expand All @@ -139,24 +139,27 @@ $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
Expand All @@ -171,7 +174,7 @@ To print receipts from PHP, use the most applicable [PrintConnector](https://git

For example, a `NetworkPrintConnector` accepts an IP address and port:

````php
```php
use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
use Mike42\Escpos\Printer;
$connector = new NetworkPrintConnector("10.x.x.x", 9100);
Expand All @@ -181,7 +184,7 @@ try {
} finally {
$printer -> close();
}
````
```

While a serial printer might use:
```php
Expand Down Expand Up @@ -235,7 +238,7 @@ Parameters:
- `PrintConnector $connector`: The PrintConnector to send data to.
- `AbstractCapabilityProfile $profile` Supported features of this printer. If not set, the DefaultCapabilityProfile 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.
Expand Down Expand Up @@ -354,6 +357,13 @@ Parameters:

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

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

Parameters:

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

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

Expand Down Expand Up @@ -421,19 +431,19 @@ Parameters:
# 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.
* [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 `example/demo.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)

# Development

This code is MIT licensed, and you are encouraged to contribute any modifications back to the project.

For development, it's suggested that you load `imagick`, `gd` and `Xdebug` PHP modules, and install `composer`.
For development, it's suggested that you load `imagick`, `gd` and `Xdebug` PHP exensions, and install `composer`.

The tests are executed on [Travis CI](https://travis-ci.org/mike42/escpos-php) over PHP 5.3, 5.4, 5.5, 5.7, 7, and HHVM. Earlier versions of PHP are not supported.

Fetch a copy of this code and load idependencies with composer:
Fetch a copy of this code and load dependencies with composer:

git clone https://github.com/mike42/escpos-php
cd escpos-php/
Expand All @@ -447,6 +457,10 @@ This project uses the PSR-2 standard, which can be checked via [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.

<!-- ## Other versions
Expand Down
7 changes: 6 additions & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
html: escpos.doxyfile
# Compile
doxygen escpos.doxyfile
# Show warnings log
cat warnings.log
# Return failure if there were doc warnings
[ ! -s warnings.log ]

latex: html
# Do nothing
Expand All @@ -8,5 +13,5 @@ xml: html
xsltproc xml/combine.xslt xml/index.xml > all.xml

clean:
rm --preserve-root -Rf html latex xml doxygen_sqlite3.db all.xml
rm --preserve-root -Rf html latex xml doxygen_sqlite3.db all.xml warnings.log

2 changes: 1 addition & 1 deletion doc/escpos.doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 27 additions & 4 deletions example/barcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,40 @@

$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(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
$printer->text("Text position\n");
$printer->selectPrintMode();
$hri = array (
Printer::BARCODE_TEXT_NONE => "No text",
Printer::BARCODE_TEXT_ABOVE => "Above",
Printer::BARCODE_TEXT_BELOW => "Below",
Printer::BARCODE_TEXT_ABOVE | Printer::BARCODE_TEXT_BELOW => "Both"
Printer::BARCODE_TEXT_NONE => "No text",
Printer::BARCODE_TEXT_ABOVE => "Above",
Printer::BARCODE_TEXT_BELOW => "Below",
Printer::BARCODE_TEXT_ABOVE | Printer::BARCODE_TEXT_BELOW => "Both"
);
foreach ($hri as $position => $caption) {
$printer->text($caption . "\n");
Expand Down
Binary file added example/resources/tulips.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions example/specific/123-code128-barcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
require __DIR__ . '/../../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;

$a = "{A012323392982";
$b = "{B012323392982";
$c = "{C" . chr(01) . chr(23) . chr(23) . chr(39) . chr(29) . chr(82);

$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector);
$printer -> 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();

15 changes: 15 additions & 0 deletions example/specific/62-greek-symbol-swap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
require __DIR__ . '/../../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\CapabilityProfiles\DefaultCapabilityProfile;

$connector = new FilePrintConnector("php://stdout");
$profile = DefaultCapabilityProfile::getInstance();
$printer = new Printer($connector, $profile);

$printer -> text("Μιχάλης Νίκος\n");
$printer -> cut();
$printer -> close();

?>
28 changes: 28 additions & 0 deletions example/specific/97-dithering.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/*
* Example of dithering used in EscposImage by default, if you have Imagick loaded.
*/
require __DIR__ . '/../../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\EscposImage;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;

$connector = new FilePrintConnector("/dev/usb/lp0");
$printer = new Printer($connector);
try {
/* Load with optimisations enabled. If you have Imagick, this will get you
a nicely dithered image, which prints very quickly
*/
$img1 = EscposImage::load(__DIR__ . '/../resources/tulips.png');
$printer -> 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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@
*/
class DefaultCapabilityProfile extends AbstractCapabilityProfile
{
/**
* List of custom code pages
*/
public function getCustomCodePages()
{
return array();
}

/**
* Return map of numbers to code page ID's.
*/
public function getSupportedCodePages()
{
/* Character code tables which the printer understands, mapping to known encoding standards we may be able to encode to.
Expand Down Expand Up @@ -99,26 +105,41 @@ public function getSupportedCodePages()
255 => false);
}

/**
* Return true for Barcode function B support, false if not supported.
*/
public function getSupportsBarcodeB()
{
return true;
}

/**
* Return true for bitImage support, false if not supported.
*/
public function getSupportsBitImage()
{
return true;
}

/**
* Return true for graphics support, false if not supported.
*/
public function getSupportsGraphics()
{
return true;
}


/**
* Return true for Star command extensions, false if not supported.
*/
public function getSupportsStarCommands()
{
return false;
}

/**
* Return true for native QR code support, false if not supported.
*/
public function getSupportsQrCode()
{
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*/
class P822DCapabilityProfile extends DefaultCapabilityProfile
{
/**
* Map of numbers to supported iconv code page names.
*/
public function getSupportedCodePages()
{
return array(
Expand Down Expand Up @@ -100,6 +103,9 @@ public function getSupportedCodePages()
);
}

/**
* Return true if graphics commands are supported, false if not.
*/
public function getSupportsGraphics()
{
/* Ask the driver to use bitImage wherever possible instead of graphics */
Expand Down
Loading

0 comments on commit cfea4c4

Please sign in to comment.