From 357870d5750bcbe7e42e63a5b28f14163498a886 Mon Sep 17 00:00:00 2001 From: David Schmidt Date: Sun, 9 Jan 2011 17:27:11 +0000 Subject: [PATCH] Add plain text printer output --- src/config.c | 2 +- src/printer.cpp | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index 4a73910..acfd30a 100644 --- a/src/config.c +++ b/src/config.c @@ -248,7 +248,7 @@ Cfg_menu g_cfg_printer_menu[] = { KNMP(g_printer), CFGTYPE_INT }, { "Printer DPI,60,60x60 dpi,180,180x180 dpi,360,360x360 dpi", KNMP(g_printer_dpi), CFGTYPE_INT }, -{ "Printer Output Type,bmp,Windows Bitmap,ps,Postscript (B&W),printer,Direct to host printer", +{ "Printer Output Type,bmp,Windows Bitmap,ps,Postscript (B&W),printer,Direct to host printer,text,Text file", KNMP(g_printer_output), CFGTYPE_STR }, { "Multipage Files? (PS Only),0,No,1,Yes", KNMP(g_printer_multipage), CFGTYPE_INT }, diff --git a/src/printer.cpp b/src/printer.cpp index 085478b..500519f 100644 --- a/src/printer.cpp +++ b/src/printer.cpp @@ -49,6 +49,13 @@ static CPrinter* defaultPrinter = NULL; +static FILE *textPrinterFile = NULL; +#ifdef WIN32 +const char* const textPrinterFileName = ".\\printer.txt"; +#else +const char* const textPrinterFileName = "./printer.txt"; +#endif + #define PARAM16(I) (params[I+1]*256+params[I]) #define PIXX ((Bitu)floor(curX*dpi+0.5)) #define PIXY ((Bitu)floor(curY*dpi+0.5)) @@ -1262,6 +1269,12 @@ void CPrinter::newPage(bool save, bool resetx) { *((Bit8u*)page->pixels+i)=i; }*/ + if (strcasecmp(output, "text") == 0) { /* Text file */ + if (textPrinterFile) { + fclose(textPrinterFile); + textPrinterFile = NULL; + } + } } void CPrinter::printChar(Bit8u ch) @@ -1273,7 +1286,14 @@ void CPrinter::printChar(Bit8u ch) if (msb == 0) ch &= 0x7F; if (msb == 1) ch |= 0x80; } - + if (strcasecmp(output, "text") == 0) { + if (!textPrinterFile) { + textPrinterFile = fopen(textPrinterFileName,"ab"); + } + fprintf(textPrinterFile,"%c",ch); + fflush(textPrinterFile); + return; + } // Are we currently printing a bit graphic? if (bitGraph.remBytes > 0) { printBitGraph(ch);