]>
Commit | Line | Data |
---|---|---|
fa034c45 | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: src/gtk/print.cpp |
fa034c45 RR |
3 | // Author: Anthony Bretaudeau |
4 | // Purpose: GTK printing support | |
5 | // Created: 2007-08-25 | |
b5b208a1 | 6 | // RCS-ID: $Id$ |
fa034c45 RR |
7 | // Copyright: (c) 2007 wxWidgets development team |
8 | // Licence: wxWindows Licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // For compilers that support precompilation, includes "wx/wx.h". | |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | #if wxUSE_GTKPRINT | |
19 | ||
20 | #include "wx/gtk/print.h" | |
21 | ||
22 | #ifndef WX_PRECOMP | |
23 | #include "wx/log.h" | |
24 | #include "wx/dcmemory.h" | |
380740af | 25 | #include "wx/dcprint.h" |
fa034c45 RR |
26 | #include "wx/icon.h" |
27 | #include "wx/math.h" | |
28 | #include "wx/image.h" | |
29 | #include "wx/module.h" | |
a7060b8c | 30 | #include "wx/crt.h" |
fa034c45 RR |
31 | #endif |
32 | ||
33 | #include "wx/fontutil.h" | |
fa034c45 RR |
34 | #include "wx/dynlib.h" |
35 | #include "wx/paper.h" | |
fa034c45 RR |
36 | |
37 | #include <gtk/gtk.h> | |
ca9e5214 VS |
38 | |
39 | #if GTK_CHECK_VERSION(2,14,0) | |
adc62081 | 40 | #include <gtk/gtkunixprint.h> |
ca9e5214 | 41 | #else |
65303ed7 | 42 | #include <gtk/gtkpagesetupunixdialog.h> |
ca9e5214 VS |
43 | #endif |
44 | ||
fa034c45 | 45 | |
2b44ffc0 RR |
46 | #if wxUSE_GRAPHICS_CONTEXT |
47 | #include "wx/graphics.h" | |
48 | #endif | |
49 | ||
fa034c45 RR |
50 | #include "wx/link.h" |
51 | wxFORCE_LINK_THIS_MODULE(gtk_print) | |
52 | ||
53 | #if wxUSE_LIBGNOMEPRINT | |
54 | #include "wx/gtk/gnome/gprint.h" | |
55 | #endif | |
56 | ||
9e19da0f VZ |
57 | #include "wx/gtk/private/object.h" |
58 | ||
d13b34d3 | 59 | // Useful to convert angles from/to Rad to/from Deg. |
fa034c45 RR |
60 | static const double RAD2DEG = 180.0 / M_PI; |
61 | static const double DEG2RAD = M_PI / 180.0; | |
62 | ||
63 | //---------------------------------------------------------------------------- | |
64 | // wxGtkPrintModule | |
65 | // Initialized when starting the app : if it successfully load the gtk-print framework, | |
66 | // it uses it. If not, it falls back to gnome print (see /gtk/gnome/gprint.cpp) then | |
67 | // to postscript if gnomeprint is not available. | |
68 | //---------------------------------------------------------------------------- | |
69 | ||
70 | class wxGtkPrintModule: public wxModule | |
71 | { | |
72 | public: | |
a7060b8c | 73 | wxGtkPrintModule() |
fa034c45 RR |
74 | { |
75 | #if wxUSE_LIBGNOMEPRINT | |
76 | // This module must be initialized AFTER gnomeprint's one | |
77 | AddDependency(CLASSINFO(wxGnomePrintModule)); | |
78 | #endif | |
79 | } | |
80 | bool OnInit(); | |
f7b8e3d6 | 81 | void OnExit() {} |
fa034c45 RR |
82 | |
83 | private: | |
84 | DECLARE_DYNAMIC_CLASS(wxGtkPrintModule) | |
85 | }; | |
86 | ||
87 | bool wxGtkPrintModule::OnInit() | |
88 | { | |
f7b8e3d6 | 89 | if (gtk_check_version(2,10,0) == NULL) |
fa034c45 | 90 | wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory ); |
fa034c45 RR |
91 | return true; |
92 | } | |
93 | ||
fa034c45 RR |
94 | IMPLEMENT_DYNAMIC_CLASS(wxGtkPrintModule, wxModule) |
95 | ||
fa034c45 RR |
96 | //---------------------------------------------------------------------------- |
97 | // wxGtkPrintFactory | |
98 | //---------------------------------------------------------------------------- | |
99 | ||
100 | wxPrinterBase* wxGtkPrintFactory::CreatePrinter( wxPrintDialogData *data ) | |
101 | { | |
102 | return new wxGtkPrinter( data ); | |
103 | } | |
104 | ||
105 | wxPrintPreviewBase *wxGtkPrintFactory::CreatePrintPreview( wxPrintout *preview, | |
106 | wxPrintout *printout, | |
107 | wxPrintDialogData *data ) | |
108 | { | |
109 | return new wxGtkPrintPreview( preview, printout, data ); | |
110 | } | |
111 | ||
112 | wxPrintPreviewBase *wxGtkPrintFactory::CreatePrintPreview( wxPrintout *preview, | |
113 | wxPrintout *printout, | |
114 | wxPrintData *data ) | |
115 | { | |
116 | return new wxGtkPrintPreview( preview, printout, data ); | |
117 | } | |
118 | ||
119 | wxPrintDialogBase *wxGtkPrintFactory::CreatePrintDialog( wxWindow *parent, | |
120 | wxPrintDialogData *data ) | |
121 | { | |
122 | return new wxGtkPrintDialog( parent, data ); | |
123 | } | |
124 | ||
125 | wxPrintDialogBase *wxGtkPrintFactory::CreatePrintDialog( wxWindow *parent, | |
126 | wxPrintData *data ) | |
127 | { | |
128 | return new wxGtkPrintDialog( parent, data ); | |
129 | } | |
130 | ||
131 | wxPageSetupDialogBase *wxGtkPrintFactory::CreatePageSetupDialog( wxWindow *parent, | |
132 | wxPageSetupDialogData * data ) | |
133 | { | |
134 | return new wxGtkPageSetupDialog( parent, data ); | |
135 | } | |
136 | ||
137 | bool wxGtkPrintFactory::HasPrintSetupDialog() | |
138 | { | |
139 | return false; | |
140 | } | |
141 | ||
e0d1fd7f VZ |
142 | wxDialog * |
143 | wxGtkPrintFactory::CreatePrintSetupDialog(wxWindow * WXUNUSED(parent), | |
144 | wxPrintData * WXUNUSED(data)) | |
fa034c45 RR |
145 | { |
146 | return NULL; | |
147 | } | |
148 | ||
888dde65 | 149 | wxDCImpl* wxGtkPrintFactory::CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) |
4f37154e | 150 | { |
888dde65 | 151 | return new wxGtkPrinterDCImpl( owner, data ); |
4f37154e RR |
152 | } |
153 | ||
fa034c45 RR |
154 | bool wxGtkPrintFactory::HasOwnPrintToFile() |
155 | { | |
156 | return true; | |
157 | } | |
158 | ||
159 | bool wxGtkPrintFactory::HasPrinterLine() | |
160 | { | |
161 | return true; | |
162 | } | |
163 | ||
164 | wxString wxGtkPrintFactory::CreatePrinterLine() | |
165 | { | |
166 | // redundant now | |
167 | return wxEmptyString; | |
168 | } | |
169 | ||
170 | bool wxGtkPrintFactory::HasStatusLine() | |
171 | { | |
172 | // redundant now | |
173 | return true; | |
174 | } | |
175 | ||
176 | wxString wxGtkPrintFactory::CreateStatusLine() | |
177 | { | |
178 | // redundant now | |
179 | return wxEmptyString; | |
180 | } | |
181 | ||
182 | wxPrintNativeDataBase *wxGtkPrintFactory::CreatePrintNativeData() | |
183 | { | |
184 | return new wxGtkPrintNativeData; | |
185 | } | |
186 | ||
187 | //---------------------------------------------------------------------------- | |
188 | // Callback functions for Gtk Printings. | |
189 | //---------------------------------------------------------------------------- | |
190 | ||
e0d1fd7f | 191 | // We use it to pass useful objects to GTK printing callback functions. |
a7060b8c | 192 | struct wxPrinterToGtkData |
fa034c45 RR |
193 | { |
194 | wxGtkPrinter * printer; | |
195 | wxPrintout * printout; | |
a7060b8c | 196 | }; |
fa034c45 RR |
197 | |
198 | extern "C" | |
199 | { | |
200 | static void gtk_begin_print_callback (GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data) | |
201 | { | |
202 | wxPrinterToGtkData *data = (wxPrinterToGtkData *) user_data; | |
203 | ||
204 | data->printer->BeginPrint(data->printout, operation, context); | |
205 | } | |
206 | ||
207 | static void gtk_draw_page_print_callback (GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data) | |
208 | { | |
209 | wxPrinterToGtkData *data = (wxPrinterToGtkData *) user_data; | |
210 | ||
211 | data->printer->DrawPage(data->printout, operation, context, page_nr); | |
212 | } | |
213 | ||
e0d1fd7f VZ |
214 | static void gtk_end_print_callback(GtkPrintOperation * WXUNUSED(operation), |
215 | GtkPrintContext * WXUNUSED(context), | |
216 | gpointer user_data) | |
fa034c45 RR |
217 | { |
218 | wxPrintout *printout = (wxPrintout *) user_data; | |
219 | ||
220 | printout->OnEndPrinting(); | |
221 | } | |
fa034c45 RR |
222 | } |
223 | ||
224 | //---------------------------------------------------------------------------- | |
225 | // wxGtkPrintNativeData | |
226 | //---------------------------------------------------------------------------- | |
227 | ||
228 | IMPLEMENT_CLASS(wxGtkPrintNativeData, wxPrintNativeDataBase) | |
229 | ||
230 | wxGtkPrintNativeData::wxGtkPrintNativeData() | |
231 | { | |
232 | m_config = gtk_print_settings_new(); | |
820ec9bb VZ |
233 | m_job = gtk_print_operation_new(); |
234 | m_context = NULL; | |
fa034c45 RR |
235 | } |
236 | ||
237 | wxGtkPrintNativeData::~wxGtkPrintNativeData() | |
238 | { | |
820ec9bb VZ |
239 | g_object_unref(m_job); |
240 | g_object_unref(m_config); | |
fa034c45 RR |
241 | } |
242 | ||
243 | // Convert datas stored in m_config to a wxPrintData. | |
244 | // Called by wxPrintData::ConvertFromNative(). | |
245 | bool wxGtkPrintNativeData::TransferTo( wxPrintData &data ) | |
246 | { | |
247 | if(!m_config) | |
248 | return false; | |
249 | ||
23abaeae VZ |
250 | int resolution = gtk_print_settings_get_resolution(m_config); |
251 | if ( resolution > 0 ) | |
252 | { | |
253 | // if resolution is explicitly set, use it | |
254 | data.SetQuality(resolution); | |
255 | } | |
256 | else // use more vague "quality" | |
257 | { | |
258 | GtkPrintQuality quality = gtk_print_settings_get_quality(m_config); | |
259 | if (quality == GTK_PRINT_QUALITY_HIGH) | |
260 | data.SetQuality(wxPRINT_QUALITY_HIGH); | |
261 | else if (quality == GTK_PRINT_QUALITY_LOW) | |
262 | data.SetQuality(wxPRINT_QUALITY_LOW); | |
263 | else if (quality == GTK_PRINT_QUALITY_DRAFT) | |
264 | data.SetQuality(wxPRINT_QUALITY_DRAFT); | |
265 | else | |
266 | data.SetQuality(wxPRINT_QUALITY_MEDIUM); | |
267 | } | |
fa034c45 RR |
268 | |
269 | data.SetNoCopies(gtk_print_settings_get_n_copies(m_config)); | |
270 | ||
271 | data.SetColour(gtk_print_settings_get_use_color(m_config)); | |
272 | ||
273 | switch (gtk_print_settings_get_duplex(m_config)) | |
274 | { | |
275 | case GTK_PRINT_DUPLEX_SIMPLEX: data.SetDuplex (wxDUPLEX_SIMPLEX); | |
276 | break; | |
277 | ||
278 | case GTK_PRINT_DUPLEX_HORIZONTAL: data.SetDuplex (wxDUPLEX_HORIZONTAL); | |
279 | break; | |
280 | ||
281 | default: | |
282 | case GTK_PRINT_DUPLEX_VERTICAL: data.SetDuplex (wxDUPLEX_VERTICAL); | |
283 | break; | |
284 | } | |
285 | ||
286 | GtkPageOrientation orientation = gtk_print_settings_get_orientation (m_config); | |
287 | if (orientation == GTK_PAGE_ORIENTATION_PORTRAIT) | |
288 | { | |
289 | data.SetOrientation(wxPORTRAIT); | |
290 | data.SetOrientationReversed(false); | |
291 | } | |
292 | else if (orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) | |
293 | { | |
294 | data.SetOrientation(wxLANDSCAPE); | |
295 | data.SetOrientationReversed(false); | |
296 | } | |
297 | else if (orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT) | |
298 | { | |
299 | data.SetOrientation(wxPORTRAIT); | |
300 | data.SetOrientationReversed(true); | |
301 | } | |
302 | else if (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE) | |
303 | { | |
304 | data.SetOrientation(wxLANDSCAPE); | |
305 | data.SetOrientationReversed(true); | |
306 | } | |
307 | ||
308 | data.SetCollate(gtk_print_settings_get_collate (m_config)); | |
309 | ||
310 | // Paper formats : these are the most common paper formats. | |
311 | GtkPaperSize *paper_size = gtk_print_settings_get_paper_size (m_config); | |
312 | if (!paper_size) | |
313 | data.SetPaperId(wxPAPER_NONE); | |
314 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_A3))) | |
315 | data.SetPaperId(wxPAPER_A3); | |
316 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_A4))) | |
317 | data.SetPaperId(wxPAPER_A4); | |
318 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_A5))) | |
319 | data.SetPaperId(wxPAPER_A5); | |
320 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_B5))) | |
321 | data.SetPaperId(wxPAPER_B5); | |
322 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_LETTER))) | |
323 | data.SetPaperId(wxPAPER_LETTER); | |
324 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_LEGAL))) | |
325 | data.SetPaperId(wxPAPER_LEGAL); | |
326 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE))) | |
327 | data.SetPaperId(wxPAPER_EXECUTIVE); | |
328 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"na_number-10"))) | |
329 | data.SetPaperId(wxPAPER_ENV_10); | |
330 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-c5"))) | |
331 | data.SetPaperId(wxPAPER_ENV_C5); | |
332 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-c6"))) | |
333 | data.SetPaperId(wxPAPER_ENV_C6); | |
334 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"jis-b5"))) | |
335 | data.SetPaperId(wxPAPER_B5_TRANSVERSE); | |
336 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-b5"))) | |
337 | data.SetPaperId(wxPAPER_ENV_B5); | |
338 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"na_monarch"))) | |
339 | data.SetPaperId(wxPAPER_ENV_MONARCH); | |
340 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"engineering-c"))) | |
341 | data.SetPaperId( wxPAPER_CSHEET); | |
342 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"engineering-d"))) | |
343 | data.SetPaperId( wxPAPER_DSHEET); | |
344 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"engineering-e"))) | |
345 | data.SetPaperId( wxPAPER_ESHEET); | |
346 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"letter"))) | |
347 | data.SetPaperId( wxPAPER_LETTERSMALL); | |
348 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"engineering-b"))) | |
349 | data.SetPaperId( wxPAPER_TABLOID); | |
350 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"ledger"))) | |
351 | data.SetPaperId( wxPAPER_LEDGER); | |
352 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"statement"))) | |
353 | data.SetPaperId( wxPAPER_STATEMENT); | |
354 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( GTK_PAPER_NAME_A4 ))) | |
355 | data.SetPaperId( wxPAPER_A4SMALL); | |
356 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-b4"))) | |
357 | data.SetPaperId( wxPAPER_B4); | |
358 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"folio"))) | |
359 | data.SetPaperId( wxPAPER_FOLIO); | |
360 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"quarto"))) | |
361 | data.SetPaperId( wxPAPER_QUARTO); | |
362 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"10x14"))) | |
363 | data.SetPaperId( wxPAPER_10X14); | |
364 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"ledger"))) | |
365 | data.SetPaperId( wxPAPER_11X17); | |
366 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"letter"))) | |
367 | data.SetPaperId( wxPAPER_NOTE); | |
368 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"na-number-9-envelope"))) | |
369 | data.SetPaperId( wxPAPER_ENV_9); | |
370 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"number-11"))) | |
371 | data.SetPaperId( wxPAPER_ENV_11); | |
372 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"number-12"))) | |
373 | data.SetPaperId( wxPAPER_ENV_12); | |
374 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"number-14"))) | |
375 | data.SetPaperId( wxPAPER_ENV_14); | |
376 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-designated"))) | |
377 | data.SetPaperId( wxPAPER_ENV_DL); | |
378 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-c3"))) | |
379 | data.SetPaperId( wxPAPER_ENV_C3); | |
380 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-c4"))) | |
381 | data.SetPaperId( wxPAPER_ENV_C4); | |
382 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"c6/c5"))) | |
383 | data.SetPaperId( wxPAPER_ENV_C65); | |
384 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-b4"))) | |
385 | data.SetPaperId( wxPAPER_ENV_B4); | |
386 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"iso-b6"))) | |
387 | data.SetPaperId( wxPAPER_ENV_B6); | |
388 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"Italian"))) | |
389 | data.SetPaperId( wxPAPER_ENV_ITALY); | |
390 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"personal"))) | |
391 | data.SetPaperId( wxPAPER_ENV_PERSONAL); | |
392 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"fanfold-us"))) | |
393 | data.SetPaperId( wxPAPER_FANFOLD_US); | |
394 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"fanfold-European"))) | |
395 | data.SetPaperId( wxPAPER_FANFOLD_STD_GERMAN); | |
396 | else if (gtk_paper_size_is_equal(paper_size,gtk_paper_size_new ( (const gchar*)"foolscap"))) | |
397 | data.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN); | |
398 | else | |
399 | data.SetPaperId(wxPAPER_NONE); | |
34b2bc59 VZ |
400 | |
401 | data.SetPrinterName(gtk_print_settings_get_printer(m_config)); | |
402 | ||
fa034c45 RR |
403 | return true; |
404 | } | |
405 | ||
406 | // Put datas given by the wxPrintData into m_config. | |
407 | // Called by wxPrintData::ConvertToNative(). | |
408 | bool wxGtkPrintNativeData::TransferFrom( const wxPrintData &data ) | |
409 | { | |
410 | if(!m_config) | |
411 | return false; | |
412 | ||
413 | wxPrintQuality quality = data.GetQuality(); | |
414 | if (quality == wxPRINT_QUALITY_HIGH) | |
415 | gtk_print_settings_set_quality (m_config, GTK_PRINT_QUALITY_HIGH); | |
416 | else if (quality == wxPRINT_QUALITY_MEDIUM) | |
417 | gtk_print_settings_set_quality (m_config, GTK_PRINT_QUALITY_NORMAL); | |
418 | else if (quality == wxPRINT_QUALITY_LOW) | |
419 | gtk_print_settings_set_quality (m_config, GTK_PRINT_QUALITY_LOW); | |
420 | else if (quality == wxPRINT_QUALITY_DRAFT) | |
421 | gtk_print_settings_set_quality (m_config, GTK_PRINT_QUALITY_DRAFT); | |
422 | else if (quality > 1) | |
423 | gtk_print_settings_set_resolution (m_config, quality); | |
424 | else | |
425 | gtk_print_settings_set_quality (m_config, GTK_PRINT_QUALITY_NORMAL); | |
426 | ||
427 | gtk_print_settings_set_n_copies(m_config, data.GetNoCopies()); | |
428 | ||
429 | gtk_print_settings_set_use_color(m_config, data.GetColour()); | |
430 | ||
431 | switch (data.GetDuplex()) | |
432 | { | |
433 | case wxDUPLEX_SIMPLEX: gtk_print_settings_set_duplex (m_config, GTK_PRINT_DUPLEX_SIMPLEX); | |
434 | break; | |
435 | ||
436 | case wxDUPLEX_HORIZONTAL: gtk_print_settings_set_duplex (m_config, GTK_PRINT_DUPLEX_HORIZONTAL); | |
437 | break; | |
438 | ||
439 | default: | |
440 | case wxDUPLEX_VERTICAL: gtk_print_settings_set_duplex (m_config, GTK_PRINT_DUPLEX_VERTICAL); | |
441 | break; | |
442 | } | |
443 | ||
444 | if (!data.IsOrientationReversed()) | |
445 | { | |
446 | if (data.GetOrientation() == wxLANDSCAPE) | |
447 | gtk_print_settings_set_orientation (m_config, GTK_PAGE_ORIENTATION_LANDSCAPE); | |
448 | else | |
449 | gtk_print_settings_set_orientation (m_config, GTK_PAGE_ORIENTATION_PORTRAIT); | |
450 | } | |
451 | else { | |
452 | if (data.GetOrientation() == wxLANDSCAPE) | |
453 | gtk_print_settings_set_orientation (m_config, GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE); | |
454 | else | |
455 | gtk_print_settings_set_orientation (m_config, GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT); | |
456 | } | |
457 | ||
458 | gtk_print_settings_set_collate (m_config, data.GetCollate()); | |
459 | ||
460 | // Paper formats: these are the most common paper formats. | |
461 | switch (data.GetPaperId()) | |
462 | { | |
463 | case wxPAPER_A3: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_A3)); | |
464 | break; | |
465 | case wxPAPER_A4: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_A4)); | |
466 | break; | |
467 | case wxPAPER_A5: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_A5)); | |
468 | break; | |
469 | case wxPAPER_B5_TRANSVERSE: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "jis-b5")); | |
470 | break; | |
471 | case wxPAPER_B5: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_B5)); | |
472 | break; | |
473 | case wxPAPER_LETTER: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_LETTER)); | |
474 | break; | |
475 | case wxPAPER_LEGAL: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_LEGAL)); | |
476 | break; | |
477 | case wxPAPER_EXECUTIVE: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_EXECUTIVE)); | |
478 | break; | |
479 | case wxPAPER_ENV_10: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "na_number-10")); | |
480 | break; | |
481 | case wxPAPER_ENV_C5: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-c5")); | |
482 | break; | |
483 | case wxPAPER_ENV_C6: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-c6")); | |
484 | break; | |
485 | case wxPAPER_ENV_B5: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-c5b5")); | |
486 | break; | |
487 | case wxPAPER_ENV_MONARCH: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "na_monarch")); | |
488 | break; | |
489 | case wxPAPER_CSHEET: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "engineering-c")); | |
490 | break; | |
491 | case wxPAPER_DSHEET: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "engineering-d")); | |
492 | break; | |
493 | case wxPAPER_ESHEET: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "engineering-e")); | |
494 | break; | |
495 | case wxPAPER_LETTERSMALL: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "letter")); | |
496 | break; | |
497 | case wxPAPER_TABLOID: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "engineering-b")); | |
498 | break; | |
499 | case wxPAPER_LEDGER: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "ledger")); | |
500 | break; | |
501 | case wxPAPER_STATEMENT: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "statement")); | |
502 | break; | |
503 | case wxPAPER_A4SMALL: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new (GTK_PAPER_NAME_A4)); | |
504 | break; | |
505 | case wxPAPER_B4: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-b4")); | |
506 | break; | |
507 | case wxPAPER_FOLIO: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "folio")); | |
508 | break; | |
509 | case wxPAPER_QUARTO: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "quarto")); | |
510 | break; | |
511 | case wxPAPER_10X14: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "10x14")); | |
512 | break; | |
513 | case wxPAPER_11X17: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "ledger")); | |
514 | break; | |
515 | case wxPAPER_NOTE: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "letter")); | |
516 | break; | |
517 | case wxPAPER_ENV_9: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "na-number-9-envelope")); | |
518 | break; | |
519 | case wxPAPER_ENV_11: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "number-11")); | |
520 | break; | |
521 | case wxPAPER_ENV_12: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "number-12")); | |
522 | break; | |
523 | case wxPAPER_ENV_14: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "number-14")); | |
524 | break; | |
525 | case wxPAPER_ENV_DL: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-designated")); | |
526 | break; | |
527 | case wxPAPER_ENV_C3: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-c3")); | |
528 | break; | |
529 | case wxPAPER_ENV_C4: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-c4")); | |
530 | break; | |
531 | case wxPAPER_ENV_C65: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "c6/c5")); | |
532 | break; | |
533 | case wxPAPER_ENV_B4: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-b4")); | |
534 | break; | |
535 | case wxPAPER_ENV_B6: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "iso-b6")); | |
536 | break; | |
537 | case wxPAPER_ENV_ITALY: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "Italian")); | |
538 | break; | |
539 | case wxPAPER_ENV_PERSONAL: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "personal")); | |
540 | break; | |
541 | case wxPAPER_FANFOLD_US: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "fanfold-us")); | |
542 | break; | |
543 | case wxPAPER_FANFOLD_STD_GERMAN: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "fanfold-European")); | |
544 | break; | |
545 | case wxPAPER_FANFOLD_LGL_GERMAN: gtk_print_settings_set_paper_size(m_config, gtk_paper_size_new ((const gchar*) "foolscap")); | |
546 | break; | |
547 | case wxPAPER_NONE: | |
548 | default: break; | |
549 | } | |
550 | ||
b37e255c | 551 | gtk_print_settings_set_printer(m_config, data.GetPrinterName().utf8_str()); |
34b2bc59 | 552 | |
fa034c45 RR |
553 | return true; |
554 | } | |
555 | ||
556 | void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings * config ) | |
557 | { | |
558 | if (config) | |
559 | m_config = gtk_print_settings_copy(config); | |
560 | } | |
561 | ||
562 | // Extract page setup from settings. | |
563 | GtkPageSetup* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings* settings) | |
564 | { | |
565 | GtkPageSetup* page_setup = gtk_page_setup_new(); | |
a7060b8c | 566 | gtk_page_setup_set_orientation (page_setup, gtk_print_settings_get_orientation (settings)); |
fa034c45 | 567 | |
a7060b8c PC |
568 | GtkPaperSize *paper_size = gtk_print_settings_get_paper_size (settings); |
569 | if (paper_size != NULL) | |
570 | gtk_page_setup_set_paper_size_and_default_margins (page_setup, paper_size); | |
fa034c45 RR |
571 | |
572 | return page_setup; | |
573 | } | |
574 | ||
575 | // Insert page setup into a given GtkPrintSettings. | |
576 | void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings* settings, GtkPageSetup* page_setup) | |
577 | { | |
578 | gtk_print_settings_set_orientation ( settings, gtk_page_setup_get_orientation (page_setup)); | |
a7060b8c | 579 | gtk_print_settings_set_paper_size ( settings, gtk_page_setup_get_paper_size (page_setup)); |
fa034c45 RR |
580 | } |
581 | ||
582 | //---------------------------------------------------------------------------- | |
583 | // wxGtkPrintDialog | |
584 | //---------------------------------------------------------------------------- | |
585 | ||
586 | IMPLEMENT_CLASS(wxGtkPrintDialog, wxPrintDialogBase) | |
587 | ||
588 | wxGtkPrintDialog::wxGtkPrintDialog( wxWindow *parent, wxPrintDialogData *data ) | |
589 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
590 | wxPoint(0, 0), wxSize(600, 600), | |
591 | wxDEFAULT_DIALOG_STYLE | | |
592 | wxTAB_TRAVERSAL) | |
593 | { | |
594 | if (data) | |
595 | m_printDialogData = *data; | |
596 | ||
597 | m_parent = parent; | |
598 | SetShowDialog(true); | |
599 | } | |
600 | ||
601 | wxGtkPrintDialog::wxGtkPrintDialog( wxWindow *parent, wxPrintData *data ) | |
602 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
603 | wxPoint(0, 0), wxSize(600, 600), | |
604 | wxDEFAULT_DIALOG_STYLE | | |
605 | wxTAB_TRAVERSAL) | |
606 | { | |
607 | if (data) | |
608 | m_printDialogData = *data; | |
609 | ||
610 | m_parent = parent; | |
611 | SetShowDialog(true); | |
612 | } | |
613 | ||
614 | ||
615 | wxGtkPrintDialog::~wxGtkPrintDialog() | |
616 | { | |
617 | } | |
618 | ||
619 | // This is called even if we actually don't want the dialog to appear. | |
620 | int wxGtkPrintDialog::ShowModal() | |
621 | { | |
622 | GtkPrintOperationResult response; | |
623 | ||
624 | // We need to restore the settings given in the constructor. | |
625 | wxPrintData data = m_printDialogData.GetPrintData(); | |
626 | wxGtkPrintNativeData *native = | |
627 | (wxGtkPrintNativeData*) data.GetNativeData(); | |
628 | data.ConvertToNative(); | |
629 | ||
630 | GtkPrintSettings * settings = native->GetPrintConfig(); | |
631 | ||
632 | // We have to restore pages to print here because they're stored in a wxPrintDialogData and ConvertToNative only works for wxPrintData. | |
633 | int fromPage = m_printDialogData.GetFromPage(); | |
634 | int toPage = m_printDialogData.GetToPage(); | |
635 | if (m_printDialogData.GetSelection()) | |
636 | gtk_print_settings_set_print_pages(settings, GTK_PRINT_PAGES_CURRENT); | |
637 | else if (m_printDialogData.GetAllPages()) | |
638 | gtk_print_settings_set_print_pages(settings, GTK_PRINT_PAGES_ALL); | |
639 | else { | |
640 | gtk_print_settings_set_print_pages(settings, GTK_PRINT_PAGES_RANGES); | |
641 | GtkPageRange *range; | |
642 | range = g_new (GtkPageRange, 1); | |
643 | range[0].start = fromPage-1; | |
644 | range[0].end = (toPage >= fromPage) ? toPage-1 : fromPage-1; | |
645 | gtk_print_settings_set_page_ranges (settings, range, 1); | |
646 | } | |
647 | ||
820ec9bb VZ |
648 | GtkPrintOperation * const printOp = native->GetPrintJob(); |
649 | ||
fa034c45 RR |
650 | // If the settings are OK, we restore it. |
651 | if (settings != NULL) | |
820ec9bb VZ |
652 | gtk_print_operation_set_print_settings (printOp, settings); |
653 | gtk_print_operation_set_default_page_setup (printOp, native->GetPageSetupFromSettings(settings)); | |
fa034c45 RR |
654 | |
655 | // Show the dialog if needed. | |
656 | GError* gError = NULL; | |
657 | if (GetShowDialog()) | |
820ec9bb | 658 | response = gtk_print_operation_run (printOp, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget) ), &gError); |
fa034c45 | 659 | else |
820ec9bb | 660 | response = gtk_print_operation_run (printOp, GTK_PRINT_OPERATION_ACTION_PRINT, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget)), &gError); |
fa034c45 RR |
661 | |
662 | // Does everything went well? | |
663 | if (response == GTK_PRINT_OPERATION_RESULT_CANCEL) | |
664 | { | |
665 | return wxID_CANCEL; | |
666 | } | |
667 | else if (response == GTK_PRINT_OPERATION_RESULT_ERROR) | |
668 | { | |
c96acfef | 669 | wxLogError(_("Error while printing: ") + wxString(gError ? gError->message : "???")); |
fa034c45 | 670 | g_error_free (gError); |
fa034c45 RR |
671 | return wxID_NO; // We use wxID_NO because there is no wxID_ERROR available |
672 | } | |
673 | ||
674 | // Now get the settings and save it. | |
820ec9bb | 675 | GtkPrintSettings* newSettings = gtk_print_operation_get_print_settings(printOp); |
fa034c45 RR |
676 | native->SetPrintConfig(newSettings); |
677 | data.ConvertFromNative(); | |
678 | ||
9e19da0f VZ |
679 | // Set PrintDialogData variables |
680 | m_printDialogData.SetPrintData(data); | |
681 | m_printDialogData.SetCollate(data.GetCollate()); | |
682 | m_printDialogData.SetNoCopies(data.GetNoCopies()); | |
683 | m_printDialogData.SetPrintToFile(data.GetPrinterName() == "Print to File"); | |
684 | ||
fa034c45 RR |
685 | // Same problem as a few lines before. |
686 | switch (gtk_print_settings_get_print_pages(newSettings)) | |
687 | { | |
688 | case GTK_PRINT_PAGES_CURRENT: | |
689 | m_printDialogData.SetSelection( true ); | |
690 | break; | |
fa034c45 | 691 | case GTK_PRINT_PAGES_RANGES: |
da249bc3 | 692 | {// wxWidgets doesn't support multiple ranges, so we can only save the first one even if the user wants to print others. |
fa034c45 RR |
693 | // 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 |
694 | // will hit "OK" button. However we can only save 1-3 in the print data. | |
695 | gint num_ranges = 0; | |
696 | GtkPageRange* range; | |
697 | range = gtk_print_settings_get_page_ranges (newSettings, &num_ranges); | |
da249bc3 RR |
698 | if (num_ranges >= 1) |
699 | { | |
a7060b8c PC |
700 | m_printDialogData.SetFromPage( range[0].start ); |
701 | m_printDialogData.SetToPage( range[0].end ); | |
da249bc3 RR |
702 | } |
703 | else { | |
704 | m_printDialogData.SetAllPages( true ); | |
705 | m_printDialogData.SetFromPage( 0 ); | |
706 | m_printDialogData.SetToPage( 9999 ); | |
707 | } | |
708 | break;} | |
709 | case GTK_PRINT_PAGES_ALL: | |
710 | default: | |
711 | m_printDialogData.SetAllPages( true ); | |
712 | m_printDialogData.SetFromPage( 0 ); | |
713 | m_printDialogData.SetToPage( 9999 ); | |
fa034c45 RR |
714 | break; |
715 | } | |
716 | ||
717 | return wxID_OK; | |
718 | } | |
719 | ||
720 | //---------------------------------------------------------------------------- | |
721 | // wxGtkPageSetupDialog | |
722 | //---------------------------------------------------------------------------- | |
723 | ||
724 | IMPLEMENT_CLASS(wxGtkPageSetupDialog, wxPageSetupDialogBase) | |
725 | ||
726 | wxGtkPageSetupDialog::wxGtkPageSetupDialog( wxWindow *parent, | |
727 | wxPageSetupDialogData* data ) | |
728 | { | |
729 | if (data) | |
730 | m_pageDialogData = *data; | |
731 | ||
732 | m_parent = parent; | |
733 | } | |
734 | ||
735 | wxGtkPageSetupDialog::~wxGtkPageSetupDialog() | |
736 | { | |
737 | } | |
738 | ||
739 | int wxGtkPageSetupDialog::ShowModal() | |
740 | { | |
741 | // Get the config. | |
742 | m_pageDialogData.GetPrintData().ConvertToNative(); | |
743 | wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
744 | GtkPrintSettings* nativeData = native->GetPrintConfig(); | |
745 | ||
746 | // We only need the pagesetup data which are part of the settings. | |
747 | GtkPageSetup* oldPageSetup = native->GetPageSetupFromSettings(nativeData); | |
748 | ||
749 | // If the user used a custom paper format the last time he printed, we have to restore it too. | |
750 | if (m_pageDialogData.GetPrintData().GetPaperId() == wxPAPER_NONE) | |
751 | { | |
752 | wxSize customPaperSize = m_pageDialogData.GetPaperSize(); | |
753 | if (customPaperSize.GetWidth() > 0 && customPaperSize.GetHeight() > 0) | |
754 | { | |
755 | wxString title = _("Custom size"); | |
756 | GtkPaperSize* customSize = gtk_paper_size_new_custom ("custom", title.mb_str(), (gdouble) customPaperSize.GetWidth(), (gdouble) customPaperSize.GetHeight(), GTK_UNIT_MM); | |
757 | gtk_page_setup_set_paper_size_and_default_margins (oldPageSetup, customSize); | |
758 | g_object_unref(customSize); | |
759 | } | |
760 | } | |
761 | ||
fa034c45 | 762 | |
9e19da0f VZ |
763 | // Set selected printer |
764 | gtk_print_settings_set(nativeData, "format-for-printer", | |
765 | gtk_print_settings_get_printer(nativeData)); | |
fa034c45 | 766 | |
9e19da0f VZ |
767 | // Create custom dialog |
768 | wxString title(GetTitle()); | |
769 | if ( title.empty() ) | |
770 | title = _("Page Setup"); | |
b37e255c VZ |
771 | GtkWidget * |
772 | dlg = gtk_page_setup_unix_dialog_new(title.utf8_str(), | |
773 | GTK_WINDOW(m_parent->m_widget)); | |
fa034c45 | 774 | |
9e19da0f VZ |
775 | gtk_page_setup_unix_dialog_set_print_settings( |
776 | GTK_PAGE_SETUP_UNIX_DIALOG(dlg), nativeData); | |
777 | gtk_page_setup_unix_dialog_set_page_setup( | |
778 | GTK_PAGE_SETUP_UNIX_DIALOG(dlg), oldPageSetup); | |
fa034c45 | 779 | |
9e19da0f VZ |
780 | int result = gtk_dialog_run(GTK_DIALOG(dlg)); |
781 | gtk_widget_hide(dlg); | |
fa034c45 | 782 | |
9e19da0f | 783 | switch ( result ) |
fa034c45 | 784 | { |
9e19da0f VZ |
785 | case GTK_RESPONSE_OK: |
786 | case GTK_RESPONSE_APPLY: | |
787 | { | |
788 | // Store Selected Printer Name | |
789 | gtk_print_settings_set_printer | |
790 | ( | |
791 | nativeData, | |
792 | gtk_print_settings_get(nativeData, "format-for-printer") | |
793 | ); | |
794 | ||
795 | wxGtkObject<GtkPageSetup> | |
796 | newPageSetup(gtk_page_setup_unix_dialog_get_page_setup( | |
797 | GTK_PAGE_SETUP_UNIX_DIALOG(dlg))); | |
798 | native->SetPageSetupToSettings(nativeData, newPageSetup); | |
799 | ||
800 | m_pageDialogData.GetPrintData().ConvertFromNative(); | |
801 | ||
802 | // Store custom paper format if any. | |
803 | if ( m_pageDialogData.GetPrintData().GetPaperId() == wxPAPER_NONE ) | |
804 | { | |
805 | gdouble ml,mr,mt,mb,pw,ph; | |
806 | ml = gtk_page_setup_get_left_margin (newPageSetup, GTK_UNIT_MM); | |
807 | mr = gtk_page_setup_get_right_margin (newPageSetup, GTK_UNIT_MM); | |
808 | mt = gtk_page_setup_get_top_margin (newPageSetup, GTK_UNIT_MM); | |
809 | mb = gtk_page_setup_get_bottom_margin (newPageSetup, GTK_UNIT_MM); | |
810 | ||
811 | pw = gtk_page_setup_get_paper_width (newPageSetup, GTK_UNIT_MM); | |
812 | ph = gtk_page_setup_get_paper_height (newPageSetup, GTK_UNIT_MM); | |
813 | ||
814 | m_pageDialogData.SetMarginTopLeft(wxPoint((int)(ml+0.5), | |
815 | (int)(mt+0.5))); | |
816 | m_pageDialogData.SetMarginBottomRight(wxPoint((int)(mr+0.5), | |
817 | (int)(mb+0.5))); | |
818 | ||
819 | m_pageDialogData.SetPaperSize(wxSize((int)(pw+0.5), | |
820 | (int)(ph+0.5))); | |
821 | } | |
822 | ||
823 | result = wxID_OK; | |
824 | } | |
825 | break; | |
826 | ||
827 | default: | |
828 | case GTK_RESPONSE_CANCEL: | |
829 | result = wxID_CANCEL; | |
830 | break; | |
fa034c45 RR |
831 | } |
832 | ||
9e19da0f VZ |
833 | gtk_widget_destroy(dlg); |
834 | ||
835 | return result; | |
fa034c45 RR |
836 | } |
837 | ||
838 | //---------------------------------------------------------------------------- | |
839 | // wxGtkPrinter | |
840 | //---------------------------------------------------------------------------- | |
841 | ||
842 | IMPLEMENT_CLASS(wxGtkPrinter, wxPrinterBase) | |
843 | ||
844 | wxGtkPrinter::wxGtkPrinter( wxPrintDialogData *data ) : | |
845 | wxPrinterBase( data ) | |
846 | { | |
847 | m_gpc = NULL; | |
848 | ||
849 | if (data) | |
850 | m_printDialogData = *data; | |
851 | } | |
852 | ||
853 | wxGtkPrinter::~wxGtkPrinter() | |
854 | { | |
855 | } | |
856 | ||
857 | bool wxGtkPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) | |
858 | { | |
859 | if (!printout) | |
860 | { | |
861 | sm_lastError = wxPRINTER_ERROR; | |
862 | return false; | |
863 | } | |
864 | ||
865 | // Let's correct the PageInfo just in case the app gives wrong values. | |
866 | int fromPage, toPage; | |
867 | int minPage, maxPage; | |
868 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
869 | m_printDialogData.SetAllPages(true); | |
870 | ||
871 | if (minPage < 1) minPage = 1; | |
872 | if (maxPage < 1) maxPage = 9999; | |
873 | if (maxPage < minPage) maxPage = minPage; | |
874 | ||
875 | m_printDialogData.SetMinPage(minPage); | |
876 | m_printDialogData.SetMaxPage(maxPage); | |
877 | if (fromPage != 0) | |
878 | { | |
879 | if (fromPage < minPage) fromPage = minPage; | |
880 | else if (fromPage > maxPage) fromPage = maxPage; | |
881 | m_printDialogData.SetFromPage(fromPage); | |
882 | } | |
883 | if (toPage != 0) | |
884 | { | |
885 | m_printDialogData.SetToPage(toPage); | |
886 | if (toPage > maxPage) toPage = maxPage; | |
887 | else if (toPage < minPage) toPage = minPage; | |
888 | } | |
889 | ||
890 | if (((minPage != fromPage) && fromPage != 0) || ((maxPage != toPage) && toPage != 0)) m_printDialogData.SetAllPages(false); | |
891 | ||
892 | ||
893 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); | |
894 | wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData(); | |
895 | ||
820ec9bb | 896 | GtkPrintOperation * const printOp = native->GetPrintJob(); |
fa034c45 | 897 | |
fa034c45 RR |
898 | wxPrinterToGtkData dataToSend; |
899 | dataToSend.printer = this; | |
900 | dataToSend.printout = printout; | |
901 | ||
90254df8 | 902 | // These Gtk signals are caught here. |
fa034c45 RR |
903 | g_signal_connect (printOp, "begin-print", G_CALLBACK (gtk_begin_print_callback), &dataToSend); |
904 | g_signal_connect (printOp, "draw-page", G_CALLBACK (gtk_draw_page_print_callback), &dataToSend); | |
905 | g_signal_connect (printOp, "end-print", G_CALLBACK (gtk_end_print_callback), printout); | |
fa034c45 | 906 | |
90254df8 RR |
907 | // This is used to setup the DC and |
908 | // show the dialog if desired | |
909 | wxGtkPrintDialog dialog( parent, &m_printDialogData ); | |
910 | dialog.SetPrintDC(m_dc); | |
911 | dialog.SetShowDialog(prompt); | |
fa034c45 | 912 | |
90254df8 RR |
913 | // doesn't necessarily show |
914 | int ret = dialog.ShowModal(); | |
915 | if (ret == wxID_CANCEL) | |
916 | { | |
917 | sm_lastError = wxPRINTER_CANCELLED; | |
918 | } | |
919 | if (ret == wxID_NO) | |
920 | { | |
921 | sm_lastError = wxPRINTER_ERROR; | |
922 | wxFAIL_MSG(_("The print dialog returned an error.")); | |
923 | } | |
fa034c45 | 924 | |
fa034c45 RR |
925 | return (sm_lastError == wxPRINTER_NO_ERROR); |
926 | } | |
927 | ||
928 | void wxGtkPrinter::BeginPrint(wxPrintout *printout, GtkPrintOperation *operation, GtkPrintContext *context) | |
929 | { | |
930 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); | |
931 | wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData(); | |
932 | ||
23abaeae VZ |
933 | // We need to update printdata with the new data from the dialog and we |
934 | // have to do this here because this method needs this new data and we | |
935 | // cannot update it earlier | |
936 | native->SetPrintConfig(gtk_print_operation_get_print_settings(operation)); | |
937 | printdata.ConvertFromNative(); | |
938 | ||
fa034c45 RR |
939 | SetPrintContext(context); |
940 | native->SetPrintContext( context ); | |
941 | ||
4f37154e | 942 | wxPrinterDC *printDC = new wxPrinterDC( printdata ); |
a9312950 | 943 | m_dc = printDC; |
fa034c45 RR |
944 | |
945 | if (!m_dc->IsOk()) | |
946 | { | |
947 | if (sm_lastError != wxPRINTER_CANCELLED) | |
948 | { | |
949 | sm_lastError = wxPRINTER_ERROR; | |
c8ddadff | 950 | wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used.")); |
fa034c45 RR |
951 | } |
952 | return; | |
953 | } | |
fa034c45 | 954 | |
40fcf546 | 955 | printout->SetPPIScreen(wxGetDisplayPPI()); |
a9312950 RR |
956 | printout->SetPPIPrinter( printDC->GetResolution(), |
957 | printDC->GetResolution() ); | |
fa034c45 RR |
958 | |
959 | printout->SetDC(m_dc); | |
960 | ||
961 | int w, h; | |
962 | m_dc->GetSize(&w, &h); | |
963 | printout->SetPageSizePixels((int)w, (int)h); | |
964 | printout->SetPaperRectPixels(wxRect(0, 0, w, h)); | |
965 | int mw, mh; | |
966 | m_dc->GetSizeMM(&mw, &mh); | |
967 | printout->SetPageSizeMM((int)mw, (int)mh); | |
968 | printout->OnPreparePrinting(); | |
969 | ||
970 | // Get some parameters from the printout, if defined. | |
971 | int fromPage, toPage; | |
972 | int minPage, maxPage; | |
973 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
974 | ||
975 | if (maxPage == 0) | |
976 | { | |
977 | sm_lastError = wxPRINTER_ERROR; | |
978 | wxFAIL_MSG(_("wxPrintout::GetPageInfo gives a null maxPage.")); | |
979 | return; | |
980 | } | |
981 | ||
982 | printout->OnBeginPrinting(); | |
983 | ||
984 | int numPages = 0; | |
985 | ||
986 | // If we're not previewing we need to calculate the number of pages to print. | |
987 | // If we're previewing, Gtk Print will render every pages without wondering about the page ranges the user may | |
988 | // have defined in the dialog. So the number of pages is the maximum available. | |
989 | if (!printout->IsPreview()) | |
990 | { | |
991 | GtkPrintSettings * settings = gtk_print_operation_get_print_settings (operation); | |
992 | switch (gtk_print_settings_get_print_pages(settings)) | |
993 | { | |
994 | case GTK_PRINT_PAGES_CURRENT: | |
995 | numPages = 1; | |
996 | break; | |
997 | case GTK_PRINT_PAGES_RANGES: | |
998 | {gint num_ranges = 0; | |
999 | GtkPageRange* range; | |
1000 | int i; | |
1001 | range = gtk_print_settings_get_page_ranges (settings, &num_ranges); | |
1002 | for (i=0; i<num_ranges; i++) | |
1003 | { | |
1004 | if (range[i].end < range[i].start) range[i].end = range[i].start; | |
1005 | if (range[i].start < minPage-1) range[i].start = minPage-1; | |
1006 | if (range[i].end > maxPage-1) range[i].end = maxPage-1; | |
1007 | if (range[i].start > maxPage-1) range[i].start = maxPage-1; | |
1008 | numPages += range[i].end - range[i].start + 1; | |
1009 | } | |
1010 | gtk_print_settings_set_page_ranges (settings, range, 1); | |
1011 | break;} | |
1012 | case GTK_PRINT_PAGES_ALL: | |
1013 | default: | |
1014 | numPages = maxPage - minPage + 1; | |
1015 | break; | |
1016 | } | |
1017 | } | |
1018 | else numPages = maxPage - minPage + 1; | |
1019 | ||
1020 | gtk_print_operation_set_n_pages(operation, numPages); | |
1021 | } | |
1022 | ||
e0d1fd7f VZ |
1023 | void wxGtkPrinter::DrawPage(wxPrintout *printout, |
1024 | GtkPrintOperation *operation, | |
1025 | GtkPrintContext * WXUNUSED(context), | |
1026 | int page_nr) | |
fa034c45 RR |
1027 | { |
1028 | int fromPage, toPage, minPage, maxPage, startPage, endPage; | |
1029 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
1030 | ||
1031 | int numPageToDraw = page_nr + minPage; | |
1032 | if (numPageToDraw < minPage) numPageToDraw = minPage; | |
1033 | if (numPageToDraw > maxPage) numPageToDraw = maxPage; | |
1034 | ||
1035 | GtkPrintSettings * settings = gtk_print_operation_get_print_settings (operation); | |
1036 | switch (gtk_print_settings_get_print_pages(settings)) | |
1037 | { | |
1038 | case GTK_PRINT_PAGES_CURRENT: | |
1039 | g_object_get_property((GObject*) operation, (const gchar *) "current-page", (GValue*) &startPage); | |
1040 | g_object_get_property((GObject*) operation, (const gchar *) "current-page", (GValue*) &endPage); | |
1041 | break; | |
1042 | case GTK_PRINT_PAGES_RANGES: | |
1043 | {gint num_ranges = 0; | |
1044 | GtkPageRange* range; | |
1045 | range = gtk_print_settings_get_page_ranges (settings, &num_ranges); | |
1046 | // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint. | |
da249bc3 RR |
1047 | if (num_ranges >= 1) |
1048 | { | |
a7060b8c PC |
1049 | startPage = range[0].start + 1; |
1050 | endPage = range[0].end + 1; | |
da249bc3 RR |
1051 | } |
1052 | else { | |
1053 | startPage = minPage; | |
1054 | endPage = maxPage; | |
1055 | } | |
fa034c45 RR |
1056 | break;} |
1057 | case GTK_PRINT_PAGES_ALL: | |
1058 | default: | |
1059 | startPage = minPage; | |
1060 | endPage = maxPage; | |
1061 | break; | |
1062 | } | |
1063 | ||
1064 | if(numPageToDraw == startPage) | |
1065 | { | |
1066 | if (!printout->OnBeginDocument(startPage, endPage)) | |
1067 | { | |
1068 | wxLogError(_("Could not start printing.")); | |
1069 | sm_lastError = wxPRINTER_ERROR; | |
1070 | } | |
1071 | } | |
1072 | ||
1073 | // The app can render the page numPageToDraw. | |
1074 | if (printout->HasPage(numPageToDraw)) | |
1075 | { | |
1076 | m_dc->StartPage(); | |
1077 | printout->OnPrintPage(numPageToDraw); | |
1078 | m_dc->EndPage(); | |
1079 | } | |
1080 | ||
1081 | ||
1082 | if(numPageToDraw == endPage) | |
1083 | { | |
1084 | printout->OnEndDocument(); | |
1085 | } | |
1086 | } | |
1087 | ||
1088 | wxDC* wxGtkPrinter::PrintDialog( wxWindow *parent ) | |
1089 | { | |
1090 | wxGtkPrintDialog dialog( parent, &m_printDialogData ); | |
fa034c45 RR |
1091 | |
1092 | dialog.SetPrintDC(m_dc); | |
90254df8 | 1093 | dialog.SetShowDialog(true); |
fa034c45 | 1094 | |
90254df8 | 1095 | int ret = dialog.ShowModal(); |
fa034c45 RR |
1096 | |
1097 | if (ret == wxID_CANCEL) | |
1098 | { | |
1099 | sm_lastError = wxPRINTER_CANCELLED; | |
1100 | return NULL; | |
1101 | } | |
1102 | if (ret == wxID_NO) | |
1103 | { | |
1104 | sm_lastError = wxPRINTER_ERROR; | |
1105 | wxFAIL_MSG(_("The print dialog returned an error.")); | |
1106 | return NULL; | |
1107 | } | |
1108 | ||
1109 | m_printDialogData = dialog.GetPrintDialogData(); | |
6d52ca53 | 1110 | |
4f37154e | 1111 | return new wxPrinterDC( m_printDialogData.GetPrintData() ); |
fa034c45 RR |
1112 | } |
1113 | ||
e0d1fd7f | 1114 | bool wxGtkPrinter::Setup( wxWindow * WXUNUSED(parent) ) |
fa034c45 RR |
1115 | { |
1116 | // Obsolete, for backward compatibility. | |
1117 | return false; | |
1118 | } | |
1119 | ||
1120 | //----------------------------------------------------------------------------- | |
c8ddadff | 1121 | // wxGtkPrinterDC |
fa034c45 RR |
1122 | //----------------------------------------------------------------------------- |
1123 | ||
eaeb9985 RR |
1124 | #define wxCAIRO_SCALE 1 |
1125 | ||
1126 | #if wxCAIRO_SCALE | |
1127 | ||
1128 | #define XLOG2DEV(x) LogicalToDeviceX(x) | |
1129 | #define XLOG2DEVREL(x) LogicalToDeviceXRel(x) | |
1130 | #define YLOG2DEV(x) LogicalToDeviceY(x) | |
1131 | #define YLOG2DEVREL(x) LogicalToDeviceYRel(x) | |
1132 | ||
1133 | #else | |
1134 | ||
a9312950 RR |
1135 | #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS) |
1136 | #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS) | |
1137 | #define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS) | |
1138 | #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS) | |
fa034c45 | 1139 | |
eaeb9985 | 1140 | #endif |
fa034c45 | 1141 | |
888dde65 | 1142 | IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl, wxDCImpl) |
4f37154e | 1143 | |
115be92b VZ |
1144 | wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC *owner, const wxPrintData& data) |
1145 | : wxDCImpl( owner ) | |
fa034c45 RR |
1146 | { |
1147 | m_printData = data; | |
1148 | ||
1149 | wxGtkPrintNativeData *native = | |
1150 | (wxGtkPrintNativeData*) m_printData.GetNativeData(); | |
1151 | ||
1152 | m_gpc = native->GetPrintContext(); | |
1153 | ||
90254df8 | 1154 | // Match print quality to resolution (high = 1200dpi) |
a9312950 | 1155 | m_resolution = m_printData.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc ); |
a7060b8c | 1156 | if (m_resolution < 0) |
a9312950 RR |
1157 | m_resolution = (1 << (m_resolution+4)) *150; |
1158 | ||
fa034c45 RR |
1159 | m_context = gtk_print_context_create_pango_context( m_gpc ); |
1160 | m_layout = gtk_print_context_create_pango_layout ( m_gpc ); | |
1161 | m_fontdesc = pango_font_description_from_string( "Sans 12" ); | |
1162 | ||
1163 | m_cairo = gtk_print_context_get_cairo_context ( m_gpc ); | |
1164 | ||
eaeb9985 RR |
1165 | #if wxCAIRO_SCALE |
1166 | m_PS2DEV = 1.0; | |
1167 | m_DEV2PS = 1.0; | |
6d52ca53 | 1168 | |
f7b8e3d6 | 1169 | cairo_scale( m_cairo, 72.0 / (double)m_resolution, 72.0 / (double)m_resolution ); |
eaeb9985 RR |
1170 | #else |
1171 | m_PS2DEV = (double)m_resolution / 72.0; | |
1172 | m_DEV2PS = 72.0 / (double)m_resolution; | |
1173 | #endif | |
1174 | ||
fa034c45 RR |
1175 | m_currentRed = 0; |
1176 | m_currentBlue = 0; | |
1177 | m_currentGreen = 0; | |
1178 | ||
90254df8 | 1179 | m_signX = 1; // default x-axis left to right. |
fa034c45 | 1180 | m_signY = 1; // default y-axis bottom up -> top down. |
da249bc3 | 1181 | |
e0d1fd7f | 1182 | // By default the origin of the Cairo context is in the upper left |
90254df8 RR |
1183 | // corner of the printable area. We need to translate it so that it |
1184 | // is in the upper left corner of the paper (without margins) | |
da249bc3 RR |
1185 | GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc ); |
1186 | gdouble ml, mt; | |
1187 | ml = gtk_page_setup_get_left_margin (setup, GTK_UNIT_POINTS); | |
1188 | mt = gtk_page_setup_get_top_margin (setup, GTK_UNIT_POINTS); | |
f7b8e3d6 | 1189 | cairo_translate(m_cairo, -ml, -mt); |
fa034c45 RR |
1190 | } |
1191 | ||
888dde65 | 1192 | wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl() |
fa034c45 RR |
1193 | { |
1194 | g_object_unref(m_context); | |
1195 | g_object_unref(m_layout); | |
1196 | } | |
1197 | ||
888dde65 | 1198 | bool wxGtkPrinterDCImpl::IsOk() const |
fa034c45 | 1199 | { |
e0d1fd7f | 1200 | return m_gpc != NULL; |
fa034c45 RR |
1201 | } |
1202 | ||
0b822969 | 1203 | void* wxGtkPrinterDCImpl::GetCairoContext() const |
2b44ffc0 | 1204 | { |
f7b8e3d6 | 1205 | return (void*) cairo_reference( m_cairo ); |
2b44ffc0 | 1206 | } |
2b44ffc0 | 1207 | |
888dde65 | 1208 | bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1), |
e0d1fd7f VZ |
1209 | wxCoord WXUNUSED(y1), |
1210 | const wxColour& WXUNUSED(col), | |
89efaf2b | 1211 | wxFloodFillStyle WXUNUSED(style)) |
fa034c45 | 1212 | { |
e0d1fd7f VZ |
1213 | // We can't access the given coord as a Cairo context is scalable, ie a |
1214 | // coord doesn't mean anything in this context. | |
fa034c45 RR |
1215 | wxFAIL_MSG(_("not implemented")); |
1216 | return false; | |
1217 | } | |
1218 | ||
888dde65 | 1219 | void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter) |
fa034c45 RR |
1220 | { |
1221 | wxCoord xC = circleCenter.x; | |
1222 | wxCoord yC = circleCenter.y; | |
1223 | wxCoord xR = rect.x; | |
1224 | wxCoord yR = rect.y; | |
1225 | wxCoord w = rect.width; | |
1226 | wxCoord h = rect.height; | |
1227 | ||
d31d30d7 VZ |
1228 | const double r2 = (w/2)*(w/2)+(h/2)*(h/2); |
1229 | double radius = sqrt(r2); | |
fa034c45 RR |
1230 | |
1231 | unsigned char redI = initialColour.Red(); | |
1232 | unsigned char blueI = initialColour.Blue(); | |
1233 | unsigned char greenI = initialColour.Green(); | |
1234 | unsigned char alphaI = initialColour.Alpha(); | |
1235 | unsigned char redD = destColour.Red(); | |
1236 | unsigned char blueD = destColour.Blue(); | |
1237 | unsigned char greenD = destColour.Green(); | |
1238 | unsigned char alphaD = destColour.Alpha(); | |
1239 | ||
1240 | double redIPS = (double)(redI) / 255.0; | |
1241 | double blueIPS = (double)(blueI) / 255.0; | |
1242 | double greenIPS = (double)(greenI) / 255.0; | |
1243 | double alphaIPS = (double)(alphaI) / 255.0; | |
1244 | double redDPS = (double)(redD) / 255.0; | |
1245 | double blueDPS = (double)(blueD) / 255.0; | |
1246 | double greenDPS = (double)(greenD) / 255.0; | |
1247 | double alphaDPS = (double)(alphaD) / 255.0; | |
1248 | ||
1249 | // Create a pattern with the gradient. | |
1250 | cairo_pattern_t* gradient; | |
f7b8e3d6 VS |
1251 | gradient = cairo_pattern_create_radial (XLOG2DEV(xC+xR), YLOG2DEV(yC+yR), 0, XLOG2DEV(xC+xR), YLOG2DEV(yC+yR), radius * m_DEV2PS ); |
1252 | cairo_pattern_add_color_stop_rgba (gradient, 0.0, redIPS, greenIPS, blueIPS, alphaIPS); | |
1253 | cairo_pattern_add_color_stop_rgba (gradient, 1.0, redDPS, greenDPS, blueDPS, alphaDPS); | |
fa034c45 RR |
1254 | |
1255 | // Fill the rectangle with this pattern. | |
f7b8e3d6 VS |
1256 | cairo_set_source(m_cairo, gradient); |
1257 | cairo_rectangle (m_cairo, XLOG2DEV(xR), YLOG2DEV(yR), XLOG2DEVREL(w), YLOG2DEVREL(h) ); | |
1258 | cairo_fill(m_cairo); | |
fa034c45 | 1259 | |
f7b8e3d6 | 1260 | cairo_pattern_destroy(gradient); |
fa034c45 RR |
1261 | |
1262 | CalcBoundingBox(xR, yR); | |
1263 | CalcBoundingBox(xR+w, yR+h); | |
1264 | } | |
1265 | ||
888dde65 | 1266 | void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, wxDirection nDirection) |
fa034c45 RR |
1267 | { |
1268 | wxCoord x = rect.x; | |
1269 | wxCoord y = rect.y; | |
1270 | wxCoord w = rect.width; | |
1271 | wxCoord h = rect.height; | |
1272 | ||
1273 | unsigned char redI = initialColour.Red(); | |
1274 | unsigned char blueI = initialColour.Blue(); | |
1275 | unsigned char greenI = initialColour.Green(); | |
1276 | unsigned char alphaI = initialColour.Alpha(); | |
1277 | unsigned char redD = destColour.Red(); | |
1278 | unsigned char blueD = destColour.Blue(); | |
1279 | unsigned char greenD = destColour.Green(); | |
1280 | unsigned char alphaD = destColour.Alpha(); | |
1281 | ||
1282 | double redIPS = (double)(redI) / 255.0; | |
1283 | double blueIPS = (double)(blueI) / 255.0; | |
1284 | double greenIPS = (double)(greenI) / 255.0; | |
1285 | double alphaIPS = (double)(alphaI) / 255.0; | |
1286 | double redDPS = (double)(redD) / 255.0; | |
1287 | double blueDPS = (double)(blueD) / 255.0; | |
1288 | double greenDPS = (double)(greenD) / 255.0; | |
1289 | double alphaDPS = (double)(alphaD) / 255.0; | |
1290 | ||
1291 | // Create a pattern with the gradient. | |
1292 | cairo_pattern_t* gradient; | |
f7b8e3d6 | 1293 | gradient = cairo_pattern_create_linear (XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x+w), YLOG2DEV(y)); |
fa034c45 RR |
1294 | |
1295 | if (nDirection == wxWEST) | |
1296 | { | |
f7b8e3d6 VS |
1297 | cairo_pattern_add_color_stop_rgba (gradient, 0.0, redDPS, greenDPS, blueDPS, alphaDPS); |
1298 | cairo_pattern_add_color_stop_rgba (gradient, 1.0, redIPS, greenIPS, blueIPS, alphaIPS); | |
fa034c45 RR |
1299 | } |
1300 | else { | |
f7b8e3d6 VS |
1301 | cairo_pattern_add_color_stop_rgba (gradient, 0.0, redIPS, greenIPS, blueIPS, alphaIPS); |
1302 | cairo_pattern_add_color_stop_rgba (gradient, 1.0, redDPS, greenDPS, blueDPS, alphaDPS); | |
fa034c45 RR |
1303 | } |
1304 | ||
1305 | // Fill the rectangle with this pattern. | |
f7b8e3d6 VS |
1306 | cairo_set_source(m_cairo, gradient); |
1307 | cairo_rectangle (m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(w), YLOG2DEVREL(h) ); | |
1308 | cairo_fill(m_cairo); | |
fa034c45 | 1309 | |
f7b8e3d6 | 1310 | cairo_pattern_destroy(gradient); |
fa034c45 RR |
1311 | |
1312 | CalcBoundingBox(x, y); | |
1313 | CalcBoundingBox(x+w, y+h); | |
1314 | } | |
1315 | ||
888dde65 | 1316 | bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord WXUNUSED(x1), |
e0d1fd7f VZ |
1317 | wxCoord WXUNUSED(y1), |
1318 | wxColour * WXUNUSED(col)) const | |
fa034c45 | 1319 | { |
fa034c45 RR |
1320 | wxFAIL_MSG(_("not implemented")); |
1321 | return false; | |
1322 | } | |
1323 | ||
888dde65 | 1324 | void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) |
fa034c45 | 1325 | { |
e6777e65 VZ |
1326 | if ( m_pen.IsTransparent() ) |
1327 | return; | |
fa034c45 RR |
1328 | |
1329 | SetPen( m_pen ); | |
f7b8e3d6 VS |
1330 | cairo_move_to ( m_cairo, XLOG2DEV(x1), YLOG2DEV(y1) ); |
1331 | cairo_line_to ( m_cairo, XLOG2DEV(x2), YLOG2DEV(y2) ); | |
1332 | cairo_stroke ( m_cairo ); | |
fa034c45 RR |
1333 | |
1334 | CalcBoundingBox( x1, y1 ); | |
1335 | CalcBoundingBox( x2, y2 ); | |
1336 | } | |
1337 | ||
888dde65 | 1338 | void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x, wxCoord y) |
fa034c45 | 1339 | { |
a9312950 RR |
1340 | int w, h; |
1341 | DoGetSize(&w, &h); | |
fa034c45 RR |
1342 | |
1343 | SetPen(m_pen); | |
1344 | ||
f7b8e3d6 VS |
1345 | cairo_move_to (m_cairo, XLOG2DEV(x), 0); |
1346 | cairo_line_to (m_cairo, XLOG2DEV(x), YLOG2DEVREL(h)); | |
1347 | cairo_move_to (m_cairo, 0, YLOG2DEV(y)); | |
1348 | cairo_line_to (m_cairo, XLOG2DEVREL(w), YLOG2DEV(y)); | |
fa034c45 | 1349 | |
f7b8e3d6 | 1350 | cairo_stroke (m_cairo); |
fa034c45 | 1351 | CalcBoundingBox( 0, 0 ); |
a9312950 | 1352 | CalcBoundingBox( w, h ); |
fa034c45 RR |
1353 | } |
1354 | ||
888dde65 | 1355 | void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) |
fa034c45 RR |
1356 | { |
1357 | double dx = x1 - xc; | |
1358 | double dy = y1 - yc; | |
1359 | double radius = sqrt((double)(dx*dx+dy*dy)); | |
1360 | ||
1361 | double alpha1, alpha2; | |
1362 | if (x1 == x2 && y1 == y2) | |
1363 | { | |
1364 | alpha1 = 0.0; | |
1365 | alpha2 = 360.0; | |
1366 | } | |
1367 | else | |
1368 | if (radius == 0.0) | |
1369 | { | |
1370 | alpha1 = alpha2 = 0.0; | |
1371 | } | |
1372 | else | |
1373 | { | |
1374 | alpha1 = (x1 - xc == 0) ? | |
1375 | (y1 - yc < 0) ? 90.0 : -90.0 : | |
1376 | atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; | |
1377 | alpha2 = (x2 - xc == 0) ? | |
1378 | (y2 - yc < 0) ? 90.0 : -90.0 : | |
1379 | atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; | |
1380 | ||
1381 | while (alpha1 <= 0) alpha1 += 360; | |
1382 | while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between. | |
1383 | while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree. | |
1384 | while (alpha2 > 360) alpha2 -= 360; | |
1385 | } | |
1386 | ||
1387 | alpha1 *= DEG2RAD; | |
1388 | alpha2 *= DEG2RAD; | |
1389 | ||
f7b8e3d6 | 1390 | cairo_new_path(m_cairo); |
da249bc3 | 1391 | |
f7b8e3d6 VS |
1392 | cairo_arc_negative ( m_cairo, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2); |
1393 | cairo_line_to(m_cairo, XLOG2DEV(xc), YLOG2DEV(yc)); | |
1394 | cairo_close_path (m_cairo); | |
fa034c45 RR |
1395 | |
1396 | SetBrush( m_brush ); | |
f7b8e3d6 | 1397 | cairo_fill_preserve( m_cairo ); |
fa034c45 RR |
1398 | |
1399 | SetPen (m_pen); | |
f7b8e3d6 | 1400 | cairo_stroke( m_cairo ); |
fa034c45 RR |
1401 | |
1402 | CalcBoundingBox (x1, y1); | |
1403 | CalcBoundingBox (xc, yc); | |
1404 | CalcBoundingBox (x2, y2); | |
1405 | } | |
1406 | ||
888dde65 | 1407 | void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) |
fa034c45 | 1408 | { |
f7b8e3d6 | 1409 | cairo_save( m_cairo ); |
fa034c45 | 1410 | |
f7b8e3d6 | 1411 | cairo_new_path(m_cairo); |
da249bc3 | 1412 | |
f7b8e3d6 | 1413 | cairo_translate( m_cairo, XLOG2DEV((wxCoord) (x + w / 2.)), XLOG2DEV((wxCoord) (y + h / 2.)) ); |
a9312950 | 1414 | double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w); |
f7b8e3d6 | 1415 | cairo_scale( m_cairo, 1.0, scale ); |
fa034c45 | 1416 | |
f7b8e3d6 | 1417 | cairo_arc_negative ( m_cairo, 0, 0, XLOG2DEVREL(w/2), -sa*DEG2RAD, -ea*DEG2RAD); |
fa034c45 RR |
1418 | |
1419 | SetPen (m_pen); | |
f7b8e3d6 | 1420 | cairo_stroke_preserve( m_cairo ); |
fa034c45 | 1421 | |
f7b8e3d6 | 1422 | cairo_line_to(m_cairo, 0,0); |
fa034c45 RR |
1423 | |
1424 | SetBrush( m_brush ); | |
f7b8e3d6 | 1425 | cairo_fill( m_cairo ); |
fa034c45 | 1426 | |
f7b8e3d6 | 1427 | cairo_restore( m_cairo ); |
fa034c45 RR |
1428 | |
1429 | CalcBoundingBox( x, y); | |
1430 | CalcBoundingBox( x+w, y+h ); | |
1431 | } | |
1432 | ||
888dde65 | 1433 | void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x, wxCoord y) |
fa034c45 | 1434 | { |
e6777e65 VZ |
1435 | if ( m_pen.IsTransparent() ) |
1436 | return; | |
fa034c45 RR |
1437 | |
1438 | SetPen( m_pen ); | |
1439 | ||
f7b8e3d6 VS |
1440 | cairo_move_to ( m_cairo, XLOG2DEV(x), YLOG2DEV(y) ); |
1441 | cairo_line_to ( m_cairo, XLOG2DEV(x), YLOG2DEV(y) ); | |
1442 | cairo_stroke ( m_cairo ); | |
fa034c45 RR |
1443 | |
1444 | CalcBoundingBox( x, y ); | |
1445 | } | |
1446 | ||
888dde65 | 1447 | void wxGtkPrinterDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) |
fa034c45 | 1448 | { |
e6777e65 VZ |
1449 | if ( m_pen.IsTransparent() ) |
1450 | return; | |
1451 | ||
fa034c45 RR |
1452 | |
1453 | if (n <= 0) return; | |
1454 | ||
1455 | SetPen (m_pen); | |
1456 | ||
1457 | int i; | |
1458 | for ( i =0; i<n ; i++ ) | |
1459 | CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset); | |
1460 | ||
f7b8e3d6 | 1461 | cairo_move_to ( m_cairo, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) ); |
fa034c45 RR |
1462 | |
1463 | for (i = 1; i < n; i++) | |
f7b8e3d6 | 1464 | cairo_line_to ( m_cairo, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) ); |
fa034c45 | 1465 | |
f7b8e3d6 | 1466 | cairo_stroke ( m_cairo); |
fa034c45 RR |
1467 | } |
1468 | ||
03647350 VZ |
1469 | void wxGtkPrinterDCImpl::DoDrawPolygon(int n, wxPoint points[], |
1470 | wxCoord xoffset, wxCoord yoffset, | |
89efaf2b | 1471 | wxPolygonFillMode fillStyle) |
fa034c45 RR |
1472 | { |
1473 | if (n==0) return; | |
1474 | ||
f7b8e3d6 | 1475 | cairo_save(m_cairo); |
fa034c45 | 1476 | if (fillStyle == wxWINDING_RULE) |
f7b8e3d6 | 1477 | cairo_set_fill_rule( m_cairo, CAIRO_FILL_RULE_WINDING); |
fa034c45 | 1478 | else |
f7b8e3d6 | 1479 | cairo_set_fill_rule( m_cairo, CAIRO_FILL_RULE_EVEN_ODD); |
fa034c45 RR |
1480 | |
1481 | int x = points[0].x + xoffset; | |
1482 | int y = points[0].y + yoffset; | |
f7b8e3d6 VS |
1483 | cairo_new_path(m_cairo); |
1484 | cairo_move_to( m_cairo, XLOG2DEV(x), YLOG2DEV(y) ); | |
fa034c45 RR |
1485 | int i; |
1486 | for (i = 1; i < n; i++) | |
1487 | { | |
1488 | int x = points[i].x + xoffset; | |
1489 | int y = points[i].y + yoffset; | |
f7b8e3d6 | 1490 | cairo_line_to( m_cairo, XLOG2DEV(x), YLOG2DEV(y) ); |
fa034c45 | 1491 | } |
f7b8e3d6 | 1492 | cairo_close_path(m_cairo); |
fa034c45 RR |
1493 | |
1494 | SetBrush( m_brush ); | |
f7b8e3d6 | 1495 | cairo_fill_preserve( m_cairo ); |
fa034c45 RR |
1496 | |
1497 | SetPen (m_pen); | |
f7b8e3d6 | 1498 | cairo_stroke( m_cairo ); |
fa034c45 RR |
1499 | |
1500 | CalcBoundingBox( x, y ); | |
1501 | ||
f7b8e3d6 | 1502 | cairo_restore(m_cairo); |
fa034c45 RR |
1503 | } |
1504 | ||
89efaf2b | 1505 | void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n, int count[], wxPoint points[], |
03647350 | 1506 | wxCoord xoffset, wxCoord yoffset, |
89efaf2b | 1507 | wxPolygonFillMode fillStyle) |
fa034c45 | 1508 | { |
888dde65 | 1509 | wxDCImpl::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle ); |
fa034c45 RR |
1510 | } |
1511 | ||
888dde65 | 1512 | void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
fa034c45 | 1513 | { |
728ddc45 RR |
1514 | width--; |
1515 | height--; | |
1516 | ||
f7b8e3d6 VS |
1517 | cairo_new_path(m_cairo); |
1518 | cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height)); | |
fa034c45 RR |
1519 | |
1520 | SetBrush( m_brush ); | |
f7b8e3d6 | 1521 | cairo_fill_preserve( m_cairo ); |
fa034c45 RR |
1522 | |
1523 | SetPen (m_pen); | |
f7b8e3d6 | 1524 | cairo_stroke( m_cairo ); |
fa034c45 RR |
1525 | |
1526 | CalcBoundingBox( x, y ); | |
1527 | CalcBoundingBox( x + width, y + height ); | |
1528 | } | |
1529 | ||
888dde65 | 1530 | void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) |
fa034c45 | 1531 | { |
728ddc45 RR |
1532 | width--; |
1533 | height--; | |
1534 | ||
fa034c45 RR |
1535 | if (radius < 0.0) radius = - radius * ((width < height) ? width : height); |
1536 | ||
1537 | wxCoord dd = 2 * (wxCoord) radius; | |
1538 | if (dd > width) dd = width; | |
1539 | if (dd > height) dd = height; | |
1540 | radius = dd / 2; | |
1541 | ||
1542 | wxCoord rad = (wxCoord) radius; | |
1543 | ||
f7b8e3d6 VS |
1544 | cairo_new_path(m_cairo); |
1545 | cairo_move_to(m_cairo,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1546 | cairo_curve_to(m_cairo, | |
5cdcb787 RR |
1547 | XLOG2DEV(x + rad),YLOG2DEV(y), |
1548 | XLOG2DEV(x),YLOG2DEV(y), | |
1549 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
f7b8e3d6 VS |
1550 | cairo_line_to(m_cairo,XLOG2DEV(x),YLOG2DEV(y + height - rad)); |
1551 | cairo_curve_to(m_cairo, | |
5cdcb787 RR |
1552 | XLOG2DEV(x),YLOG2DEV(y + height - rad), |
1553 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1554 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
f7b8e3d6 VS |
1555 | cairo_line_to(m_cairo,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); |
1556 | cairo_curve_to(m_cairo, | |
5cdcb787 RR |
1557 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), |
1558 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1559 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
f7b8e3d6 VS |
1560 | cairo_line_to(m_cairo,XLOG2DEV(x + width),YLOG2DEV(y + rad)); |
1561 | cairo_curve_to(m_cairo, | |
5cdcb787 RR |
1562 | XLOG2DEV(x + width),YLOG2DEV(y + rad), |
1563 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1564 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
f7b8e3d6 VS |
1565 | cairo_line_to(m_cairo,XLOG2DEV(x + rad),YLOG2DEV(y)); |
1566 | cairo_close_path(m_cairo); | |
fa034c45 RR |
1567 | |
1568 | SetBrush(m_brush); | |
f7b8e3d6 | 1569 | cairo_fill_preserve(m_cairo); |
fa034c45 RR |
1570 | |
1571 | SetPen(m_pen); | |
f7b8e3d6 | 1572 | cairo_stroke(m_cairo); |
fa034c45 RR |
1573 | |
1574 | CalcBoundingBox(x,y); | |
1575 | CalcBoundingBox(x+width,y+height); | |
1576 | } | |
1577 | ||
888dde65 | 1578 | void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
fa034c45 | 1579 | { |
728ddc45 RR |
1580 | width--; |
1581 | height--; | |
1582 | ||
f7b8e3d6 | 1583 | cairo_save (m_cairo); |
fa034c45 | 1584 | |
f7b8e3d6 | 1585 | cairo_new_path(m_cairo); |
da249bc3 | 1586 | |
f7b8e3d6 VS |
1587 | cairo_translate (m_cairo, XLOG2DEV((wxCoord) (x + width / 2.)), YLOG2DEV((wxCoord) (y + height / 2.))); |
1588 | cairo_scale(m_cairo, 1, (double)YLOG2DEVREL(height)/(double)XLOG2DEVREL(width)); | |
1589 | cairo_arc ( m_cairo, 0, 0, XLOG2DEVREL(width/2), 0, 2 * M_PI); | |
fa034c45 RR |
1590 | |
1591 | SetBrush( m_brush ); | |
f7b8e3d6 | 1592 | cairo_fill_preserve( m_cairo ); |
fa034c45 RR |
1593 | |
1594 | SetPen (m_pen); | |
f7b8e3d6 | 1595 | cairo_stroke( m_cairo ); |
fa034c45 RR |
1596 | |
1597 | CalcBoundingBox( x, y ); | |
1598 | CalcBoundingBox( x + width, y + height ); | |
1599 | ||
f7b8e3d6 | 1600 | cairo_restore (m_cairo); |
fa034c45 RR |
1601 | } |
1602 | ||
1603 | #if wxUSE_SPLINES | |
888dde65 | 1604 | void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList *points) |
fa034c45 RR |
1605 | { |
1606 | SetPen (m_pen); | |
1607 | ||
1608 | double c, d, x1, y1, x2, y2, x3, y3; | |
1609 | wxPoint *p, *q; | |
1610 | ||
b0d7707b RR |
1611 | wxPointList::compatibility_iterator node = points->GetFirst(); |
1612 | p = node->GetData(); | |
fa034c45 RR |
1613 | x1 = p->x; |
1614 | y1 = p->y; | |
1615 | ||
1616 | node = node->GetNext(); | |
b0d7707b | 1617 | p = node->GetData(); |
fa034c45 RR |
1618 | c = p->x; |
1619 | d = p->y; | |
1620 | x3 = | |
1621 | (double)(x1 + c) / 2; | |
1622 | y3 = | |
1623 | (double)(y1 + d) / 2; | |
1624 | ||
f7b8e3d6 VS |
1625 | cairo_new_path( m_cairo ); |
1626 | cairo_move_to( m_cairo, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) ); | |
1627 | cairo_line_to( m_cairo, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
fa034c45 RR |
1628 | |
1629 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1630 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1631 | ||
1632 | node = node->GetNext(); | |
1633 | while (node) | |
1634 | { | |
b0d7707b | 1635 | q = node->GetData(); |
fa034c45 RR |
1636 | |
1637 | x1 = x3; | |
1638 | y1 = y3; | |
1639 | x2 = c; | |
1640 | y2 = d; | |
1641 | c = q->x; | |
1642 | d = q->y; | |
1643 | x3 = (double)(x2 + c) / 2; | |
1644 | y3 = (double)(y2 + d) / 2; | |
1645 | ||
f7b8e3d6 | 1646 | cairo_curve_to(m_cairo, |
5cdcb787 RR |
1647 | XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1), |
1648 | XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2), | |
1649 | XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
fa034c45 RR |
1650 | |
1651 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1652 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1653 | ||
1654 | node = node->GetNext(); | |
1655 | } | |
1656 | ||
f7b8e3d6 | 1657 | cairo_line_to ( m_cairo, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) ); |
fa034c45 | 1658 | |
f7b8e3d6 | 1659 | cairo_stroke( m_cairo ); |
fa034c45 RR |
1660 | } |
1661 | #endif // wxUSE_SPLINES | |
1662 | ||
888dde65 | 1663 | bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, |
e0d1fd7f VZ |
1664 | wxCoord width, wxCoord height, |
1665 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
89efaf2b | 1666 | wxRasterOperationMode rop, bool useMask, |
e0d1fd7f VZ |
1667 | wxCoord WXUNUSED_UNLESS_DEBUG(xsrcMask), |
1668 | wxCoord WXUNUSED_UNLESS_DEBUG(ysrcMask)) | |
fa034c45 | 1669 | { |
e0d1fd7f VZ |
1670 | wxASSERT_MSG( xsrcMask == wxDefaultCoord && ysrcMask == wxDefaultCoord, |
1671 | wxT("mask coordinates are not supported") ); | |
1672 | ||
fa034c45 RR |
1673 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); |
1674 | ||
1675 | // Blit into a bitmap. | |
1676 | wxBitmap bitmap( width, height ); | |
1677 | wxMemoryDC memDC; | |
1678 | memDC.SelectObject(bitmap); | |
1679 | memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); | |
1680 | memDC.SelectObject(wxNullBitmap); | |
1681 | ||
1682 | // Draw bitmap. scaling and positioning is done there. | |
4f37154e | 1683 | GetOwner()->DrawBitmap( bitmap, xdest, ydest, useMask ); |
fa034c45 RR |
1684 | |
1685 | return true; | |
1686 | } | |
1687 | ||
888dde65 | 1688 | void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) |
fa034c45 RR |
1689 | { |
1690 | DoDrawBitmap( icon, x, y, true ); | |
1691 | } | |
1692 | ||
888dde65 | 1693 | void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask ) |
fa034c45 | 1694 | { |
888dde65 | 1695 | wxCHECK_RET( bitmap.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap")); |
fa034c45 | 1696 | |
5cdcb787 RR |
1697 | x = wxCoord(XLOG2DEV(x)); |
1698 | y = wxCoord(YLOG2DEV(y)); | |
fa034c45 RR |
1699 | int bw = bitmap.GetWidth(); |
1700 | int bh = bitmap.GetHeight(); | |
1701 | wxBitmap bmpSource = bitmap; // we need a non-const instance. | |
fb14d960 PC |
1702 | if (!useMask && !bitmap.HasPixbuf() && bitmap.GetMask()) |
1703 | bmpSource.SetMask(NULL); | |
fa034c45 | 1704 | |
f7b8e3d6 | 1705 | cairo_save(m_cairo); |
fa034c45 RR |
1706 | |
1707 | // Prepare to draw the image. | |
f7b8e3d6 | 1708 | cairo_translate(m_cairo, x, y); |
4d1d071d RR |
1709 | |
1710 | // Scale the image | |
5cdcb787 RR |
1711 | wxDouble scaleX = (wxDouble) XLOG2DEVREL(bw) / (wxDouble) bw; |
1712 | wxDouble scaleY = (wxDouble) YLOG2DEVREL(bh) / (wxDouble) bh; | |
f7b8e3d6 | 1713 | cairo_scale(m_cairo, scaleX, scaleY); |
4d1d071d | 1714 | |
fb14d960 PC |
1715 | gdk_cairo_set_source_pixbuf(m_cairo, bmpSource.GetPixbuf(), 0, 0); |
1716 | cairo_pattern_set_filter(cairo_get_source(m_cairo), CAIRO_FILTER_NEAREST); | |
fa034c45 | 1717 | // Use the original size here since the context is scaled already. |
f7b8e3d6 | 1718 | cairo_rectangle(m_cairo, 0, 0, bw, bh); |
fa034c45 | 1719 | // Fill the rectangle using the pattern. |
f7b8e3d6 | 1720 | cairo_fill(m_cairo); |
fa034c45 | 1721 | |
fa034c45 RR |
1722 | CalcBoundingBox(0,0); |
1723 | CalcBoundingBox(bw,bh); | |
1724 | ||
f7b8e3d6 | 1725 | cairo_restore(m_cairo); |
fa034c45 RR |
1726 | } |
1727 | ||
888dde65 | 1728 | void wxGtkPrinterDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y ) |
fa034c45 RR |
1729 | { |
1730 | DoDrawRotatedText( text, x, y, 0.0 ); | |
1731 | } | |
1732 | ||
888dde65 | 1733 | void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) |
fa034c45 | 1734 | { |
a9312950 RR |
1735 | double xx = XLOG2DEV(x); |
1736 | double yy = YLOG2DEV(y); | |
fa034c45 RR |
1737 | |
1738 | angle = -angle; | |
1739 | ||
197380a0 | 1740 | const wxScopedCharBuffer data = text.utf8_str(); |
fa034c45 | 1741 | |
c7e99122 | 1742 | pango_layout_set_text(m_layout, data, data.length()); |
fa034c45 | 1743 | |
c7e99122 | 1744 | const bool setAttrs = m_font.GTKSetPangoAttrs(m_layout); |
a1b806b9 | 1745 | if (m_textForegroundColour.IsOk()) |
fa034c45 RR |
1746 | { |
1747 | unsigned char red = m_textForegroundColour.Red(); | |
1748 | unsigned char blue = m_textForegroundColour.Blue(); | |
1749 | unsigned char green = m_textForegroundColour.Green(); | |
1750 | unsigned char alpha = m_textForegroundColour.Alpha(); | |
1751 | ||
1752 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue && alpha == m_currentAlpha)) | |
1753 | { | |
1754 | double redPS = (double)(red) / 255.0; | |
1755 | double bluePS = (double)(blue) / 255.0; | |
1756 | double greenPS = (double)(green) / 255.0; | |
1757 | double alphaPS = (double)(alpha) / 255.0; | |
1758 | ||
f7b8e3d6 | 1759 | cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS ); |
fa034c45 RR |
1760 | |
1761 | m_currentRed = red; | |
1762 | m_currentBlue = blue; | |
1763 | m_currentGreen = green; | |
1764 | m_currentAlpha = alpha; | |
1765 | } | |
1766 | } | |
1767 | ||
a9312950 | 1768 | // Draw layout. |
f7b8e3d6 | 1769 | cairo_move_to (m_cairo, xx, yy); |
a7060b8c | 1770 | |
f7b8e3d6 | 1771 | cairo_save( m_cairo ); |
a7060b8c | 1772 | |
a9312950 | 1773 | if (fabs(angle) > 0.00001) |
f7b8e3d6 | 1774 | cairo_rotate( m_cairo, angle*DEG2RAD ); |
a7060b8c | 1775 | |
12ca5586 VS |
1776 | cairo_scale(m_cairo, m_scaleX, m_scaleY); |
1777 | ||
1778 | int w,h; | |
1779 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1780 | ||
1781 | if ( m_backgroundMode == wxBRUSHSTYLE_SOLID ) | |
1782 | { | |
1783 | unsigned char red = m_textBackgroundColour.Red(); | |
1784 | unsigned char blue = m_textBackgroundColour.Blue(); | |
1785 | unsigned char green = m_textBackgroundColour.Green(); | |
1786 | unsigned char alpha = m_textBackgroundColour.Alpha(); | |
1787 | ||
1788 | double redPS = (double)(red) / 255.0; | |
1789 | double bluePS = (double)(blue) / 255.0; | |
1790 | double greenPS = (double)(green) / 255.0; | |
1791 | double alphaPS = (double)(alpha) / 255.0; | |
1792 | ||
1793 | cairo_save(m_cairo); | |
1794 | cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS ); | |
1795 | cairo_rectangle(m_cairo, 0, 0, w, h); // still in cairo units | |
1796 | cairo_fill(m_cairo); | |
1797 | cairo_restore(m_cairo); | |
1798 | } | |
1799 | ||
f7b8e3d6 VS |
1800 | pango_cairo_update_layout (m_cairo, m_layout); |
1801 | pango_cairo_show_layout (m_cairo, m_layout); | |
a7060b8c | 1802 | |
f7b8e3d6 | 1803 | cairo_restore( m_cairo ); |
fa034c45 | 1804 | |
c7a49742 | 1805 | if (setAttrs) |
fa034c45 RR |
1806 | { |
1807 | // Undo underline attributes setting | |
1808 | pango_layout_set_attributes(m_layout, NULL); | |
1809 | } | |
a7060b8c | 1810 | |
1d9fe50d | 1811 | // Back to device units: |
a9312950 RR |
1812 | CalcBoundingBox (x, y); |
1813 | CalcBoundingBox (x + w, y + h); | |
fa034c45 RR |
1814 | } |
1815 | ||
888dde65 | 1816 | void wxGtkPrinterDCImpl::Clear() |
fa034c45 | 1817 | { |
0187f0bc | 1818 | // Clear does nothing for printing, but keep the code |
6d52ca53 | 1819 | // for later reuse |
0187f0bc | 1820 | /* |
f7b8e3d6 VS |
1821 | cairo_save(m_cairo); |
1822 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE); | |
fa034c45 | 1823 | SetBrush(m_backgroundBrush); |
f7b8e3d6 VS |
1824 | cairo_paint(m_cairo); |
1825 | cairo_restore(m_cairo); | |
0187f0bc | 1826 | */ |
fa034c45 RR |
1827 | } |
1828 | ||
888dde65 | 1829 | void wxGtkPrinterDCImpl::SetFont( const wxFont& font ) |
fa034c45 RR |
1830 | { |
1831 | m_font = font; | |
1832 | ||
a1b806b9 | 1833 | if (m_font.IsOk()) |
fa034c45 RR |
1834 | { |
1835 | if (m_fontdesc) | |
1836 | pango_font_description_free( m_fontdesc ); | |
1837 | ||
3e7ea45c | 1838 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); |
1d9fe50d | 1839 | |
12ca5586 VS |
1840 | float size = pango_font_description_get_size( m_fontdesc ); |
1841 | size = size * GetFontPointSizeAdjustment(72.0); | |
1842 | pango_font_description_set_size( m_fontdesc, (gint)size ); | |
1843 | ||
fa034c45 RR |
1844 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
1845 | } | |
1846 | } | |
1847 | ||
888dde65 | 1848 | void wxGtkPrinterDCImpl::SetPen( const wxPen& pen ) |
fa034c45 | 1849 | { |
a1b806b9 | 1850 | if (!pen.IsOk()) return; |
fa034c45 RR |
1851 | |
1852 | m_pen = pen; | |
1853 | ||
b29b9485 | 1854 | double width; |
6d52ca53 | 1855 | |
b29b9485 RR |
1856 | if (m_pen.GetWidth() <= 0) |
1857 | width = 0.1; | |
1858 | else | |
1859 | width = (double) m_pen.GetWidth(); | |
fa034c45 | 1860 | |
f7b8e3d6 | 1861 | cairo_set_line_width( m_cairo, width * m_DEV2PS * m_scaleX ); |
fa034c45 RR |
1862 | static const double dotted[] = {2.0, 5.0}; |
1863 | static const double short_dashed[] = {4.0, 4.0}; | |
1864 | static const double long_dashed[] = {4.0, 8.0}; | |
1865 | static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0}; | |
1866 | ||
1867 | switch (m_pen.GetStyle()) | |
1868 | { | |
f7b8e3d6 VS |
1869 | case wxPENSTYLE_DOT: cairo_set_dash( m_cairo, dotted, 2, 0 ); break; |
1870 | case wxPENSTYLE_SHORT_DASH: cairo_set_dash( m_cairo, short_dashed, 2, 0 ); break; | |
1871 | case wxPENSTYLE_LONG_DASH: cairo_set_dash( m_cairo, long_dashed, 2, 0 ); break; | |
1872 | case wxPENSTYLE_DOT_DASH: cairo_set_dash( m_cairo, dotted_dashed, 4, 0 ); break; | |
04ee05f9 | 1873 | case wxPENSTYLE_USER_DASH: |
fa034c45 RR |
1874 | { |
1875 | wxDash *wx_dashes; | |
da249bc3 | 1876 | int num = m_pen.GetDashes (&wx_dashes); |
fa034c45 RR |
1877 | gdouble *g_dashes = g_new( gdouble, num ); |
1878 | int i; | |
1879 | for (i = 0; i < num; ++i) | |
1880 | g_dashes[i] = (gdouble) wx_dashes[i]; | |
f7b8e3d6 | 1881 | cairo_set_dash( m_cairo, g_dashes, num, 0); |
fa034c45 RR |
1882 | g_free( g_dashes ); |
1883 | } | |
1884 | break; | |
04ee05f9 PC |
1885 | case wxPENSTYLE_SOLID: |
1886 | case wxPENSTYLE_TRANSPARENT: | |
f7b8e3d6 | 1887 | default: cairo_set_dash( m_cairo, NULL, 0, 0 ); break; |
fa034c45 RR |
1888 | } |
1889 | ||
1890 | switch (m_pen.GetCap()) | |
1891 | { | |
f7b8e3d6 VS |
1892 | case wxCAP_PROJECTING: cairo_set_line_cap (m_cairo, CAIRO_LINE_CAP_SQUARE); break; |
1893 | case wxCAP_BUTT: cairo_set_line_cap (m_cairo, CAIRO_LINE_CAP_BUTT); break; | |
fa034c45 | 1894 | case wxCAP_ROUND: |
f7b8e3d6 | 1895 | default: cairo_set_line_cap (m_cairo, CAIRO_LINE_CAP_ROUND); break; |
fa034c45 RR |
1896 | } |
1897 | ||
1898 | switch (m_pen.GetJoin()) | |
1899 | { | |
f7b8e3d6 VS |
1900 | case wxJOIN_BEVEL: cairo_set_line_join (m_cairo, CAIRO_LINE_JOIN_BEVEL); break; |
1901 | case wxJOIN_MITER: cairo_set_line_join (m_cairo, CAIRO_LINE_JOIN_MITER); break; | |
fa034c45 | 1902 | case wxJOIN_ROUND: |
f7b8e3d6 | 1903 | default: cairo_set_line_join (m_cairo, CAIRO_LINE_JOIN_ROUND); break; |
fa034c45 RR |
1904 | } |
1905 | ||
1906 | unsigned char red = m_pen.GetColour().Red(); | |
1907 | unsigned char blue = m_pen.GetColour().Blue(); | |
1908 | unsigned char green = m_pen.GetColour().Green(); | |
1909 | unsigned char alpha = m_pen.GetColour().Alpha(); | |
1910 | ||
1911 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue && alpha == m_currentAlpha)) | |
1912 | { | |
1913 | double redPS = (double)(red) / 255.0; | |
1914 | double bluePS = (double)(blue) / 255.0; | |
1915 | double greenPS = (double)(green) / 255.0; | |
1916 | double alphaPS = (double)(alpha) / 255.0; | |
1917 | ||
f7b8e3d6 | 1918 | cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS ); |
fa034c45 RR |
1919 | |
1920 | m_currentRed = red; | |
1921 | m_currentBlue = blue; | |
1922 | m_currentGreen = green; | |
1923 | m_currentAlpha = alpha; | |
1924 | } | |
1925 | } | |
1926 | ||
888dde65 | 1927 | void wxGtkPrinterDCImpl::SetBrush( const wxBrush& brush ) |
fa034c45 | 1928 | { |
a1b806b9 | 1929 | if (!brush.IsOk()) return; |
fa034c45 RR |
1930 | |
1931 | m_brush = brush; | |
1932 | ||
04ee05f9 | 1933 | if (m_brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT) |
a9312950 | 1934 | { |
f7b8e3d6 | 1935 | cairo_set_source_rgba( m_cairo, 0, 0, 0, 0 ); |
a9312950 RR |
1936 | m_currentRed = 0; |
1937 | m_currentBlue = 0; | |
1938 | m_currentGreen = 0; | |
1939 | m_currentAlpha = 0; | |
1940 | return; | |
1941 | } | |
1942 | ||
fa034c45 RR |
1943 | // Brush colour. |
1944 | unsigned char red = m_brush.GetColour().Red(); | |
1945 | unsigned char blue = m_brush.GetColour().Blue(); | |
1946 | unsigned char green = m_brush.GetColour().Green(); | |
1947 | unsigned char alpha = m_brush.GetColour().Alpha(); | |
1948 | ||
1949 | double redPS = (double)(red) / 255.0; | |
1950 | double bluePS = (double)(blue) / 255.0; | |
1951 | double greenPS = (double)(green) / 255.0; | |
1952 | double alphaPS = (double)(alpha) / 255.0; | |
1953 | ||
1954 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue && alpha == m_currentAlpha)) | |
1955 | { | |
f7b8e3d6 | 1956 | cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS ); |
fa034c45 RR |
1957 | |
1958 | m_currentRed = red; | |
1959 | m_currentBlue = blue; | |
1960 | m_currentGreen = green; | |
1961 | m_currentAlpha = alpha; | |
1962 | } | |
1963 | ||
1964 | if (m_brush.IsHatch()) | |
1965 | { | |
1966 | cairo_t * cr; | |
1967 | cairo_surface_t *surface; | |
f7b8e3d6 VS |
1968 | surface = cairo_surface_create_similar(cairo_get_target(m_cairo),CAIRO_CONTENT_COLOR_ALPHA,10,10); |
1969 | cr = cairo_create(surface); | |
1970 | cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE); | |
1971 | cairo_set_line_width(cr, 1); | |
1972 | cairo_set_line_join(cr,CAIRO_LINE_JOIN_MITER); | |
fa034c45 RR |
1973 | |
1974 | switch (m_brush.GetStyle()) | |
1975 | { | |
04ee05f9 | 1976 | case wxBRUSHSTYLE_CROSS_HATCH: |
f7b8e3d6 VS |
1977 | cairo_move_to(cr, 5, 0); |
1978 | cairo_line_to(cr, 5, 10); | |
1979 | cairo_move_to(cr, 0, 5); | |
1980 | cairo_line_to(cr, 10, 5); | |
fa034c45 | 1981 | break; |
04ee05f9 | 1982 | case wxBRUSHSTYLE_BDIAGONAL_HATCH: |
f7b8e3d6 VS |
1983 | cairo_move_to(cr, 0, 10); |
1984 | cairo_line_to(cr, 10, 0); | |
fa034c45 | 1985 | break; |
04ee05f9 | 1986 | case wxBRUSHSTYLE_FDIAGONAL_HATCH: |
f7b8e3d6 VS |
1987 | cairo_move_to(cr, 0, 0); |
1988 | cairo_line_to(cr, 10, 10); | |
fa034c45 | 1989 | break; |
04ee05f9 | 1990 | case wxBRUSHSTYLE_CROSSDIAG_HATCH: |
f7b8e3d6 VS |
1991 | cairo_move_to(cr, 0, 0); |
1992 | cairo_line_to(cr, 10, 10); | |
1993 | cairo_move_to(cr, 10, 0); | |
1994 | cairo_line_to(cr, 0, 10); | |
fa034c45 | 1995 | break; |
04ee05f9 | 1996 | case wxBRUSHSTYLE_HORIZONTAL_HATCH: |
f7b8e3d6 VS |
1997 | cairo_move_to(cr, 0, 5); |
1998 | cairo_line_to(cr, 10, 5); | |
fa034c45 | 1999 | break; |
04ee05f9 | 2000 | case wxBRUSHSTYLE_VERTICAL_HATCH: |
f7b8e3d6 VS |
2001 | cairo_move_to(cr, 5, 0); |
2002 | cairo_line_to(cr, 5, 10); | |
fa034c45 RR |
2003 | break; |
2004 | default: | |
2005 | wxFAIL_MSG(_("Couldn't get hatch style from wxBrush.")); | |
2006 | } | |
2007 | ||
f7b8e3d6 VS |
2008 | cairo_set_source_rgba(cr, redPS, greenPS, bluePS, alphaPS); |
2009 | cairo_stroke (cr); | |
fa034c45 | 2010 | |
f7b8e3d6 VS |
2011 | cairo_destroy(cr); |
2012 | cairo_pattern_t * pattern = cairo_pattern_create_for_surface (surface); | |
2013 | cairo_surface_destroy(surface); | |
2014 | cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); | |
2015 | cairo_set_source(m_cairo, pattern); | |
2016 | cairo_pattern_destroy(pattern); | |
fa034c45 RR |
2017 | } |
2018 | } | |
2019 | ||
89efaf2b | 2020 | void wxGtkPrinterDCImpl::SetLogicalFunction( wxRasterOperationMode function ) |
fa034c45 RR |
2021 | { |
2022 | if (function == wxCLEAR) | |
f7b8e3d6 | 2023 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_CLEAR); |
fa034c45 | 2024 | else if (function == wxOR) |
f7b8e3d6 | 2025 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_OUT); |
fa034c45 | 2026 | else if (function == wxNO_OP) |
f7b8e3d6 | 2027 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_DEST); |
fa034c45 | 2028 | else if (function == wxAND) |
f7b8e3d6 | 2029 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_ADD); |
fa034c45 | 2030 | else if (function == wxSET) |
f7b8e3d6 | 2031 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_SATURATE); |
fa034c45 | 2032 | else if (function == wxXOR) |
f7b8e3d6 | 2033 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_XOR); |
fa034c45 | 2034 | else // wxCOPY or anything else. |
f7b8e3d6 | 2035 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE); |
fa034c45 RR |
2036 | } |
2037 | ||
888dde65 | 2038 | void wxGtkPrinterDCImpl::SetBackground( const wxBrush& brush ) |
fa034c45 RR |
2039 | { |
2040 | m_backgroundBrush = brush; | |
f7b8e3d6 VS |
2041 | cairo_save(m_cairo); |
2042 | cairo_set_operator (m_cairo, CAIRO_OPERATOR_DEST_OVER); | |
fa034c45 RR |
2043 | |
2044 | SetBrush(m_backgroundBrush); | |
f7b8e3d6 VS |
2045 | cairo_paint(m_cairo); |
2046 | cairo_restore(m_cairo); | |
fa034c45 RR |
2047 | } |
2048 | ||
888dde65 | 2049 | void wxGtkPrinterDCImpl::SetBackgroundMode(int mode) |
fa034c45 | 2050 | { |
04ee05f9 PC |
2051 | if (mode == wxBRUSHSTYLE_SOLID) |
2052 | m_backgroundMode = wxBRUSHSTYLE_SOLID; | |
e0d1fd7f | 2053 | else |
04ee05f9 | 2054 | m_backgroundMode = wxBRUSHSTYLE_TRANSPARENT; |
fa034c45 RR |
2055 | } |
2056 | ||
888dde65 | 2057 | void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
fa034c45 | 2058 | { |
f7b8e3d6 VS |
2059 | cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height)); |
2060 | cairo_clip(m_cairo); | |
fa034c45 RR |
2061 | } |
2062 | ||
888dde65 | 2063 | void wxGtkPrinterDCImpl::DestroyClippingRegion() |
fa034c45 | 2064 | { |
f7b8e3d6 | 2065 | cairo_reset_clip(m_cairo); |
fa034c45 RR |
2066 | } |
2067 | ||
888dde65 | 2068 | bool wxGtkPrinterDCImpl::StartDoc(const wxString& WXUNUSED(message)) |
fa034c45 RR |
2069 | { |
2070 | return true; | |
2071 | } | |
2072 | ||
888dde65 | 2073 | void wxGtkPrinterDCImpl::EndDoc() |
fa034c45 RR |
2074 | { |
2075 | return; | |
2076 | } | |
2077 | ||
888dde65 | 2078 | void wxGtkPrinterDCImpl::StartPage() |
fa034c45 RR |
2079 | { |
2080 | return; | |
2081 | } | |
2082 | ||
888dde65 | 2083 | void wxGtkPrinterDCImpl::EndPage() |
fa034c45 RR |
2084 | { |
2085 | return; | |
2086 | } | |
2087 | ||
888dde65 | 2088 | wxCoord wxGtkPrinterDCImpl::GetCharHeight() const |
fa034c45 RR |
2089 | { |
2090 | pango_layout_set_text( m_layout, "H", 1 ); | |
2091 | ||
2092 | int w,h; | |
2093 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
2094 | ||
a9312950 | 2095 | return wxRound( h * m_PS2DEV ); |
fa034c45 RR |
2096 | } |
2097 | ||
888dde65 | 2098 | wxCoord wxGtkPrinterDCImpl::GetCharWidth() const |
fa034c45 RR |
2099 | { |
2100 | pango_layout_set_text( m_layout, "H", 1 ); | |
2101 | ||
2102 | int w,h; | |
2103 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
2104 | ||
a9312950 | 2105 | return wxRound( w * m_PS2DEV ); |
fa034c45 RR |
2106 | } |
2107 | ||
888dde65 | 2108 | void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, |
fa034c45 RR |
2109 | wxCoord *descent, |
2110 | wxCoord *externalLeading, | |
2111 | const wxFont *theFont ) const | |
2112 | { | |
2113 | if ( width ) | |
2114 | *width = 0; | |
2115 | if ( height ) | |
2116 | *height = 0; | |
2117 | if ( descent ) | |
2118 | *descent = 0; | |
2119 | if ( externalLeading ) | |
2120 | *externalLeading = 0; | |
2121 | ||
2122 | if (string.empty()) | |
2123 | { | |
2124 | return; | |
2125 | } | |
2126 | ||
12ca5586 VS |
2127 | cairo_save( m_cairo ); |
2128 | cairo_scale(m_cairo, m_scaleX, m_scaleY); | |
2129 | ||
fa034c45 | 2130 | // Set layout's text |
197380a0 | 2131 | const wxScopedCharBuffer dataUTF8 = string.utf8_str(); |
fa034c45 | 2132 | |
8cf694d4 | 2133 | gint oldSize=0; |
12ca5586 VS |
2134 | if ( theFont ) |
2135 | { | |
2136 | // scale the font and apply it | |
2137 | PangoFontDescription *desc = theFont->GetNativeFontInfo()->description; | |
565ed8bf PC |
2138 | oldSize = pango_font_description_get_size(desc); |
2139 | const float size = oldSize * GetFontPointSizeAdjustment(72.0); | |
12ca5586 | 2140 | pango_font_description_set_size(desc, (gint)size); |
fa034c45 | 2141 | |
12ca5586 VS |
2142 | pango_layout_set_font_description(m_layout, desc); |
2143 | } | |
fa034c45 RR |
2144 | |
2145 | pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); | |
2146 | ||
12ca5586 VS |
2147 | int h; |
2148 | pango_layout_get_pixel_size( m_layout, width, &h ); | |
2149 | if ( height ) | |
2150 | *height = h; | |
a7060b8c | 2151 | |
fa034c45 RR |
2152 | if (descent) |
2153 | { | |
2154 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); | |
2155 | int baseline = pango_layout_iter_get_baseline(iter); | |
2156 | pango_layout_iter_free(iter); | |
12ca5586 | 2157 | *descent = h - PANGO_PIXELS(baseline); |
fa034c45 RR |
2158 | } |
2159 | ||
12ca5586 VS |
2160 | if ( theFont ) |
2161 | { | |
2162 | // restore font and reset font's size back | |
2163 | pango_layout_set_font_description(m_layout, m_fontdesc); | |
fa034c45 | 2164 | |
12ca5586 VS |
2165 | PangoFontDescription *desc = theFont->GetNativeFontInfo()->description; |
2166 | pango_font_description_set_size(desc, oldSize); | |
2167 | } | |
2168 | ||
2169 | cairo_restore( m_cairo ); | |
fa034c45 RR |
2170 | } |
2171 | ||
888dde65 | 2172 | void wxGtkPrinterDCImpl::DoGetSize(int* width, int* height) const |
fa034c45 | 2173 | { |
a9312950 RR |
2174 | GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc ); |
2175 | ||
fa034c45 | 2176 | if (width) |
eaeb9985 | 2177 | *width = wxRound( (double)gtk_page_setup_get_paper_width( setup, GTK_UNIT_POINTS ) * (double)m_resolution / 72.0 ); |
fa034c45 | 2178 | if (height) |
eaeb9985 | 2179 | *height = wxRound( (double)gtk_page_setup_get_paper_height( setup, GTK_UNIT_POINTS ) * (double)m_resolution / 72.0 ); |
fa034c45 RR |
2180 | } |
2181 | ||
888dde65 | 2182 | void wxGtkPrinterDCImpl::DoGetSizeMM(int *width, int *height) const |
fa034c45 | 2183 | { |
a9312950 | 2184 | GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc ); |
fa034c45 RR |
2185 | |
2186 | if (width) | |
a9312950 | 2187 | *width = wxRound( gtk_page_setup_get_paper_width( setup, GTK_UNIT_MM ) ); |
fa034c45 | 2188 | if (height) |
a9312950 | 2189 | *height = wxRound( gtk_page_setup_get_paper_height( setup, GTK_UNIT_MM ) ); |
fa034c45 RR |
2190 | } |
2191 | ||
888dde65 | 2192 | wxSize wxGtkPrinterDCImpl::GetPPI() const |
fa034c45 | 2193 | { |
a9312950 | 2194 | return wxSize( (int)m_resolution, (int)m_resolution ); |
fa034c45 RR |
2195 | } |
2196 | ||
888dde65 | 2197 | void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData& data) |
fa034c45 RR |
2198 | { |
2199 | m_printData = data; | |
fa034c45 RR |
2200 | } |
2201 | ||
4c51a665 | 2202 | // overridden for wxPrinterDC Impl |
4f37154e | 2203 | |
6d52ca53 | 2204 | wxRect wxGtkPrinterDCImpl::GetPaperRect() const |
fa034c45 | 2205 | { |
4f37154e RR |
2206 | // Does GtkPrint support printer margins? |
2207 | int w = 0; | |
2208 | int h = 0; | |
2209 | DoGetSize( &w, &h ); | |
2210 | return wxRect( 0,0,w,h ); | |
fa034c45 RR |
2211 | } |
2212 | ||
6d52ca53 | 2213 | int wxGtkPrinterDCImpl::GetResolution() const |
fa034c45 | 2214 | { |
a9312950 | 2215 | return m_resolution; |
fa034c45 RR |
2216 | } |
2217 | ||
2218 | // ---------------------------------------------------------------------------- | |
2219 | // Print preview | |
2220 | // ---------------------------------------------------------------------------- | |
2221 | ||
2222 | IMPLEMENT_CLASS(wxGtkPrintPreview, wxPrintPreviewBase) | |
2223 | ||
2224 | void wxGtkPrintPreview::Init(wxPrintout * WXUNUSED(printout), | |
115be92b VZ |
2225 | wxPrintout * WXUNUSED(printoutForPrinting), |
2226 | wxPrintData *data) | |
fa034c45 | 2227 | { |
115be92b VZ |
2228 | // convert wxPrintQuality to resolution (input pointer can be NULL) |
2229 | wxPrintQuality quality = data ? data->GetQuality() : wxPRINT_QUALITY_MEDIUM; | |
2230 | switch ( quality ) | |
2231 | { | |
2232 | case wxPRINT_QUALITY_HIGH: | |
2233 | m_resolution = 1200; | |
2234 | break; | |
2235 | ||
115be92b VZ |
2236 | case wxPRINT_QUALITY_LOW: |
2237 | m_resolution = 300; | |
2238 | break; | |
2239 | ||
2240 | case wxPRINT_QUALITY_DRAFT: | |
2241 | m_resolution = 150; | |
2242 | break; | |
1f2a1c3c VZ |
2243 | |
2244 | default: | |
2245 | if ( quality > 0 ) | |
2246 | { | |
2247 | // positive values directly indicate print resolution | |
2248 | m_resolution = quality; | |
2249 | break; | |
2250 | } | |
2251 | ||
2252 | wxFAIL_MSG( "unknown print quality" ); | |
2253 | // fall through | |
2254 | ||
2255 | case wxPRINT_QUALITY_MEDIUM: | |
2256 | m_resolution = 600; | |
2257 | break; | |
2258 | ||
115be92b | 2259 | } |
1f2a1c3c VZ |
2260 | |
2261 | DetermineScaling(); | |
fa034c45 RR |
2262 | } |
2263 | ||
2264 | wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout *printout, | |
115be92b VZ |
2265 | wxPrintout *printoutForPrinting, |
2266 | wxPrintDialogData *data) | |
2267 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
fa034c45 | 2268 | { |
115be92b | 2269 | Init(printout, printoutForPrinting, data ? &data->GetPrintData() : NULL); |
fa034c45 RR |
2270 | } |
2271 | ||
2272 | wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout *printout, | |
115be92b VZ |
2273 | wxPrintout *printoutForPrinting, |
2274 | wxPrintData *data) | |
2275 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
fa034c45 | 2276 | { |
115be92b | 2277 | Init(printout, printoutForPrinting, data); |
fa034c45 RR |
2278 | } |
2279 | ||
2280 | wxGtkPrintPreview::~wxGtkPrintPreview() | |
2281 | { | |
2282 | } | |
2283 | ||
2284 | bool wxGtkPrintPreview::Print(bool interactive) | |
2285 | { | |
2286 | if (!m_printPrintout) | |
2287 | return false; | |
2288 | ||
2289 | wxPrinter printer(& m_printDialogData); | |
2290 | return printer.Print(m_previewFrame, m_printPrintout, interactive); | |
2291 | } | |
2292 | ||
2293 | void wxGtkPrintPreview::DetermineScaling() | |
2294 | { | |
2295 | wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId(); | |
2296 | ||
2297 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType); | |
2298 | if (!paper) | |
2299 | paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); | |
2300 | ||
2301 | if (paper) | |
2302 | { | |
ac78a90a VZ |
2303 | const wxSize screenPPI = wxGetDisplayPPI(); |
2304 | int logPPIScreenX = screenPPI.GetWidth(); | |
2305 | int logPPIScreenY = screenPPI.GetHeight(); | |
2306 | int logPPIPrinterX = m_resolution; | |
2307 | int logPPIPrinterY = m_resolution; | |
2308 | ||
2309 | m_previewPrintout->SetPPIScreen( logPPIScreenX, logPPIScreenY ); | |
2310 | m_previewPrintout->SetPPIPrinter( logPPIPrinterX, logPPIPrinterY ); | |
a7060b8c | 2311 | |
fa034c45 RR |
2312 | // Get width and height in points (1/72th of an inch) |
2313 | wxSize sizeDevUnits(paper->GetSizeDeviceUnits()); | |
115be92b VZ |
2314 | sizeDevUnits.x = wxRound((double)sizeDevUnits.x * (double)m_resolution / 72.0); |
2315 | sizeDevUnits.y = wxRound((double)sizeDevUnits.y * (double)m_resolution / 72.0); | |
6d52ca53 | 2316 | |
fa034c45 RR |
2317 | wxSize sizeTenthsMM(paper->GetSize()); |
2318 | wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10); | |
2319 | ||
2320 | // If in landscape mode, we need to swap the width and height. | |
2321 | if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE ) | |
2322 | { | |
2323 | m_pageWidth = sizeDevUnits.y; | |
2324 | m_pageHeight = sizeDevUnits.x; | |
2325 | m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x); | |
2326 | } | |
2327 | else | |
2328 | { | |
2329 | m_pageWidth = sizeDevUnits.x; | |
2330 | m_pageHeight = sizeDevUnits.y; | |
2331 | m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y); | |
2332 | } | |
2333 | m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); | |
2334 | m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight)); | |
2335 | ||
2336 | // At 100%, the page should look about page-size on the screen. | |
ac78a90a VZ |
2337 | m_previewScaleX = float(logPPIScreenX) / logPPIPrinterX; |
2338 | m_previewScaleY = float(logPPIScreenY) / logPPIPrinterY; | |
fa034c45 RR |
2339 | } |
2340 | } | |
2341 | ||
2342 | #endif | |
2343 | // wxUSE_GTKPRINT |