1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/print.cpp
3 // Author: Anthony Bretaudeau
4 // Purpose: GTK printing support
6 // RCS-ID: $Id: print.cpp,v 1 2007-08-25 05:44:44 PC Exp $
7 // Copyright: (c) 2007 wxWidgets development team
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/gtk/print.h"
24 #include "wx/dcmemory.h"
28 #include "wx/module.h"
32 #include "wx/fontutil.h"
33 #include "wx/gtk/private.h"
34 #include "wx/dynlib.h"
36 #include "wx/rawbmp.h"
39 #include <gtk/gtkpagesetupunixdialog.h>
42 wxFORCE_LINK_THIS_MODULE(gtk_print
)
44 #if wxUSE_LIBGNOMEPRINT
45 #include "wx/gtk/gnome/gprint.h"
48 // Usefull to convert angles from/to Rad to/from Deg.
49 static const double RAD2DEG
= 180.0 / M_PI
;
50 static const double DEG2RAD
= M_PI
/ 180.0;
52 static wxCairoLibrary
* gs_cairo
= NULL
;
54 //----------------------------------------------------------------------------
56 // Initialized when starting the app : if it successfully load the gtk-print framework,
57 // it uses it. If not, it falls back to gnome print (see /gtk/gnome/gprint.cpp) then
58 // to postscript if gnomeprint is not available.
59 //----------------------------------------------------------------------------
61 class wxGtkPrintModule
: public wxModule
66 #if wxUSE_LIBGNOMEPRINT
67 // This module must be initialized AFTER gnomeprint's one
68 AddDependency(CLASSINFO(wxGnomePrintModule
));
75 DECLARE_DYNAMIC_CLASS(wxGtkPrintModule
)
78 bool wxGtkPrintModule::OnInit()
80 gs_cairo
= wxCairoLibrary::Get();
81 if (gs_cairo
&& gtk_check_version(2,10,0) == NULL
)
82 wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory
);
86 void wxGtkPrintModule::OnExit()
91 IMPLEMENT_DYNAMIC_CLASS(wxGtkPrintModule
, wxModule
)
93 //----------------------------------------------------------------------------
95 //----------------------------------------------------------------------------
97 wxPrinterBase
* wxGtkPrintFactory::CreatePrinter( wxPrintDialogData
*data
)
99 return new wxGtkPrinter( data
);
102 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
103 wxPrintout
*printout
,
104 wxPrintDialogData
*data
)
106 return new wxGtkPrintPreview( preview
, printout
, data
);
109 wxPrintPreviewBase
*wxGtkPrintFactory::CreatePrintPreview( wxPrintout
*preview
,
110 wxPrintout
*printout
,
113 return new wxGtkPrintPreview( preview
, printout
, data
);
116 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
117 wxPrintDialogData
*data
)
119 return new wxGtkPrintDialog( parent
, data
);
122 wxPrintDialogBase
*wxGtkPrintFactory::CreatePrintDialog( wxWindow
*parent
,
125 return new wxGtkPrintDialog( parent
, data
);
128 wxPageSetupDialogBase
*wxGtkPrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
129 wxPageSetupDialogData
* data
)
131 return new wxGtkPageSetupDialog( parent
, data
);
134 bool wxGtkPrintFactory::HasPrintSetupDialog()
140 wxGtkPrintFactory::CreatePrintSetupDialog(wxWindow
* WXUNUSED(parent
),
141 wxPrintData
* WXUNUSED(data
))
148 wxImplDC
* wxGtkPrintFactory::CreatePrinterImplDC( wxPrinterDC
*owner
, const wxPrintData
& data
)
150 return new wxGtkPrinterImplDC( owner
, data
);
155 wxDC
* wxGtkPrintFactory::CreatePrinterDC( const wxPrintData
& data
)
157 return new wxGtkPrinterDC(data
);
162 bool wxGtkPrintFactory::HasOwnPrintToFile()
167 bool wxGtkPrintFactory::HasPrinterLine()
172 wxString
wxGtkPrintFactory::CreatePrinterLine()
175 return wxEmptyString
;
178 bool wxGtkPrintFactory::HasStatusLine()
184 wxString
wxGtkPrintFactory::CreateStatusLine()
187 return wxEmptyString
;
190 wxPrintNativeDataBase
*wxGtkPrintFactory::CreatePrintNativeData()
192 return new wxGtkPrintNativeData
;
195 //----------------------------------------------------------------------------
196 // Callback functions for Gtk Printings.
197 //----------------------------------------------------------------------------
199 // We use it to pass useful objects to GTK printing callback functions.
200 struct wxPrinterToGtkData
202 wxGtkPrinter
* printer
;
203 wxPrintout
* printout
;
208 static void gtk_begin_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
210 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
212 data
->printer
->BeginPrint(data
->printout
, operation
, context
);
215 static void gtk_draw_page_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gint page_nr
, gpointer user_data
)
217 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
219 data
->printer
->DrawPage(data
->printout
, operation
, context
, page_nr
);
222 static void gtk_end_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
223 GtkPrintContext
* WXUNUSED(context
),
226 wxPrintout
*printout
= (wxPrintout
*) user_data
;
228 printout
->OnEndPrinting();
232 gtk_preview_print_callback(GtkPrintOperation
* WXUNUSED(operation
),
233 GtkPrintOperationPreview
* WXUNUSED(preview
),
234 GtkPrintContext
*context
,
238 wxPrintout
*printout
= (wxPrintout
*) user_data
;
240 printout
->SetIsPreview(true);
242 /* We create a Cairo context with 72dpi resolution. This resolution is
243 * only used for positioning. */
244 cairo_t
*cairo
= gdk_cairo_create(GTK_WIDGET(parent
)->window
);
245 gtk_print_context_set_cairo_context(context
, cairo
, 72, 72);
251 //----------------------------------------------------------------------------
252 // wxGtkPrintNativeData
253 //----------------------------------------------------------------------------
255 IMPLEMENT_CLASS(wxGtkPrintNativeData
, wxPrintNativeDataBase
)
257 wxGtkPrintNativeData::wxGtkPrintNativeData()
259 m_config
= gtk_print_settings_new();
262 wxGtkPrintNativeData::~wxGtkPrintNativeData()
264 g_object_unref (m_config
);
267 // Convert datas stored in m_config to a wxPrintData.
268 // Called by wxPrintData::ConvertFromNative().
269 bool wxGtkPrintNativeData::TransferTo( wxPrintData
&data
)
274 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
275 if (quality
== GTK_PRINT_QUALITY_HIGH
)
276 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
277 else if (quality
== GTK_PRINT_QUALITY_LOW
)
278 data
.SetQuality(wxPRINT_QUALITY_LOW
);
279 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
280 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
282 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
284 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
286 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
288 switch (gtk_print_settings_get_duplex(m_config
))
290 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
293 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
297 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
301 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
302 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
304 data
.SetOrientation(wxPORTRAIT
);
305 data
.SetOrientationReversed(false);
307 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
309 data
.SetOrientation(wxLANDSCAPE
);
310 data
.SetOrientationReversed(false);
312 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
314 data
.SetOrientation(wxPORTRAIT
);
315 data
.SetOrientationReversed(true);
317 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
319 data
.SetOrientation(wxLANDSCAPE
);
320 data
.SetOrientationReversed(true);
323 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
325 // Paper formats : these are the most common paper formats.
326 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
328 data
.SetPaperId(wxPAPER_NONE
);
329 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
330 data
.SetPaperId(wxPAPER_A3
);
331 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
332 data
.SetPaperId(wxPAPER_A4
);
333 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
334 data
.SetPaperId(wxPAPER_A5
);
335 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
336 data
.SetPaperId(wxPAPER_B5
);
337 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
338 data
.SetPaperId(wxPAPER_LETTER
);
339 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
340 data
.SetPaperId(wxPAPER_LEGAL
);
341 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
342 data
.SetPaperId(wxPAPER_EXECUTIVE
);
343 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
344 data
.SetPaperId(wxPAPER_ENV_10
);
345 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
346 data
.SetPaperId(wxPAPER_ENV_C5
);
347 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
348 data
.SetPaperId(wxPAPER_ENV_C6
);
349 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
350 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
351 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
352 data
.SetPaperId(wxPAPER_ENV_B5
);
353 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
354 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
355 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
356 data
.SetPaperId( wxPAPER_CSHEET
);
357 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
358 data
.SetPaperId( wxPAPER_DSHEET
);
359 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
360 data
.SetPaperId( wxPAPER_ESHEET
);
361 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
362 data
.SetPaperId( wxPAPER_LETTERSMALL
);
363 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
364 data
.SetPaperId( wxPAPER_TABLOID
);
365 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
366 data
.SetPaperId( wxPAPER_LEDGER
);
367 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
368 data
.SetPaperId( wxPAPER_STATEMENT
);
369 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
370 data
.SetPaperId( wxPAPER_A4SMALL
);
371 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
372 data
.SetPaperId( wxPAPER_B4
);
373 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
374 data
.SetPaperId( wxPAPER_FOLIO
);
375 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
376 data
.SetPaperId( wxPAPER_QUARTO
);
377 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
378 data
.SetPaperId( wxPAPER_10X14
);
379 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
380 data
.SetPaperId( wxPAPER_11X17
);
381 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
382 data
.SetPaperId( wxPAPER_NOTE
);
383 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
384 data
.SetPaperId( wxPAPER_ENV_9
);
385 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
386 data
.SetPaperId( wxPAPER_ENV_11
);
387 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
388 data
.SetPaperId( wxPAPER_ENV_12
);
389 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
390 data
.SetPaperId( wxPAPER_ENV_14
);
391 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
392 data
.SetPaperId( wxPAPER_ENV_DL
);
393 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
394 data
.SetPaperId( wxPAPER_ENV_C3
);
395 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
396 data
.SetPaperId( wxPAPER_ENV_C4
);
397 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
398 data
.SetPaperId( wxPAPER_ENV_C65
);
399 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
400 data
.SetPaperId( wxPAPER_ENV_B4
);
401 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
402 data
.SetPaperId( wxPAPER_ENV_B6
);
403 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
404 data
.SetPaperId( wxPAPER_ENV_ITALY
);
405 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
406 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
407 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
408 data
.SetPaperId( wxPAPER_FANFOLD_US
);
409 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
410 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
411 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
412 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
414 data
.SetPaperId(wxPAPER_NONE
);
418 // Put datas given by the wxPrintData into m_config.
419 // Called by wxPrintData::ConvertToNative().
420 bool wxGtkPrintNativeData::TransferFrom( const wxPrintData
&data
)
425 wxPrintQuality quality
= data
.GetQuality();
426 if (quality
== wxPRINT_QUALITY_HIGH
)
427 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
428 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
429 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
430 else if (quality
== wxPRINT_QUALITY_LOW
)
431 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
432 else if (quality
== wxPRINT_QUALITY_DRAFT
)
433 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
434 else if (quality
> 1)
435 gtk_print_settings_set_resolution (m_config
, quality
);
437 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
439 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
441 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
443 switch (data
.GetDuplex())
445 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
448 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
452 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
456 if (!data
.IsOrientationReversed())
458 if (data
.GetOrientation() == wxLANDSCAPE
)
459 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
461 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
464 if (data
.GetOrientation() == wxLANDSCAPE
)
465 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
467 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
470 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
472 // Paper formats: these are the most common paper formats.
473 switch (data
.GetPaperId())
475 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
477 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
479 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
481 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
483 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
485 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
487 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
489 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
491 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
493 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
495 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
497 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
499 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
501 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
503 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
505 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
507 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
509 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
511 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
513 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
515 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
517 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
519 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
521 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
523 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
525 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
527 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
529 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
531 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
533 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
535 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
537 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
539 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
541 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
543 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
545 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
547 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
549 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
551 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
553 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
555 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
557 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
566 void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings
* config
)
569 m_config
= gtk_print_settings_copy(config
);
572 // Extract page setup from settings.
573 GtkPageSetup
* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
575 GtkPageSetup
* page_setup
= gtk_page_setup_new();
576 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
578 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
579 if (paper_size
!= NULL
)
580 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
585 // Insert page setup into a given GtkPrintSettings.
586 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
588 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
589 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
592 //----------------------------------------------------------------------------
594 //----------------------------------------------------------------------------
596 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
598 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
599 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
600 wxPoint(0, 0), wxSize(600, 600),
601 wxDEFAULT_DIALOG_STYLE
|
605 m_printDialogData
= *data
;
611 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
612 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
613 wxPoint(0, 0), wxSize(600, 600),
614 wxDEFAULT_DIALOG_STYLE
|
618 m_printDialogData
= *data
;
625 wxGtkPrintDialog::~wxGtkPrintDialog()
629 // This is called even if we actually don't want the dialog to appear.
630 int wxGtkPrintDialog::ShowModal()
632 GtkPrintOperationResult response
;
634 // We need to restore the settings given in the constructor.
635 wxPrintData data
= m_printDialogData
.GetPrintData();
636 wxGtkPrintNativeData
*native
=
637 (wxGtkPrintNativeData
*) data
.GetNativeData();
638 data
.ConvertToNative();
640 GtkPrintSettings
* settings
= native
->GetPrintConfig();
642 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
643 int fromPage
= m_printDialogData
.GetFromPage();
644 int toPage
= m_printDialogData
.GetToPage();
645 if (m_printDialogData
.GetSelection())
646 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
647 else if (m_printDialogData
.GetAllPages())
648 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
650 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
652 range
= g_new (GtkPageRange
, 1);
653 range
[0].start
= fromPage
-1;
654 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
655 gtk_print_settings_set_page_ranges (settings
, range
, 1);
658 // If the settings are OK, we restore it.
659 if (settings
!= NULL
)
660 gtk_print_operation_set_print_settings (native
->GetPrintJob(), settings
);
661 gtk_print_operation_set_default_page_setup (native
->GetPrintJob(), native
->GetPageSetupFromSettings(settings
));
663 // Show the dialog if needed.
664 GError
* gError
= NULL
;
666 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
668 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
)), &gError
);
670 // Does everything went well?
671 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
675 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
677 g_error_free (gError
);
678 wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError
->message
));
679 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
682 // Now get the settings and save it.
683 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings (native
->GetPrintJob());
684 native
->SetPrintConfig(newSettings
);
685 data
.ConvertFromNative();
687 // Same problem as a few lines before.
688 switch (gtk_print_settings_get_print_pages(newSettings
))
690 case GTK_PRINT_PAGES_CURRENT
:
691 m_printDialogData
.SetSelection( true );
693 case GTK_PRINT_PAGES_RANGES
:
694 {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
695 // 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
696 // will hit "OK" button. However we can only save 1-3 in the print data.
699 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
702 m_printDialogData
.SetFromPage( range
[0].start
);
703 m_printDialogData
.SetToPage( range
[0].end
);
706 m_printDialogData
.SetAllPages( true );
707 m_printDialogData
.SetFromPage( 0 );
708 m_printDialogData
.SetToPage( 9999 );
711 case GTK_PRINT_PAGES_ALL
:
713 m_printDialogData
.SetAllPages( true );
714 m_printDialogData
.SetFromPage( 0 );
715 m_printDialogData
.SetToPage( 9999 );
722 //----------------------------------------------------------------------------
723 // wxGtkPageSetupDialog
724 //----------------------------------------------------------------------------
726 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
728 wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow
*parent
,
729 wxPageSetupDialogData
* data
)
732 m_pageDialogData
= *data
;
737 wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
741 int wxGtkPageSetupDialog::ShowModal()
744 m_pageDialogData
.GetPrintData().ConvertToNative();
745 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
746 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
748 // We only need the pagesetup data which are part of the settings.
749 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
751 // If the user used a custom paper format the last time he printed, we have to restore it too.
752 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
754 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
755 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
757 wxString title
= _("Custom size");
758 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
759 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
760 g_object_unref(customSize
);
764 // Now show the dialog.
765 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
770 if (newPageSetup
!= oldPageSetup
)
772 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
773 m_pageDialogData
.GetPrintData().ConvertFromNative();
775 // Store custom paper format if any.
776 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
778 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
779 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
780 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
781 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
782 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
784 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
785 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
787 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
788 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
790 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
803 //----------------------------------------------------------------------------
805 //----------------------------------------------------------------------------
807 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
809 wxGtkPrinter::wxGtkPrinter( wxPrintDialogData
*data
) :
810 wxPrinterBase( data
)
815 m_printDialogData
= *data
;
818 wxGtkPrinter::~wxGtkPrinter()
822 bool wxGtkPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
826 sm_lastError
= wxPRINTER_ERROR
;
830 // Let's correct the PageInfo just in case the app gives wrong values.
831 int fromPage
, toPage
;
832 int minPage
, maxPage
;
833 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
834 m_printDialogData
.SetAllPages(true);
836 if (minPage
< 1) minPage
= 1;
837 if (maxPage
< 1) maxPage
= 9999;
838 if (maxPage
< minPage
) maxPage
= minPage
;
840 m_printDialogData
.SetMinPage(minPage
);
841 m_printDialogData
.SetMaxPage(maxPage
);
844 if (fromPage
< minPage
) fromPage
= minPage
;
845 else if (fromPage
> maxPage
) fromPage
= maxPage
;
846 m_printDialogData
.SetFromPage(fromPage
);
850 m_printDialogData
.SetToPage(toPage
);
851 if (toPage
> maxPage
) toPage
= maxPage
;
852 else if (toPage
< minPage
) toPage
= minPage
;
855 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
858 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
859 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
861 GtkPrintOperation
*printOp
= gtk_print_operation_new ();
863 native
->SetPrintJob( printOp
);
865 printout
->SetIsPreview(false);
867 wxPrinterToGtkData dataToSend
;
868 dataToSend
.printer
= this;
869 dataToSend
.printout
= printout
;
871 // These Gtk signals are caught here.
872 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
873 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
874 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
875 g_signal_connect (printOp
, "preview", G_CALLBACK (gtk_preview_print_callback
), printout
);
877 // This is used to setup the DC and
878 // show the dialog if desired
879 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
880 dialog
.SetPrintDC(m_dc
);
881 dialog
.SetShowDialog(prompt
);
883 // doesn't necessarily show
884 int ret
= dialog
.ShowModal();
885 if (ret
== wxID_CANCEL
)
887 sm_lastError
= wxPRINTER_CANCELLED
;
891 sm_lastError
= wxPRINTER_ERROR
;
892 wxFAIL_MSG(_("The print dialog returned an error."));
895 g_object_unref (printOp
);
897 return (sm_lastError
== wxPRINTER_NO_ERROR
);
900 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
902 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
903 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
905 SetPrintContext(context
);
906 native
->SetPrintContext( context
);
909 wxPrinterDC
*printDC
= new wxPrinterDC( printdata
);
911 wxGtkPrinterDC
*printDC
= new wxGtkPrinterDC( printdata
);
917 if (sm_lastError
!= wxPRINTER_CANCELLED
)
919 sm_lastError
= wxPRINTER_ERROR
;
920 wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used."));
924 wxSize ScreenPixels
= wxGetDisplaySize();
925 wxSize ScreenMM
= wxGetDisplaySizeMM();
927 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
928 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
929 printout
->SetPPIPrinter( printDC
->GetResolution(),
930 printDC
->GetResolution() );
932 printout
->SetDC(m_dc
);
935 m_dc
->GetSize(&w
, &h
);
936 printout
->SetPageSizePixels((int)w
, (int)h
);
937 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
939 m_dc
->GetSizeMM(&mw
, &mh
);
940 printout
->SetPageSizeMM((int)mw
, (int)mh
);
941 printout
->OnPreparePrinting();
943 // Get some parameters from the printout, if defined.
944 int fromPage
, toPage
;
945 int minPage
, maxPage
;
946 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
950 sm_lastError
= wxPRINTER_ERROR
;
951 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
955 printout
->OnBeginPrinting();
959 // If we're not previewing we need to calculate the number of pages to print.
960 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
961 // have defined in the dialog. So the number of pages is the maximum available.
962 if (!printout
->IsPreview())
964 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
965 switch (gtk_print_settings_get_print_pages(settings
))
967 case GTK_PRINT_PAGES_CURRENT
:
970 case GTK_PRINT_PAGES_RANGES
:
971 {gint num_ranges
= 0;
974 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
975 for (i
=0; i
<num_ranges
; i
++)
977 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
978 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
979 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
980 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
981 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
983 gtk_print_settings_set_page_ranges (settings
, range
, 1);
985 case GTK_PRINT_PAGES_ALL
:
987 numPages
= maxPage
- minPage
+ 1;
991 else numPages
= maxPage
- minPage
+ 1;
993 gtk_print_operation_set_n_pages(operation
, numPages
);
996 void wxGtkPrinter::DrawPage(wxPrintout
*printout
,
997 GtkPrintOperation
*operation
,
998 GtkPrintContext
* WXUNUSED(context
),
1001 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
1002 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
1004 int numPageToDraw
= page_nr
+ minPage
;
1005 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
1006 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
1008 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
1009 switch (gtk_print_settings_get_print_pages(settings
))
1011 case GTK_PRINT_PAGES_CURRENT
:
1012 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
1013 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
1015 case GTK_PRINT_PAGES_RANGES
:
1016 {gint num_ranges
= 0;
1017 GtkPageRange
* range
;
1018 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
1019 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
1020 if (num_ranges
>= 1)
1022 startPage
= range
[0].start
+ 1;
1023 endPage
= range
[0].end
+ 1;
1026 startPage
= minPage
;
1030 case GTK_PRINT_PAGES_ALL
:
1032 startPage
= minPage
;
1037 if(numPageToDraw
== startPage
)
1039 if (!printout
->OnBeginDocument(startPage
, endPage
))
1041 wxLogError(_("Could not start printing."));
1042 sm_lastError
= wxPRINTER_ERROR
;
1046 // The app can render the page numPageToDraw.
1047 if (printout
->HasPage(numPageToDraw
))
1050 printout
->OnPrintPage(numPageToDraw
);
1055 if(numPageToDraw
== endPage
)
1057 printout
->OnEndDocument();
1061 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1063 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1065 dialog
.SetPrintDC(m_dc
);
1066 dialog
.SetShowDialog(true);
1068 int ret
= dialog
.ShowModal();
1070 if (ret
== wxID_CANCEL
)
1072 sm_lastError
= wxPRINTER_CANCELLED
;
1077 sm_lastError
= wxPRINTER_ERROR
;
1078 wxFAIL_MSG(_("The print dialog returned an error."));
1082 m_printDialogData
= dialog
.GetPrintDialogData();
1085 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
1087 return new wxGtkPrinterDC( m_printDialogData
.GetPrintData() );
1091 bool wxGtkPrinter::Setup( wxWindow
* WXUNUSED(parent
) )
1093 // Obsolete, for backward compatibility.
1097 //-----------------------------------------------------------------------------
1099 //-----------------------------------------------------------------------------
1101 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
1102 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
1103 #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
1104 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
1108 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterImplDC
, wxImplDC
)
1110 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDC
, wxDC
)
1114 wxGtkPrinterImplDC::wxGtkPrinterImplDC( wxPrinterDC
*owner
, const wxPrintData
& data
) :
1117 wxGtkPrinterDC::wxGtkPrinterDC( const wxPrintData
& data
)
1122 wxGtkPrintNativeData
*native
=
1123 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1125 m_gpc
= native
->GetPrintContext();
1127 // Match print quality to resolution (high = 1200dpi)
1128 m_resolution
= m_printData
.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
1129 if (m_resolution
< 0)
1130 m_resolution
= (1 << (m_resolution
+4)) *150;
1132 m_PS2DEV
= (double)m_resolution
/ 72.0;
1133 m_DEV2PS
= 72.0 / (double)m_resolution
;
1135 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1136 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1137 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1139 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1145 m_signX
= 1; // default x-axis left to right.
1146 m_signY
= 1; // default y-axis bottom up -> top down.
1148 // By default the origin of the Cairo context is in the upper left
1149 // corner of the printable area. We need to translate it so that it
1150 // is in the upper left corner of the paper (without margins)
1151 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
1153 ml
= gtk_page_setup_get_left_margin (setup
, GTK_UNIT_POINTS
);
1154 mt
= gtk_page_setup_get_top_margin (setup
, GTK_UNIT_POINTS
);
1155 gs_cairo
->cairo_translate(m_cairo
, -ml
, -mt
);
1158 wxGtkPrinterImplDC::~wxGtkPrinterImplDC()
1160 g_object_unref(m_context
);
1161 g_object_unref(m_layout
);
1164 bool wxGtkPrinterImplDC::IsOk() const
1166 return m_gpc
!= NULL
;
1169 bool wxGtkPrinterImplDC::DoFloodFill(wxCoord
WXUNUSED(x1
),
1170 wxCoord
WXUNUSED(y1
),
1171 const wxColour
& WXUNUSED(col
),
1172 int WXUNUSED(style
))
1174 // We can't access the given coord as a Cairo context is scalable, ie a
1175 // coord doesn't mean anything in this context.
1176 wxFAIL_MSG(_("not implemented"));
1180 void wxGtkPrinterImplDC::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1182 wxCoord xC
= circleCenter
.x
;
1183 wxCoord yC
= circleCenter
.y
;
1184 wxCoord xR
= rect
.x
;
1185 wxCoord yR
= rect
.y
;
1186 wxCoord w
= rect
.width
;
1187 wxCoord h
= rect
.height
;
1189 double radius
= sqrt((w
/2)*(w
/2)+(h
/2)*(h
/2));
1191 unsigned char redI
= initialColour
.Red();
1192 unsigned char blueI
= initialColour
.Blue();
1193 unsigned char greenI
= initialColour
.Green();
1194 unsigned char alphaI
= initialColour
.Alpha();
1195 unsigned char redD
= destColour
.Red();
1196 unsigned char blueD
= destColour
.Blue();
1197 unsigned char greenD
= destColour
.Green();
1198 unsigned char alphaD
= destColour
.Alpha();
1200 double redIPS
= (double)(redI
) / 255.0;
1201 double blueIPS
= (double)(blueI
) / 255.0;
1202 double greenIPS
= (double)(greenI
) / 255.0;
1203 double alphaIPS
= (double)(alphaI
) / 255.0;
1204 double redDPS
= (double)(redD
) / 255.0;
1205 double blueDPS
= (double)(blueD
) / 255.0;
1206 double greenDPS
= (double)(greenD
) / 255.0;
1207 double alphaDPS
= (double)(alphaD
) / 255.0;
1209 // Create a pattern with the gradient.
1210 cairo_pattern_t
* gradient
;
1211 gradient
= gs_cairo
->cairo_pattern_create_radial (XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), 0, XLOG2DEV(xC
+xR
), YLOG2DEV(yC
+yR
), radius
* m_DEV2PS
);
1212 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1213 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1215 // Fill the rectangle with this pattern.
1216 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1217 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(xR
), YLOG2DEV(yR
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1218 gs_cairo
->cairo_fill(m_cairo
);
1220 gs_cairo
->cairo_pattern_destroy(gradient
);
1222 CalcBoundingBox(xR
, yR
);
1223 CalcBoundingBox(xR
+w
, yR
+h
);
1226 void wxGtkPrinterImplDC::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1230 wxCoord w
= rect
.width
;
1231 wxCoord h
= rect
.height
;
1233 unsigned char redI
= initialColour
.Red();
1234 unsigned char blueI
= initialColour
.Blue();
1235 unsigned char greenI
= initialColour
.Green();
1236 unsigned char alphaI
= initialColour
.Alpha();
1237 unsigned char redD
= destColour
.Red();
1238 unsigned char blueD
= destColour
.Blue();
1239 unsigned char greenD
= destColour
.Green();
1240 unsigned char alphaD
= destColour
.Alpha();
1242 double redIPS
= (double)(redI
) / 255.0;
1243 double blueIPS
= (double)(blueI
) / 255.0;
1244 double greenIPS
= (double)(greenI
) / 255.0;
1245 double alphaIPS
= (double)(alphaI
) / 255.0;
1246 double redDPS
= (double)(redD
) / 255.0;
1247 double blueDPS
= (double)(blueD
) / 255.0;
1248 double greenDPS
= (double)(greenD
) / 255.0;
1249 double alphaDPS
= (double)(alphaD
) / 255.0;
1251 // Create a pattern with the gradient.
1252 cairo_pattern_t
* gradient
;
1253 gradient
= gs_cairo
->cairo_pattern_create_linear (XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x
+w
), YLOG2DEV(y
));
1255 if (nDirection
== wxWEST
)
1257 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1258 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1261 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1262 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1265 // Fill the rectangle with this pattern.
1266 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1267 gs_cairo
->cairo_rectangle (m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(w
), YLOG2DEVREL(h
) );
1268 gs_cairo
->cairo_fill(m_cairo
);
1270 gs_cairo
->cairo_pattern_destroy(gradient
);
1272 CalcBoundingBox(x
, y
);
1273 CalcBoundingBox(x
+w
, y
+h
);
1276 bool wxGtkPrinterImplDC::DoGetPixel(wxCoord
WXUNUSED(x1
),
1277 wxCoord
WXUNUSED(y1
),
1278 wxColour
* WXUNUSED(col
)) const
1280 wxFAIL_MSG(_("not implemented"));
1284 void wxGtkPrinterImplDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1286 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1289 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
1290 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
1291 gs_cairo
->cairo_stroke ( m_cairo
);
1293 CalcBoundingBox( x1
, y1
);
1294 CalcBoundingBox( x2
, y2
);
1297 void wxGtkPrinterImplDC::DoCrossHair(wxCoord x
, wxCoord y
)
1304 gs_cairo
->cairo_move_to (m_cairo
, XLOG2DEV(x
), 0);
1305 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEV(x
), YLOG2DEVREL(h
));
1306 gs_cairo
->cairo_move_to (m_cairo
, 0, YLOG2DEV(y
));
1307 gs_cairo
->cairo_line_to (m_cairo
, XLOG2DEVREL(w
), YLOG2DEV(y
));
1309 gs_cairo
->cairo_stroke (m_cairo
);
1310 CalcBoundingBox( 0, 0 );
1311 CalcBoundingBox( w
, h
);
1314 void wxGtkPrinterImplDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1316 double dx
= x1
- xc
;
1317 double dy
= y1
- yc
;
1318 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1320 double alpha1
, alpha2
;
1321 if (x1
== x2
&& y1
== y2
)
1329 alpha1
= alpha2
= 0.0;
1333 alpha1
= (x1
- xc
== 0) ?
1334 (y1
- yc
< 0) ? 90.0 : -90.0 :
1335 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1336 alpha2
= (x2
- xc
== 0) ?
1337 (y2
- yc
< 0) ? 90.0 : -90.0 :
1338 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1340 while (alpha1
<= 0) alpha1
+= 360;
1341 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1342 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1343 while (alpha2
> 360) alpha2
-= 360;
1349 gs_cairo
->cairo_new_path(m_cairo
);
1351 gs_cairo
->cairo_arc_negative ( m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
);
1352 gs_cairo
->cairo_line_to(m_cairo
, XLOG2DEV(xc
), YLOG2DEV(yc
));
1353 gs_cairo
->cairo_close_path (m_cairo
);
1355 SetBrush( m_brush
);
1356 gs_cairo
->cairo_fill_preserve( m_cairo
);
1359 gs_cairo
->cairo_stroke( m_cairo
);
1361 CalcBoundingBox (x1
, y1
);
1362 CalcBoundingBox (xc
, yc
);
1363 CalcBoundingBox (x2
, y2
);
1366 void wxGtkPrinterImplDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1368 gs_cairo
->cairo_save( m_cairo
);
1370 gs_cairo
->cairo_new_path(m_cairo
);
1372 gs_cairo
->cairo_translate( m_cairo
, XLOG2DEV((wxCoord
) (x
+ w
/ 2.)), XLOG2DEV((wxCoord
) (y
+ h
/ 2.)) );
1373 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
1374 gs_cairo
->cairo_scale( m_cairo
, 1.0, scale
);
1376 gs_cairo
->cairo_arc_negative ( m_cairo
, 0, 0, XLOG2DEVREL(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1379 gs_cairo
->cairo_stroke_preserve( m_cairo
);
1381 gs_cairo
->cairo_line_to(m_cairo
, 0,0);
1383 SetBrush( m_brush
);
1384 gs_cairo
->cairo_fill( m_cairo
);
1386 gs_cairo
->cairo_restore( m_cairo
);
1388 CalcBoundingBox( x
, y
);
1389 CalcBoundingBox( x
+w
, y
+h
);
1392 void wxGtkPrinterImplDC::DoDrawPoint(wxCoord x
, wxCoord y
)
1394 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1398 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1399 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1400 gs_cairo
->cairo_stroke ( m_cairo
);
1402 CalcBoundingBox( x
, y
);
1405 void wxGtkPrinterImplDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1407 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1414 for ( i
=0; i
<n
; i
++ )
1415 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1417 gs_cairo
->cairo_move_to ( m_cairo
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1419 for (i
= 1; i
< n
; i
++)
1420 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1422 gs_cairo
->cairo_stroke ( m_cairo
);
1425 void wxGtkPrinterImplDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1429 gs_cairo
->cairo_save(m_cairo
);
1430 if (fillStyle
== wxWINDING_RULE
)
1431 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1433 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1435 int x
= points
[0].x
+ xoffset
;
1436 int y
= points
[0].y
+ yoffset
;
1437 gs_cairo
->cairo_new_path(m_cairo
);
1438 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1440 for (i
= 1; i
< n
; i
++)
1442 int x
= points
[i
].x
+ xoffset
;
1443 int y
= points
[i
].y
+ yoffset
;
1444 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
) );
1446 gs_cairo
->cairo_close_path(m_cairo
);
1448 SetBrush( m_brush
);
1449 gs_cairo
->cairo_fill_preserve( m_cairo
);
1452 gs_cairo
->cairo_stroke( m_cairo
);
1454 CalcBoundingBox( x
, y
);
1456 gs_cairo
->cairo_restore(m_cairo
);
1459 void wxGtkPrinterImplDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1462 wxImplDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1464 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1468 void wxGtkPrinterImplDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1473 gs_cairo
->cairo_new_path(m_cairo
);
1474 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
1476 SetBrush( m_brush
);
1477 gs_cairo
->cairo_fill_preserve( m_cairo
);
1480 gs_cairo
->cairo_stroke( m_cairo
);
1482 CalcBoundingBox( x
, y
);
1483 CalcBoundingBox( x
+ width
, y
+ height
);
1486 void wxGtkPrinterImplDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1491 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1493 wxCoord dd
= 2 * (wxCoord
) radius
;
1494 if (dd
> width
) dd
= width
;
1495 if (dd
> height
) dd
= height
;
1498 wxCoord rad
= (wxCoord
) radius
;
1500 gs_cairo
->cairo_new_path(m_cairo
);
1501 gs_cairo
->cairo_move_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1502 gs_cairo
->cairo_curve_to(m_cairo
,
1503 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1504 XLOG2DEV(x
),YLOG2DEV(y
),
1505 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1506 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1507 gs_cairo
->cairo_curve_to(m_cairo
,
1508 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1509 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1510 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1511 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1512 gs_cairo
->cairo_curve_to(m_cairo
,
1513 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1514 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1515 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1516 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1517 gs_cairo
->cairo_curve_to(m_cairo
,
1518 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1519 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1520 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1521 gs_cairo
->cairo_line_to(m_cairo
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1522 gs_cairo
->cairo_close_path(m_cairo
);
1525 gs_cairo
->cairo_fill_preserve(m_cairo
);
1528 gs_cairo
->cairo_stroke(m_cairo
);
1530 CalcBoundingBox(x
,y
);
1531 CalcBoundingBox(x
+width
,y
+height
);
1534 void wxGtkPrinterImplDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1539 gs_cairo
->cairo_save (m_cairo
);
1541 gs_cairo
->cairo_new_path(m_cairo
);
1543 gs_cairo
->cairo_translate (m_cairo
, XLOG2DEV((wxCoord
) (x
+ width
/ 2.)), YLOG2DEV((wxCoord
) (y
+ height
/ 2.)));
1544 gs_cairo
->cairo_scale(m_cairo
, 1, (double)YLOG2DEVREL(height
)/(double)XLOG2DEVREL(width
));
1545 gs_cairo
->cairo_arc ( m_cairo
, 0, 0, XLOG2DEVREL(width
/2), 0, 2 * M_PI
);
1547 SetBrush( m_brush
);
1548 gs_cairo
->cairo_fill_preserve( m_cairo
);
1551 gs_cairo
->cairo_stroke( m_cairo
);
1553 CalcBoundingBox( x
, y
);
1554 CalcBoundingBox( x
+ width
, y
+ height
);
1556 gs_cairo
->cairo_restore (m_cairo
);
1560 void wxGtkPrinterImplDC::DoDrawSpline(const wxPointList
*points
)
1564 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1567 wxPointList::compatibility_iterator node
= points
->GetFirst();
1568 p
= node
->GetData();
1572 node
= node
->GetNext();
1573 p
= node
->GetData();
1577 (double)(x1
+ c
) / 2;
1579 (double)(y1
+ d
) / 2;
1581 gs_cairo
->cairo_new_path( m_cairo
);
1582 gs_cairo
->cairo_move_to( m_cairo
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1583 gs_cairo
->cairo_line_to( m_cairo
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1585 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1586 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1588 node
= node
->GetNext();
1591 q
= node
->GetData();
1599 x3
= (double)(x2
+ c
) / 2;
1600 y3
= (double)(y2
+ d
) / 2;
1602 gs_cairo
->cairo_curve_to(m_cairo
,
1603 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1604 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1605 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1607 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1608 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1610 node
= node
->GetNext();
1613 gs_cairo
->cairo_line_to ( m_cairo
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1615 gs_cairo
->cairo_stroke( m_cairo
);
1617 #endif // wxUSE_SPLINES
1619 bool wxGtkPrinterImplDC::DoBlit(wxCoord xdest
, wxCoord ydest
,
1620 wxCoord width
, wxCoord height
,
1621 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1622 int rop
, bool useMask
,
1623 wxCoord
WXUNUSED_UNLESS_DEBUG(xsrcMask
),
1624 wxCoord
WXUNUSED_UNLESS_DEBUG(ysrcMask
))
1626 wxASSERT_MSG( xsrcMask
== wxDefaultCoord
&& ysrcMask
== wxDefaultCoord
,
1627 wxT("mask coordinates are not supported") );
1629 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1631 // Blit into a bitmap.
1632 wxBitmap
bitmap( width
, height
);
1634 memDC
.SelectObject(bitmap
);
1635 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1636 memDC
.SelectObject(wxNullBitmap
);
1638 // Draw bitmap. scaling and positioning is done there.
1639 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1644 void wxGtkPrinterImplDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1646 DoDrawBitmap( icon
, x
, y
, true );
1649 void wxGtkPrinterImplDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1651 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrinterImplDC::DoDrawBitmap"));
1653 cairo_surface_t
* surface
;
1654 x
= wxCoord(XLOG2DEV(x
));
1655 y
= wxCoord(YLOG2DEV(y
));
1656 int bw
= bitmap
.GetWidth();
1657 int bh
= bitmap
.GetHeight();
1658 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1659 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1660 wxUint32
* data
= (wxUint32
*)buffer
;
1662 wxMask
*mask
= NULL
;
1663 if (useMask
) mask
= bmpSource
.GetMask();
1665 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1666 // then we'll use a different format and iterator than if it doesn't.
1667 if (bmpSource
.HasAlpha() || mask
)
1669 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1670 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1671 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1672 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1674 wxAlphaPixelData::Iterator
p(pixData
);
1676 for (y
=0; y
<bh
; y
++)
1678 wxAlphaPixelData::Iterator rowStart
= p
;
1679 for (x
=0; x
<bw
; x
++)
1681 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1682 // with alpha in the upper 8 bits, then red, then green, then
1683 // blue. The 32-bit quantities are stored native-endian.
1684 // Pre-multiplied alpha is used.
1685 unsigned char alpha
= p
.Alpha();
1687 if (!bmpSource
.HasAlpha() && mask
)
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
= gs_cairo
->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 gs_cairo
->cairo_save(m_cairo
);
1734 // Prepare to draw the image.
1735 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1738 cairo_filter_t filter
= CAIRO_FILTER_BILINEAR
;
1739 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1740 cairo_pattern_set_filter(pattern
,filter
);
1741 wxDouble scaleX
= (wxDouble
) XLOG2DEVREL(bw
) / (wxDouble
) bw
;
1742 wxDouble scaleY
= (wxDouble
) YLOG2DEVREL(bh
) / (wxDouble
) bh
;
1743 cairo_scale(m_cairo
, scaleX
, scaleY
);
1745 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
1746 // Use the original size here since the context is scaled already.
1747 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1748 // Fill the rectangle using the pattern.
1749 gs_cairo
->cairo_fill(m_cairo
);
1752 gs_cairo
->cairo_pattern_destroy(pattern
);
1753 gs_cairo
->cairo_surface_destroy(surface
);
1756 CalcBoundingBox(0,0);
1757 CalcBoundingBox(bw
,bh
);
1759 gs_cairo
->cairo_restore(m_cairo
);
1762 void wxGtkPrinterImplDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1764 DoDrawRotatedText( text
, x
, y
, 0.0 );
1767 void wxGtkPrinterImplDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1769 double xx
= XLOG2DEV(x
);
1770 double yy
= YLOG2DEV(y
);
1774 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1776 const wxUTF8Buf data
= text
.utf8_str();
1778 size_t datalen
= strlen(data
);
1779 pango_layout_set_text( m_layout
, data
, datalen
);
1783 PangoAttrList
*attrs
= pango_attr_list_new();
1784 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1786 a
->end_index
= datalen
;
1787 pango_attr_list_insert(attrs
, a
);
1788 pango_layout_set_attributes(m_layout
, attrs
);
1789 pango_attr_list_unref(attrs
);
1792 if (m_textForegroundColour
.Ok())
1794 unsigned char red
= m_textForegroundColour
.Red();
1795 unsigned char blue
= m_textForegroundColour
.Blue();
1796 unsigned char green
= m_textForegroundColour
.Green();
1797 unsigned char alpha
= m_textForegroundColour
.Alpha();
1799 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1801 double redPS
= (double)(red
) / 255.0;
1802 double bluePS
= (double)(blue
) / 255.0;
1803 double greenPS
= (double)(green
) / 255.0;
1804 double alphaPS
= (double)(alpha
) / 255.0;
1806 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1809 m_currentBlue
= blue
;
1810 m_currentGreen
= green
;
1811 m_currentAlpha
= alpha
;
1817 // Scale font description.
1818 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1819 double size
= oldSize
;
1820 size
= size
* m_scaleX
;
1821 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1823 // Actually apply scaled font.
1824 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1826 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1828 if ( m_backgroundMode
== wxSOLID
)
1830 unsigned char red
= m_textBackgroundColour
.Red();
1831 unsigned char blue
= m_textBackgroundColour
.Blue();
1832 unsigned char green
= m_textBackgroundColour
.Green();
1833 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1835 double redPS
= (double)(red
) / 255.0;
1836 double bluePS
= (double)(blue
) / 255.0;
1837 double greenPS
= (double)(green
) / 255.0;
1838 double alphaPS
= (double)(alpha
) / 255.0;
1840 gs_cairo
->cairo_save(m_cairo
);
1841 gs_cairo
->cairo_translate(m_cairo
, xx
, yy
);
1842 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1843 gs_cairo
->cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1844 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, w
, h
); // still in cairo units
1845 gs_cairo
->cairo_fill(m_cairo
);
1846 gs_cairo
->cairo_restore(m_cairo
);
1850 gs_cairo
->cairo_move_to (m_cairo
, xx
, yy
);
1852 gs_cairo
->cairo_save( m_cairo
);
1854 if (fabs(angle
) > 0.00001)
1855 gs_cairo
->cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1857 gs_cairo
->pango_cairo_update_layout (m_cairo
, m_layout
);
1858 gs_cairo
->pango_cairo_show_layout (m_cairo
, m_layout
);
1860 gs_cairo
->cairo_restore( m_cairo
);
1864 // Undo underline attributes setting
1865 pango_layout_set_attributes(m_layout
, NULL
);
1868 // Reset unscaled size.
1869 pango_font_description_set_size( m_fontdesc
, oldSize
);
1871 // Actually apply unscaled font.
1872 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1874 // Back to device units:
1875 CalcBoundingBox (x
, y
);
1876 CalcBoundingBox (x
+ w
, y
+ h
);
1879 void wxGtkPrinterImplDC::Clear()
1881 // Clear does nothing for printing, but keep the code
1884 gs_cairo->cairo_save(m_cairo);
1885 gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
1886 SetBrush(m_backgroundBrush);
1887 gs_cairo->cairo_paint(m_cairo);
1888 gs_cairo->cairo_restore(m_cairo);
1892 void wxGtkPrinterImplDC::SetFont( const wxFont
& font
)
1899 pango_font_description_free( m_fontdesc
);
1901 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
); // m_fontdesc is now set to device units
1903 // Scale font description from device units to pango units
1904 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1905 double size
= oldSize
*m_DEV2PS
; // scale to cairo units
1906 pango_font_description_set_size( m_fontdesc
, (gint
)size
); // apply to description
1908 // Actually apply scaled font.
1909 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1913 void wxGtkPrinterImplDC::SetPen( const wxPen
& pen
)
1915 if (!pen
.Ok()) return;
1921 if (m_pen
.GetWidth() <= 0)
1924 width
= (double) m_pen
.GetWidth();
1926 gs_cairo
->cairo_set_line_width( m_cairo
, width
* m_DEV2PS
* m_scaleX
);
1927 static const double dotted
[] = {2.0, 5.0};
1928 static const double short_dashed
[] = {4.0, 4.0};
1929 static const double long_dashed
[] = {4.0, 8.0};
1930 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1932 switch (m_pen
.GetStyle())
1934 case wxDOT
: gs_cairo
->cairo_set_dash( m_cairo
, dotted
, 2, 0 ); break;
1935 case wxSHORT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, short_dashed
, 2, 0 ); break;
1936 case wxLONG_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, long_dashed
, 2, 0 ); break;
1937 case wxDOT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, dotted_dashed
, 4, 0 ); break;
1941 int num
= m_pen
.GetDashes (&wx_dashes
);
1942 gdouble
*g_dashes
= g_new( gdouble
, num
);
1944 for (i
= 0; i
< num
; ++i
)
1945 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1946 gs_cairo
->cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
1952 default: gs_cairo
->cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
1955 switch (m_pen
.GetCap())
1957 case wxCAP_PROJECTING
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
1958 case wxCAP_BUTT
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
1960 default: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
1963 switch (m_pen
.GetJoin())
1965 case wxJOIN_BEVEL
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
1966 case wxJOIN_MITER
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
1968 default: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
1971 unsigned char red
= m_pen
.GetColour().Red();
1972 unsigned char blue
= m_pen
.GetColour().Blue();
1973 unsigned char green
= m_pen
.GetColour().Green();
1974 unsigned char alpha
= m_pen
.GetColour().Alpha();
1976 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1978 double redPS
= (double)(red
) / 255.0;
1979 double bluePS
= (double)(blue
) / 255.0;
1980 double greenPS
= (double)(green
) / 255.0;
1981 double alphaPS
= (double)(alpha
) / 255.0;
1983 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1986 m_currentBlue
= blue
;
1987 m_currentGreen
= green
;
1988 m_currentAlpha
= alpha
;
1992 void wxGtkPrinterImplDC::SetBrush( const wxBrush
& brush
)
1994 if (!brush
.Ok()) return;
1998 if (m_brush
.GetStyle() == wxTRANSPARENT
)
2000 gs_cairo
->cairo_set_source_rgba( m_cairo
, 0, 0, 0, 0 );
2009 unsigned char red
= m_brush
.GetColour().Red();
2010 unsigned char blue
= m_brush
.GetColour().Blue();
2011 unsigned char green
= m_brush
.GetColour().Green();
2012 unsigned char alpha
= m_brush
.GetColour().Alpha();
2014 double redPS
= (double)(red
) / 255.0;
2015 double bluePS
= (double)(blue
) / 255.0;
2016 double greenPS
= (double)(green
) / 255.0;
2017 double alphaPS
= (double)(alpha
) / 255.0;
2019 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
2021 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
2024 m_currentBlue
= blue
;
2025 m_currentGreen
= green
;
2026 m_currentAlpha
= alpha
;
2029 if (m_brush
.IsHatch())
2032 cairo_surface_t
*surface
;
2033 surface
= gs_cairo
->cairo_surface_create_similar(gs_cairo
->cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
2034 cr
= gs_cairo
->cairo_create(surface
);
2035 gs_cairo
->cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
2036 gs_cairo
->cairo_set_line_width(cr
, 1);
2037 gs_cairo
->cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
2039 switch (m_brush
.GetStyle())
2042 gs_cairo
->cairo_move_to(cr
, 5, 0);
2043 gs_cairo
->cairo_line_to(cr
, 5, 10);
2044 gs_cairo
->cairo_move_to(cr
, 0, 5);
2045 gs_cairo
->cairo_line_to(cr
, 10, 5);
2047 case wxBDIAGONAL_HATCH
:
2048 gs_cairo
->cairo_move_to(cr
, 0, 10);
2049 gs_cairo
->cairo_line_to(cr
, 10, 0);
2051 case wxFDIAGONAL_HATCH
:
2052 gs_cairo
->cairo_move_to(cr
, 0, 0);
2053 gs_cairo
->cairo_line_to(cr
, 10, 10);
2055 case wxCROSSDIAG_HATCH
:
2056 gs_cairo
->cairo_move_to(cr
, 0, 0);
2057 gs_cairo
->cairo_line_to(cr
, 10, 10);
2058 gs_cairo
->cairo_move_to(cr
, 10, 0);
2059 gs_cairo
->cairo_line_to(cr
, 0, 10);
2061 case wxHORIZONTAL_HATCH
:
2062 gs_cairo
->cairo_move_to(cr
, 0, 5);
2063 gs_cairo
->cairo_line_to(cr
, 10, 5);
2065 case wxVERTICAL_HATCH
:
2066 gs_cairo
->cairo_move_to(cr
, 5, 0);
2067 gs_cairo
->cairo_line_to(cr
, 5, 10);
2070 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
2073 gs_cairo
->cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
2074 gs_cairo
->cairo_stroke (cr
);
2076 gs_cairo
->cairo_destroy(cr
);
2077 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface (surface
);
2078 gs_cairo
->cairo_surface_destroy(surface
);
2079 gs_cairo
->cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
2080 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
2081 gs_cairo
->cairo_pattern_destroy(pattern
);
2085 void wxGtkPrinterImplDC::SetLogicalFunction( int function
)
2087 if (function
== wxCLEAR
)
2088 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
2089 else if (function
== wxOR
)
2090 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
2091 else if (function
== wxNO_OP
)
2092 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
2093 else if (function
== wxAND
)
2094 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
2095 else if (function
== wxSET
)
2096 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
2097 else if (function
== wxXOR
)
2098 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
2099 else // wxCOPY or anything else.
2100 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
2103 void wxGtkPrinterImplDC::SetBackground( const wxBrush
& brush
)
2105 m_backgroundBrush
= brush
;
2106 gs_cairo
->cairo_save(m_cairo
);
2107 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2109 SetBrush(m_backgroundBrush
);
2110 gs_cairo
->cairo_paint(m_cairo
);
2111 gs_cairo
->cairo_restore(m_cairo
);
2114 void wxGtkPrinterImplDC::SetBackgroundMode(int mode
)
2116 if (mode
== wxSOLID
)
2117 m_backgroundMode
= wxSOLID
;
2119 m_backgroundMode
= wxTRANSPARENT
;
2122 void wxGtkPrinterImplDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2124 gs_cairo
->cairo_rectangle ( m_cairo
, XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2125 gs_cairo
->cairo_clip(m_cairo
);
2128 void wxGtkPrinterImplDC::DestroyClippingRegion()
2130 gs_cairo
->cairo_reset_clip(m_cairo
);
2133 bool wxGtkPrinterImplDC::StartDoc(const wxString
& WXUNUSED(message
))
2138 void wxGtkPrinterImplDC::EndDoc()
2143 void wxGtkPrinterImplDC::StartPage()
2148 void wxGtkPrinterImplDC::EndPage()
2153 wxCoord
wxGtkPrinterImplDC::GetCharHeight() const
2155 pango_layout_set_text( m_layout
, "H", 1 );
2158 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2160 return wxRound( h
* m_PS2DEV
);
2163 wxCoord
wxGtkPrinterImplDC::GetCharWidth() const
2165 pango_layout_set_text( m_layout
, "H", 1 );
2168 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2170 return wxRound( w
* m_PS2DEV
);
2173 void wxGtkPrinterImplDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2175 wxCoord
*externalLeading
,
2176 const wxFont
*theFont
) const
2184 if ( externalLeading
)
2185 *externalLeading
= 0;
2192 // Set layout's text
2193 const wxUTF8Buf dataUTF8
= string
.utf8_str();
2195 PangoFontDescription
*desc
= m_fontdesc
;
2196 if (theFont
) desc
= theFont
->GetNativeFontInfo()->description
;
2198 gint oldSize
= pango_font_description_get_size( desc
);
2199 double size
= oldSize
;
2200 size
= size
* m_scaleY
;
2201 pango_font_description_set_size( desc
, (gint
)size
);
2203 // apply scaled font
2204 pango_layout_set_font_description( m_layout
, desc
);
2206 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2209 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2212 *width
= wxRound( (double)w
/ m_scaleX
* m_PS2DEV
);
2214 *height
= wxRound( (double)h
/ m_scaleY
* m_PS2DEV
);
2218 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2219 int baseline
= pango_layout_iter_get_baseline(iter
);
2220 pango_layout_iter_free(iter
);
2221 *descent
= wxRound( (h
- PANGO_PIXELS(baseline
)) * m_PS2DEV
);
2224 // Reset unscaled size.
2225 pango_font_description_set_size( desc
, oldSize
);
2227 // Reset unscaled font.
2228 pango_layout_set_font_description( m_layout
, m_fontdesc
);
2231 void wxGtkPrinterImplDC::DoGetSize(int* width
, int* height
) const
2233 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2236 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_POINTS
) * m_PS2DEV
);
2238 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_POINTS
) * m_PS2DEV
);
2241 void wxGtkPrinterImplDC::DoGetSizeMM(int *width
, int *height
) const
2243 GtkPageSetup
*setup
= gtk_print_context_get_page_setup( m_gpc
);
2246 *width
= wxRound( gtk_page_setup_get_paper_width( setup
, GTK_UNIT_MM
) );
2248 *height
= wxRound( gtk_page_setup_get_paper_height( setup
, GTK_UNIT_MM
) );
2251 wxSize
wxGtkPrinterImplDC::GetPPI() const
2253 return wxSize( (int)m_resolution
, (int)m_resolution
);
2256 void wxGtkPrinterImplDC::SetPrintData(const wxPrintData
& data
)
2261 // overriden for wxPrinterDC Impl
2263 wxRect
wxGtkPrinterImplDC::GetPaperRect()
2265 // Does GtkPrint support printer margins?
2268 DoGetSize( &w
, &h
);
2269 return wxRect( 0,0,w
,h
);
2272 int wxGtkPrinterImplDC::GetResolution()
2274 return m_resolution
;
2277 // ----------------------------------------------------------------------------
2279 // ----------------------------------------------------------------------------
2281 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2283 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2284 wxPrintout
* WXUNUSED(printoutForPrinting
))
2289 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2290 wxPrintout
*printoutForPrinting
,
2291 wxPrintDialogData
*data
)
2292 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2294 Init(printout
, printoutForPrinting
);
2297 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2298 wxPrintout
*printoutForPrinting
,
2300 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2302 Init(printout
, printoutForPrinting
);
2305 wxGtkPrintPreview::~wxGtkPrintPreview()
2309 bool wxGtkPrintPreview::Print(bool interactive
)
2311 if (!m_printPrintout
)
2314 wxPrinter
printer(& m_printDialogData
);
2315 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2318 void wxGtkPrintPreview::DetermineScaling()
2320 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2322 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2324 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2328 wxSize ScreenPixels
= wxGetDisplaySize();
2329 wxSize ScreenMM
= wxGetDisplaySizeMM();
2331 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2332 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2334 // TODO !!!!!!!!!!!!!!!
2335 int resolution
= 600;
2336 m_previewPrintout
->SetPPIPrinter( resolution
, resolution
);
2338 // Get width and height in points (1/72th of an inch)
2339 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2341 sizeDevUnits
.x
= wxRound((double)sizeDevUnits
.x
* (double)resolution
/ 72.0);
2342 sizeDevUnits
.y
= wxRound((double)sizeDevUnits
.y
* (double)resolution
/ 72.0);
2343 wxSize
sizeTenthsMM(paper
->GetSize());
2344 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2346 // If in landscape mode, we need to swap the width and height.
2347 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2349 m_pageWidth
= sizeDevUnits
.y
;
2350 m_pageHeight
= sizeDevUnits
.x
;
2351 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2355 m_pageWidth
= sizeDevUnits
.x
;
2356 m_pageHeight
= sizeDevUnits
.y
;
2357 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2359 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2360 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2362 // At 100%, the page should look about page-size on the screen.
2363 m_previewScaleX
= 0.8 * 72.0 / (double)resolution
;
2364 m_previewScaleY
= m_previewScaleX
;