X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/16c1f7f345e1850f590cfbf67c3b00fbb6d2e62e..520e470fdd0daef09c77938db642e4583933c90d:/src/common/postscrp.cpp diff --git a/src/common/postscrp.cpp b/src/common/postscrp.cpp index d332f426f7..0a6dd57b7f 100644 --- a/src/common/postscrp.cpp +++ b/src/common/postscrp.cpp @@ -24,7 +24,7 @@ #include "wx/defs.h" -#if USE_POSTSCRIPT +#if wxUSE_POSTSCRIPT #ifndef WX_PRECOMP #include "wx/intl.h" @@ -48,13 +48,17 @@ #include "wx/msw/private.h" #endif -#if USE_IOSTREAMH +#if wxUSE_IOSTREAMH #include +#include #else #include +#include +# ifdef _MSC_VER + using namespace std; +# endif #endif -#include #include #include #include @@ -127,7 +131,7 @@ double UnderlineThickness = 0.0F; #define _MAXPATHLEN 500 /* See "wxspline.inc" and "xfspline.inc" */ -#if USE_XFIG_SPLINE_CODE +#if wxUSE_XFIG_SPLINE_CODE static const char *wxPostScriptHeaderSpline = " \ /DrawSplineSection {\n\ /y3 exch def\n\ @@ -148,7 +152,7 @@ static const char *wxPostScriptHeaderSpline = " \ // No extra PS header for this spline implementation. static const char *wxPostScriptHeaderSpline = (char *) NULL; -#endif /* USE_XFIG_SPLINE_CODE */ +#endif /* wxUSE_XFIG_SPLINE_CODE */ // steve, 05.09.94 // VMS has a bug in the ofstream class. @@ -161,6 +165,7 @@ static char *fileBuffer = NULL; #endif #if !USE_SHARED_LIBRARY +IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule, wxModule) IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC, wxDC) IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType, wxObject) @@ -294,7 +299,7 @@ void wxPostScriptDC::SetClippingRegion (long cx, long cy, long cw, long ch) *m_pstream << "gsave\n"; *m_pstream << "newpath\n"; *m_pstream << cx << " " << YSCALE (cy) << " moveto\n"; - *m_pstream << cx + cw << " " << YSCALE (cy) << " lineto\n"; + *m_pstream << (cx + cw) << " " << YSCALE (cy) << " lineto\n"; *m_pstream << cx + cw << " " << YSCALE (cy + ch) << " lineto\n"; *m_pstream << cx << " " << YSCALE (cy + ch) << " lineto\n"; *m_pstream << "closepath clip newpath\n"; @@ -413,10 +418,10 @@ void wxPostScriptDC::DrawEllipticArc(long x,long y,long w,long h,double sa,doubl { SetBrush (m_brush); - *m_pstream << + *m_pstream << "newpath\n" << - x+w/2 << " " << YSCALE (y+h/2) << " " << - w/2 << " " << h/2 << " " << + (x+w/2) << " " << YSCALE (y+h/2) << " " << + w/2 << " " << (h/2) << " " << int(sa) <<" "<< int(ea)<<" true ellipticarc\n"; CalcBoundingBox (x , (long)YSCALE (y )); @@ -426,10 +431,10 @@ void wxPostScriptDC::DrawEllipticArc(long x,long y,long w,long h,double sa,doubl { SetPen (m_pen); - *m_pstream << + *m_pstream << "newpath\n" << - x+w/2 << " " << YSCALE (y+h/2) << " " << - w/2 << " " << h/2 << " " << + (x+w/2) << " " << YSCALE (y+h/2) << " " << + (w/2) << " " << (h/2) << " " << int(sa) <<" "<< int(ea)<<" false ellipticarc\n"; CalcBoundingBox (x , (long)YSCALE (y )); @@ -545,8 +550,8 @@ void wxPostScriptDC::DrawRectangle (long x, long y, long width, long height) *m_pstream << "newpath\n"; *m_pstream << x << " " << YSCALE (y) << " moveto\n"; - *m_pstream << x + width << " " << YSCALE (y) << " lineto\n"; - *m_pstream << x + width << " " << YSCALE (y + height) << " lineto\n"; + *m_pstream << (x + width) << " " << YSCALE (y) << " lineto\n"; + *m_pstream << (x + width) << " " << YSCALE (y + height) << " lineto\n"; *m_pstream << x << " " << YSCALE (y + height) << " lineto\n"; *m_pstream << "closepath\n"; *m_pstream << "fill\n"; @@ -560,8 +565,8 @@ void wxPostScriptDC::DrawRectangle (long x, long y, long width, long height) *m_pstream << "newpath\n"; *m_pstream << x << " " << YSCALE (y) << " moveto\n"; - *m_pstream << x + width << " " << YSCALE (y) << " lineto\n"; - *m_pstream << x + width << " " << YSCALE (y + height) << " lineto\n"; + *m_pstream << (x + width) << " " << YSCALE (y) << " lineto\n"; + *m_pstream << (x + width) << " " << YSCALE (y + height) << " lineto\n"; *m_pstream << x << " " << YSCALE (y + height) << " lineto\n"; *m_pstream << "closepath\n"; *m_pstream << "stroke\n"; @@ -593,19 +598,19 @@ void wxPostScriptDC::DrawRoundedRectangle (long x, long y, long width, long heig SetBrush (m_brush); // Draw rectangle anticlockwise *m_pstream << "newpath\n"; - *m_pstream << x + radius << " " << YSCALE (y + radius) << " " << radius << " 90 180 arc\n"; + *m_pstream << (x + radius) << " " << YSCALE (y + radius) << " " << radius << " 90 180 arc\n"; *m_pstream << x << " " << YSCALE (y + radius) << " moveto\n"; - *m_pstream << x + radius << " " << YSCALE (y + height - radius) << " " << radius << " 180 270 arc\n"; - *m_pstream << x + width - radius << " " << YSCALE (y + height) << " lineto\n"; + *m_pstream << (x + radius) << " " << YSCALE (y + height - radius) << " " << radius << " 180 270 arc\n"; + *m_pstream << (x + width - radius) << " " << YSCALE (y + height) << " lineto\n"; - *m_pstream << x + width - radius << " " << YSCALE (y + height - radius) << " " << radius << " 270 0 arc\n"; - *m_pstream << x + width << " " << YSCALE (y + radius) << " lineto\n"; + *m_pstream << (x + width - radius) << " " << YSCALE (y + height - radius) << " " << radius << " 270 0 arc\n"; + *m_pstream << (x + width) << " " << YSCALE (y + radius) << " lineto\n"; - *m_pstream << x + width - radius << " " << YSCALE (y + radius) << " " << radius << " 0 90 arc\n"; + *m_pstream << (x + width - radius) << " " << YSCALE (y + radius) << " " << radius << " 0 90 arc\n"; - *m_pstream << x + radius << " " << YSCALE (y) << " lineto\n"; + *m_pstream << (x + radius) << " " << YSCALE (y) << " lineto\n"; *m_pstream << "closepath\n"; @@ -619,19 +624,19 @@ void wxPostScriptDC::DrawRoundedRectangle (long x, long y, long width, long heig SetPen (m_pen); // Draw rectangle anticlockwise *m_pstream << "newpath\n"; - *m_pstream << x + radius << " " << YSCALE (y + radius) << " " << radius << " 90 180 arc\n"; + *m_pstream << (x + radius) << " " << YSCALE (y + radius) << " " << radius << " 90 180 arc\n"; *m_pstream << x << " " << YSCALE (y + height - radius) << " lineto\n"; - *m_pstream << x + radius << " " << YSCALE (y + height - radius) << " " << radius << " 180 270 arc\n"; - *m_pstream << x + width - radius << " " << YSCALE (y + height) << " lineto\n"; + *m_pstream << (x + radius) << " " << YSCALE (y + height - radius) << " " << radius << " 180 270 arc\n"; + *m_pstream << (x + width - radius) << " " << YSCALE (y + height) << " lineto\n"; - *m_pstream << x + width - radius << " " << YSCALE (y + height - radius) << " " << radius << " 270 0 arc\n"; - *m_pstream << x + width << " " << YSCALE (y + radius) << " lineto\n"; + *m_pstream << (x + width - radius) << " " << YSCALE (y + height - radius) << " " << radius << " 270 0 arc\n"; + *m_pstream << (x + width) << " " << YSCALE (y + radius) << " lineto\n"; - *m_pstream << x + width - radius << " " << YSCALE (y + radius) << " " << radius << " 0 90 arc\n"; + *m_pstream << (x + width - radius) << " " << YSCALE (y + radius) << " " << radius << " 0 90 arc\n"; - *m_pstream << x + radius << " " << YSCALE (y) << " lineto\n"; + *m_pstream << (x + radius) << " " << YSCALE (y) << " lineto\n"; *m_pstream << "closepath\n"; @@ -651,8 +656,8 @@ void wxPostScriptDC::DrawEllipse (long x, long y, long width, long height) SetBrush (m_brush); *m_pstream << "newpath\n"; - *m_pstream << x + width / 2 << " " << YSCALE (y + height / 2) << " "; - *m_pstream << width / 2 << " " << height / 2 << " 0 360 ellipse\n"; + *m_pstream << (x + width / 2) << " " << YSCALE (y + height / 2) << " "; + *m_pstream << (width / 2) << " " << (height / 2) << " 0 360 ellipse\n"; *m_pstream << "fill\n"; CalcBoundingBox (x - width, (long)YSCALE (y - height)); @@ -663,8 +668,8 @@ void wxPostScriptDC::DrawEllipse (long x, long y, long width, long height) SetPen (m_pen); *m_pstream << "newpath\n"; - *m_pstream << x + width / 2 << " " << YSCALE (y + height / 2) << " "; - *m_pstream << width / 2 << " " << height / 2 << " 0 360 ellipse\n"; + *m_pstream << (x + width / 2) << " " << YSCALE (y + height / 2) << " "; + *m_pstream << (width / 2) << " " << (height / 2) << " 0 360 ellipse\n"; *m_pstream << "stroke\n"; CalcBoundingBox (x - width, (long)YSCALE (y - height)); @@ -767,7 +772,7 @@ void wxPostScriptDC::SetFont (const wxFont& the_font) strcpy (buf, name); strcat (buf, style); *m_pstream << buf << " findfont\n"; - *m_pstream << m_font.GetPointSize() * m_scaleFactor << " scalefont setfont\n"; + *m_pstream << (m_font.GetPointSize() * m_scaleFactor) << " scalefont setfont\n"; } void wxPostScriptDC::SetPen (const wxPen& pen) @@ -976,10 +981,10 @@ void wxPostScriptDC::DrawText (const wxString& text, long x, long y, bool WXUNUS *m_pstream << "gsave " << x << " " << YSCALE (y + size - UnderlinePosition) << " moveto\n" << UnderlineThickness << " setlinewidth " - << x + w << " " << YSCALE (y + size - UnderlinePosition) + << (x + w) << " " << YSCALE (y + size - UnderlinePosition) << " lineto stroke grestore\n"; } - + CalcBoundingBox (x, (long)YSCALE (y + size)); CalcBoundingBox (x + size * strlen ((char *)(const char *)text), (long)YSCALE (y)); } @@ -1056,7 +1061,7 @@ bool wxPostScriptDC::StartDoc (const wxString& message) // VMS is sh*t! m_pstream = new ofstream; if(fileBuffer) delete[] fileBuffer; - fileBuffer = new char[VMS_BUFSIZ]; + fileBuffer = new char[VMS_BUFSIZ]; m_pstream->setbuf(fileBuffer,VMS_BUFSIZ); m_pstream->open(wxThePrintSetupData->GetPrinterFile()); #else @@ -1216,7 +1221,7 @@ void wxPostScriptDC::EndDoc (void) *m_pstream << "%%BoundingBox: " << floor((double)llx) << " " << floor((double)lly) << " " << ceil((double)urx) << " " << ceil((double)ury) << "\n"; - *m_pstream << "%%Pages: " << wxPageNumber - 1 << "\n"; + *m_pstream << "%%Pages: " << (wxPageNumber - 1) << "\n"; *m_pstream << "%%EndComments\n\n"; // To check the correctness of the bounding box, postscript commands @@ -1237,7 +1242,7 @@ void wxPostScriptDC::EndDoc (void) if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE) { real_translate_y -= m_maxY; - // The following line can be used instead of the adjustment to + // The following line can be used instead of the adjustment to // llx and urx above. // real_translate_y -= m_minX; *m_pstream << "90 rotate\n"; @@ -1247,7 +1252,7 @@ void wxPostScriptDC::EndDoc (void) * We should rationalise the scaling code to one place. JACS, October 1995 * Do we take the next 2 lines out or not? */ - + *m_pstream << wx_printer_scale_x << " " << wx_printer_scale_y << " scale\n"; *m_pstream << wx_printer_translate_x << " " << real_translate_y << " translate\n"; #endif @@ -1303,7 +1308,7 @@ void wxPostScriptDC::EndDoc (void) char * opts = wxThePrintSetupData->GetPrinterOptions(); if (opts && *opts) argv[argc++] = opts; - + argv[argc++] = wxThePrintSetupData->GetPrinterFile(); argv[argc++] = (char *) NULL; wxExecute (argv, TRUE); @@ -1322,7 +1327,7 @@ void wxPostScriptDC::StartPage (void) { if (!m_pstream) return; - *m_pstream << "%%Page: " << wxPageNumber++ << "\n"; + *m_pstream << "%%Page: " << (wxPageNumber++) << "\n"; // *m_pstream << "matrix currentmatrix\n"; // Added by Chris Breeze @@ -1403,8 +1408,6 @@ void wxPostScriptDC::EndPage (void) #endif } -/* MATTHEW: Implement Blit: */ -/* MATTHEW: [4] Re-wrote to use colormap */ bool wxPostScriptDC:: Blit (long xdest, long ydest, long fwidth, long fheight, wxDC *source, long xsrc, long ysrc, int WXUNUSED(rop), bool WXUNUSED(useMask)) @@ -1441,7 +1444,7 @@ Blit (long xdest, long ydest, long fwidth, long fheight, XImage *image; long j, i; char s[3]; - + #ifdef __WXGTK__ d = gdk_display; @@ -1449,7 +1452,7 @@ Blit (long xdest, long ydest, long fwidth, long fheight, GdkWindow *gwin = ((wxClientDC*)source)->GetWindow(); image = XGetImage(d, ((GdkWindowPrivate*)gwin)->xwindow, x, y, width, height, AllPlanes, ZPixmap); -#else +#else #ifdef __WXMOTIF__ // TODO. for now, use global display @@ -1462,7 +1465,7 @@ Blit (long xdest, long ydest, long fwidth, long fheight, cm = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) d); // TODO - implement GetPixmap() and uncomment this line // image = XGetImage(d, source->GetPixmap(), x, y, width, height, AllPlanes, ZPixmap); - + #endif @@ -1492,10 +1495,10 @@ Blit (long xdest, long ydest, long fwidth, long fheight, pixel = cachedest[k]; goto install; } - + cachesrc[cache_pos] = xcol.pixel = spixel; XQueryColor(d, cm, &xcol); - + long r, g, b; r = (long)((double)(xcol.red) / MAX_COLOR); @@ -1505,13 +1508,13 @@ Blit (long xdest, long ydest, long fwidth, long fheight, pixel = (int)(255 * sqrt(((r * r) + (g * g) + (b * b)) / 3)); cachedest[cache_pos] = pixel; - + if (++cache_pos >= CM_CACHE_SIZE) { cache_pos = 0; all_cache = TRUE; } - install: + install: int h, l; h = (pixel >> 4) & 0xF; @@ -1525,7 +1528,7 @@ Blit (long xdest, long ydest, long fwidth, long fheight, s[1] = '0' + l; else s[1] = 'a' + (l - 10); - + *m_pstream << s; } *m_pstream << "\n"; @@ -1578,7 +1581,7 @@ void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, *externalLeading = 0; #else // +++++ start of contributed code +++++ - + // ************************************************************ // method for calculating string widths in postscript: // read in the AFM (adobe font metrics) file for the @@ -1671,16 +1674,16 @@ void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, // // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ; // - // that means, we have a character with ascii code 63, and width + // that means, we have a character with ascii code 63, and width // (444/1000 * fontSize) points. // the other data is ignored for now! // // when the font has changed, we read in the right AFM file and store the // character widths in an array, which is processed below (see point 3.). - + // new elements JC Sun Aug 25 23:21:44 MET DST 1996 - + strcat(afmName,name); strcat(afmName,".afm"); FILE *afmFile = fopen(afmName,"r"); @@ -1797,7 +1800,7 @@ void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, if(lastDescender!=INT_MIN){ height += (long)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */ } - + // return size values *x = widthSum; *y = height; @@ -1820,7 +1823,7 @@ void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, #endif } -void wxPostScriptDC::DrawOpenSpline( wxList *points ) +void wxPostScriptDC::DrawSpline( wxList *points ) { double a, b, c, d, x1, y1, x2, y2, x3, y3; wxPoint *p, *q; @@ -1836,7 +1839,7 @@ void wxPostScriptDC::DrawOpenSpline( wxList *points ) x3 = a = (double)(x1 + c) / 2; y3 = b = (double)(y1 + d) / 2; - *(GetStream()) << "newpath " << x1 << " " << GetYOrigin() - y1 << " moveto " << x3 << " " << GetYOrigin() - y3; + *(GetStream()) << "newpath " << x1 << " " << (GetYOrigin() - y1) << " moveto " << x3 << " " << (GetYOrigin() - y3); *(GetStream()) << " lineto\n"; CalcBoundingBox( (long)x1, (long)(GetYOrigin() - y1)); CalcBoundingBox( (long)x3, (long)(GetYOrigin() - y3)); @@ -1850,17 +1853,17 @@ void wxPostScriptDC::DrawOpenSpline( wxList *points ) c = q->x; d = q->y; x3 = (double)(x2 + c) / 2; y3 = (double)(y2 + d) / 2; - *(GetStream()) << x1 << " " << GetYOrigin() - y1 << " " << x2 << " " << GetYOrigin() - y2 << " "; - *(GetStream()) << x3 << " " << GetYOrigin() - y3 << " DrawSplineSection\n"; + *(GetStream()) << x1 << " " << (GetYOrigin() - y1) << " " << x2 << " " << (GetYOrigin() - y2) << " "; + *(GetStream()) << x3 << " " << (GetYOrigin() - y3) << " DrawSplineSection\n"; CalcBoundingBox( (long)x1, (long)(GetYOrigin() - y1)); CalcBoundingBox( (long)x3, (long)(GetYOrigin() - y3)); } /* - * At this point, (x2,y2) and (c,d) are the position of the + * At this point, (x2,y2) and (c,d) are the position of the * next-to-last and last point respectively, in the point list */ - *(GetStream()) << c << " " << GetYOrigin() - d << " lineto stroke\n"; + *(GetStream()) << c << " " << (GetYOrigin() - d) << " lineto stroke\n"; } long wxPostScriptDC::GetCharWidth (void) @@ -2058,14 +2061,14 @@ wxDialog(parent, -1, title, pos, size, style) int yPos = 40; #if defined(__WXGTK__) || defined (__WXMOTIF__) - (void) new wxStaticText( this, -1, _("Printer Command: "), + (void) new wxStaticText( this, -1, _("Printer Command: "), wxPoint(5, yPos) ); - (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND, wxThePrintSetupData->GetPrinterCommand(), + (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND, wxThePrintSetupData->GetPrinterCommand(), wxPoint(100, yPos), wxSize(100, -1) ); - - (void) new wxStaticText( this, -1, _("Printer Options: "), + + (void) new wxStaticText( this, -1, _("Printer Options: "), wxPoint(210, yPos) ); - (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS, wxThePrintSetupData->GetPrinterOptions(), + (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS, wxThePrintSetupData->GetPrinterOptions(), wxPoint(305, yPos), wxSize(150, -1) ); yPos += 40; @@ -2101,7 +2104,7 @@ wxDialog(parent, -1, title, pos, size, style) #endif radio1->SetSelection((int)wxThePrintSetupData->GetPrinterMode()); - + long wx_printer_translate_x, wx_printer_translate_y; double wx_printer_scale_x, wx_printer_scale_y; wxThePrintSetupData->GetPrinterTranslation(&wx_printer_translate_x, &wx_printer_translate_y); @@ -2318,7 +2321,7 @@ void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd) { if (cmd == previewCommand) return; - + if (previewCommand) delete[] previewCommand; if (cmd) @@ -2344,7 +2347,7 @@ void wxPrintSetupData::SetPrinterOptions(const char *flags) { if (printerFlags == flags) return; - + if (printerFlags) delete[] printerFlags; if (flags) @@ -2357,7 +2360,7 @@ void wxPrintSetupData::SetPrinterFile(const char *f) { if (f == printerFile) return; - + if (printerFile) delete[] printerFile; if (f) @@ -2393,7 +2396,7 @@ void wxPrintSetupData::SetAFMPath(const char *f) { if (f == afmPath) return; - + if (afmPath) delete[] afmPath; if (f) @@ -2560,7 +2563,7 @@ void wxPrintPaperDatabase::CreateDatabase(void) // Can't remember where the PostScript origin is by default. // Heck, someone will know how to make it hunky-dory... // JACS 25/5/95 - + AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842); AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191); AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791); @@ -2586,4 +2589,25 @@ wxPrintPaperType *wxPrintPaperDatabase::FindPaperType(const char *name) return (wxPrintPaperType *) NULL; } +/* + * Initialization/cleanup module + */ + +bool wxPostScriptModule::OnInit() +{ + wxInitializePrintSetupData(); + wxThePrintPaperDatabase = new wxPrintPaperDatabase; + wxThePrintPaperDatabase->CreateDatabase(); + + return TRUE; +} + +void wxPostScriptModule::OnExit() +{ + wxInitializePrintSetupData(FALSE); + delete wxThePrintPaperDatabase; + wxThePrintPaperDatabase = NULL; +} + + #endif