#include "wx/math.h"
#include "wx/image.h"
#include "wx/module.h"
+#include "wx/crt.h"
#endif
#include "wx/fontutil.h"
class wxGtkPrintModule: public wxModule
{
public:
- wxGtkPrintModule()
+ wxGtkPrintModule()
{
#if wxUSE_LIBGNOMEPRINT
// This module must be initialized AFTER gnomeprint's one
//----------------------------------------------------------------------------
// We use it to pass useful objets to gtk printing callback functions.
-typedef struct
+struct wxPrinterToGtkData
{
wxGtkPrinter * printer;
wxPrintout * printout;
-}
-wxPrinterToGtkData;
+};
extern "C"
{
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;
}
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));
}
//----------------------------------------------------------------------------
// 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)
range = gtk_print_settings_get_page_ranges (newSettings, &num_ranges);
if (num_ranges >= 1)
{
- m_printDialogData.SetFromPage( range[0].start );
- m_printDialogData.SetToPage( range[0].end );
+ m_printDialogData.SetFromPage( range[0].start );
+ m_printDialogData.SetToPage( range[0].end );
}
else {
m_printDialogData.SetAllPages( true );
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);
// We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
if (num_ranges >= 1)
{
- startPage = range[0].start + 1;
- endPage = range[0].end + 1;
+ startPage = range[0].start + 1;
+ endPage = range[0].end + 1;
}
else {
startPage = minPage;
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)
{
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" );
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 origine of cairo contexte 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 (i.e. doesn't care about margins)
+ // 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);
}
int w,h;
-
+
// Scale font description.
gint oldSize = pango_font_description_get_size( m_fontdesc );
double size = oldSize;
// Draw layout.
gs_cairo->cairo_move_to (m_cairo, xx, yy);
-
+
gs_cairo->cairo_save( m_cairo );
-
+
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)
// Undo underline attributes setting
pango_layout_set_attributes(m_layout, NULL);
}
-
+
// Reset unscaled size.
pango_font_description_set_size( m_fontdesc, oldSize );
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
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, (width * m_PS2DEV) / m_scaleX );
+ 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};
*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);
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());