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 wxDC
* wxGtkPrintFactory::CreatePrinterDC( const wxPrintData
& data
)
148 return new wxGtkPrintDC(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 wxGtkPrintDC
*printDC
= new wxGtkPrintDC( printdata
);
902 if (sm_lastError
!= wxPRINTER_CANCELLED
)
904 sm_lastError
= wxPRINTER_ERROR
;
905 wxFAIL_MSG(_("The wxGtkPrintDC 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();
1068 return new wxGtkPrintDC( m_printDialogData
.GetPrintData() );
1071 bool wxGtkPrinter::Setup( wxWindow
* WXUNUSED(parent
) )
1073 // Obsolete, for backward compatibility.
1077 //-----------------------------------------------------------------------------
1079 //-----------------------------------------------------------------------------
1081 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
1082 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
1083 #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
1084 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
1086 IMPLEMENT_CLASS(wxGtkPrintDC
, wxDC
)
1088 wxGtkPrintDC::wxGtkPrintDC( const wxPrintData
& data
)
1092 wxGtkPrintNativeData
*native
=
1093 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1095 m_gpc
= native
->GetPrintContext();
1097 // Match print quality to resolution (high = 1200dpi)
1098 m_resolution
= m_printData
.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
1099 if (m_resolution
< 0)
1100 m_resolution
= (1 << (m_resolution
+4)) *150;
1102 m_PS2DEV
= (double)m_resolution
/ 72.0;
1103 m_DEV2PS
= 72.0 / (double)m_resolution
;
1105 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1106 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1107 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1109 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1115 m_signX
= 1; // default x-axis left to right.
1116 m_signY
= 1; // default y-axis bottom up -> top down.
1118 // By default the origin of the Cairo context is in the upper left
1119 // corner of the printable area. We need to translate it so that it
1120 // is in the upper left corner of the paper (without margins)
1121 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
1123 ml
= gtk_page_setup_get_left_margin (setup
, GTK_UNIT_POINTS
);
1124 mt
= gtk_page_setup_get_top_margin (setup
, GTK_UNIT_POINTS
);
1125 gs_cairo
->cairo_translate(m_cairo
, -ml
, -mt
);
1128 wxGtkPrintDC::~wxGtkPrintDC()
1130 g_object_unref(m_context
);
1131 g_object_unref(m_layout
);
1134 bool wxGtkPrintDC::IsOk() const
1136 return m_gpc
!= NULL
;
1139 bool wxGtkPrintDC::DoFloodFill(wxCoord
WXUNUSED(x1
),
1140 wxCoord
WXUNUSED(y1
),
1141 const wxColour
& WXUNUSED(col
),
1142 int WXUNUSED(style
))
1144 // We can't access the given coord as a Cairo context is scalable, ie a
1145 // coord doesn't mean anything in this context.
1146 wxFAIL_MSG(_("not implemented"));
1150 void wxGtkPrintDC::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1152 wxCoord xC
= circleCenter
.x
;
1153 wxCoord yC
= circleCenter
.y
;
1154 wxCoord xR
= rect
.x
;
1155 wxCoord yR
= rect
.y
;
1156 wxCoord w
= rect
.width
;
1157 wxCoord h
= rect
.height
;
1159 double radius
= sqrt((w
/2)*(w
/2)+(h
/2)*(h
/2));
1161 unsigned char redI
= initialColour
.Red();
1162 unsigned char blueI
= initialColour
.Blue();
1163 unsigned char greenI
= initialColour
.Green();
1164 unsigned char alphaI
= initialColour
.Alpha();
1165 unsigned char redD
= destColour
.Red();
1166 unsigned char blueD
= destColour
.Blue();
1167 unsigned char greenD
= destColour
.Green();
1168 unsigned char alphaD
= destColour
.Alpha();
1170 double redIPS
= (double)(redI
) / 255.0;
1171 double blueIPS
= (double)(blueI
) / 255.0;
1172 double greenIPS
= (double)(greenI
) / 255.0;
1173 double alphaIPS
= (double)(alphaI
) / 255.0;
1174 double redDPS
= (double)(redD
) / 255.0;
1175 double blueDPS
= (double)(blueD
) / 255.0;
1176 double greenDPS
= (double)(greenD
) / 255.0;
1177 double alphaDPS
= (double)(alphaD
) / 255.0;
1179 // Create a pattern with the gradient.
1180 cairo_pattern_t
* gradient
;
1181 gradient
= gs_cairo
->cairo_pattern_create_radial (XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), 0, XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), radius
* m_DEV2PS
);
1182 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1183 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1185 // Fill the rectangle with this pattern.
1186 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1187 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(xR
), YLOG2DEV(yR
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1188 gs_cairo
->cairo_fill(m_cairo
);
1190 gs_cairo
->cairo_pattern_destroy(gradient
);
1192 CalcBoundingBox(xR
, yR
);
1193 CalcBoundingBox(xR
+w
, yR
+h
);
1196 void wxGtkPrintDC::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1200 wxCoord w
= rect
.width
;
1201 wxCoord h
= rect
.height
;
1203 unsigned char redI
= initialColour
.Red();
1204 unsigned char blueI
= initialColour
.Blue();
1205 unsigned char greenI
= initialColour
.Green();
1206 unsigned char alphaI
= initialColour
.Alpha();
1207 unsigned char redD
= destColour
.Red();
1208 unsigned char blueD
= destColour
.Blue();
1209 unsigned char greenD
= destColour
.Green();
1210 unsigned char alphaD
= destColour
.Alpha();
1212 double redIPS
= (double)(redI
) / 255.0;
1213 double blueIPS
= (double)(blueI
) / 255.0;
1214 double greenIPS
= (double)(greenI
) / 255.0;
1215 double alphaIPS
= (double)(alphaI
) / 255.0;
1216 double redDPS
= (double)(redD
) / 255.0;
1217 double blueDPS
= (double)(blueD
) / 255.0;
1218 double greenDPS
= (double)(greenD
) / 255.0;
1219 double alphaDPS
= (double)(alphaD
) / 255.0;
1221 // Create a pattern with the gradient.
1222 cairo_pattern_t
* gradient
;
1223 gradient
= gs_cairo
->cairo_pattern_create_linear (XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x
+w
), YLOG2DEV(y
));
1225 if (nDirection
== wxWEST
)
1227 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1228 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1231 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1232 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1235 // Fill the rectangle with this pattern.
1236 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1237 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1238 gs_cairo
->cairo_fill(m_cairo
);
1240 gs_cairo
->cairo_pattern_destroy(gradient
);
1242 CalcBoundingBox(x
, y
);
1243 CalcBoundingBox(x
+w
, y
+h
);
1246 bool wxGtkPrintDC::DoGetPixel(wxCoord
WXUNUSED(x1
),
1247 wxCoord
WXUNUSED(y1
),
1248 wxColour
* WXUNUSED(col
)) const
1250 wxFAIL_MSG(_("not implemented"));
1254 void wxGtkPrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1256 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1259 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1260 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1261 gs_cairo
->cairo_stroke ( m_cairo
);
1263 CalcBoundingBox( x1
, y1
);
1264 CalcBoundingBox( x2
, y2
);
1267 void wxGtkPrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
1274 gs_cairo
->cairo_move_to (m_cairo
, XLOG2DEV(x
), 0);
1275 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEV(x
), YLOG2DEVREL(h
));
1276 gs_cairo
->cairo_move_to (m_cairo
, 0, YLOG2DEV(y
));
1277 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEVREL(w
), YLOG2DEV(y
));
1279 gs_cairo
->cairo_stroke (m_cairo
);
1280 CalcBoundingBox( 0, 0 );
1281 CalcBoundingBox( w
, h
);
1284 void wxGtkPrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1286 double dx
= x1
- xc
;
1287 double dy
= y1
- yc
;
1288 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1290 double alpha1
, alpha2
;
1291 if (x1
== x2
&& y1
== y2
)
1299 alpha1
= alpha2
= 0.0;
1303 alpha1
= (x1
- xc
== 0) ?
1304 (y1
- yc
< 0) ? 90.0 : -90.0 :
1305 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1306 alpha2
= (x2
- xc
== 0) ?
1307 (y2
- yc
< 0) ? 90.0 : -90.0 :
1308 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1310 while (alpha1
<= 0) alpha1
+= 360;
1311 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1312 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1313 while (alpha2
> 360) alpha2
-= 360;
1319 gs_cairo
->cairo_new_path(m_cairo
);
1321 gs_cairo
->cairo_arc_negative ( m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
);
1322 gs_cairo
->cairo_line_to(m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
));
1323 gs_cairo
->cairo_close_path (m_cairo
);
1325 SetBrush( m_brush
);
1326 gs_cairo
->cairo_fill_preserve( m_cairo
);
1329 gs_cairo
->cairo_stroke( m_cairo
);
1331 CalcBoundingBox (x1
, y1
);
1332 CalcBoundingBox (xc
, yc
);
1333 CalcBoundingBox (x2
, y2
);
1336 void wxGtkPrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1338 gs_cairo
->cairo_save( m_cairo
);
1340 gs_cairo
->cairo_new_path(m_cairo
);
1342 gs_cairo
->cairo_translate( m_cairo
, XLOG2DEV((wxCoord
) (x
+ w
/ 2.)), XLOG2DEV((wxCoord
) (y
+ h
/ 2.)) );
1343 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1344 gs_cairo
->cairo_scale( m_cairo
, 1.0, scale
);
1346 gs_cairo
->cairo_arc_negative ( m_cairo
, 0, 0, XLOG2DEVREL(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1349 gs_cairo
->cairo_stroke_preserve( m_cairo
);
1351 gs_cairo
->cairo_line_to(m_cairo
, 0,0);
1353 SetBrush( m_brush
);
1354 gs_cairo
->cairo_fill( m_cairo
);
1356 gs_cairo
->cairo_restore( m_cairo
);
1358 CalcBoundingBox( x
, y
);
1359 CalcBoundingBox( x
+w
, y
+h
);
1362 void wxGtkPrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
1364 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1368 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1369 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1370 gs_cairo
->cairo_stroke ( m_cairo
);
1372 CalcBoundingBox( x
, y
);
1375 void wxGtkPrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1377 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1384 for ( i
=0; i
<n
; i
++ )
1385 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1387 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1389 for (i
= 1; i
< n
; i
++)
1390 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1392 gs_cairo
->cairo_stroke ( m_cairo
);
1395 void wxGtkPrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1399 gs_cairo
->cairo_save(m_cairo
);
1400 if (fillStyle
== wxWINDING_RULE
)
1401 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1403 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1405 int x
= points
[0].x
+ xoffset
;
1406 int y
= points
[0].y
+ yoffset
;
1407 gs_cairo
->cairo_new_path(m_cairo
);
1408 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1410 for (i
= 1; i
< n
; i
++)
1412 int x
= points
[i
].x
+ xoffset
;
1413 int y
= points
[i
].y
+ yoffset
;
1414 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1416 gs_cairo
->cairo_close_path(m_cairo
);
1418 SetBrush( m_brush
);
1419 gs_cairo
->cairo_fill_preserve( m_cairo
);
1422 gs_cairo
->cairo_stroke( m_cairo
);
1424 CalcBoundingBox( x
, y
);
1426 gs_cairo
->cairo_restore(m_cairo
);
1429 void wxGtkPrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1431 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1434 void wxGtkPrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1439 gs_cairo
->cairo_new_path(m_cairo
);
1440 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
1442 SetBrush( m_brush
);
1443 gs_cairo
->cairo_fill_preserve( m_cairo
);
1446 gs_cairo
->cairo_stroke( m_cairo
);
1448 CalcBoundingBox( x
, y
);
1449 CalcBoundingBox( x
+ width
, y
+ height
);
1452 void wxGtkPrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1457 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1459 wxCoord dd
= 2 * (wxCoord
) radius
;
1460 if (dd
> width
) dd
= width
;
1461 if (dd
> height
) dd
= height
;
1464 wxCoord rad
= (wxCoord
) radius
;
1466 gs_cairo
->cairo_new_path(m_cairo
);
1467 gs_cairo
->cairo_move_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1468 gs_cairo
->cairo_curve_to(m_cairo
,
1469 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1470 XLOG2DEV(x
),YLOG2DEV(y
),
1471 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1472 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1473 gs_cairo
->cairo_curve_to(m_cairo
,
1474 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1475 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1476 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1477 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1478 gs_cairo
->cairo_curve_to(m_cairo
,
1479 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1480 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1481 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1482 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1483 gs_cairo
->cairo_curve_to(m_cairo
,
1484 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1485 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1486 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1487 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1488 gs_cairo
->cairo_close_path(m_cairo
);
1491 gs_cairo
->cairo_fill_preserve(m_cairo
);
1494 gs_cairo
->cairo_stroke(m_cairo
);
1496 CalcBoundingBox(x
,y
);
1497 CalcBoundingBox(x
+width
,y
+height
);
1500 void wxGtkPrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1505 gs_cairo
->cairo_save (m_cairo
);
1507 gs_cairo
->cairo_new_path(m_cairo
);
1509 gs_cairo
->cairo_translate (m_cairo
, XLOG2DEV((wxCoord
) (x
+ width
/ 2.)), YLOG2DEV((wxCoord
) (y
+ height
/ 2.)));
1510 gs_cairo
->cairo_scale(m_cairo
, 1, (double)YLOG2DEVREL(height
)/(double)XLOG2DEVREL(width
));
1511 gs_cairo
->cairo_arc ( m_cairo
, 0, 0, XLOG2DEVREL(width
/2), 0, 2 * M_PI
);
1513 SetBrush( m_brush
);
1514 gs_cairo
->cairo_fill_preserve( m_cairo
);
1517 gs_cairo
->cairo_stroke( m_cairo
);
1519 CalcBoundingBox( x
, y
);
1520 CalcBoundingBox( x
+ width
, y
+ height
);
1522 gs_cairo
->cairo_restore (m_cairo
);
1526 void wxGtkPrintDC::DoDrawSpline(const wxPointList
*points
)
1530 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1533 wxPointList::compatibility_iterator node
= points
->GetFirst();
1534 p
= node
->GetData();
1538 node
= node
->GetNext();
1539 p
= node
->GetData();
1543 (double)(x1
+ c
) / 2;
1545 (double)(y1
+ d
) / 2;
1547 gs_cairo
->cairo_new_path( m_cairo
);
1548 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1549 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1551 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1552 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1554 node
= node
->GetNext();
1557 q
= node
->GetData();
1565 x3
= (double)(x2
+ c
) / 2;
1566 y3
= (double)(y2
+ d
) / 2;
1568 gs_cairo
->cairo_curve_to(m_cairo
,
1569 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1570 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1571 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1573 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1574 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1576 node
= node
->GetNext();
1579 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1581 gs_cairo
->cairo_stroke( m_cairo
);
1583 #endif // wxUSE_SPLINES
1585 bool wxGtkPrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
,
1586 wxCoord width
, wxCoord height
,
1587 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1588 int rop
, bool useMask
,
1589 wxCoord
WXUNUSED_UNLESS_DEBUG(xsrcMask
),
1590 wxCoord
WXUNUSED_UNLESS_DEBUG(ysrcMask
))
1592 wxASSERT_MSG( xsrcMask
== wxDefaultCoord
&& ysrcMask
== wxDefaultCoord
,
1593 wxT("mask coordinates are not supported") );
1595 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1597 // Blit into a bitmap.
1598 wxBitmap
bitmap( width
, height
);
1600 memDC
.SelectObject(bitmap
);
1601 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1602 memDC
.SelectObject(wxNullBitmap
);
1604 // Draw bitmap. scaling and positioning is done there.
1605 DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1610 void wxGtkPrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1612 DoDrawBitmap( icon
, x
, y
, true );
1615 void wxGtkPrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1617 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrintDC::DoDrawBitmap"));
1619 cairo_surface_t
* surface
;
1620 x
= wxCoord(XLOG2DEV(x
));
1621 y
= wxCoord(YLOG2DEV(y
));
1622 int bw
= bitmap
.GetWidth();
1623 int bh
= bitmap
.GetHeight();
1624 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1625 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1626 wxUint32
* data
= (wxUint32
*)buffer
;
1628 wxMask
*mask
= NULL
;
1629 if (useMask
) mask
= bmpSource
.GetMask();
1631 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1632 // then we'll use a different format and iterator than if it doesn't.
1633 if (bmpSource
.HasAlpha() || mask
)
1635 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1636 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1637 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1638 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1640 wxAlphaPixelData::Iterator
p(pixData
);
1642 for (y
=0; y
<bh
; y
++)
1644 wxAlphaPixelData::Iterator rowStart
= p
;
1645 for (x
=0; x
<bw
; x
++)
1647 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1648 // with alpha in the upper 8 bits, then red, then green, then
1649 // blue. The 32-bit quantities are stored native-endian.
1650 // Pre-multiplied alpha is used.
1651 unsigned char alpha
= p
.Alpha();
1653 if (!bmpSource
.HasAlpha() && mask
)
1659 *data
= ( alpha
<< 24
1660 | (p
.Red() * alpha
/255) << 16
1661 | (p
.Green() * alpha
/255) << 8
1662 | (p
.Blue() * alpha
/255) );
1667 p
.OffsetY(pixData
, 1);
1672 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1673 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1674 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1675 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1677 wxNativePixelData::Iterator
p(pixData
);
1679 for (y
=0; y
<bh
; y
++)
1681 wxNativePixelData::Iterator rowStart
= p
;
1682 for (x
=0; x
<bw
; x
++)
1684 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1685 // the upper 8 bits unused. Red, Green, and Blue are stored in
1686 // the remaining 24 bits in that order. The 32-bit quantities
1687 // are stored native-endian.
1688 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1693 p
.OffsetY(pixData
, 1);
1698 gs_cairo
->cairo_save(m_cairo
);
1700 // Prepare to draw the image.
1701 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1704 cairo_filter_t filter
= CAIRO_FILTER_BILINEAR
;
1705 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1706 cairo_pattern_set_filter(pattern
,filter
);
1707 wxDouble scaleX
= (wxDouble
) XLOG2DEVREL(bw
) / (wxDouble
) bw
;
1708 wxDouble scaleY
= (wxDouble
) YLOG2DEVREL(bh
) / (wxDouble
) bh
;
1709 cairo_scale(m_cairo
, scaleX
, scaleY
);
1711 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
1712 // Use the original size here since the context is scaled already.
1713 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1714 // Fill the rectangle using the pattern.
1715 gs_cairo
->cairo_fill(m_cairo
);
1718 gs_cairo
->cairo_pattern_destroy(pattern
);
1719 gs_cairo
->cairo_surface_destroy(surface
);
1722 CalcBoundingBox(0,0);
1723 CalcBoundingBox(bw
,bh
);
1725 gs_cairo
->cairo_restore(m_cairo
);
1728 void wxGtkPrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1730 DoDrawRotatedText( text
, x
, y
, 0.0 );
1733 void wxGtkPrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1735 double xx
= XLOG2DEV(x
);
1736 double yy
= YLOG2DEV(y
);
1740 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1742 const wxUTF8Buf data
= text
.utf8_str();
1744 size_t datalen
= strlen(data
);
1745 pango_layout_set_text( m_layout
, data
, datalen
);
1749 PangoAttrList
*attrs
= pango_attr_list_new();
1750 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1752 a
->end_index
= datalen
;
1753 pango_attr_list_insert(attrs
, a
);
1754 pango_layout_set_attributes(m_layout
, attrs
);
1755 pango_attr_list_unref(attrs
);
1758 if (m_textForegroundColour
.Ok())
1760 unsigned char red
= m_textForegroundColour
.Red();
1761 unsigned char blue
= m_textForegroundColour
.Blue();
1762 unsigned char green
= m_textForegroundColour
.Green();
1763 unsigned char alpha
= m_textForegroundColour
.Alpha();
1765 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1767 double redPS
= (double)(red
) / 255.0;
1768 double bluePS
= (double)(blue
) / 255.0;
1769 double greenPS
= (double)(green
) / 255.0;
1770 double alphaPS
= (double)(alpha
) / 255.0;
1772 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1775 m_currentBlue
= blue
;
1776 m_currentGreen
= green
;
1777 m_currentAlpha
= alpha
;
1783 // Scale font description.
1784 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1785 double size
= oldSize
;
1786 size
= size
* m_scaleX
;
1787 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1789 // Actually apply scaled font.
1790 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1792 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1794 if ( m_backgroundMode
== wxSOLID
)
1796 unsigned char red
= m_textBackgroundColour
.Red();
1797 unsigned char blue
= m_textBackgroundColour
.Blue();
1798 unsigned char green
= m_textBackgroundColour
.Green();
1799 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1801 double redPS
= (double)(red
) / 255.0;
1802 double bluePS
= (double)(blue
) / 255.0;
1803 double greenPS
= (double)(green
) / 255.0;
1804 double alphaPS
= (double)(alpha
) / 255.0;
1806 gs_cairo
->cairo_save(m_cairo
);
1807 gs_cairo
->cairo_translate(m_cairo
, xx
, yy
);
1808 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1809 gs_cairo
->cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1810 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1811 gs_cairo
->cairo_fill(m_cairo
);
1812 gs_cairo
->cairo_restore(m_cairo
);
1816 gs_cairo
->cairo_move_to (m_cairo
, xx
, yy
);
1818 gs_cairo
->cairo_save( m_cairo
);
1820 if (fabs(angle
) > 0.00001)
1821 gs_cairo
->cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1823 gs_cairo
->pango_cairo_update_layout (m_cairo
, m_layout
);
1824 gs_cairo
->pango_cairo_show_layout (m_cairo
, m_layout
);
1826 gs_cairo
->cairo_restore( m_cairo
);
1830 // Undo underline attributes setting
1831 pango_layout_set_attributes(m_layout
, NULL
);
1834 // Reset unscaled size.
1835 pango_font_description_set_size( m_fontdesc
, oldSize
);
1837 // Actually apply unscaled font.
1838 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1840 // Back to device units:
1841 CalcBoundingBox (x
, y
);
1842 CalcBoundingBox (x
+ w
, y
+ h
);
1845 void wxGtkPrintDC::Clear()
1847 // Clear does nothing for printing, but keep the code
1850 gs_cairo->cairo_save(m_cairo);
1851 gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1852 SetBrush(m_backgroundBrush);
1853 gs_cairo->cairo_paint(m_cairo);
1854 gs_cairo->cairo_restore(m_cairo);
1858 void wxGtkPrintDC::SetFont( const wxFont
& font
)
1865 pango_font_description_free( m_fontdesc
);
1867 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
); // m_fontdesc is now set to device units
1869 // Scale font description from device units to pango units
1870 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1871 double size
= oldSize
*m_DEV2PS
; // scale to cairo units
1872 pango_font_description_set_size( m_fontdesc
, (gint
)size
); // apply to description
1874 // Actually apply scaled font.
1875 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1879 void wxGtkPrintDC::SetPen( const wxPen
& pen
)
1881 if (!pen
.Ok()) return;
1887 if (m_pen
.GetWidth() <= 0)
1890 width
= (double) m_pen
.GetWidth();
1892 gs_cairo
->cairo_set_line_width( m_cairo
, width
* m_DEV2PS
* m_scaleX
);
1893 static const double dotted
[] = {2.0, 5.0};
1894 static const double short_dashed
[] = {4.0, 4.0};
1895 static const double long_dashed
[] = {4.0, 8.0};
1896 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1898 switch (m_pen
.GetStyle())
1900 case wxDOT
: gs_cairo
->cairo_set_dash( m_cairo
, dotted
, 2, 0 ); break;
1901 case wxSHORT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, short_dashed
, 2, 0 ); break;
1902 case wxLONG_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, long_dashed
, 2, 0 ); break;
1903 case wxDOT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, dotted_dashed
, 4, 0 ); break;
1907 int num
= m_pen
.GetDashes (&wx_dashes
);
1908 gdouble
*g_dashes
= g_new( gdouble
, num
);
1910 for (i
= 0; i
< num
; ++i
)
1911 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1912 gs_cairo
->cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1918 default: gs_cairo
->cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
1921 switch (m_pen
.GetCap())
1923 case wxCAP_PROJECTING
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
1924 case wxCAP_BUTT
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
1926 default: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
1929 switch (m_pen
.GetJoin())
1931 case wxJOIN_BEVEL
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
1932 case wxJOIN_MITER
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
1934 default: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
1937 unsigned char red
= m_pen
.GetColour().Red();
1938 unsigned char blue
= m_pen
.GetColour().Blue();
1939 unsigned char green
= m_pen
.GetColour().Green();
1940 unsigned char alpha
= m_pen
.GetColour().Alpha();
1942 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1944 double redPS
= (double)(red
) / 255.0;
1945 double bluePS
= (double)(blue
) / 255.0;
1946 double greenPS
= (double)(green
) / 255.0;
1947 double alphaPS
= (double)(alpha
) / 255.0;
1949 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1952 m_currentBlue
= blue
;
1953 m_currentGreen
= green
;
1954 m_currentAlpha
= alpha
;
1958 void wxGtkPrintDC::SetBrush( const wxBrush
& brush
)
1960 if (!brush
.Ok()) return;
1964 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1966 gs_cairo
->cairo_set_source_rgba( m_cairo
, 0, 0, 0, 0 );
1975 unsigned char red
= m_brush
.GetColour().Red();
1976 unsigned char blue
= m_brush
.GetColour().Blue();
1977 unsigned char green
= m_brush
.GetColour().Green();
1978 unsigned char alpha
= m_brush
.GetColour().Alpha();
1980 double redPS
= (double)(red
) / 255.0;
1981 double bluePS
= (double)(blue
) / 255.0;
1982 double greenPS
= (double)(green
) / 255.0;
1983 double alphaPS
= (double)(alpha
) / 255.0;
1985 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1987 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1990 m_currentBlue
= blue
;
1991 m_currentGreen
= green
;
1992 m_currentAlpha
= alpha
;
1995 if (m_brush
.IsHatch())
1998 cairo_surface_t
*surface
;
1999 surface
= gs_cairo
->cairo_surface_create_similar(gs_cairo
->cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
2000 cr
= gs_cairo
->cairo_create(surface
);
2001 gs_cairo
->cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
2002 gs_cairo
->cairo_set_line_width(cr
, 1);
2003 gs_cairo
->cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
2005 switch (m_brush
.GetStyle())
2008 gs_cairo
->cairo_move_to(cr
, 5, 0);
2009 gs_cairo
->cairo_line_to(cr
, 5, 10);
2010 gs_cairo
->cairo_move_to(cr
, 0, 5);
2011 gs_cairo
->cairo_line_to(cr
, 10, 5);
2013 case wxBDIAGONAL_HATCH
:
2014 gs_cairo
->cairo_move_to(cr
, 0, 10);
2015 gs_cairo
->cairo_line_to(cr
, 10, 0);
2017 case wxFDIAGONAL_HATCH
:
2018 gs_cairo
->cairo_move_to(cr
, 0, 0);
2019 gs_cairo
->cairo_line_to(cr
, 10, 10);
2021 case wxCROSSDIAG_HATCH
:
2022 gs_cairo
->cairo_move_to(cr
, 0, 0);
2023 gs_cairo
->cairo_line_to(cr
, 10, 10);
2024 gs_cairo
->cairo_move_to(cr
, 10, 0);
2025 gs_cairo
->cairo_line_to(cr
, 0, 10);
2027 case wxHORIZONTAL_HATCH
:
2028 gs_cairo
->cairo_move_to(cr
, 0, 5);
2029 gs_cairo
->cairo_line_to(cr
, 10, 5);
2031 case wxVERTICAL_HATCH
:
2032 gs_cairo
->cairo_move_to(cr
, 5, 0);
2033 gs_cairo
->cairo_line_to(cr
, 5, 10);
2036 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
2039 gs_cairo
->cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
2040 gs_cairo
->cairo_stroke (cr
);
2042 gs_cairo
->cairo_destroy(cr
);
2043 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface (surface
);
2044 gs_cairo
->cairo_surface_destroy(surface
);
2045 gs_cairo
->cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
2046 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
2047 gs_cairo
->cairo_pattern_destroy(pattern
);
2051 void wxGtkPrintDC::SetLogicalFunction( int function
)
2053 if (function
== wxCLEAR
)
2054 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
2055 else if (function
== wxOR
)
2056 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
2057 else if (function
== wxNO_OP
)
2058 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
2059 else if (function
== wxAND
)
2060 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
2061 else if (function
== wxSET
)
2062 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
2063 else if (function
== wxXOR
)
2064 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
2065 else // wxCOPY or anything else.
2066 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
2069 void wxGtkPrintDC::SetBackground( const wxBrush
& brush
)
2071 m_backgroundBrush
= brush
;
2072 gs_cairo
->cairo_save(m_cairo
);
2073 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2075 SetBrush(m_backgroundBrush
);
2076 gs_cairo
->cairo_paint(m_cairo
);
2077 gs_cairo
->cairo_restore(m_cairo
);
2080 void wxGtkPrintDC::SetBackgroundMode(int mode
)
2082 if (mode
== wxSOLID
)
2083 m_backgroundMode
= wxSOLID
;
2085 m_backgroundMode
= wxTRANSPARENT
;
2088 void wxGtkPrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2090 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2091 gs_cairo
->cairo_clip(m_cairo
);
2094 void wxGtkPrintDC::DestroyClippingRegion()
2096 gs_cairo
->cairo_reset_clip(m_cairo
);
2099 bool wxGtkPrintDC::StartDoc(const wxString
& WXUNUSED(message
))
2104 void wxGtkPrintDC::EndDoc()
2109 void wxGtkPrintDC::StartPage()
2114 void wxGtkPrintDC::EndPage()
2119 wxCoord
wxGtkPrintDC::GetCharHeight() const
2121 pango_layout_set_text( m_layout
, "H", 1 );
2124 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2126 return wxRound( h
* m_PS2DEV
);
2129 wxCoord
wxGtkPrintDC::GetCharWidth() const
2131 pango_layout_set_text( m_layout
, "H", 1 );
2134 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2136 return wxRound( w
* m_PS2DEV
);
2139 void wxGtkPrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2141 wxCoord
*externalLeading
,
2142 const wxFont
*theFont
) const
2150 if ( externalLeading
)
2151 *externalLeading
= 0;
2158 // Set layout's text
2159 const wxUTF8Buf dataUTF8
= string
.utf8_str();
2161 PangoFontDescription
*desc
= m_fontdesc
;
2162 if (theFont
) desc
= theFont
->GetNativeFontInfo()->description
;
2164 gint oldSize
= pango_font_description_get_size( desc
);
2165 double size
= oldSize
;
2166 size
= size
* m_scaleY
;
2167 pango_font_description_set_size( desc
, (gint
)size
);
2169 // apply scaled font
2170 pango_layout_set_font_description( m_layout
, desc
);
2172 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2175 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2178 *width
= wxRound( (double)w
/ m_scaleX
* m_PS2DEV
);
2180 *height
= wxRound( (double)h
/ m_scaleY
* m_PS2DEV
);
2184 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2185 int baseline
= pango_layout_iter_get_baseline(iter
);
2186 pango_layout_iter_free(iter
);
2187 *descent
= wxRound( (h
- PANGO_PIXELS(baseline
)) * m_PS2DEV
);
2190 // Reset unscaled size.
2191 pango_font_description_set_size( desc
, oldSize
);
2193 // Reset unscaled font.
2194 pango_layout_set_font_description( m_layout
, m_fontdesc
);
2197 void wxGtkPrintDC::DoGetSize(int* width
, int* height
) const
2199 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2202 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_POINTS
) * m_PS2DEV
);
2204 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_POINTS
) * m_PS2DEV
);
2207 void wxGtkPrintDC::DoGetSizeMM(int *width
, int *height
) const
2209 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2212 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_MM
) );
2214 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_MM
) );
2217 wxSize
wxGtkPrintDC::GetPPI() const
2219 return wxSize( (int)m_resolution
, (int)m_resolution
);
2222 void wxGtkPrintDC::SetPrintData(const wxPrintData
& data
)
2227 void wxGtkPrintDC::SetResolution(int WXUNUSED(ppi
))
2229 // We can't change ppi of the GtkPrintContext.
2230 // TODO: should we really support this?
2233 int wxGtkPrintDC::GetResolution()
2235 return m_resolution
;
2238 // ----------------------------------------------------------------------------
2240 // ----------------------------------------------------------------------------
2242 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2244 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2245 wxPrintout
* WXUNUSED(printoutForPrinting
))
2250 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2251 wxPrintout
*printoutForPrinting
,
2252 wxPrintDialogData
*data
)
2253 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2255 Init(printout
, printoutForPrinting
);
2258 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2259 wxPrintout
*printoutForPrinting
,
2261 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2263 Init(printout
, printoutForPrinting
);
2266 wxGtkPrintPreview::~wxGtkPrintPreview()
2270 bool wxGtkPrintPreview::Print(bool interactive
)
2272 if (!m_printPrintout
)
2275 wxPrinter
printer(& m_printDialogData
);
2276 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2279 void wxGtkPrintPreview::DetermineScaling()
2281 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2283 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2285 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2289 wxSize ScreenPixels
= wxGetDisplaySize();
2290 wxSize ScreenMM
= wxGetDisplaySizeMM();
2292 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2293 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2295 // TODO !!!!!!!!!!!!!!!
2296 int resolution
= 600;
2297 m_previewPrintout
->SetPPIPrinter( resolution
, resolution
);
2299 // Get width and height in points (1/72th of an inch)
2300 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2302 sizeDevUnits
.x
= wxRound((double)sizeDevUnits
.x
* (double)resolution
/ 72.0);
2303 sizeDevUnits
.y
= wxRound((double)sizeDevUnits
.y
* (double)resolution
/ 72.0);
2304 wxSize
sizeTenthsMM(paper
->GetSize());
2305 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2307 // If in landscape mode, we need to swap the width and height.
2308 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2310 m_pageWidth
= sizeDevUnits
.y
;
2311 m_pageHeight
= sizeDevUnits
.x
;
2312 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2316 m_pageWidth
= sizeDevUnits
.x
;
2317 m_pageHeight
= sizeDevUnits
.y
;
2318 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2320 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2321 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2323 // At 100%, the page should look about page-size on the screen.
2324 m_previewScaleX
= 0.8 * 72.0 / (double)resolution
;
2325 m_previewScaleY
= m_previewScaleX
;