X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a9312950732c67a5e75b0c4e6875140c3757b4c7..9356b709aa15b5304f9fcae7313bc90c451fc4c6:/src/gtk/print.cpp diff --git a/src/gtk/print.cpp b/src/gtk/print.cpp index ab1cd37790..d1f3080828 100644 --- a/src/gtk/print.cpp +++ b/src/gtk/print.cpp @@ -26,6 +26,7 @@ #include "wx/math.h" #include "wx/image.h" #include "wx/module.h" +#include "wx/crt.h" #endif #include "wx/fontutil.h" @@ -60,7 +61,7 @@ static wxCairoLibrary* gs_cairo = NULL; class wxGtkPrintModule: public wxModule { public: - wxGtkPrintModule() + wxGtkPrintModule() { #if wxUSE_LIBGNOMEPRINT // This module must be initialized AFTER gnomeprint's one @@ -79,7 +80,6 @@ bool wxGtkPrintModule::OnInit() gs_cairo = wxCairoLibrary::Get(); if (gs_cairo && gtk_check_version(2,10,0) == NULL) wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory ); - return true; } @@ -184,12 +184,11 @@ wxPrintNativeDataBase *wxGtkPrintFactory::CreatePrintNativeData() //---------------------------------------------------------------------------- // We use it to pass useful objets to gtk printing callback functions. -typedef struct +struct wxPrinterToGtkData { wxGtkPrinter * printer; wxPrintout * printout; -} -wxPrinterToGtkData; +}; extern "C" { @@ -553,11 +552,11 @@ void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings * config ) GtkPageSetup* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings* settings) { GtkPageSetup* page_setup = gtk_page_setup_new(); - gtk_page_setup_set_orientation (page_setup, gtk_print_settings_get_orientation (settings)); + gtk_page_setup_set_orientation (page_setup, gtk_print_settings_get_orientation (settings)); - GtkPaperSize *paper_size = gtk_print_settings_get_paper_size (settings); - if (paper_size != NULL) - gtk_page_setup_set_paper_size_and_default_margins (page_setup, paper_size); + GtkPaperSize *paper_size = gtk_print_settings_get_paper_size (settings); + if (paper_size != NULL) + gtk_page_setup_set_paper_size_and_default_margins (page_setup, paper_size); return page_setup; } @@ -566,7 +565,7 @@ GtkPageSetup* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings* s void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings* settings, GtkPageSetup* page_setup) { gtk_print_settings_set_orientation ( settings, gtk_page_setup_get_orientation (page_setup)); - gtk_print_settings_set_paper_size ( settings, gtk_page_setup_get_paper_size (page_setup)); + gtk_print_settings_set_paper_size ( settings, gtk_page_setup_get_paper_size (page_setup)); } //---------------------------------------------------------------------------- @@ -638,14 +637,14 @@ int wxGtkPrintDialog::ShowModal() // If the settings are OK, we restore it. if (settings != NULL) gtk_print_operation_set_print_settings (native->GetPrintJob(), settings); - gtk_print_operation_set_default_page_setup (native->GetPrintJob(), native->GetPageSetupFromSettings(settings)); + gtk_print_operation_set_default_page_setup (native->GetPrintJob(), native->GetPageSetupFromSettings(settings)); // Show the dialog if needed. GError* gError = NULL; if (GetShowDialog()) response = gtk_print_operation_run (native->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget) ), &gError); else - response = gtk_print_operation_run (native->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT, (GtkWindow *) m_parent, &gError); + response = gtk_print_operation_run (native->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget)), &gError); // Does everything went well? if (response == GTK_PRINT_OPERATION_RESULT_CANCEL) @@ -670,21 +669,29 @@ int wxGtkPrintDialog::ShowModal() case GTK_PRINT_PAGES_CURRENT: m_printDialogData.SetSelection( true ); break; - case GTK_PRINT_PAGES_ALL: - m_printDialogData.SetAllPages( true ); - m_printDialogData.SetFromPage( 0 ); - m_printDialogData.SetToPage( 9999 ); - break; case GTK_PRINT_PAGES_RANGES: - default: - // wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others. + {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others. // For example, the user enters "1-3;5-7" in the dialog: pages 1-3 and 5-7 will be correctly printed when the user // will hit "OK" button. However we can only save 1-3 in the print data. gint num_ranges = 0; GtkPageRange* range; range = gtk_print_settings_get_page_ranges (newSettings, &num_ranges); - m_printDialogData.SetFromPage( range[0].start ); - m_printDialogData.SetToPage( range[0].end ); + if (num_ranges >= 1) + { + m_printDialogData.SetFromPage( range[0].start ); + m_printDialogData.SetToPage( range[0].end ); + } + else { + m_printDialogData.SetAllPages( true ); + m_printDialogData.SetFromPage( 0 ); + m_printDialogData.SetToPage( 9999 ); + } + break;} + case GTK_PRINT_PAGES_ALL: + default: + m_printDialogData.SetAllPages( true ); + m_printDialogData.SetFromPage( 0 ); + m_printDialogData.SetToPage( 9999 ); break; } @@ -840,19 +847,29 @@ bool wxGtkPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) dataToSend.printer = this; dataToSend.printout = printout; - // These Gtk signals are catched here. + // These Gtk signals are caught here. g_signal_connect (printOp, "begin-print", G_CALLBACK (gtk_begin_print_callback), &dataToSend); g_signal_connect (printOp, "draw-page", G_CALLBACK (gtk_draw_page_print_callback), &dataToSend); g_signal_connect (printOp, "end-print", G_CALLBACK (gtk_end_print_callback), printout); g_signal_connect (printOp, "preview", G_CALLBACK (gtk_preview_print_callback), printout); - m_showDialog = true; - if (!prompt) - m_showDialog = false; + // This is used to setup the DC and + // show the dialog if desired + wxGtkPrintDialog dialog( parent, &m_printDialogData ); + dialog.SetPrintDC(m_dc); + dialog.SetShowDialog(prompt); - // PrintDialog returns a wxDC but we created it before so we don't need it anymore: we just delete it. - wxDC* uselessdc = PrintDialog( parent ); - delete uselessdc; + // doesn't necessarily show + int ret = dialog.ShowModal(); + if (ret == wxID_CANCEL) + { + sm_lastError = wxPRINTER_CANCELLED; + } + if (ret == wxID_NO) + { + sm_lastError = wxPRINTER_ERROR; + wxFAIL_MSG(_("The print dialog returned an error.")); + } g_object_unref (printOp); @@ -972,8 +989,15 @@ void wxGtkPrinter::DrawPage(wxPrintout *printout, GtkPrintOperation *operation, GtkPageRange* range; range = gtk_print_settings_get_page_ranges (settings, &num_ranges); // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint. - startPage = range[0].start + 1; - endPage = range[0].end + 1; + if (num_ranges >= 1) + { + startPage = range[0].start + 1; + endPage = range[0].end + 1; + } + else { + startPage = minPage; + endPage = maxPage; + } break;} case GTK_PRINT_PAGES_ALL: default: @@ -1009,13 +1033,11 @@ void wxGtkPrinter::DrawPage(wxPrintout *printout, GtkPrintOperation *operation, wxDC* wxGtkPrinter::PrintDialog( wxWindow *parent ) { wxGtkPrintDialog dialog( parent, &m_printDialogData ); - int ret; dialog.SetPrintDC(m_dc); + dialog.SetShowDialog(true); - dialog.SetShowDialog(m_showDialog); - - ret = dialog.ShowModal(); + int ret = dialog.ShowModal(); if (ret == wxID_CANCEL) { @@ -1059,16 +1081,14 @@ wxGtkPrintDC::wxGtkPrintDC( const wxPrintData& data ) m_gpc = native->GetPrintContext(); - // RR: what does this do? + // Match print quality to resolution (high = 1200dpi) m_resolution = m_printData.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc ); - if (m_resolution < 0) + if (m_resolution < 0) m_resolution = (1 << (m_resolution+4)) *150; - wxPrintf( "resolution %d\n", m_resolution ); - m_PS2DEV = (double)m_resolution / 72.0; m_DEV2PS = 72.0 / (double)m_resolution; - + m_context = gtk_print_context_create_pango_context( m_gpc ); m_layout = gtk_print_context_create_pango_layout ( m_gpc ); m_fontdesc = pango_font_description_from_string( "Sans 12" ); @@ -1079,8 +1099,17 @@ wxGtkPrintDC::wxGtkPrintDC( const wxPrintData& data ) m_currentBlue = 0; m_currentGreen = 0; - m_signX = 1; // default x-axis left to right. + m_signX = 1; // default x-axis left to right. m_signY = 1; // default y-axis bottom up -> top down. + + // By default the origin of the cairo context is in the upper left + // corner of the printable area. We need to translate it so that it + // is in the upper left corner of the paper (without margins) + GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc ); + gdouble ml, mt; + ml = gtk_page_setup_get_left_margin (setup, GTK_UNIT_POINTS); + mt = gtk_page_setup_get_top_margin (setup, GTK_UNIT_POINTS); + gs_cairo->cairo_translate(m_cairo, -ml, -mt); } wxGtkPrintDC::~wxGtkPrintDC() @@ -1132,13 +1161,13 @@ void wxGtkPrintDC::DoGradientFillConcentric(const wxRect& rect, const wxColour& // Create a pattern with the gradient. cairo_pattern_t* gradient; - gradient = gs_cairo->cairo_pattern_create_radial (XLOG2DEV(xC+xR), YLOG2DEVREL(yC+yR), 0, XLOG2DEV(xC+xR), YLOG2DEVREL(yC+yR), radius * m_DEV2PS ); + gradient = gs_cairo->cairo_pattern_create_radial (XLOG2DEV(xC+xR), YLOG2DEV(yC+yR), 0, XLOG2DEV(xC+xR), YLOG2DEV(yC+yR), radius * m_DEV2PS ); gs_cairo->cairo_pattern_add_color_stop_rgba (gradient, 0.0, redIPS, greenIPS, blueIPS, alphaIPS); gs_cairo->cairo_pattern_add_color_stop_rgba (gradient, 1.0, redDPS, greenDPS, blueDPS, alphaDPS); // Fill the rectangle with this pattern. gs_cairo->cairo_set_source(m_cairo, gradient); - gs_cairo->cairo_rectangle (m_cairo, XLOG2DEV(xR), YLOG2DEVREL(yR), XLOG2DEVREL(w), YLOG2DEVREL(h) ); + gs_cairo->cairo_rectangle (m_cairo, XLOG2DEV(xR), YLOG2DEV(yR), XLOG2DEVREL(w), YLOG2DEVREL(h) ); gs_cairo->cairo_fill(m_cairo); gs_cairo->cairo_pattern_destroy(gradient); @@ -1174,7 +1203,7 @@ void wxGtkPrintDC::DoGradientFillLinear(const wxRect& rect, const wxColour& init // Create a pattern with the gradient. cairo_pattern_t* gradient; - gradient = gs_cairo->cairo_pattern_create_linear (XLOG2DEVREL(x), YLOG2DEVREL(y), XLOG2DEVREL(x+w), YLOG2DEVREL(y)); + gradient = gs_cairo->cairo_pattern_create_linear (XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x+w), YLOG2DEV(y)); if (nDirection == wxWEST) { @@ -1188,7 +1217,7 @@ void wxGtkPrintDC::DoGradientFillLinear(const wxRect& rect, const wxColour& init // Fill the rectangle with this pattern. gs_cairo->cairo_set_source(m_cairo, gradient); - gs_cairo->cairo_rectangle (m_cairo, XLOG2DEVREL(x), YLOG2DEVREL(y), XLOG2DEVREL(w), YLOG2DEVREL(h) ); + gs_cairo->cairo_rectangle (m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(w), YLOG2DEVREL(h) ); gs_cairo->cairo_fill(m_cairo); gs_cairo->cairo_pattern_destroy(gradient); @@ -1209,8 +1238,8 @@ void wxGtkPrintDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) if (m_pen.GetStyle() == wxTRANSPARENT) return; SetPen( m_pen ); - gs_cairo->cairo_move_to ( m_cairo, XLOG2DEVREL(x1), YLOG2DEVREL(y1) ); - gs_cairo->cairo_line_to ( m_cairo, XLOG2DEVREL(x2), YLOG2DEVREL(y2) ); + gs_cairo->cairo_move_to ( m_cairo, XLOG2DEV(x1), YLOG2DEV(y1) ); + gs_cairo->cairo_line_to ( m_cairo, XLOG2DEV(x2), YLOG2DEV(y2) ); gs_cairo->cairo_stroke ( m_cairo ); CalcBoundingBox( x1, y1 ); @@ -1224,10 +1253,10 @@ void wxGtkPrintDC::DoCrossHair(wxCoord x, wxCoord y) SetPen(m_pen); - gs_cairo->cairo_move_to (m_cairo, XLOG2DEVREL(x), 0); - gs_cairo->cairo_line_to (m_cairo, XLOG2DEVREL(x), h * m_DEV2PS); - gs_cairo->cairo_move_to (m_cairo, 0, YLOG2DEVREL(y)); - gs_cairo->cairo_line_to (m_cairo, w * m_DEV2PS, YLOG2DEVREL(y)); + gs_cairo->cairo_move_to (m_cairo, XLOG2DEV(x), 0); + gs_cairo->cairo_line_to (m_cairo, XLOG2DEV(x), YLOG2DEVREL(h)); + gs_cairo->cairo_move_to (m_cairo, 0, YLOG2DEV(y)); + gs_cairo->cairo_line_to (m_cairo, XLOG2DEVREL(w), YLOG2DEV(y)); gs_cairo->cairo_stroke (m_cairo); CalcBoundingBox( 0, 0 ); @@ -1269,8 +1298,10 @@ void wxGtkPrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord alpha1 *= DEG2RAD; alpha2 *= DEG2RAD; - gs_cairo->cairo_arc_negative ( m_cairo, XLOG2DEVREL(xc), YLOG2DEVREL(yc), XLOG2DEVREL((int)radius), alpha1, alpha2); - gs_cairo->cairo_line_to(m_cairo, XLOG2DEVREL(xc), YLOG2DEVREL(yc)); + gs_cairo->cairo_new_path(m_cairo); + + gs_cairo->cairo_arc_negative ( m_cairo, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2); + gs_cairo->cairo_line_to(m_cairo, XLOG2DEV(xc), YLOG2DEV(yc)); gs_cairo->cairo_close_path (m_cairo); SetBrush( m_brush ); @@ -1288,7 +1319,9 @@ void wxGtkPrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,dou { gs_cairo->cairo_save( m_cairo ); - gs_cairo->cairo_translate( m_cairo, XLOG2DEVREL((wxCoord) (x + w / 2.)), XLOG2DEVREL((wxCoord) (y + h / 2.)) ); + gs_cairo->cairo_new_path(m_cairo); + + gs_cairo->cairo_translate( m_cairo, XLOG2DEV((wxCoord) (x + w / 2.)), XLOG2DEV((wxCoord) (y + h / 2.)) ); double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w); gs_cairo->cairo_scale( m_cairo, 1.0, scale ); @@ -1314,8 +1347,8 @@ void wxGtkPrintDC::DoDrawPoint(wxCoord x, wxCoord y) SetPen( m_pen ); - gs_cairo->cairo_move_to ( m_cairo, XLOG2DEVREL(x), YLOG2DEVREL(y) ); - gs_cairo->cairo_line_to ( m_cairo, XLOG2DEVREL(x), YLOG2DEVREL(y) ); + gs_cairo->cairo_move_to ( m_cairo, XLOG2DEV(x), YLOG2DEV(y) ); + gs_cairo->cairo_line_to ( m_cairo, XLOG2DEV(x), YLOG2DEV(y) ); gs_cairo->cairo_stroke ( m_cairo ); CalcBoundingBox( x, y ); @@ -1333,10 +1366,10 @@ void wxGtkPrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord for ( i =0; icairo_move_to ( m_cairo, XLOG2DEVREL(points[0].x+xoffset), YLOG2DEVREL(points[0].y+yoffset) ); + gs_cairo->cairo_move_to ( m_cairo, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) ); for (i = 1; i < n; i++) - gs_cairo->cairo_line_to ( m_cairo, XLOG2DEVREL(points[i].x+xoffset), YLOG2DEVREL(points[i].y+yoffset) ); + gs_cairo->cairo_line_to ( m_cairo, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) ); gs_cairo->cairo_stroke ( m_cairo); } @@ -1354,13 +1387,13 @@ void wxGtkPrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoo int x = points[0].x + xoffset; int y = points[0].y + yoffset; gs_cairo->cairo_new_path(m_cairo); - gs_cairo->cairo_move_to( m_cairo, XLOG2DEVREL(x), YLOG2DEVREL(y) ); + gs_cairo->cairo_move_to( m_cairo, XLOG2DEV(x), YLOG2DEV(y) ); int i; for (i = 1; i < n; i++) { int x = points[i].x + xoffset; int y = points[i].y + yoffset; - gs_cairo->cairo_line_to( m_cairo, XLOG2DEVREL(x), YLOG2DEVREL(y) ); + gs_cairo->cairo_line_to( m_cairo, XLOG2DEV(x), YLOG2DEV(y) ); } gs_cairo->cairo_close_path(m_cairo); @@ -1382,7 +1415,8 @@ void wxGtkPrintDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoo void wxGtkPrintDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { - gs_cairo->cairo_rectangle ( m_cairo, XLOG2DEVREL(x), YLOG2DEVREL(y), XLOG2DEVREL(width), YLOG2DEVREL(height)); + gs_cairo->cairo_new_path(m_cairo); + gs_cairo->cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height)); SetBrush( m_brush ); gs_cairo->cairo_fill_preserve( m_cairo ); @@ -1406,27 +1440,27 @@ void wxGtkPrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, w wxCoord rad = (wxCoord) radius; gs_cairo->cairo_new_path(m_cairo); - gs_cairo->cairo_move_to(m_cairo,XLOG2DEVREL(x + rad),YLOG2DEVREL(y)); + gs_cairo->cairo_move_to(m_cairo,XLOG2DEV(x + rad),YLOG2DEV(y)); gs_cairo->cairo_curve_to(m_cairo, - XLOG2DEVREL(x + rad),YLOG2DEVREL(y), - XLOG2DEVREL(x),YLOG2DEVREL(y), - XLOG2DEVREL(x),YLOG2DEVREL(y + rad)); - gs_cairo->cairo_line_to(m_cairo,XLOG2DEVREL(x),YLOG2DEVREL(y + height - rad)); + XLOG2DEV(x + rad),YLOG2DEV(y), + XLOG2DEV(x),YLOG2DEV(y), + XLOG2DEV(x),YLOG2DEV(y + rad)); + gs_cairo->cairo_line_to(m_cairo,XLOG2DEV(x),YLOG2DEV(y + height - rad)); gs_cairo->cairo_curve_to(m_cairo, - XLOG2DEVREL(x),YLOG2DEVREL(y + height - rad), - XLOG2DEVREL(x),YLOG2DEVREL(y + height), - XLOG2DEVREL(x + rad),YLOG2DEVREL(y + height)); - gs_cairo->cairo_line_to(m_cairo,XLOG2DEVREL(x + width - rad),YLOG2DEVREL(y + height)); + XLOG2DEV(x),YLOG2DEV(y + height - rad), + XLOG2DEV(x),YLOG2DEV(y + height), + XLOG2DEV(x + rad),YLOG2DEV(y + height)); + gs_cairo->cairo_line_to(m_cairo,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); gs_cairo->cairo_curve_to(m_cairo, - XLOG2DEVREL(x + width - rad),YLOG2DEVREL(y + height), - XLOG2DEVREL(x + width),YLOG2DEVREL(y + height), - XLOG2DEVREL(x + width),YLOG2DEVREL(y + height - rad)); - gs_cairo->cairo_line_to(m_cairo,XLOG2DEVREL(x + width),YLOG2DEVREL(y + rad)); + XLOG2DEV(x + width - rad),YLOG2DEV(y + height), + XLOG2DEV(x + width),YLOG2DEV(y + height), + XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); + gs_cairo->cairo_line_to(m_cairo,XLOG2DEV(x + width),YLOG2DEV(y + rad)); gs_cairo->cairo_curve_to(m_cairo, - XLOG2DEVREL(x + width),YLOG2DEVREL(y + rad), - XLOG2DEVREL(x + width),YLOG2DEVREL(y), - XLOG2DEVREL(x + width - rad),YLOG2DEVREL(y)); - gs_cairo->cairo_line_to(m_cairo,XLOG2DEVREL(x + rad),YLOG2DEVREL(y)); + XLOG2DEV(x + width),YLOG2DEV(y + rad), + XLOG2DEV(x + width),YLOG2DEV(y), + XLOG2DEV(x + width - rad),YLOG2DEV(y)); + gs_cairo->cairo_line_to(m_cairo,XLOG2DEV(x + rad),YLOG2DEV(y)); gs_cairo->cairo_close_path(m_cairo); SetBrush(m_brush); @@ -1443,7 +1477,9 @@ void wxGtkPrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord he { gs_cairo->cairo_save (m_cairo); - gs_cairo->cairo_translate (m_cairo, XLOG2DEVREL((wxCoord) (x + width / 2.)), YLOG2DEVREL((wxCoord) (y + height / 2.))); + gs_cairo->cairo_new_path(m_cairo); + + gs_cairo->cairo_translate (m_cairo, XLOG2DEV((wxCoord) (x + width / 2.)), YLOG2DEV((wxCoord) (y + height / 2.))); gs_cairo->cairo_scale(m_cairo, 1, (double)YLOG2DEVREL(height)/(double)XLOG2DEVREL(width)); gs_cairo->cairo_arc ( m_cairo, 0, 0, XLOG2DEVREL(width/2), 0, 2 * M_PI); @@ -1482,8 +1518,8 @@ void wxGtkPrintDC::DoDrawSpline(wxList *points) (double)(y1 + d) / 2; gs_cairo->cairo_new_path( m_cairo ); - gs_cairo->cairo_move_to( m_cairo, XLOG2DEVREL((wxCoord)x1), YLOG2DEVREL((wxCoord)y1) ); - gs_cairo->cairo_line_to( m_cairo, XLOG2DEVREL((wxCoord)x3), YLOG2DEVREL((wxCoord)y3) ); + gs_cairo->cairo_move_to( m_cairo, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) ); + gs_cairo->cairo_line_to( m_cairo, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); @@ -1503,9 +1539,9 @@ void wxGtkPrintDC::DoDrawSpline(wxList *points) y3 = (double)(y2 + d) / 2; gs_cairo->cairo_curve_to(m_cairo, - XLOG2DEVREL((wxCoord)x1), YLOG2DEVREL((wxCoord)y1), - XLOG2DEVREL((wxCoord)x2), YLOG2DEVREL((wxCoord)y2), - XLOG2DEVREL((wxCoord)x3), YLOG2DEVREL((wxCoord)y3) ); + XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1), + XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2), + XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); @@ -1513,7 +1549,7 @@ void wxGtkPrintDC::DoDrawSpline(wxList *points) node = node->GetNext(); } - gs_cairo->cairo_line_to ( m_cairo, XLOG2DEVREL((wxCoord)c), YLOG2DEVREL((wxCoord)d) ); + gs_cairo->cairo_line_to ( m_cairo, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) ); gs_cairo->cairo_stroke( m_cairo ); } @@ -1548,8 +1584,8 @@ void wxGtkPrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, b wxCHECK_RET( bitmap.IsOk(), wxT("Invalid bitmap in wxGtkPrintDC::DoDrawBitmap")); cairo_surface_t* surface; - x = wxCoord(XLOG2DEVREL(x)); - y = wxCoord(YLOG2DEVREL(y)); + x = wxCoord(XLOG2DEV(x)); + y = wxCoord(YLOG2DEV(y)); int bw = bitmap.GetWidth(); int bh = bitmap.GetHeight(); wxBitmap bmpSource = bitmap; // we need a non-const instance. @@ -1580,10 +1616,14 @@ void wxGtkPrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, b // blue. The 32-bit quantities are stored native-endian. // Pre-multiplied alpha is used. unsigned char alpha = p.Alpha(); + + if (!bmpSource.HasAlpha() && mask) + alpha = 255; + if (alpha == 0) *data = 0; else - *data = ( alpha/255 << 24 + *data = ( alpha << 24 | (p.Red() * alpha/255) << 16 | (p.Green() * alpha/255) << 8 | (p.Blue() * alpha/255) ); @@ -1623,13 +1663,18 @@ void wxGtkPrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, b gs_cairo->cairo_save(m_cairo); - // In case we're scaling the image by using a width and height different - // than the bitmap's size create a pattern transformation on the surface and - // draw the transformed pattern. - cairo_pattern_t* pattern = gs_cairo->cairo_pattern_create_for_surface(surface); // Prepare to draw the image. gs_cairo->cairo_translate(m_cairo, x, y); + + // Scale the image + cairo_filter_t filter = CAIRO_FILTER_BILINEAR; + cairo_pattern_t* pattern = cairo_pattern_create_for_surface(surface); + cairo_pattern_set_filter(pattern,filter); + wxDouble scaleX = (wxDouble) XLOG2DEVREL(bw) / (wxDouble) bw; + wxDouble scaleY = (wxDouble) YLOG2DEVREL(bh) / (wxDouble) bh; + cairo_scale(m_cairo, scaleX, scaleY); + gs_cairo->cairo_set_source(m_cairo, pattern); // Use the original size here since the context is scaled already. gs_cairo->cairo_rectangle(m_cairo, 0, 0, bw, bh); @@ -1705,11 +1750,18 @@ void wxGtkPrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, } } - - // TODO: steal scale implementation from GNOME print + int w,h; - int w,h; - pango_layout_get_pixel_size( m_layout, &w, &h ); // cairo units + // Scale font description. + gint oldSize = pango_font_description_get_size( m_fontdesc ); + double size = oldSize; + size = size * m_scaleX; + pango_font_description_set_size( m_fontdesc, (gint)size ); + + // Actually apply scaled font. + pango_layout_set_font_description( m_layout, m_fontdesc ); + + pango_layout_get_pixel_size( m_layout, &w, &h ); if ( m_backgroundMode == wxSOLID ) { @@ -1734,17 +1786,15 @@ void wxGtkPrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, // Draw layout. gs_cairo->cairo_move_to (m_cairo, xx, yy); - + gs_cairo->cairo_save( m_cairo ); - - gs_cairo->cairo_scale( m_cairo, m_scaleX, m_scaleY ); - + if (fabs(angle) > 0.00001) gs_cairo->cairo_rotate( m_cairo, angle*DEG2RAD ); - + gs_cairo->pango_cairo_update_layout (m_cairo, m_layout); gs_cairo->pango_cairo_show_layout (m_cairo, m_layout); - + gs_cairo->cairo_restore( m_cairo ); if (underlined) @@ -1752,7 +1802,13 @@ void wxGtkPrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, // Undo underline attributes setting pango_layout_set_attributes(m_layout, NULL); } - + + // Reset unscaled size. + pango_font_description_set_size( m_fontdesc, oldSize ); + + // Actually apply unscaled font. + pango_layout_set_font_description( m_layout, m_fontdesc ); + // Back to device units: CalcBoundingBox (x, y); CalcBoundingBox (x + w, y + h); @@ -1783,7 +1839,7 @@ void wxGtkPrintDC::SetFont( const wxFont& font ) m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); // m_fontdesc is now set to device units // Scale font description from device units to pango units - gint oldSize = pango_font_description_get_size( m_fontdesc ); + gint oldSize = pango_font_description_get_size( m_fontdesc ); double size = oldSize *m_DEV2PS; // scale to cairo units pango_font_description_set_size( m_fontdesc, (gint)size ); // apply to description @@ -1798,10 +1854,14 @@ void wxGtkPrintDC::SetPen( const wxPen& pen ) m_pen = pen; - double width = (double) m_pen.GetWidth(); - if (width == 0) width = 0.1; + double width; + + if (m_pen.GetWidth() <= 0) + width = 0.1; + else + width = (double) m_pen.GetWidth(); - gs_cairo->cairo_set_line_width( m_cairo, XLOG2DEVREL( (wxCoord)((1000.0 * (double)width ) / 1000.0)) ); + gs_cairo->cairo_set_line_width( m_cairo, width * m_DEV2PS * m_scaleX ); static const double dotted[] = {2.0, 5.0}; static const double short_dashed[] = {4.0, 4.0}; static const double long_dashed[] = {4.0, 8.0}; @@ -1809,14 +1869,14 @@ void wxGtkPrintDC::SetPen( const wxPen& pen ) switch (m_pen.GetStyle()) { - case wxDOT: gs_cairo->cairo_set_dash( m_cairo, dotted, 1, 0 ); break; - case wxSHORT_DASH: gs_cairo->cairo_set_dash( m_cairo, short_dashed, 1, 0 ); break; - case wxLONG_DASH: gs_cairo->cairo_set_dash( m_cairo, long_dashed, 1, 0 ); break; - case wxDOT_DASH: gs_cairo->cairo_set_dash( m_cairo, dotted_dashed, 3, 0 ); break; + case wxDOT: gs_cairo->cairo_set_dash( m_cairo, dotted, 2, 0 ); break; + case wxSHORT_DASH: gs_cairo->cairo_set_dash( m_cairo, short_dashed, 2, 0 ); break; + case wxLONG_DASH: gs_cairo->cairo_set_dash( m_cairo, long_dashed, 2, 0 ); break; + case wxDOT_DASH: gs_cairo->cairo_set_dash( m_cairo, dotted_dashed, 4, 0 ); break; case wxUSER_DASH: { wxDash *wx_dashes; - int num = m_pen.GetDashes (&wx_dashes) - 1; + int num = m_pen.GetDashes (&wx_dashes); gdouble *g_dashes = g_new( gdouble, num ); int i; for (i = 0; i < num; ++i) @@ -1997,7 +2057,7 @@ void wxGtkPrintDC::SetBackgroundMode(int mode) void wxGtkPrintDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { - gs_cairo->cairo_rectangle ( m_cairo, XLOG2DEVREL(x), YLOG2DEVREL(y), XLOG2DEVREL(width), YLOG2DEVREL(height)); + gs_cairo->cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height)); gs_cairo->cairo_clip(m_cairo); } @@ -2093,7 +2153,7 @@ void wxGtkPrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoo *width = wxRound( (double)w / m_scaleX * m_PS2DEV ); if (height) *height = wxRound( (double)h / m_scaleY * m_PS2DEV ); - + if (descent) { PangoLayoutIter *iter = pango_layout_get_iter(m_layout); @@ -2206,11 +2266,11 @@ void wxGtkPrintPreview::DetermineScaling() m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); - + // TODO !!!!!!!!!!!!!!! int resolution = 600; m_previewPrintout->SetPPIPrinter( resolution, resolution ); - + // Get width and height in points (1/72th of an inch) wxSize sizeDevUnits(paper->GetSizeDeviceUnits());