Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unifont-based text renderer #814

Merged
merged 4 commits into from Oct 13, 2019
Merged

Add Unifont-based text renderer #814

merged 4 commits into from Oct 13, 2019

Conversation

mike42
Copy link
Owner

@mike42 mike42 commented Oct 13, 2019

This change adds a text rendering plugin called UnifontPrintBuffer. I've placed it in an "Experimental" package to indicate that the API is not stable.

The example is:

<?php

require __DIR__ . '/../vendor/autoload.php';

use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
use Mike42\Escpos\Experimental\Unifont\UnifontPrintBuffer;

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

// Use Unifont to render text
$unifontBuffer = new UnifontPrintBuffer("/usr/share/unifont/unifont.hex");
$printer -> setPrintBuffer($unifontBuffer);

// Most simple example
$printer->text("Hello\n");
$printer->setUpsideDown(true);
$printer->text("World\n");
$printer->cut();
$printer->close();

Which renders like this - demonstrating that text formatting commands work:

2019-10-unifont-example

Key points are-

  • This method is only suitable for printers which support user-defined fonts at 9x17 size - tested on Epson TM-series thermal printers.
  • This is also only suitable for scripts where code points map easily to glyphs - eg. contextual forms, composing characters and bi-directional text will not render correctly.
  • The user must supply the path to a GNU Unifont hex file, which is freely available.

Ref:

@mike42 mike42 changed the title [WIP] Add unifont-based text renderer Add Unifont-based text renderer Oct 13, 2019
@mike42 mike42 merged commit 203c53e into development Oct 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant