X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f04371f0813ccd2a71f35aa94eeefb47ef74854b..fd323a5e230f2b08227b307ff900698fb85d5519:/src/gtk1/dcps.cpp diff --git a/src/gtk1/dcps.cpp b/src/gtk1/dcps.cpp index 5530fdaeab..710668c98a 100644 --- a/src/gtk1/dcps.cpp +++ b/src/gtk1/dcps.cpp @@ -14,6 +14,10 @@ #pragma interface #endif +#include "wx/defs.h" + +#if wxUSE_POSTSCRIPT + #include "wx/postscrp.h" #include "wx/dcmemory.h" #include "wx/utils.h" @@ -21,6 +25,11 @@ #include "wx/filedlg.h" #include "wx/app.h" #include "wx/msgdlg.h" +#include "wx/image.h" +#include "wx/log.h" + +#include "gdk/gdk.h" +#include "gtk/gtk.h" //----------------------------------------------------------------------------- // start and end of document/page @@ -254,6 +263,11 @@ wxPostScriptDC::~wxPostScriptDC () if (m_pstream) delete m_pstream; } +bool wxPostScriptDC::Ok() const +{ + return m_ok; +} + bool wxPostScriptDC::PrinterDialog(wxWindow *parent) { wxPostScriptPrintDialog dialog( parent, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400), @@ -299,14 +313,14 @@ bool wxPostScriptDC::PrinterDialog(wxWindow *parent) m_ok = TRUE; } - return m_ok; + return m_ok; } void wxPostScriptDC::SetClippingRegion (long x, long y, long w, long h) { - if (m_clipping) return; + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); - if (!m_pstream) return; + if (m_clipping) return; wxDC::SetClippingRegion( x, y, w, h ); @@ -326,7 +340,7 @@ void wxPostScriptDC::SetClippingRegion( const wxRegion &WXUNUSED(region) ) void wxPostScriptDC::DestroyClippingRegion() { - if (!m_pstream) return; + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); wxDC::DestroyClippingRegion(); @@ -360,7 +374,7 @@ void wxPostScriptDC::CrossHair (long WXUNUSED(x), long WXUNUSED(y)) void wxPostScriptDC::DrawLine (long x1, long y1, long x2, long y2) { - if (!m_pstream) return; + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (m_pen.GetStyle() == wxTRANSPARENT) return; @@ -379,8 +393,8 @@ 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) { - if (!m_pstream) return; - + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); + long dx = x1 - xc; long dy = y1 - yc; long radius = (long) sqrt(dx*dx+dy*dy); @@ -442,8 +456,8 @@ 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) { - if (!m_pstream) return; - + 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; if (sa<0) sa+=360; @@ -484,7 +498,7 @@ void wxPostScriptDC::DrawEllipticArc(long x,long y,long w,long h,double sa,doubl void wxPostScriptDC::DrawPoint (long x, long y) { - if (!m_pstream) return; + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (m_pen.GetStyle() == wxTRANSPARENT) return; @@ -500,8 +514,8 @@ void wxPostScriptDC::DrawPoint (long x, long y) void wxPostScriptDC::DrawPolygon (int n, wxPoint points[], long xoffset, long yoffset, int WXUNUSED(fillStyle)) { - if (!m_pstream) return; - + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); + if (n <= 0) return; if (m_brush.GetStyle () != wxTRANSPARENT) @@ -550,8 +564,8 @@ void wxPostScriptDC::DrawPolygon (int n, wxPoint points[], long xoffset, long yo void wxPostScriptDC::DrawLines (int n, wxPoint points[], long xoffset, long yoffset) { - if (!m_pstream) return; - + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); + if (m_pen.GetStyle() == wxTRANSPARENT) return; if (n <= 0) return; @@ -577,7 +591,7 @@ void wxPostScriptDC::DrawLines (int n, wxPoint points[], long xoffset, long yoff void wxPostScriptDC::DrawRectangle (long x, long y, long width, long height) { - if (!m_pstream) return; + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (m_brush.GetStyle () != wxTRANSPARENT) { @@ -614,8 +628,8 @@ void wxPostScriptDC::DrawRectangle (long x, long y, long width, long height) void wxPostScriptDC::DrawRoundedRectangle (long x, long y, long width, long height, double radius) { - if (!m_pstream) return; - + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); + if (radius < 0.0) { // Now, a negative radius is interpreted to mean @@ -675,8 +689,8 @@ void wxPostScriptDC::DrawRoundedRectangle (long x, long y, long width, long heig void wxPostScriptDC::DrawEllipse (long x, long y, long width, long height) { - if (!m_pstream) return; - + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); + if (m_brush.GetStyle () != wxTRANSPARENT) { SetBrush (m_brush); @@ -706,22 +720,67 @@ void wxPostScriptDC::DrawEllipse (long x, long y, long width, long height) void wxPostScriptDC::DrawIcon (const wxIcon& icon, long x, long y) { - 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) ) { - wxMemoryDC memDC; - memDC.SelectObject( bitmap ); - Blit( x, y, bitmap.GetWidth(), bitmap.GetHeight(), &memDC, 0, 0, useMask ); + 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"; + } void wxPostScriptDC::SetFont (const wxFont& font) { - if (!m_pstream) return; - + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); + if (!font.Ok()) return; m_font = font; @@ -739,8 +798,8 @@ void wxPostScriptDC::SetFont (const wxFont& font) void wxPostScriptDC::SetPen( const wxPen& pen ) { - if (!m_pstream) return; - + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); + if (!pen.Ok()) return; int oldStyle = m_pen.GetStyle(); @@ -818,8 +877,8 @@ void wxPostScriptDC::SetPen( const wxPen& pen ) void wxPostScriptDC::SetBrush( const wxBrush& brush ) { - if (!m_pstream) return; - + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); + if (!brush.Ok()) return; m_brush = brush; @@ -857,8 +916,8 @@ void wxPostScriptDC::SetBrush( const wxBrush& brush ) void wxPostScriptDC::DrawText( const wxString& text, long x, long y, bool WXUNUSED(use16bit) ) { - if (!m_pstream) return; - + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); + SetFont( m_font ); if (m_textForegroundColour.Ok ()) @@ -952,7 +1011,7 @@ void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function)) void wxPostScriptDC::DrawSpline( wxList *points ) { - if (!m_pstream) return; + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); SetPen( m_pen ); @@ -1015,6 +1074,8 @@ long wxPostScriptDC::GetCharWidth () void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) { + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); + m_signX = (xLeftRight ? 1 : -1); m_signY = (yBottomUp ? 1 : -1); @@ -1023,11 +1084,13 @@ void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) void wxPostScriptDC::SetDeviceOrigin( long x, long y ) { - int h = 0; - int w = 0; - GetSize( &w, &h ); + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); + + int h = 0; + int w = 0; + GetSize( &w, &h ); - wxDC::SetDeviceOrigin( x, h-y ); + wxDC::SetDeviceOrigin( x, h-y ); } void wxPostScriptDC::GetSize(int* width, int* height) const @@ -1042,18 +1105,20 @@ void wxPostScriptDC::GetSize(int* width, int* height) const if (paper) { - *width = paper->widthPixels; - *height = paper->heightPixels; + if (width) *width = paper->widthPixels; + if (height) *height = paper->heightPixels; } else { - *width = 595; - *height = 842; + if (width) *width = 595; + if (height) *height = 842; } } bool wxPostScriptDC::StartDoc (const wxString& message) { + wxCHECK_MSG( m_ok, FALSE, "invalid postscript dc" ); + if (m_filename == "") { m_filename = wxGetTempFileName("ps"); @@ -1092,7 +1157,7 @@ bool wxPostScriptDC::StartDoc (const wxString& message) void wxPostScriptDC::EndDoc () { - if (!m_pstream) return; + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); if (m_clipping) { @@ -1188,6 +1253,7 @@ void wxPostScriptDC::EndDoc () *m_pstream << "%%BeginProlog\n"; *m_pstream << wxPostScriptHeaderEllipse; *m_pstream << wxPostScriptHeaderEllipticArc; + *m_pstream << wxPostScriptHeaderColourImage; *m_pstream << wxPostScriptHeaderReencodeISO1; *m_pstream << wxPostScriptHeaderReencodeISO2; @@ -1249,7 +1315,7 @@ void wxPostScriptDC::EndDoc () void wxPostScriptDC::StartPage () { - if (!m_pstream) return; + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); *m_pstream << "%%Page: " << (wxPageNumber++) << "\n"; @@ -1285,14 +1351,21 @@ void wxPostScriptDC::StartPage () void wxPostScriptDC::EndPage () { - if (!m_pstream) return; + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); *m_pstream << "showpage\n"; } -bool wxPostScriptDC::Blit (long xdest, long ydest, long fwidth, long fheight, - wxDC *source, long xsrc, long ysrc, int WXUNUSED(rop), bool WXUNUSED(useMask)) +bool wxPostScriptDC::Blit( long WXUNUSED(xdest), long WXUNUSED(ydest), + long WXUNUSED(fwidth), long WXUNUSED(fheight), + wxDC *WXUNUSED(source), + long WXUNUSED(xsrc), long WXUNUSED(ysrc), + int WXUNUSED(rop), bool WXUNUSED(useMask) ) { + wxCHECK_MSG( m_ok && m_pstream, FALSE, "invalid postscript dc" ); + + wxFAIL_MSG( "wxPostScriptDC::Blit no yet implemented." ); + return TRUE; } @@ -1439,8 +1512,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. @@ -1459,7 +1532,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); } } @@ -1467,7 +1540,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); } } @@ -1475,7 +1548,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); } } @@ -1483,12 +1556,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); } } @@ -1496,18 +1569,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. @@ -1540,7 +1613,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{ @@ -1586,13 +1659,15 @@ void wxPostScriptDC::GetSizeMM(long *width, long *height) const if (paper) { - *width = paper->widthMM; - *height = paper->heightMM; + if (width) *width = paper->widthMM; + if (height) *height = paper->heightMM; } else { - *width = 210; - *height = 297; + if (width) *width = 210; + if (height) *height = 297; } } +#endif + // wxUSE_POSTSCRIPT