DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/parport/printer.h
00001 /*
00002  *  Copyright (C) 2002-2013  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 //#include <dosbox.h>
00020 #include "config.h"
00021 
00022 #if C_PRINTER
00023 
00024 #if !defined __PRINTER_H
00025 #define __PRINTER_H
00026 
00027 #ifdef C_LIBPNG
00028 #include <png.h>
00029 #endif
00030 
00031 #include "SDL.h"
00032 
00033 #include <ft2build.h>
00034 #include FT_FREETYPE_H
00035 
00036 #if defined (WIN32)
00037 #include <windows.h>
00038 #include <winspool.h>
00039 #endif
00040 
00041 #define Z_BEST_COMPRESSION 9
00042 #define Z_DEFAULT_STRATEGY 0
00043 
00044 #define STYLE_PROP 0x01
00045 #define STYLE_CONDENSED 0x02
00046 #define STYLE_BOLD 0x04
00047 #define STYLE_DOUBLESTRIKE 0x08
00048 #define STYLE_DOUBLEWIDTH 0x10
00049 #define STYLE_ITALICS 0x20
00050 #define STYLE_UNDERLINE 0x40
00051 #define STYLE_SUPERSCRIPT 0x80
00052 #define STYLE_SUBSCRIPT 0x100
00053 #define STYLE_STRIKETHROUGH 0x200
00054 #define STYLE_OVERSCORE 0x400
00055 #define STYLE_DOUBLEWIDTHONELINE 0x800
00056 #define STYLE_DOUBLEHEIGHT 0x1000
00057 
00058 #define SCORE_NONE 0x00
00059 #define SCORE_SINGLE 0x01
00060 #define SCORE_DOUBLE 0x02
00061 #define SCORE_SINGLEBROKEN 0x05
00062 #define SCORE_DOUBLEBROKEN 0x06
00063 
00064 #define QUALITY_DRAFT 0x01
00065 #define QUALITY_LQ 0x02
00066 
00067 #define COLOR_BLACK 7<<5
00068 
00069 enum Typeface
00070 {
00071         roman = 0,
00072         sansserif,
00073         courier,
00074         prestige,
00075         script,
00076         ocrb,
00077         ocra,
00078         orator,
00079         orators,
00080         scriptc,
00081         romant,
00082         sansserifh,
00083         svbusaba = 30,
00084         svjittra = 31
00085 };
00086 
00087 class CPrinter {
00088 public:
00089 
00090         CPrinter (Bit16u dpi, Bit16u width, Bit16u height, char* output, bool multipageOutput);
00091         virtual ~CPrinter();
00092 
00093         // Process one character sent to virtual printer
00094         void printChar(Bit8u ch);
00095 
00096         // Hard Reset (like switching printer off and on)
00097         void resetPrinterHard();
00098 
00099         // Set Autofeed value 
00100         void setAutofeed(bool feed);
00101 
00102         // Get Autofeed value
00103         bool getAutofeed();
00104 
00105         // True if printer is unable to process more data right now (do not use printChar)
00106         bool isBusy();
00107 
00108         // True if the last sent character was received 
00109         bool ack();
00110 
00111         // Manual formfeed
00112         void formFeed();
00113 
00114         // Returns true if the current page is blank
00115         bool isBlank();
00116 
00117 private:
00118 
00119         // used to fill the color "sub-pallettes"
00120         void FillPalette(Bit8u redmax, Bit8u greenmax, Bit8u bluemax, Bit8u colorID,
00121                                                         SDL_Palette* pal);
00122 
00123     // Checks if given char belongs to a command and process it. If false, the character
00124         // should be printed
00125         bool processCommandChar(Bit8u ch);
00126 
00127         // Resets the printer to the factory settings
00128         void resetPrinter();
00129 
00130         // Reload font. Must be called after changing dpi, style or cpi
00131         void updateFont();
00132 
00133         // Clears page. If save is true, saves the current page to a bitmap
00134         void newPage(bool save, bool resetx);
00135 
00136         // Blits the given glyph on the page surface. If add is true, the values of bitmap are
00137         // added to the values of the pixels in the page
00138         void blitGlyph(FT_Bitmap bitmap, Bit16u destx, Bit16u desty, bool add);
00139 
00140         // Draws an anti-aliased line from (fromx, y) to (tox, y). If broken is true, gaps are included
00141         void drawLine(Bitu fromx, Bitu tox, Bitu y, bool broken);
00142 
00143         // Setup the bitGraph structure
00144         void setupBitImage(Bit8u dens, Bit16u numCols);
00145 
00146         // Process a character that is part of bit image. Must be called iff bitGraph.remBytes > 0.
00147         void printBitGraph(Bit8u ch);
00148 
00149         // Copies the codepage mapping from the constant array to CurMap
00150         void selectCodepage(Bit16u cp);
00151 
00152         // Output current page 
00153         void outputPage();
00154 
00155         // Prints out a byte using ASCII85 encoding (only outputs something every four bytes). When b>255, closes the ASCII85 string
00156         void fprintASCII85(FILE* f, Bit16u b);
00157 
00158         // Closes a multipage document
00159         void finishMultipage();
00160 
00161         // Returns value of the num-th pixel (couting left-right, top-down) in a safe way
00162         Bit8u getPixel(Bit32u num);
00163 
00164         FT_Library FTlib;                                       // FreeType2 library used to render the characters
00165 
00166         SDL_Surface* page;                                      // Surface representing the current page
00167         FT_Face curFont;                                        // The font currently used to render characters
00168         Bit8u color;
00169 
00170         Real64 curX, curY;                                      // Position of the print head (in inch)
00171 
00172         Bit16u dpi;                                                     // dpi of the page
00173         Bit16u ESCCmd;                                          // ESC-command that is currently processed
00174         bool ESCSeen;                                           // True if last read character was an ESC (0x1B)
00175         bool FSSeen;                                            // True if last read character was an FS (0x1C) (IBM commands)
00176 
00177         Bit8u numParam, neededParam;            // Numbers of parameters already read/needed to process command
00178 
00179         Bit8u params[20];                                       // Buffer for the read params
00180         Bit16u style;                                           // Style of font (see STYLE_* constants)
00181         Real64 cpi, actcpi;                                     // CPI value set by program and the actual one (taking in account font types)
00182         Bit8u score;                                            // Score for lines (see SCORE_* constants)
00183 
00184         Real64 topMargin, bottomMargin, rightMargin, leftMargin;        // Margins of the page (in inch)
00185         Real64 pageWidth, pageHeight;                                                           // Size of page (in inch)
00186         Real64 defaultPageWidth, defaultPageHeight;                                     // Default size of page (in inch)
00187         Real64 lineSpacing;                                                                                     // Size of one line (in inch)
00188 
00189         Real64 horiztabs[32];                           // Stores the set horizontal tabs (in inch)
00190         Bit8u numHorizTabs;                                     // Number of configured tabs
00191 
00192         Real64 verttabs[16];                            // Stores the set vertical tabs (in inch)
00193         Bit8u numVertTabs;                                      // Number of configured tabs
00194 
00195         Bit8u curCharTable;                                     // Currently used char table und charset
00196         Bit8u printQuality;                                     // Print quality (see QUALITY_* constants)
00197 
00198         Typeface LQtypeFace;                            // Typeface used in LQ printing mode
00199 
00200         Real64 extraIntraSpace;                         // Extra space between two characters (set by program, in inch)
00201 
00202         bool charRead;                                          // True if a character was read since the printer was last initialized
00203         bool autoFeed;                                          // True if a LF should automatically added after a CR
00204         bool printUpperContr;                           // True if the upper command characters should be printed
00205 
00206         struct bitGraphicParams                         // Holds information about printing bit images
00207         {
00208                 Bit16u horizDens, vertDens;             // Density of image to print (in dpi)
00209                 bool adjacent;                                  // Print adjacent pixels? (ignored)
00210                 Bit8u bytesColumn;                              // Bytes per column
00211                 Bit16u remBytes;                                // Bytes left to read before image is done
00212                 Bit8u column[6];                                // Bytes of the current and last column
00213                 Bit8u readBytesColumn;                  // Bytes read so far for the current column
00214         } bitGraph;
00215 
00216         Bit8u densk, densl, densy, densz;       // Image density modes used in ESC K/L/Y/Z commands
00217 
00218         Bit16u curMap[256];                                     // Currently used ASCII => Unicode mapping
00219         Bit16u charTables[4];                           // Charactertables
00220 
00221         Real64 definedUnit;                                     // Unit used by some ESC/P2 commands (negative => use default)
00222 
00223         bool multipoint;                                        // If multipoint mode is enabled
00224         Real64 multiPointSize;                          // Point size of font in multipoint mode
00225         Real64 multicpi;                                        // CPI used in multipoint mode
00226 
00227         Real64 hmi;                                                     // Horizontal motion index (in inch; overrides CPI settings)
00228 
00229         Bit8u msb;                                                      // MSB mode
00230         Bit16u numPrintAsChar;                          // Number of bytes to print as characters (even when normally control codes)
00231 
00232 #if defined (WIN32)
00233         HDC printerDC;                                          // Win32 printer device
00234 #endif
00235 
00236         char* output;                                           // Output method selected by user
00237         void* outputHandle;                                     // If not null, additional pages will be appended to the given handle
00238         bool multipageOutput;                           // If true, all pages are combined to one file/print job etc. until the "eject page" button is pressed
00239         Bit16u multiPageCounter;                        // Current page (when printing multipages)
00240 
00241         Bit8u ASCII85Buffer[4];                         // Buffer used in ASCII85 encoding
00242         Bit8u ASCII85BufferPos;                         // Position in ASCII85 encode buffer
00243         Bit8u ASCII85CurCol;                            // Columns printed so far in the current lines
00244 };
00245 
00246 #endif
00247 
00248 #endif