X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f04371f0813ccd2a71f35aa94eeefb47ef74854b..e487524e492809638b7e335937c41fd432458a54:/src/gtk1/dcps.cpp diff --git a/src/gtk1/dcps.cpp b/src/gtk1/dcps.cpp index 5530fdaeab..bb7800ea0d 100644 --- a/src/gtk1/dcps.cpp +++ b/src/gtk1/dcps.cpp @@ -21,6 +21,7 @@ #include "wx/filedlg.h" #include "wx/app.h" #include "wx/msgdlg.h" +#include "wx/image.h" //----------------------------------------------------------------------------- // start and end of document/page @@ -254,6 +255,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 +305,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 +332,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 +366,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 +385,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 +448,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 +490,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 +506,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 +556,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 +583,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 +620,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 +681,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 +712,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 +790,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 +869,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 +908,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 +1003,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 +1066,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 +1076,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 +1097,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 +1149,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 +1245,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 +1307,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,7 +1343,7 @@ void wxPostScriptDC::StartPage () void wxPostScriptDC::EndPage () { - if (!m_pstream) return; + wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" ); *m_pstream << "showpage\n"; } @@ -1293,6 +1351,8 @@ 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( m_ok && m_pstream, FALSE, "invalid postscript dc" ); + return TRUE; } @@ -1586,13 +1646,13 @@ 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; } }