#pragma interface
#endif
+#include "wx/defs.h"
+
+#if wxUSE_POSTSCRIPT
+
#include "wx/postscrp.h"
#include "wx/dcmemory.h"
#include "wx/utils.h"
#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
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))
+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;
}
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.
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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.
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{
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