1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/print.cpp
3 // Author: Anthony Bretaudeau
4 // Purpose: GTK printing support
6 // RCS-ID: $Id: print.cpp,v 1 2007-08-25 05:44:44 PC Exp $
7 // Copyright: (c) 2007 wxWidgets development team
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/gtk/print.h"
24 #include "wx/dcmemory.h"
25 #include "wx/dcprint.h"
29 #include "wx/module.h"
33 #include "wx/fontutil.h"
34 #include "wx/gtk/private.h"
35 #include "wx/dynlib.h"
37 #include "wx/rawbmp.h"
40 #include <gtk/gtkpagesetupunixdialog.h>
42 #if wxUSE_GRAPHICS_CONTEXT
43 #include "wx/graphics.h"
47 wxFORCE_LINK_THIS_MODULE(gtk_print
)
49 #if wxUSE_LIBGNOMEPRINT
50 #include "wx/gtk/gnome/gprint.h"
53 // Usefull to convert angles from/to Rad to/from Deg.
54 static const double RAD2DEG
= 180.0 / M_PI
;
55 static const double DEG2RAD
= M_PI
/ 180.0;
57 static wxCairoLibrary
* gs_cairo
= NULL
;
59 //----------------------------------------------------------------------------
61 // Initialized when starting the app : if it successfully load the gtk-print framework,
62 // it uses it. If not, it falls back to gnome print (see /gtk/gnome/gprint.cpp) then
63 // to postscript if gnomeprint is not available.
64 //----------------------------------------------------------------------------
66 class wxGtkPrintModule
: public wxModule
71 #if wxUSE_LIBGNOMEPRINT
72 // This module must be initialized AFTER gnomeprint's one
73 AddDependency(CLASSINFO(wxGnomePrintModule
));
80 DECLARE_DYNAMIC_CLASS(wxGtkPrintModule
)
83 bool wxGtkPrintModule::OnInit()
85 gs_cairo
= wxCairoLibrary::Get();
86 if (gs_cairo
&& gtk_check_version(2,10,0) == NULL
)
87 wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory
);
91 void wxGtkPrintModule::OnExit()
96 IMPLEMENT_DYNAMIC_CLASS(wxGtkPrintModule
, wxModule
)
98 //----------------------------------------------------------------------------
100 //----------------------------------------------------------------------------
102 wxPrinterBase
* wxGtkPrintFactory::CreatePrinter( wxPrintDialogData
*data
)
104 return new wxGtkPrinter( data
);
107 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
108 wxPrintout
*printout
,
109 wxPrintDialogData
*data
)
111 return new wxGtkPrintPreview( preview
, printout
, data
);
114 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
115 wxPrintout
*printout
,
118 return new wxGtkPrintPreview( preview
, printout
, data
);
121 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
122 wxPrintDialogData
*data
)
124 return new wxGtkPrintDialog( parent
, data
);
127 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
130 return new wxGtkPrintDialog( parent
, data
);
133 wxPageSetupDialogBase
*wxGtkPrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
134 wxPageSetupDialogData
* data
)
136 return new wxGtkPageSetupDialog( parent
, data
);
139 bool wxGtkPrintFactory::HasPrintSetupDialog()
145 wxGtkPrintFactory::CreatePrintSetupDialog(wxWindow
* WXUNUSED(parent
),
146 wxPrintData
* WXUNUSED(data
))
151 wxDCImpl
* wxGtkPrintFactory::CreatePrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
)
153 return new wxGtkPrinterDCImpl( owner
, data
);
156 bool wxGtkPrintFactory::HasOwnPrintToFile()
161 bool wxGtkPrintFactory::HasPrinterLine()
166 wxString
wxGtkPrintFactory::CreatePrinterLine()
169 return wxEmptyString
;
172 bool wxGtkPrintFactory::HasStatusLine()
178 wxString
wxGtkPrintFactory::CreateStatusLine()
181 return wxEmptyString
;
184 wxPrintNativeDataBase
*wxGtkPrintFactory::CreatePrintNativeData()
186 return new wxGtkPrintNativeData
;
189 //----------------------------------------------------------------------------
190 // Callback functions for Gtk Printings.
191 //----------------------------------------------------------------------------
193 // We use it to pass useful objects to GTK printing callback functions.
194 struct wxPrinterToGtkData
196 wxGtkPrinter
* printer
;
197 wxPrintout
* printout
;
202 static void gtk_begin_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
204 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
206 data
->printer
->BeginPrint(data
->printout
, operation
, context
);
209 static void gtk_draw_page_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gint page_nr
, gpointer user_data
)
211 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
213 data
->printer
->DrawPage(data
->printout
, operation
, context
, page_nr
);
216 static void gtk_end_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
217 GtkPrintContext
* WXUNUSED(context
),
220 wxPrintout
*printout
= (wxPrintout
*) user_data
;
222 printout
->OnEndPrinting();
226 gtk_preview_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
227 GtkPrintOperationPreview
* WXUNUSED(preview
),
228 GtkPrintContext
*context
,
232 wxPrintout
*printout
= (wxPrintout
*) user_data
;
234 printout
->SetIsPreview(true);
236 /* We create a Cairo context with 72dpi resolution. This resolution is
237 * only used for positioning. */
238 cairo_t
*cairo
= gdk_cairo_create(GTK_WIDGET(parent
)->window
);
239 gtk_print_context_set_cairo_context(context
, cairo
, 72, 72);
245 //----------------------------------------------------------------------------
246 // wxGtkPrintNativeData
247 //----------------------------------------------------------------------------
249 IMPLEMENT_CLASS(wxGtkPrintNativeData
, wxPrintNativeDataBase
)
251 wxGtkPrintNativeData::wxGtkPrintNativeData()
253 m_config
= gtk_print_settings_new();
256 wxGtkPrintNativeData::~wxGtkPrintNativeData()
258 g_object_unref (m_config
);
261 // Convert datas stored in m_config to a wxPrintData.
262 // Called by wxPrintData::ConvertFromNative().
263 bool wxGtkPrintNativeData::TransferTo( wxPrintData
&data
)
268 int resolution
= gtk_print_settings_get_resolution(m_config
);
269 if ( resolution
> 0 )
271 // if resolution is explicitly set, use it
272 data
.SetQuality(resolution
);
274 else // use more vague "quality"
276 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
277 if (quality
== GTK_PRINT_QUALITY_HIGH
)
278 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
279 else if (quality
== GTK_PRINT_QUALITY_LOW
)
280 data
.SetQuality(wxPRINT_QUALITY_LOW
);
281 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
282 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
284 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
287 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
289 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
291 switch (gtk_print_settings_get_duplex(m_config
))
293 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
296 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
300 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
304 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
305 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
307 data
.SetOrientation(wxPORTRAIT
);
308 data
.SetOrientationReversed(false);
310 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
312 data
.SetOrientation(wxLANDSCAPE
);
313 data
.SetOrientationReversed(false);
315 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
317 data
.SetOrientation(wxPORTRAIT
);
318 data
.SetOrientationReversed(true);
320 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
322 data
.SetOrientation(wxLANDSCAPE
);
323 data
.SetOrientationReversed(true);
326 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
328 // Paper formats : these are the most common paper formats.
329 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
331 data
.SetPaperId(wxPAPER_NONE
);
332 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
333 data
.SetPaperId(wxPAPER_A3
);
334 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
335 data
.SetPaperId(wxPAPER_A4
);
336 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
337 data
.SetPaperId(wxPAPER_A5
);
338 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
339 data
.SetPaperId(wxPAPER_B5
);
340 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
341 data
.SetPaperId(wxPAPER_LETTER
);
342 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
343 data
.SetPaperId(wxPAPER_LEGAL
);
344 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
345 data
.SetPaperId(wxPAPER_EXECUTIVE
);
346 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
347 data
.SetPaperId(wxPAPER_ENV_10
);
348 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
349 data
.SetPaperId(wxPAPER_ENV_C5
);
350 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
351 data
.SetPaperId(wxPAPER_ENV_C6
);
352 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
353 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
354 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
355 data
.SetPaperId(wxPAPER_ENV_B5
);
356 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
357 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
358 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
359 data
.SetPaperId( wxPAPER_CSHEET
);
360 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
361 data
.SetPaperId( wxPAPER_DSHEET
);
362 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
363 data
.SetPaperId( wxPAPER_ESHEET
);
364 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
365 data
.SetPaperId( wxPAPER_LETTERSMALL
);
366 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
367 data
.SetPaperId( wxPAPER_TABLOID
);
368 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
369 data
.SetPaperId( wxPAPER_LEDGER
);
370 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
371 data
.SetPaperId( wxPAPER_STATEMENT
);
372 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
373 data
.SetPaperId( wxPAPER_A4SMALL
);
374 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
375 data
.SetPaperId( wxPAPER_B4
);
376 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
377 data
.SetPaperId( wxPAPER_FOLIO
);
378 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
379 data
.SetPaperId( wxPAPER_QUARTO
);
380 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
381 data
.SetPaperId( wxPAPER_10X14
);
382 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
383 data
.SetPaperId( wxPAPER_11X17
);
384 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
385 data
.SetPaperId( wxPAPER_NOTE
);
386 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
387 data
.SetPaperId( wxPAPER_ENV_9
);
388 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
389 data
.SetPaperId( wxPAPER_ENV_11
);
390 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
391 data
.SetPaperId( wxPAPER_ENV_12
);
392 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
393 data
.SetPaperId( wxPAPER_ENV_14
);
394 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
395 data
.SetPaperId( wxPAPER_ENV_DL
);
396 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
397 data
.SetPaperId( wxPAPER_ENV_C3
);
398 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
399 data
.SetPaperId( wxPAPER_ENV_C4
);
400 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
401 data
.SetPaperId( wxPAPER_ENV_C65
);
402 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
403 data
.SetPaperId( wxPAPER_ENV_B4
);
404 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
405 data
.SetPaperId( wxPAPER_ENV_B6
);
406 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
407 data
.SetPaperId( wxPAPER_ENV_ITALY
);
408 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
409 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
410 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
411 data
.SetPaperId( wxPAPER_FANFOLD_US
);
412 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
413 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
414 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
415 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
417 data
.SetPaperId(wxPAPER_NONE
);
421 // Put datas given by the wxPrintData into m_config.
422 // Called by wxPrintData::ConvertToNative().
423 bool wxGtkPrintNativeData::TransferFrom( const wxPrintData
&data
)
428 wxPrintQuality quality
= data
.GetQuality();
429 if (quality
== wxPRINT_QUALITY_HIGH
)
430 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
431 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
432 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
433 else if (quality
== wxPRINT_QUALITY_LOW
)
434 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
435 else if (quality
== wxPRINT_QUALITY_DRAFT
)
436 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
437 else if (quality
> 1)
438 gtk_print_settings_set_resolution (m_config
, quality
);
440 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
442 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
444 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
446 switch (data
.GetDuplex())
448 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
451 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
455 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
459 if (!data
.IsOrientationReversed())
461 if (data
.GetOrientation() == wxLANDSCAPE
)
462 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
464 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
467 if (data
.GetOrientation() == wxLANDSCAPE
)
468 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
470 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
473 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
475 // Paper formats: these are the most common paper formats.
476 switch (data
.GetPaperId())
478 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
480 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
482 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
484 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
486 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
488 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
490 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
492 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
494 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
496 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
498 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
500 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
502 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
504 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
506 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
508 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
510 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
512 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
514 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
516 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
518 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
520 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
522 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
524 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
526 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
528 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
530 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
532 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
534 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
536 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
538 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
540 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
542 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
544 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
546 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
548 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
550 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
552 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
554 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
556 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
558 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
560 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
569 void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings
* config
)
572 m_config
= gtk_print_settings_copy(config
);
575 // Extract page setup from settings.
576 GtkPageSetup
* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
578 GtkPageSetup
* page_setup
= gtk_page_setup_new();
579 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
581 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
582 if (paper_size
!= NULL
)
583 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
588 // Insert page setup into a given GtkPrintSettings.
589 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
591 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
592 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
595 //----------------------------------------------------------------------------
597 //----------------------------------------------------------------------------
599 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
601 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
602 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
603 wxPoint(0, 0), wxSize(600, 600),
604 wxDEFAULT_DIALOG_STYLE
|
608 m_printDialogData
= *data
;
614 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
615 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
616 wxPoint(0, 0), wxSize(600, 600),
617 wxDEFAULT_DIALOG_STYLE
|
621 m_printDialogData
= *data
;
628 wxGtkPrintDialog::~wxGtkPrintDialog()
632 // This is called even if we actually don't want the dialog to appear.
633 int wxGtkPrintDialog::ShowModal()
635 GtkPrintOperationResult response
;
637 // We need to restore the settings given in the constructor.
638 wxPrintData data
= m_printDialogData
.GetPrintData();
639 wxGtkPrintNativeData
*native
=
640 (wxGtkPrintNativeData
*) data
.GetNativeData();
641 data
.ConvertToNative();
643 GtkPrintSettings
* settings
= native
->GetPrintConfig();
645 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
646 int fromPage
= m_printDialogData
.GetFromPage();
647 int toPage
= m_printDialogData
.GetToPage();
648 if (m_printDialogData
.GetSelection())
649 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
650 else if (m_printDialogData
.GetAllPages())
651 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
653 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
655 range
= g_new (GtkPageRange
, 1);
656 range
[0].start
= fromPage
-1;
657 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
658 gtk_print_settings_set_page_ranges (settings
, range
, 1);
661 // If the settings are OK, we restore it.
662 if (settings
!= NULL
)
663 gtk_print_operation_set_print_settings (native
->GetPrintJob(), settings
);
664 gtk_print_operation_set_default_page_setup (native
->GetPrintJob(), native
->GetPageSetupFromSettings(settings
));
666 // Show the dialog if needed.
667 GError
* gError
= NULL
;
669 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
671 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
)), &gError
);
673 // Does everything went well?
674 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
678 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
680 g_error_free (gError
);
681 wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError
->message
));
682 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
685 // Now get the settings and save it.
686 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings (native
->GetPrintJob());
687 native
->SetPrintConfig(newSettings
);
688 data
.ConvertFromNative();
690 // Same problem as a few lines before.
691 switch (gtk_print_settings_get_print_pages(newSettings
))
693 case GTK_PRINT_PAGES_CURRENT
:
694 m_printDialogData
.SetSelection( true );
696 case GTK_PRINT_PAGES_RANGES
:
697 {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
698 // For example, the user enters "1-3;5-7" in the dialog: pages 1-3 and 5-7 will be correctly printed when the user
699 // will hit "OK" button. However we can only save 1-3 in the print data.
702 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
705 m_printDialogData
.SetFromPage( range
[0].start
);
706 m_printDialogData
.SetToPage( range
[0].end
);
709 m_printDialogData
.SetAllPages( true );
710 m_printDialogData
.SetFromPage( 0 );
711 m_printDialogData
.SetToPage( 9999 );
714 case GTK_PRINT_PAGES_ALL
:
716 m_printDialogData
.SetAllPages( true );
717 m_printDialogData
.SetFromPage( 0 );
718 m_printDialogData
.SetToPage( 9999 );
725 //----------------------------------------------------------------------------
726 // wxGtkPageSetupDialog
727 //----------------------------------------------------------------------------
729 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
731 wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow
*parent
,
732 wxPageSetupDialogData
* data
)
735 m_pageDialogData
= *data
;
740 wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
744 int wxGtkPageSetupDialog::ShowModal()
747 m_pageDialogData
.GetPrintData().ConvertToNative();
748 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
749 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
751 // We only need the pagesetup data which are part of the settings.
752 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
754 // If the user used a custom paper format the last time he printed, we have to restore it too.
755 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
757 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
758 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
760 wxString title
= _("Custom size");
761 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
762 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
763 g_object_unref(customSize
);
767 // Now show the dialog.
768 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
773 if (newPageSetup
!= oldPageSetup
)
775 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
776 m_pageDialogData
.GetPrintData().ConvertFromNative();
778 // Store custom paper format if any.
779 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
781 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
782 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
783 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
784 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
785 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
787 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
788 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
790 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
791 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
793 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
806 //----------------------------------------------------------------------------
808 //----------------------------------------------------------------------------
810 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
812 wxGtkPrinter::wxGtkPrinter( wxPrintDialogData
*data
) :
813 wxPrinterBase( data
)
818 m_printDialogData
= *data
;
821 wxGtkPrinter::~wxGtkPrinter()
825 bool wxGtkPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
829 sm_lastError
= wxPRINTER_ERROR
;
833 // Let's correct the PageInfo just in case the app gives wrong values.
834 int fromPage
, toPage
;
835 int minPage
, maxPage
;
836 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
837 m_printDialogData
.SetAllPages(true);
839 if (minPage
< 1) minPage
= 1;
840 if (maxPage
< 1) maxPage
= 9999;
841 if (maxPage
< minPage
) maxPage
= minPage
;
843 m_printDialogData
.SetMinPage(minPage
);
844 m_printDialogData
.SetMaxPage(maxPage
);
847 if (fromPage
< minPage
) fromPage
= minPage
;
848 else if (fromPage
> maxPage
) fromPage
= maxPage
;
849 m_printDialogData
.SetFromPage(fromPage
);
853 m_printDialogData
.SetToPage(toPage
);
854 if (toPage
> maxPage
) toPage
= maxPage
;
855 else if (toPage
< minPage
) toPage
= minPage
;
858 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
861 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
862 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
864 GtkPrintOperation
*printOp
= gtk_print_operation_new ();
866 native
->SetPrintJob( printOp
);
868 printout
->SetIsPreview(false);
870 wxPrinterToGtkData dataToSend
;
871 dataToSend
.printer
= this;
872 dataToSend
.printout
= printout
;
874 // These Gtk signals are caught here.
875 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
876 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
877 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
878 g_signal_connect (printOp
, "preview", G_CALLBACK (gtk_preview_print_callback
), printout
);
880 // This is used to setup the DC and
881 // show the dialog if desired
882 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
883 dialog
.SetPrintDC(m_dc
);
884 dialog
.SetShowDialog(prompt
);
886 // doesn't necessarily show
887 int ret
= dialog
.ShowModal();
888 if (ret
== wxID_CANCEL
)
890 sm_lastError
= wxPRINTER_CANCELLED
;
894 sm_lastError
= wxPRINTER_ERROR
;
895 wxFAIL_MSG(_("The print dialog returned an error."));
898 g_object_unref (printOp
);
900 return (sm_lastError
== wxPRINTER_NO_ERROR
);
903 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
905 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
906 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
908 // We need to update printdata with the new data from the dialog and we
909 // have to do this here because this method needs this new data and we
910 // cannot update it earlier
911 native
->SetPrintConfig(gtk_print_operation_get_print_settings(operation
));
912 printdata
.ConvertFromNative();
914 SetPrintContext(context
);
915 native
->SetPrintContext( context
);
917 wxPrinterDC
*printDC
= new wxPrinterDC( printdata
);
922 if (sm_lastError
!= wxPRINTER_CANCELLED
)
924 sm_lastError
= wxPRINTER_ERROR
;
925 wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used."));
929 wxSize ScreenPixels
= wxGetDisplaySize();
930 wxSize ScreenMM
= wxGetDisplaySizeMM();
932 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
933 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
934 printout
->SetPPIPrinter( printDC
->GetResolution(),
935 printDC
->GetResolution() );
937 printout
->SetDC(m_dc
);
940 m_dc
->GetSize(&w
, &h
);
941 printout
->SetPageSizePixels((int)w
, (int)h
);
942 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
944 m_dc
->GetSizeMM(&mw
, &mh
);
945 printout
->SetPageSizeMM((int)mw
, (int)mh
);
946 printout
->OnPreparePrinting();
948 // Get some parameters from the printout, if defined.
949 int fromPage
, toPage
;
950 int minPage
, maxPage
;
951 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
955 sm_lastError
= wxPRINTER_ERROR
;
956 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
960 printout
->OnBeginPrinting();
964 // If we're not previewing we need to calculate the number of pages to print.
965 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
966 // have defined in the dialog. So the number of pages is the maximum available.
967 if (!printout
->IsPreview())
969 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
970 switch (gtk_print_settings_get_print_pages(settings
))
972 case GTK_PRINT_PAGES_CURRENT
:
975 case GTK_PRINT_PAGES_RANGES
:
976 {gint num_ranges
= 0;
979 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
980 for (i
=0; i
<num_ranges
; i
++)
982 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
983 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
984 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
985 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
986 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
988 gtk_print_settings_set_page_ranges (settings
, range
, 1);
990 case GTK_PRINT_PAGES_ALL
:
992 numPages
= maxPage
- minPage
+ 1;
996 else numPages
= maxPage
- minPage
+ 1;
998 gtk_print_operation_set_n_pages(operation
, numPages
);
1001 void wxGtkPrinter::DrawPage(wxPrintout
*printout
,
1002 GtkPrintOperation
*operation
,
1003 GtkPrintContext
* WXUNUSED(context
),
1006 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
1007 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
1009 int numPageToDraw
= page_nr
+ minPage
;
1010 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
1011 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
1013 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
1014 switch (gtk_print_settings_get_print_pages(settings
))
1016 case GTK_PRINT_PAGES_CURRENT
:
1017 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
1018 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
1020 case GTK_PRINT_PAGES_RANGES
:
1021 {gint num_ranges
= 0;
1022 GtkPageRange
* range
;
1023 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
1024 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
1025 if (num_ranges
>= 1)
1027 startPage
= range
[0].start
+ 1;
1028 endPage
= range
[0].end
+ 1;
1031 startPage
= minPage
;
1035 case GTK_PRINT_PAGES_ALL
:
1037 startPage
= minPage
;
1042 if(numPageToDraw
== startPage
)
1044 if (!printout
->OnBeginDocument(startPage
, endPage
))
1046 wxLogError(_("Could not start printing."));
1047 sm_lastError
= wxPRINTER_ERROR
;
1051 // The app can render the page numPageToDraw.
1052 if (printout
->HasPage(numPageToDraw
))
1055 printout
->OnPrintPage(numPageToDraw
);
1060 if(numPageToDraw
== endPage
)
1062 printout
->OnEndDocument();
1066 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1068 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1070 dialog
.SetPrintDC(m_dc
);
1071 dialog
.SetShowDialog(true);
1073 int ret
= dialog
.ShowModal();
1075 if (ret
== wxID_CANCEL
)
1077 sm_lastError
= wxPRINTER_CANCELLED
;
1082 sm_lastError
= wxPRINTER_ERROR
;
1083 wxFAIL_MSG(_("The print dialog returned an error."));
1087 m_printDialogData
= dialog
.GetPrintDialogData();
1089 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
1092 bool wxGtkPrinter::Setup( wxWindow
* WXUNUSED(parent
) )
1094 // Obsolete, for backward compatibility.
1098 //-----------------------------------------------------------------------------
1100 //-----------------------------------------------------------------------------
1102 #define wxCAIRO_SCALE 1
1106 #define XLOG2DEV(x) LogicalToDeviceX(x)
1107 #define XLOG2DEVREL(x) LogicalToDeviceXRel(x)
1108 #define YLOG2DEV(x) LogicalToDeviceY(x)
1109 #define YLOG2DEVREL(x) LogicalToDeviceYRel(x)
1113 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
1114 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
1115 #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
1116 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
1120 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl
, wxDCImpl
)
1122 wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC
*owner
, const wxPrintData
& data
)
1127 wxGtkPrintNativeData
*native
=
1128 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1130 m_gpc
= native
->GetPrintContext();
1132 // Match print quality to resolution (high = 1200dpi)
1133 m_resolution
= m_printData
.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
1134 if (m_resolution
< 0)
1135 m_resolution
= (1 << (m_resolution
+4)) *150;
1137 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1138 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1139 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1141 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1147 gs_cairo
->cairo_scale( m_cairo
, 72.0 / (double)m_resolution
, 72.0 / (double)m_resolution
);
1149 m_PS2DEV
= (double)m_resolution
/ 72.0;
1150 m_DEV2PS
= 72.0 / (double)m_resolution
;
1157 m_signX
= 1; // default x-axis left to right.
1158 m_signY
= 1; // default y-axis bottom up -> top down.
1160 // By default the origin of the Cairo context is in the upper left
1161 // corner of the printable area. We need to translate it so that it
1162 // is in the upper left corner of the paper (without margins)
1163 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
1165 ml
= gtk_page_setup_get_left_margin (setup
, GTK_UNIT_POINTS
);
1166 mt
= gtk_page_setup_get_top_margin (setup
, GTK_UNIT_POINTS
);
1167 gs_cairo
->cairo_translate(m_cairo
, -ml
, -mt
);
1170 wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
1172 g_object_unref(m_context
);
1173 g_object_unref(m_layout
);
1176 bool wxGtkPrinterDCImpl::IsOk() const
1178 return m_gpc
!= NULL
;
1181 void* wxGtkPrinterDCImpl::GetCairoContext() const
1183 return (void*) cairo_reference( m_cairo
);
1186 bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord
WXUNUSED(x1
),
1187 wxCoord
WXUNUSED(y1
),
1188 const wxColour
& WXUNUSED(col
),
1189 int WXUNUSED(style
))
1191 // We can't access the given coord as a Cairo context is scalable, ie a
1192 // coord doesn't mean anything in this context.
1193 wxFAIL_MSG(_("not implemented"));
1197 void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1199 wxCoord xC
= circleCenter
.x
;
1200 wxCoord yC
= circleCenter
.y
;
1201 wxCoord xR
= rect
.x
;
1202 wxCoord yR
= rect
.y
;
1203 wxCoord w
= rect
.width
;
1204 wxCoord h
= rect
.height
;
1206 double radius
= sqrt((w
/2)*(w
/2)+(h
/2)*(h
/2));
1208 unsigned char redI
= initialColour
.Red();
1209 unsigned char blueI
= initialColour
.Blue();
1210 unsigned char greenI
= initialColour
.Green();
1211 unsigned char alphaI
= initialColour
.Alpha();
1212 unsigned char redD
= destColour
.Red();
1213 unsigned char blueD
= destColour
.Blue();
1214 unsigned char greenD
= destColour
.Green();
1215 unsigned char alphaD
= destColour
.Alpha();
1217 double redIPS
= (double)(redI
) / 255.0;
1218 double blueIPS
= (double)(blueI
) / 255.0;
1219 double greenIPS
= (double)(greenI
) / 255.0;
1220 double alphaIPS
= (double)(alphaI
) / 255.0;
1221 double redDPS
= (double)(redD
) / 255.0;
1222 double blueDPS
= (double)(blueD
) / 255.0;
1223 double greenDPS
= (double)(greenD
) / 255.0;
1224 double alphaDPS
= (double)(alphaD
) / 255.0;
1226 // Create a pattern with the gradient.
1227 cairo_pattern_t
* gradient
;
1228 gradient
= gs_cairo
->cairo_pattern_create_radial (XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), 0, XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), radius
* m_DEV2PS
);
1229 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1230 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1232 // Fill the rectangle with this pattern.
1233 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1234 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(xR
), YLOG2DEV(yR
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1235 gs_cairo
->cairo_fill(m_cairo
);
1237 gs_cairo
->cairo_pattern_destroy(gradient
);
1239 CalcBoundingBox(xR
, yR
);
1240 CalcBoundingBox(xR
+w
, yR
+h
);
1243 void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1247 wxCoord w
= rect
.width
;
1248 wxCoord h
= rect
.height
;
1250 unsigned char redI
= initialColour
.Red();
1251 unsigned char blueI
= initialColour
.Blue();
1252 unsigned char greenI
= initialColour
.Green();
1253 unsigned char alphaI
= initialColour
.Alpha();
1254 unsigned char redD
= destColour
.Red();
1255 unsigned char blueD
= destColour
.Blue();
1256 unsigned char greenD
= destColour
.Green();
1257 unsigned char alphaD
= destColour
.Alpha();
1259 double redIPS
= (double)(redI
) / 255.0;
1260 double blueIPS
= (double)(blueI
) / 255.0;
1261 double greenIPS
= (double)(greenI
) / 255.0;
1262 double alphaIPS
= (double)(alphaI
) / 255.0;
1263 double redDPS
= (double)(redD
) / 255.0;
1264 double blueDPS
= (double)(blueD
) / 255.0;
1265 double greenDPS
= (double)(greenD
) / 255.0;
1266 double alphaDPS
= (double)(alphaD
) / 255.0;
1268 // Create a pattern with the gradient.
1269 cairo_pattern_t
* gradient
;
1270 gradient
= gs_cairo
->cairo_pattern_create_linear (XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x
+w
), YLOG2DEV(y
));
1272 if (nDirection
== wxWEST
)
1274 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1275 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1278 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1279 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1282 // Fill the rectangle with this pattern.
1283 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1284 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1285 gs_cairo
->cairo_fill(m_cairo
);
1287 gs_cairo
->cairo_pattern_destroy(gradient
);
1289 CalcBoundingBox(x
, y
);
1290 CalcBoundingBox(x
+w
, y
+h
);
1293 bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord
WXUNUSED(x1
),
1294 wxCoord
WXUNUSED(y1
),
1295 wxColour
* WXUNUSED(col
)) const
1297 wxFAIL_MSG(_("not implemented"));
1301 void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1303 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1306 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1307 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1308 gs_cairo
->cairo_stroke ( m_cairo
);
1310 CalcBoundingBox( x1
, y1
);
1311 CalcBoundingBox( x2
, y2
);
1314 void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x
, wxCoord y
)
1321 gs_cairo
->cairo_move_to (m_cairo
, XLOG2DEV(x
), 0);
1322 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEV(x
), YLOG2DEVREL(h
));
1323 gs_cairo
->cairo_move_to (m_cairo
, 0, YLOG2DEV(y
));
1324 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEVREL(w
), YLOG2DEV(y
));
1326 gs_cairo
->cairo_stroke (m_cairo
);
1327 CalcBoundingBox( 0, 0 );
1328 CalcBoundingBox( w
, h
);
1331 void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1333 double dx
= x1
- xc
;
1334 double dy
= y1
- yc
;
1335 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1337 double alpha1
, alpha2
;
1338 if (x1
== x2
&& y1
== y2
)
1346 alpha1
= alpha2
= 0.0;
1350 alpha1
= (x1
- xc
== 0) ?
1351 (y1
- yc
< 0) ? 90.0 : -90.0 :
1352 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1353 alpha2
= (x2
- xc
== 0) ?
1354 (y2
- yc
< 0) ? 90.0 : -90.0 :
1355 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1357 while (alpha1
<= 0) alpha1
+= 360;
1358 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1359 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1360 while (alpha2
> 360) alpha2
-= 360;
1366 gs_cairo
->cairo_new_path(m_cairo
);
1368 gs_cairo
->cairo_arc_negative ( m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
);
1369 gs_cairo
->cairo_line_to(m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
));
1370 gs_cairo
->cairo_close_path (m_cairo
);
1372 SetBrush( m_brush
);
1373 gs_cairo
->cairo_fill_preserve( m_cairo
);
1376 gs_cairo
->cairo_stroke( m_cairo
);
1378 CalcBoundingBox (x1
, y1
);
1379 CalcBoundingBox (xc
, yc
);
1380 CalcBoundingBox (x2
, y2
);
1383 void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1385 gs_cairo
->cairo_save( m_cairo
);
1387 gs_cairo
->cairo_new_path(m_cairo
);
1389 gs_cairo
->cairo_translate( m_cairo
, XLOG2DEV((wxCoord
) (x
+ w
/ 2.)), XLOG2DEV((wxCoord
) (y
+ h
/ 2.)) );
1390 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1391 gs_cairo
->cairo_scale( m_cairo
, 1.0, scale
);
1393 gs_cairo
->cairo_arc_negative ( m_cairo
, 0, 0, XLOG2DEVREL(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1396 gs_cairo
->cairo_stroke_preserve( m_cairo
);
1398 gs_cairo
->cairo_line_to(m_cairo
, 0,0);
1400 SetBrush( m_brush
);
1401 gs_cairo
->cairo_fill( m_cairo
);
1403 gs_cairo
->cairo_restore( m_cairo
);
1405 CalcBoundingBox( x
, y
);
1406 CalcBoundingBox( x
+w
, y
+h
);
1409 void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x
, wxCoord y
)
1411 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1415 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1416 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1417 gs_cairo
->cairo_stroke ( m_cairo
);
1419 CalcBoundingBox( x
, y
);
1422 void wxGtkPrinterDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1424 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
1431 for ( i
=0; i
<n
; i
++ )
1432 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1434 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1436 for (i
= 1; i
< n
; i
++)
1437 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1439 gs_cairo
->cairo_stroke ( m_cairo
);
1442 void wxGtkPrinterDCImpl::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1446 gs_cairo
->cairo_save(m_cairo
);
1447 if (fillStyle
== wxWINDING_RULE
)
1448 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1450 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1452 int x
= points
[0].x
+ xoffset
;
1453 int y
= points
[0].y
+ yoffset
;
1454 gs_cairo
->cairo_new_path(m_cairo
);
1455 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1457 for (i
= 1; i
< n
; i
++)
1459 int x
= points
[i
].x
+ xoffset
;
1460 int y
= points
[i
].y
+ yoffset
;
1461 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1463 gs_cairo
->cairo_close_path(m_cairo
);
1465 SetBrush( m_brush
);
1466 gs_cairo
->cairo_fill_preserve( m_cairo
);
1469 gs_cairo
->cairo_stroke( m_cairo
);
1471 CalcBoundingBox( x
, y
);
1473 gs_cairo
->cairo_restore(m_cairo
);
1476 void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1478 wxDCImpl::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1481 void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1486 gs_cairo
->cairo_new_path(m_cairo
);
1487 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
1489 SetBrush( m_brush
);
1490 gs_cairo
->cairo_fill_preserve( m_cairo
);
1493 gs_cairo
->cairo_stroke( m_cairo
);
1495 CalcBoundingBox( x
, y
);
1496 CalcBoundingBox( x
+ width
, y
+ height
);
1499 void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1504 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1506 wxCoord dd
= 2 * (wxCoord
) radius
;
1507 if (dd
> width
) dd
= width
;
1508 if (dd
> height
) dd
= height
;
1511 wxCoord rad
= (wxCoord
) radius
;
1513 gs_cairo
->cairo_new_path(m_cairo
);
1514 gs_cairo
->cairo_move_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1515 gs_cairo
->cairo_curve_to(m_cairo
,
1516 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1517 XLOG2DEV(x
),YLOG2DEV(y
),
1518 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1519 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1520 gs_cairo
->cairo_curve_to(m_cairo
,
1521 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1522 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1523 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1524 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1525 gs_cairo
->cairo_curve_to(m_cairo
,
1526 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1527 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1528 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1529 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1530 gs_cairo
->cairo_curve_to(m_cairo
,
1531 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1532 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1533 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1534 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1535 gs_cairo
->cairo_close_path(m_cairo
);
1538 gs_cairo
->cairo_fill_preserve(m_cairo
);
1541 gs_cairo
->cairo_stroke(m_cairo
);
1543 CalcBoundingBox(x
,y
);
1544 CalcBoundingBox(x
+width
,y
+height
);
1547 void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1552 gs_cairo
->cairo_save (m_cairo
);
1554 gs_cairo
->cairo_new_path(m_cairo
);
1556 gs_cairo
->cairo_translate (m_cairo
, XLOG2DEV((wxCoord
) (x
+ width
/ 2.)), YLOG2DEV((wxCoord
) (y
+ height
/ 2.)));
1557 gs_cairo
->cairo_scale(m_cairo
, 1, (double)YLOG2DEVREL(height
)/(double)XLOG2DEVREL(width
));
1558 gs_cairo
->cairo_arc ( m_cairo
, 0, 0, XLOG2DEVREL(width
/2), 0, 2 * M_PI
);
1560 SetBrush( m_brush
);
1561 gs_cairo
->cairo_fill_preserve( m_cairo
);
1564 gs_cairo
->cairo_stroke( m_cairo
);
1566 CalcBoundingBox( x
, y
);
1567 CalcBoundingBox( x
+ width
, y
+ height
);
1569 gs_cairo
->cairo_restore (m_cairo
);
1573 void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList
*points
)
1577 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1580 wxPointList::compatibility_iterator node
= points
->GetFirst();
1581 p
= node
->GetData();
1585 node
= node
->GetNext();
1586 p
= node
->GetData();
1590 (double)(x1
+ c
) / 2;
1592 (double)(y1
+ d
) / 2;
1594 gs_cairo
->cairo_new_path( m_cairo
);
1595 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1596 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1598 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1599 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1601 node
= node
->GetNext();
1604 q
= node
->GetData();
1612 x3
= (double)(x2
+ c
) / 2;
1613 y3
= (double)(y2
+ d
) / 2;
1615 gs_cairo
->cairo_curve_to(m_cairo
,
1616 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1617 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1618 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1620 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1621 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1623 node
= node
->GetNext();
1626 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1628 gs_cairo
->cairo_stroke( m_cairo
);
1630 #endif // wxUSE_SPLINES
1632 bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest
, wxCoord ydest
,
1633 wxCoord width
, wxCoord height
,
1634 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1635 int rop
, bool useMask
,
1636 wxCoord
WXUNUSED_UNLESS_DEBUG(xsrcMask
),
1637 wxCoord
WXUNUSED_UNLESS_DEBUG(ysrcMask
))
1639 wxASSERT_MSG( xsrcMask
== wxDefaultCoord
&& ysrcMask
== wxDefaultCoord
,
1640 wxT("mask coordinates are not supported") );
1642 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1644 // Blit into a bitmap.
1645 wxBitmap
bitmap( width
, height
);
1647 memDC
.SelectObject(bitmap
);
1648 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1649 memDC
.SelectObject(wxNullBitmap
);
1651 // Draw bitmap. scaling and positioning is done there.
1652 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1657 void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1659 DoDrawBitmap( icon
, x
, y
, true );
1662 void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1664 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
1666 cairo_surface_t
* surface
;
1667 x
= wxCoord(XLOG2DEV(x
));
1668 y
= wxCoord(YLOG2DEV(y
));
1669 int bw
= bitmap
.GetWidth();
1670 int bh
= bitmap
.GetHeight();
1671 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1672 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1673 wxUint32
* data
= (wxUint32
*)buffer
;
1675 wxMask
*mask
= NULL
;
1676 if (useMask
) mask
= bmpSource
.GetMask();
1678 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1679 // then we'll use a different format and iterator than if it doesn't.
1680 if (bmpSource
.HasAlpha() || mask
)
1682 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1683 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1684 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1685 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1687 wxAlphaPixelData::Iterator
p(pixData
);
1689 for (y
=0; y
<bh
; y
++)
1691 wxAlphaPixelData::Iterator rowStart
= p
;
1692 for (x
=0; x
<bw
; x
++)
1694 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1695 // with alpha in the upper 8 bits, then red, then green, then
1696 // blue. The 32-bit quantities are stored native-endian.
1697 // Pre-multiplied alpha is used.
1698 unsigned char alpha
= p
.Alpha();
1700 if (!bmpSource
.HasAlpha() && mask
)
1706 *data
= ( alpha
<< 24
1707 | (p
.Red() * alpha
/255) << 16
1708 | (p
.Green() * alpha
/255) << 8
1709 | (p
.Blue() * alpha
/255) );
1714 p
.OffsetY(pixData
, 1);
1719 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1720 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1721 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1722 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1724 wxNativePixelData::Iterator
p(pixData
);
1726 for (y
=0; y
<bh
; y
++)
1728 wxNativePixelData::Iterator rowStart
= p
;
1729 for (x
=0; x
<bw
; x
++)
1731 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1732 // the upper 8 bits unused. Red, Green, and Blue are stored in
1733 // the remaining 24 bits in that order. The 32-bit quantities
1734 // are stored native-endian.
1735 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1740 p
.OffsetY(pixData
, 1);
1745 gs_cairo
->cairo_save(m_cairo
);
1747 // Prepare to draw the image.
1748 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1751 cairo_filter_t filter
= CAIRO_FILTER_BILINEAR
;
1752 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1753 cairo_pattern_set_filter(pattern
,filter
);
1754 wxDouble scaleX
= (wxDouble
) XLOG2DEVREL(bw
) / (wxDouble
) bw
;
1755 wxDouble scaleY
= (wxDouble
) YLOG2DEVREL(bh
) / (wxDouble
) bh
;
1756 cairo_scale(m_cairo
, scaleX
, scaleY
);
1758 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
1759 // Use the original size here since the context is scaled already.
1760 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1761 // Fill the rectangle using the pattern.
1762 gs_cairo
->cairo_fill(m_cairo
);
1765 gs_cairo
->cairo_pattern_destroy(pattern
);
1766 gs_cairo
->cairo_surface_destroy(surface
);
1769 CalcBoundingBox(0,0);
1770 CalcBoundingBox(bw
,bh
);
1772 gs_cairo
->cairo_restore(m_cairo
);
1775 void wxGtkPrinterDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1777 DoDrawRotatedText( text
, x
, y
, 0.0 );
1780 void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1782 double xx
= XLOG2DEV(x
);
1783 double yy
= YLOG2DEV(y
);
1787 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1789 const wxUTF8Buf data
= text
.utf8_str();
1791 size_t datalen
= strlen(data
);
1792 pango_layout_set_text( m_layout
, data
, datalen
);
1796 PangoAttrList
*attrs
= pango_attr_list_new();
1797 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1799 a
->end_index
= datalen
;
1800 pango_attr_list_insert(attrs
, a
);
1801 pango_layout_set_attributes(m_layout
, attrs
);
1802 pango_attr_list_unref(attrs
);
1805 if (m_textForegroundColour
.Ok())
1807 unsigned char red
= m_textForegroundColour
.Red();
1808 unsigned char blue
= m_textForegroundColour
.Blue();
1809 unsigned char green
= m_textForegroundColour
.Green();
1810 unsigned char alpha
= m_textForegroundColour
.Alpha();
1812 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1814 double redPS
= (double)(red
) / 255.0;
1815 double bluePS
= (double)(blue
) / 255.0;
1816 double greenPS
= (double)(green
) / 255.0;
1817 double alphaPS
= (double)(alpha
) / 255.0;
1819 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1822 m_currentBlue
= blue
;
1823 m_currentGreen
= green
;
1824 m_currentAlpha
= alpha
;
1830 // Scale font description.
1831 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1832 double size
= oldSize
;
1833 size
= size
* m_scaleX
;
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
);
1841 if ( m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1843 unsigned char red
= m_textBackgroundColour
.Red();
1844 unsigned char blue
= m_textBackgroundColour
.Blue();
1845 unsigned char green
= m_textBackgroundColour
.Green();
1846 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1848 double redPS
= (double)(red
) / 255.0;
1849 double bluePS
= (double)(blue
) / 255.0;
1850 double greenPS
= (double)(green
) / 255.0;
1851 double alphaPS
= (double)(alpha
) / 255.0;
1853 gs_cairo
->cairo_save(m_cairo
);
1854 gs_cairo
->cairo_translate(m_cairo
, xx
, yy
);
1855 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1856 gs_cairo
->cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1857 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1858 gs_cairo
->cairo_fill(m_cairo
);
1859 gs_cairo
->cairo_restore(m_cairo
);
1863 gs_cairo
->cairo_move_to (m_cairo
, xx
, yy
);
1865 gs_cairo
->cairo_save( m_cairo
);
1867 if (fabs(angle
) > 0.00001)
1868 gs_cairo
->cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1870 gs_cairo
->pango_cairo_update_layout (m_cairo
, m_layout
);
1871 gs_cairo
->pango_cairo_show_layout (m_cairo
, m_layout
);
1873 gs_cairo
->cairo_restore( m_cairo
);
1877 // Undo underline attributes setting
1878 pango_layout_set_attributes(m_layout
, NULL
);
1881 // Reset unscaled size.
1882 pango_font_description_set_size( m_fontdesc
, oldSize
);
1884 // Actually apply unscaled font.
1885 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1887 // Back to device units:
1888 CalcBoundingBox (x
, y
);
1889 CalcBoundingBox (x
+ w
, y
+ h
);
1892 void wxGtkPrinterDCImpl::Clear()
1894 // Clear does nothing for printing, but keep the code
1897 gs_cairo->cairo_save(m_cairo);
1898 gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1899 SetBrush(m_backgroundBrush);
1900 gs_cairo->cairo_paint(m_cairo);
1901 gs_cairo->cairo_restore(m_cairo);
1905 void wxGtkPrinterDCImpl::SetFont( const wxFont
& font
)
1912 pango_font_description_free( m_fontdesc
);
1914 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1916 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1920 void wxGtkPrinterDCImpl::SetPen( const wxPen
& pen
)
1922 if (!pen
.Ok()) return;
1928 if (m_pen
.GetWidth() <= 0)
1931 width
= (double) m_pen
.GetWidth();
1933 gs_cairo
->cairo_set_line_width( m_cairo
, width
* m_DEV2PS
* m_scaleX
);
1934 static const double dotted
[] = {2.0, 5.0};
1935 static const double short_dashed
[] = {4.0, 4.0};
1936 static const double long_dashed
[] = {4.0, 8.0};
1937 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1939 switch (m_pen
.GetStyle())
1941 case wxPENSTYLE_DOT
: gs_cairo
->cairo_set_dash( m_cairo
, dotted
, 2, 0 ); break;
1942 case wxPENSTYLE_SHORT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, short_dashed
, 2, 0 ); break;
1943 case wxPENSTYLE_LONG_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, long_dashed
, 2, 0 ); break;
1944 case wxPENSTYLE_DOT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, dotted_dashed
, 4, 0 ); break;
1945 case wxPENSTYLE_USER_DASH
:
1948 int num
= m_pen
.GetDashes (&wx_dashes
);
1949 gdouble
*g_dashes
= g_new( gdouble
, num
);
1951 for (i
= 0; i
< num
; ++i
)
1952 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1953 gs_cairo
->cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1957 case wxPENSTYLE_SOLID
:
1958 case wxPENSTYLE_TRANSPARENT
:
1959 default: gs_cairo
->cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
1962 switch (m_pen
.GetCap())
1964 case wxCAP_PROJECTING
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
1965 case wxCAP_BUTT
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
1967 default: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
1970 switch (m_pen
.GetJoin())
1972 case wxJOIN_BEVEL
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
1973 case wxJOIN_MITER
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
1975 default: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
1978 unsigned char red
= m_pen
.GetColour().Red();
1979 unsigned char blue
= m_pen
.GetColour().Blue();
1980 unsigned char green
= m_pen
.GetColour().Green();
1981 unsigned char alpha
= m_pen
.GetColour().Alpha();
1983 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1985 double redPS
= (double)(red
) / 255.0;
1986 double bluePS
= (double)(blue
) / 255.0;
1987 double greenPS
= (double)(green
) / 255.0;
1988 double alphaPS
= (double)(alpha
) / 255.0;
1990 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1993 m_currentBlue
= blue
;
1994 m_currentGreen
= green
;
1995 m_currentAlpha
= alpha
;
1999 void wxGtkPrinterDCImpl::SetBrush( const wxBrush
& brush
)
2001 if (!brush
.Ok()) return;
2005 if (m_brush
.GetStyle() == wxBRUSHSTYLE_TRANSPARENT
)
2007 gs_cairo
->cairo_set_source_rgba( m_cairo
, 0, 0, 0, 0 );
2016 unsigned char red
= m_brush
.GetColour().Red();
2017 unsigned char blue
= m_brush
.GetColour().Blue();
2018 unsigned char green
= m_brush
.GetColour().Green();
2019 unsigned char alpha
= m_brush
.GetColour().Alpha();
2021 double redPS
= (double)(red
) / 255.0;
2022 double bluePS
= (double)(blue
) / 255.0;
2023 double greenPS
= (double)(green
) / 255.0;
2024 double alphaPS
= (double)(alpha
) / 255.0;
2026 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
2028 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
2031 m_currentBlue
= blue
;
2032 m_currentGreen
= green
;
2033 m_currentAlpha
= alpha
;
2036 if (m_brush
.IsHatch())
2039 cairo_surface_t
*surface
;
2040 surface
= gs_cairo
->cairo_surface_create_similar(gs_cairo
->cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
2041 cr
= gs_cairo
->cairo_create(surface
);
2042 gs_cairo
->cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
2043 gs_cairo
->cairo_set_line_width(cr
, 1);
2044 gs_cairo
->cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
2046 switch (m_brush
.GetStyle())
2048 case wxBRUSHSTYLE_CROSS_HATCH
:
2049 gs_cairo
->cairo_move_to(cr
, 5, 0);
2050 gs_cairo
->cairo_line_to(cr
, 5, 10);
2051 gs_cairo
->cairo_move_to(cr
, 0, 5);
2052 gs_cairo
->cairo_line_to(cr
, 10, 5);
2054 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
2055 gs_cairo
->cairo_move_to(cr
, 0, 10);
2056 gs_cairo
->cairo_line_to(cr
, 10, 0);
2058 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
2059 gs_cairo
->cairo_move_to(cr
, 0, 0);
2060 gs_cairo
->cairo_line_to(cr
, 10, 10);
2062 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
2063 gs_cairo
->cairo_move_to(cr
, 0, 0);
2064 gs_cairo
->cairo_line_to(cr
, 10, 10);
2065 gs_cairo
->cairo_move_to(cr
, 10, 0);
2066 gs_cairo
->cairo_line_to(cr
, 0, 10);
2068 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
2069 gs_cairo
->cairo_move_to(cr
, 0, 5);
2070 gs_cairo
->cairo_line_to(cr
, 10, 5);
2072 case wxBRUSHSTYLE_VERTICAL_HATCH
:
2073 gs_cairo
->cairo_move_to(cr
, 5, 0);
2074 gs_cairo
->cairo_line_to(cr
, 5, 10);
2077 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
2080 gs_cairo
->cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
2081 gs_cairo
->cairo_stroke (cr
);
2083 gs_cairo
->cairo_destroy(cr
);
2084 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface (surface
);
2085 gs_cairo
->cairo_surface_destroy(surface
);
2086 gs_cairo
->cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
2087 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
2088 gs_cairo
->cairo_pattern_destroy(pattern
);
2092 void wxGtkPrinterDCImpl::SetLogicalFunction( int function
)
2094 if (function
== wxCLEAR
)
2095 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
2096 else if (function
== wxOR
)
2097 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
2098 else if (function
== wxNO_OP
)
2099 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
2100 else if (function
== wxAND
)
2101 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
2102 else if (function
== wxSET
)
2103 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
2104 else if (function
== wxXOR
)
2105 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
2106 else // wxCOPY or anything else.
2107 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
2110 void wxGtkPrinterDCImpl::SetBackground( const wxBrush
& brush
)
2112 m_backgroundBrush
= brush
;
2113 gs_cairo
->cairo_save(m_cairo
);
2114 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2116 SetBrush(m_backgroundBrush
);
2117 gs_cairo
->cairo_paint(m_cairo
);
2118 gs_cairo
->cairo_restore(m_cairo
);
2121 void wxGtkPrinterDCImpl::SetBackgroundMode(int mode
)
2123 if (mode
== wxBRUSHSTYLE_SOLID
)
2124 m_backgroundMode
= wxBRUSHSTYLE_SOLID
;
2126 m_backgroundMode
= wxBRUSHSTYLE_TRANSPARENT
;
2129 void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2131 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2132 gs_cairo
->cairo_clip(m_cairo
);
2135 void wxGtkPrinterDCImpl::DestroyClippingRegion()
2137 gs_cairo
->cairo_reset_clip(m_cairo
);
2140 bool wxGtkPrinterDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
2145 void wxGtkPrinterDCImpl::EndDoc()
2150 void wxGtkPrinterDCImpl::StartPage()
2155 void wxGtkPrinterDCImpl::EndPage()
2160 wxCoord
wxGtkPrinterDCImpl::GetCharHeight() const
2162 pango_layout_set_text( m_layout
, "H", 1 );
2165 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2167 return wxRound( h
* m_PS2DEV
);
2170 wxCoord
wxGtkPrinterDCImpl::GetCharWidth() const
2172 pango_layout_set_text( m_layout
, "H", 1 );
2175 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2177 return wxRound( w
* m_PS2DEV
);
2180 void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2182 wxCoord
*externalLeading
,
2183 const wxFont
*theFont
) const
2191 if ( externalLeading
)
2192 *externalLeading
= 0;
2199 // Set layout's text
2200 const wxUTF8Buf dataUTF8
= string
.utf8_str();
2202 PangoFontDescription
*desc
= m_fontdesc
;
2203 if (theFont
) desc
= theFont
->GetNativeFontInfo()->description
;
2205 gint oldSize
= pango_font_description_get_size( desc
);
2206 double size
= oldSize
;
2207 size
= size
* m_scaleY
;
2208 pango_font_description_set_size( desc
, (gint
)size
);
2210 // apply scaled font
2211 pango_layout_set_font_description( m_layout
, desc
);
2213 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2216 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2219 *width
= wxRound( (double)w
/ m_scaleX
* m_PS2DEV
);
2221 *height
= wxRound( (double)h
/ m_scaleY
* m_PS2DEV
);
2225 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2226 int baseline
= pango_layout_iter_get_baseline(iter
);
2227 pango_layout_iter_free(iter
);
2228 *descent
= wxRound( (h
- PANGO_PIXELS(baseline
)) * m_PS2DEV
);
2231 // Reset unscaled size.
2232 pango_font_description_set_size( desc
, oldSize
);
2234 // Reset unscaled font.
2235 pango_layout_set_font_description( m_layout
, m_fontdesc
);
2238 void wxGtkPrinterDCImpl::DoGetSize(int* width
, int* height
) const
2240 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2243 *width
= wxRound( (double)gtk_page_setup_get_paper_width( setup
, GTK_UNIT_POINTS
) * (double)m_resolution
/ 72.0 );
2245 *height
= wxRound( (double)gtk_page_setup_get_paper_height( setup
, GTK_UNIT_POINTS
) * (double)m_resolution
/ 72.0 );
2248 void wxGtkPrinterDCImpl::DoGetSizeMM(int *width
, int *height
) const
2250 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2253 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_MM
) );
2255 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_MM
) );
2258 wxSize
wxGtkPrinterDCImpl::GetPPI() const
2260 return wxSize( (int)m_resolution
, (int)m_resolution
);
2263 void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData
& data
)
2268 // overriden for wxPrinterDC Impl
2270 wxRect
wxGtkPrinterDCImpl::GetPaperRect()
2272 // Does GtkPrint support printer margins?
2275 DoGetSize( &w
, &h
);
2276 return wxRect( 0,0,w
,h
);
2279 int wxGtkPrinterDCImpl::GetResolution()
2281 return m_resolution
;
2284 // ----------------------------------------------------------------------------
2286 // ----------------------------------------------------------------------------
2288 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2290 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2291 wxPrintout
* WXUNUSED(printoutForPrinting
),
2294 // convert wxPrintQuality to resolution (input pointer can be NULL)
2295 wxPrintQuality quality
= data
? data
->GetQuality() : wxPRINT_QUALITY_MEDIUM
;
2298 case wxPRINT_QUALITY_HIGH
:
2299 m_resolution
= 1200;
2302 case wxPRINT_QUALITY_LOW
:
2306 case wxPRINT_QUALITY_DRAFT
:
2313 // positive values directly indicate print resolution
2314 m_resolution
= quality
;
2318 wxFAIL_MSG( "unknown print quality" );
2321 case wxPRINT_QUALITY_MEDIUM
:
2330 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2331 wxPrintout
*printoutForPrinting
,
2332 wxPrintDialogData
*data
)
2333 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2335 Init(printout
, printoutForPrinting
, data
? &data
->GetPrintData() : NULL
);
2338 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2339 wxPrintout
*printoutForPrinting
,
2341 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2343 Init(printout
, printoutForPrinting
, data
);
2346 wxGtkPrintPreview::~wxGtkPrintPreview()
2350 bool wxGtkPrintPreview::Print(bool interactive
)
2352 if (!m_printPrintout
)
2355 wxPrinter
printer(& m_printDialogData
);
2356 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2359 void wxGtkPrintPreview::DetermineScaling()
2361 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2363 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2365 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2369 wxSize ScreenPixels
= wxGetDisplaySize();
2370 wxSize ScreenMM
= wxGetDisplaySizeMM();
2372 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2373 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2375 m_previewPrintout
->SetPPIPrinter( m_resolution
, m_resolution
);
2377 // Get width and height in points (1/72th of an inch)
2378 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2379 sizeDevUnits
.x
= wxRound((double)sizeDevUnits
.x
* (double)m_resolution
/ 72.0);
2380 sizeDevUnits
.y
= wxRound((double)sizeDevUnits
.y
* (double)m_resolution
/ 72.0);
2382 wxSize
sizeTenthsMM(paper
->GetSize());
2383 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2385 // If in landscape mode, we need to swap the width and height.
2386 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2388 m_pageWidth
= sizeDevUnits
.y
;
2389 m_pageHeight
= sizeDevUnits
.x
;
2390 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2394 m_pageWidth
= sizeDevUnits
.x
;
2395 m_pageHeight
= sizeDevUnits
.y
;
2396 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2398 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2399 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2401 // At 100%, the page should look about page-size on the screen.
2402 m_previewScaleX
= 0.8 * 72.0 / (double)m_resolution
;
2403 m_previewScaleY
= m_previewScaleX
;