1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/print.cpp
3 // Author: Anthony Bretaudeau
4 // Purpose: GTK printing support
6 // RCS-ID: $Id: print.cpp,v 1 2007-08-25 05:44:44 PC Exp $
7 // Copyright: (c) 2007 wxWidgets development team
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/gtk/print.h"
24 #include "wx/dcmemory.h"
28 #include "wx/module.h"
31 #include "wx/fontutil.h"
32 #include "wx/gtk/private.h"
33 #include "wx/dynlib.h"
35 #include "wx/rawbmp.h"
38 #include <gtk/gtkpagesetupunixdialog.h>
41 wxFORCE_LINK_THIS_MODULE(gtk_print
)
43 #if wxUSE_LIBGNOMEPRINT
44 #include "wx/gtk/gnome/gprint.h"
47 // Usefull to convert angles from/to Rad to/from Deg.
48 static const double RAD2DEG
= 180.0 / M_PI
;
49 static const double DEG2RAD
= M_PI
/ 180.0;
51 static wxCairoLibrary
* gs_cairo
= NULL
;
53 //----------------------------------------------------------------------------
55 // Initialized when starting the app : if it successfully load the gtk-print framework,
56 // it uses it. If not, it falls back to gnome print (see /gtk/gnome/gprint.cpp) then
57 // to postscript if gnomeprint is not available.
58 //----------------------------------------------------------------------------
60 class wxGtkPrintModule
: public wxModule
65 #if wxUSE_LIBGNOMEPRINT
66 // This module must be initialized AFTER gnomeprint's one
67 AddDependency(CLASSINFO(wxGnomePrintModule
));
74 DECLARE_DYNAMIC_CLASS(wxGtkPrintModule
)
77 bool wxGtkPrintModule::OnInit()
79 gs_cairo
= wxCairoLibrary::Get();
80 if (gs_cairo
&& gtk_check_version(2,10,0) == NULL
)
81 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()
139 wxDialog
*wxGtkPrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
144 wxDC
* wxGtkPrintFactory::CreatePrinterDC( const wxPrintData
& data
)
146 return new wxGtkPrintDC(data
);
149 bool wxGtkPrintFactory::HasOwnPrintToFile()
154 bool wxGtkPrintFactory::HasPrinterLine()
159 wxString
wxGtkPrintFactory::CreatePrinterLine()
162 return wxEmptyString
;
165 bool wxGtkPrintFactory::HasStatusLine()
171 wxString
wxGtkPrintFactory::CreateStatusLine()
174 return wxEmptyString
;
177 wxPrintNativeDataBase
*wxGtkPrintFactory::CreatePrintNativeData()
179 return new wxGtkPrintNativeData
;
182 //----------------------------------------------------------------------------
183 // Callback functions for Gtk Printings.
184 //----------------------------------------------------------------------------
186 // We use it to pass useful objets to gtk printing callback functions.
189 wxGtkPrinter
* printer
;
190 wxPrintout
* printout
;
196 static void gtk_begin_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
198 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
200 data
->printer
->BeginPrint(data
->printout
, operation
, context
);
203 static void gtk_draw_page_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gint page_nr
, gpointer user_data
)
205 wxPrinterToGtkData
*data
= (wxPrinterToGtkData
*) user_data
;
207 data
->printer
->DrawPage(data
->printout
, operation
, context
, page_nr
);
210 static void gtk_end_print_callback (GtkPrintOperation
*operation
, GtkPrintContext
*context
, gpointer user_data
)
212 wxPrintout
*printout
= (wxPrintout
*) user_data
;
214 printout
->OnEndPrinting();
217 static gboolean
gtk_preview_print_callback (GtkPrintOperation
*operation
, GtkPrintOperationPreview
*preview
, GtkPrintContext
*context
, GtkWindow
*parent
, gpointer user_data
)
219 wxPrintout
*printout
= (wxPrintout
*) user_data
;
221 printout
->SetIsPreview(true);
223 /* We create a cairo context with 72dpi resolution. This resolution is only used for positionning. */
224 cairo_t
*cairo
= gdk_cairo_create(GTK_WIDGET(parent
)->window
);
225 gtk_print_context_set_cairo_context(context
, cairo
, 72, 72);
231 //----------------------------------------------------------------------------
232 // wxGtkPrintNativeData
233 //----------------------------------------------------------------------------
235 IMPLEMENT_CLASS(wxGtkPrintNativeData
, wxPrintNativeDataBase
)
237 wxGtkPrintNativeData::wxGtkPrintNativeData()
239 m_config
= gtk_print_settings_new();
242 wxGtkPrintNativeData::~wxGtkPrintNativeData()
244 g_object_unref (m_config
);
247 // Convert datas stored in m_config to a wxPrintData.
248 // Called by wxPrintData::ConvertFromNative().
249 bool wxGtkPrintNativeData::TransferTo( wxPrintData
&data
)
254 GtkPrintQuality quality
= gtk_print_settings_get_quality(m_config
);
255 if (quality
== GTK_PRINT_QUALITY_HIGH
)
256 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
257 else if (quality
== GTK_PRINT_QUALITY_LOW
)
258 data
.SetQuality(wxPRINT_QUALITY_LOW
);
259 else if (quality
== GTK_PRINT_QUALITY_DRAFT
)
260 data
.SetQuality(wxPRINT_QUALITY_DRAFT
);
262 data
.SetQuality(wxPRINT_QUALITY_MEDIUM
);
264 data
.SetNoCopies(gtk_print_settings_get_n_copies(m_config
));
266 data
.SetColour(gtk_print_settings_get_use_color(m_config
));
268 switch (gtk_print_settings_get_duplex(m_config
))
270 case GTK_PRINT_DUPLEX_SIMPLEX
: data
.SetDuplex (wxDUPLEX_SIMPLEX
);
273 case GTK_PRINT_DUPLEX_HORIZONTAL
: data
.SetDuplex (wxDUPLEX_HORIZONTAL
);
277 case GTK_PRINT_DUPLEX_VERTICAL
: data
.SetDuplex (wxDUPLEX_VERTICAL
);
281 GtkPageOrientation orientation
= gtk_print_settings_get_orientation (m_config
);
282 if (orientation
== GTK_PAGE_ORIENTATION_PORTRAIT
)
284 data
.SetOrientation(wxPORTRAIT
);
285 data
.SetOrientationReversed(false);
287 else if (orientation
== GTK_PAGE_ORIENTATION_LANDSCAPE
)
289 data
.SetOrientation(wxLANDSCAPE
);
290 data
.SetOrientationReversed(false);
292 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
)
294 data
.SetOrientation(wxPORTRAIT
);
295 data
.SetOrientationReversed(true);
297 else if (orientation
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
)
299 data
.SetOrientation(wxLANDSCAPE
);
300 data
.SetOrientationReversed(true);
303 data
.SetCollate(gtk_print_settings_get_collate (m_config
));
305 // Paper formats : these are the most common paper formats.
306 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (m_config
);
308 data
.SetPaperId(wxPAPER_NONE
);
309 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A3
)))
310 data
.SetPaperId(wxPAPER_A3
);
311 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A4
)))
312 data
.SetPaperId(wxPAPER_A4
);
313 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_A5
)))
314 data
.SetPaperId(wxPAPER_A5
);
315 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_B5
)))
316 data
.SetPaperId(wxPAPER_B5
);
317 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LETTER
)))
318 data
.SetPaperId(wxPAPER_LETTER
);
319 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
)))
320 data
.SetPaperId(wxPAPER_LEGAL
);
321 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
)))
322 data
.SetPaperId(wxPAPER_EXECUTIVE
);
323 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_number-10")))
324 data
.SetPaperId(wxPAPER_ENV_10
);
325 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c5")))
326 data
.SetPaperId(wxPAPER_ENV_C5
);
327 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c6")))
328 data
.SetPaperId(wxPAPER_ENV_C6
);
329 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"jis-b5")))
330 data
.SetPaperId(wxPAPER_B5_TRANSVERSE
);
331 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b5")))
332 data
.SetPaperId(wxPAPER_ENV_B5
);
333 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na_monarch")))
334 data
.SetPaperId(wxPAPER_ENV_MONARCH
);
335 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-c")))
336 data
.SetPaperId( wxPAPER_CSHEET
);
337 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-d")))
338 data
.SetPaperId( wxPAPER_DSHEET
);
339 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-e")))
340 data
.SetPaperId( wxPAPER_ESHEET
);
341 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
342 data
.SetPaperId( wxPAPER_LETTERSMALL
);
343 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"engineering-b")))
344 data
.SetPaperId( wxPAPER_TABLOID
);
345 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
346 data
.SetPaperId( wxPAPER_LEDGER
);
347 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"statement")))
348 data
.SetPaperId( wxPAPER_STATEMENT
);
349 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( GTK_PAPER_NAME_A4
)))
350 data
.SetPaperId( wxPAPER_A4SMALL
);
351 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
352 data
.SetPaperId( wxPAPER_B4
);
353 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"folio")))
354 data
.SetPaperId( wxPAPER_FOLIO
);
355 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"quarto")))
356 data
.SetPaperId( wxPAPER_QUARTO
);
357 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"10x14")))
358 data
.SetPaperId( wxPAPER_10X14
);
359 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"ledger")))
360 data
.SetPaperId( wxPAPER_11X17
);
361 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"letter")))
362 data
.SetPaperId( wxPAPER_NOTE
);
363 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"na-number-9-envelope")))
364 data
.SetPaperId( wxPAPER_ENV_9
);
365 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-11")))
366 data
.SetPaperId( wxPAPER_ENV_11
);
367 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-12")))
368 data
.SetPaperId( wxPAPER_ENV_12
);
369 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"number-14")))
370 data
.SetPaperId( wxPAPER_ENV_14
);
371 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-designated")))
372 data
.SetPaperId( wxPAPER_ENV_DL
);
373 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c3")))
374 data
.SetPaperId( wxPAPER_ENV_C3
);
375 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-c4")))
376 data
.SetPaperId( wxPAPER_ENV_C4
);
377 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"c6/c5")))
378 data
.SetPaperId( wxPAPER_ENV_C65
);
379 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b4")))
380 data
.SetPaperId( wxPAPER_ENV_B4
);
381 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"iso-b6")))
382 data
.SetPaperId( wxPAPER_ENV_B6
);
383 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"Italian")))
384 data
.SetPaperId( wxPAPER_ENV_ITALY
);
385 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"personal")))
386 data
.SetPaperId( wxPAPER_ENV_PERSONAL
);
387 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-us")))
388 data
.SetPaperId( wxPAPER_FANFOLD_US
);
389 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"fanfold-European")))
390 data
.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN
);
391 else if (gtk_paper_size_is_equal(paper_size
,gtk_paper_size_new ( (const gchar
*)"foolscap")))
392 data
.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN
);
394 data
.SetPaperId(wxPAPER_NONE
);
398 // Put datas given by the wxPrintData into m_config.
399 // Called by wxPrintData::ConvertToNative().
400 bool wxGtkPrintNativeData::TransferFrom( const wxPrintData
&data
)
405 wxPrintQuality quality
= data
.GetQuality();
406 if (quality
== wxPRINT_QUALITY_HIGH
)
407 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_HIGH
);
408 else if (quality
== wxPRINT_QUALITY_MEDIUM
)
409 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
410 else if (quality
== wxPRINT_QUALITY_LOW
)
411 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_LOW
);
412 else if (quality
== wxPRINT_QUALITY_DRAFT
)
413 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_DRAFT
);
414 else if (quality
> 1)
415 gtk_print_settings_set_resolution (m_config
, quality
);
417 gtk_print_settings_set_quality (m_config
, GTK_PRINT_QUALITY_NORMAL
);
419 gtk_print_settings_set_n_copies(m_config
, data
.GetNoCopies());
421 gtk_print_settings_set_use_color(m_config
, data
.GetColour());
423 switch (data
.GetDuplex())
425 case wxDUPLEX_SIMPLEX
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_SIMPLEX
);
428 case wxDUPLEX_HORIZONTAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_HORIZONTAL
);
432 case wxDUPLEX_VERTICAL
: gtk_print_settings_set_duplex (m_config
, GTK_PRINT_DUPLEX_VERTICAL
);
436 if (!data
.IsOrientationReversed())
438 if (data
.GetOrientation() == wxLANDSCAPE
)
439 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_LANDSCAPE
);
441 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_PORTRAIT
);
444 if (data
.GetOrientation() == wxLANDSCAPE
)
445 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
);
447 gtk_print_settings_set_orientation (m_config
, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
);
450 gtk_print_settings_set_collate (m_config
, data
.GetCollate());
452 // Paper formats: these are the most common paper formats.
453 switch (data
.GetPaperId())
455 case wxPAPER_A3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A3
));
457 case wxPAPER_A4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
459 case wxPAPER_A5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A5
));
461 case wxPAPER_B5_TRANSVERSE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "jis-b5"));
463 case wxPAPER_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_B5
));
465 case wxPAPER_LETTER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LETTER
));
467 case wxPAPER_LEGAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL
));
469 case wxPAPER_EXECUTIVE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE
));
471 case wxPAPER_ENV_10
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_number-10"));
473 case wxPAPER_ENV_C5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5"));
475 case wxPAPER_ENV_C6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c6"));
477 case wxPAPER_ENV_B5
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c5b5"));
479 case wxPAPER_ENV_MONARCH
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na_monarch"));
481 case wxPAPER_CSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-c"));
483 case wxPAPER_DSHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-d"));
485 case wxPAPER_ESHEET
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-e"));
487 case wxPAPER_LETTERSMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
489 case wxPAPER_TABLOID
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "engineering-b"));
491 case wxPAPER_LEDGER
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
493 case wxPAPER_STATEMENT
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "statement"));
495 case wxPAPER_A4SMALL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new (GTK_PAPER_NAME_A4
));
497 case wxPAPER_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
499 case wxPAPER_FOLIO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "folio"));
501 case wxPAPER_QUARTO
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "quarto"));
503 case wxPAPER_10X14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "10x14"));
505 case wxPAPER_11X17
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "ledger"));
507 case wxPAPER_NOTE
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "letter"));
509 case wxPAPER_ENV_9
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "na-number-9-envelope"));
511 case wxPAPER_ENV_11
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-11"));
513 case wxPAPER_ENV_12
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-12"));
515 case wxPAPER_ENV_14
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "number-14"));
517 case wxPAPER_ENV_DL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-designated"));
519 case wxPAPER_ENV_C3
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c3"));
521 case wxPAPER_ENV_C4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-c4"));
523 case wxPAPER_ENV_C65
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "c6/c5"));
525 case wxPAPER_ENV_B4
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b4"));
527 case wxPAPER_ENV_B6
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "iso-b6"));
529 case wxPAPER_ENV_ITALY
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "Italian"));
531 case wxPAPER_ENV_PERSONAL
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "personal"));
533 case wxPAPER_FANFOLD_US
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-us"));
535 case wxPAPER_FANFOLD_STD_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "fanfold-European"));
537 case wxPAPER_FANFOLD_LGL_GERMAN
: gtk_print_settings_set_paper_size(m_config
, gtk_paper_size_new ((const gchar
*) "foolscap"));
546 void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings
* config
)
549 m_config
= gtk_print_settings_copy(config
);
552 // Extract page setup from settings.
553 GtkPageSetup
* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings
* settings
)
555 GtkPageSetup
* page_setup
= gtk_page_setup_new();
556 gtk_page_setup_set_orientation (page_setup
, gtk_print_settings_get_orientation (settings
));
558 GtkPaperSize
*paper_size
= gtk_print_settings_get_paper_size (settings
);
559 if (paper_size
!= NULL
)
560 gtk_page_setup_set_paper_size_and_default_margins (page_setup
, paper_size
);
565 // Insert page setup into a given GtkPrintSettings.
566 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
)
568 gtk_print_settings_set_orientation ( settings
, gtk_page_setup_get_orientation (page_setup
));
569 gtk_print_settings_set_paper_size ( settings
, gtk_page_setup_get_paper_size (page_setup
));
572 //----------------------------------------------------------------------------
574 //----------------------------------------------------------------------------
576 IMPLEMENT_CLASS(wxGtkPrintDialog
, wxPrintDialogBase
)
578 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
579 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
580 wxPoint(0, 0), wxSize(600, 600),
581 wxDEFAULT_DIALOG_STYLE
|
585 m_printDialogData
= *data
;
591 wxGtkPrintDialog::wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
*data
)
592 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
593 wxPoint(0, 0), wxSize(600, 600),
594 wxDEFAULT_DIALOG_STYLE
|
598 m_printDialogData
= *data
;
605 wxGtkPrintDialog::~wxGtkPrintDialog()
609 // This is called even if we actually don't want the dialog to appear.
610 int wxGtkPrintDialog::ShowModal()
612 GtkPrintOperationResult response
;
614 // We need to restore the settings given in the constructor.
615 wxPrintData data
= m_printDialogData
.GetPrintData();
616 wxGtkPrintNativeData
*native
=
617 (wxGtkPrintNativeData
*) data
.GetNativeData();
618 data
.ConvertToNative();
620 GtkPrintSettings
* settings
= native
->GetPrintConfig();
622 // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData.
623 int fromPage
= m_printDialogData
.GetFromPage();
624 int toPage
= m_printDialogData
.GetToPage();
625 if (m_printDialogData
.GetSelection())
626 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_CURRENT
);
627 else if (m_printDialogData
.GetAllPages())
628 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_ALL
);
630 gtk_print_settings_set_print_pages(settings
, GTK_PRINT_PAGES_RANGES
);
632 range
= g_new (GtkPageRange
, 1);
633 range
[0].start
= fromPage
-1;
634 range
[0].end
= (toPage
>= fromPage
) ? toPage
-1 : fromPage
-1;
635 gtk_print_settings_set_page_ranges (settings
, range
, 1);
638 // If the settings are OK, we restore it.
639 if (settings
!= NULL
)
640 gtk_print_operation_set_print_settings (native
->GetPrintJob(), settings
);
641 gtk_print_operation_set_default_page_setup (native
->GetPrintJob(), native
->GetPageSetupFromSettings(settings
));
643 // Show the dialog if needed.
644 GError
* gError
= NULL
;
646 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
, GTK_WINDOW(gtk_widget_get_toplevel(m_parent
->m_widget
) ), &gError
);
648 response
= gtk_print_operation_run (native
->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT
, (GtkWindow
*) m_parent
, &gError
);
650 // Does everything went well?
651 if (response
== GTK_PRINT_OPERATION_RESULT_CANCEL
)
655 else if (response
== GTK_PRINT_OPERATION_RESULT_ERROR
)
657 g_error_free (gError
);
658 wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError
->message
));
659 return wxID_NO
; // We use wxID_NO because there is no wxID_ERROR available
662 // Now get the settings and save it.
663 GtkPrintSettings
* newSettings
= gtk_print_operation_get_print_settings (native
->GetPrintJob());
664 native
->SetPrintConfig(newSettings
);
665 data
.ConvertFromNative();
667 // Same problem as a few lines before.
668 switch (gtk_print_settings_get_print_pages(newSettings
))
670 case GTK_PRINT_PAGES_CURRENT
:
671 m_printDialogData
.SetSelection( true );
673 case GTK_PRINT_PAGES_ALL
:
674 m_printDialogData
.SetAllPages( true );
675 m_printDialogData
.SetFromPage( 0 );
676 m_printDialogData
.SetToPage( 9999 );
678 case GTK_PRINT_PAGES_RANGES
:
680 // wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others.
681 // 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
682 // will hit "OK" button. However we can only save 1-3 in the print data.
685 range
= gtk_print_settings_get_page_ranges (newSettings
, &num_ranges
);
686 m_printDialogData
.SetFromPage( range
[0].start
);
687 m_printDialogData
.SetToPage( range
[0].end
);
694 //----------------------------------------------------------------------------
695 // wxGtkPageSetupDialog
696 //----------------------------------------------------------------------------
698 IMPLEMENT_CLASS(wxGtkPageSetupDialog
, wxPageSetupDialogBase
)
700 wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow
*parent
,
701 wxPageSetupDialogData
* data
)
704 m_pageDialogData
= *data
;
709 wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
713 int wxGtkPageSetupDialog::ShowModal()
716 m_pageDialogData
.GetPrintData().ConvertToNative();
717 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
718 GtkPrintSettings
* nativeData
= native
->GetPrintConfig();
720 // We only need the pagesetup data which are part of the settings.
721 GtkPageSetup
* oldPageSetup
= native
->GetPageSetupFromSettings(nativeData
);
723 // If the user used a custom paper format the last time he printed, we have to restore it too.
724 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
726 wxSize customPaperSize
= m_pageDialogData
.GetPaperSize();
727 if (customPaperSize
.GetWidth() > 0 && customPaperSize
.GetHeight() > 0)
729 wxString title
= _("Custom size");
730 GtkPaperSize
* customSize
= gtk_paper_size_new_custom ("custom", title
.mb_str(), (gdouble
) customPaperSize
.GetWidth(), (gdouble
) customPaperSize
.GetHeight(), GTK_UNIT_MM
);
731 gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup
, customSize
);
732 g_object_unref(customSize
);
736 // Now show the dialog.
737 GtkPageSetup
* newPageSetup
= gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent
->m_widget
),
742 if (newPageSetup
!= oldPageSetup
)
744 native
->SetPageSetupToSettings(nativeData
, newPageSetup
);
745 m_pageDialogData
.GetPrintData().ConvertFromNative();
747 // Store custom paper format if any.
748 if (m_pageDialogData
.GetPrintData().GetPaperId() == wxPAPER_NONE
)
750 gdouble ml
,mr
,mt
,mb
,pw
,ph
;
751 ml
= gtk_page_setup_get_left_margin (newPageSetup
, GTK_UNIT_MM
);
752 mr
= gtk_page_setup_get_right_margin (newPageSetup
, GTK_UNIT_MM
);
753 mt
= gtk_page_setup_get_top_margin (newPageSetup
, GTK_UNIT_MM
);
754 mb
= gtk_page_setup_get_bottom_margin (newPageSetup
, GTK_UNIT_MM
);
756 pw
= gtk_page_setup_get_paper_width (newPageSetup
, GTK_UNIT_MM
);
757 ph
= gtk_page_setup_get_paper_height (newPageSetup
, GTK_UNIT_MM
);
759 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
760 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
762 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
775 //----------------------------------------------------------------------------
777 //----------------------------------------------------------------------------
779 IMPLEMENT_CLASS(wxGtkPrinter
, wxPrinterBase
)
781 wxGtkPrinter::wxGtkPrinter( wxPrintDialogData
*data
) :
782 wxPrinterBase( data
)
787 m_printDialogData
= *data
;
790 wxGtkPrinter::~wxGtkPrinter()
794 bool wxGtkPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
798 sm_lastError
= wxPRINTER_ERROR
;
802 // Let's correct the PageInfo just in case the app gives wrong values.
803 int fromPage
, toPage
;
804 int minPage
, maxPage
;
805 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
806 m_printDialogData
.SetAllPages(true);
808 if (minPage
< 1) minPage
= 1;
809 if (maxPage
< 1) maxPage
= 9999;
810 if (maxPage
< minPage
) maxPage
= minPage
;
812 m_printDialogData
.SetMinPage(minPage
);
813 m_printDialogData
.SetMaxPage(maxPage
);
816 if (fromPage
< minPage
) fromPage
= minPage
;
817 else if (fromPage
> maxPage
) fromPage
= maxPage
;
818 m_printDialogData
.SetFromPage(fromPage
);
822 m_printDialogData
.SetToPage(toPage
);
823 if (toPage
> maxPage
) toPage
= maxPage
;
824 else if (toPage
< minPage
) toPage
= minPage
;
827 if (((minPage
!= fromPage
) && fromPage
!= 0) || ((maxPage
!= toPage
) && toPage
!= 0)) m_printDialogData
.SetAllPages(false);
830 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
831 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
833 GtkPrintOperation
*printOp
= gtk_print_operation_new ();
835 native
->SetPrintJob( printOp
);
837 printout
->SetIsPreview(false);
839 wxPrinterToGtkData dataToSend
;
840 dataToSend
.printer
= this;
841 dataToSend
.printout
= printout
;
843 // These Gtk signals are catched here.
844 g_signal_connect (printOp
, "begin-print", G_CALLBACK (gtk_begin_print_callback
), &dataToSend
);
845 g_signal_connect (printOp
, "draw-page", G_CALLBACK (gtk_draw_page_print_callback
), &dataToSend
);
846 g_signal_connect (printOp
, "end-print", G_CALLBACK (gtk_end_print_callback
), printout
);
847 g_signal_connect (printOp
, "preview", G_CALLBACK (gtk_preview_print_callback
), printout
);
851 m_showDialog
= false;
853 // PrintDialog returns a wxDC but we created it before so we don't need it anymore: we just delete it.
854 wxDC
* uselessdc
= PrintDialog( parent
);
857 g_object_unref (printOp
);
859 return (sm_lastError
== wxPRINTER_NO_ERROR
);
862 void wxGtkPrinter::BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
)
864 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
865 wxGtkPrintNativeData
*native
= (wxGtkPrintNativeData
*) printdata
.GetNativeData();
867 SetPrintContext(context
);
868 native
->SetPrintContext( context
);
870 m_dc
= new wxGtkPrintDC( printdata
);
874 if (sm_lastError
!= wxPRINTER_CANCELLED
)
876 sm_lastError
= wxPRINTER_ERROR
;
877 wxFAIL_MSG(_("The wxGtkPrintDC cannot be used."));
881 wxSize ScreenPixels
= wxGetDisplaySize();
882 wxSize ScreenMM
= wxGetDisplaySizeMM();
884 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
885 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
886 printout
->SetPPIPrinter( wxGtkPrintDC::GetResolution(),
887 wxGtkPrintDC::GetResolution() );
889 printout
->SetDC(m_dc
);
892 m_dc
->GetSize(&w
, &h
);
893 printout
->SetPageSizePixels((int)w
, (int)h
);
894 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
896 m_dc
->GetSizeMM(&mw
, &mh
);
897 printout
->SetPageSizeMM((int)mw
, (int)mh
);
898 printout
->OnPreparePrinting();
900 // Get some parameters from the printout, if defined.
901 int fromPage
, toPage
;
902 int minPage
, maxPage
;
903 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
907 sm_lastError
= wxPRINTER_ERROR
;
908 wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage."));
912 printout
->OnBeginPrinting();
916 // If we're not previewing we need to calculate the number of pages to print.
917 // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may
918 // have defined in the dialog. So the number of pages is the maximum available.
919 if (!printout
->IsPreview())
921 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
922 switch (gtk_print_settings_get_print_pages(settings
))
924 case GTK_PRINT_PAGES_CURRENT
:
927 case GTK_PRINT_PAGES_RANGES
:
928 {gint num_ranges
= 0;
931 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
932 for (i
=0; i
<num_ranges
; i
++)
934 if (range
[i
].end
< range
[i
].start
) range
[i
].end
= range
[i
].start
;
935 if (range
[i
].start
< minPage
-1) range
[i
].start
= minPage
-1;
936 if (range
[i
].end
> maxPage
-1) range
[i
].end
= maxPage
-1;
937 if (range
[i
].start
> maxPage
-1) range
[i
].start
= maxPage
-1;
938 numPages
+= range
[i
].end
- range
[i
].start
+ 1;
940 gtk_print_settings_set_page_ranges (settings
, range
, 1);
942 case GTK_PRINT_PAGES_ALL
:
944 numPages
= maxPage
- minPage
+ 1;
948 else numPages
= maxPage
- minPage
+ 1;
950 gtk_print_operation_set_n_pages(operation
, numPages
);
953 void wxGtkPrinter::DrawPage(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
, int page_nr
)
955 int fromPage
, toPage
, minPage
, maxPage
, startPage
, endPage
;
956 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
958 int numPageToDraw
= page_nr
+ minPage
;
959 if (numPageToDraw
< minPage
) numPageToDraw
= minPage
;
960 if (numPageToDraw
> maxPage
) numPageToDraw
= maxPage
;
962 GtkPrintSettings
* settings
= gtk_print_operation_get_print_settings (operation
);
963 switch (gtk_print_settings_get_print_pages(settings
))
965 case GTK_PRINT_PAGES_CURRENT
:
966 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &startPage
);
967 g_object_get_property((GObject
*) operation
, (const gchar
*) "current-page", (GValue
*) &endPage
);
969 case GTK_PRINT_PAGES_RANGES
:
970 {gint num_ranges
= 0;
972 range
= gtk_print_settings_get_page_ranges (settings
, &num_ranges
);
973 // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
974 startPage
= range
[0].start
+ 1;
975 endPage
= range
[0].end
+ 1;
977 case GTK_PRINT_PAGES_ALL
:
984 if(numPageToDraw
== startPage
)
986 if (!printout
->OnBeginDocument(startPage
, endPage
))
988 wxLogError(_("Could not start printing."));
989 sm_lastError
= wxPRINTER_ERROR
;
993 // The app can render the page numPageToDraw.
994 if (printout
->HasPage(numPageToDraw
))
997 printout
->OnPrintPage(numPageToDraw
);
1002 if(numPageToDraw
== endPage
)
1004 printout
->OnEndDocument();
1008 wxDC
* wxGtkPrinter::PrintDialog( wxWindow
*parent
)
1010 wxGtkPrintDialog
dialog( parent
, &m_printDialogData
);
1013 dialog
.SetPrintDC(m_dc
);
1015 dialog
.SetShowDialog(m_showDialog
);
1017 ret
= dialog
.ShowModal();
1019 if (ret
== wxID_CANCEL
)
1021 sm_lastError
= wxPRINTER_CANCELLED
;
1026 sm_lastError
= wxPRINTER_ERROR
;
1027 wxFAIL_MSG(_("The print dialog returned an error."));
1031 m_printDialogData
= dialog
.GetPrintDialogData();
1032 return new wxGtkPrintDC( m_printDialogData
.GetPrintData() );
1035 bool wxGtkPrinter::Setup( wxWindow
*parent
)
1037 // Obsolete, for backward compatibility.
1041 //-----------------------------------------------------------------------------
1043 //-----------------------------------------------------------------------------
1045 IMPLEMENT_CLASS(wxGtkPrintDC
, wxDC
)
1047 // Define the default resolution for this DC. This resolution is just used for positioning as the cairo context is scalable.
1048 int wxGtkPrintDC::ms_resolution
= 72;
1050 wxGtkPrintDC::wxGtkPrintDC( const wxPrintData
& data
)
1054 wxGtkPrintNativeData
*native
=
1055 (wxGtkPrintNativeData
*) m_printData
.GetNativeData();
1057 m_gpc
= native
->GetPrintContext();
1059 ms_resolution
= (int) gtk_print_context_get_dpi_x(m_gpc
);
1060 m_context
= gtk_print_context_create_pango_context( m_gpc
);
1061 m_layout
= gtk_print_context_create_pango_layout ( m_gpc
);
1062 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
1064 m_cairo
= gtk_print_context_get_cairo_context ( m_gpc
);
1070 m_signX
= 1; // default x-axis left to right.
1071 m_signY
= 1; // default y-axis bottom up -> top down.
1073 GetSize( &m_deviceOffsetX
, &m_deviceOffsetY
);
1076 wxGtkPrintDC::~wxGtkPrintDC()
1078 g_object_unref(m_context
);
1079 g_object_unref(m_layout
);
1082 bool wxGtkPrintDC::IsOk() const
1087 void wxGtkPrintDC::ComputeScaleAndOrigin()
1089 // Called when the scale and/or origin of the context has to be changed.
1090 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1091 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1093 gs_cairo
->cairo_translate(m_cairo
, m_deviceOriginX
, m_deviceOriginY
);
1094 gs_cairo
->cairo_scale(m_cairo
, m_scaleX
, m_scaleY
);
1097 bool wxGtkPrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
1099 // We can't access the given coord as a cairo context is scalable, ie a coord doesn't mean anything in this context.
1100 wxFAIL_MSG(_("not implemented"));
1104 void wxGtkPrintDC::DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
)
1106 wxCoord xC
= circleCenter
.x
;
1107 wxCoord yC
= circleCenter
.y
;
1108 wxCoord xR
= rect
.x
;
1109 wxCoord yR
= rect
.y
;
1110 wxCoord w
= rect
.width
;
1111 wxCoord h
= rect
.height
;
1113 double radius
= sqrt((w
/2)*(w
/2)+(h
/2)*(h
/2));
1115 unsigned char redI
= initialColour
.Red();
1116 unsigned char blueI
= initialColour
.Blue();
1117 unsigned char greenI
= initialColour
.Green();
1118 unsigned char alphaI
= initialColour
.Alpha();
1119 unsigned char redD
= destColour
.Red();
1120 unsigned char blueD
= destColour
.Blue();
1121 unsigned char greenD
= destColour
.Green();
1122 unsigned char alphaD
= destColour
.Alpha();
1124 double redIPS
= (double)(redI
) / 255.0;
1125 double blueIPS
= (double)(blueI
) / 255.0;
1126 double greenIPS
= (double)(greenI
) / 255.0;
1127 double alphaIPS
= (double)(alphaI
) / 255.0;
1128 double redDPS
= (double)(redD
) / 255.0;
1129 double blueDPS
= (double)(blueD
) / 255.0;
1130 double greenDPS
= (double)(greenD
) / 255.0;
1131 double alphaDPS
= (double)(alphaD
) / 255.0;
1133 // Create a pattern with the gradient.
1134 cairo_pattern_t
* gradient
;
1135 gradient
= gs_cairo
->cairo_pattern_create_radial (LogicalToDeviceX(xC
+xR
), LogicalToDeviceY(yC
+yR
), 0, LogicalToDeviceX(xC
+xR
), LogicalToDeviceY(yC
+yR
), radius
);
1136 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1137 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1139 // Fill the rectangle with this pattern.
1140 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1141 gs_cairo
->cairo_rectangle (m_cairo
, LogicalToDeviceX(xR
), LogicalToDeviceY(yR
), LogicalToDeviceXRel(w
), LogicalToDeviceYRel(h
) );
1142 gs_cairo
->cairo_fill(m_cairo
);
1144 gs_cairo
->cairo_pattern_destroy(gradient
);
1146 CalcBoundingBox(xR
, yR
);
1147 CalcBoundingBox(xR
+w
, yR
+h
);
1150 void wxGtkPrintDC::DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
)
1154 wxCoord w
= rect
.width
;
1155 wxCoord h
= rect
.height
;
1157 unsigned char redI
= initialColour
.Red();
1158 unsigned char blueI
= initialColour
.Blue();
1159 unsigned char greenI
= initialColour
.Green();
1160 unsigned char alphaI
= initialColour
.Alpha();
1161 unsigned char redD
= destColour
.Red();
1162 unsigned char blueD
= destColour
.Blue();
1163 unsigned char greenD
= destColour
.Green();
1164 unsigned char alphaD
= destColour
.Alpha();
1166 double redIPS
= (double)(redI
) / 255.0;
1167 double blueIPS
= (double)(blueI
) / 255.0;
1168 double greenIPS
= (double)(greenI
) / 255.0;
1169 double alphaIPS
= (double)(alphaI
) / 255.0;
1170 double redDPS
= (double)(redD
) / 255.0;
1171 double blueDPS
= (double)(blueD
) / 255.0;
1172 double greenDPS
= (double)(greenD
) / 255.0;
1173 double alphaDPS
= (double)(alphaD
) / 255.0;
1175 // Create a pattern with the gradient.
1176 cairo_pattern_t
* gradient
;
1177 gradient
= gs_cairo
->cairo_pattern_create_linear (LogicalToDeviceX(x
), LogicalToDeviceY(y
), LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
));
1179 if (nDirection
== wxWEST
)
1181 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1182 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1185 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 0.0, redIPS
, greenIPS
, blueIPS
, alphaIPS
);
1186 gs_cairo
->cairo_pattern_add_color_stop_rgba (gradient
, 1.0, redDPS
, greenDPS
, blueDPS
, alphaDPS
);
1189 // Fill the rectangle with this pattern.
1190 gs_cairo
->cairo_set_source(m_cairo
, gradient
);
1191 gs_cairo
->cairo_rectangle (m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
), LogicalToDeviceXRel(w
), LogicalToDeviceYRel(h
) );
1192 gs_cairo
->cairo_fill(m_cairo
);
1194 gs_cairo
->cairo_pattern_destroy(gradient
);
1196 CalcBoundingBox(x
, y
);
1197 CalcBoundingBox(x
+w
, y
+h
);
1200 bool wxGtkPrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
1202 // We can't access the given coord as a cairo context is scalable, ie a coord doesn't mean anything in this context.
1203 wxFAIL_MSG(_("not implemented"));
1207 void wxGtkPrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1209 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1212 gs_cairo
->cairo_move_to ( m_cairo
, LogicalToDeviceX(x1
), LogicalToDeviceY(y1
) );
1213 gs_cairo
->cairo_line_to ( m_cairo
, LogicalToDeviceX(x2
), LogicalToDeviceY(y2
) );
1214 gs_cairo
->cairo_stroke ( m_cairo
);
1216 CalcBoundingBox( x1
, y1
);
1217 CalcBoundingBox( x2
, y2
);
1220 void wxGtkPrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
1229 gs_cairo
->cairo_move_to (m_cairo
, LogicalToDeviceX(x
), 0);
1230 gs_cairo
->cairo_line_to (m_cairo
, LogicalToDeviceX(x
), *h
);
1231 gs_cairo
->cairo_move_to (m_cairo
, 0, LogicalToDeviceY(y
));
1232 gs_cairo
->cairo_line_to (m_cairo
, *w
, LogicalToDeviceY(y
));
1234 gs_cairo
->cairo_stroke (m_cairo
);
1235 CalcBoundingBox( 0, 0 );
1236 CalcBoundingBox( *w
, *h
);
1242 void wxGtkPrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
1244 double dx
= x1
- xc
;
1245 double dy
= y1
- yc
;
1246 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1248 double alpha1
, alpha2
;
1249 if (x1
== x2
&& y1
== y2
)
1257 alpha1
= alpha2
= 0.0;
1261 alpha1
= (x1
- xc
== 0) ?
1262 (y1
- yc
< 0) ? 90.0 : -90.0 :
1263 atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
1264 alpha2
= (x2
- xc
== 0) ?
1265 (y2
- yc
< 0) ? 90.0 : -90.0 :
1266 atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
1268 while (alpha1
<= 0) alpha1
+= 360;
1269 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between.
1270 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree.
1271 while (alpha2
> 360) alpha2
-= 360;
1277 gs_cairo
->cairo_arc_negative ( m_cairo
, LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel((int)radius
), alpha1
, alpha2
);
1278 gs_cairo
->cairo_line_to(m_cairo
, LogicalToDeviceX(xc
), LogicalToDeviceY(yc
));
1279 gs_cairo
->cairo_close_path (m_cairo
);
1281 SetBrush( m_brush
);
1282 gs_cairo
->cairo_fill_preserve( m_cairo
);
1285 gs_cairo
->cairo_stroke( m_cairo
);
1287 CalcBoundingBox (x1
, y1
);
1288 CalcBoundingBox (xc
, yc
);
1289 CalcBoundingBox (x2
, y2
);
1292 void wxGtkPrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
1294 gs_cairo
->cairo_save( m_cairo
);
1296 gs_cairo
->cairo_translate( m_cairo
, LogicalToDeviceX((wxCoord
) (x
+ w
/ 2.)), LogicalToDeviceX((wxCoord
) (y
+ h
/ 2.)) );
1297 double scale
= (double)LogicalToDeviceYRel(h
) / (double) LogicalToDeviceXRel(w
);
1298 gs_cairo
->cairo_scale( m_cairo
, 1.0, scale
);
1300 gs_cairo
->cairo_arc_negative ( m_cairo
, 0, 0, LogicalToDeviceXRel(w
/2), -sa
*DEG2RAD
, -ea
*DEG2RAD
);
1303 gs_cairo
->cairo_stroke_preserve( m_cairo
);
1305 gs_cairo
->cairo_line_to(m_cairo
, 0,0);
1307 SetBrush( m_brush
);
1308 gs_cairo
->cairo_fill( m_cairo
);
1310 gs_cairo
->cairo_restore( m_cairo
);
1312 CalcBoundingBox( x
, y
);
1313 CalcBoundingBox( x
+w
, y
+h
);
1316 void wxGtkPrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
1318 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1322 gs_cairo
->cairo_move_to ( m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
) );
1323 gs_cairo
->cairo_line_to ( m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
) );
1324 gs_cairo
->cairo_stroke ( m_cairo
);
1326 CalcBoundingBox( x
, y
);
1329 void wxGtkPrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1331 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1338 for ( i
=0; i
<n
; i
++ )
1339 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1341 gs_cairo
->cairo_move_to ( m_cairo
, LogicalToDeviceX(points
[0].x
+xoffset
), LogicalToDeviceY(points
[0].y
+yoffset
) );
1343 for (i
= 1; i
< n
; i
++)
1344 gs_cairo
->cairo_line_to ( m_cairo
, LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
) );
1346 gs_cairo
->cairo_stroke ( m_cairo
);
1349 void wxGtkPrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1353 gs_cairo
->cairo_save(m_cairo
);
1354 if (fillStyle
== wxWINDING_RULE
)
1355 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_WINDING
);
1357 gs_cairo
->cairo_set_fill_rule( m_cairo
, CAIRO_FILL_RULE_EVEN_ODD
);
1359 int x
= points
[0].x
+ xoffset
;
1360 int y
= points
[0].y
+ yoffset
;
1361 gs_cairo
->cairo_new_path(m_cairo
);
1362 gs_cairo
->cairo_move_to( m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
) );
1364 for (i
= 1; i
< n
; i
++)
1366 int x
= points
[i
].x
+ xoffset
;
1367 int y
= points
[i
].y
+ yoffset
;
1368 gs_cairo
->cairo_line_to( m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
) );
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( x
, y
);
1380 gs_cairo
->cairo_restore(m_cairo
);
1383 void wxGtkPrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1385 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1388 void wxGtkPrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1390 gs_cairo
->cairo_rectangle ( m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
), LogicalToDeviceXRel(width
), LogicalToDeviceYRel(height
));
1392 SetBrush( m_brush
);
1393 gs_cairo
->cairo_fill_preserve( m_cairo
);
1396 gs_cairo
->cairo_stroke( m_cairo
);
1398 CalcBoundingBox( x
, y
);
1399 CalcBoundingBox( x
+ width
, y
+ height
);
1402 void wxGtkPrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1404 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
1406 wxCoord dd
= 2 * (wxCoord
) radius
;
1407 if (dd
> width
) dd
= width
;
1408 if (dd
> height
) dd
= height
;
1411 wxCoord rad
= (wxCoord
) radius
;
1413 gs_cairo
->cairo_new_path(m_cairo
);
1414 gs_cairo
->cairo_move_to(m_cairo
,LogicalToDeviceX(x
+ rad
),LogicalToDeviceY(y
));
1415 gs_cairo
->cairo_curve_to(m_cairo
,
1416 LogicalToDeviceX(x
+ rad
),LogicalToDeviceY(y
),
1417 LogicalToDeviceX(x
),LogicalToDeviceY(y
),
1418 LogicalToDeviceX(x
),LogicalToDeviceY(y
+ rad
));
1419 gs_cairo
->cairo_line_to(m_cairo
,LogicalToDeviceX(x
),LogicalToDeviceY(y
+ height
- rad
));
1420 gs_cairo
->cairo_curve_to(m_cairo
,
1421 LogicalToDeviceX(x
),LogicalToDeviceY(y
+ height
- rad
),
1422 LogicalToDeviceX(x
),LogicalToDeviceY(y
+ height
),
1423 LogicalToDeviceX(x
+ rad
),LogicalToDeviceY(y
+ height
));
1424 gs_cairo
->cairo_line_to(m_cairo
,LogicalToDeviceX(x
+ width
- rad
),LogicalToDeviceY(y
+ height
));
1425 gs_cairo
->cairo_curve_to(m_cairo
,
1426 LogicalToDeviceX(x
+ width
- rad
),LogicalToDeviceY(y
+ height
),
1427 LogicalToDeviceX(x
+ width
),LogicalToDeviceY(y
+ height
),
1428 LogicalToDeviceX(x
+ width
),LogicalToDeviceY(y
+ height
- rad
));
1429 gs_cairo
->cairo_line_to(m_cairo
,LogicalToDeviceX(x
+ width
),LogicalToDeviceY(y
+ rad
));
1430 gs_cairo
->cairo_curve_to(m_cairo
,
1431 LogicalToDeviceX(x
+ width
),LogicalToDeviceY(y
+ rad
),
1432 LogicalToDeviceX(x
+ width
),LogicalToDeviceY(y
),
1433 LogicalToDeviceX(x
+ width
- rad
),LogicalToDeviceY(y
));
1434 gs_cairo
->cairo_line_to(m_cairo
,LogicalToDeviceX(x
+ rad
),LogicalToDeviceY(y
));
1435 gs_cairo
->cairo_close_path(m_cairo
);
1438 gs_cairo
->cairo_fill_preserve(m_cairo
);
1441 gs_cairo
->cairo_stroke(m_cairo
);
1443 CalcBoundingBox(x
,y
);
1444 CalcBoundingBox(x
+width
,y
+height
);
1447 void wxGtkPrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1449 gs_cairo
->cairo_save (m_cairo
);
1451 gs_cairo
->cairo_translate (m_cairo
, LogicalToDeviceX((wxCoord
) (x
+ width
/ 2.)), LogicalToDeviceY((wxCoord
) (y
+ height
/ 2.)));
1452 gs_cairo
->cairo_scale(m_cairo
, 1, (double)LogicalToDeviceYRel(height
)/(double)LogicalToDeviceXRel(width
));
1453 gs_cairo
->cairo_arc ( m_cairo
, 0, 0, LogicalToDeviceXRel(width
/2), 0, 2 * M_PI
);
1455 SetBrush( m_brush
);
1456 gs_cairo
->cairo_fill_preserve( m_cairo
);
1459 gs_cairo
->cairo_stroke( m_cairo
);
1461 CalcBoundingBox( x
, y
);
1462 CalcBoundingBox( x
+ width
, y
+ height
);
1464 gs_cairo
->cairo_restore (m_cairo
);
1468 void wxGtkPrintDC::DoDrawSpline(wxList
*points
)
1472 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1475 wxList::compatibility_iterator node
= points
->GetFirst();
1476 p
= (wxPoint
*)node
->GetData();
1480 node
= node
->GetNext();
1481 p
= (wxPoint
*)node
->GetData();
1485 (double)(x1
+ c
) / 2;
1487 (double)(y1
+ d
) / 2;
1489 gs_cairo
->cairo_new_path( m_cairo
);
1490 gs_cairo
->cairo_move_to( m_cairo
, LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
) );
1491 gs_cairo
->cairo_line_to( m_cairo
, LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1493 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1494 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1496 node
= node
->GetNext();
1499 q
= (wxPoint
*)node
->GetData();
1507 x3
= (double)(x2
+ c
) / 2;
1508 y3
= (double)(y2
+ d
) / 2;
1510 gs_cairo
->cairo_curve_to(m_cairo
,
1511 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1512 LogicalToDeviceX((wxCoord
)x2
), LogicalToDeviceY((wxCoord
)y2
),
1513 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1515 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1516 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1518 node
= node
->GetNext();
1521 gs_cairo
->cairo_line_to ( m_cairo
, LogicalToDeviceX((wxCoord
)c
), LogicalToDeviceY((wxCoord
)d
) );
1523 gs_cairo
->cairo_stroke( m_cairo
);
1525 #endif // wxUSE_SPLINES
1527 bool wxGtkPrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1528 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1529 wxCoord xsrcMask
, wxCoord ysrcMask
)
1531 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1533 // Blit into a bitmap.
1534 wxBitmap
bitmap( width
, height
);
1536 memDC
.SelectObject(bitmap
);
1537 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
);
1538 memDC
.SelectObject(wxNullBitmap
);
1540 // Draw bitmap. scaling and positioning is done there.
1541 DrawBitmap( bitmap
, xdest
, ydest
, useMask
);
1546 void wxGtkPrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1548 DoDrawBitmap( icon
, x
, y
, true );
1551 void wxGtkPrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1553 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrintDC::DoDrawBitmap"));
1555 cairo_surface_t
* surface
;
1556 x
= LogicalToDeviceX(x
);
1557 y
= LogicalToDeviceY(y
);
1558 int bw
= bitmap
.GetWidth();
1559 int bh
= bitmap
.GetHeight();
1560 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1561 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1562 wxUint32
* data
= (wxUint32
*)buffer
;
1564 wxMask
*mask
= NULL
;
1565 if (useMask
) mask
= bmpSource
.GetMask();
1567 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1568 // then we'll use a different format and iterator than if it doesn't.
1569 if (bmpSource
.HasAlpha() || mask
)
1571 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1572 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1573 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1574 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1576 wxAlphaPixelData::Iterator
p(pixData
);
1578 for (y
=0; y
<bh
; y
++)
1580 wxAlphaPixelData::Iterator rowStart
= p
;
1581 for (x
=0; x
<bw
; x
++)
1583 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1584 // with alpha in the upper 8 bits, then red, then green, then
1585 // blue. The 32-bit quantities are stored native-endian.
1586 // Pre-multiplied alpha is used.
1587 unsigned char alpha
= p
.Alpha();
1591 *data
= ( alpha
/255 << 24
1592 | (p
.Red() * alpha
/255) << 16
1593 | (p
.Green() * alpha
/255) << 8
1594 | (p
.Blue() * alpha
/255) );
1599 p
.OffsetY(pixData
, 1);
1604 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1605 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1606 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1607 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1609 wxNativePixelData::Iterator
p(pixData
);
1611 for (y
=0; y
<bh
; y
++)
1613 wxNativePixelData::Iterator rowStart
= p
;
1614 for (x
=0; x
<bw
; x
++)
1616 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1617 // the upper 8 bits unused. Red, Green, and Blue are stored in
1618 // the remaining 24 bits in that order. The 32-bit quantities
1619 // are stored native-endian.
1620 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1625 p
.OffsetY(pixData
, 1);
1630 gs_cairo
->cairo_save(m_cairo
);
1631 // In case we're scaling the image by using a width and height different
1632 // than the bitmap's size create a pattern transformation on the surface and
1633 // draw the transformed pattern.
1634 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface(surface
);
1636 // Prepare to draw the image.
1637 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1638 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
1639 // Use the original size here since the context is scaled already.
1640 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1641 // Fill the rectangle using the pattern.
1642 gs_cairo
->cairo_fill(m_cairo
);
1645 gs_cairo
->cairo_pattern_destroy(pattern
);
1646 gs_cairo
->cairo_surface_destroy(surface
);
1649 CalcBoundingBox(0,0);
1650 CalcBoundingBox(bw
,bh
);
1652 gs_cairo
->cairo_restore(m_cairo
);
1655 // wxGtkPrintDC has a constant resolution of 72dpi. If we want an higher resolution for printing
1656 // an image, the scaling has to be done by cairo.
1657 void wxGtkPrintDC::DoDrawScaledBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
, bool useMask
, int quality
)
1659 wxCHECK_RET( bitmap
.IsOk(), wxT("Invalid bitmap in wxGtkPrintDC::DoDrawBitmap"));
1661 cairo_surface_t
* surface
;
1662 int bw
= bitmap
.GetWidth();
1663 int bh
= bitmap
.GetHeight();
1664 x
= LogicalToDeviceX(x
);
1665 y
= LogicalToDeviceY(y
);
1666 w
= LogicalToDeviceXRel(w
);
1667 h
= LogicalToDeviceYRel(h
);
1668 wxBitmap bmpSource
= bitmap
; // we need a non-const instance.
1669 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1670 wxUint32
* data
= (wxUint32
*)buffer
;
1672 // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
1673 // then we'll use a different format and iterator than if it doesn't.
1674 if (bmpSource
.HasAlpha() || bmpSource
.GetMask())
1676 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1677 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1678 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1679 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1681 wxAlphaPixelData::Iterator
p(pixData
);
1683 for (y
=0; y
<bh
; y
++)
1685 wxAlphaPixelData::Iterator rowStart
= p
;
1686 for (x
=0; x
<bw
; x
++)
1688 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1689 // with alpha in the upper 8 bits, then red, then green, then
1690 // blue. The 32-bit quantities are stored native-endian.
1691 // Pre-multiplied alpha is used.
1692 unsigned char alpha
= p
.Alpha();
1696 *data
= ( alpha
<< 24
1697 | (p
.Red() * alpha
/255) << 16
1698 | (p
.Green() * alpha
/255) << 8
1699 | (p
.Blue() * alpha
/255) );
1704 p
.OffsetY(pixData
, 1);
1709 surface
= gs_cairo
->cairo_image_surface_create_for_data(
1710 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1711 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1712 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1714 wxNativePixelData::Iterator
p(pixData
);
1716 for (y
=0; y
<bh
; y
++)
1718 wxNativePixelData::Iterator rowStart
= p
;
1719 for (x
=0; x
<bw
; x
++)
1721 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1722 // the upper 8 bits unused. Red, Green, and Blue are stored in
1723 // the remaining 24 bits in that order. The 32-bit quantities
1724 // are stored native-endian.
1725 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1730 p
.OffsetY(pixData
, 1);
1735 gs_cairo
->cairo_save(m_cairo
);
1737 // Prepare to draw the image.
1738 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1740 // In case we're scaling the image by using a width and height different
1741 // than the bitmap's size create a pattern transformation on the surface and
1742 // draw the transformed pattern.
1743 cairo_filter_t filter
;
1744 if (quality
== wxIMAGE_QUALITY_HIGH
) filter
= CAIRO_FILTER_BILINEAR
;
1745 else filter
= CAIRO_FILTER_GOOD
;
1746 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface(surface
);
1747 gs_cairo
->cairo_pattern_set_filter(pattern
,filter
);
1748 wxDouble scaleX
= (wxDouble
) w
/ (wxDouble
) bw
;
1749 wxDouble scaleY
= (wxDouble
) h
/ (wxDouble
) bh
;
1750 gs_cairo
->cairo_scale(m_cairo
, scaleX
, scaleY
);
1752 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
1753 // Use the original size here since the context is scaled already.
1754 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, bw
, bh
);
1755 // Fill the rectangle using the pattern.
1756 gs_cairo
->cairo_fill(m_cairo
);
1759 gs_cairo
->cairo_pattern_destroy(pattern
);
1760 gs_cairo
->cairo_surface_destroy(surface
);
1763 CalcBoundingBox(0,0);
1764 CalcBoundingBox(bw
,bh
);
1766 gs_cairo
->cairo_restore(m_cairo
);
1769 void wxGtkPrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1771 DoDrawRotatedText( text
, x
, y
, 0.0 );
1774 void wxGtkPrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1776 x
= LogicalToDeviceX(x
);
1777 y
= LogicalToDeviceY(y
);
1781 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1783 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
1784 #if wxUSE_UNICODE_UTF8
1785 const char *data
= text
.utf8_str();
1787 const wxCharBuffer data
= text
.utf8_str();
1790 size_t datalen
= strlen(data
);
1791 pango_layout_set_text( m_layout
, data
, datalen
);
1795 PangoAttrList
*attrs
= pango_attr_list_new();
1796 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1798 a
->end_index
= datalen
;
1799 pango_attr_list_insert(attrs
, a
);
1800 pango_layout_set_attributes(m_layout
, attrs
);
1801 pango_attr_list_unref(attrs
);
1804 if (m_textForegroundColour
.Ok())
1806 unsigned char red
= m_textForegroundColour
.Red();
1807 unsigned char blue
= m_textForegroundColour
.Blue();
1808 unsigned char green
= m_textForegroundColour
.Green();
1809 unsigned char alpha
= m_textForegroundColour
.Alpha();
1811 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
1813 double redPS
= (double)(red
) / 255.0;
1814 double bluePS
= (double)(blue
) / 255.0;
1815 double greenPS
= (double)(green
) / 255.0;
1816 double alphaPS
= (double)(alpha
) / 255.0;
1818 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1821 m_currentBlue
= blue
;
1822 m_currentGreen
= green
;
1823 m_currentAlpha
= alpha
;
1829 if (fabs(m_scaleY
- 1.0) > 0.00001)
1831 // If there is a user or actually any scale applied to the device context, scale the font.
1833 // Scale font description.
1834 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1835 double size
= oldSize
;
1836 size
= size
* m_scaleY
;
1837 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1839 // Actually apply scaled font.
1840 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1842 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1843 w
= LogicalToDeviceXRel(w
);
1844 h
= LogicalToDeviceYRel(h
);
1846 if ( m_backgroundMode
== wxSOLID
)
1848 unsigned char red
= m_textBackgroundColour
.Red();
1849 unsigned char blue
= m_textBackgroundColour
.Blue();
1850 unsigned char green
= m_textBackgroundColour
.Green();
1851 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1853 double redPS
= (double)(red
) / 255.0;
1854 double bluePS
= (double)(blue
) / 255.0;
1855 double greenPS
= (double)(green
) / 255.0;
1856 double alphaPS
= (double)(alpha
) / 255.0;
1858 gs_cairo
->cairo_save(m_cairo
);
1859 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1860 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1861 gs_cairo
->cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1862 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, w
, h
);
1863 gs_cairo
->cairo_fill(m_cairo
);
1864 gs_cairo
->cairo_restore(m_cairo
);
1868 gs_cairo
->cairo_move_to (m_cairo
, x
, y
);
1869 if (fabs(angle
) > 0.00001)
1871 gs_cairo
->cairo_save( m_cairo
);
1872 gs_cairo
->cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1873 // pango_cairo_update_layout (m_cairo, m_layout);
1874 // pango_cairo_show_layout (m_cairo, m_layout);
1875 gs_cairo
->cairo_restore( m_cairo
);
1879 // pango_cairo_update_layout (m_cairo, m_layout);
1880 // pango_cairo_show_layout (m_cairo, m_layout);
1883 // Reset unscaled size.
1884 pango_font_description_set_size( m_fontdesc
, oldSize
);
1886 // Actually apply unscaled font.
1887 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1891 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1893 if ( m_backgroundMode
== wxSOLID
)
1895 unsigned char red
= m_textBackgroundColour
.Red();
1896 unsigned char blue
= m_textBackgroundColour
.Blue();
1897 unsigned char green
= m_textBackgroundColour
.Green();
1898 unsigned char alpha
= m_textBackgroundColour
.Alpha();
1900 double redPS
= (double)(red
) / 255.0;
1901 double bluePS
= (double)(blue
) / 255.0;
1902 double greenPS
= (double)(green
) / 255.0;
1903 double alphaPS
= (double)(alpha
) / 255.0;
1905 gs_cairo
->cairo_save(m_cairo
);
1906 gs_cairo
->cairo_translate(m_cairo
, x
, y
);
1907 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
1908 gs_cairo
->cairo_rotate(m_cairo
,angle
*DEG2RAD
);
1909 gs_cairo
->cairo_rectangle(m_cairo
, 0, 0, w
, h
);
1910 gs_cairo
->cairo_fill(m_cairo
);
1911 gs_cairo
->cairo_restore(m_cairo
);
1915 gs_cairo
->cairo_move_to (m_cairo
, x
, y
);
1916 if (fabs(angle
) > 0.00001)
1918 gs_cairo
->cairo_save( m_cairo
);
1919 gs_cairo
->cairo_rotate( m_cairo
, angle
*DEG2RAD
);
1920 // pango_cairo_update_layout (m_cairo, m_layout);
1921 // pango_cairo_show_layout (m_cairo, m_layout);
1922 gs_cairo
->cairo_restore( m_cairo
);
1926 // pango_cairo_update_layout (m_cairo, m_layout);
1927 // pango_cairo_show_layout (m_cairo, m_layout);
1933 // Undo underline attributes setting
1934 pango_layout_set_attributes(m_layout
, NULL
);
1937 CalcBoundingBox (x
,y
);
1938 CalcBoundingBox (x
+ w
, y
+ h
);
1941 void wxGtkPrintDC::Clear()
1943 gs_cairo
->cairo_save(m_cairo
);
1944 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
1945 SetBrush(m_backgroundBrush
);
1946 gs_cairo
->cairo_paint(m_cairo
);
1947 gs_cairo
->cairo_restore(m_cairo
);
1950 void wxGtkPrintDC::SetFont( const wxFont
& font
)
1957 pango_font_description_free( m_fontdesc
);
1959 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1961 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1965 void wxGtkPrintDC::SetPen( const wxPen
& pen
)
1967 if (!pen
.Ok()) return;
1971 double width
= (double) m_pen
.GetWidth();
1972 if (width
== 0) width
= 0.1;
1974 gs_cairo
->cairo_set_line_width( m_cairo
, LogicalToDeviceXRel( (wxCoord
) (1000 * width
)) / 1000.0f
);
1975 static const double dotted
[] = {2.0, 5.0};
1976 static const double short_dashed
[] = {4.0, 4.0};
1977 static const double long_dashed
[] = {4.0, 8.0};
1978 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1980 switch (m_pen
.GetStyle())
1982 case wxDOT
: gs_cairo
->cairo_set_dash( m_cairo
, dotted
, 1, 0 ); break;
1983 case wxSHORT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, short_dashed
, 1, 0 ); break;
1984 case wxLONG_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, long_dashed
, 1, 0 ); break;
1985 case wxDOT_DASH
: gs_cairo
->cairo_set_dash( m_cairo
, dotted_dashed
, 3, 0 ); break;
1989 int num
= m_pen
.GetDashes (&wx_dashes
) - 1;
1990 gdouble
*g_dashes
= g_new( gdouble
, num
);
1992 for (i
= 0; i
< num
; ++i
)
1993 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1994 gs_cairo
->cairo_set_dash( m_cairo
, g_dashes
, num
, 0);
2000 default: gs_cairo
->cairo_set_dash( m_cairo
, NULL
, 0, 0 ); break;
2003 switch (m_pen
.GetCap())
2005 case wxCAP_PROJECTING
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_SQUARE
); break;
2006 case wxCAP_BUTT
: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_BUTT
); break;
2008 default: gs_cairo
->cairo_set_line_cap (m_cairo
, CAIRO_LINE_CAP_ROUND
); break;
2011 switch (m_pen
.GetJoin())
2013 case wxJOIN_BEVEL
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_BEVEL
); break;
2014 case wxJOIN_MITER
: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_MITER
); break;
2016 default: gs_cairo
->cairo_set_line_join (m_cairo
, CAIRO_LINE_JOIN_ROUND
); break;
2019 unsigned char red
= m_pen
.GetColour().Red();
2020 unsigned char blue
= m_pen
.GetColour().Blue();
2021 unsigned char green
= m_pen
.GetColour().Green();
2022 unsigned char alpha
= m_pen
.GetColour().Alpha();
2024 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
2026 double redPS
= (double)(red
) / 255.0;
2027 double bluePS
= (double)(blue
) / 255.0;
2028 double greenPS
= (double)(green
) / 255.0;
2029 double alphaPS
= (double)(alpha
) / 255.0;
2031 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
2034 m_currentBlue
= blue
;
2035 m_currentGreen
= green
;
2036 m_currentAlpha
= alpha
;
2040 void wxGtkPrintDC::SetBrush( const wxBrush
& brush
)
2042 if (!brush
.Ok()) return;
2047 unsigned char red
= m_brush
.GetColour().Red();
2048 unsigned char blue
= m_brush
.GetColour().Blue();
2049 unsigned char green
= m_brush
.GetColour().Green();
2050 unsigned char alpha
= m_brush
.GetColour().Alpha();
2052 double redPS
= (double)(red
) / 255.0;
2053 double bluePS
= (double)(blue
) / 255.0;
2054 double greenPS
= (double)(green
) / 255.0;
2055 double alphaPS
= (double)(alpha
) / 255.0;
2057 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
&& alpha
== m_currentAlpha
))
2059 gs_cairo
->cairo_set_source_rgba( m_cairo
, redPS
, greenPS
, bluePS
, alphaPS
);
2062 m_currentBlue
= blue
;
2063 m_currentGreen
= green
;
2064 m_currentAlpha
= alpha
;
2067 if (m_brush
.IsHatch())
2070 cairo_surface_t
*surface
;
2071 surface
= gs_cairo
->cairo_surface_create_similar(gs_cairo
->cairo_get_target(m_cairo
),CAIRO_CONTENT_COLOR_ALPHA
,10,10);
2072 cr
= gs_cairo
->cairo_create(surface
);
2073 gs_cairo
->cairo_set_line_cap(cr
, CAIRO_LINE_CAP_SQUARE
);
2074 gs_cairo
->cairo_set_line_width(cr
, 1);
2075 gs_cairo
->cairo_set_line_join(cr
,CAIRO_LINE_JOIN_MITER
);
2077 switch (m_brush
.GetStyle())
2080 gs_cairo
->cairo_move_to(cr
, 5, 0);
2081 gs_cairo
->cairo_line_to(cr
, 5, 10);
2082 gs_cairo
->cairo_move_to(cr
, 0, 5);
2083 gs_cairo
->cairo_line_to(cr
, 10, 5);
2085 case wxBDIAGONAL_HATCH
:
2086 gs_cairo
->cairo_move_to(cr
, 0, 10);
2087 gs_cairo
->cairo_line_to(cr
, 10, 0);
2089 case wxFDIAGONAL_HATCH
:
2090 gs_cairo
->cairo_move_to(cr
, 0, 0);
2091 gs_cairo
->cairo_line_to(cr
, 10, 10);
2093 case wxCROSSDIAG_HATCH
:
2094 gs_cairo
->cairo_move_to(cr
, 0, 0);
2095 gs_cairo
->cairo_line_to(cr
, 10, 10);
2096 gs_cairo
->cairo_move_to(cr
, 10, 0);
2097 gs_cairo
->cairo_line_to(cr
, 0, 10);
2099 case wxHORIZONTAL_HATCH
:
2100 gs_cairo
->cairo_move_to(cr
, 0, 5);
2101 gs_cairo
->cairo_line_to(cr
, 10, 5);
2103 case wxVERTICAL_HATCH
:
2104 gs_cairo
->cairo_move_to(cr
, 5, 0);
2105 gs_cairo
->cairo_line_to(cr
, 5, 10);
2108 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
2111 gs_cairo
->cairo_set_source_rgba(cr
, redPS
, greenPS
, bluePS
, alphaPS
);
2112 gs_cairo
->cairo_stroke (cr
);
2114 gs_cairo
->cairo_destroy(cr
);
2115 cairo_pattern_t
* pattern
= gs_cairo
->cairo_pattern_create_for_surface (surface
);
2116 gs_cairo
->cairo_surface_destroy(surface
);
2117 gs_cairo
->cairo_pattern_set_extend (pattern
, CAIRO_EXTEND_REPEAT
);
2118 gs_cairo
->cairo_set_source(m_cairo
, pattern
);
2119 gs_cairo
->cairo_pattern_destroy(pattern
);
2123 void wxGtkPrintDC::SetLogicalFunction( int function
)
2125 if (function
== wxCLEAR
)
2126 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_CLEAR
);
2127 else if (function
== wxOR
)
2128 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_OUT
);
2129 else if (function
== wxNO_OP
)
2130 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST
);
2131 else if (function
== wxAND
)
2132 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_ADD
);
2133 else if (function
== wxSET
)
2134 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SATURATE
);
2135 else if (function
== wxXOR
)
2136 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_XOR
);
2137 else // wxCOPY or anything else.
2138 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_SOURCE
);
2141 void wxGtkPrintDC::SetBackground( const wxBrush
& brush
)
2143 m_backgroundBrush
= brush
;
2144 gs_cairo
->cairo_save(m_cairo
);
2145 gs_cairo
->cairo_set_operator (m_cairo
, CAIRO_OPERATOR_DEST_OVER
);
2147 SetBrush(m_backgroundBrush
);
2148 gs_cairo
->cairo_paint(m_cairo
);
2149 gs_cairo
->cairo_restore(m_cairo
);
2152 void wxGtkPrintDC::SetBackgroundMode(int mode
)
2154 if (mode
== wxSOLID
) m_backgroundMode
= wxSOLID
;
2155 else m_backgroundMode
= wxTRANSPARENT
;
2158 void wxGtkPrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2160 gs_cairo
->cairo_rectangle ( m_cairo
, LogicalToDeviceX(x
), LogicalToDeviceY(y
), LogicalToDeviceXRel(width
), LogicalToDeviceYRel(height
));
2161 gs_cairo
->cairo_clip(m_cairo
);
2164 void wxGtkPrintDC::DestroyClippingRegion()
2166 gs_cairo
->cairo_reset_clip(m_cairo
);
2169 bool wxGtkPrintDC::StartDoc(const wxString
& message
)
2174 void wxGtkPrintDC::EndDoc()
2179 void wxGtkPrintDC::StartPage()
2184 void wxGtkPrintDC::EndPage()
2189 wxCoord
wxGtkPrintDC::GetCharHeight() const
2191 pango_layout_set_text( m_layout
, "H", 1 );
2194 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2196 return DeviceToLogicalYRel(h
);
2199 wxCoord
wxGtkPrintDC::GetCharWidth() const
2201 pango_layout_set_text( m_layout
, "H", 1 );
2204 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2206 return DeviceToLogicalXRel(w
);
2209 void wxGtkPrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
2211 wxCoord
*externalLeading
,
2212 const wxFont
*theFont
) const
2220 if ( externalLeading
)
2221 *externalLeading
= 0;
2228 // Set layout's text
2229 // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
2230 #if wxUSE_UNICODE_UTF8
2231 const char *dataUTF8
= string
.utf8_str();
2233 const wxCharBuffer dataUTF8
= string
.utf8_str();
2236 PangoFontDescription
*desc
= m_fontdesc
;
2237 if (theFont
) desc
= theFont
->GetNativeFontInfo()->description
;
2239 gint oldSize
= pango_font_description_get_size( desc
);
2240 double size
= oldSize
;
2241 size
= size
* m_scaleY
;
2242 pango_font_description_set_size( desc
, (gint
)size
);
2244 // apply scaled font
2245 pango_layout_set_font_description( m_layout
, desc
);
2247 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
2250 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
2253 *width
= (wxCoord
)(w
/ m_scaleX
);
2255 *height
= (wxCoord
)(h
/ m_scaleY
);
2258 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
2259 int baseline
= pango_layout_iter_get_baseline(iter
);
2260 pango_layout_iter_free(iter
);
2261 *descent
= h
- PANGO_PIXELS(baseline
);
2264 // Reset unscaled size.
2265 pango_font_description_set_size( desc
, oldSize
);
2267 // Reset unscaled font.
2268 pango_layout_set_font_description( m_layout
, m_fontdesc
);
2271 void wxGtkPrintDC::DoGetSize(int* width
, int* height
) const
2274 *width
= (int) (gtk_print_context_get_width( m_gpc
) + 0.5);
2276 *height
= (int) (gtk_print_context_get_height( m_gpc
) + 0.5);
2279 void wxGtkPrintDC::DoGetSizeMM(int *width
, int *height
) const
2281 // This function takes margins into consideration.
2282 gdouble w
= gtk_page_setup_get_page_width( gtk_print_context_get_page_setup( m_gpc
), GTK_UNIT_MM
);
2283 gdouble h
= gtk_page_setup_get_page_height( gtk_print_context_get_page_setup( m_gpc
), GTK_UNIT_MM
);
2286 *width
= (int) (w
+ 0.5);
2288 *height
= (int) (h
+ 0.5);
2291 wxSize
wxGtkPrintDC::GetPPI() const
2293 gdouble xDpi
= gtk_print_context_get_dpi_x( m_gpc
);
2294 gdouble yDpi
= gtk_print_context_get_dpi_y( m_gpc
);
2295 return wxSize((int) xDpi
,(int) yDpi
);
2298 void wxGtkPrintDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
2300 wxDC::SetLogicalOrigin( x
, y
);
2303 void wxGtkPrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
2305 wxDC::SetDeviceOrigin( x
, y
);
2308 void wxGtkPrintDC::SetPrintData(const wxPrintData
& data
)
2312 if (m_printData
.GetOrientation() == wxPORTRAIT
)
2313 GetSize( &m_deviceOffsetX
, &m_deviceOffsetY
);
2315 GetSize( &m_deviceOffsetY
, &m_deviceOffsetX
);
2318 void wxGtkPrintDC::SetResolution(int ppi
)
2320 // We can't change ppi of the GtkPrintContext.
2321 ms_resolution
= ppi
;
2324 int wxGtkPrintDC::GetResolution()
2326 return ms_resolution
;
2329 // ----------------------------------------------------------------------------
2331 // ----------------------------------------------------------------------------
2333 IMPLEMENT_CLASS(wxGtkPrintPreview
, wxPrintPreviewBase
)
2335 void wxGtkPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
2336 wxPrintout
* WXUNUSED(printoutForPrinting
))
2341 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2342 wxPrintout
*printoutForPrinting
,
2343 wxPrintDialogData
*data
)
2344 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2346 Init(printout
, printoutForPrinting
);
2349 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout
*printout
,
2350 wxPrintout
*printoutForPrinting
,
2352 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
2354 Init(printout
, printoutForPrinting
);
2357 wxGtkPrintPreview::~wxGtkPrintPreview()
2361 bool wxGtkPrintPreview::Print(bool interactive
)
2363 if (!m_printPrintout
)
2366 wxPrinter
printer(& m_printDialogData
);
2367 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
2370 void wxGtkPrintPreview::DetermineScaling()
2372 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
2374 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2376 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
2380 wxSize ScreenPixels
= wxGetDisplaySize();
2381 wxSize ScreenMM
= wxGetDisplaySizeMM();
2383 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
2384 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
2385 m_previewPrintout
->SetPPIPrinter(wxGtkPrintDC::GetResolution(), wxGtkPrintDC::GetResolution());
2386 // Get width and height in points (1/72th of an inch)
2387 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
2389 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxGtkPrintDC::GetResolution() / 72.0);
2390 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxGtkPrintDC::GetResolution() / 72.0);
2391 wxSize
sizeTenthsMM(paper
->GetSize());
2392 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
2394 // If in landscape mode, we need to swap the width and height.
2395 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
2397 m_pageWidth
= sizeDevUnits
.y
;
2398 m_pageHeight
= sizeDevUnits
.x
;
2399 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
2403 m_pageWidth
= sizeDevUnits
.x
;
2404 m_pageHeight
= sizeDevUnits
.y
;
2405 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
2407 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
2408 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
2410 // At 100%, the page should look about page-size on the screen.
2411 m_previewScaleX
= (float)0.8 * 72.0 / (float)wxGtkPrintDC::GetResolution();
2412 m_previewScaleY
= m_previewScaleX
;