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"
31 #include "wx/fontutil.h"
32 #include "wx/gtk/private.h"
33 #include "wx/dynlib.h"
35 #include "wx/rawbmp.h"
38 #include <gtk/gtkpagesetupunixdialog.h>
41 wxFORCE_LINK_THIS_MODULE(gtk_print
)
43 #if wxUSE_LIBGNOMEPRINT
44 #include "wx/gtk/gnome/gprint.h"
47 // Usefull to convert angles from/to Rad to/from Deg.
48 static const double RAD2DEG
= 180.0 / M_PI
;
49 static const double DEG2RAD
= M_PI
/ 180.0;
51 //----------------------------------------------------------------------------
53 // Initialized when starting the app : if it successfully load the gtk-print framework,
54 // it uses it. If not, it falls back to gnome print (see /gtk/gnome/gprint.cpp) then
55 // to postscript if gnomeprint is not available.
56 //----------------------------------------------------------------------------
58 class wxGtkPrintModule
: public wxModule
63 #if wxUSE_LIBGNOMEPRINT
64 // This module must be initialized AFTER gnomeprint's one
65 AddDependency(CLASSINFO(wxGnomePrintModule
));
72 DECLARE_DYNAMIC_CLASS(wxGtkPrintModule
)
75 bool wxGtkPrintModule::OnInit()
77 if (gtk_check_version(2,10,0) == NULL
)
78 wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory
);
83 void wxGtkPrintModule::OnExit()
87 IMPLEMENT_DYNAMIC_CLASS(wxGtkPrintModule
, wxModule
)
90 //----------------------------------------------------------------------------
92 //----------------------------------------------------------------------------
94 wxPrinterBase
* wxGtkPrintFactory::CreatePrinter( wxPrintDialogData
*data
)
96 return new wxGtkPrinter( data
);
99 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
100 wxPrintout
*printout
,
101 wxPrintDialogData
*data
)
103 return new wxGtkPrintPreview( preview
, printout
, data
);
106 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
107 wxPrintout
*printout
,
110 return new wxGtkPrintPreview( preview
, printout
, data
);
113 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
114 wxPrintDialogData
*data
)
116 return new wxGtkPrintDialog( parent
, data
);
119 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
122 return new wxGtkPrintDialog( parent
, data
);
125 wxPageSetupDialogBase
*wxGtkPrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
126 wxPageSetupDialogData
* data
)
128 return new wxGtkPageSetupDialog( parent
, data
);
131 bool wxGtkPrintFactory::HasPrintSetupDialog()
136 wxDialog
*wxGtkPrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
141 wxDC
* wxGtkPrintFactory::CreatePrinterDC( const wxPrintData
& data
)
143 return new wxGtkPrintDC(data
);
146 bool wxGtkPrintFactory::HasOwnPrintToFile()
151 bool wxGtkPrintFactory::HasPrinterLine()
156 wxString
wxGtkPrintFactory::CreatePrinterLine()
159 return wxEmptyString
;
162 bool wxGtkPrintFactory::HasStatusLine()
168 wxString
wxGtkPrintFactory::CreateStatusLine()
171 return wxEmptyString
;
174 wxPrintNativeDataBase
*wxGtkPrintFactory::CreatePrintNativeData()
176 return new wxGtkPrintNativeData
;
179 //----------------------------------------------------------------------------
180 // Callback functions for Gtk Printings.
181 //----------------------------------------------------------------------------
183 // We use it to pass useful objets to gtk printing callback functions.
186 wxGtkPrinter
* printer
;
187 wxPrintout
* printout
;
193 static void gtk_begin_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
195 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
197 data
->printer
->BeginPrint(data
->printout
, operation
, context
);
200 static void gtk_draw_page_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gint page_nr
, gpointer user_data
)
202 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
204 data
->printer
->DrawPage(data
->printout
, operation
, context
, page_nr
);
207 static void gtk_end_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
209 wxPrintout
*printout
= (wxPrintout
*) user_data
;
211 printout
->OnEndPrinting();
214 static gboolean
gtk_preview_print_callback (GtkPrintOperation
*operation
, GtkPrintOperationPreview
*preview
, GtkPrintContext
*context
, GtkWindow
*parent
, gpointer user_data
)
216 wxPrintout
*printout
= (wxPrintout
*) user_data
;
218 printout
->SetIsPreview(true);
220 /* We create a cairo context with 72dpi resolution. This resolution is only used for positionning. */
221 cairo_t
*cairo
= gdk_cairo_create(GTK_WIDGET(parent
)->window
);
222 gtk_print_context_set_cairo_context(context
, cairo
, 72, 72);
228 //----------------------------------------------------------------------------
229 // wxGtkPrintNativeData
230 //----------------------------------------------------------------------------
232 IMPLEMENT_CLASS(wxGtkPrintNativeData
, wxPrintNativeDataBase
)
234 wxGtkPrintNativeData::wxGtkPrintNativeData()
236 m_config
= gtk_print_settings_new();
239 wxGtkPrintNativeData::~wxGtkPrintNativeData()
241 g_object_unref (m_config
);
244 // Convert datas stored in m_config to a wxPrintData.
245 // Called by wxPrintData::ConvertFromNative().
246 bool wxGtkPrintNativeData::TransferTo( wxPrintData
&data
)
251 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
252 if (quality
== GTK_PRINT_QUALITY_HIGH
)
253 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
254 else if (quality
== GTK_PRINT_QUALITY_LOW
)
255 data
.SetQuality(wxPRINT_QUALITY_LOW
);
256 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
257 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
259 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
261 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
263 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
265 switch (gtk_print_settings_get_duplex(m_config
))
267 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
270 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
274 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
278 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
279 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
281 data
.SetOrientation(wxPORTRAIT
);
282 data
.SetOrientationReversed(false);
284 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
286 data
.SetOrientation(wxLANDSCAPE
);
287 data
.SetOrientationReversed(false);
289 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
291 data
.SetOrientation(wxPORTRAIT
);
292 data
.SetOrientationReversed(true);
294 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
296 data
.SetOrientation(wxLANDSCAPE
);
297 data
.SetOrientationReversed(true);
300 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
302 // Paper formats : these are the most common paper formats.
303 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
305 data
.SetPaperId(wxPAPER_NONE
);
306 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
307 data
.SetPaperId(wxPAPER_A3
);
308 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
309 data
.SetPaperId(wxPAPER_A4
);
310 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
311 data
.SetPaperId(wxPAPER_A5
);
312 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
313 data
.SetPaperId(wxPAPER_B5
);
314 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
315 data
.SetPaperId(wxPAPER_LETTER
);
316 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
317 data
.SetPaperId(wxPAPER_LEGAL
);
318 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
319 data
.SetPaperId(wxPAPER_EXECUTIVE
);
320 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
321 data
.SetPaperId(wxPAPER_ENV_10
);
322 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
323 data
.SetPaperId(wxPAPER_ENV_C5
);
324 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
325 data
.SetPaperId(wxPAPER_ENV_C6
);
326 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
327 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
328 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
329 data
.SetPaperId(wxPAPER_ENV_B5
);
330 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
331 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
332 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
333 data
.SetPaperId( wxPAPER_CSHEET
);
334 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
335 data
.SetPaperId( wxPAPER_DSHEET
);
336 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
337 data
.SetPaperId( wxPAPER_ESHEET
);
338 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
339 data
.SetPaperId( wxPAPER_LETTERSMALL
);
340 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
341 data
.SetPaperId( wxPAPER_TABLOID
);
342 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
343 data
.SetPaperId( wxPAPER_LEDGER
);
344 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
345 data
.SetPaperId( wxPAPER_STATEMENT
);
346 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
347 data
.SetPaperId( wxPAPER_A4SMALL
);
348 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
349 data
.SetPaperId( wxPAPER_B4
);
350 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
351 data
.SetPaperId( wxPAPER_FOLIO
);
352 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
353 data
.SetPaperId( wxPAPER_QUARTO
);
354 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
355 data
.SetPaperId( wxPAPER_10X14
);
356 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
357 data
.SetPaperId( wxPAPER_11X17
);
358 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
359 data
.SetPaperId( wxPAPER_NOTE
);
360 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
361 data
.SetPaperId( wxPAPER_ENV_9
);
362 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
363 data
.SetPaperId( wxPAPER_ENV_11
);
364 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
365 data
.SetPaperId( wxPAPER_ENV_12
);
366 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
367 data
.SetPaperId( wxPAPER_ENV_14
);
368 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
369 data
.SetPaperId( wxPAPER_ENV_DL
);
370 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
371 data
.SetPaperId( wxPAPER_ENV_C3
);
372 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
373 data
.SetPaperId( wxPAPER_ENV_C4
);
374 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
375 data
.SetPaperId( wxPAPER_ENV_C65
);
376 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
377 data
.SetPaperId( wxPAPER_ENV_B4
);
378 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
379 data
.SetPaperId( wxPAPER_ENV_B6
);
380 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
381 data
.SetPaperId( wxPAPER_ENV_ITALY
);
382 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
383 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
384 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
385 data
.SetPaperId( wxPAPER_FANFOLD_US
);
386 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
387 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
388 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
389 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
391 data
.SetPaperId(wxPAPER_NONE
);
395 // Put datas given by the wxPrintData into m_config.
396 // Called by wxPrintData::ConvertToNative().
397 bool wxGtkPrintNativeData::TransferFrom( const wxPrintData
&data
)
402 wxPrintQuality quality
= data
.GetQuality();
403 if (quality
== wxPRINT_QUALITY_HIGH
)
404 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
405 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
406 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
407 else if (quality
== wxPRINT_QUALITY_LOW
)
408 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
409 else if (quality
== wxPRINT_QUALITY_DRAFT
)
410 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
411 else if (quality
> 1)
412 gtk_print_settings_set_resolution (m_config
, quality
);
414 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
416 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
418 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
420 switch (data
.GetDuplex())
422 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
425 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
429 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
433 if (!data
.IsOrientationReversed())
435 if (data
.GetOrientation() == wxLANDSCAPE
)
436 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
438 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
441 if (data
.GetOrientation() == wxLANDSCAPE
)
442 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
444 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
447 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
449 // Paper formats: these are the most common paper formats.
450 switch (data
.GetPaperId())
452 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
454 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
456 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
458 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
460 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
462 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
464 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
466 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
468 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
470 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
472 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
474 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
476 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
478 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
480 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
482 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
484 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
486 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
488 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
490 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
492 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
494 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
496 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
498 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
500 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
502 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
504 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
506 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
508 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
510 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
512 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
514 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
516 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
518 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
520 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
522 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
524 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
526 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
528 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
530 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
532 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
534 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
543 void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings
* config
)
546 m_config
= gtk_print_settings_copy(config
);
549 // Extract page setup from settings.
550 GtkPageSetup
* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
552 GtkPageSetup
* page_setup
= gtk_page_setup_new();
553 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
555 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
556 if (paper_size
!= NULL
)
557 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
562 // Insert page setup into a given GtkPrintSettings.
563 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
565 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
566 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
569 //----------------------------------------------------------------------------
571 //----------------------------------------------------------------------------
573 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
575 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
576 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
577 wxPoint(0, 0), wxSize(600, 600),
578 wxDEFAULT_DIALOG_STYLE
|
582 m_printDialogData
= *data
;
588 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
589 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
590 wxPoint(0, 0), wxSize(600, 600),
591 wxDEFAULT_DIALOG_STYLE
|
595 m_printDialogData
= *data
;
602 wxGtkPrintDialog::~wxGtkPrintDialog()
606 // This is called even if we actually don't want the dialog to appear.
607 int wxGtkPrintDialog::ShowModal()
609 GtkPrintOperationResult response
;
611 // We need to restore the settings given in the constructor.
612 wxPrintData data
= m_printDialogData
.GetPrintData();
613 wxGtkPrintNativeData
*native
=
614 (wxGtkPrintNativeData
*) data
.GetNativeData();
615 data
.ConvertToNative();
617 GtkPrintSettings
* settings
= native
->GetPrintConfig();
619 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
620 int fromPage
= m_printDialogData
.GetFromPage();
621 int toPage
= m_printDialogData
.GetToPage();
622 if (m_printDialogData
.GetSelection())
623 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
624 else if (m_printDialogData
.GetAllPages())
625 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
627 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
629 range
= g_new (GtkPageRange
, 1);
630 range
[0].start
= fromPage
-1;
631 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
632 gtk_print_settings_set_page_ranges (settings
, range
, 1);
635 // If the settings are OK, we restore it.
636 if (settings
!= NULL
)
637 gtk_print_operation_set_print_settings (native
->GetPrintJob(), settings
);
638 gtk_print_operation_set_default_page_setup (native
->GetPrintJob(), native
->GetPageSetupFromSettings(settings
));
640 // Show the dialog if needed.
641 GError
* gError
= NULL
;
643 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
645 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT
, (GtkWindow
*) m_parent
, &gError
);
647 // Does everything went well?
648 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
652 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
654 g_error_free (gError
);
655 wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError
->message
));
656 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
659 // Now get the settings and save it.
660 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings (native
->GetPrintJob());
661 native
->SetPrintConfig(newSettings
);
662 data
.ConvertFromNative();
664 // Same problem as a few lines before.
665 switch (gtk_print_settings_get_print_pages(newSettings
))
667 case GTK_PRINT_PAGES_CURRENT
:
668 m_printDialogData
.SetSelection( true );
670 case GTK_PRINT_PAGES_ALL
:
671 m_printDialogData
.SetAllPages( true );
672 m_printDialogData
.SetFromPage( 0 );
673 m_printDialogData
.SetToPage( 9999 );
675 case GTK_PRINT_PAGES_RANGES
:
677 // wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
678 // 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
679 // will hit "OK" button. However we can only save 1-3 in the print data.
682 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
683 m_printDialogData
.SetFromPage( range
[0].start
);
684 m_printDialogData
.SetToPage( range
[0].end
);
691 //----------------------------------------------------------------------------
692 // wxGtkPageSetupDialog
693 //----------------------------------------------------------------------------
695 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
697 wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow
*parent
,
698 wxPageSetupDialogData
* data
)
701 m_pageDialogData
= *data
;
706 wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
710 int wxGtkPageSetupDialog::ShowModal()
713 m_pageDialogData
.GetPrintData().ConvertToNative();
714 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
715 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
717 // We only need the pagesetup data which are part of the settings.
718 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
720 // If the user used a custom paper format the last time he printed, we have to restore it too.
721 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
723 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
724 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
726 wxString title
= _("Custom size");
727 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
728 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
729 g_object_unref(customSize
);
733 // Now show the dialog.
734 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
739 if (newPageSetup
!= oldPageSetup
)
741 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
742 m_pageDialogData
.GetPrintData().ConvertFromNative();
744 // Store custom paper format if any.
745 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
747 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
748 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
749 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
750 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
751 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
753 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
754 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
756 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
757 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
759 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
772 //----------------------------------------------------------------------------
774 //----------------------------------------------------------------------------
776 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
778 wxGtkPrinter::wxGtkPrinter( wxPrintDialogData
*data
) :
779 wxPrinterBase( data
)
784 m_printDialogData
= *data
;
787 wxGtkPrinter::~wxGtkPrinter()
791 bool wxGtkPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
795 sm_lastError
= wxPRINTER_ERROR
;
799 // Let's correct the PageInfo just in case the app gives wrong values.
800 int fromPage
, toPage
;
801 int minPage
, maxPage
;
802 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
803 m_printDialogData
.SetAllPages(true);
805 if (minPage
< 1) minPage
= 1;
806 if (maxPage
< 1) maxPage
= 9999;
807 if (maxPage
< minPage
) maxPage
= minPage
;
809 m_printDialogData
.SetMinPage(minPage
);
810 m_printDialogData
.SetMaxPage(maxPage
);
813 if (fromPage
< minPage
) fromPage
= minPage
;
814 else if (fromPage
> maxPage
) fromPage
= maxPage
;
815 m_printDialogData
.SetFromPage(fromPage
);
819 m_printDialogData
.SetToPage(toPage
);
820 if (toPage
> maxPage
) toPage
= maxPage
;
821 else if (toPage
< minPage
) toPage
= minPage
;
824 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
827 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
828 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
830 GtkPrintOperation
*printOp
= gtk_print_operation_new ();
832 native
->SetPrintJob( printOp
);
834 printout
->SetIsPreview(false);
836 wxPrinterToGtkData dataToSend
;
837 dataToSend
.printer
= this;
838 dataToSend
.printout
= printout
;
840 // These Gtk signals are catched here.
841 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
842 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
843 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
844 g_signal_connect (printOp
, "preview", G_CALLBACK (gtk_preview_print_callback
), printout
);
848 m_showDialog
= false;
850 // PrintDialog returns a wxDC but we created it before so we don't need it anymore: we just delete it.
851 wxDC
* uselessdc
= PrintDialog( parent
);
854 g_object_unref (printOp
);
856 return (sm_lastError
== wxPRINTER_NO_ERROR
);
859 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
861 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
862 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
864 SetPrintContext(context
);
865 native
->SetPrintContext( context
);
867 m_dc
= new wxGtkPrintDC( printdata
);
871 if (sm_lastError
!= wxPRINTER_CANCELLED
)
873 sm_lastError
= wxPRINTER_ERROR
;
874 wxFAIL_MSG(_("The wxGtkPrintDC cannot be used."));
878 wxSize ScreenPixels
= wxGetDisplaySize();
879 wxSize ScreenMM
= wxGetDisplaySizeMM();
881 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
882 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
883 printout
->SetPPIPrinter( wxGtkPrintDC::GetResolution(),
884 wxGtkPrintDC::GetResolution() );
886 printout
->SetDC(m_dc
);
889 m_dc
->GetSize(&w
, &h
);
890 printout
->SetPageSizePixels((int)w
, (int)h
);
891 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
893 m_dc
->GetSizeMM(&mw
, &mh
);
894 printout
->SetPageSizeMM((int)mw
, (int)mh
);
895 printout
->OnPreparePrinting();
897 // Get some parameters from the printout, if defined.
898 int fromPage
, toPage
;
899 int minPage
, maxPage
;
900 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
904 sm_lastError
= wxPRINTER_ERROR
;
905 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
909 printout
->OnBeginPrinting();
913 // If we're not previewing we need to calculate the number of pages to print.
914 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
915 // have defined in the dialog. So the number of pages is the maximum available.
916 if (!printout
->IsPreview())
918 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
919 switch (gtk_print_settings_get_print_pages(settings
))
921 case GTK_PRINT_PAGES_CURRENT
:
924 case GTK_PRINT_PAGES_RANGES
:
925 {gint num_ranges
= 0;
928 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
929 for (i
=0; i
<num_ranges
; i
++)
931 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
932 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
933 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
934 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
935 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
937 gtk_print_settings_set_page_ranges (settings
, range
, 1);
939 case GTK_PRINT_PAGES_ALL
:
941 numPages
= maxPage
- minPage
+ 1;
945 else numPages
= maxPage
- minPage
+ 1;
947 gtk_print_operation_set_n_pages(operation
, numPages
);
950 void wxGtkPrinter::DrawPage(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
, int page_nr
)
952 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
953 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
955 int numPageToDraw
= page_nr
+ minPage
;
956 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
957 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
959 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
960 switch (gtk_print_settings_get_print_pages(settings
))
962 case GTK_PRINT_PAGES_CURRENT
:
963 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
964 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
966 case GTK_PRINT_PAGES_RANGES
:
967 {gint num_ranges
= 0;
969 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
970 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
971 startPage
= range
[0].start
+ 1;
972 endPage
= range
[0].end
+ 1;
974 case GTK_PRINT_PAGES_ALL
:
981 if(numPageToDraw
== startPage
)
983 if (!printout
->OnBeginDocument(startPage
, endPage
))
985 wxLogError(_("Could not start printing."));
986 sm_lastError
= wxPRINTER_ERROR
;
990 // The app can render the page numPageToDraw.
991 if (printout
->HasPage(numPageToDraw
))
994 printout
->OnPrintPage(numPageToDraw
);
999 if(numPageToDraw
== endPage
)
1001 printout
->OnEndDocument();
1005 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1007 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1010 dialog
.SetPrintDC(m_dc
);
1012 dialog
.SetShowDialog(m_showDialog
);
1014 ret
= dialog
.ShowModal();
1016 if (ret
== wxID_CANCEL
)
1018 sm_lastError
= wxPRINTER_CANCELLED
;
1023 sm_lastError
= wxPRINTER_ERROR
;
1024 wxFAIL_MSG(_("The print dialog returned an error."));
1028 m_printDialogData
= dialog
.GetPrintDialogData();
1029 return new wxGtkPrintDC( m_printDialogData
.GetPrintData() );
1032 bool wxGtkPrinter::Setup( wxWindow
*parent
)
1034 // Obsolete, for backward compatibility.
1038 //-----------------------------------------------------------------------------
1040 //-----------------------------------------------------------------------------
1042 IMPLEMENT_CLASS(wxGtkPrintDC
, wxDC
)
1044 // Define the default resolution for this DC. This resolution is just used for positioning as the cairo context is scalable.
1045 int wxGtkPrintDC::ms_resolution
= 72;
1047 wxGtkPrintDC::wxGtkPrintDC( const wxPrintData
& data
)
1051 wxGtkPrintNativeData
*native
=
1052 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1054 m_gpc
= native
->GetPrintContext();
1056 ms_resolution
= (int) gtk_print_context_get_dpi_x(m_gpc
);
1057 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1058 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1059 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1061 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1067 m_signX
= 1; // default x-axis left to right.
1068 m_signY
= 1; // default y-axis bottom up -> top down.
1070 GetSize( &m_deviceOffsetX
, &m_deviceOffsetY
);
1073 wxGtkPrintDC::~wxGtkPrintDC()
1075 g_object_unref(m_context
);
1076 g_object_unref(m_layout
);
1079 bool wxGtkPrintDC::IsOk() const
1084 void wxGtkPrintDC::ComputeScaleAndOrigin()
1086 // Called when the scale and/or origin of the context has to be changed.
1087 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1088 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1090 cairo_translate(m_cairo
, m_deviceOriginX
, m_deviceOriginY
);
1091 cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
1094 bool wxGtkPrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
1096 // We can't access the given coord as a cairo context is scalable, ie a coord doesn't mean anything in this context.
1097 wxFAIL_MSG(_("not implemented"));
1101 void wxGtkPrintDC::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1103 wxCoord xC
= circleCenter
.x
;
1104 wxCoord yC
= circleCenter
.y
;
1105 wxCoord xR
= rect
.x
;
1106 wxCoord yR
= rect
.y
;
1107 wxCoord w
= rect
.width
;
1108 wxCoord h
= rect
.height
;
1110 double radius
= sqrt((w
/2)*(w
/2)+(h
/2)*(h
/2));
1112 unsigned char redI
= initialColour
.Red();
1113 unsigned char blueI
= initialColour
.Blue();
1114 unsigned char greenI
= initialColour
.Green();
1115 unsigned char alphaI
= initialColour
.Alpha();
1116 unsigned char redD
= destColour
.Red();
1117 unsigned char blueD
= destColour
.Blue();
1118 unsigned char greenD
= destColour
.Green();
1119 unsigned char alphaD
= destColour
.Alpha();
1121 double redIPS
= (double)(redI
) / 255.0;
1122 double blueIPS
= (double)(blueI
) / 255.0;
1123 double greenIPS
= (double)(greenI
) / 255.0;
1124 double alphaIPS
= (double)(alphaI
) / 255.0;
1125 double redDPS
= (double)(redD
) / 255.0;
1126 double blueDPS
= (double)(blueD
) / 255.0;
1127 double greenDPS
= (double)(greenD
) / 255.0;
1128 double alphaDPS
= (double)(alphaD
) / 255.0;
1130 // Create a pattern with the gradient.
1131 cairo_pattern_t
* gradient
;
1132 gradient
= cairo_pattern_create_radial (LogicalToDeviceX(xC
+xR
), LogicalToDeviceY(yC
+yR
), 0, LogicalToDeviceX(xC
+xR
), LogicalToDeviceY(yC
+yR
), radius
);
1133 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1134 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1136 // Fill the rectangle with this pattern.
1137 cairo_set_source(m_cairo
, gradient
);
1138 cairo_rectangle (m_cairo
, LogicalToDeviceX(xR
), LogicalToDeviceY(yR
), LogicalToDeviceXRel(w
), LogicalToDeviceYRel(h
) );
1139 cairo_fill(m_cairo
);
1141 cairo_pattern_destroy(gradient
);
1143 CalcBoundingBox(xR
, yR
);
1144 CalcBoundingBox(xR
+w
, yR
+h
);
1147 void wxGtkPrintDC::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1151 wxCoord w
= rect
.width
;
1152 wxCoord h
= rect
.height
;
1154 unsigned char redI
= initialColour
.Red();
1155 unsigned char blueI
= initialColour
.Blue();
1156 unsigned char greenI
= initialColour
.Green();
1157 unsigned char alphaI
= initialColour
.Alpha();
1158 unsigned char redD
= destColour
.Red();
1159 unsigned char blueD
= destColour
.Blue();
1160 unsigned char greenD
= destColour
.Green();
1161 unsigned char alphaD
= destColour
.Alpha();
1163 double redIPS
= (double)(redI
) / 255.0;
1164 double blueIPS
= (double)(blueI
) / 255.0;
1165 double greenIPS
= (double)(greenI
) / 255.0;
1166 double alphaIPS
= (double)(alphaI
) / 255.0;
1167 double redDPS
= (double)(redD
) / 255.0;
1168 double blueDPS
= (double)(blueD
) / 255.0;
1169 double greenDPS
= (double)(greenD
) / 255.0;
1170 double alphaDPS
= (double)(alphaD
) / 255.0;
1172 // Create a pattern with the gradient.
1173 cairo_pattern_t
* gradient
;
1174 gradient
= cairo_pattern_create_linear (LogicalToDeviceX(x
), LogicalToDeviceY(y
), LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
));
1176 if (nDirection
== wxWEST
)
1178 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1179 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1182 cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1183 cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1186 // Fill the rectangle with this pattern.
1187 cairo_set_source(m_cairo
, gradient
);
1188 cairo_rectangle (m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
), LogicalToDeviceXRel(w
), LogicalToDeviceYRel(h
) );
1189 cairo_fill(m_cairo
);
1191 cairo_pattern_destroy(gradient
);
1193 CalcBoundingBox(x
, y
);
1194 CalcBoundingBox(x
+w
, y
+h
);
1197 bool wxGtkPrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
1199 // We can't access the given coord as a cairo context is scalable, ie a coord doesn't mean anything in this context.
1200 wxFAIL_MSG(_("not implemented"));
1204 void wxGtkPrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1206 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1209 cairo_move_to ( m_cairo
, LogicalToDeviceX(x1
), LogicalToDeviceY(y1
) );
1210 cairo_line_to ( m_cairo
, LogicalToDeviceX(x2
), LogicalToDeviceY(y2
) );
1211 cairo_stroke ( m_cairo
);
1213 CalcBoundingBox( x1
, y1
);
1214 CalcBoundingBox( x2
, y2
);
1217 void wxGtkPrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
1226 cairo_move_to (m_cairo
, LogicalToDeviceX(x
), 0);
1227 cairo_line_to (m_cairo
, LogicalToDeviceX(x
), *h
);
1228 cairo_move_to (m_cairo
, 0, LogicalToDeviceY(y
));
1229 cairo_line_to (m_cairo
, *w
, LogicalToDeviceY(y
));
1231 cairo_stroke (m_cairo
);
1232 CalcBoundingBox( 0, 0 );
1233 CalcBoundingBox( *w
, *h
);
1239 void wxGtkPrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1241 double dx
= x1
- xc
;
1242 double dy
= y1
- yc
;
1243 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1245 double alpha1
, alpha2
;
1246 if (x1
== x2
&& y1
== y2
)
1254 alpha1
= alpha2
= 0.0;
1258 alpha1
= (x1
- xc
== 0) ?
1259 (y1
- yc
< 0) ? 90.0 : -90.0 :
1260 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1261 alpha2
= (x2
- xc
== 0) ?
1262 (y2
- yc
< 0) ? 90.0 : -90.0 :
1263 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1265 while (alpha1
<= 0) alpha1
+= 360;
1266 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1267 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1268 while (alpha2
> 360) alpha2
-= 360;
1274 cairo_arc_negative ( m_cairo
, LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel((int)radius
), alpha1
, alpha2
);
1275 cairo_line_to(m_cairo
, LogicalToDeviceX(xc
), LogicalToDeviceY(yc
));
1276 cairo_close_path (m_cairo
);
1278 SetBrush( m_brush
);
1279 cairo_fill_preserve( m_cairo
);
1282 cairo_stroke( m_cairo
);
1284 CalcBoundingBox (x1
, y1
);
1285 CalcBoundingBox (xc
, yc
);
1286 CalcBoundingBox (x2
, y2
);
1289 void wxGtkPrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1291 cairo_save( m_cairo
);
1293 cairo_translate( m_cairo
, LogicalToDeviceX((wxCoord
) (x
+ w
/ 2.)), LogicalToDeviceX((wxCoord
) (y
+ h
/ 2.)) );
1294 double scale
= (double)LogicalToDeviceYRel(h
) / (double) LogicalToDeviceXRel(w
);
1295 cairo_scale( m_cairo
, 1.0, scale
);
1297 cairo_arc_negative ( m_cairo
, 0, 0, LogicalToDeviceXRel(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1300 cairo_stroke_preserve( m_cairo
);
1302 cairo_line_to(m_cairo
, 0,0);
1304 SetBrush( m_brush
);
1305 cairo_fill( m_cairo
);
1307 cairo_restore( m_cairo
);
1309 CalcBoundingBox( x
, y
);
1310 CalcBoundingBox( x
+w
, y
+h
);
1313 void wxGtkPrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
1315 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1319 cairo_move_to ( m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
) );
1320 cairo_line_to ( m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
) );
1321 cairo_stroke ( m_cairo
);
1323 CalcBoundingBox( x
, y
);
1326 void wxGtkPrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1328 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1335 for ( i
=0; i
<n
; i
++ )
1336 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1338 cairo_move_to ( m_cairo
, LogicalToDeviceX(points
[0].x
+xoffset
), LogicalToDeviceY(points
[0].y
+yoffset
) );
1340 for (i
= 1; i
< n
; i
++)
1341 cairo_line_to ( m_cairo
, LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
) );
1343 cairo_stroke ( m_cairo
);
1346 void wxGtkPrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1350 cairo_save(m_cairo
);
1351 if (fillStyle
== wxWINDING_RULE
)
1352 cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1354 cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1356 int x
= points
[0].x
+ xoffset
;
1357 int y
= points
[0].y
+ yoffset
;
1358 cairo_new_path(m_cairo
);
1359 cairo_move_to( m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
) );
1361 for (i
= 1; i
< n
; i
++)
1363 int x
= points
[i
].x
+ xoffset
;
1364 int y
= points
[i
].y
+ yoffset
;
1365 cairo_line_to( m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
) );
1367 cairo_close_path(m_cairo
);
1369 SetBrush( m_brush
);
1370 cairo_fill_preserve( m_cairo
);
1373 cairo_stroke( m_cairo
);
1375 CalcBoundingBox( x
, y
);
1377 cairo_restore(m_cairo
);
1380 void wxGtkPrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1382 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1385 void wxGtkPrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1387 cairo_rectangle ( m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
), LogicalToDeviceXRel(width
), LogicalToDeviceYRel(height
));
1389 SetBrush( m_brush
);
1390 cairo_fill_preserve( m_cairo
);
1393 cairo_stroke( m_cairo
);
1395 CalcBoundingBox( x
, y
);
1396 CalcBoundingBox( x
+ width
, y
+ height
);
1399 void wxGtkPrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1401 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1403 wxCoord dd
= 2 * (wxCoord
) radius
;
1404 if (dd
> width
) dd
= width
;
1405 if (dd
> height
) dd
= height
;
1408 wxCoord rad
= (wxCoord
) radius
;
1410 cairo_new_path(m_cairo
);
1411 cairo_move_to(m_cairo
,LogicalToDeviceX(x
+ rad
),LogicalToDeviceY(y
));
1412 cairo_curve_to(m_cairo
,
1413 LogicalToDeviceX(x
+ rad
),LogicalToDeviceY(y
),
1414 LogicalToDeviceX(x
),LogicalToDeviceY(y
),
1415 LogicalToDeviceX(x
),LogicalToDeviceY(y
+ rad
));
1416 cairo_line_to(m_cairo
,LogicalToDeviceX(x
),LogicalToDeviceY(y
+ height
- rad
));
1417 cairo_curve_to(m_cairo
,
1418 LogicalToDeviceX(x
),LogicalToDeviceY(y
+ height
- rad
),
1419 LogicalToDeviceX(x
),LogicalToDeviceY(y
+ height
),
1420 LogicalToDeviceX(x
+ rad
),LogicalToDeviceY(y
+ height
));
1421 cairo_line_to(m_cairo
,LogicalToDeviceX(x
+ width
- rad
),LogicalToDeviceY(y
+ height
));
1422 cairo_curve_to(m_cairo
,
1423 LogicalToDeviceX(x
+ width
- rad
),LogicalToDeviceY(y
+ height
),
1424 LogicalToDeviceX(x
+ width
),LogicalToDeviceY(y
+ height
),
1425 LogicalToDeviceX(x
+ width
),LogicalToDeviceY(y
+ height
- rad
));
1426 cairo_line_to(m_cairo
,LogicalToDeviceX(x
+ width
),LogicalToDeviceY(y
+ rad
));
1427 cairo_curve_to(m_cairo
,
1428 LogicalToDeviceX(x
+ width
),LogicalToDeviceY(y
+ rad
),
1429 LogicalToDeviceX(x
+ width
),LogicalToDeviceY(y
),
1430 LogicalToDeviceX(x
+ width
- rad
),LogicalToDeviceY(y
));
1431 cairo_line_to(m_cairo
,LogicalToDeviceX(x
+ rad
),LogicalToDeviceY(y
));
1432 cairo_close_path(m_cairo
);
1435 cairo_fill_preserve(m_cairo
);
1438 cairo_stroke(m_cairo
);
1440 CalcBoundingBox(x
,y
);
1441 CalcBoundingBox(x
+width
,y
+height
);
1444 void wxGtkPrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1446 cairo_save (m_cairo
);
1448 cairo_translate (m_cairo
, LogicalToDeviceX((wxCoord
) (x
+ width
/ 2.)), LogicalToDeviceY((wxCoord
) (y
+ height
/ 2.)));
1449 cairo_scale(m_cairo
, 1, (double)LogicalToDeviceYRel(height
)/(double)LogicalToDeviceXRel(width
));
1450 cairo_arc ( m_cairo
, 0, 0, LogicalToDeviceXRel(width
/2), 0, 2 * M_PI
);
1452 SetBrush( m_brush
);
1453 cairo_fill_preserve( m_cairo
);
1456 cairo_stroke( m_cairo
);
1458 CalcBoundingBox( x
, y
);
1459 CalcBoundingBox( x
+ width
, y
+ height
);
1461 cairo_restore (m_cairo
);
1465 void wxGtkPrintDC::DoDrawSpline(wxList
*points
)
1469 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1472 wxList::compatibility_iterator node
= points
->GetFirst();
1473 p
= (wxPoint
*)node
->GetData();
1477 node
= node
->GetNext();
1478 p
= (wxPoint
*)node
->GetData();
1482 (double)(x1
+ c
) / 2;
1484 (double)(y1
+ d
) / 2;
1486 cairo_new_path( m_cairo
);
1487 cairo_move_to( m_cairo
, LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
) );
1488 cairo_line_to( m_cairo
, LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1490 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1491 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1493 node
= node
->GetNext();
1496 q
= (wxPoint
*)node
->GetData();
1504 x3
= (double)(x2
+ c
) / 2;
1505 y3
= (double)(y2
+ d
) / 2;
1507 cairo_curve_to(m_cairo
,
1508 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1509 LogicalToDeviceX((wxCoord
)x2
), LogicalToDeviceY((wxCoord
)y2
),
1510 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1512 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1513 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1515 node
= node
->GetNext();
1518 cairo_line_to ( m_cairo
, LogicalToDeviceX((wxCoord
)c
), LogicalToDeviceY((wxCoord
)d
) );
1520 cairo_stroke( m_cairo
);
1522 #endif // wxUSE_SPLINES
1524 bool wxGtkPrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1525 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1526 wxCoord xsrcMask
, wxCoord ysrcMask
)
1528 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1530 // Blit into a bitmap.
1531 wxBitmap
bitmap( width
, height
);
1533 memDC
.SelectObject(bitmap
);
1534 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1535 memDC
.SelectObject(wxNullBitmap
);
1537 // Draw bitmap. scaling and positioning is done there.
1538 DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1543 void wxGtkPrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1545 DoDrawBitmap( icon
, x
, y
, true );
1548 void wxGtkPrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1550 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrintDC::DoDrawBitmap"));
1552 cairo_surface_t
* surface
;
1553 x
= LogicalToDeviceX(x
);
1554 y
= LogicalToDeviceY(y
);
1555 int bw
= bitmap
.GetWidth();
1556 int bh
= bitmap
.GetHeight();
1557 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1558 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1559 wxUint32
* data
= (wxUint32
*)buffer
;
1561 wxMask
*mask
= NULL
;
1562 if (useMask
) mask
= bmpSource
.GetMask();
1564 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1565 // then we'll use a different format and iterator than if it doesn't.
1566 if (bmpSource
.HasAlpha() || mask
)
1568 surface
= cairo_image_surface_create_for_data(
1569 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1570 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1571 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1573 wxAlphaPixelData::Iterator
p(pixData
);
1575 for (y
=0; y
<bh
; y
++)
1577 wxAlphaPixelData::Iterator rowStart
= p
;
1578 for (x
=0; x
<bw
; x
++)
1580 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1581 // with alpha in the upper 8 bits, then red, then green, then
1582 // blue. The 32-bit quantities are stored native-endian.
1583 // Pre-multiplied alpha is used.
1584 unsigned char alpha
= p
.Alpha();
1588 *data
= ( alpha
/255 << 24
1589 | (p
.Red() * alpha
/255) << 16
1590 | (p
.Green() * alpha
/255) << 8
1591 | (p
.Blue() * alpha
/255) );
1596 p
.OffsetY(pixData
, 1);
1601 surface
= cairo_image_surface_create_for_data(
1602 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1603 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1604 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1606 wxNativePixelData::Iterator
p(pixData
);
1608 for (y
=0; y
<bh
; y
++)
1610 wxNativePixelData::Iterator rowStart
= p
;
1611 for (x
=0; x
<bw
; x
++)
1613 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1614 // the upper 8 bits unused. Red, Green, and Blue are stored in
1615 // the remaining 24 bits in that order. The 32-bit quantities
1616 // are stored native-endian.
1617 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1622 p
.OffsetY(pixData
, 1);
1627 cairo_save(m_cairo
);
1628 // In case we're scaling the image by using a width and height different
1629 // than the bitmap's size create a pattern transformation on the surface and
1630 // draw the transformed pattern.
1631 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1633 // Prepare to draw the image.
1634 cairo_translate(m_cairo
, x
, y
);
1635 cairo_set_source(m_cairo
, pattern
);
1636 // Use the original size here since the context is scaled already.
1637 cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1638 // Fill the rectangle using the pattern.
1639 cairo_fill(m_cairo
);
1642 cairo_pattern_destroy(pattern
);
1643 cairo_surface_destroy(surface
);
1646 CalcBoundingBox(0,0);
1647 CalcBoundingBox(bw
,bh
);
1649 cairo_restore(m_cairo
);
1652 // wxGtkPrintDC has a constant resolution of 72dpi. If we want an higher resolution for printing
1653 // an image, the scaling has to be done by cairo.
1654 void wxGtkPrintDC::DoDrawScaledBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
, bool useMask
, int quality
)
1656 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrintDC::DoDrawBitmap"));
1658 cairo_surface_t
* surface
;
1659 int bw
= bitmap
.GetWidth();
1660 int bh
= bitmap
.GetHeight();
1661 x
= LogicalToDeviceX(x
);
1662 y
= LogicalToDeviceY(y
);
1663 w
= LogicalToDeviceXRel(w
);
1664 h
= LogicalToDeviceYRel(h
);
1665 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1666 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1667 wxUint32
* data
= (wxUint32
*)buffer
;
1669 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1670 // then we'll use a different format and iterator than if it doesn't.
1671 if (bmpSource
.HasAlpha() || bmpSource
.GetMask())
1673 surface
= cairo_image_surface_create_for_data(
1674 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1675 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1676 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1678 wxAlphaPixelData::Iterator
p(pixData
);
1680 for (y
=0; y
<bh
; y
++)
1682 wxAlphaPixelData::Iterator rowStart
= p
;
1683 for (x
=0; x
<bw
; x
++)
1685 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1686 // with alpha in the upper 8 bits, then red, then green, then
1687 // blue. The 32-bit quantities are stored native-endian.
1688 // Pre-multiplied alpha is used.
1689 unsigned char alpha
= p
.Alpha();
1693 *data
= ( alpha
<< 24
1694 | (p
.Red() * alpha
/255) << 16
1695 | (p
.Green() * alpha
/255) << 8
1696 | (p
.Blue() * alpha
/255) );
1701 p
.OffsetY(pixData
, 1);
1706 surface
= cairo_image_surface_create_for_data(
1707 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1708 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1709 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1711 wxNativePixelData::Iterator
p(pixData
);
1713 for (y
=0; y
<bh
; y
++)
1715 wxNativePixelData::Iterator rowStart
= p
;
1716 for (x
=0; x
<bw
; x
++)
1718 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1719 // the upper 8 bits unused. Red, Green, and Blue are stored in
1720 // the remaining 24 bits in that order. The 32-bit quantities
1721 // are stored native-endian.
1722 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1727 p
.OffsetY(pixData
, 1);
1732 cairo_save(m_cairo
);
1734 // Prepare to draw the image.
1735 cairo_translate(m_cairo
, x
, y
);
1737 // In case we're scaling the image by using a width and height different
1738 // than the bitmap's size create a pattern transformation on the surface and
1739 // draw the transformed pattern.
1740 cairo_filter_t filter
;
1741 if (quality
== wxIMAGE_QUALITY_HIGH
) filter
= CAIRO_FILTER_BILINEAR
;
1742 else filter
= CAIRO_FILTER_GOOD
;
1743 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1744 cairo_pattern_set_filter(pattern
,filter
);
1745 wxDouble scaleX
= (wxDouble
) w
/ (wxDouble
) bw
;
1746 wxDouble scaleY
= (wxDouble
) h
/ (wxDouble
) bh
;
1747 cairo_scale(m_cairo
, scaleX
, scaleY
);
1749 cairo_set_source(m_cairo
, pattern
);
1750 // Use the original size here since the context is scaled already.
1751 cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1752 // Fill the rectangle using the pattern.
1753 cairo_fill(m_cairo
);
1756 cairo_pattern_destroy(pattern
);
1757 cairo_surface_destroy(surface
);
1760 CalcBoundingBox(0,0);
1761 CalcBoundingBox(bw
,bh
);
1763 cairo_restore(m_cairo
);
1766 void wxGtkPrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1768 DoDrawRotatedText( text
, x
, y
, 0.0 );
1771 void wxGtkPrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1773 x
= LogicalToDeviceX(x
);
1774 y
= LogicalToDeviceY(y
);
1778 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1780 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1781 #if wxUSE_UNICODE_UTF8
1782 const char *data
= text
.utf8_str();
1784 const wxCharBuffer data
= text
.utf8_str();
1787 size_t datalen
= strlen(data
);
1788 pango_layout_set_text( m_layout
, data
, datalen
);
1792 PangoAttrList
*attrs
= pango_attr_list_new();
1793 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1795 a
->end_index
= datalen
;
1796 pango_attr_list_insert(attrs
, a
);
1797 pango_layout_set_attributes(m_layout
, attrs
);
1798 pango_attr_list_unref(attrs
);
1801 if (m_textForegroundColour
.Ok())
1803 unsigned char red
= m_textForegroundColour
.Red();
1804 unsigned char blue
= m_textForegroundColour
.Blue();
1805 unsigned char green
= m_textForegroundColour
.Green();
1806 unsigned char alpha
= m_textForegroundColour
.Alpha();
1808 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1810 double redPS
= (double)(red
) / 255.0;
1811 double bluePS
= (double)(blue
) / 255.0;
1812 double greenPS
= (double)(green
) / 255.0;
1813 double alphaPS
= (double)(alpha
) / 255.0;
1815 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1818 m_currentBlue
= blue
;
1819 m_currentGreen
= green
;
1820 m_currentAlpha
= alpha
;
1826 if (fabs(m_scaleY
- 1.0) > 0.00001)
1828 // If there is a user or actually any scale applied to the device context, scale the font.
1830 // Scale font description.
1831 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1832 double size
= oldSize
;
1833 size
= size
* m_scaleY
;
1834 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1836 // Actually apply scaled font.
1837 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1839 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1840 w
= LogicalToDeviceXRel(w
);
1841 h
= LogicalToDeviceYRel(h
);
1843 if ( m_backgroundMode
== wxSOLID
)
1845 unsigned char red
= m_textBackgroundColour
.Red();
1846 unsigned char blue
= m_textBackgroundColour
.Blue();
1847 unsigned char green
= m_textBackgroundColour
.Green();
1848 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1850 double redPS
= (double)(red
) / 255.0;
1851 double bluePS
= (double)(blue
) / 255.0;
1852 double greenPS
= (double)(green
) / 255.0;
1853 double alphaPS
= (double)(alpha
) / 255.0;
1855 cairo_save(m_cairo
);
1856 cairo_translate(m_cairo
, x
, y
);
1857 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1858 cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1859 cairo_rectangle(m_cairo
, 0, 0, w
, h
);
1860 cairo_fill(m_cairo
);
1861 cairo_restore(m_cairo
);
1865 cairo_move_to (m_cairo
, x
, y
);
1866 if (fabs(angle
) > 0.00001)
1868 cairo_save( m_cairo
);
1869 cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1870 pango_cairo_update_layout (m_cairo
, m_layout
);
1871 pango_cairo_show_layout (m_cairo
, m_layout
);
1872 cairo_restore( m_cairo
);
1876 pango_cairo_update_layout (m_cairo
, m_layout
);
1877 pango_cairo_show_layout (m_cairo
, m_layout
);
1880 // Reset unscaled size.
1881 pango_font_description_set_size( m_fontdesc
, oldSize
);
1883 // Actually apply unscaled font.
1884 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1888 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1890 if ( m_backgroundMode
== wxSOLID
)
1892 unsigned char red
= m_textBackgroundColour
.Red();
1893 unsigned char blue
= m_textBackgroundColour
.Blue();
1894 unsigned char green
= m_textBackgroundColour
.Green();
1895 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1897 double redPS
= (double)(red
) / 255.0;
1898 double bluePS
= (double)(blue
) / 255.0;
1899 double greenPS
= (double)(green
) / 255.0;
1900 double alphaPS
= (double)(alpha
) / 255.0;
1902 cairo_save(m_cairo
);
1903 cairo_translate(m_cairo
, x
, y
);
1904 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1905 cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1906 cairo_rectangle(m_cairo
, 0, 0, w
, h
);
1907 cairo_fill(m_cairo
);
1908 cairo_restore(m_cairo
);
1912 cairo_move_to (m_cairo
, x
, y
);
1913 if (fabs(angle
) > 0.00001)
1915 cairo_save( m_cairo
);
1916 cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1917 pango_cairo_update_layout (m_cairo
, m_layout
);
1918 pango_cairo_show_layout (m_cairo
, m_layout
);
1919 cairo_restore( m_cairo
);
1923 pango_cairo_update_layout (m_cairo
, m_layout
);
1924 pango_cairo_show_layout (m_cairo
, m_layout
);
1930 // Undo underline attributes setting
1931 pango_layout_set_attributes(m_layout
, NULL
);
1934 CalcBoundingBox (x
,y
);
1935 CalcBoundingBox (x
+ w
, y
+ h
);
1938 void wxGtkPrintDC::Clear()
1940 cairo_save(m_cairo
);
1941 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
1942 SetBrush(m_backgroundBrush
);
1943 cairo_paint(m_cairo
);
1944 cairo_restore(m_cairo
);
1947 void wxGtkPrintDC::SetFont( const wxFont
& font
)
1954 pango_font_description_free( m_fontdesc
);
1956 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1958 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1962 void wxGtkPrintDC::SetPen( const wxPen
& pen
)
1964 if (!pen
.Ok()) return;
1968 double width
= (double) m_pen
.GetWidth();
1969 if (width
== 0) width
= 0.1;
1971 cairo_set_line_width( m_cairo
, LogicalToDeviceXRel( (wxCoord
) (1000 * width
)) / 1000.0f
);
1972 static const double dotted
[] = {2.0, 5.0};
1973 static const double short_dashed
[] = {4.0, 4.0};
1974 static const double long_dashed
[] = {4.0, 8.0};
1975 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1977 switch (m_pen
.GetStyle())
1979 case wxDOT
: cairo_set_dash( m_cairo
, dotted
, 1, 0 ); break;
1980 case wxSHORT_DASH
: cairo_set_dash( m_cairo
, short_dashed
, 1, 0 ); break;
1981 case wxLONG_DASH
: cairo_set_dash( m_cairo
, long_dashed
, 1, 0 ); break;
1982 case wxDOT_DASH
: cairo_set_dash( m_cairo
, dotted_dashed
, 3, 0 ); break;
1986 int num
= m_pen
.GetDashes (&wx_dashes
) - 1;
1987 gdouble
*g_dashes
= g_new( gdouble
, num
);
1989 for (i
= 0; i
< num
; ++i
)
1990 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1991 cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1997 default: cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
2000 switch (m_pen
.GetCap())
2002 case wxCAP_PROJECTING
: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
2003 case wxCAP_BUTT
: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
2005 default: cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
2008 switch (m_pen
.GetJoin())
2010 case wxJOIN_BEVEL
: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
2011 case wxJOIN_MITER
: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
2013 default: cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
2016 unsigned char red
= m_pen
.GetColour().Red();
2017 unsigned char blue
= m_pen
.GetColour().Blue();
2018 unsigned char green
= m_pen
.GetColour().Green();
2019 unsigned char alpha
= m_pen
.GetColour().Alpha();
2021 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
2023 double redPS
= (double)(red
) / 255.0;
2024 double bluePS
= (double)(blue
) / 255.0;
2025 double greenPS
= (double)(green
) / 255.0;
2026 double alphaPS
= (double)(alpha
) / 255.0;
2028 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
2031 m_currentBlue
= blue
;
2032 m_currentGreen
= green
;
2033 m_currentAlpha
= alpha
;
2037 void wxGtkPrintDC::SetBrush( const wxBrush
& brush
)
2039 if (!brush
.Ok()) return;
2044 unsigned char red
= m_brush
.GetColour().Red();
2045 unsigned char blue
= m_brush
.GetColour().Blue();
2046 unsigned char green
= m_brush
.GetColour().Green();
2047 unsigned char alpha
= m_brush
.GetColour().Alpha();
2049 double redPS
= (double)(red
) / 255.0;
2050 double bluePS
= (double)(blue
) / 255.0;
2051 double greenPS
= (double)(green
) / 255.0;
2052 double alphaPS
= (double)(alpha
) / 255.0;
2054 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
2056 cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
2059 m_currentBlue
= blue
;
2060 m_currentGreen
= green
;
2061 m_currentAlpha
= alpha
;
2064 if (m_brush
.IsHatch())
2067 cairo_surface_t
*surface
;
2068 surface
= cairo_surface_create_similar(cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
2069 cr
= cairo_create(surface
);
2070 cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
2071 cairo_set_line_width(cr
, 1);
2072 cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
2074 switch (m_brush
.GetStyle())
2077 cairo_move_to(cr
, 5, 0);
2078 cairo_line_to(cr
, 5, 10);
2079 cairo_move_to(cr
, 0, 5);
2080 cairo_line_to(cr
, 10, 5);
2082 case wxBDIAGONAL_HATCH
:
2083 cairo_move_to(cr
, 0, 10);
2084 cairo_line_to(cr
, 10, 0);
2086 case wxFDIAGONAL_HATCH
:
2087 cairo_move_to(cr
, 0, 0);
2088 cairo_line_to(cr
, 10, 10);
2090 case wxCROSSDIAG_HATCH
:
2091 cairo_move_to(cr
, 0, 0);
2092 cairo_line_to(cr
, 10, 10);
2093 cairo_move_to(cr
, 10, 0);
2094 cairo_line_to(cr
, 0, 10);
2096 case wxHORIZONTAL_HATCH
:
2097 cairo_move_to(cr
, 0, 5);
2098 cairo_line_to(cr
, 10, 5);
2100 case wxVERTICAL_HATCH
:
2101 cairo_move_to(cr
, 5, 0);
2102 cairo_line_to(cr
, 5, 10);
2105 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
2108 cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
2112 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface (surface
);
2113 cairo_surface_destroy(surface
);
2114 cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
2115 cairo_set_source(m_cairo
, pattern
);
2116 cairo_pattern_destroy(pattern
);
2120 void wxGtkPrintDC::SetLogicalFunction( int function
)
2122 if (function
== wxCLEAR
)
2123 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
2124 else if (function
== wxOR
)
2125 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
2126 else if (function
== wxNO_OP
)
2127 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
2128 else if (function
== wxAND
)
2129 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
2130 else if (function
== wxSET
)
2131 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
2132 else if (function
== wxXOR
)
2133 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
2134 else // wxCOPY or anything else.
2135 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
2138 void wxGtkPrintDC::SetBackground( const wxBrush
& brush
)
2140 m_backgroundBrush
= brush
;
2141 cairo_save(m_cairo
);
2142 cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2144 SetBrush(m_backgroundBrush
);
2145 cairo_paint(m_cairo
);
2146 cairo_restore(m_cairo
);
2149 void wxGtkPrintDC::SetBackgroundMode(int mode
)
2151 if (mode
== wxSOLID
) m_backgroundMode
= wxSOLID
;
2152 else m_backgroundMode
= wxTRANSPARENT
;
2155 void wxGtkPrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2157 cairo_rectangle ( m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
), LogicalToDeviceXRel(width
), LogicalToDeviceYRel(height
));
2158 cairo_clip(m_cairo
);
2161 void wxGtkPrintDC::DestroyClippingRegion()
2163 cairo_reset_clip(m_cairo
);
2166 bool wxGtkPrintDC::StartDoc(const wxString
& message
)
2171 void wxGtkPrintDC::EndDoc()
2176 void wxGtkPrintDC::StartPage()
2181 void wxGtkPrintDC::EndPage()
2186 wxCoord
wxGtkPrintDC::GetCharHeight() const
2188 pango_layout_set_text( m_layout
, "H", 1 );
2191 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2193 return DeviceToLogicalYRel(h
);
2196 wxCoord
wxGtkPrintDC::GetCharWidth() const
2198 pango_layout_set_text( m_layout
, "H", 1 );
2201 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2203 return DeviceToLogicalXRel(w
);
2206 void wxGtkPrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2208 wxCoord
*externalLeading
,
2209 const wxFont
*theFont
) const
2217 if ( externalLeading
)
2218 *externalLeading
= 0;
2225 // Set layout's text
2226 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
2227 #if wxUSE_UNICODE_UTF8
2228 const char *dataUTF8
= string
.utf8_str();
2230 const wxCharBuffer dataUTF8
= string
.utf8_str();
2233 PangoFontDescription
*desc
= m_fontdesc
;
2234 if (theFont
) desc
= theFont
->GetNativeFontInfo()->description
;
2236 gint oldSize
= pango_font_description_get_size( desc
);
2237 double size
= oldSize
;
2238 size
= size
* m_scaleY
;
2239 pango_font_description_set_size( desc
, (gint
)size
);
2241 // apply scaled font
2242 pango_layout_set_font_description( m_layout
, desc
);
2244 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2247 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2250 *width
= (wxCoord
)(w
/ m_scaleX
);
2252 *height
= (wxCoord
)(h
/ m_scaleY
);
2255 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2256 int baseline
= pango_layout_iter_get_baseline(iter
);
2257 pango_layout_iter_free(iter
);
2258 *descent
= h
- PANGO_PIXELS(baseline
);
2261 // Reset unscaled size.
2262 pango_font_description_set_size( desc
, oldSize
);
2264 // Reset unscaled font.
2265 pango_layout_set_font_description( m_layout
, m_fontdesc
);
2268 void wxGtkPrintDC::DoGetSize(int* width
, int* height
) const
2271 *width
= (int) (gtk_print_context_get_width( m_gpc
) + 0.5);
2273 *height
= (int) (gtk_print_context_get_height( m_gpc
) + 0.5);
2276 void wxGtkPrintDC::DoGetSizeMM(int *width
, int *height
) const
2278 // This function takes margins into consideration.
2279 gdouble w
= gtk_page_setup_get_page_width( gtk_print_context_get_page_setup( m_gpc
), GTK_UNIT_MM
);
2280 gdouble h
= gtk_page_setup_get_page_height( gtk_print_context_get_page_setup( m_gpc
), GTK_UNIT_MM
);
2283 *width
= (int) (w
+ 0.5);
2285 *height
= (int) (h
+ 0.5);
2288 wxSize
wxGtkPrintDC::GetPPI() const
2290 gdouble xDpi
= gtk_print_context_get_dpi_x( m_gpc
);
2291 gdouble yDpi
= gtk_print_context_get_dpi_y( m_gpc
);
2292 return wxSize((int) xDpi
,(int) yDpi
);
2295 void wxGtkPrintDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
2297 wxDC::SetLogicalOrigin( x
, y
);
2300 void wxGtkPrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
2302 wxDC::SetDeviceOrigin( x
, y
);
2305 void wxGtkPrintDC::SetPrintData(const wxPrintData
& data
)
2309 if (m_printData
.GetOrientation() == wxPORTRAIT
)
2310 GetSize( &m_deviceOffsetX
, &m_deviceOffsetY
);
2312 GetSize( &m_deviceOffsetY
, &m_deviceOffsetX
);
2315 void wxGtkPrintDC::SetResolution(int ppi
)
2317 // We can't change ppi of the GtkPrintContext.
2318 ms_resolution
= ppi
;
2321 int wxGtkPrintDC::GetResolution()
2323 return ms_resolution
;
2326 // ----------------------------------------------------------------------------
2328 // ----------------------------------------------------------------------------
2330 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2332 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2333 wxPrintout
* WXUNUSED(printoutForPrinting
))
2338 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2339 wxPrintout
*printoutForPrinting
,
2340 wxPrintDialogData
*data
)
2341 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2343 Init(printout
, printoutForPrinting
);
2346 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2347 wxPrintout
*printoutForPrinting
,
2349 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2351 Init(printout
, printoutForPrinting
);
2354 wxGtkPrintPreview::~wxGtkPrintPreview()
2358 bool wxGtkPrintPreview::Print(bool interactive
)
2360 if (!m_printPrintout
)
2363 wxPrinter
printer(& m_printDialogData
);
2364 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2367 void wxGtkPrintPreview::DetermineScaling()
2369 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2371 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2373 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2377 wxSize ScreenPixels
= wxGetDisplaySize();
2378 wxSize ScreenMM
= wxGetDisplaySizeMM();
2380 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2381 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2382 m_previewPrintout
->SetPPIPrinter(wxGtkPrintDC::GetResolution(), wxGtkPrintDC::GetResolution());
2383 // Get width and height in points (1/72th of an inch)
2384 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2386 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxGtkPrintDC::GetResolution() / 72.0);
2387 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxGtkPrintDC::GetResolution() / 72.0);
2388 wxSize
sizeTenthsMM(paper
->GetSize());
2389 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2391 // If in landscape mode, we need to swap the width and height.
2392 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2394 m_pageWidth
= sizeDevUnits
.y
;
2395 m_pageHeight
= sizeDevUnits
.x
;
2396 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2400 m_pageWidth
= sizeDevUnits
.x
;
2401 m_pageHeight
= sizeDevUnits
.y
;
2402 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2404 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2405 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2407 // At 100%, the page should look about page-size on the screen.
2408 m_previewScaleX
= (float)0.8 * 72.0 / (float)wxGtkPrintDC::GetResolution();
2409 m_previewScaleY
= m_previewScaleX
;