1 // FXDCNativePrinter.h 2 // 3 // This was derived from a file of this name on the FOX/FXEX repository, 4 // and its (lack of) explicit copyright claims etc has been preserved. 5 // As the most recent hacker of this version, I (A C Norman, Codemist) 6 // contribute all my adjustments back under an MIT/BSD-style bunch of 7 // permissions. 8 // 9 // see associated file FXDCNativePrinter.cpp for commentary etc. and a 10 // more careful explanation of the licensing situation. 11 12 13 #ifndef FXDCNATIVEPRINTER_H 14 #define FXDCNATIVEPRINTER_H 15 16 #ifndef FXDC_H 17 #include <fx.h> 18 #include <FXDC.h> 19 #endif 20 21 #include <FXDCPrint.h> 22 #include "FXPostscriptFont.h" 23 24 // 25 // The class described here is intended to allow FOX applications to 26 // print - under Windows it uses the native Windows API while on other 27 // operating systems and if used to print to file it generates Postscript. 28 // 29 // The basic protocol for use is 30 // 31 // FXPrintDialog dlg(this, ""); 32 // dlg.execute(); // user gets to select a printer 33 // FXPrinter printer; 34 // dlg.getPrinter(printer); // find out which one! 35 // FXDCNativePrinter ptr(getApp()); // printing framework 36 // if (!prt.beginPrint(printer)) FAIL // unable to print just now 37 // FXFont *f1 = prt.fntGenerateFont("courier", 12); // or whatever! 38 // // font sizes given in points (1/72in) 39 // f1->create(); // remember to make font really there! 40 // for (page=1;WHENEVER;page++) 41 // { prt.beginPage(page); // start page 42 // prt.setFont(f1); 43 // x = prt.getPageWidth(); // at page border, does not leave any... 44 // y = prt.getPageHeight(); // margins, so leave some yourself. 45 // prt.drawLine(x1, y1, x2, y2); 46 // prt.setForeground(FXRGB(255,0,0)); // colours 47 // prt.drawText(x, y, "string", strlen("string")); 48 // int w = prt.fntGetTextWidth("string", strlen("string")); 49 // etc etc // measurements are in units of 1/72in 50 // // by default. 51 // prt.endPage(); 52 // } 53 // prt.endPrint(); 54 // delete f1; // remember to tidy up afterwards 55 56 57 #ifdef WIN32 58 #include <windows.h> 59 #endif 60 61 namespace FX { 62 63 class FXAPI FXDCNativePrinter : public FXDC { 64 protected: 65 FXint pagecount; // Number of pages printed 66 FXint dctype; 67 68 enum { TYPE_PS=0, TYPE_WIN32=1 }; 69 70 protected: 71 #ifdef WIN32 72 HDC dc; 73 DOCINFO di; 74 DEVMODE devmode; 75 HANDLE devmode_handle; 76 // opaque hold a FXPrinterDrawable, which is an auxilliary class only 77 // defined in the .cpp file 78 FXObject *opaque; 79 #endif 80 FXDC *pdc; 81 protected: 82 FXdouble scalex,scaley; 83 FXint logpixelsx, logpixelsy; 84 FXfloat unitsx,unitsy; 85 FXfloat fontScale, fontScaleBack, PSscale; 86 FXint fontoffset; 87 FXfloat pagewidth, pageheight; 88 FX::FXPostscriptFont *postscriptFont; 89 public: 90 91 /// Construct 92 FXDCNativePrinter(FXApp *a); 93 94 /// Generate print job prolog 95 virtual FXbool beginPrint(FXPrinter& job); 96 97 /// Generate print job epilog 98 virtual FXbool endPrint(); 99 100 /// Generate begin of page 101 virtual FXbool beginPage(FXuint page=1); 102 103 /// Generate end of page 104 virtual FXbool endPage(); 105 106 107 void setHorzUnitsInch(FXfloat sx); 108 void setVertUnitsInch(FXfloat sy); ScaleX(FXint x)109 FXint ScaleX(FXint x) { return (int)(x*scalex); } ScaleY(FXint y)110 FXint ScaleY(FXint y) { return (int)(y*scaley); } getHorzUnitsInch(void)111 FXfloat getHorzUnitsInch(void) { return unitsx; } getVertUnitsInch(void)112 FXfloat getVertUnitsInch(void) { return unitsy; } getLogPixelsX(void)113 FXint getLogPixelsX(void) { return logpixelsx; } getLogPixelsY(void)114 FXint getLogPixelsY(void) { return logpixelsy; } 115 116 void scalePoints(FXPoint *dst, FXPoint *src, FXuint npoints ); 117 void scaleRectangles(FXRectangle *dst, FXRectangle *src, FXuint nrectangles ); 118 void scaleSegments(FXSegment *dst, FXSegment *src, FXuint nsegments ); 119 void scaleArcs(FXArc *dst, FXArc *src, FXuint narcs ); 120 121 FXint getPageWidth(void); 122 FXint getPageHeight(void); 123 double doublePageWidth(void); 124 double doublePageHeight(void); 125 126 /// Draw points 127 virtual void drawPoint(FXint x,FXint y); 128 virtual void drawPoints(const FXPoint *points,FXuint npoints); 129 virtual void drawPointsRel(const FXPoint *points,FXuint npoints); 130 131 /// Draw lines 132 virtual void drawLine(FXint x1,FXint y1,FXint x2,FXint y2); 133 virtual void drawLines(const FXPoint *points,FXuint npoints); 134 virtual void drawLinesRel(const FXPoint *points,FXuint npoints); 135 virtual void drawLineSegments(const FXSegment *segments,FXuint nsegments); 136 137 /// Draw rectangles 138 virtual void drawRectangle(FXint x,FXint y,FXint w,FXint h); 139 virtual void drawRectangles(const FXRectangle *rectangles,FXuint nrectangles); 140 141 /// Draw arcs 142 virtual void drawArc(FXint x,FXint y,FXint w,FXint h,FXint ang1,FXint ang2); 143 virtual void drawArcs(const FXArc *arcs,FXuint narcs); 144 145 /// Filled rectangles 146 virtual void fillRectangle(FXint x,FXint y,FXint w,FXint h); 147 virtual void fillRectangles(const FXRectangle *rectangles,FXuint nrectangles); 148 149 /// Draw arcs 150 virtual void fillArc(FXint x,FXint y,FXint w,FXint h,FXint ang1,FXint ang2); 151 virtual void fillArcs(const FXArc *arcs,FXuint narcs); 152 153 /// Filled polygon 154 virtual void fillPolygon(const FXPoint *points,FXuint npoints); 155 virtual void fillConcavePolygon(const FXPoint *points,FXuint npoints); 156 virtual void fillComplexPolygon(const FXPoint *points,FXuint npoints); 157 158 /// Filled polygon with relative points 159 virtual void fillPolygonRel(const FXPoint *points,FXuint npoints); 160 virtual void fillConcavePolygonRel(const FXPoint *points,FXuint npoints); 161 virtual void fillComplexPolygonRel(const FXPoint *points,FXuint npoints); 162 163 /// Draw hashed box 164 virtual void drawHashBox(FXint x,FXint y,FXint w,FXint h,FXint b=1); 165 166 /// Draw area from source 167 virtual void drawArea(const FXDrawable *source,FXint sx,FXint sy,FXint sw,FXint sh,FXint dx,FXint dy); 168 169 /// Draw image 170 virtual void drawImage(const FXImage *image,FXint dx,FXint dy); 171 172 /// Draw bitmap 173 virtual void drawBitmap(const FXBitmap *bitmap,FXint dx,FXint dy); 174 175 /// Draw icon 176 virtual void drawIcon(const FXIcon *icon,FXint dx,FXint dy); 177 virtual void drawIconShaded(const FXIcon *icon,FXint dx,FXint dy); 178 virtual void drawIconSunken(const FXIcon *icon,FXint dx,FXint dy); 179 180 /// Draw string 181 virtual void drawText(FXint x, FXint y, const FXchar *string, FXuint length); 182 virtual void drawImageText(FXint x, FXint y, const FXchar *string, FXuint length); 183 184 /// Set foreground/background drawing color 185 virtual void setForeground(FXColor clr); 186 virtual void setBackground(FXColor clr); 187 188 /// Set dash pattern 189 virtual void setDashes(FXuint dashoffset,const FXchar *dashlist,FXuint n); 190 191 /// Set line width 192 virtual void setLineWidth(FXuint linewidth=0); 193 194 /// Set line cap style 195 virtual void setLineCap(FXCapStyle capstyle=CAP_BUTT); 196 197 /// Set line join style 198 virtual void setLineJoin(FXJoinStyle joinstyle=JOIN_MITER); 199 200 /// Set line style 201 virtual void setLineStyle(FXLineStyle linestyle=LINE_SOLID); 202 203 /// Set fill style 204 virtual void setFillStyle(FXFillStyle fillstyle=FILL_SOLID); 205 206 /// Set fill rule 207 virtual void setFillRule(FXFillRule fillrule=RULE_EVEN_ODD); 208 209 /// Set blit function 210 virtual void setFunction(FXFunction func=BLT_SRC); 211 212 /// Set the tile 213 virtual void setTile(FXImage *tile,FXint dx=0,FXint dy=0); 214 215 /// Set the stipple pattern 216 virtual void setStipple(FXBitmap *stipple,FXint dx=0,FXint dy=0); 217 218 /// Set the stipple pattern 219 virtual void setStipple(FXStipplePattern stipple,FXint dx=0,FXint dy=0); 220 221 /// Set clip rectangle 222 virtual void setClipRectangle(FXint x,FXint y,FXint w,FXint h); 223 224 /// Set clip rectangle 225 virtual void setClipRectangle(const FXRectangle& rectangle); 226 227 /// Clear clipping 228 virtual void clearClipRectangle(); 229 230 /// Set clip mask 231 virtual void setClipMask(FXBitmap *mask,FXint dx=0,FXint dy=0); 232 233 /// Clear clip mask 234 virtual void clearClipMask(); 235 236 /// Set font to draw text with 237 virtual void setFont(FXFont *fnt); 238 239 /// Clip drawing by child windows 240 virtual void clipChildren(FXbool yes); 241 242 /// Cleanup 243 virtual ~FXDCNativePrinter(); 244 245 /****** Font management ******/ 246 #if (FOX_MINOR<=4) 247 FXFont *fntGenerateFont(const FXString& face, FXuint sz, 248 FXuint wt=FONTWEIGHT_NORMAL, FXuint sl=FONTSLANT_REGULAR, 249 FXuint enc=FONTENCODING_DEFAULT, FXuint setw=FONTSETWIDTH_DONTCARE, 250 FXuint h=0); 251 FXFont *fntDoubleGenerateFont(const FXString& face, double sz, 252 FXuint wt=FONTWEIGHT_NORMAL, FXuint sl=FONTSLANT_REGULAR, 253 FXuint enc=FONTENCODING_DEFAULT, FXuint setw=FONTSETWIDTH_DONTCARE, 254 FXuint h=0); 255 #else 256 FXFont *fntGenerateFont(const FXString& face, FXuint sz, 257 FXuint wt=FXFont::Normal, FXuint sl=FXFont::Straight, 258 FXuint enc=FONTENCODING_DEFAULT, FXuint setw=FXFont::NonExpanded, 259 FXuint h=0); 260 FXFont *fntDoubleGenerateFont(const FXString& face, double sz, 261 FXuint wt=FXFont::Normal, FXuint sl=FXFont::Straight, 262 FXuint enc=FONTENCODING_DEFAULT, FXuint setw=FXFont::NonExpanded, 263 FXuint h=0); 264 #endif 265 FXString fntGetName(); 266 FXuint fntGetSize(); 267 FXuint fntGetWeight(); 268 FXuint fntGetSlant(); 269 FXuint fntGetEncoding(); 270 FXuint fntGetSetWidth(); 271 FXuint fntGetHints(); 272 void fntGetFontDesc(FXFontDesc& fontdesc) const; 273 void fntSetFontDesc(const FXFontDesc& fontdesc); 274 FXbool fntIsFontMono() const; 275 FXbool fntHasChar(FXint ch) const; 276 FXint fntGetMinChar() const; 277 FXint fntGetMaxChar() const; 278 FXint fntLeftBearing(FXchar ch) const; 279 FXint fntRightBearing(FXchar ch) const; 280 FXint fntGetFontWidth() const; 281 FXint fntGetFontHeight() const; 282 FXint fntGetFontAscent() const; 283 FXint fntGetFontDescent() const; 284 FXint fntGetFontLeading() const; 285 FXint fntGetFontSpacing() const; 286 FXint fntGetTextWidth(const FXchar *text,FXuint n) const; 287 FXint fntGetTextHeight(const FXchar *text,FXuint n) const; 288 // Versions of the above that return floating point values 289 double fntDoubleSize(); 290 double fntDoubleLeftBearing(FXchar ch) const; 291 double fntDoubleRightBearing(FXchar ch) const; 292 double fntDoubleFontWidth() const; 293 double fntDoubleFontHeight() const; 294 double fntDoubleFontAscent() const; 295 double fntDoubleFontDescent() const; 296 double fntDoubleFontLeading() const; 297 double fntDoubleFontSpacing() const; 298 double fntDoubleTextWidth(const FXchar *text,FXuint n) const; 299 double fntDoubleTextHeight(const FXchar *text,FXuint n) const; 300 }; 301 302 } 303 304 #endif 305 306 // end of FXDCNativePrinter.h 307 308