#pragma hdrstop
#endif
-#include "wx/gtk/gnome/gprint.h"
-
#if wxUSE_LIBGNOMEPRINT
+#include "wx/gtk/gnome/gprint.h"
+
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/dcmemory.h"
#include "wx/fontutil.h"
#include "wx/gtk/private.h"
#include "wx/dynlib.h"
+#include "wx/paper.h"
#include <libgnomeprint/gnome-print.h>
#include <libgnomeprint/gnome-print-pango.h>
static const double RAD2DEG = 180.0 / M_PI;
-#include "wx/html/forcelnk.h"
-FORCE_LINK_ME(gnome_print)
+#include "wx/link.h"
+wxFORCE_LINK_THIS_MODULE(gnome_print)
//----------------------------------------------------------------------------
// wxGnomePrintLibrary
wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_job_preview_new,
(GnomePrintJob *gpm, const guchar *title), (gpm, title), NULL )
+
+ DECLARE_NO_COPY_CLASS(wxGnomePrintLibrary)
};
wxGnomePrintLibrary::wxGnomePrintLibrary()
wxPrintout *printout,
wxPrintDialogData *data )
{
- return new wxPostScriptPrintPreview( preview, printout, data );
+ return new wxGnomePrintPreview( preview, printout, data );
}
wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview,
wxPrintout *printout,
wxPrintData *data )
{
- return new wxPostScriptPrintPreview( preview, printout, data );
+ return new wxGnomePrintPreview( preview, printout, data );
}
wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent,
return NULL;
}
+wxDC* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData& data )
+{
+ return new wxGnomePrintDC(data);
+}
+
bool wxGnomePrintFactory::HasOwnPrintToFile()
{
return true;
{
gs_lgp->gnome_print_job_close( job );
g_object_unref (job);
- sm_lastError = wxPRINTER_ERROR;
+ if (sm_lastError != wxPRINTER_CANCELLED)
+ sm_lastError = wxPRINTER_ERROR;
return false;
}
int w, h;
dc->GetSize(&w, &h);
printout->SetPageSizePixels((int)w, (int)h);
- dc->GetSizeMM(&w, &h);
- printout->SetPageSizeMM((int)w, (int)h);
-
+ printout->SetPaperRectPixels(wxRect(0, 0, w, h));
+ int mw, mh;
+ dc->GetSizeMM(&mw, &mh);
+ printout->SetPageSizeMM((int)mw, (int)mh);
printout->OnPreparePrinting();
// Get some parameters from the printout, if defined
m_printer = printer;
m_gpc = printer->GetPrintContext();
+ m_job = NULL; // only used and destroyed when created with wxPrintData
m_layout = gs_lgp->gnome_print_pango_create_layout( m_gpc );
m_fontdesc = pango_font_description_from_string( "Sans 12" );
+ m_context = NULL;
m_currentRed = 0;
m_currentBlue = 0;
m_signX = 1; // default x-axis left to right
m_signY = -1; // default y-axis bottom up -> top down
+
+ GetSize( NULL, &m_deviceOffsetY );
+}
+
+wxGnomePrintDC::wxGnomePrintDC( const wxPrintData& data )
+{
+ m_printer = NULL;
+ m_printData = data;
+
+ wxGnomePrintNativeData *native =
+ (wxGnomePrintNativeData*) m_printData.GetNativeData();
+
+ GnomePrintJob *job = gs_lgp->gnome_print_job_new( native->GetPrintConfig() );
+ m_gpc = gs_lgp->gnome_print_job_get_context (job);
+ m_job = job; // only used and destroyed when created with wxPrintData
+
+ m_layout = gs_lgp->gnome_print_pango_create_layout( m_gpc );
+ m_fontdesc = pango_font_description_from_string( "Sans 12" );
+ m_context = NULL;
+
+ m_currentRed = 0;
+ m_currentBlue = 0;
+ m_currentGreen = 0;
+
+ m_signX = 1; // default x-axis left to right
+ m_signY = -1; // default y-axis bottom up -> top down
+
+ GetSize( NULL, &m_deviceOffsetY );
}
wxGnomePrintDC::~wxGnomePrintDC()
{
+ if (m_job)
+ g_object_unref (m_job);
}
-bool wxGnomePrintDC::Ok() const
+bool wxGnomePrintDC::IsOk() const
{
return true;
}
while (alpha2 > 360) alpha2 -= 360;
}
- if (m_brush.GetStyle() != wxTRANSPARENT)
- {
- SetBrush( m_brush );
- gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) );
- gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 );
+ if (m_brush.GetStyle() != wxTRANSPARENT)
+ {
+ SetBrush( m_brush );
+ gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) );
+ gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 );
- gs_lgp->gnome_print_fill( m_gpc );
- }
+ gs_lgp->gnome_print_fill( m_gpc );
+ }
- if (m_pen.GetStyle() != wxTRANSPARENT)
- {
- SetPen (m_pen);
- gs_lgp->gnome_print_newpath( m_gpc );
- gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) );
- gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 );
- gs_lgp->gnome_print_closepath( m_gpc );
+ if (m_pen.GetStyle() != wxTRANSPARENT)
+ {
+ SetPen (m_pen);
+ gs_lgp->gnome_print_newpath( m_gpc );
+ gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) );
+ gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 );
+ gs_lgp->gnome_print_closepath( m_gpc );
- gs_lgp->gnome_print_stroke( m_gpc );
- }
+ gs_lgp->gnome_print_stroke( m_gpc );
+ }
CalcBoundingBox (x1, y1);
CalcBoundingBox (x2, y2);
bool wxGnomePrintDC::StartDoc(const wxString& message)
{
- SetDeviceOrigin( 0,0 );
-
return true;
}
void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height,
wxCoord *descent,
wxCoord *externalLeading,
- wxFont *theFont ) const
+ const wxFont *theFont ) const
{
if ( width )
*width = 0;
(wxGnomePrintNativeData*) m_printData.GetNativeData();
// Query page size. This seems to omit the margins
- // right now, although it shouldn't
double pw,ph;
gs_lgp->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph );
ComputeScaleAndOrigin();
}
-void wxGnomePrintDC::SetDeviceOrigin( wxCoord x, wxCoord y )
+void wxGnomePrintDC::SetLogicalOrigin( wxCoord x, wxCoord y )
{
- int h = 0;
- int w = 0;
- GetSize( &w, &h );
+ wxDC::SetLogicalOrigin( x, y );
+}
- wxDC::SetDeviceOrigin( x, h-y );
+void wxGnomePrintDC::SetDeviceOrigin( wxCoord x, wxCoord y )
+{
+ wxDC::SetDeviceOrigin( x, y );
}
void wxGnomePrintDC::SetResolution(int ppi)
IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule)
+// ----------------------------------------------------------------------------
+// Print preview
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_CLASS(wxGnomePrintPreview, wxPrintPreviewBase)
+
+void wxGnomePrintPreview::Init(wxPrintout * WXUNUSED(printout),
+ wxPrintout * WXUNUSED(printoutForPrinting))
+{
+ DetermineScaling();
+}
+
+wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout,
+ wxPrintout *printoutForPrinting,
+ wxPrintDialogData *data)
+ : wxPrintPreviewBase(printout, printoutForPrinting, data)
+{
+ Init(printout, printoutForPrinting);
+}
+
+wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout,
+ wxPrintout *printoutForPrinting,
+ wxPrintData *data)
+ : wxPrintPreviewBase(printout, printoutForPrinting, data)
+{
+ Init(printout, printoutForPrinting);
+}
+
+wxGnomePrintPreview::~wxGnomePrintPreview()
+{
+}
+
+bool wxGnomePrintPreview::Print(bool interactive)
+{
+ if (!m_printPrintout)
+ return false;
+
+ wxPrinter printer(& m_printDialogData);
+ return printer.Print(m_previewFrame, m_printPrintout, interactive);
+}
+
+void wxGnomePrintPreview::DetermineScaling()
+{
+ wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId();
+ if (paperType == wxPAPER_NONE)
+ paperType = wxPAPER_NONE;
+
+ wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType);
+ if (!paper)
+ paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4);
+
+ if (paper)
+ {
+ wxSize ScreenPixels = wxGetDisplaySize();
+ wxSize ScreenMM = wxGetDisplaySizeMM();
+
+ m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
+ (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
+ m_previewPrintout->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution());
+
+ wxSize sizeDevUnits(paper->GetSizeDeviceUnits());
+
+ // TODO: get better resolution information from wxGnomePrintDC, if possible.
+
+ sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * wxGnomePrintDC::GetResolution() / 72.0);
+ sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * wxGnomePrintDC::GetResolution() / 72.0);
+ wxSize sizeTenthsMM(paper->GetSize());
+ wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10);
+
+ // If in landscape mode, we need to swap the width and height.
+ if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE )
+ {
+ m_pageWidth = sizeDevUnits.y;
+ m_pageHeight = sizeDevUnits.x;
+ m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x);
+ }
+ else
+ {
+ m_pageWidth = sizeDevUnits.x;
+ m_pageHeight = sizeDevUnits.y;
+ m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y);
+ }
+ m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight);
+ m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight));
+
+ // At 100%, the page should look about page-size on the screen.
+ m_previewScaleX = (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution();
+ m_previewScaleY = m_previewScaleX;
+ }
+}
+
#endif
// wxUSE_LIBGNOMEPRINT