1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/print.cpp
3 // Author: Anthony Bretaudeau
4 // Purpose: GTK printing support
6 // RCS-ID: $Id: print.cpp,v 1 2007-08-25 05:44:44 PC Exp $
7 // Copyright: (c) 2007 wxWidgets development team
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/gtk/print.h"
24 #include "wx/dcmemory.h"
25 #include "wx/dcprint.h"
29 #include "wx/module.h"
33 #include "wx/fontutil.h"
34 #include "wx/gtk/private.h"
35 #include "wx/dynlib.h"
37 #include "wx/rawbmp.h"
40 #include <gtk/gtkpagesetupunixdialog.h>
42 #if wxUSE_GRAPHICS_CONTEXT
43 #include "wx/graphics.h"
47 wxFORCE_LINK_THIS_MODULE(gtk_print
)
49 #if wxUSE_LIBGNOMEPRINT
50 #include "wx/gtk/gnome/gprint.h"
53 // Usefull to convert angles from/to Rad to/from Deg.
54 static const double RAD2DEG
= 180.0 / M_PI
;
55 static const double DEG2RAD
= M_PI
/ 180.0;
57 static wxCairoLibrary
* gs_cairo
= NULL
;
59 //----------------------------------------------------------------------------
61 // Initialized when starting the app : if it successfully load the gtk-print framework,
62 // it uses it. If not, it falls back to gnome print (see /gtk/gnome/gprint.cpp) then
63 // to postscript if gnomeprint is not available.
64 //----------------------------------------------------------------------------
66 class wxGtkPrintModule
: public wxModule
71 #if wxUSE_LIBGNOMEPRINT
72 // This module must be initialized AFTER gnomeprint's one
73 AddDependency(CLASSINFO(wxGnomePrintModule
));
80 DECLARE_DYNAMIC_CLASS(wxGtkPrintModule
)
83 bool wxGtkPrintModule::OnInit()
85 gs_cairo
= wxCairoLibrary::Get();
86 if (gs_cairo
&& gtk_check_version(2,10,0) == NULL
)
87 wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory
);
91 void wxGtkPrintModule::OnExit()
96 IMPLEMENT_DYNAMIC_CLASS(wxGtkPrintModule
, wxModule
)
98 //----------------------------------------------------------------------------
100 //----------------------------------------------------------------------------
102 wxPrinterBase
* wxGtkPrintFactory::CreatePrinter( wxPrintDialogData
*data
)
104 return new wxGtkPrinter( data
);
107 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
108 wxPrintout
*printout
,
109 wxPrintDialogData
*data
)
111 return new wxGtkPrintPreview( preview
, printout
, data
);
114 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
115 wxPrintout
*printout
,
118 return new wxGtkPrintPreview( preview
, printout
, data
);
121 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
122 wxPrintDialogData
*data
)
124 return new wxGtkPrintDialog( parent
, data
);
127 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
130 return new wxGtkPrintDialog( parent
, data
);
133 wxPageSetupDialogBase
*wxGtkPrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
134 wxPageSetupDialogData
* data
)
136 return new wxGtkPageSetupDialog( parent
, data
);
139 bool wxGtkPrintFactory::HasPrintSetupDialog()
145 wxGtkPrintFactory::CreatePrintSetupDialog(wxWindow
* WXUNUSED(parent
),
146 wxPrintData
* WXUNUSED(data
))
151 wxDCImpl
* wxGtkPrintFactory::CreatePrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
)
153 return new wxGtkPrinterDCImpl( owner
, data
);
156 bool wxGtkPrintFactory::HasOwnPrintToFile()
161 bool wxGtkPrintFactory::HasPrinterLine()
166 wxString
wxGtkPrintFactory::CreatePrinterLine()
169 return wxEmptyString
;
172 bool wxGtkPrintFactory::HasStatusLine()
178 wxString
wxGtkPrintFactory::CreateStatusLine()
181 return wxEmptyString
;
184 wxPrintNativeDataBase
*wxGtkPrintFactory::CreatePrintNativeData()
186 return new wxGtkPrintNativeData
;
189 //----------------------------------------------------------------------------
190 // Callback functions for Gtk Printings.
191 //----------------------------------------------------------------------------
193 // We use it to pass useful objects to GTK printing callback functions.
194 struct wxPrinterToGtkData
196 wxGtkPrinter
* printer
;
197 wxPrintout
* printout
;
202 static void gtk_begin_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
204 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
206 data
->printer
->BeginPrint(data
->printout
, operation
, context
);
209 static void gtk_draw_page_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gint page_nr
, gpointer user_data
)
211 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
213 data
->printer
->DrawPage(data
->printout
, operation
, context
, page_nr
);
216 static void gtk_end_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
217 GtkPrintContext
* WXUNUSED(context
),
220 wxPrintout
*printout
= (wxPrintout
*) user_data
;
222 printout
->OnEndPrinting();
226 gtk_preview_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
227 GtkPrintOperationPreview
* WXUNUSED(preview
),
228 GtkPrintContext
*context
,
232 wxPrintout
*printout
= (wxPrintout
*) user_data
;
234 printout
->SetIsPreview(true);
236 /* We create a Cairo context with 72dpi resolution. This resolution is
237 * only used for positioning. */
238 cairo_t
*cairo
= gdk_cairo_create(GTK_WIDGET(parent
)->window
);
239 gtk_print_context_set_cairo_context(context
, cairo
, 72, 72);
245 //----------------------------------------------------------------------------
246 // wxGtkPrintNativeData
247 //----------------------------------------------------------------------------
249 IMPLEMENT_CLASS(wxGtkPrintNativeData
, wxPrintNativeDataBase
)
251 wxGtkPrintNativeData::wxGtkPrintNativeData()
253 m_config
= gtk_print_settings_new();
256 wxGtkPrintNativeData::~wxGtkPrintNativeData()
258 g_object_unref (m_config
);
261 // Convert datas stored in m_config to a wxPrintData.
262 // Called by wxPrintData::ConvertFromNative().
263 bool wxGtkPrintNativeData::TransferTo( wxPrintData
&data
)
268 int resolution
= gtk_print_settings_get_resolution(m_config
);
269 if ( resolution
> 0 )
271 // if resolution is explicitly set, use it
272 data
.SetQuality(resolution
);
274 else // use more vague "quality"
276 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
277 if (quality
== GTK_PRINT_QUALITY_HIGH
)
278 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
279 else if (quality
== GTK_PRINT_QUALITY_LOW
)
280 data
.SetQuality(wxPRINT_QUALITY_LOW
);
281 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
282 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
284 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
287 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
289 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
291 switch (gtk_print_settings_get_duplex(m_config
))
293 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
296 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
300 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
304 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
305 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
307 data
.SetOrientation(wxPORTRAIT
);
308 data
.SetOrientationReversed(false);
310 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
312 data
.SetOrientation(wxLANDSCAPE
);
313 data
.SetOrientationReversed(false);
315 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
317 data
.SetOrientation(wxPORTRAIT
);
318 data
.SetOrientationReversed(true);
320 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
322 data
.SetOrientation(wxLANDSCAPE
);
323 data
.SetOrientationReversed(true);
326 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
328 // Paper formats : these are the most common paper formats.
329 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
331 data
.SetPaperId(wxPAPER_NONE
);
332 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
333 data
.SetPaperId(wxPAPER_A3
);
334 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
335 data
.SetPaperId(wxPAPER_A4
);
336 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
337 data
.SetPaperId(wxPAPER_A5
);
338 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
339 data
.SetPaperId(wxPAPER_B5
);
340 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
341 data
.SetPaperId(wxPAPER_LETTER
);
342 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
343 data
.SetPaperId(wxPAPER_LEGAL
);
344 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
345 data
.SetPaperId(wxPAPER_EXECUTIVE
);
346 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
347 data
.SetPaperId(wxPAPER_ENV_10
);
348 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
349 data
.SetPaperId(wxPAPER_ENV_C5
);
350 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
351 data
.SetPaperId(wxPAPER_ENV_C6
);
352 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
353 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
354 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
355 data
.SetPaperId(wxPAPER_ENV_B5
);
356 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
357 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
358 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
359 data
.SetPaperId( wxPAPER_CSHEET
);
360 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
361 data
.SetPaperId( wxPAPER_DSHEET
);
362 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
363 data
.SetPaperId( wxPAPER_ESHEET
);
364 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
365 data
.SetPaperId( wxPAPER_LETTERSMALL
);
366 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
367 data
.SetPaperId( wxPAPER_TABLOID
);
368 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
369 data
.SetPaperId( wxPAPER_LEDGER
);
370 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
371 data
.SetPaperId( wxPAPER_STATEMENT
);
372 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
373 data
.SetPaperId( wxPAPER_A4SMALL
);
374 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
375 data
.SetPaperId( wxPAPER_B4
);
376 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
377 data
.SetPaperId( wxPAPER_FOLIO
);
378 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
379 data
.SetPaperId( wxPAPER_QUARTO
);
380 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
381 data
.SetPaperId( wxPAPER_10X14
);
382 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
383 data
.SetPaperId( wxPAPER_11X17
);
384 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
385 data
.SetPaperId( wxPAPER_NOTE
);
386 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
387 data
.SetPaperId( wxPAPER_ENV_9
);
388 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
389 data
.SetPaperId( wxPAPER_ENV_11
);
390 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
391 data
.SetPaperId( wxPAPER_ENV_12
);
392 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
393 data
.SetPaperId( wxPAPER_ENV_14
);
394 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
395 data
.SetPaperId( wxPAPER_ENV_DL
);
396 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
397 data
.SetPaperId( wxPAPER_ENV_C3
);
398 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
399 data
.SetPaperId( wxPAPER_ENV_C4
);
400 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
401 data
.SetPaperId( wxPAPER_ENV_C65
);
402 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
403 data
.SetPaperId( wxPAPER_ENV_B4
);
404 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
405 data
.SetPaperId( wxPAPER_ENV_B6
);
406 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
407 data
.SetPaperId( wxPAPER_ENV_ITALY
);
408 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
409 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
410 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
411 data
.SetPaperId( wxPAPER_FANFOLD_US
);
412 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
413 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
414 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
415 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
417 data
.SetPaperId(wxPAPER_NONE
);
421 // Put datas given by the wxPrintData into m_config.
422 // Called by wxPrintData::ConvertToNative().
423 bool wxGtkPrintNativeData::TransferFrom( const wxPrintData
&data
)
428 wxPrintQuality quality
= data
.GetQuality();
429 if (quality
== wxPRINT_QUALITY_HIGH
)
430 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
431 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
432 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
433 else if (quality
== wxPRINT_QUALITY_LOW
)
434 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
435 else if (quality
== wxPRINT_QUALITY_DRAFT
)
436 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
437 else if (quality
> 1)
438 gtk_print_settings_set_resolution (m_config
, quality
);
440 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
442 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
444 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
446 switch (data
.GetDuplex())
448 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
451 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
455 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
459 if (!data
.IsOrientationReversed())
461 if (data
.GetOrientation() == wxLANDSCAPE
)
462 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
464 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
467 if (data
.GetOrientation() == wxLANDSCAPE
)
468 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
470 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
473 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
475 // Paper formats: these are the most common paper formats.
476 switch (data
.GetPaperId())
478 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
480 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
482 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
484 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
486 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
488 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
490 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
492 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
494 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
496 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
498 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
500 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
502 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
504 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
506 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
508 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
510 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
512 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
514 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
516 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
518 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
520 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
522 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
524 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
526 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
528 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
530 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
532 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
534 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
536 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
538 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
540 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
542 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
544 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
546 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
548 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
550 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
552 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
554 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
556 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
558 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
560 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
569 void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings
* config
)
572 m_config
= gtk_print_settings_copy(config
);
575 // Extract page setup from settings.
576 GtkPageSetup
* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
578 GtkPageSetup
* page_setup
= gtk_page_setup_new();
579 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
581 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
582 if (paper_size
!= NULL
)
583 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
588 // Insert page setup into a given GtkPrintSettings.
589 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
591 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
592 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
595 //----------------------------------------------------------------------------
597 //----------------------------------------------------------------------------
599 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
601 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
602 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
603 wxPoint(0, 0), wxSize(600, 600),
604 wxDEFAULT_DIALOG_STYLE
|
608 m_printDialogData
= *data
;
614 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
615 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
616 wxPoint(0, 0), wxSize(600, 600),
617 wxDEFAULT_DIALOG_STYLE
|
621 m_printDialogData
= *data
;
628 wxGtkPrintDialog::~wxGtkPrintDialog()
632 // This is called even if we actually don't want the dialog to appear.
633 int wxGtkPrintDialog::ShowModal()
635 GtkPrintOperationResult response
;
637 // We need to restore the settings given in the constructor.
638 wxPrintData data
= m_printDialogData
.GetPrintData();
639 wxGtkPrintNativeData
*native
=
640 (wxGtkPrintNativeData
*) data
.GetNativeData();
641 data
.ConvertToNative();
643 GtkPrintSettings
* settings
= native
->GetPrintConfig();
645 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
646 int fromPage
= m_printDialogData
.GetFromPage();
647 int toPage
= m_printDialogData
.GetToPage();
648 if (m_printDialogData
.GetSelection())
649 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
650 else if (m_printDialogData
.GetAllPages())
651 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
653 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
655 range
= g_new (GtkPageRange
, 1);
656 range
[0].start
= fromPage
-1;
657 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
658 gtk_print_settings_set_page_ranges (settings
, range
, 1);
661 // If the settings are OK, we restore it.
662 if (settings
!= NULL
)
663 gtk_print_operation_set_print_settings (native
->GetPrintJob(), settings
);
664 gtk_print_operation_set_default_page_setup (native
->GetPrintJob(), native
->GetPageSetupFromSettings(settings
));
666 // Show the dialog if needed.
667 GError
* gError
= NULL
;
669 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
671 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
)), &gError
);
673 // Does everything went well?
674 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
678 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
680 g_error_free (gError
);
681 wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError
->message
));
682 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
685 // Now get the settings and save it.
686 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings (native
->GetPrintJob());
687 native
->SetPrintConfig(newSettings
);
688 data
.ConvertFromNative();
690 // Same problem as a few lines before.
691 switch (gtk_print_settings_get_print_pages(newSettings
))
693 case GTK_PRINT_PAGES_CURRENT
:
694 m_printDialogData
.SetSelection( true );
696 case GTK_PRINT_PAGES_RANGES
:
697 {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
698 // 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
699 // will hit "OK" button. However we can only save 1-3 in the print data.
702 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
705 m_printDialogData
.SetFromPage( range
[0].start
);
706 m_printDialogData
.SetToPage( range
[0].end
);
709 m_printDialogData
.SetAllPages( true );
710 m_printDialogData
.SetFromPage( 0 );
711 m_printDialogData
.SetToPage( 9999 );
714 case GTK_PRINT_PAGES_ALL
:
716 m_printDialogData
.SetAllPages( true );
717 m_printDialogData
.SetFromPage( 0 );
718 m_printDialogData
.SetToPage( 9999 );
725 //----------------------------------------------------------------------------
726 // wxGtkPageSetupDialog
727 //----------------------------------------------------------------------------
729 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
731 wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow
*parent
,
732 wxPageSetupDialogData
* data
)
735 m_pageDialogData
= *data
;
740 wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
744 int wxGtkPageSetupDialog::ShowModal()
747 m_pageDialogData
.GetPrintData().ConvertToNative();
748 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
749 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
751 // We only need the pagesetup data which are part of the settings.
752 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
754 // If the user used a custom paper format the last time he printed, we have to restore it too.
755 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
757 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
758 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
760 wxString title
= _("Custom size");
761 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
762 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
763 g_object_unref(customSize
);
767 // Now show the dialog.
768 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
773 if (newPageSetup
!= oldPageSetup
)
775 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
776 m_pageDialogData
.GetPrintData().ConvertFromNative();
778 // Store custom paper format if any.
779 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
781 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
782 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
783 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
784 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
785 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
787 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
788 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
790 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
791 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
793 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
806 //----------------------------------------------------------------------------
808 //----------------------------------------------------------------------------
810 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
812 wxGtkPrinter::wxGtkPrinter( wxPrintDialogData
*data
) :
813 wxPrinterBase( data
)
818 m_printDialogData
= *data
;
821 wxGtkPrinter::~wxGtkPrinter()
825 bool wxGtkPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
829 sm_lastError
= wxPRINTER_ERROR
;
833 // Let's correct the PageInfo just in case the app gives wrong values.
834 int fromPage
, toPage
;
835 int minPage
, maxPage
;
836 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
837 m_printDialogData
.SetAllPages(true);
839 if (minPage
< 1) minPage
= 1;
840 if (maxPage
< 1) maxPage
= 9999;
841 if (maxPage
< minPage
) maxPage
= minPage
;
843 m_printDialogData
.SetMinPage(minPage
);
844 m_printDialogData
.SetMaxPage(maxPage
);
847 if (fromPage
< minPage
) fromPage
= minPage
;
848 else if (fromPage
> maxPage
) fromPage
= maxPage
;
849 m_printDialogData
.SetFromPage(fromPage
);
853 m_printDialogData
.SetToPage(toPage
);
854 if (toPage
> maxPage
) toPage
= maxPage
;
855 else if (toPage
< minPage
) toPage
= minPage
;
858 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
861 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
862 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
864 GtkPrintOperation
*printOp
= gtk_print_operation_new ();
866 native
->SetPrintJob( printOp
);
868 printout
->SetIsPreview(false);
870 wxPrinterToGtkData dataToSend
;
871 dataToSend
.printer
= this;
872 dataToSend
.printout
= printout
;
874 // These Gtk signals are caught here.
875 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
876 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
877 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
878 g_signal_connect (printOp
, "preview", G_CALLBACK (gtk_preview_print_callback
), printout
);
880 // This is used to setup the DC and
881 // show the dialog if desired
882 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
883 dialog
.SetPrintDC(m_dc
);
884 dialog
.SetShowDialog(prompt
);
886 // doesn't necessarily show
887 int ret
= dialog
.ShowModal();
888 if (ret
== wxID_CANCEL
)
890 sm_lastError
= wxPRINTER_CANCELLED
;
894 sm_lastError
= wxPRINTER_ERROR
;
895 wxFAIL_MSG(_("The print dialog returned an error."));
898 g_object_unref (printOp
);
900 return (sm_lastError
== wxPRINTER_NO_ERROR
);
903 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
905 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
906 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
908 // We need to update printdata with the new data from the dialog and we
909 // have to do this here because this method needs this new data and we
910 // cannot update it earlier
911 native
->SetPrintConfig(gtk_print_operation_get_print_settings(operation
));
912 printdata
.ConvertFromNative();
914 SetPrintContext(context
);
915 native
->SetPrintContext( context
);
917 wxPrinterDC
*printDC
= new wxPrinterDC( printdata
);
922 if (sm_lastError
!= wxPRINTER_CANCELLED
)
924 sm_lastError
= wxPRINTER_ERROR
;
925 wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used."));
929 wxSize ScreenPixels
= wxGetDisplaySize();
930 wxSize ScreenMM
= wxGetDisplaySizeMM();
932 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
933 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
934 printout
->SetPPIPrinter( printDC
->GetResolution(),
935 printDC
->GetResolution() );
937 printout
->SetDC(m_dc
);
940 m_dc
->GetSize(&w
, &h
);
941 printout
->SetPageSizePixels((int)w
, (int)h
);
942 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
944 m_dc
->GetSizeMM(&mw
, &mh
);
945 printout
->SetPageSizeMM((int)mw
, (int)mh
);
946 printout
->OnPreparePrinting();
948 // Get some parameters from the printout, if defined.
949 int fromPage
, toPage
;
950 int minPage
, maxPage
;
951 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
955 sm_lastError
= wxPRINTER_ERROR
;
956 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
960 printout
->OnBeginPrinting();
964 // If we're not previewing we need to calculate the number of pages to print.
965 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
966 // have defined in the dialog. So the number of pages is the maximum available.
967 if (!printout
->IsPreview())
969 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
970 switch (gtk_print_settings_get_print_pages(settings
))
972 case GTK_PRINT_PAGES_CURRENT
:
975 case GTK_PRINT_PAGES_RANGES
:
976 {gint num_ranges
= 0;
979 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
980 for (i
=0; i
<num_ranges
; i
++)
982 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
983 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
984 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
985 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
986 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
988 gtk_print_settings_set_page_ranges (settings
, range
, 1);
990 case GTK_PRINT_PAGES_ALL
:
992 numPages
= maxPage
- minPage
+ 1;
996 else numPages
= maxPage
- minPage
+ 1;
998 gtk_print_operation_set_n_pages(operation
, numPages
);
1001 void wxGtkPrinter::DrawPage(wxPrintout
*printout
,
1002 GtkPrintOperation
*operation
,
1003 GtkPrintContext
* WXUNUSED(context
),
1006 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
1007 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
1009 int numPageToDraw
= page_nr
+ minPage
;
1010 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
1011 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
1013 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
1014 switch (gtk_print_settings_get_print_pages(settings
))
1016 case GTK_PRINT_PAGES_CURRENT
:
1017 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
1018 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
1020 case GTK_PRINT_PAGES_RANGES
:
1021 {gint num_ranges
= 0;
1022 GtkPageRange
* range
;
1023 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
1024 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
1025 if (num_ranges
>= 1)
1027 startPage
= range
[0].start
+ 1;
1028 endPage
= range
[0].end
+ 1;
1031 startPage
= minPage
;
1035 case GTK_PRINT_PAGES_ALL
:
1037 startPage
= minPage
;
1042 if(numPageToDraw
== startPage
)
1044 if (!printout
->OnBeginDocument(startPage
, endPage
))
1046 wxLogError(_("Could not start printing."));
1047 sm_lastError
= wxPRINTER_ERROR
;
1051 // The app can render the page numPageToDraw.
1052 if (printout
->HasPage(numPageToDraw
))
1055 printout
->OnPrintPage(numPageToDraw
);
1060 if(numPageToDraw
== endPage
)
1062 printout
->OnEndDocument();
1066 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1068 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1070 dialog
.SetPrintDC(m_dc
);
1071 dialog
.SetShowDialog(true);
1073 int ret
= dialog
.ShowModal();
1075 if (ret
== wxID_CANCEL
)
1077 sm_lastError
= wxPRINTER_CANCELLED
;
1082 sm_lastError
= wxPRINTER_ERROR
;
1083 wxFAIL_MSG(_("The print dialog returned an error."));
1087 m_printDialogData
= dialog
.GetPrintDialogData();
1089 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
1092 bool wxGtkPrinter::Setup( wxWindow
* WXUNUSED(parent
) )
1094 // Obsolete, for backward compatibility.
1098 //-----------------------------------------------------------------------------
1100 //-----------------------------------------------------------------------------
1102 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
1103 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
1104 #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
1105 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
1108 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl
, wxDCImpl
)
1110 wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC
*owner
, const wxPrintData
& data
)
1115 wxGtkPrintNativeData
*native
=
1116 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1118 m_gpc
= native
->GetPrintContext();
1120 // Match print quality to resolution (high = 1200dpi)
1121 m_resolution
= m_printData
.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
1122 if (m_resolution
< 0)
1123 m_resolution
= (1 << (m_resolution
+4)) *150;
1125 m_PS2DEV
= (double)m_resolution
/ 72.0;
1126 m_DEV2PS
= 72.0 / (double)m_resolution
;
1128 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1129 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1130 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1132 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1138 m_signX
= 1; // default x-axis left to right.
1139 m_signY
= 1; // default y-axis bottom up -> top down.
1141 // By default the origin of the Cairo context is in the upper left
1142 // corner of the printable area. We need to translate it so that it
1143 // is in the upper left corner of the paper (without margins)
1144 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
1146 ml
= gtk_page_setup_get_left_margin (setup
, GTK_UNIT_POINTS
);
1147 mt
= gtk_page_setup_get_top_margin (setup
, GTK_UNIT_POINTS
);
1148 gs_cairo
->cairo_translate(m_cairo
, -ml
, -mt
);
1151 wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
1153 g_object_unref(m_context
);
1154 g_object_unref(m_layout
);
1157 bool wxGtkPrinterDCImpl::IsOk() const
1159 return m_gpc
!= NULL
;
1162 #if wxUSE_GRAPHICS_CONTEXT
1163 wxGraphicsContext
* wxGtkPrinterDCImpl::CreateGraphicsContext()
1165 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeContext( (void*) m_cairo
);
1169 bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord
WXUNUSED(x1
),
1170 wxCoord
WXUNUSED(y1
),
1171 const wxColour
& WXUNUSED(col
),
1172 int WXUNUSED(style
))
1174 // We can't access the given coord as a Cairo context is scalable, ie a
1175 // coord doesn't mean anything in this context.
1176 wxFAIL_MSG(_("not implemented"));
1180 void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1182 wxCoord xC
= circleCenter
.x
;
1183 wxCoord yC
= circleCenter
.y
;
1184 wxCoord xR
= rect
.x
;
1185 wxCoord yR
= rect
.y
;
1186 wxCoord w
= rect
.width
;
1187 wxCoord h
= rect
.height
;
1189 double radius
= sqrt((w
/2)*(w
/2)+(h
/2)*(h
/2));
1191 unsigned char redI
= initialColour
.Red();
1192 unsigned char blueI
= initialColour
.Blue();
1193 unsigned char greenI
= initialColour
.Green();
1194 unsigned char alphaI
= initialColour
.Alpha();
1195 unsigned char redD
= destColour
.Red();
1196 unsigned char blueD
= destColour
.Blue();
1197 unsigned char greenD
= destColour
.Green();
1198 unsigned char alphaD
= destColour
.Alpha();
1200 double redIPS
= (double)(redI
) / 255.0;
1201 double blueIPS
= (double)(blueI
) / 255.0;
1202 double greenIPS
= (double)(greenI
) / 255.0;
1203 double alphaIPS
= (double)(alphaI
) / 255.0;
1204 double redDPS
= (double)(redD
) / 255.0;
1205 double blueDPS
= (double)(blueD
) / 255.0;
1206 double greenDPS
= (double)(greenD
) / 255.0;
1207 double alphaDPS
= (double)(alphaD
) / 255.0;
1209 // Create a pattern with the gradient.
1210 cairo_pattern_t
* gradient
;
1211 gradient
= gs_cairo
->cairo_pattern_create_radial (XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), 0, XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), radius
* m_DEV2PS
);
1212 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1213 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1215 // Fill the rectangle with this pattern.
1216 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1217 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(xR
), YLOG2DEV(yR
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1218 gs_cairo
->cairo_fill(m_cairo
);
1220 gs_cairo
->cairo_pattern_destroy(gradient
);
1222 CalcBoundingBox(xR
, yR
);
1223 CalcBoundingBox(xR
+w
, yR
+h
);
1226 void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1230 wxCoord w
= rect
.width
;
1231 wxCoord h
= rect
.height
;
1233 unsigned char redI
= initialColour
.Red();
1234 unsigned char blueI
= initialColour
.Blue();
1235 unsigned char greenI
= initialColour
.Green();
1236 unsigned char alphaI
= initialColour
.Alpha();
1237 unsigned char redD
= destColour
.Red();
1238 unsigned char blueD
= destColour
.Blue();
1239 unsigned char greenD
= destColour
.Green();
1240 unsigned char alphaD
= destColour
.Alpha();
1242 double redIPS
= (double)(redI
) / 255.0;
1243 double blueIPS
= (double)(blueI
) / 255.0;
1244 double greenIPS
= (double)(greenI
) / 255.0;
1245 double alphaIPS
= (double)(alphaI
) / 255.0;
1246 double redDPS
= (double)(redD
) / 255.0;
1247 double blueDPS
= (double)(blueD
) / 255.0;
1248 double greenDPS
= (double)(greenD
) / 255.0;
1249 double alphaDPS
= (double)(alphaD
) / 255.0;
1251 // Create a pattern with the gradient.
1252 cairo_pattern_t
* gradient
;
1253 gradient
= gs_cairo
->cairo_pattern_create_linear (XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x
+w
), YLOG2DEV(y
));
1255 if (nDirection
== wxWEST
)
1257 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1258 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1261 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1262 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1265 // Fill the rectangle with this pattern.
1266 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1267 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1268 gs_cairo
->cairo_fill(m_cairo
);
1270 gs_cairo
->cairo_pattern_destroy(gradient
);
1272 CalcBoundingBox(x
, y
);
1273 CalcBoundingBox(x
+w
, y
+h
);
1276 bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord
WXUNUSED(x1
),
1277 wxCoord
WXUNUSED(y1
),
1278 wxColour
* WXUNUSED(col
)) const
1280 wxFAIL_MSG(_("not implemented"));
1284 void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1286 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1289 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1290 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1291 gs_cairo
->cairo_stroke ( m_cairo
);
1293 CalcBoundingBox( x1
, y1
);
1294 CalcBoundingBox( x2
, y2
);
1297 void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x
, wxCoord y
)
1304 gs_cairo
->cairo_move_to (m_cairo
, XLOG2DEV(x
), 0);
1305 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEV(x
), YLOG2DEVREL(h
));
1306 gs_cairo
->cairo_move_to (m_cairo
, 0, YLOG2DEV(y
));
1307 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEVREL(w
), YLOG2DEV(y
));
1309 gs_cairo
->cairo_stroke (m_cairo
);
1310 CalcBoundingBox( 0, 0 );
1311 CalcBoundingBox( w
, h
);
1314 void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1316 double dx
= x1
- xc
;
1317 double dy
= y1
- yc
;
1318 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1320 double alpha1
, alpha2
;
1321 if (x1
== x2
&& y1
== y2
)
1329 alpha1
= alpha2
= 0.0;
1333 alpha1
= (x1
- xc
== 0) ?
1334 (y1
- yc
< 0) ? 90.0 : -90.0 :
1335 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1336 alpha2
= (x2
- xc
== 0) ?
1337 (y2
- yc
< 0) ? 90.0 : -90.0 :
1338 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1340 while (alpha1
<= 0) alpha1
+= 360;
1341 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1342 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1343 while (alpha2
> 360) alpha2
-= 360;
1349 gs_cairo
->cairo_new_path(m_cairo
);
1351 gs_cairo
->cairo_arc_negative ( m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
);
1352 gs_cairo
->cairo_line_to(m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
));
1353 gs_cairo
->cairo_close_path (m_cairo
);
1355 SetBrush( m_brush
);
1356 gs_cairo
->cairo_fill_preserve( m_cairo
);
1359 gs_cairo
->cairo_stroke( m_cairo
);
1361 CalcBoundingBox (x1
, y1
);
1362 CalcBoundingBox (xc
, yc
);
1363 CalcBoundingBox (x2
, y2
);
1366 void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1368 gs_cairo
->cairo_save( m_cairo
);
1370 gs_cairo
->cairo_new_path(m_cairo
);
1372 gs_cairo
->cairo_translate( m_cairo
, XLOG2DEV((wxCoord
) (x
+ w
/ 2.)), XLOG2DEV((wxCoord
) (y
+ h
/ 2.)) );
1373 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1374 gs_cairo
->cairo_scale( m_cairo
, 1.0, scale
);
1376 gs_cairo
->cairo_arc_negative ( m_cairo
, 0, 0, XLOG2DEVREL(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1379 gs_cairo
->cairo_stroke_preserve( m_cairo
);
1381 gs_cairo
->cairo_line_to(m_cairo
, 0,0);
1383 SetBrush( m_brush
);
1384 gs_cairo
->cairo_fill( m_cairo
);
1386 gs_cairo
->cairo_restore( m_cairo
);
1388 CalcBoundingBox( x
, y
);
1389 CalcBoundingBox( x
+w
, y
+h
);
1392 void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x
, wxCoord y
)
1394 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1398 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1399 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1400 gs_cairo
->cairo_stroke ( m_cairo
);
1402 CalcBoundingBox( x
, y
);
1405 void wxGtkPrinterDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1407 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1414 for ( i
=0; i
<n
; i
++ )
1415 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1417 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1419 for (i
= 1; i
< n
; i
++)
1420 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1422 gs_cairo
->cairo_stroke ( m_cairo
);
1425 void wxGtkPrinterDCImpl::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1429 gs_cairo
->cairo_save(m_cairo
);
1430 if (fillStyle
== wxWINDING_RULE
)
1431 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1433 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1435 int x
= points
[0].x
+ xoffset
;
1436 int y
= points
[0].y
+ yoffset
;
1437 gs_cairo
->cairo_new_path(m_cairo
);
1438 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1440 for (i
= 1; i
< n
; i
++)
1442 int x
= points
[i
].x
+ xoffset
;
1443 int y
= points
[i
].y
+ yoffset
;
1444 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1446 gs_cairo
->cairo_close_path(m_cairo
);
1448 SetBrush( m_brush
);
1449 gs_cairo
->cairo_fill_preserve( m_cairo
);
1452 gs_cairo
->cairo_stroke( m_cairo
);
1454 CalcBoundingBox( x
, y
);
1456 gs_cairo
->cairo_restore(m_cairo
);
1459 void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1461 wxDCImpl::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1464 void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1469 gs_cairo
->cairo_new_path(m_cairo
);
1470 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
1472 SetBrush( m_brush
);
1473 gs_cairo
->cairo_fill_preserve( m_cairo
);
1476 gs_cairo
->cairo_stroke( m_cairo
);
1478 CalcBoundingBox( x
, y
);
1479 CalcBoundingBox( x
+ width
, y
+ height
);
1482 void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1487 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1489 wxCoord dd
= 2 * (wxCoord
) radius
;
1490 if (dd
> width
) dd
= width
;
1491 if (dd
> height
) dd
= height
;
1494 wxCoord rad
= (wxCoord
) radius
;
1496 gs_cairo
->cairo_new_path(m_cairo
);
1497 gs_cairo
->cairo_move_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1498 gs_cairo
->cairo_curve_to(m_cairo
,
1499 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1500 XLOG2DEV(x
),YLOG2DEV(y
),
1501 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1502 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1503 gs_cairo
->cairo_curve_to(m_cairo
,
1504 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1505 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1506 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1507 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1508 gs_cairo
->cairo_curve_to(m_cairo
,
1509 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1510 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1511 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1512 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1513 gs_cairo
->cairo_curve_to(m_cairo
,
1514 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1515 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1516 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1517 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1518 gs_cairo
->cairo_close_path(m_cairo
);
1521 gs_cairo
->cairo_fill_preserve(m_cairo
);
1524 gs_cairo
->cairo_stroke(m_cairo
);
1526 CalcBoundingBox(x
,y
);
1527 CalcBoundingBox(x
+width
,y
+height
);
1530 void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1535 gs_cairo
->cairo_save (m_cairo
);
1537 gs_cairo
->cairo_new_path(m_cairo
);
1539 gs_cairo
->cairo_translate (m_cairo
, XLOG2DEV((wxCoord
) (x
+ width
/ 2.)), YLOG2DEV((wxCoord
) (y
+ height
/ 2.)));
1540 gs_cairo
->cairo_scale(m_cairo
, 1, (double)YLOG2DEVREL(height
)/(double)XLOG2DEVREL(width
));
1541 gs_cairo
->cairo_arc ( m_cairo
, 0, 0, XLOG2DEVREL(width
/2), 0, 2 * M_PI
);
1543 SetBrush( m_brush
);
1544 gs_cairo
->cairo_fill_preserve( m_cairo
);
1547 gs_cairo
->cairo_stroke( m_cairo
);
1549 CalcBoundingBox( x
, y
);
1550 CalcBoundingBox( x
+ width
, y
+ height
);
1552 gs_cairo
->cairo_restore (m_cairo
);
1556 void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList
*points
)
1560 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1563 wxPointList::compatibility_iterator node
= points
->GetFirst();
1564 p
= node
->GetData();
1568 node
= node
->GetNext();
1569 p
= node
->GetData();
1573 (double)(x1
+ c
) / 2;
1575 (double)(y1
+ d
) / 2;
1577 gs_cairo
->cairo_new_path( m_cairo
);
1578 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1579 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1581 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1582 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1584 node
= node
->GetNext();
1587 q
= node
->GetData();
1595 x3
= (double)(x2
+ c
) / 2;
1596 y3
= (double)(y2
+ d
) / 2;
1598 gs_cairo
->cairo_curve_to(m_cairo
,
1599 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1600 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1601 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1603 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1604 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1606 node
= node
->GetNext();
1609 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1611 gs_cairo
->cairo_stroke( m_cairo
);
1613 #endif // wxUSE_SPLINES
1615 bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest
, wxCoord ydest
,
1616 wxCoord width
, wxCoord height
,
1617 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1618 int rop
, bool useMask
,
1619 wxCoord
WXUNUSED_UNLESS_DEBUG(xsrcMask
),
1620 wxCoord
WXUNUSED_UNLESS_DEBUG(ysrcMask
))
1622 wxASSERT_MSG( xsrcMask
== wxDefaultCoord
&& ysrcMask
== wxDefaultCoord
,
1623 wxT("mask coordinates are not supported") );
1625 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1627 // Blit into a bitmap.
1628 wxBitmap
bitmap( width
, height
);
1630 memDC
.SelectObject(bitmap
);
1631 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1632 memDC
.SelectObject(wxNullBitmap
);
1634 // Draw bitmap. scaling and positioning is done there.
1635 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1640 void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1642 DoDrawBitmap( icon
, x
, y
, true );
1645 void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1647 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
1649 cairo_surface_t
* surface
;
1650 x
= wxCoord(XLOG2DEV(x
));
1651 y
= wxCoord(YLOG2DEV(y
));
1652 int bw
= bitmap
.GetWidth();
1653 int bh
= bitmap
.GetHeight();
1654 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1655 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1656 wxUint32
* data
= (wxUint32
*)buffer
;
1658 wxMask
*mask
= NULL
;
1659 if (useMask
) mask
= bmpSource
.GetMask();
1661 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1662 // then we'll use a different format and iterator than if it doesn't.
1663 if (bmpSource
.HasAlpha() || mask
)
1665 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1666 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1667 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1668 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1670 wxAlphaPixelData::Iterator
p(pixData
);
1672 for (y
=0; y
<bh
; y
++)
1674 wxAlphaPixelData::Iterator rowStart
= p
;
1675 for (x
=0; x
<bw
; x
++)
1677 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1678 // with alpha in the upper 8 bits, then red, then green, then
1679 // blue. The 32-bit quantities are stored native-endian.
1680 // Pre-multiplied alpha is used.
1681 unsigned char alpha
= p
.Alpha();
1683 if (!bmpSource
.HasAlpha() && mask
)
1689 *data
= ( alpha
<< 24
1690 | (p
.Red() * alpha
/255) << 16
1691 | (p
.Green() * alpha
/255) << 8
1692 | (p
.Blue() * alpha
/255) );
1697 p
.OffsetY(pixData
, 1);
1702 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1703 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1704 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1705 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1707 wxNativePixelData::Iterator
p(pixData
);
1709 for (y
=0; y
<bh
; y
++)
1711 wxNativePixelData::Iterator rowStart
= p
;
1712 for (x
=0; x
<bw
; x
++)
1714 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1715 // the upper 8 bits unused. Red, Green, and Blue are stored in
1716 // the remaining 24 bits in that order. The 32-bit quantities
1717 // are stored native-endian.
1718 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1723 p
.OffsetY(pixData
, 1);
1728 gs_cairo
->cairo_save(m_cairo
);
1730 // Prepare to draw the image.
1731 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1734 cairo_filter_t filter
= CAIRO_FILTER_BILINEAR
;
1735 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1736 cairo_pattern_set_filter(pattern
,filter
);
1737 wxDouble scaleX
= (wxDouble
) XLOG2DEVREL(bw
) / (wxDouble
) bw
;
1738 wxDouble scaleY
= (wxDouble
) YLOG2DEVREL(bh
) / (wxDouble
) bh
;
1739 cairo_scale(m_cairo
, scaleX
, scaleY
);
1741 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
1742 // Use the original size here since the context is scaled already.
1743 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1744 // Fill the rectangle using the pattern.
1745 gs_cairo
->cairo_fill(m_cairo
);
1748 gs_cairo
->cairo_pattern_destroy(pattern
);
1749 gs_cairo
->cairo_surface_destroy(surface
);
1752 CalcBoundingBox(0,0);
1753 CalcBoundingBox(bw
,bh
);
1755 gs_cairo
->cairo_restore(m_cairo
);
1758 void wxGtkPrinterDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1760 DoDrawRotatedText( text
, x
, y
, 0.0 );
1763 void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1765 double xx
= XLOG2DEV(x
);
1766 double yy
= YLOG2DEV(y
);
1770 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1772 const wxUTF8Buf data
= text
.utf8_str();
1774 size_t datalen
= strlen(data
);
1775 pango_layout_set_text( m_layout
, data
, datalen
);
1779 PangoAttrList
*attrs
= pango_attr_list_new();
1780 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1782 a
->end_index
= datalen
;
1783 pango_attr_list_insert(attrs
, a
);
1784 pango_layout_set_attributes(m_layout
, attrs
);
1785 pango_attr_list_unref(attrs
);
1788 if (m_textForegroundColour
.Ok())
1790 unsigned char red
= m_textForegroundColour
.Red();
1791 unsigned char blue
= m_textForegroundColour
.Blue();
1792 unsigned char green
= m_textForegroundColour
.Green();
1793 unsigned char alpha
= m_textForegroundColour
.Alpha();
1795 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1797 double redPS
= (double)(red
) / 255.0;
1798 double bluePS
= (double)(blue
) / 255.0;
1799 double greenPS
= (double)(green
) / 255.0;
1800 double alphaPS
= (double)(alpha
) / 255.0;
1802 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1805 m_currentBlue
= blue
;
1806 m_currentGreen
= green
;
1807 m_currentAlpha
= alpha
;
1813 // Scale font description.
1814 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1815 double size
= oldSize
;
1816 size
= size
* m_scaleX
;
1817 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1819 // Actually apply scaled font.
1820 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1822 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1824 if ( m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1826 unsigned char red
= m_textBackgroundColour
.Red();
1827 unsigned char blue
= m_textBackgroundColour
.Blue();
1828 unsigned char green
= m_textBackgroundColour
.Green();
1829 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1831 double redPS
= (double)(red
) / 255.0;
1832 double bluePS
= (double)(blue
) / 255.0;
1833 double greenPS
= (double)(green
) / 255.0;
1834 double alphaPS
= (double)(alpha
) / 255.0;
1836 gs_cairo
->cairo_save(m_cairo
);
1837 gs_cairo
->cairo_translate(m_cairo
, xx
, yy
);
1838 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1839 gs_cairo
->cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1840 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1841 gs_cairo
->cairo_fill(m_cairo
);
1842 gs_cairo
->cairo_restore(m_cairo
);
1846 gs_cairo
->cairo_move_to (m_cairo
, xx
, yy
);
1848 gs_cairo
->cairo_save( m_cairo
);
1850 if (fabs(angle
) > 0.00001)
1851 gs_cairo
->cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1853 gs_cairo
->pango_cairo_update_layout (m_cairo
, m_layout
);
1854 gs_cairo
->pango_cairo_show_layout (m_cairo
, m_layout
);
1856 gs_cairo
->cairo_restore( m_cairo
);
1860 // Undo underline attributes setting
1861 pango_layout_set_attributes(m_layout
, NULL
);
1864 // Reset unscaled size.
1865 pango_font_description_set_size( m_fontdesc
, oldSize
);
1867 // Actually apply unscaled font.
1868 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1870 // Back to device units:
1871 CalcBoundingBox (x
, y
);
1872 CalcBoundingBox (x
+ w
, y
+ h
);
1875 void wxGtkPrinterDCImpl::Clear()
1877 // Clear does nothing for printing, but keep the code
1880 gs_cairo->cairo_save(m_cairo);
1881 gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1882 SetBrush(m_backgroundBrush);
1883 gs_cairo->cairo_paint(m_cairo);
1884 gs_cairo->cairo_restore(m_cairo);
1888 void wxGtkPrinterDCImpl::SetFont( const wxFont
& font
)
1895 pango_font_description_free( m_fontdesc
);
1897 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
); // m_fontdesc is now set to device units
1899 // Scale font description from device units to pango units
1900 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1901 double size
= oldSize
*m_DEV2PS
; // scale to cairo units
1902 pango_font_description_set_size( m_fontdesc
, (gint
)size
); // apply to description
1904 // Actually apply scaled font.
1905 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1909 void wxGtkPrinterDCImpl::SetPen( const wxPen
& pen
)
1911 if (!pen
.Ok()) return;
1917 if (m_pen
.GetWidth() <= 0)
1920 width
= (double) m_pen
.GetWidth();
1922 gs_cairo
->cairo_set_line_width( m_cairo
, width
* m_DEV2PS
* m_scaleX
);
1923 static const double dotted
[] = {2.0, 5.0};
1924 static const double short_dashed
[] = {4.0, 4.0};
1925 static const double long_dashed
[] = {4.0, 8.0};
1926 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1928 switch (m_pen
.GetStyle())
1930 case wxPENSTYLE_DOT
: gs_cairo
->cairo_set_dash( m_cairo
, dotted
, 2, 0 ); break;
1931 case wxPENSTYLE_SHORT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, short_dashed
, 2, 0 ); break;
1932 case wxPENSTYLE_LONG_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, long_dashed
, 2, 0 ); break;
1933 case wxPENSTYLE_DOT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, dotted_dashed
, 4, 0 ); break;
1934 case wxPENSTYLE_USER_DASH
:
1937 int num
= m_pen
.GetDashes (&wx_dashes
);
1938 gdouble
*g_dashes
= g_new( gdouble
, num
);
1940 for (i
= 0; i
< num
; ++i
)
1941 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1942 gs_cairo
->cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1946 case wxPENSTYLE_SOLID
:
1947 case wxPENSTYLE_TRANSPARENT
:
1948 default: gs_cairo
->cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
1951 switch (m_pen
.GetCap())
1953 case wxCAP_PROJECTING
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
1954 case wxCAP_BUTT
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
1956 default: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
1959 switch (m_pen
.GetJoin())
1961 case wxJOIN_BEVEL
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
1962 case wxJOIN_MITER
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
1964 default: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
1967 unsigned char red
= m_pen
.GetColour().Red();
1968 unsigned char blue
= m_pen
.GetColour().Blue();
1969 unsigned char green
= m_pen
.GetColour().Green();
1970 unsigned char alpha
= m_pen
.GetColour().Alpha();
1972 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1974 double redPS
= (double)(red
) / 255.0;
1975 double bluePS
= (double)(blue
) / 255.0;
1976 double greenPS
= (double)(green
) / 255.0;
1977 double alphaPS
= (double)(alpha
) / 255.0;
1979 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1982 m_currentBlue
= blue
;
1983 m_currentGreen
= green
;
1984 m_currentAlpha
= alpha
;
1988 void wxGtkPrinterDCImpl::SetBrush( const wxBrush
& brush
)
1990 if (!brush
.Ok()) return;
1994 if (m_brush
.GetStyle() == wxBRUSHSTYLE_TRANSPARENT
)
1996 gs_cairo
->cairo_set_source_rgba( m_cairo
, 0, 0, 0, 0 );
2005 unsigned char red
= m_brush
.GetColour().Red();
2006 unsigned char blue
= m_brush
.GetColour().Blue();
2007 unsigned char green
= m_brush
.GetColour().Green();
2008 unsigned char alpha
= m_brush
.GetColour().Alpha();
2010 double redPS
= (double)(red
) / 255.0;
2011 double bluePS
= (double)(blue
) / 255.0;
2012 double greenPS
= (double)(green
) / 255.0;
2013 double alphaPS
= (double)(alpha
) / 255.0;
2015 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
2017 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
2020 m_currentBlue
= blue
;
2021 m_currentGreen
= green
;
2022 m_currentAlpha
= alpha
;
2025 if (m_brush
.IsHatch())
2028 cairo_surface_t
*surface
;
2029 surface
= gs_cairo
->cairo_surface_create_similar(gs_cairo
->cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
2030 cr
= gs_cairo
->cairo_create(surface
);
2031 gs_cairo
->cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
2032 gs_cairo
->cairo_set_line_width(cr
, 1);
2033 gs_cairo
->cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
2035 switch (m_brush
.GetStyle())
2037 case wxBRUSHSTYLE_CROSS_HATCH
:
2038 gs_cairo
->cairo_move_to(cr
, 5, 0);
2039 gs_cairo
->cairo_line_to(cr
, 5, 10);
2040 gs_cairo
->cairo_move_to(cr
, 0, 5);
2041 gs_cairo
->cairo_line_to(cr
, 10, 5);
2043 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
2044 gs_cairo
->cairo_move_to(cr
, 0, 10);
2045 gs_cairo
->cairo_line_to(cr
, 10, 0);
2047 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
2048 gs_cairo
->cairo_move_to(cr
, 0, 0);
2049 gs_cairo
->cairo_line_to(cr
, 10, 10);
2051 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
2052 gs_cairo
->cairo_move_to(cr
, 0, 0);
2053 gs_cairo
->cairo_line_to(cr
, 10, 10);
2054 gs_cairo
->cairo_move_to(cr
, 10, 0);
2055 gs_cairo
->cairo_line_to(cr
, 0, 10);
2057 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
2058 gs_cairo
->cairo_move_to(cr
, 0, 5);
2059 gs_cairo
->cairo_line_to(cr
, 10, 5);
2061 case wxBRUSHSTYLE_VERTICAL_HATCH
:
2062 gs_cairo
->cairo_move_to(cr
, 5, 0);
2063 gs_cairo
->cairo_line_to(cr
, 5, 10);
2066 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
2069 gs_cairo
->cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
2070 gs_cairo
->cairo_stroke (cr
);
2072 gs_cairo
->cairo_destroy(cr
);
2073 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface (surface
);
2074 gs_cairo
->cairo_surface_destroy(surface
);
2075 gs_cairo
->cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
2076 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
2077 gs_cairo
->cairo_pattern_destroy(pattern
);
2081 void wxGtkPrinterDCImpl::SetLogicalFunction( int function
)
2083 if (function
== wxCLEAR
)
2084 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
2085 else if (function
== wxOR
)
2086 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
2087 else if (function
== wxNO_OP
)
2088 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
2089 else if (function
== wxAND
)
2090 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
2091 else if (function
== wxSET
)
2092 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
2093 else if (function
== wxXOR
)
2094 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
2095 else // wxCOPY or anything else.
2096 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
2099 void wxGtkPrinterDCImpl::SetBackground( const wxBrush
& brush
)
2101 m_backgroundBrush
= brush
;
2102 gs_cairo
->cairo_save(m_cairo
);
2103 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2105 SetBrush(m_backgroundBrush
);
2106 gs_cairo
->cairo_paint(m_cairo
);
2107 gs_cairo
->cairo_restore(m_cairo
);
2110 void wxGtkPrinterDCImpl::SetBackgroundMode(int mode
)
2112 if (mode
== wxBRUSHSTYLE_SOLID
)
2113 m_backgroundMode
= wxBRUSHSTYLE_SOLID
;
2115 m_backgroundMode
= wxBRUSHSTYLE_TRANSPARENT
;
2118 void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2120 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2121 gs_cairo
->cairo_clip(m_cairo
);
2124 void wxGtkPrinterDCImpl::DestroyClippingRegion()
2126 gs_cairo
->cairo_reset_clip(m_cairo
);
2129 bool wxGtkPrinterDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
2134 void wxGtkPrinterDCImpl::EndDoc()
2139 void wxGtkPrinterDCImpl::StartPage()
2144 void wxGtkPrinterDCImpl::EndPage()
2149 wxCoord
wxGtkPrinterDCImpl::GetCharHeight() const
2151 pango_layout_set_text( m_layout
, "H", 1 );
2154 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2156 return wxRound( h
* m_PS2DEV
);
2159 wxCoord
wxGtkPrinterDCImpl::GetCharWidth() const
2161 pango_layout_set_text( m_layout
, "H", 1 );
2164 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2166 return wxRound( w
* m_PS2DEV
);
2169 void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2171 wxCoord
*externalLeading
,
2172 const wxFont
*theFont
) const
2180 if ( externalLeading
)
2181 *externalLeading
= 0;
2188 // Set layout's text
2189 const wxUTF8Buf dataUTF8
= string
.utf8_str();
2191 PangoFontDescription
*desc
= m_fontdesc
;
2192 if (theFont
) desc
= theFont
->GetNativeFontInfo()->description
;
2194 gint oldSize
= pango_font_description_get_size( desc
);
2195 double size
= oldSize
;
2196 size
= size
* m_scaleY
;
2197 pango_font_description_set_size( desc
, (gint
)size
);
2199 // apply scaled font
2200 pango_layout_set_font_description( m_layout
, desc
);
2202 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2205 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2208 *width
= wxRound( (double)w
/ m_scaleX
* m_PS2DEV
);
2210 *height
= wxRound( (double)h
/ m_scaleY
* m_PS2DEV
);
2214 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2215 int baseline
= pango_layout_iter_get_baseline(iter
);
2216 pango_layout_iter_free(iter
);
2217 *descent
= wxRound( (h
- PANGO_PIXELS(baseline
)) * m_PS2DEV
);
2220 // Reset unscaled size.
2221 pango_font_description_set_size( desc
, oldSize
);
2223 // Reset unscaled font.
2224 pango_layout_set_font_description( m_layout
, m_fontdesc
);
2227 void wxGtkPrinterDCImpl::DoGetSize(int* width
, int* height
) const
2229 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2232 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_POINTS
) * m_PS2DEV
);
2234 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_POINTS
) * m_PS2DEV
);
2237 void wxGtkPrinterDCImpl::DoGetSizeMM(int *width
, int *height
) const
2239 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2242 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_MM
) );
2244 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_MM
) );
2247 wxSize
wxGtkPrinterDCImpl::GetPPI() const
2249 return wxSize( (int)m_resolution
, (int)m_resolution
);
2252 void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData
& data
)
2257 // overriden for wxPrinterDC Impl
2259 wxRect
wxGtkPrinterDCImpl::GetPaperRect()
2261 // Does GtkPrint support printer margins?
2264 DoGetSize( &w
, &h
);
2265 return wxRect( 0,0,w
,h
);
2268 int wxGtkPrinterDCImpl::GetResolution()
2270 return m_resolution
;
2273 // ----------------------------------------------------------------------------
2275 // ----------------------------------------------------------------------------
2277 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2279 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2280 wxPrintout
* WXUNUSED(printoutForPrinting
),
2283 // convert wxPrintQuality to resolution (input pointer can be NULL)
2284 wxPrintQuality quality
= data
? data
->GetQuality() : wxPRINT_QUALITY_MEDIUM
;
2287 case wxPRINT_QUALITY_HIGH
:
2288 m_resolution
= 1200;
2291 case wxPRINT_QUALITY_LOW
:
2295 case wxPRINT_QUALITY_DRAFT
:
2302 // positive values directly indicate print resolution
2303 m_resolution
= quality
;
2307 wxFAIL_MSG( "unknown print quality" );
2310 case wxPRINT_QUALITY_MEDIUM
:
2319 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2320 wxPrintout
*printoutForPrinting
,
2321 wxPrintDialogData
*data
)
2322 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2324 Init(printout
, printoutForPrinting
, data
? &data
->GetPrintData() : NULL
);
2327 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2328 wxPrintout
*printoutForPrinting
,
2330 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2332 Init(printout
, printoutForPrinting
, data
);
2335 wxGtkPrintPreview::~wxGtkPrintPreview()
2339 bool wxGtkPrintPreview::Print(bool interactive
)
2341 if (!m_printPrintout
)
2344 wxPrinter
printer(& m_printDialogData
);
2345 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2348 void wxGtkPrintPreview::DetermineScaling()
2350 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2352 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2354 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2358 wxSize ScreenPixels
= wxGetDisplaySize();
2359 wxSize ScreenMM
= wxGetDisplaySizeMM();
2361 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2362 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2364 m_previewPrintout
->SetPPIPrinter( m_resolution
, m_resolution
);
2366 // Get width and height in points (1/72th of an inch)
2367 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2369 sizeDevUnits
.x
= wxRound((double)sizeDevUnits
.x
* (double)m_resolution
/ 72.0);
2370 sizeDevUnits
.y
= wxRound((double)sizeDevUnits
.y
* (double)m_resolution
/ 72.0);
2371 wxSize
sizeTenthsMM(paper
->GetSize());
2372 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2374 // If in landscape mode, we need to swap the width and height.
2375 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2377 m_pageWidth
= sizeDevUnits
.y
;
2378 m_pageHeight
= sizeDevUnits
.x
;
2379 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2383 m_pageWidth
= sizeDevUnits
.x
;
2384 m_pageHeight
= sizeDevUnits
.y
;
2385 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2387 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2388 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2390 // At 100%, the page should look about page-size on the screen.
2391 m_previewScaleX
= 0.8 * 72.0 / (double)m_resolution
;
2392 m_previewScaleY
= m_previewScaleX
;