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"
28 #include "wx/module.h"
32 #include "wx/fontutil.h"
33 #include "wx/gtk/private.h"
34 #include "wx/dynlib.h"
36 #include "wx/rawbmp.h"
39 #include <gtk/gtkpagesetupunixdialog.h>
42 wxFORCE_LINK_THIS_MODULE(gtk_print
)
44 #if wxUSE_LIBGNOMEPRINT
45 #include "wx/gtk/gnome/gprint.h"
48 // Usefull to convert angles from/to Rad to/from Deg.
49 static const double RAD2DEG
= 180.0 / M_PI
;
50 static const double DEG2RAD
= M_PI
/ 180.0;
52 static wxCairoLibrary
* gs_cairo
= NULL
;
54 //----------------------------------------------------------------------------
56 // Initialized when starting the app : if it successfully load the gtk-print framework,
57 // it uses it. If not, it falls back to gnome print (see /gtk/gnome/gprint.cpp) then
58 // to postscript if gnomeprint is not available.
59 //----------------------------------------------------------------------------
61 class wxGtkPrintModule
: public wxModule
66 #if wxUSE_LIBGNOMEPRINT
67 // This module must be initialized AFTER gnomeprint's one
68 AddDependency(CLASSINFO(wxGnomePrintModule
));
75 DECLARE_DYNAMIC_CLASS(wxGtkPrintModule
)
78 bool wxGtkPrintModule::OnInit()
80 gs_cairo
= wxCairoLibrary::Get();
81 if (gs_cairo
&& gtk_check_version(2,10,0) == NULL
)
82 wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory
);
86 void wxGtkPrintModule::OnExit()
91 IMPLEMENT_DYNAMIC_CLASS(wxGtkPrintModule
, wxModule
)
93 //----------------------------------------------------------------------------
95 //----------------------------------------------------------------------------
97 wxPrinterBase
* wxGtkPrintFactory::CreatePrinter( wxPrintDialogData
*data
)
99 return new wxGtkPrinter( data
);
102 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
103 wxPrintout
*printout
,
104 wxPrintDialogData
*data
)
106 return new wxGtkPrintPreview( preview
, printout
, data
);
109 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
110 wxPrintout
*printout
,
113 return new wxGtkPrintPreview( preview
, printout
, data
);
116 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
117 wxPrintDialogData
*data
)
119 return new wxGtkPrintDialog( parent
, data
);
122 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
125 return new wxGtkPrintDialog( parent
, data
);
128 wxPageSetupDialogBase
*wxGtkPrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
129 wxPageSetupDialogData
* data
)
131 return new wxGtkPageSetupDialog( parent
, data
);
134 bool wxGtkPrintFactory::HasPrintSetupDialog()
140 wxGtkPrintFactory::CreatePrintSetupDialog(wxWindow
* WXUNUSED(parent
),
141 wxPrintData
* WXUNUSED(data
))
146 wxDCImpl
* wxGtkPrintFactory::CreatePrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
)
148 return new wxGtkPrinterDCImpl( owner
, data
);
151 bool wxGtkPrintFactory::HasOwnPrintToFile()
156 bool wxGtkPrintFactory::HasPrinterLine()
161 wxString
wxGtkPrintFactory::CreatePrinterLine()
164 return wxEmptyString
;
167 bool wxGtkPrintFactory::HasStatusLine()
173 wxString
wxGtkPrintFactory::CreateStatusLine()
176 return wxEmptyString
;
179 wxPrintNativeDataBase
*wxGtkPrintFactory::CreatePrintNativeData()
181 return new wxGtkPrintNativeData
;
184 //----------------------------------------------------------------------------
185 // Callback functions for Gtk Printings.
186 //----------------------------------------------------------------------------
188 // We use it to pass useful objects to GTK printing callback functions.
189 struct wxPrinterToGtkData
191 wxGtkPrinter
* printer
;
192 wxPrintout
* printout
;
197 static void gtk_begin_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
199 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
201 data
->printer
->BeginPrint(data
->printout
, operation
, context
);
204 static void gtk_draw_page_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gint page_nr
, gpointer user_data
)
206 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
208 data
->printer
->DrawPage(data
->printout
, operation
, context
, page_nr
);
211 static void gtk_end_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
212 GtkPrintContext
* WXUNUSED(context
),
215 wxPrintout
*printout
= (wxPrintout
*) user_data
;
217 printout
->OnEndPrinting();
221 gtk_preview_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
222 GtkPrintOperationPreview
* WXUNUSED(preview
),
223 GtkPrintContext
*context
,
227 wxPrintout
*printout
= (wxPrintout
*) user_data
;
229 printout
->SetIsPreview(true);
231 /* We create a Cairo context with 72dpi resolution. This resolution is
232 * only used for positioning. */
233 cairo_t
*cairo
= gdk_cairo_create(GTK_WIDGET(parent
)->window
);
234 gtk_print_context_set_cairo_context(context
, cairo
, 72, 72);
240 //----------------------------------------------------------------------------
241 // wxGtkPrintNativeData
242 //----------------------------------------------------------------------------
244 IMPLEMENT_CLASS(wxGtkPrintNativeData
, wxPrintNativeDataBase
)
246 wxGtkPrintNativeData::wxGtkPrintNativeData()
248 m_config
= gtk_print_settings_new();
251 wxGtkPrintNativeData::~wxGtkPrintNativeData()
253 g_object_unref (m_config
);
256 // Convert datas stored in m_config to a wxPrintData.
257 // Called by wxPrintData::ConvertFromNative().
258 bool wxGtkPrintNativeData::TransferTo( wxPrintData
&data
)
263 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
264 if (quality
== GTK_PRINT_QUALITY_HIGH
)
265 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
266 else if (quality
== GTK_PRINT_QUALITY_LOW
)
267 data
.SetQuality(wxPRINT_QUALITY_LOW
);
268 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
269 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
271 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
273 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
275 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
277 switch (gtk_print_settings_get_duplex(m_config
))
279 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
282 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
286 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
290 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
291 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
293 data
.SetOrientation(wxPORTRAIT
);
294 data
.SetOrientationReversed(false);
296 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
298 data
.SetOrientation(wxLANDSCAPE
);
299 data
.SetOrientationReversed(false);
301 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
303 data
.SetOrientation(wxPORTRAIT
);
304 data
.SetOrientationReversed(true);
306 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
308 data
.SetOrientation(wxLANDSCAPE
);
309 data
.SetOrientationReversed(true);
312 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
314 // Paper formats : these are the most common paper formats.
315 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
317 data
.SetPaperId(wxPAPER_NONE
);
318 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
319 data
.SetPaperId(wxPAPER_A3
);
320 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
321 data
.SetPaperId(wxPAPER_A4
);
322 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
323 data
.SetPaperId(wxPAPER_A5
);
324 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
325 data
.SetPaperId(wxPAPER_B5
);
326 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
327 data
.SetPaperId(wxPAPER_LETTER
);
328 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
329 data
.SetPaperId(wxPAPER_LEGAL
);
330 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
331 data
.SetPaperId(wxPAPER_EXECUTIVE
);
332 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
333 data
.SetPaperId(wxPAPER_ENV_10
);
334 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
335 data
.SetPaperId(wxPAPER_ENV_C5
);
336 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
337 data
.SetPaperId(wxPAPER_ENV_C6
);
338 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
339 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
340 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
341 data
.SetPaperId(wxPAPER_ENV_B5
);
342 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
343 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
344 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
345 data
.SetPaperId( wxPAPER_CSHEET
);
346 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
347 data
.SetPaperId( wxPAPER_DSHEET
);
348 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
349 data
.SetPaperId( wxPAPER_ESHEET
);
350 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
351 data
.SetPaperId( wxPAPER_LETTERSMALL
);
352 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
353 data
.SetPaperId( wxPAPER_TABLOID
);
354 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
355 data
.SetPaperId( wxPAPER_LEDGER
);
356 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
357 data
.SetPaperId( wxPAPER_STATEMENT
);
358 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
359 data
.SetPaperId( wxPAPER_A4SMALL
);
360 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
361 data
.SetPaperId( wxPAPER_B4
);
362 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
363 data
.SetPaperId( wxPAPER_FOLIO
);
364 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
365 data
.SetPaperId( wxPAPER_QUARTO
);
366 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
367 data
.SetPaperId( wxPAPER_10X14
);
368 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
369 data
.SetPaperId( wxPAPER_11X17
);
370 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
371 data
.SetPaperId( wxPAPER_NOTE
);
372 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
373 data
.SetPaperId( wxPAPER_ENV_9
);
374 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
375 data
.SetPaperId( wxPAPER_ENV_11
);
376 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
377 data
.SetPaperId( wxPAPER_ENV_12
);
378 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
379 data
.SetPaperId( wxPAPER_ENV_14
);
380 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
381 data
.SetPaperId( wxPAPER_ENV_DL
);
382 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
383 data
.SetPaperId( wxPAPER_ENV_C3
);
384 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
385 data
.SetPaperId( wxPAPER_ENV_C4
);
386 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
387 data
.SetPaperId( wxPAPER_ENV_C65
);
388 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
389 data
.SetPaperId( wxPAPER_ENV_B4
);
390 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
391 data
.SetPaperId( wxPAPER_ENV_B6
);
392 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
393 data
.SetPaperId( wxPAPER_ENV_ITALY
);
394 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
395 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
396 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
397 data
.SetPaperId( wxPAPER_FANFOLD_US
);
398 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
399 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
400 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
401 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
403 data
.SetPaperId(wxPAPER_NONE
);
407 // Put datas given by the wxPrintData into m_config.
408 // Called by wxPrintData::ConvertToNative().
409 bool wxGtkPrintNativeData::TransferFrom( const wxPrintData
&data
)
414 wxPrintQuality quality
= data
.GetQuality();
415 if (quality
== wxPRINT_QUALITY_HIGH
)
416 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
417 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
418 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
419 else if (quality
== wxPRINT_QUALITY_LOW
)
420 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
421 else if (quality
== wxPRINT_QUALITY_DRAFT
)
422 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
423 else if (quality
> 1)
424 gtk_print_settings_set_resolution (m_config
, quality
);
426 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
428 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
430 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
432 switch (data
.GetDuplex())
434 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
437 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
441 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
445 if (!data
.IsOrientationReversed())
447 if (data
.GetOrientation() == wxLANDSCAPE
)
448 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
450 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
453 if (data
.GetOrientation() == wxLANDSCAPE
)
454 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
456 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
459 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
461 // Paper formats: these are the most common paper formats.
462 switch (data
.GetPaperId())
464 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
466 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
468 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
470 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
472 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
474 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
476 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
478 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
480 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
482 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
484 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
486 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
488 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
490 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
492 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
494 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
496 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
498 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
500 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
502 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
504 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
506 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
508 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
510 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
512 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
514 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
516 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
518 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
520 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
522 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
524 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
526 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
528 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
530 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
532 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
534 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
536 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
538 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
540 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
542 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
544 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
546 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
555 void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings
* config
)
558 m_config
= gtk_print_settings_copy(config
);
561 // Extract page setup from settings.
562 GtkPageSetup
* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
564 GtkPageSetup
* page_setup
= gtk_page_setup_new();
565 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
567 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
568 if (paper_size
!= NULL
)
569 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
574 // Insert page setup into a given GtkPrintSettings.
575 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
577 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
578 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
581 //----------------------------------------------------------------------------
583 //----------------------------------------------------------------------------
585 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
587 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
588 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
589 wxPoint(0, 0), wxSize(600, 600),
590 wxDEFAULT_DIALOG_STYLE
|
594 m_printDialogData
= *data
;
600 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
601 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
602 wxPoint(0, 0), wxSize(600, 600),
603 wxDEFAULT_DIALOG_STYLE
|
607 m_printDialogData
= *data
;
614 wxGtkPrintDialog::~wxGtkPrintDialog()
618 // This is called even if we actually don't want the dialog to appear.
619 int wxGtkPrintDialog::ShowModal()
621 GtkPrintOperationResult response
;
623 // We need to restore the settings given in the constructor.
624 wxPrintData data
= m_printDialogData
.GetPrintData();
625 wxGtkPrintNativeData
*native
=
626 (wxGtkPrintNativeData
*) data
.GetNativeData();
627 data
.ConvertToNative();
629 GtkPrintSettings
* settings
= native
->GetPrintConfig();
631 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
632 int fromPage
= m_printDialogData
.GetFromPage();
633 int toPage
= m_printDialogData
.GetToPage();
634 if (m_printDialogData
.GetSelection())
635 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
636 else if (m_printDialogData
.GetAllPages())
637 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
639 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
641 range
= g_new (GtkPageRange
, 1);
642 range
[0].start
= fromPage
-1;
643 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
644 gtk_print_settings_set_page_ranges (settings
, range
, 1);
647 // If the settings are OK, we restore it.
648 if (settings
!= NULL
)
649 gtk_print_operation_set_print_settings (native
->GetPrintJob(), settings
);
650 gtk_print_operation_set_default_page_setup (native
->GetPrintJob(), native
->GetPageSetupFromSettings(settings
));
652 // Show the dialog if needed.
653 GError
* gError
= NULL
;
655 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
657 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
)), &gError
);
659 // Does everything went well?
660 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
664 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
666 g_error_free (gError
);
667 wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError
->message
));
668 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
671 // Now get the settings and save it.
672 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings (native
->GetPrintJob());
673 native
->SetPrintConfig(newSettings
);
674 data
.ConvertFromNative();
676 // Same problem as a few lines before.
677 switch (gtk_print_settings_get_print_pages(newSettings
))
679 case GTK_PRINT_PAGES_CURRENT
:
680 m_printDialogData
.SetSelection( true );
682 case GTK_PRINT_PAGES_RANGES
:
683 {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
684 // 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
685 // will hit "OK" button. However we can only save 1-3 in the print data.
688 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
691 m_printDialogData
.SetFromPage( range
[0].start
);
692 m_printDialogData
.SetToPage( range
[0].end
);
695 m_printDialogData
.SetAllPages( true );
696 m_printDialogData
.SetFromPage( 0 );
697 m_printDialogData
.SetToPage( 9999 );
700 case GTK_PRINT_PAGES_ALL
:
702 m_printDialogData
.SetAllPages( true );
703 m_printDialogData
.SetFromPage( 0 );
704 m_printDialogData
.SetToPage( 9999 );
711 //----------------------------------------------------------------------------
712 // wxGtkPageSetupDialog
713 //----------------------------------------------------------------------------
715 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
717 wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow
*parent
,
718 wxPageSetupDialogData
* data
)
721 m_pageDialogData
= *data
;
726 wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
730 int wxGtkPageSetupDialog::ShowModal()
733 m_pageDialogData
.GetPrintData().ConvertToNative();
734 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
735 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
737 // We only need the pagesetup data which are part of the settings.
738 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
740 // If the user used a custom paper format the last time he printed, we have to restore it too.
741 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
743 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
744 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
746 wxString title
= _("Custom size");
747 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
748 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
749 g_object_unref(customSize
);
753 // Now show the dialog.
754 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
759 if (newPageSetup
!= oldPageSetup
)
761 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
762 m_pageDialogData
.GetPrintData().ConvertFromNative();
764 // Store custom paper format if any.
765 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
767 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
768 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
769 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
770 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
771 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
773 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
774 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
776 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
777 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
779 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
792 //----------------------------------------------------------------------------
794 //----------------------------------------------------------------------------
796 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
798 wxGtkPrinter::wxGtkPrinter( wxPrintDialogData
*data
) :
799 wxPrinterBase( data
)
804 m_printDialogData
= *data
;
807 wxGtkPrinter::~wxGtkPrinter()
811 bool wxGtkPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
815 sm_lastError
= wxPRINTER_ERROR
;
819 // Let's correct the PageInfo just in case the app gives wrong values.
820 int fromPage
, toPage
;
821 int minPage
, maxPage
;
822 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
823 m_printDialogData
.SetAllPages(true);
825 if (minPage
< 1) minPage
= 1;
826 if (maxPage
< 1) maxPage
= 9999;
827 if (maxPage
< minPage
) maxPage
= minPage
;
829 m_printDialogData
.SetMinPage(minPage
);
830 m_printDialogData
.SetMaxPage(maxPage
);
833 if (fromPage
< minPage
) fromPage
= minPage
;
834 else if (fromPage
> maxPage
) fromPage
= maxPage
;
835 m_printDialogData
.SetFromPage(fromPage
);
839 m_printDialogData
.SetToPage(toPage
);
840 if (toPage
> maxPage
) toPage
= maxPage
;
841 else if (toPage
< minPage
) toPage
= minPage
;
844 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
847 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
848 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
850 GtkPrintOperation
*printOp
= gtk_print_operation_new ();
852 native
->SetPrintJob( printOp
);
854 printout
->SetIsPreview(false);
856 wxPrinterToGtkData dataToSend
;
857 dataToSend
.printer
= this;
858 dataToSend
.printout
= printout
;
860 // These Gtk signals are caught here.
861 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
862 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
863 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
864 g_signal_connect (printOp
, "preview", G_CALLBACK (gtk_preview_print_callback
), printout
);
866 // This is used to setup the DC and
867 // show the dialog if desired
868 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
869 dialog
.SetPrintDC(m_dc
);
870 dialog
.SetShowDialog(prompt
);
872 // doesn't necessarily show
873 int ret
= dialog
.ShowModal();
874 if (ret
== wxID_CANCEL
)
876 sm_lastError
= wxPRINTER_CANCELLED
;
880 sm_lastError
= wxPRINTER_ERROR
;
881 wxFAIL_MSG(_("The print dialog returned an error."));
884 g_object_unref (printOp
);
886 return (sm_lastError
== wxPRINTER_NO_ERROR
);
889 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
891 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
892 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
894 SetPrintContext(context
);
895 native
->SetPrintContext( context
);
897 wxPrinterDC
*printDC
= new wxPrinterDC( printdata
);
902 if (sm_lastError
!= wxPRINTER_CANCELLED
)
904 sm_lastError
= wxPRINTER_ERROR
;
905 wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used."));
909 wxSize ScreenPixels
= wxGetDisplaySize();
910 wxSize ScreenMM
= wxGetDisplaySizeMM();
912 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
913 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
914 printout
->SetPPIPrinter( printDC
->GetResolution(),
915 printDC
->GetResolution() );
917 printout
->SetDC(m_dc
);
920 m_dc
->GetSize(&w
, &h
);
921 printout
->SetPageSizePixels((int)w
, (int)h
);
922 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
924 m_dc
->GetSizeMM(&mw
, &mh
);
925 printout
->SetPageSizeMM((int)mw
, (int)mh
);
926 printout
->OnPreparePrinting();
928 // Get some parameters from the printout, if defined.
929 int fromPage
, toPage
;
930 int minPage
, maxPage
;
931 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
935 sm_lastError
= wxPRINTER_ERROR
;
936 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
940 printout
->OnBeginPrinting();
944 // If we're not previewing we need to calculate the number of pages to print.
945 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
946 // have defined in the dialog. So the number of pages is the maximum available.
947 if (!printout
->IsPreview())
949 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
950 switch (gtk_print_settings_get_print_pages(settings
))
952 case GTK_PRINT_PAGES_CURRENT
:
955 case GTK_PRINT_PAGES_RANGES
:
956 {gint num_ranges
= 0;
959 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
960 for (i
=0; i
<num_ranges
; i
++)
962 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
963 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
964 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
965 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
966 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
968 gtk_print_settings_set_page_ranges (settings
, range
, 1);
970 case GTK_PRINT_PAGES_ALL
:
972 numPages
= maxPage
- minPage
+ 1;
976 else numPages
= maxPage
- minPage
+ 1;
978 gtk_print_operation_set_n_pages(operation
, numPages
);
981 void wxGtkPrinter::DrawPage(wxPrintout
*printout
,
982 GtkPrintOperation
*operation
,
983 GtkPrintContext
* WXUNUSED(context
),
986 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
987 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
989 int numPageToDraw
= page_nr
+ minPage
;
990 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
991 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
993 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
994 switch (gtk_print_settings_get_print_pages(settings
))
996 case GTK_PRINT_PAGES_CURRENT
:
997 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
998 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
1000 case GTK_PRINT_PAGES_RANGES
:
1001 {gint num_ranges
= 0;
1002 GtkPageRange
* range
;
1003 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
1004 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
1005 if (num_ranges
>= 1)
1007 startPage
= range
[0].start
+ 1;
1008 endPage
= range
[0].end
+ 1;
1011 startPage
= minPage
;
1015 case GTK_PRINT_PAGES_ALL
:
1017 startPage
= minPage
;
1022 if(numPageToDraw
== startPage
)
1024 if (!printout
->OnBeginDocument(startPage
, endPage
))
1026 wxLogError(_("Could not start printing."));
1027 sm_lastError
= wxPRINTER_ERROR
;
1031 // The app can render the page numPageToDraw.
1032 if (printout
->HasPage(numPageToDraw
))
1035 printout
->OnPrintPage(numPageToDraw
);
1040 if(numPageToDraw
== endPage
)
1042 printout
->OnEndDocument();
1046 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1048 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1050 dialog
.SetPrintDC(m_dc
);
1051 dialog
.SetShowDialog(true);
1053 int ret
= dialog
.ShowModal();
1055 if (ret
== wxID_CANCEL
)
1057 sm_lastError
= wxPRINTER_CANCELLED
;
1062 sm_lastError
= wxPRINTER_ERROR
;
1063 wxFAIL_MSG(_("The print dialog returned an error."));
1067 m_printDialogData
= dialog
.GetPrintDialogData();
1069 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
1072 bool wxGtkPrinter::Setup( wxWindow
* WXUNUSED(parent
) )
1074 // Obsolete, for backward compatibility.
1078 //-----------------------------------------------------------------------------
1080 //-----------------------------------------------------------------------------
1082 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
1083 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
1084 #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
1085 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
1088 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl
, wxDCImpl
)
1090 wxGtkPrinterDCImpl::wxGtkPrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
) :
1095 wxGtkPrintNativeData
*native
=
1096 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1098 m_gpc
= native
->GetPrintContext();
1100 // Match print quality to resolution (high = 1200dpi)
1101 m_resolution
= m_printData
.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
1102 if (m_resolution
< 0)
1103 m_resolution
= (1 << (m_resolution
+4)) *150;
1105 m_PS2DEV
= (double)m_resolution
/ 72.0;
1106 m_DEV2PS
= 72.0 / (double)m_resolution
;
1108 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1109 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1110 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1112 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1118 m_signX
= 1; // default x-axis left to right.
1119 m_signY
= 1; // default y-axis bottom up -> top down.
1121 // By default the origin of the Cairo context is in the upper left
1122 // corner of the printable area. We need to translate it so that it
1123 // is in the upper left corner of the paper (without margins)
1124 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
1126 ml
= gtk_page_setup_get_left_margin (setup
, GTK_UNIT_POINTS
);
1127 mt
= gtk_page_setup_get_top_margin (setup
, GTK_UNIT_POINTS
);
1128 gs_cairo
->cairo_translate(m_cairo
, -ml
, -mt
);
1131 wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
1133 g_object_unref(m_context
);
1134 g_object_unref(m_layout
);
1137 bool wxGtkPrinterDCImpl::IsOk() const
1139 return m_gpc
!= NULL
;
1142 bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord
WXUNUSED(x1
),
1143 wxCoord
WXUNUSED(y1
),
1144 const wxColour
& WXUNUSED(col
),
1145 int WXUNUSED(style
))
1147 // We can't access the given coord as a Cairo context is scalable, ie a
1148 // coord doesn't mean anything in this context.
1149 wxFAIL_MSG(_("not implemented"));
1153 void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1155 wxCoord xC
= circleCenter
.x
;
1156 wxCoord yC
= circleCenter
.y
;
1157 wxCoord xR
= rect
.x
;
1158 wxCoord yR
= rect
.y
;
1159 wxCoord w
= rect
.width
;
1160 wxCoord h
= rect
.height
;
1162 double radius
= sqrt((w
/2)*(w
/2)+(h
/2)*(h
/2));
1164 unsigned char redI
= initialColour
.Red();
1165 unsigned char blueI
= initialColour
.Blue();
1166 unsigned char greenI
= initialColour
.Green();
1167 unsigned char alphaI
= initialColour
.Alpha();
1168 unsigned char redD
= destColour
.Red();
1169 unsigned char blueD
= destColour
.Blue();
1170 unsigned char greenD
= destColour
.Green();
1171 unsigned char alphaD
= destColour
.Alpha();
1173 double redIPS
= (double)(redI
) / 255.0;
1174 double blueIPS
= (double)(blueI
) / 255.0;
1175 double greenIPS
= (double)(greenI
) / 255.0;
1176 double alphaIPS
= (double)(alphaI
) / 255.0;
1177 double redDPS
= (double)(redD
) / 255.0;
1178 double blueDPS
= (double)(blueD
) / 255.0;
1179 double greenDPS
= (double)(greenD
) / 255.0;
1180 double alphaDPS
= (double)(alphaD
) / 255.0;
1182 // Create a pattern with the gradient.
1183 cairo_pattern_t
* gradient
;
1184 gradient
= gs_cairo
->cairo_pattern_create_radial (XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), 0, XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), radius
* m_DEV2PS
);
1185 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1186 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1188 // Fill the rectangle with this pattern.
1189 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1190 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(xR
), YLOG2DEV(yR
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1191 gs_cairo
->cairo_fill(m_cairo
);
1193 gs_cairo
->cairo_pattern_destroy(gradient
);
1195 CalcBoundingBox(xR
, yR
);
1196 CalcBoundingBox(xR
+w
, yR
+h
);
1199 void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1203 wxCoord w
= rect
.width
;
1204 wxCoord h
= rect
.height
;
1206 unsigned char redI
= initialColour
.Red();
1207 unsigned char blueI
= initialColour
.Blue();
1208 unsigned char greenI
= initialColour
.Green();
1209 unsigned char alphaI
= initialColour
.Alpha();
1210 unsigned char redD
= destColour
.Red();
1211 unsigned char blueD
= destColour
.Blue();
1212 unsigned char greenD
= destColour
.Green();
1213 unsigned char alphaD
= destColour
.Alpha();
1215 double redIPS
= (double)(redI
) / 255.0;
1216 double blueIPS
= (double)(blueI
) / 255.0;
1217 double greenIPS
= (double)(greenI
) / 255.0;
1218 double alphaIPS
= (double)(alphaI
) / 255.0;
1219 double redDPS
= (double)(redD
) / 255.0;
1220 double blueDPS
= (double)(blueD
) / 255.0;
1221 double greenDPS
= (double)(greenD
) / 255.0;
1222 double alphaDPS
= (double)(alphaD
) / 255.0;
1224 // Create a pattern with the gradient.
1225 cairo_pattern_t
* gradient
;
1226 gradient
= gs_cairo
->cairo_pattern_create_linear (XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x
+w
), YLOG2DEV(y
));
1228 if (nDirection
== wxWEST
)
1230 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1231 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1234 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1235 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1238 // Fill the rectangle with this pattern.
1239 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1240 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1241 gs_cairo
->cairo_fill(m_cairo
);
1243 gs_cairo
->cairo_pattern_destroy(gradient
);
1245 CalcBoundingBox(x
, y
);
1246 CalcBoundingBox(x
+w
, y
+h
);
1249 bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord
WXUNUSED(x1
),
1250 wxCoord
WXUNUSED(y1
),
1251 wxColour
* WXUNUSED(col
)) const
1253 wxFAIL_MSG(_("not implemented"));
1257 void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1259 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1262 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1263 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1264 gs_cairo
->cairo_stroke ( m_cairo
);
1266 CalcBoundingBox( x1
, y1
);
1267 CalcBoundingBox( x2
, y2
);
1270 void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x
, wxCoord y
)
1277 gs_cairo
->cairo_move_to (m_cairo
, XLOG2DEV(x
), 0);
1278 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEV(x
), YLOG2DEVREL(h
));
1279 gs_cairo
->cairo_move_to (m_cairo
, 0, YLOG2DEV(y
));
1280 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEVREL(w
), YLOG2DEV(y
));
1282 gs_cairo
->cairo_stroke (m_cairo
);
1283 CalcBoundingBox( 0, 0 );
1284 CalcBoundingBox( w
, h
);
1287 void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1289 double dx
= x1
- xc
;
1290 double dy
= y1
- yc
;
1291 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1293 double alpha1
, alpha2
;
1294 if (x1
== x2
&& y1
== y2
)
1302 alpha1
= alpha2
= 0.0;
1306 alpha1
= (x1
- xc
== 0) ?
1307 (y1
- yc
< 0) ? 90.0 : -90.0 :
1308 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1309 alpha2
= (x2
- xc
== 0) ?
1310 (y2
- yc
< 0) ? 90.0 : -90.0 :
1311 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1313 while (alpha1
<= 0) alpha1
+= 360;
1314 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1315 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1316 while (alpha2
> 360) alpha2
-= 360;
1322 gs_cairo
->cairo_new_path(m_cairo
);
1324 gs_cairo
->cairo_arc_negative ( m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
);
1325 gs_cairo
->cairo_line_to(m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
));
1326 gs_cairo
->cairo_close_path (m_cairo
);
1328 SetBrush( m_brush
);
1329 gs_cairo
->cairo_fill_preserve( m_cairo
);
1332 gs_cairo
->cairo_stroke( m_cairo
);
1334 CalcBoundingBox (x1
, y1
);
1335 CalcBoundingBox (xc
, yc
);
1336 CalcBoundingBox (x2
, y2
);
1339 void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1341 gs_cairo
->cairo_save( m_cairo
);
1343 gs_cairo
->cairo_new_path(m_cairo
);
1345 gs_cairo
->cairo_translate( m_cairo
, XLOG2DEV((wxCoord
) (x
+ w
/ 2.)), XLOG2DEV((wxCoord
) (y
+ h
/ 2.)) );
1346 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1347 gs_cairo
->cairo_scale( m_cairo
, 1.0, scale
);
1349 gs_cairo
->cairo_arc_negative ( m_cairo
, 0, 0, XLOG2DEVREL(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1352 gs_cairo
->cairo_stroke_preserve( m_cairo
);
1354 gs_cairo
->cairo_line_to(m_cairo
, 0,0);
1356 SetBrush( m_brush
);
1357 gs_cairo
->cairo_fill( m_cairo
);
1359 gs_cairo
->cairo_restore( m_cairo
);
1361 CalcBoundingBox( x
, y
);
1362 CalcBoundingBox( x
+w
, y
+h
);
1365 void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x
, wxCoord y
)
1367 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1371 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1372 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1373 gs_cairo
->cairo_stroke ( m_cairo
);
1375 CalcBoundingBox( x
, y
);
1378 void wxGtkPrinterDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1380 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1387 for ( i
=0; i
<n
; i
++ )
1388 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1390 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1392 for (i
= 1; i
< n
; i
++)
1393 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1395 gs_cairo
->cairo_stroke ( m_cairo
);
1398 void wxGtkPrinterDCImpl::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1402 gs_cairo
->cairo_save(m_cairo
);
1403 if (fillStyle
== wxWINDING_RULE
)
1404 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1406 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1408 int x
= points
[0].x
+ xoffset
;
1409 int y
= points
[0].y
+ yoffset
;
1410 gs_cairo
->cairo_new_path(m_cairo
);
1411 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1413 for (i
= 1; i
< n
; i
++)
1415 int x
= points
[i
].x
+ xoffset
;
1416 int y
= points
[i
].y
+ yoffset
;
1417 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1419 gs_cairo
->cairo_close_path(m_cairo
);
1421 SetBrush( m_brush
);
1422 gs_cairo
->cairo_fill_preserve( m_cairo
);
1425 gs_cairo
->cairo_stroke( m_cairo
);
1427 CalcBoundingBox( x
, y
);
1429 gs_cairo
->cairo_restore(m_cairo
);
1432 void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1434 wxDCImpl::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1437 void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1442 gs_cairo
->cairo_new_path(m_cairo
);
1443 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
1445 SetBrush( m_brush
);
1446 gs_cairo
->cairo_fill_preserve( m_cairo
);
1449 gs_cairo
->cairo_stroke( m_cairo
);
1451 CalcBoundingBox( x
, y
);
1452 CalcBoundingBox( x
+ width
, y
+ height
);
1455 void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1460 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1462 wxCoord dd
= 2 * (wxCoord
) radius
;
1463 if (dd
> width
) dd
= width
;
1464 if (dd
> height
) dd
= height
;
1467 wxCoord rad
= (wxCoord
) radius
;
1469 gs_cairo
->cairo_new_path(m_cairo
);
1470 gs_cairo
->cairo_move_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1471 gs_cairo
->cairo_curve_to(m_cairo
,
1472 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1473 XLOG2DEV(x
),YLOG2DEV(y
),
1474 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1475 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1476 gs_cairo
->cairo_curve_to(m_cairo
,
1477 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1478 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1479 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1480 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1481 gs_cairo
->cairo_curve_to(m_cairo
,
1482 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1483 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1484 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1485 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1486 gs_cairo
->cairo_curve_to(m_cairo
,
1487 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1488 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1489 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1490 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1491 gs_cairo
->cairo_close_path(m_cairo
);
1494 gs_cairo
->cairo_fill_preserve(m_cairo
);
1497 gs_cairo
->cairo_stroke(m_cairo
);
1499 CalcBoundingBox(x
,y
);
1500 CalcBoundingBox(x
+width
,y
+height
);
1503 void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1508 gs_cairo
->cairo_save (m_cairo
);
1510 gs_cairo
->cairo_new_path(m_cairo
);
1512 gs_cairo
->cairo_translate (m_cairo
, XLOG2DEV((wxCoord
) (x
+ width
/ 2.)), YLOG2DEV((wxCoord
) (y
+ height
/ 2.)));
1513 gs_cairo
->cairo_scale(m_cairo
, 1, (double)YLOG2DEVREL(height
)/(double)XLOG2DEVREL(width
));
1514 gs_cairo
->cairo_arc ( m_cairo
, 0, 0, XLOG2DEVREL(width
/2), 0, 2 * M_PI
);
1516 SetBrush( m_brush
);
1517 gs_cairo
->cairo_fill_preserve( m_cairo
);
1520 gs_cairo
->cairo_stroke( m_cairo
);
1522 CalcBoundingBox( x
, y
);
1523 CalcBoundingBox( x
+ width
, y
+ height
);
1525 gs_cairo
->cairo_restore (m_cairo
);
1529 void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList
*points
)
1533 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1536 wxPointList::compatibility_iterator node
= points
->GetFirst();
1537 p
= node
->GetData();
1541 node
= node
->GetNext();
1542 p
= node
->GetData();
1546 (double)(x1
+ c
) / 2;
1548 (double)(y1
+ d
) / 2;
1550 gs_cairo
->cairo_new_path( m_cairo
);
1551 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1552 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1554 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1555 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1557 node
= node
->GetNext();
1560 q
= node
->GetData();
1568 x3
= (double)(x2
+ c
) / 2;
1569 y3
= (double)(y2
+ d
) / 2;
1571 gs_cairo
->cairo_curve_to(m_cairo
,
1572 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1573 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1574 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1576 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1577 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1579 node
= node
->GetNext();
1582 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1584 gs_cairo
->cairo_stroke( m_cairo
);
1586 #endif // wxUSE_SPLINES
1588 bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest
, wxCoord ydest
,
1589 wxCoord width
, wxCoord height
,
1590 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1591 int rop
, bool useMask
,
1592 wxCoord
WXUNUSED_UNLESS_DEBUG(xsrcMask
),
1593 wxCoord
WXUNUSED_UNLESS_DEBUG(ysrcMask
))
1595 wxASSERT_MSG( xsrcMask
== wxDefaultCoord
&& ysrcMask
== wxDefaultCoord
,
1596 wxT("mask coordinates are not supported") );
1598 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1600 // Blit into a bitmap.
1601 wxBitmap
bitmap( width
, height
);
1603 memDC
.SelectObject(bitmap
);
1604 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1605 memDC
.SelectObject(wxNullBitmap
);
1607 // Draw bitmap. scaling and positioning is done there.
1608 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1613 void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1615 DoDrawBitmap( icon
, x
, y
, true );
1618 void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1620 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
1622 cairo_surface_t
* surface
;
1623 x
= wxCoord(XLOG2DEV(x
));
1624 y
= wxCoord(YLOG2DEV(y
));
1625 int bw
= bitmap
.GetWidth();
1626 int bh
= bitmap
.GetHeight();
1627 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1628 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1629 wxUint32
* data
= (wxUint32
*)buffer
;
1631 wxMask
*mask
= NULL
;
1632 if (useMask
) mask
= bmpSource
.GetMask();
1634 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1635 // then we'll use a different format and iterator than if it doesn't.
1636 if (bmpSource
.HasAlpha() || mask
)
1638 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1639 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1640 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1641 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1643 wxAlphaPixelData::Iterator
p(pixData
);
1645 for (y
=0; y
<bh
; y
++)
1647 wxAlphaPixelData::Iterator rowStart
= p
;
1648 for (x
=0; x
<bw
; x
++)
1650 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1651 // with alpha in the upper 8 bits, then red, then green, then
1652 // blue. The 32-bit quantities are stored native-endian.
1653 // Pre-multiplied alpha is used.
1654 unsigned char alpha
= p
.Alpha();
1656 if (!bmpSource
.HasAlpha() && mask
)
1662 *data
= ( alpha
<< 24
1663 | (p
.Red() * alpha
/255) << 16
1664 | (p
.Green() * alpha
/255) << 8
1665 | (p
.Blue() * alpha
/255) );
1670 p
.OffsetY(pixData
, 1);
1675 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1676 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1677 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1678 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1680 wxNativePixelData::Iterator
p(pixData
);
1682 for (y
=0; y
<bh
; y
++)
1684 wxNativePixelData::Iterator rowStart
= p
;
1685 for (x
=0; x
<bw
; x
++)
1687 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1688 // the upper 8 bits unused. Red, Green, and Blue are stored in
1689 // the remaining 24 bits in that order. The 32-bit quantities
1690 // are stored native-endian.
1691 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1696 p
.OffsetY(pixData
, 1);
1701 gs_cairo
->cairo_save(m_cairo
);
1703 // Prepare to draw the image.
1704 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1707 cairo_filter_t filter
= CAIRO_FILTER_BILINEAR
;
1708 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1709 cairo_pattern_set_filter(pattern
,filter
);
1710 wxDouble scaleX
= (wxDouble
) XLOG2DEVREL(bw
) / (wxDouble
) bw
;
1711 wxDouble scaleY
= (wxDouble
) YLOG2DEVREL(bh
) / (wxDouble
) bh
;
1712 cairo_scale(m_cairo
, scaleX
, scaleY
);
1714 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
1715 // Use the original size here since the context is scaled already.
1716 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1717 // Fill the rectangle using the pattern.
1718 gs_cairo
->cairo_fill(m_cairo
);
1721 gs_cairo
->cairo_pattern_destroy(pattern
);
1722 gs_cairo
->cairo_surface_destroy(surface
);
1725 CalcBoundingBox(0,0);
1726 CalcBoundingBox(bw
,bh
);
1728 gs_cairo
->cairo_restore(m_cairo
);
1731 void wxGtkPrinterDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1733 DoDrawRotatedText( text
, x
, y
, 0.0 );
1736 void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1738 double xx
= XLOG2DEV(x
);
1739 double yy
= YLOG2DEV(y
);
1743 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1745 const wxUTF8Buf data
= text
.utf8_str();
1747 size_t datalen
= strlen(data
);
1748 pango_layout_set_text( m_layout
, data
, datalen
);
1752 PangoAttrList
*attrs
= pango_attr_list_new();
1753 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1755 a
->end_index
= datalen
;
1756 pango_attr_list_insert(attrs
, a
);
1757 pango_layout_set_attributes(m_layout
, attrs
);
1758 pango_attr_list_unref(attrs
);
1761 if (m_textForegroundColour
.Ok())
1763 unsigned char red
= m_textForegroundColour
.Red();
1764 unsigned char blue
= m_textForegroundColour
.Blue();
1765 unsigned char green
= m_textForegroundColour
.Green();
1766 unsigned char alpha
= m_textForegroundColour
.Alpha();
1768 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1770 double redPS
= (double)(red
) / 255.0;
1771 double bluePS
= (double)(blue
) / 255.0;
1772 double greenPS
= (double)(green
) / 255.0;
1773 double alphaPS
= (double)(alpha
) / 255.0;
1775 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1778 m_currentBlue
= blue
;
1779 m_currentGreen
= green
;
1780 m_currentAlpha
= alpha
;
1786 // Scale font description.
1787 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1788 double size
= oldSize
;
1789 size
= size
* m_scaleX
;
1790 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1792 // Actually apply scaled font.
1793 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1795 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1797 if ( m_backgroundMode
== wxSOLID
)
1799 unsigned char red
= m_textBackgroundColour
.Red();
1800 unsigned char blue
= m_textBackgroundColour
.Blue();
1801 unsigned char green
= m_textBackgroundColour
.Green();
1802 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1804 double redPS
= (double)(red
) / 255.0;
1805 double bluePS
= (double)(blue
) / 255.0;
1806 double greenPS
= (double)(green
) / 255.0;
1807 double alphaPS
= (double)(alpha
) / 255.0;
1809 gs_cairo
->cairo_save(m_cairo
);
1810 gs_cairo
->cairo_translate(m_cairo
, xx
, yy
);
1811 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1812 gs_cairo
->cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1813 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1814 gs_cairo
->cairo_fill(m_cairo
);
1815 gs_cairo
->cairo_restore(m_cairo
);
1819 gs_cairo
->cairo_move_to (m_cairo
, xx
, yy
);
1821 gs_cairo
->cairo_save( m_cairo
);
1823 if (fabs(angle
) > 0.00001)
1824 gs_cairo
->cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1826 gs_cairo
->pango_cairo_update_layout (m_cairo
, m_layout
);
1827 gs_cairo
->pango_cairo_show_layout (m_cairo
, m_layout
);
1829 gs_cairo
->cairo_restore( m_cairo
);
1833 // Undo underline attributes setting
1834 pango_layout_set_attributes(m_layout
, NULL
);
1837 // Reset unscaled size.
1838 pango_font_description_set_size( m_fontdesc
, oldSize
);
1840 // Actually apply unscaled font.
1841 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1843 // Back to device units:
1844 CalcBoundingBox (x
, y
);
1845 CalcBoundingBox (x
+ w
, y
+ h
);
1848 void wxGtkPrinterDCImpl::Clear()
1850 // Clear does nothing for printing, but keep the code
1853 gs_cairo->cairo_save(m_cairo);
1854 gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1855 SetBrush(m_backgroundBrush);
1856 gs_cairo->cairo_paint(m_cairo);
1857 gs_cairo->cairo_restore(m_cairo);
1861 void wxGtkPrinterDCImpl::SetFont( const wxFont
& font
)
1868 pango_font_description_free( m_fontdesc
);
1870 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
); // m_fontdesc is now set to device units
1872 // Scale font description from device units to pango units
1873 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1874 double size
= oldSize
*m_DEV2PS
; // scale to cairo units
1875 pango_font_description_set_size( m_fontdesc
, (gint
)size
); // apply to description
1877 // Actually apply scaled font.
1878 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1882 void wxGtkPrinterDCImpl::SetPen( const wxPen
& pen
)
1884 if (!pen
.Ok()) return;
1890 if (m_pen
.GetWidth() <= 0)
1893 width
= (double) m_pen
.GetWidth();
1895 gs_cairo
->cairo_set_line_width( m_cairo
, width
* m_DEV2PS
* m_scaleX
);
1896 static const double dotted
[] = {2.0, 5.0};
1897 static const double short_dashed
[] = {4.0, 4.0};
1898 static const double long_dashed
[] = {4.0, 8.0};
1899 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1901 switch (m_pen
.GetStyle())
1903 case wxDOT
: gs_cairo
->cairo_set_dash( m_cairo
, dotted
, 2, 0 ); break;
1904 case wxSHORT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, short_dashed
, 2, 0 ); break;
1905 case wxLONG_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, long_dashed
, 2, 0 ); break;
1906 case wxDOT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, dotted_dashed
, 4, 0 ); break;
1910 int num
= m_pen
.GetDashes (&wx_dashes
);
1911 gdouble
*g_dashes
= g_new( gdouble
, num
);
1913 for (i
= 0; i
< num
; ++i
)
1914 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1915 gs_cairo
->cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1921 default: gs_cairo
->cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
1924 switch (m_pen
.GetCap())
1926 case wxCAP_PROJECTING
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
1927 case wxCAP_BUTT
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
1929 default: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
1932 switch (m_pen
.GetJoin())
1934 case wxJOIN_BEVEL
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
1935 case wxJOIN_MITER
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
1937 default: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
1940 unsigned char red
= m_pen
.GetColour().Red();
1941 unsigned char blue
= m_pen
.GetColour().Blue();
1942 unsigned char green
= m_pen
.GetColour().Green();
1943 unsigned char alpha
= m_pen
.GetColour().Alpha();
1945 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1947 double redPS
= (double)(red
) / 255.0;
1948 double bluePS
= (double)(blue
) / 255.0;
1949 double greenPS
= (double)(green
) / 255.0;
1950 double alphaPS
= (double)(alpha
) / 255.0;
1952 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1955 m_currentBlue
= blue
;
1956 m_currentGreen
= green
;
1957 m_currentAlpha
= alpha
;
1961 void wxGtkPrinterDCImpl::SetBrush( const wxBrush
& brush
)
1963 if (!brush
.Ok()) return;
1967 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1969 gs_cairo
->cairo_set_source_rgba( m_cairo
, 0, 0, 0, 0 );
1978 unsigned char red
= m_brush
.GetColour().Red();
1979 unsigned char blue
= m_brush
.GetColour().Blue();
1980 unsigned char green
= m_brush
.GetColour().Green();
1981 unsigned char alpha
= m_brush
.GetColour().Alpha();
1983 double redPS
= (double)(red
) / 255.0;
1984 double bluePS
= (double)(blue
) / 255.0;
1985 double greenPS
= (double)(green
) / 255.0;
1986 double alphaPS
= (double)(alpha
) / 255.0;
1988 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1990 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1993 m_currentBlue
= blue
;
1994 m_currentGreen
= green
;
1995 m_currentAlpha
= alpha
;
1998 if (m_brush
.IsHatch())
2001 cairo_surface_t
*surface
;
2002 surface
= gs_cairo
->cairo_surface_create_similar(gs_cairo
->cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
2003 cr
= gs_cairo
->cairo_create(surface
);
2004 gs_cairo
->cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
2005 gs_cairo
->cairo_set_line_width(cr
, 1);
2006 gs_cairo
->cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
2008 switch (m_brush
.GetStyle())
2011 gs_cairo
->cairo_move_to(cr
, 5, 0);
2012 gs_cairo
->cairo_line_to(cr
, 5, 10);
2013 gs_cairo
->cairo_move_to(cr
, 0, 5);
2014 gs_cairo
->cairo_line_to(cr
, 10, 5);
2016 case wxBDIAGONAL_HATCH
:
2017 gs_cairo
->cairo_move_to(cr
, 0, 10);
2018 gs_cairo
->cairo_line_to(cr
, 10, 0);
2020 case wxFDIAGONAL_HATCH
:
2021 gs_cairo
->cairo_move_to(cr
, 0, 0);
2022 gs_cairo
->cairo_line_to(cr
, 10, 10);
2024 case wxCROSSDIAG_HATCH
:
2025 gs_cairo
->cairo_move_to(cr
, 0, 0);
2026 gs_cairo
->cairo_line_to(cr
, 10, 10);
2027 gs_cairo
->cairo_move_to(cr
, 10, 0);
2028 gs_cairo
->cairo_line_to(cr
, 0, 10);
2030 case wxHORIZONTAL_HATCH
:
2031 gs_cairo
->cairo_move_to(cr
, 0, 5);
2032 gs_cairo
->cairo_line_to(cr
, 10, 5);
2034 case wxVERTICAL_HATCH
:
2035 gs_cairo
->cairo_move_to(cr
, 5, 0);
2036 gs_cairo
->cairo_line_to(cr
, 5, 10);
2039 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
2042 gs_cairo
->cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
2043 gs_cairo
->cairo_stroke (cr
);
2045 gs_cairo
->cairo_destroy(cr
);
2046 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface (surface
);
2047 gs_cairo
->cairo_surface_destroy(surface
);
2048 gs_cairo
->cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
2049 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
2050 gs_cairo
->cairo_pattern_destroy(pattern
);
2054 void wxGtkPrinterDCImpl::SetLogicalFunction( int function
)
2056 if (function
== wxCLEAR
)
2057 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
2058 else if (function
== wxOR
)
2059 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
2060 else if (function
== wxNO_OP
)
2061 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
2062 else if (function
== wxAND
)
2063 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
2064 else if (function
== wxSET
)
2065 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
2066 else if (function
== wxXOR
)
2067 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
2068 else // wxCOPY or anything else.
2069 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
2072 void wxGtkPrinterDCImpl::SetBackground( const wxBrush
& brush
)
2074 m_backgroundBrush
= brush
;
2075 gs_cairo
->cairo_save(m_cairo
);
2076 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2078 SetBrush(m_backgroundBrush
);
2079 gs_cairo
->cairo_paint(m_cairo
);
2080 gs_cairo
->cairo_restore(m_cairo
);
2083 void wxGtkPrinterDCImpl::SetBackgroundMode(int mode
)
2085 if (mode
== wxSOLID
)
2086 m_backgroundMode
= wxSOLID
;
2088 m_backgroundMode
= wxTRANSPARENT
;
2091 void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2093 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2094 gs_cairo
->cairo_clip(m_cairo
);
2097 void wxGtkPrinterDCImpl::DestroyClippingRegion()
2099 gs_cairo
->cairo_reset_clip(m_cairo
);
2102 bool wxGtkPrinterDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
2107 void wxGtkPrinterDCImpl::EndDoc()
2112 void wxGtkPrinterDCImpl::StartPage()
2117 void wxGtkPrinterDCImpl::EndPage()
2122 wxCoord
wxGtkPrinterDCImpl::GetCharHeight() const
2124 pango_layout_set_text( m_layout
, "H", 1 );
2127 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2129 return wxRound( h
* m_PS2DEV
);
2132 wxCoord
wxGtkPrinterDCImpl::GetCharWidth() const
2134 pango_layout_set_text( m_layout
, "H", 1 );
2137 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2139 return wxRound( w
* m_PS2DEV
);
2142 void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2144 wxCoord
*externalLeading
,
2145 const wxFont
*theFont
) const
2153 if ( externalLeading
)
2154 *externalLeading
= 0;
2161 // Set layout's text
2162 const wxUTF8Buf dataUTF8
= string
.utf8_str();
2164 PangoFontDescription
*desc
= m_fontdesc
;
2165 if (theFont
) desc
= theFont
->GetNativeFontInfo()->description
;
2167 gint oldSize
= pango_font_description_get_size( desc
);
2168 double size
= oldSize
;
2169 size
= size
* m_scaleY
;
2170 pango_font_description_set_size( desc
, (gint
)size
);
2172 // apply scaled font
2173 pango_layout_set_font_description( m_layout
, desc
);
2175 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2178 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2181 *width
= wxRound( (double)w
/ m_scaleX
* m_PS2DEV
);
2183 *height
= wxRound( (double)h
/ m_scaleY
* m_PS2DEV
);
2187 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2188 int baseline
= pango_layout_iter_get_baseline(iter
);
2189 pango_layout_iter_free(iter
);
2190 *descent
= wxRound( (h
- PANGO_PIXELS(baseline
)) * m_PS2DEV
);
2193 // Reset unscaled size.
2194 pango_font_description_set_size( desc
, oldSize
);
2196 // Reset unscaled font.
2197 pango_layout_set_font_description( m_layout
, m_fontdesc
);
2200 void wxGtkPrinterDCImpl::DoGetSize(int* width
, int* height
) const
2202 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2205 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_POINTS
) * m_PS2DEV
);
2207 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_POINTS
) * m_PS2DEV
);
2210 void wxGtkPrinterDCImpl::DoGetSizeMM(int *width
, int *height
) const
2212 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2215 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_MM
) );
2217 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_MM
) );
2220 wxSize
wxGtkPrinterDCImpl::GetPPI() const
2222 return wxSize( (int)m_resolution
, (int)m_resolution
);
2225 void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData
& data
)
2230 // overriden for wxPrinterDC Impl
2232 wxRect
wxGtkPrinterDCImpl::GetPaperRect()
2234 // Does GtkPrint support printer margins?
2237 DoGetSize( &w
, &h
);
2238 return wxRect( 0,0,w
,h
);
2241 int wxGtkPrinterDCImpl::GetResolution()
2243 return m_resolution
;
2246 // ----------------------------------------------------------------------------
2248 // ----------------------------------------------------------------------------
2250 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2252 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2253 wxPrintout
* WXUNUSED(printoutForPrinting
))
2258 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2259 wxPrintout
*printoutForPrinting
,
2260 wxPrintDialogData
*data
)
2261 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2263 Init(printout
, printoutForPrinting
);
2266 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2267 wxPrintout
*printoutForPrinting
,
2269 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2271 Init(printout
, printoutForPrinting
);
2274 wxGtkPrintPreview::~wxGtkPrintPreview()
2278 bool wxGtkPrintPreview::Print(bool interactive
)
2280 if (!m_printPrintout
)
2283 wxPrinter
printer(& m_printDialogData
);
2284 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2287 void wxGtkPrintPreview::DetermineScaling()
2289 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2291 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2293 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2297 wxSize ScreenPixels
= wxGetDisplaySize();
2298 wxSize ScreenMM
= wxGetDisplaySizeMM();
2300 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2301 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2303 // TODO !!!!!!!!!!!!!!!
2304 int resolution
= 600;
2305 m_previewPrintout
->SetPPIPrinter( resolution
, resolution
);
2307 // Get width and height in points (1/72th of an inch)
2308 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2310 sizeDevUnits
.x
= wxRound((double)sizeDevUnits
.x
* (double)resolution
/ 72.0);
2311 sizeDevUnits
.y
= wxRound((double)sizeDevUnits
.y
* (double)resolution
/ 72.0);
2312 wxSize
sizeTenthsMM(paper
->GetSize());
2313 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2315 // If in landscape mode, we need to swap the width and height.
2316 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2318 m_pageWidth
= sizeDevUnits
.y
;
2319 m_pageHeight
= sizeDevUnits
.x
;
2320 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2324 m_pageWidth
= sizeDevUnits
.x
;
2325 m_pageHeight
= sizeDevUnits
.y
;
2326 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2328 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2329 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2331 // At 100%, the page should look about page-size on the screen.
2332 m_previewScaleX
= 0.8 * 72.0 / (double)resolution
;
2333 m_previewScaleY
= m_previewScaleX
;