Printer.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /******************************************************************************/
  2. struct PrinterInfo
  3. {
  4. Str name, model;
  5. Bool color, // if can print in color
  6. local; // if available locally (if false then network)
  7. Int width, height, // paper size, in 1/10 of mili-meter units
  8. dpi;
  9. VecI2 res; // get resolution (in pixels)
  10. Dbl widthMM()C {return width/10.0;} // get width in mili-meters
  11. Dbl heightMM()C {return height/10.0;} // get height in mili-meters
  12. Dbl widthCM()C {return width/100.0;} // get width in centi-meters
  13. Dbl heightCM()C {return height/100.0;} // get height in centi-meters
  14. Dbl widthM()C {return width/10000.0;} // get width in meters
  15. Dbl heightM()C {return height/10000.0;} // get height in meters
  16. };
  17. Bool GetPrinters(MemPtr<PrinterInfo> printers); // get list of available printers, false on fail
  18. /******************************************************************************/
  19. struct RawPrinter
  20. {
  21. // manage
  22. Bool connect(C Str &printer_name); // connect to 'printer_name' printer, false on fail
  23. void disconnect();
  24. ~RawPrinter() {disconnect();}
  25. RawPrinter();
  26. #if !EE_PRIVATE
  27. private:
  28. #endif
  29. Str8 data;
  30. Str printer_name;
  31. #if WINDOWS_OLD
  32. #if EE_PRIVATE
  33. HANDLE printer;
  34. #else
  35. Ptr printer;
  36. #endif
  37. #endif
  38. #if EE_PRIVATE
  39. Bool send(C Str8 &data, C Str &document_name=S);
  40. #endif
  41. };
  42. STRUCT_PRIVATE(ReceiptPrinter , RawPrinter)
  43. //{
  44. // manage
  45. Bool connect(C Str &printer_name); // connect to 'printer_name' printer, false on fail
  46. void disconnect();
  47. // print
  48. void operator++(); // skip line
  49. void operator+=(C Str8 &text); // print text
  50. Bool operator+=(C Image &img); // print image, false on fail
  51. void justify(Int j); // set justification, <0=left, 0=center, >0 right
  52. void barcodeWidth ( Byte width ); // set bar-code width
  53. void barcodeHeight( Byte height); // set bar-code height
  54. void barcode39 (C Str8 &code); // print bar-code based on specified 'code' using "Code 39"
  55. void barcode93 (C Str8 &code); // print bar-code based on specified 'code' using "Code 93"
  56. void barcode128 (C Str8 &code); // print bar-code based on specified 'code' using "Code 128"
  57. Bool end(C Str &document_name=S); // flush all queued printing commands to printer and cut paper, false on fail
  58. // cash drawer
  59. Bool openCashDrawer(); // open cash drawer (this does not require 'end'), false on fail
  60. #if !EE_PRIVATE
  61. private:
  62. #endif
  63. Byte code_page;
  64. #if EE_PRIVATE
  65. void init();
  66. void codePage(Byte cp);
  67. void lineHeight(Byte height); // set custom line height
  68. void lineHeight( ); // set default line height
  69. #endif
  70. };
  71. STRUCT_PRIVATE(LabelPrinter , RawPrinter)
  72. //{
  73. // manage
  74. Bool connect(C Str &printer_name); // connect to 'printer_name' printer, false on fail
  75. void disconnect();
  76. // print
  77. void text (C VecI2 &pos, C Str &text); // print text at 'pos' position
  78. Bool image(C VecI2 &pos, C Image &img); // print image at 'pos' position, false on fail
  79. void barcodeHeight(Byte height); // set bar-code height
  80. void barcode39 (C VecI2 &pos, C Str8 &code); // print bar-code based on specified 'code' at 'pos' position using "Code 39"
  81. void barcode93 (C VecI2 &pos, C Str8 &code); // print bar-code based on specified 'code' at 'pos' position using "Code 93"
  82. void barcode128 (C VecI2 &pos, C Str8 &code); // print bar-code based on specified 'code' at 'pos' position using "Code 128"
  83. void speed(Int speed); // set printing speed, in inches per second (2..12)
  84. Bool end(C Str &document_name=S); // flush all queued printing commands to printer, false on fail
  85. #if !EE_PRIVATE
  86. private:
  87. #endif
  88. #if EE_PRIVATE
  89. void init();
  90. void pos(C VecI2 &pos); // set print position
  91. #endif
  92. VecI2 res;
  93. };
  94. /******************************************************************************/
  95. void Barcode128(C Str8 &barcode, MemPtr<Bool> data); // generate "Code 128" bar-code bitmap
  96. /******************************************************************************/