X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4bc67cc550bcd9d5f93f88ae22a4f6ac7fafb5f7..5de5db0eb14aa86b5b177050720deb0f4c210fba:/src/gtk/dcps.cpp diff --git a/src/gtk/dcps.cpp b/src/gtk/dcps.cpp index d4362ef4a4..6812fe95b4 100644 --- a/src/gtk/dcps.cpp +++ b/src/gtk/dcps.cpp @@ -21,6 +21,8 @@ #include "wx/filedlg.h" #include "wx/app.h" #include "wx/msgdlg.h" +#include "wx/image.h" +#include "wx/log.h" //----------------------------------------------------------------------------- // start and end of document/page @@ -256,7 +258,7 @@ wxPostScriptDC::~wxPostScriptDC () bool wxPostScriptDC::Ok() const { - return (m_ok && m_pstream); + return m_ok; } bool wxPostScriptDC::PrinterDialog(wxWindow *parent) @@ -309,7 +311,7 @@ bool wxPostScriptDC::PrinterDialog(wxWindow *parent) void wxPostScriptDC::SetClippingRegion (long x, long y, long w, long h) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (m_clipping) return; @@ -331,7 +333,7 @@ void wxPostScriptDC::SetClippingRegion( const wxRegion &WXUNUSED(region) ) void wxPostScriptDC::DestroyClippingRegion() { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); wxDC::DestroyClippingRegion(); @@ -365,7 +367,7 @@ void wxPostScriptDC::CrossHair (long WXUNUSED(x), long WXUNUSED(y)) void wxPostScriptDC::DrawLine (long x1, long y1, long x2, long y2) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (m_pen.GetStyle() == wxTRANSPARENT) return; @@ -384,7 +386,7 @@ void wxPostScriptDC::DrawLine (long x1, long y1, long x2, long y2) void wxPostScriptDC::DrawArc (long x1, long y1, long x2, long y2, long xc, long yc) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); long dx = x1 - xc; long dy = y1 - yc; @@ -447,7 +449,7 @@ void wxPostScriptDC::DrawArc (long x1, long y1, long x2, long y2, long xc, long void wxPostScriptDC::DrawEllipticArc(long x,long y,long w,long h,double sa,double ea) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (sa>=360 || sa<=-360) sa=sa-int(sa/360)*360; if (ea>=360 || ea<=-360) ea=ea-int(ea/360)*360; @@ -489,7 +491,7 @@ void wxPostScriptDC::DrawEllipticArc(long x,long y,long w,long h,double sa,doubl void wxPostScriptDC::DrawPoint (long x, long y) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (m_pen.GetStyle() == wxTRANSPARENT) return; @@ -505,7 +507,7 @@ void wxPostScriptDC::DrawPoint (long x, long y) void wxPostScriptDC::DrawPolygon (int n, wxPoint points[], long xoffset, long yoffset, int WXUNUSED(fillStyle)) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (n <= 0) return; @@ -555,7 +557,7 @@ void wxPostScriptDC::DrawPolygon (int n, wxPoint points[], long xoffset, long yo void wxPostScriptDC::DrawLines (int n, wxPoint points[], long xoffset, long yoffset) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (m_pen.GetStyle() == wxTRANSPARENT) return; if (n <= 0) return; @@ -582,7 +584,7 @@ void wxPostScriptDC::DrawLines (int n, wxPoint points[], long xoffset, long yoff void wxPostScriptDC::DrawRectangle (long x, long y, long width, long height) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (m_brush.GetStyle () != wxTRANSPARENT) { @@ -619,7 +621,7 @@ void wxPostScriptDC::DrawRectangle (long x, long y, long width, long height) void wxPostScriptDC::DrawRoundedRectangle (long x, long y, long width, long height, double radius) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (radius < 0.0) { @@ -680,7 +682,7 @@ void wxPostScriptDC::DrawRoundedRectangle (long x, long y, long width, long heig void wxPostScriptDC::DrawEllipse (long x, long y, long width, long height) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (m_brush.GetStyle () != wxTRANSPARENT) { @@ -711,25 +713,66 @@ void wxPostScriptDC::DrawEllipse (long x, long y, long width, long height) void wxPostScriptDC::DrawIcon (const wxIcon& icon, long x, long y) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); - - wxMemoryDC memDC; - memDC.SelectObject( icon ); - Blit(x, y, icon.GetWidth(), icon.GetHeight(), &memDC, 0, 0); + DrawBitmap( icon, x, y, TRUE ); } -void wxPostScriptDC::DrawBitmap( const wxBitmap& bitmap, long x, long y, bool useMask ) +void wxPostScriptDC::DrawBitmap( const wxBitmap& bitmap, long x, long y, bool WXUNUSED(useMask) ) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); + + if (!bitmap.Ok()) return; + + wxImage image( bitmap ); + + if (!image.Ok()) return; + + int ww = XLOG2DEVREL(image.GetWidth()); + int hh = YLOG2DEVREL(image.GetHeight()); + + image = image.Scale( ww, hh ); + + if (!image.Ok()) return; + + int xx = XLOG2DEV(x); + int yy = YLOG2DEV(y + bitmap.GetHeight()); + + *m_pstream << "/origstate save def\n" + << "20 dict begin\n" + << "/pix " << ww << " string def\n" + << "/grays " << ww << " string def\n" + << "/npixels 0 def\n" + << "/rgbindx 0 def\n" + << xx << " " << yy << " translate\n" + << ww << " " << hh << " scale\n" + << ww << " " << hh << " 8\n" + << "[" << ww << " 0 0 " << (-hh) << " 0 " << hh << "]\n" + << "{currentfile pix readhexstring pop}\n" + << "false 3 colorimage\n"; + + for (int j = 0; j < hh; j++) + { + for (int i = 0; i < ww; i++) + { + char buffer[5]; + buffer[2] = 0; + wxDecToHex( image.GetRed(i,j), buffer ); + *m_pstream << buffer; + wxDecToHex( image.GetGreen(i,j), buffer ); + *m_pstream << buffer; + wxDecToHex( image.GetBlue(i,j), buffer ); + *m_pstream << buffer; + } + *m_pstream << "\n"; + } + + *m_pstream << "end\n"; + *m_pstream << "origstate restore\n"; - wxMemoryDC memDC; - memDC.SelectObject( bitmap ); - Blit( x, y, bitmap.GetWidth(), bitmap.GetHeight(), &memDC, 0, 0, useMask ); } void wxPostScriptDC::SetFont (const wxFont& font) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (!font.Ok()) return; @@ -748,7 +791,7 @@ void wxPostScriptDC::SetFont (const wxFont& font) void wxPostScriptDC::SetPen( const wxPen& pen ) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (!pen.Ok()) return; @@ -827,7 +870,7 @@ void wxPostScriptDC::SetPen( const wxPen& pen ) void wxPostScriptDC::SetBrush( const wxBrush& brush ) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (!brush.Ok()) return; @@ -866,7 +909,7 @@ void wxPostScriptDC::SetBrush( const wxBrush& brush ) void wxPostScriptDC::DrawText( const wxString& text, long x, long y, bool WXUNUSED(use16bit) ) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); SetFont( m_font ); @@ -961,7 +1004,7 @@ void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function)) void wxPostScriptDC::DrawSpline( wxList *points ) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); SetPen( m_pen ); @@ -1024,7 +1067,7 @@ long wxPostScriptDC::GetCharWidth () void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); m_signX = (xLeftRight ? 1 : -1); m_signY = (yBottomUp ? 1 : -1); @@ -1034,7 +1077,7 @@ void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) void wxPostScriptDC::SetDeviceOrigin( long x, long y ) { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); int h = 0; int w = 0; @@ -1045,8 +1088,6 @@ void wxPostScriptDC::SetDeviceOrigin( long x, long y ) void wxPostScriptDC::GetSize(int* width, int* height) const { - wxCHECK_RET( Ok(), "invalid postscript dc" ); - const char *paperType = wxThePrintSetupData->GetPaperName(); if (!paperType) paperType = _("A4 210 x 297 mm"); @@ -1069,7 +1110,7 @@ void wxPostScriptDC::GetSize(int* width, int* height) const bool wxPostScriptDC::StartDoc (const wxString& message) { - wxCHECK_MSG( Ok(), FALSE, "invalid postscript dc" ); + wxCHECK_MSG( m_ok, FALSE, "invalid postscript dc" ); if (m_filename == "") { @@ -1109,7 +1150,7 @@ bool wxPostScriptDC::StartDoc (const wxString& message) void wxPostScriptDC::EndDoc () { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (m_clipping) { @@ -1205,6 +1246,7 @@ void wxPostScriptDC::EndDoc () *m_pstream << "%%BeginProlog\n"; *m_pstream << wxPostScriptHeaderEllipse; *m_pstream << wxPostScriptHeaderEllipticArc; + *m_pstream << wxPostScriptHeaderColourImage; *m_pstream << wxPostScriptHeaderReencodeISO1; *m_pstream << wxPostScriptHeaderReencodeISO2; @@ -1266,7 +1308,7 @@ void wxPostScriptDC::EndDoc () void wxPostScriptDC::StartPage () { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); *m_pstream << "%%Page: " << (wxPageNumber++) << "\n"; @@ -1302,7 +1344,7 @@ void wxPostScriptDC::StartPage () void wxPostScriptDC::EndPage () { - wxCHECK_RET( Ok(), "invalid postscript dc" ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); *m_pstream << "showpage\n"; } @@ -1310,7 +1352,7 @@ void wxPostScriptDC::EndPage () bool wxPostScriptDC::Blit (long xdest, long ydest, long fwidth, long fheight, wxDC *source, long xsrc, long ysrc, int WXUNUSED(rop), bool WXUNUSED(useMask)) { - wxCHECK_MSG( Ok(), FALSE, "invalid postscript dc" ); + wxCHECK_MSG( m_ok && m_pstream, FALSE, "invalid postscript dc" ); return TRUE; } @@ -1458,8 +1500,8 @@ void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, strcat(afmName,".afm"); FILE *afmFile = fopen(afmName,"r"); if(afmFile==NULL){ - wxDebugMsg("GetTextExtent: can't open AFM file '%s'\n",afmName); - wxDebugMsg(" using approximate values\n"); + wxLogDebug("GetTextExtent: can't open AFM file '%s'\n",afmName); + wxLogDebug(" using approximate values\n"); int i; for (i=0; i<256; i++) lastWidths[i] = 500; // an approximate value lastDescender = -150; // dito. @@ -1478,7 +1520,7 @@ void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, if(strncmp(line,"Descender",9)==0){ if((sscanf(line,"%s%d",descString,&lastDescender)!=2) || (strcmp(descString,"Descender")!=0)) { - wxDebugMsg("AFM-file '%s': line '%s' has error (bad descender)\n", + wxLogDebug("AFM-file '%s': line '%s' has error (bad descender)\n", afmName,line); } } @@ -1486,7 +1528,7 @@ void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, else if(strncmp(line,"UnderlinePosition",17)==0){ if((sscanf(line,"%s%lf",upString,&UnderlinePosition)!=2) || (strcmp(upString,"UnderlinePosition")!=0)) { - wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n", + wxLogDebug("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n", afmName,line); } } @@ -1494,7 +1536,7 @@ void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, else if(strncmp(line,"UnderlineThickness",18)==0){ if((sscanf(line,"%s%lf",utString,&UnderlineThickness)!=2) || (strcmp(utString,"UnderlineThickness")!=0)) { - wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n", + wxLogDebug("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n", afmName,line); } } @@ -1502,12 +1544,12 @@ void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, else if(strncmp(line,"EncodingScheme",14)==0){ if((sscanf(line,"%s%s",utString,encString)!=2) || (strcmp(utString,"EncodingScheme")!=0)) { - wxDebugMsg("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n", + wxLogDebug("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n", afmName,line); } else if (strncmp(encString, "AdobeStandardEncoding", 21)) { - wxDebugMsg("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n", + wxLogDebug("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n", afmName,line, encString); } } @@ -1515,18 +1557,18 @@ void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, else if(strncmp(line,"C ",2)==0){ if(sscanf(line,"%s%d%s%s%d", cString,&ascii,semiString,WXString,&cWidth)!=5){ - wxDebugMsg("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName,line); + wxLogDebug("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName,line); } if(strcmp(cString,"C")!=0 || strcmp(semiString,";")!=0 || strcmp(WXString,"WX")!=0){ - wxDebugMsg("AFM-file '%s': line '%s' has a format error\n",afmName,line); + wxLogDebug("AFM-file '%s': line '%s' has a format error\n",afmName,line); } //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); if(ascii>=0 && ascii<256){ lastWidths[ascii] = cWidth; // store width }else{ /* MATTHEW: this happens a lot; don't print an error */ - // wxDebugMsg("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii); + // wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii); } } // C.) ignore other entries. @@ -1559,7 +1601,7 @@ void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, unsigned char *p; for(p=(unsigned char *)(const char *)string; *p; p++){ if(lastWidths[*p]== INT_MIN){ - wxDebugMsg("GetTextExtent: undefined width for character '%c' (%d)\n", + wxLogDebug("GetTextExtent: undefined width for character '%c' (%d)\n", *p,*p); widthSum += (long)(lastWidths[' ']/1000.0F * Size); // assume space }else{