text-size.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * This print-out shows how large the available font sizes are. It is included
  4. * separately due to the amount of text it prints.
  5. *
  6. * @author Michael Billington <michael.billington@gmail.com>
  7. */
  8. require __DIR__ . '/../vendor/autoload.php';
  9. use Mike42\Escpos\Printer;
  10. use Mike42\Escpos\PrintConnectors\FilePrintConnector;
  11. $connector = new FilePrintConnector("php://stdout");
  12. $printer = new Printer($connector);
  13. /* Initialize */
  14. $printer -> initialize();
  15. /* Text of various (in-proportion) sizes */
  16. title($printer, "Change height & width\n");
  17. for ($i = 1; $i <= 8; $i++) {
  18. $printer -> setTextSize($i, $i);
  19. $printer -> text($i);
  20. }
  21. $printer -> text("\n");
  22. /* Width changing only */
  23. title($printer, "Change width only (height=4):\n");
  24. for ($i = 1; $i <= 8; $i++) {
  25. $printer -> setTextSize($i, 4);
  26. $printer -> text($i);
  27. }
  28. $printer -> text("\n");
  29. /* Height changing only */
  30. title($printer, "Change height only (width=4):\n");
  31. for ($i = 1; $i <= 8; $i++) {
  32. $printer -> setTextSize(4, $i);
  33. $printer -> text($i);
  34. }
  35. $printer -> text("\n");
  36. /* Very narrow text */
  37. title($printer, "Very narrow text:\n");
  38. $printer -> setTextSize(1, 8);
  39. $printer -> text("The quick brown fox jumps over the lazy dog.\n");
  40. /* Very flat text */
  41. title($printer, "Very wide text:\n");
  42. $printer -> setTextSize(4, 1);
  43. $printer -> text("Hello world!\n");
  44. /* Very large text */
  45. title($printer, "Largest possible text:\n");
  46. $printer -> setTextSize(8, 8);
  47. $printer -> text("Hello\nworld!\n");
  48. $printer -> cut();
  49. $printer -> close();
  50. function title(Printer $printer, $text)
  51. {
  52. $printer -> selectPrintMode(Printer::MODE_EMPHASIZED);
  53. $printer -> text("\n" . $text);
  54. $printer -> selectPrintMode(); // Reset
  55. }