#include "wx/filedlg.h"
#include "wx/app.h"
#include "wx/msgdlg.h"
+#include "wx/image.h"
//-----------------------------------------------------------------------------
// start and end of document/page
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),
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 );
void wxPostScriptDC::DestroyClippingRegion()
{
- if (!m_pstream) return;
+ wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" );
wxDC::DestroyClippingRegion();
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;
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);
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;
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;
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)
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;
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)
{
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
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);
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;
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();
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;
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 ())
void wxPostScriptDC::DrawSpline( wxList *points )
{
- if (!m_pstream) return;
+ wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" );
SetPen( m_pen );
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);
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
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");
void wxPostScriptDC::EndDoc ()
{
- if (!m_pstream) return;
+ wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" );
if (m_clipping)
{
*m_pstream << "%%BeginProlog\n";
*m_pstream << wxPostScriptHeaderEllipse;
*m_pstream << wxPostScriptHeaderEllipticArc;
+ *m_pstream << wxPostScriptHeaderColourImage;
*m_pstream << wxPostScriptHeaderReencodeISO1;
*m_pstream << wxPostScriptHeaderReencodeISO2;
void wxPostScriptDC::StartPage ()
{
- if (!m_pstream) return;
+ wxCHECK_RET( m_ok && m_pstream, "invalid postscript dc" );
*m_pstream << "%%Page: " << (wxPageNumber++) << "\n";
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))
{
+ wxCHECK_MSG( m_ok && m_pstream, FALSE, "invalid postscript dc" );
+
return TRUE;
}
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;
}
}