X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b8f3257625070bda4bf9289e6089c95e0ac61223..166c3ef0f9a77a66143968be2c1b58747994d32e:/src/gtk/gnome/gprint.cpp diff --git a/src/gtk/gnome/gprint.cpp b/src/gtk/gnome/gprint.cpp index b338acf603..0e14a5ca39 100644 --- a/src/gtk/gnome/gprint.cpp +++ b/src/gtk/gnome/gprint.cpp @@ -19,14 +19,19 @@ #if wxUSE_LIBGNOMEPRINT -#include "wx/math.h" +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/dcmemory.h" + #include "wx/icon.h" + #include "wx/math.h" + #include "wx/image.h" + #include "wx/module.h" +#endif + #include "wx/fontutil.h" #include "wx/gtk/private.h" -#include "wx/module.h" #include "wx/dynlib.h" -#include "wx/dcmemory.h" -#include "wx/log.h" -#include "wx/icon.h" +#include "wx/paper.h" #include #include @@ -277,7 +282,7 @@ wxGnomePrintNativeData::wxGnomePrintNativeData() wxGnomePrintNativeData::~wxGnomePrintNativeData() { - g_object_unref (G_OBJECT (m_config)); + g_object_unref (m_config); } bool wxGnomePrintNativeData::TransferTo( wxPrintData &data ) @@ -305,14 +310,14 @@ wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview 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, @@ -350,6 +355,11 @@ wxDialog *wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow *parent, wxPrint return NULL; } +wxDC* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData& data ) +{ + return new wxGnomePrintDC(data); +} + bool wxGnomePrintFactory::HasOwnPrintToFile() { return true; @@ -704,7 +714,7 @@ bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) if (!dc) { gs_lgp->gnome_print_job_close( job ); - g_object_unref (G_OBJECT (job)); + g_object_unref (job); sm_lastError = wxPRINTER_ERROR; return false; } @@ -735,7 +745,7 @@ bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) if (maxPage == 0) { gs_lgp->gnome_print_job_close( job ); - g_object_unref (G_OBJECT (job)); + g_object_unref (job); sm_lastError = wxPRINTER_ERROR; return false; } @@ -780,10 +790,11 @@ bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) gs_lgp->gnome_print_job_close( job ); if (m_native_preview) { + const wxCharBuffer title(wxGTK_CONV_SYS(_("Print preview"))); GtkWidget *preview = gs_lgp->gnome_print_job_preview_new ( job, - wxGTK_CONV_SYS(_("Print preview")) + (const guchar *)title.data() ); gtk_widget_show(preview); } @@ -792,7 +803,7 @@ bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) gs_lgp->gnome_print_job_print( job ); } - g_object_unref (G_OBJECT (job)); + g_object_unref (job); delete dc; return (sm_lastError == wxPRINTER_NO_ERROR); @@ -830,6 +841,7 @@ wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter *printer ) 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" ); @@ -842,11 +854,36 @@ wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter *printer ) m_signY = -1; // default y-axis bottom up -> top down } +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_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 +} + wxGnomePrintDC::~wxGnomePrintDC() { + if (m_job) + g_object_unref (m_job); } -bool wxGnomePrintDC::Ok() const +bool wxGnomePrintDC::IsOk() const { return true; } @@ -1159,7 +1196,7 @@ void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, } } -void wxGnomePrintDC::makeEllipticalPath(wxCoord x, wxCoord y, +void wxGnomePrintDC::makeEllipticalPath(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { double r = 4 * (sqrt (2) - 1) / 3; @@ -1169,22 +1206,22 @@ void wxGnomePrintDC::makeEllipticalPath(wxCoord x, wxCoord y, halfHR = r * halfH; wxCoord halfWI = (wxCoord) halfW, halfHI = (wxCoord) halfH; - + gs_lgp->gnome_print_newpath( m_gpc ); - + // Approximate an ellipse using four cubic splines, clockwise from 0 deg */ gs_lgp->gnome_print_moveto( m_gpc, - XLOG2DEV(x + width), + XLOG2DEV(x + width), YLOG2DEV(y + halfHI) ); gs_lgp->gnome_print_curveto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), - XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), + XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), YLOG2DEV(y + height), - XLOG2DEV(x + halfWI), + XLOG2DEV(x + halfWI), YLOG2DEV(y + height) ); gs_lgp->gnome_print_curveto( m_gpc, - XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)), + XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)), YLOG2DEV(y + height), XLOG2DEV(x), YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), @@ -1201,7 +1238,7 @@ void wxGnomePrintDC::makeEllipticalPath(wxCoord x, wxCoord y, XLOG2DEV(x + width), YLOG2DEV(y + (wxCoord) rint(halfH - halfHR)), XLOG2DEV(x + width), YLOG2DEV(y + halfHI) ); - + gs_lgp->gnome_print_closepath(m_gpc); } @@ -1533,7 +1570,7 @@ void wxGnomePrintDC::SetPen( const wxPen& pen ) case wxSHORT_DASH: gs_lgp->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break; case wxLONG_DASH: gs_lgp->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break; case wxDOT_DASH: gs_lgp->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break; - case wxUSER_DASH: + case wxUSER_DASH: { // It may be noted that libgnomeprint between at least // versions 2.8.0 and 2.12.1 makes a copy of the dashes @@ -1834,5 +1871,95 @@ void wxGnomePrintModule::OnExit() 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); + m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); + } + else + { + m_pageWidth = sizeDevUnits.x; + m_pageHeight = sizeDevUnits.y; + m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y); + m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); + } + + // At 100%, the page should look about page-size on the screen. + m_previewScale = (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution(); + } +} + #endif // wxUSE_LIBGNOMEPRINT