]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: gprint.cpp | |
3 | // Author: Robert Roebling | |
4 | // Purpose: Implement GNOME printing support | |
5 | // Created: 09/20/04 | |
6 | // Copyright: Robert Roebling | |
7 | // Licence: wxWindows Licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
11 | #pragma implementation "gprint.h" | |
12 | #endif | |
13 | ||
14 | // For compilers that support precompilation, includes "wx/wx.h". | |
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
21 | #include "wx/gtk/gnome/gprint.h" | |
22 | ||
23 | #if wxUSE_LIBGNOMEPRINT | |
24 | ||
25 | #include "wx/math.h" | |
26 | #include "wx/fontutil.h" | |
27 | #include "wx/printdlg.h" | |
28 | #include "wx/gtk/private.h" | |
29 | #include "wx/module.h" | |
30 | #include "wx/generic/prntdlgg.h" | |
31 | #include "wx/dynlib.h" | |
32 | ||
33 | #include <libgnomeprint/gnome-print.h> | |
34 | #include <libgnomeprint/gnome-print-pango.h> | |
35 | #include <libgnomeprint/gnome-print-config.h> | |
36 | #include <libgnomeprintui/gnome-print-dialog.h> | |
37 | #include <libgnomeprintui/gnome-print-job-preview.h> | |
38 | #include <libgnomeprintui/gnome-print-paper-selector.h> | |
39 | ||
40 | ||
41 | #include "wx/html/forcelnk.h" | |
42 | FORCE_LINK_ME(gnome_print) | |
43 | ||
44 | //---------------------------------------------------------------------------- | |
45 | // wxGnomePrintLibrary | |
46 | //---------------------------------------------------------------------------- | |
47 | ||
48 | #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \ | |
49 | typedef rettype (* name ## Type) args ; \ | |
50 | name ## Type pfn_ ## name; \ | |
51 | rettype name args \ | |
52 | { if (m_ok) return pfn_ ## name shortargs ; return defret; } | |
53 | ||
54 | #define wxDL_METHOD_LOAD( lib, name, success ) \ | |
55 | pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \ | |
56 | if (!success) return; | |
57 | ||
58 | class wxGnomePrintLibrary | |
59 | { | |
60 | public: | |
61 | wxGnomePrintLibrary(); | |
62 | ~wxGnomePrintLibrary(); | |
63 | ||
64 | bool IsOk(); | |
65 | void InitializeMethods(); | |
66 | ||
67 | private: | |
68 | bool m_ok; | |
69 | wxDynamicLibrary *m_gnome_print_lib; | |
70 | wxDynamicLibrary *m_gnome_printui_lib; | |
71 | ||
72 | public: | |
73 | wxDL_METHOD_DEFINE( gint, gnome_print_newpath, | |
74 | (GnomePrintContext *pc), (pc), 0 ) | |
75 | wxDL_METHOD_DEFINE( gint, gnome_print_moveto, | |
76 | (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 ) | |
77 | wxDL_METHOD_DEFINE( gint, gnome_print_lineto, | |
78 | (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 ) | |
79 | wxDL_METHOD_DEFINE( gint, gnome_print_curveto, | |
80 | (GnomePrintContext *pc, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble x3, gdouble y3), (pc, x1, y1, x2, y2, x3, y3), 0 ) | |
81 | wxDL_METHOD_DEFINE( gint, gnome_print_closepath, | |
82 | (GnomePrintContext *pc), (pc), 0 ) | |
83 | wxDL_METHOD_DEFINE( gint, gnome_print_stroke, | |
84 | (GnomePrintContext *pc), (pc), 0 ) | |
85 | wxDL_METHOD_DEFINE( gint, gnome_print_fill, | |
86 | (GnomePrintContext *pc), (pc), 0 ) | |
87 | wxDL_METHOD_DEFINE( gint, gnome_print_setrgbcolor, | |
88 | (GnomePrintContext *pc, gdouble r, gdouble g, gdouble b), (pc, r, g, b), 0 ) | |
89 | wxDL_METHOD_DEFINE( gint, gnome_print_setlinewidth, | |
90 | (GnomePrintContext *pc, gdouble width), (pc, width), 0 ) | |
91 | wxDL_METHOD_DEFINE( gint, gnome_print_setdash, | |
92 | (GnomePrintContext *pc, gint n_values, const gdouble *values, gdouble offset), (pc, n_values, values, offset), 0 ) | |
93 | ||
94 | wxDL_METHOD_DEFINE( gint, gnome_print_rgbimage, | |
95 | (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 ) | |
96 | wxDL_METHOD_DEFINE( gint, gnome_print_rgbaimage, | |
97 | (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 ) | |
98 | ||
99 | wxDL_METHOD_DEFINE( gint, gnome_print_concat, | |
100 | (GnomePrintContext *pc, const gdouble *matrix), (pc, matrix), 0 ) | |
101 | wxDL_METHOD_DEFINE( gint, gnome_print_scale, | |
102 | (GnomePrintContext *pc, gdouble sx, gdouble sy), (pc, sx, sy), 0 ) | |
103 | wxDL_METHOD_DEFINE( gint, gnome_print_rotate, | |
104 | (GnomePrintContext *pc, gdouble theta), (pc, theta), 0 ) | |
105 | ||
106 | wxDL_METHOD_DEFINE( gint, gnome_print_gsave, | |
107 | (GnomePrintContext *pc), (pc), 0 ) | |
108 | wxDL_METHOD_DEFINE( gint, gnome_print_grestore, | |
109 | (GnomePrintContext *pc), (pc), 0 ) | |
110 | ||
111 | wxDL_METHOD_DEFINE( gint, gnome_print_beginpage, | |
112 | (GnomePrintContext *pc, const guchar* name), (pc, name), 0 ) | |
113 | wxDL_METHOD_DEFINE( gint, gnome_print_showpage, | |
114 | (GnomePrintContext *pc), (pc), 0 ) | |
115 | wxDL_METHOD_DEFINE( gint, gnome_print_end_doc, | |
116 | (GnomePrintContext *pc), (pc), 0 ) | |
117 | ||
118 | wxDL_METHOD_DEFINE( PangoLayout*, gnome_print_pango_create_layout, | |
119 | (GnomePrintContext *gpc), (gpc), NULL ) | |
120 | wxDL_METHOD_DEFINE( void, gnome_print_pango_layout, | |
121 | (GnomePrintContext *gpc, PangoLayout *layout), (gpc, layout), /**/ ) | |
122 | ||
123 | wxDL_METHOD_DEFINE( GnomePrintJob*, gnome_print_job_new, | |
124 | (GnomePrintConfig *config), (config), NULL ) | |
125 | wxDL_METHOD_DEFINE( GnomePrintContext*, gnome_print_job_get_context, | |
126 | (GnomePrintJob *job), (job), NULL ) | |
127 | wxDL_METHOD_DEFINE( gint, gnome_print_job_close, | |
128 | (GnomePrintJob *job), (job), 0 ) | |
129 | wxDL_METHOD_DEFINE( gint, gnome_print_job_print, | |
130 | (GnomePrintJob *job), (job), 0 ) | |
131 | wxDL_METHOD_DEFINE( gboolean, gnome_print_job_get_page_size, | |
132 | (GnomePrintJob *job, gdouble *width, gdouble *height), (job, width, height), 0 ) | |
133 | ||
134 | wxDL_METHOD_DEFINE( GnomePrintUnit*, gnome_print_unit_get_by_abbreviation, | |
135 | (const guchar *abbreviation), (abbreviation), NULL ) | |
136 | wxDL_METHOD_DEFINE( gboolean, gnome_print_convert_distance, | |
137 | (gdouble *distance, const GnomePrintUnit *from, const GnomePrintUnit *to), (distance, from, to), false ) | |
138 | ||
139 | wxDL_METHOD_DEFINE( GnomePrintConfig*, gnome_print_config_default, | |
140 | (void), (), NULL ) | |
141 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set, | |
142 | (GnomePrintConfig *config, const guchar *key, const guchar *value), (config, key, value), false ) | |
143 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_get_length, | |
144 | (GnomePrintConfig *config, const guchar *key, gdouble *val, const GnomePrintUnit **unit), (config, key, val, unit), false ) | |
145 | ||
146 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_dialog_new, | |
147 | (GnomePrintJob *gpj, const guchar *title, gint flags), (gpj, title, flags), NULL ) | |
148 | wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page, | |
149 | (GnomePrintDialog *gpd, gint flags, gint start, gint end, | |
150 | const guchar *currentlabel, const guchar *rangelabel), | |
151 | (gpd, flags, start, end, currentlabel, rangelabel), /**/ ) | |
152 | wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies, | |
153 | (GnomePrintDialog *gpd, gint *copies, gboolean *collate), (gpd, copies, collate), /**/ ) | |
154 | wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies, | |
155 | (GnomePrintDialog *gpd, gint copies, gint collate), (gpd, copies, collate), /**/ ) | |
156 | wxDL_METHOD_DEFINE( GnomePrintRangeType, gnome_print_dialog_get_range, | |
157 | (GnomePrintDialog *gpd), (gpd), GNOME_PRINT_RANGETYPE_NONE ) | |
158 | wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page, | |
159 | (GnomePrintDialog *gpd, gint *start, gint *end), (gpd, start, end), 0 ) | |
160 | ||
161 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_paper_selector_new_with_flags, | |
162 | (GnomePrintConfig *config, gint flags), (config, flags), NULL ) | |
163 | ||
164 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_job_preview_new, | |
165 | (GnomePrintJob *gpm, const guchar *title), (gpm, title), NULL ) | |
166 | }; | |
167 | ||
168 | wxGnomePrintLibrary::wxGnomePrintLibrary() | |
169 | { | |
170 | m_gnome_print_lib = NULL; | |
171 | m_gnome_printui_lib = NULL; | |
172 | ||
173 | wxLogNull log; | |
174 | ||
175 | m_gnome_print_lib = new wxDynamicLibrary( wxT("libgnomeprint-2-2.so") ); | |
176 | m_ok = m_gnome_print_lib->IsLoaded(); | |
177 | if (!m_ok) return; | |
178 | ||
179 | m_gnome_printui_lib = new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so") ); | |
180 | m_ok = m_gnome_printui_lib->IsLoaded(); | |
181 | if (!m_ok) return; | |
182 | ||
183 | InitializeMethods(); | |
184 | } | |
185 | ||
186 | wxGnomePrintLibrary::~wxGnomePrintLibrary() | |
187 | { | |
188 | if (m_gnome_print_lib) | |
189 | delete m_gnome_print_lib; | |
190 | if (m_gnome_printui_lib) | |
191 | delete m_gnome_printui_lib; | |
192 | } | |
193 | ||
194 | bool wxGnomePrintLibrary::IsOk() | |
195 | { | |
196 | return m_ok; | |
197 | } | |
198 | ||
199 | void wxGnomePrintLibrary::InitializeMethods() | |
200 | { | |
201 | m_ok = false; | |
202 | bool success; | |
203 | ||
204 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_newpath, success ) | |
205 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_moveto, success ) | |
206 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_lineto, success ) | |
207 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_curveto, success ) | |
208 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_closepath, success ) | |
209 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_stroke, success ) | |
210 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_fill, success ) | |
211 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_setrgbcolor, success ) | |
212 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_setlinewidth, success ) | |
213 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_setdash, success ) | |
214 | ||
215 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_rgbimage, success ) | |
216 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_rgbaimage, success ) | |
217 | ||
218 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_concat, success ) | |
219 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_scale, success ) | |
220 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_rotate, success ) | |
221 | ||
222 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_gsave, success ) | |
223 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_grestore, success ) | |
224 | ||
225 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_beginpage, success ) | |
226 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_showpage, success ) | |
227 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_end_doc, success ) | |
228 | ||
229 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_pango_create_layout, success ) | |
230 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_pango_layout, success ) | |
231 | ||
232 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_new, success ) | |
233 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_get_context, success ) | |
234 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_close, success ) | |
235 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_print, success ) | |
236 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_get_page_size, success ) | |
237 | ||
238 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_unit_get_by_abbreviation, success ) | |
239 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_convert_distance, success ) | |
240 | ||
241 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_config_default, success ) | |
242 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_config_set, success ) | |
243 | wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_config_get_length, success ) | |
244 | ||
245 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_new, success ) | |
246 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_construct_range_page, success ) | |
247 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_get_copies, success ) | |
248 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_set_copies, success ) | |
249 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_get_range, success ) | |
250 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_get_range_page, success ) | |
251 | ||
252 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_paper_selector_new_with_flags, success ) | |
253 | ||
254 | wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_job_preview_new, success ) | |
255 | ||
256 | m_ok = true; | |
257 | } | |
258 | ||
259 | static wxGnomePrintLibrary* gs_lgp = NULL; | |
260 | ||
261 | //---------------------------------------------------------------------------- | |
262 | // wxGnomePrintNativeData | |
263 | //---------------------------------------------------------------------------- | |
264 | ||
265 | IMPLEMENT_CLASS(wxGnomePrintNativeData, wxPrintNativeDataBase) | |
266 | ||
267 | wxGnomePrintNativeData::wxGnomePrintNativeData() | |
268 | { | |
269 | m_config = gs_lgp->gnome_print_config_default(); | |
270 | m_job = gs_lgp->gnome_print_job_new( m_config ); | |
271 | } | |
272 | ||
273 | wxGnomePrintNativeData::~wxGnomePrintNativeData() | |
274 | { | |
275 | g_object_unref (G_OBJECT (m_config)); | |
276 | } | |
277 | ||
278 | bool wxGnomePrintNativeData::TransferTo( wxPrintData &data ) | |
279 | { | |
280 | // TODO | |
281 | return true; | |
282 | } | |
283 | ||
284 | bool wxGnomePrintNativeData::TransferFrom( const wxPrintData &data ) | |
285 | { | |
286 | // TODO | |
287 | return true; | |
288 | } | |
289 | ||
290 | //---------------------------------------------------------------------------- | |
291 | // wxGnomePrintFactory | |
292 | //---------------------------------------------------------------------------- | |
293 | ||
294 | wxPrinterBase* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData *data ) | |
295 | { | |
296 | return new wxGnomePrinter( data ); | |
297 | } | |
298 | ||
299 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, | |
300 | wxPrintout *printout, | |
301 | wxPrintDialogData *data ) | |
302 | { | |
303 | return new wxPostScriptPrintPreview( preview, printout, data ); | |
304 | } | |
305 | ||
306 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, | |
307 | wxPrintout *printout, | |
308 | wxPrintData *data ) | |
309 | { | |
310 | return new wxPostScriptPrintPreview( preview, printout, data ); | |
311 | } | |
312 | ||
313 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, | |
314 | wxPrintDialogData *data ) | |
315 | { | |
316 | return new wxGnomePrintDialog( parent, data ); | |
317 | } | |
318 | ||
319 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, | |
320 | wxPrintData *data ) | |
321 | { | |
322 | return new wxGnomePrintDialog( parent, data ); | |
323 | } | |
324 | ||
325 | wxPageSetupDialogBase *wxGnomePrintFactory::CreatePageSetupDialog( wxWindow *parent, | |
326 | wxPageSetupDialogData * data ) | |
327 | { | |
328 | // The native page setup dialog is broken. It | |
329 | // miscalculates newly entered values for the | |
330 | // margins if you have not chose "points" but | |
331 | // e.g. centimerters. | |
332 | // This has been fixed in GNOME CVS (maybe | |
333 | // fixed in libgnomeprintui 2.8.1) | |
334 | ||
335 | return new wxGnomePageSetupDialog( parent, data ); | |
336 | } | |
337 | ||
338 | bool wxGnomePrintFactory::HasPrintSetupDialog() | |
339 | { | |
340 | return false; | |
341 | } | |
342 | ||
343 | wxDialog *wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data ) | |
344 | { | |
345 | return NULL; | |
346 | } | |
347 | ||
348 | bool wxGnomePrintFactory::HasOwnPrintToFile() | |
349 | { | |
350 | return true; | |
351 | } | |
352 | ||
353 | bool wxGnomePrintFactory::HasPrinterLine() | |
354 | { | |
355 | return true; | |
356 | } | |
357 | ||
358 | wxString wxGnomePrintFactory::CreatePrinterLine() | |
359 | { | |
360 | // redundant now | |
361 | return wxEmptyString; | |
362 | } | |
363 | ||
364 | bool wxGnomePrintFactory::HasStatusLine() | |
365 | { | |
366 | // redundant now | |
367 | return true; | |
368 | } | |
369 | ||
370 | wxString wxGnomePrintFactory::CreateStatusLine() | |
371 | { | |
372 | // redundant now | |
373 | return wxEmptyString; | |
374 | } | |
375 | ||
376 | wxPrintNativeDataBase *wxGnomePrintFactory::CreatePrintNativeData() | |
377 | { | |
378 | return new wxGnomePrintNativeData; | |
379 | } | |
380 | ||
381 | //---------------------------------------------------------------------------- | |
382 | // wxGnomePrintSetupDialog | |
383 | //---------------------------------------------------------------------------- | |
384 | ||
385 | IMPLEMENT_CLASS(wxGnomePrintDialog, wxPrintDialogBase) | |
386 | ||
387 | wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintDialogData *data ) | |
388 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
389 | wxPoint(0, 0), wxSize(600, 600), | |
390 | wxDEFAULT_DIALOG_STYLE | | |
391 | wxTAB_TRAVERSAL) | |
392 | { | |
393 | if (data) | |
394 | m_printDialogData = *data; | |
395 | ||
396 | Init(); | |
397 | } | |
398 | ||
399 | wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintData *data ) | |
400 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
401 | wxPoint(0, 0), wxSize(600, 600), | |
402 | wxDEFAULT_DIALOG_STYLE | | |
403 | wxTAB_TRAVERSAL) | |
404 | { | |
405 | if (data) | |
406 | m_printDialogData = *data; | |
407 | ||
408 | Init(); | |
409 | } | |
410 | ||
411 | void wxGnomePrintDialog::Init() | |
412 | { | |
413 | wxPrintData data = m_printDialogData.GetPrintData(); | |
414 | ||
415 | wxGnomePrintNativeData *native = | |
416 | (wxGnomePrintNativeData*) data.GetNativeData(); | |
417 | ||
418 | m_widget = gs_lgp->gnome_print_dialog_new( native->GetPrintJob(), | |
419 | (guchar*)"Print", | |
420 | GNOME_PRINT_DIALOG_RANGE|GNOME_PRINT_DIALOG_COPIES ); | |
421 | ||
422 | int flag = 0; | |
423 | if (m_printDialogData.GetEnableSelection()) | |
424 | flag |= GNOME_PRINT_RANGE_SELECTION; | |
425 | if (m_printDialogData.GetEnablePageNumbers()) | |
426 | flag |= GNOME_PRINT_RANGE_ALL|GNOME_PRINT_RANGE_RANGE; | |
427 | ||
428 | gs_lgp->gnome_print_dialog_construct_range_page( (GnomePrintDialog*) m_widget, | |
429 | flag, | |
430 | m_printDialogData.GetMinPage(), | |
431 | m_printDialogData.GetMaxPage(), | |
432 | NULL, | |
433 | NULL ); | |
434 | } | |
435 | ||
436 | wxGnomePrintDialog::~wxGnomePrintDialog() | |
437 | { | |
438 | m_widget = NULL; | |
439 | } | |
440 | ||
441 | int wxGnomePrintDialog::ShowModal() | |
442 | { | |
443 | // Transfer data from m_printDalogData to dialog here | |
444 | ||
445 | int response = gtk_dialog_run (GTK_DIALOG (m_widget)); | |
446 | ||
447 | if (response == GNOME_PRINT_DIALOG_RESPONSE_CANCEL) | |
448 | { | |
449 | gtk_widget_destroy(m_widget); | |
450 | m_widget = NULL; | |
451 | ||
452 | return wxID_CANCEL; | |
453 | } | |
454 | ||
455 | gint copies = 1; | |
456 | gboolean collate = false; | |
457 | gs_lgp->gnome_print_dialog_get_copies( (GnomePrintDialog*) m_widget, &copies, &collate ); | |
458 | m_printDialogData.SetNoCopies( copies ); | |
459 | m_printDialogData.SetCollate( collate ); | |
460 | ||
461 | switch (gs_lgp->gnome_print_dialog_get_range( (GnomePrintDialog*) m_widget )) | |
462 | { | |
463 | case GNOME_PRINT_RANGE_SELECTION: | |
464 | m_printDialogData.SetSelection( true ); | |
465 | break; | |
466 | case GNOME_PRINT_RANGE_ALL: | |
467 | m_printDialogData.SetAllPages( true ); | |
468 | m_printDialogData.SetFromPage( 0 ); | |
469 | m_printDialogData.SetToPage( 9999 ); | |
470 | break; | |
471 | case GNOME_PRINT_RANGE_RANGE: | |
472 | default: | |
473 | gint start,end; | |
474 | gs_lgp->gnome_print_dialog_get_range_page( (GnomePrintDialog*) m_widget, &start, &end ); | |
475 | m_printDialogData.SetFromPage( start ); | |
476 | m_printDialogData.SetToPage( end ); | |
477 | break; | |
478 | } | |
479 | ||
480 | gtk_widget_destroy(m_widget); | |
481 | m_widget = NULL; | |
482 | ||
483 | if (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW) | |
484 | return wxID_PREVIEW; | |
485 | ||
486 | return wxID_OK; | |
487 | } | |
488 | ||
489 | wxDC *wxGnomePrintDialog::GetPrintDC() | |
490 | { | |
491 | // Later | |
492 | return NULL; | |
493 | } | |
494 | ||
495 | bool wxGnomePrintDialog::Validate() | |
496 | { | |
497 | return true; | |
498 | } | |
499 | ||
500 | bool wxGnomePrintDialog::TransferDataToWindow() | |
501 | { | |
502 | return true; | |
503 | } | |
504 | ||
505 | bool wxGnomePrintDialog::TransferDataFromWindow() | |
506 | { | |
507 | return true; | |
508 | } | |
509 | ||
510 | //---------------------------------------------------------------------------- | |
511 | // wxGnomePageSetupDialog | |
512 | //---------------------------------------------------------------------------- | |
513 | ||
514 | IMPLEMENT_CLASS(wxGnomePageSetupDialog, wxPageSetupDialogBase) | |
515 | ||
516 | wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow *parent, | |
517 | wxPageSetupDialogData* data ) | |
518 | { | |
519 | if (data) | |
520 | m_pageDialogData = *data; | |
521 | ||
522 | wxGnomePrintNativeData *native = | |
523 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
524 | ||
525 | // This is required as the page setup dialog | |
526 | // calculates wrong values otherwise. | |
527 | gs_lgp->gnome_print_config_set( native->GetPrintConfig(), | |
528 | (const guchar*) GNOME_PRINT_KEY_PREFERED_UNIT, | |
529 | (const guchar*) "Pts" ); | |
530 | ||
531 | m_widget = gtk_dialog_new(); | |
532 | ||
533 | gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( _("Page setup") ) ); | |
534 | ||
535 | GtkWidget *main = gs_lgp->gnome_paper_selector_new_with_flags( native->GetPrintConfig(), | |
536 | GNOME_PAPER_SELECTOR_MARGINS|GNOME_PAPER_SELECTOR_FEED_ORIENTATION ); | |
537 | gtk_container_set_border_width (GTK_CONTAINER (main), 8); | |
538 | gtk_widget_show (main); | |
539 | ||
540 | gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget)->vbox), main ); | |
541 | ||
542 | gtk_dialog_set_has_separator (GTK_DIALOG (m_widget), TRUE); | |
543 | ||
544 | gtk_dialog_add_buttons (GTK_DIALOG (m_widget), | |
545 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
546 | GTK_STOCK_OK, GTK_RESPONSE_OK, | |
547 | NULL); | |
548 | ||
549 | gtk_dialog_set_default_response (GTK_DIALOG (m_widget), | |
550 | GTK_RESPONSE_OK); | |
551 | } | |
552 | ||
553 | wxGnomePageSetupDialog::~wxGnomePageSetupDialog() | |
554 | { | |
555 | } | |
556 | ||
557 | wxPageSetupDialogData& wxGnomePageSetupDialog::GetPageSetupDialogData() | |
558 | { | |
559 | return m_pageDialogData; | |
560 | } | |
561 | ||
562 | int wxGnomePageSetupDialog::ShowModal() | |
563 | { | |
564 | wxGnomePrintNativeData *native = | |
565 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
566 | GnomePrintConfig *config = native->GetPrintConfig(); | |
567 | ||
568 | // Transfer data from m_pageDialogData to native dialog | |
569 | ||
570 | int ret = gtk_dialog_run( GTK_DIALOG(m_widget) ); | |
571 | ||
572 | if (ret == GTK_RESPONSE_OK) | |
573 | { | |
574 | // Transfer data back to m_pageDialogData | |
575 | ||
576 | // I don't know how querying the last parameter works | |
577 | // I cannot test it as the dialog is currently broken | |
578 | // anyways (it only works for points). | |
579 | double ml,mr,mt,mb,pw,ph; | |
580 | gs_lgp->gnome_print_config_get_length (config, | |
581 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &ml, NULL); | |
582 | gs_lgp->gnome_print_config_get_length (config, | |
583 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &mr, NULL); | |
584 | gs_lgp->gnome_print_config_get_length (config, | |
585 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &mt, NULL); | |
586 | gs_lgp->gnome_print_config_get_length (config, | |
587 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &mb, NULL); | |
588 | gs_lgp->gnome_print_config_get_length (config, | |
589 | (const guchar*) GNOME_PRINT_KEY_PAPER_WIDTH, &pw, NULL); | |
590 | gs_lgp->gnome_print_config_get_length (config, | |
591 | (const guchar*) GNOME_PRINT_KEY_PAPER_HEIGHT, &ph, NULL); | |
592 | ||
593 | // This probably assumes that the user entered the | |
594 | // values in Pts. Since that is the only the dialog | |
595 | // works right now, we need to fix this later. | |
596 | const GnomePrintUnit *mm_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); | |
597 | const GnomePrintUnit *pts_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
598 | gs_lgp->gnome_print_convert_distance( &ml, pts_unit, mm_unit ); | |
599 | gs_lgp->gnome_print_convert_distance( &mr, pts_unit, mm_unit ); | |
600 | gs_lgp->gnome_print_convert_distance( &mt, pts_unit, mm_unit ); | |
601 | gs_lgp->gnome_print_convert_distance( &mb, pts_unit, mm_unit ); | |
602 | gs_lgp->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
603 | gs_lgp->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
604 | ||
605 | m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) ); | |
606 | m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) ); | |
607 | ||
608 | m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) ); | |
609 | ||
610 | #if 0 | |
611 | wxPrintf( wxT("paper %d %d, top margin %d\n"), | |
612 | m_pageDialogData.GetPaperSize().x, | |
613 | m_pageDialogData.GetPaperSize().y, | |
614 | m_pageDialogData.GetMarginTopLeft().x ); | |
615 | #endif | |
616 | ||
617 | ret = wxID_OK; | |
618 | } | |
619 | else | |
620 | { | |
621 | ret = wxID_CANCEL; | |
622 | } | |
623 | ||
624 | gtk_widget_destroy( m_widget ); | |
625 | m_widget = NULL; | |
626 | ||
627 | return ret; | |
628 | } | |
629 | ||
630 | bool wxGnomePageSetupDialog::Validate() | |
631 | { | |
632 | return true; | |
633 | } | |
634 | ||
635 | bool wxGnomePageSetupDialog::TransferDataToWindow() | |
636 | { | |
637 | return true; | |
638 | } | |
639 | ||
640 | bool wxGnomePageSetupDialog::TransferDataFromWindow() | |
641 | { | |
642 | return true; | |
643 | } | |
644 | ||
645 | //---------------------------------------------------------------------------- | |
646 | // wxGnomePrinter | |
647 | //---------------------------------------------------------------------------- | |
648 | ||
649 | IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase) | |
650 | ||
651 | wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) : | |
652 | wxPrinterBase( data ) | |
653 | { | |
654 | m_gpc = NULL; | |
655 | m_native_preview = false; | |
656 | } | |
657 | ||
658 | wxGnomePrinter::~wxGnomePrinter() | |
659 | { | |
660 | } | |
661 | ||
662 | bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) | |
663 | { | |
664 | if (!printout) | |
665 | { | |
666 | sm_lastError = wxPRINTER_ERROR; | |
667 | return false; | |
668 | } | |
669 | ||
670 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); | |
671 | wxGnomePrintNativeData *native = | |
672 | (wxGnomePrintNativeData*) printdata.GetNativeData(); | |
673 | ||
674 | GnomePrintJob *job = gs_lgp->gnome_print_job_new( native->GetPrintConfig() ); | |
675 | m_gpc = gs_lgp->gnome_print_job_get_context (job); | |
676 | ||
677 | // The GnomePrintJob is temporarily stored in the | |
678 | // native print data as the native print dialog | |
679 | // needs to access it. | |
680 | native->SetPrintJob( job ); | |
681 | ||
682 | ||
683 | printout->SetIsPreview(false); | |
684 | ||
685 | if (m_printDialogData.GetMinPage() < 1) | |
686 | m_printDialogData.SetMinPage(1); | |
687 | if (m_printDialogData.GetMaxPage() < 1) | |
688 | m_printDialogData.SetMaxPage(9999); | |
689 | ||
690 | wxDC *dc; | |
691 | if (prompt) | |
692 | dc = PrintDialog( parent ); | |
693 | else | |
694 | dc = new wxGnomePrintDC( this ); | |
695 | ||
696 | if (m_native_preview) | |
697 | printout->SetIsPreview(true); | |
698 | ||
699 | if (!dc) | |
700 | { | |
701 | gs_lgp->gnome_print_job_close( job ); | |
702 | g_object_unref (G_OBJECT (job)); | |
703 | sm_lastError = wxPRINTER_ERROR; | |
704 | return false; | |
705 | } | |
706 | ||
707 | wxSize ScreenPixels = wxGetDisplaySize(); | |
708 | wxSize ScreenMM = wxGetDisplaySizeMM(); | |
709 | ||
710 | printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), | |
711 | (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); | |
712 | printout->SetPPIPrinter( wxGnomePrintDC::GetResolution(), | |
713 | wxGnomePrintDC::GetResolution() ); | |
714 | ||
715 | printout->SetDC(dc); | |
716 | ||
717 | int w, h; | |
718 | dc->GetSize(&w, &h); | |
719 | printout->SetPageSizePixels((int)w, (int)h); | |
720 | dc->GetSizeMM(&w, &h); | |
721 | printout->SetPageSizeMM((int)w, (int)h); | |
722 | ||
723 | printout->OnPreparePrinting(); | |
724 | ||
725 | // Get some parameters from the printout, if defined | |
726 | int fromPage, toPage; | |
727 | int minPage, maxPage; | |
728 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
729 | ||
730 | if (maxPage == 0) | |
731 | { | |
732 | gs_lgp->gnome_print_job_close( job ); | |
733 | g_object_unref (G_OBJECT (job)); | |
734 | sm_lastError = wxPRINTER_ERROR; | |
735 | return false; | |
736 | } | |
737 | ||
738 | printout->OnBeginPrinting(); | |
739 | ||
740 | int minPageNum = minPage, maxPageNum = maxPage; | |
741 | ||
742 | if ( !m_printDialogData.GetAllPages() ) | |
743 | { | |
744 | minPageNum = m_printDialogData.GetFromPage(); | |
745 | maxPageNum = m_printDialogData.GetToPage(); | |
746 | } | |
747 | ||
748 | ||
749 | int copyCount; | |
750 | for ( copyCount = 1; | |
751 | copyCount <= m_printDialogData.GetNoCopies(); | |
752 | copyCount++ ) | |
753 | { | |
754 | if (!printout->OnBeginDocument(minPageNum, maxPageNum)) | |
755 | { | |
756 | wxLogError(_("Could not start printing.")); | |
757 | sm_lastError = wxPRINTER_ERROR; | |
758 | break; | |
759 | } | |
760 | ||
761 | int pn; | |
762 | for ( pn = minPageNum; | |
763 | pn <= maxPageNum && printout->HasPage(pn); | |
764 | pn++ ) | |
765 | { | |
766 | dc->StartPage(); | |
767 | printout->OnPrintPage(pn); | |
768 | dc->EndPage(); | |
769 | } | |
770 | ||
771 | printout->OnEndDocument(); | |
772 | printout->OnEndPrinting(); | |
773 | } | |
774 | ||
775 | gs_lgp->gnome_print_job_close( job ); | |
776 | if (m_native_preview) | |
777 | { | |
778 | wxString title( _("Print preview") ); | |
779 | gtk_widget_show( gs_lgp->gnome_print_job_preview_new( job, (const guchar*)(const char*)wxGTK_CONV(title) )); | |
780 | } | |
781 | else | |
782 | { | |
783 | gs_lgp->gnome_print_job_print( job ); | |
784 | } | |
785 | ||
786 | g_object_unref (G_OBJECT (job)); | |
787 | delete dc; | |
788 | ||
789 | return (sm_lastError == wxPRINTER_NO_ERROR); | |
790 | } | |
791 | ||
792 | wxDC* wxGnomePrinter::PrintDialog( wxWindow *parent ) | |
793 | { | |
794 | wxGnomePrintDialog dialog( parent, &m_printDialogData ); | |
795 | int ret = dialog.ShowModal(); | |
796 | if (ret == wxID_CANCEL) | |
797 | { | |
798 | sm_lastError = wxPRINTER_CANCELLED; | |
799 | return NULL; | |
800 | } | |
801 | ||
802 | m_native_preview = ret == wxID_PREVIEW; | |
803 | ||
804 | m_printDialogData = dialog.GetPrintDialogData(); | |
805 | return new wxGnomePrintDC( this ); | |
806 | } | |
807 | ||
808 | bool wxGnomePrinter::Setup( wxWindow *parent ) | |
809 | { | |
810 | return false; | |
811 | } | |
812 | ||
813 | //----------------------------------------------------------------------------- | |
814 | // wxGnomePrintDC | |
815 | //----------------------------------------------------------------------------- | |
816 | ||
817 | IMPLEMENT_CLASS(wxGnomePrintDC, wxDC) | |
818 | ||
819 | wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter *printer ) | |
820 | { | |
821 | m_printer = printer; | |
822 | ||
823 | m_gpc = printer->GetPrintContext(); | |
824 | ||
825 | m_layout = gs_lgp->gnome_print_pango_create_layout( m_gpc ); | |
826 | m_fontdesc = pango_font_description_from_string( "Sans 12" ); | |
827 | ||
828 | m_currentRed = 0; | |
829 | m_currentBlue = 0; | |
830 | m_currentGreen = 0; | |
831 | ||
832 | m_signX = 1; // default x-axis left to right | |
833 | m_signY = -1; // default y-axis bottom up -> top down | |
834 | } | |
835 | ||
836 | wxGnomePrintDC::~wxGnomePrintDC() | |
837 | { | |
838 | } | |
839 | ||
840 | bool wxGnomePrintDC::Ok() const | |
841 | { | |
842 | return true; | |
843 | } | |
844 | ||
845 | bool wxGnomePrintDC::DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style ) | |
846 | { | |
847 | return false; | |
848 | } | |
849 | ||
850 | bool wxGnomePrintDC::DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const | |
851 | { | |
852 | return false; | |
853 | } | |
854 | ||
855 | void wxGnomePrintDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
856 | { | |
857 | if (m_pen.GetStyle() == wxTRANSPARENT) return; | |
858 | ||
859 | SetPen( m_pen ); | |
860 | ||
861 | gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) ); | |
862 | gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) ); | |
863 | gs_lgp->gnome_print_stroke ( m_gpc); | |
864 | ||
865 | CalcBoundingBox( x1, y1 ); | |
866 | CalcBoundingBox( x2, y2 ); | |
867 | } | |
868 | ||
869 | void wxGnomePrintDC::DoCrossHair(wxCoord x, wxCoord y) | |
870 | { | |
871 | } | |
872 | ||
873 | void wxGnomePrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) | |
874 | { | |
875 | } | |
876 | ||
877 | void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) | |
878 | { | |
879 | } | |
880 | ||
881 | void wxGnomePrintDC::DoDrawPoint(wxCoord x, wxCoord y) | |
882 | { | |
883 | } | |
884 | ||
885 | void wxGnomePrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) | |
886 | { | |
887 | if (m_pen.GetStyle() == wxTRANSPARENT) return; | |
888 | ||
889 | if (n <= 0) return; | |
890 | ||
891 | SetPen (m_pen); | |
892 | ||
893 | int i; | |
894 | for ( i =0; i<n ; i++ ) | |
895 | CalcBoundingBox( XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset)); | |
896 | ||
897 | gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) ); | |
898 | ||
899 | for (i = 1; i < n; i++) | |
900 | gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) ); | |
901 | ||
902 | gs_lgp->gnome_print_stroke ( m_gpc); | |
903 | } | |
904 | ||
905 | void wxGnomePrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
906 | { | |
907 | } | |
908 | ||
909 | void wxGnomePrintDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
910 | { | |
911 | } | |
912 | ||
913 | void wxGnomePrintDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
914 | { | |
915 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
916 | { | |
917 | SetBrush( m_brush ); | |
918 | ||
919 | gs_lgp->gnome_print_newpath( m_gpc ); | |
920 | gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
921 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
922 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
923 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
924 | gs_lgp->gnome_print_closepath( m_gpc ); | |
925 | gs_lgp->gnome_print_fill( m_gpc ); | |
926 | ||
927 | CalcBoundingBox( x, y ); | |
928 | CalcBoundingBox( x + width, y + height ); | |
929 | } | |
930 | ||
931 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
932 | { | |
933 | SetPen (m_pen); | |
934 | ||
935 | gs_lgp->gnome_print_newpath( m_gpc ); | |
936 | gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
937 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
938 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
939 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
940 | gs_lgp->gnome_print_closepath( m_gpc ); | |
941 | gs_lgp->gnome_print_stroke( m_gpc ); | |
942 | ||
943 | CalcBoundingBox( x, y ); | |
944 | CalcBoundingBox( x + width, y + height ); | |
945 | } | |
946 | } | |
947 | ||
948 | void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) | |
949 | { | |
950 | wxCoord rad = (wxCoord) radius; | |
951 | ||
952 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
953 | { | |
954 | SetBrush(m_brush); | |
955 | gs_lgp->gnome_print_newpath(m_gpc); | |
956 | gs_lgp->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
957 | gs_lgp->gnome_print_curveto(m_gpc, | |
958 | XLOG2DEV(x + rad),YLOG2DEV(y), | |
959 | XLOG2DEV(x),YLOG2DEV(y), | |
960 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
961 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); | |
962 | gs_lgp->gnome_print_curveto(m_gpc, | |
963 | XLOG2DEV(x),YLOG2DEV(y + height - rad), | |
964 | XLOG2DEV(x),YLOG2DEV(y + height), | |
965 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
966 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); | |
967 | gs_lgp->gnome_print_curveto(m_gpc, | |
968 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), | |
969 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
970 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
971 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); | |
972 | gs_lgp->gnome_print_curveto(m_gpc, | |
973 | XLOG2DEV(x + width),YLOG2DEV(y + rad), | |
974 | XLOG2DEV(x + width),YLOG2DEV(y), | |
975 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
976 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
977 | gs_lgp->gnome_print_closepath(m_gpc); | |
978 | gs_lgp->gnome_print_fill(m_gpc); | |
979 | ||
980 | CalcBoundingBox(x,y); | |
981 | CalcBoundingBox(x+width,y+height); | |
982 | } | |
983 | ||
984 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
985 | { | |
986 | SetPen(m_pen); | |
987 | gs_lgp->gnome_print_newpath(m_gpc); | |
988 | gs_lgp->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
989 | gs_lgp->gnome_print_curveto(m_gpc, | |
990 | XLOG2DEV(x + rad),YLOG2DEV(y), | |
991 | XLOG2DEV(x),YLOG2DEV(y), | |
992 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
993 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); | |
994 | gs_lgp->gnome_print_curveto(m_gpc, | |
995 | XLOG2DEV(x),YLOG2DEV(y + height - rad), | |
996 | XLOG2DEV(x),YLOG2DEV(y + height), | |
997 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
998 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); | |
999 | gs_lgp->gnome_print_curveto(m_gpc, | |
1000 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), | |
1001 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1002 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
1003 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); | |
1004 | gs_lgp->gnome_print_curveto(m_gpc, | |
1005 | XLOG2DEV(x + width),YLOG2DEV(y + rad), | |
1006 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1007 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
1008 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1009 | gs_lgp->gnome_print_closepath(m_gpc); | |
1010 | gs_lgp->gnome_print_stroke(m_gpc); | |
1011 | ||
1012 | CalcBoundingBox(x,y); | |
1013 | CalcBoundingBox(x+width,y+height); | |
1014 | } | |
1015 | } | |
1016 | ||
1017 | void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1018 | { | |
1019 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1020 | { | |
1021 | SetBrush( m_brush ); | |
1022 | ||
1023 | gs_lgp->gnome_print_newpath( m_gpc ); | |
1024 | gs_lgp->gnome_print_moveto( m_gpc, | |
1025 | XLOG2DEV(x), YLOG2DEV(y+height/2) ); | |
1026 | ||
1027 | // start with top half | |
1028 | gs_lgp->gnome_print_curveto( m_gpc, | |
1029 | XLOG2DEV(x), YLOG2DEV(y), | |
1030 | XLOG2DEV(x+width), YLOG2DEV(y), | |
1031 | XLOG2DEV(x+width), YLOG2DEV(y+height/2) ); | |
1032 | // lower half | |
1033 | gs_lgp->gnome_print_curveto( m_gpc, | |
1034 | XLOG2DEV(x+width), YLOG2DEV(y+height), | |
1035 | XLOG2DEV(x), YLOG2DEV(y+height), | |
1036 | XLOG2DEV(x), YLOG2DEV(y+height/2) ); | |
1037 | ||
1038 | gs_lgp->gnome_print_closepath( m_gpc ); | |
1039 | gs_lgp->gnome_print_fill( m_gpc ); | |
1040 | ||
1041 | CalcBoundingBox( x, y ); | |
1042 | CalcBoundingBox( x + width, y + height ); | |
1043 | } | |
1044 | ||
1045 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1046 | { | |
1047 | SetPen (m_pen); | |
1048 | ||
1049 | gs_lgp->gnome_print_newpath( m_gpc ); | |
1050 | gs_lgp->gnome_print_moveto( m_gpc, | |
1051 | XLOG2DEV(x), YLOG2DEV(y+height/2) ); | |
1052 | ||
1053 | // start with top half | |
1054 | gs_lgp->gnome_print_curveto( m_gpc, | |
1055 | XLOG2DEV(x), YLOG2DEV(y), | |
1056 | XLOG2DEV(x+width), YLOG2DEV(y), | |
1057 | XLOG2DEV(x+width), YLOG2DEV(y+height/2) ); | |
1058 | // lower half | |
1059 | gs_lgp->gnome_print_curveto( m_gpc, | |
1060 | XLOG2DEV(x+width), YLOG2DEV(y+height), | |
1061 | XLOG2DEV(x), YLOG2DEV(y+height), | |
1062 | XLOG2DEV(x), YLOG2DEV(y+height/2) ); | |
1063 | ||
1064 | gs_lgp->gnome_print_closepath( m_gpc ); | |
1065 | gs_lgp->gnome_print_stroke( m_gpc ); | |
1066 | ||
1067 | CalcBoundingBox( x, y ); | |
1068 | CalcBoundingBox( x + width, y + height ); | |
1069 | } | |
1070 | } | |
1071 | ||
1072 | void wxGnomePrintDC::DoDrawSpline(wxList *points) | |
1073 | { | |
1074 | } | |
1075 | ||
1076 | bool wxGnomePrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
1077 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask, | |
1078 | wxCoord xsrcMask, wxCoord ysrcMask) | |
1079 | { | |
1080 | return false; | |
1081 | } | |
1082 | ||
1083 | void wxGnomePrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) | |
1084 | { | |
1085 | DoDrawBitmap( icon, x, y, true ); | |
1086 | } | |
1087 | ||
1088 | void wxGnomePrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask ) | |
1089 | { | |
1090 | if (!bitmap.Ok()) return; | |
1091 | ||
1092 | if (bitmap.HasPixbuf()) | |
1093 | { | |
1094 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); | |
1095 | guchar *raw_image = gdk_pixbuf_get_pixels( pixbuf ); | |
1096 | bool has_alpha = gdk_pixbuf_get_has_alpha( pixbuf ); | |
1097 | int rowstride = gdk_pixbuf_get_rowstride( pixbuf ); | |
1098 | int height = gdk_pixbuf_get_height( pixbuf ); | |
1099 | int width = gdk_pixbuf_get_width( pixbuf ); | |
1100 | ||
1101 | gs_lgp->gnome_print_gsave( m_gpc ); | |
1102 | double matrix[6]; | |
1103 | matrix[0] = XLOG2DEVREL(width); | |
1104 | matrix[1] = 0; | |
1105 | matrix[2] = 0; | |
1106 | matrix[3] = YLOG2DEVREL(height); | |
1107 | matrix[4] = XLOG2DEV(x); | |
1108 | matrix[5] = YLOG2DEV(y+height); | |
1109 | gs_lgp->gnome_print_concat( m_gpc, matrix ); | |
1110 | gs_lgp->gnome_print_moveto( m_gpc, 0, 0 ); | |
1111 | if (has_alpha) | |
1112 | gs_lgp->gnome_print_rgbaimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); | |
1113 | else | |
1114 | gs_lgp->gnome_print_rgbimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); | |
1115 | gs_lgp->gnome_print_grestore( m_gpc ); | |
1116 | } | |
1117 | else | |
1118 | { | |
1119 | wxImage image = bitmap.ConvertToImage(); | |
1120 | ||
1121 | if (!image.Ok()) return; | |
1122 | ||
1123 | gs_lgp->gnome_print_gsave( m_gpc ); | |
1124 | double matrix[6]; | |
1125 | matrix[0] = XLOG2DEVREL(image.GetWidth()); | |
1126 | matrix[1] = 0; | |
1127 | matrix[2] = 0; | |
1128 | matrix[3] = YLOG2DEVREL(image.GetHeight()); | |
1129 | matrix[4] = XLOG2DEV(x); | |
1130 | matrix[5] = YLOG2DEV(y+image.GetHeight()); | |
1131 | gs_lgp->gnome_print_concat( m_gpc, matrix ); | |
1132 | gs_lgp->gnome_print_moveto( m_gpc, 0, 0 ); | |
1133 | gs_lgp->gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 ); | |
1134 | gs_lgp->gnome_print_grestore( m_gpc ); | |
1135 | } | |
1136 | } | |
1137 | ||
1138 | void wxGnomePrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y ) | |
1139 | { | |
1140 | DoDrawRotatedText( text, x, y, 0.0 ); | |
1141 | } | |
1142 | ||
1143 | void wxGnomePrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) | |
1144 | { | |
1145 | x = XLOG2DEV(x); | |
1146 | y = YLOG2DEV(y); | |
1147 | ||
1148 | bool underlined = m_font.Ok() && m_font.GetUnderlined(); | |
1149 | ||
1150 | #if wxUSE_UNICODE | |
1151 | const wxCharBuffer data = wxConvUTF8.cWC2MB( text ); | |
1152 | #else | |
1153 | const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text ); | |
1154 | if ( !wdata ) | |
1155 | return; | |
1156 | const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); | |
1157 | #endif | |
1158 | ||
1159 | size_t datalen = strlen((const char*)data); | |
1160 | pango_layout_set_text( m_layout, (const char*) data, datalen); | |
1161 | ||
1162 | if (underlined) | |
1163 | { | |
1164 | PangoAttrList *attrs = pango_attr_list_new(); | |
1165 | PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); | |
1166 | a->start_index = 0; | |
1167 | a->end_index = datalen; | |
1168 | pango_attr_list_insert(attrs, a); | |
1169 | pango_layout_set_attributes(m_layout, attrs); | |
1170 | pango_attr_list_unref(attrs); | |
1171 | } | |
1172 | ||
1173 | if (m_textForegroundColour.Ok()) | |
1174 | { | |
1175 | unsigned char red = m_textForegroundColour.Red(); | |
1176 | unsigned char blue = m_textForegroundColour.Blue(); | |
1177 | unsigned char green = m_textForegroundColour.Green(); | |
1178 | ||
1179 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1180 | { | |
1181 | double redPS = (double)(red) / 255.0; | |
1182 | double bluePS = (double)(blue) / 255.0; | |
1183 | double greenPS = (double)(green) / 255.0; | |
1184 | ||
1185 | gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); | |
1186 | ||
1187 | m_currentRed = red; | |
1188 | m_currentBlue = blue; | |
1189 | m_currentGreen = green; | |
1190 | } | |
1191 | } | |
1192 | ||
1193 | int w,h; | |
1194 | ||
1195 | if (fabs(m_scaleY - 1.0) > 0.00001) | |
1196 | { | |
1197 | // If there is a user or actually any scale applied to | |
1198 | // the device context, scale the font. | |
1199 | ||
1200 | // scale font description | |
1201 | gint oldSize = pango_font_description_get_size( m_fontdesc ); | |
1202 | double size = oldSize; | |
1203 | size = size * m_scaleY; | |
1204 | pango_font_description_set_size( m_fontdesc, (gint)size ); | |
1205 | ||
1206 | // actually apply scaled font | |
1207 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1208 | ||
1209 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1210 | #if 0 | |
1211 | if ( m_backgroundMode == wxSOLID ) | |
1212 | { | |
1213 | gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); | |
1214 | gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h); | |
1215 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); | |
1216 | } | |
1217 | #endif | |
1218 | // Draw layout. | |
1219 | gs_lgp->gnome_print_moveto (m_gpc, x, y); | |
1220 | if (fabs(angle) > 0.00001) | |
1221 | { | |
1222 | gs_lgp->gnome_print_gsave( m_gpc ); | |
1223 | gs_lgp->gnome_print_rotate( m_gpc, angle ); | |
1224 | gs_lgp->gnome_print_pango_layout( m_gpc, m_layout ); | |
1225 | gs_lgp->gnome_print_grestore( m_gpc ); | |
1226 | } | |
1227 | else | |
1228 | { | |
1229 | gs_lgp->gnome_print_pango_layout( m_gpc, m_layout ); | |
1230 | } | |
1231 | ||
1232 | // reset unscaled size | |
1233 | pango_font_description_set_size( m_fontdesc, oldSize ); | |
1234 | ||
1235 | // actually apply unscaled font | |
1236 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1237 | } | |
1238 | else | |
1239 | { | |
1240 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1241 | #if 0 | |
1242 | if ( m_backgroundMode == wxSOLID ) | |
1243 | { | |
1244 | gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); | |
1245 | gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h); | |
1246 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); | |
1247 | } | |
1248 | #endif | |
1249 | // Draw layout. | |
1250 | gs_lgp->gnome_print_moveto (m_gpc, x, y); | |
1251 | if (fabs(angle) > 0.00001) | |
1252 | { | |
1253 | gs_lgp->gnome_print_gsave( m_gpc ); | |
1254 | gs_lgp->gnome_print_rotate( m_gpc, angle ); | |
1255 | gs_lgp->gnome_print_pango_layout( m_gpc, m_layout ); | |
1256 | gs_lgp->gnome_print_grestore( m_gpc ); | |
1257 | } | |
1258 | else | |
1259 | { | |
1260 | gs_lgp->gnome_print_pango_layout( m_gpc, m_layout ); | |
1261 | } | |
1262 | } | |
1263 | ||
1264 | if (underlined) | |
1265 | { | |
1266 | // undo underline attributes setting: | |
1267 | pango_layout_set_attributes(m_layout, NULL); | |
1268 | } | |
1269 | ||
1270 | CalcBoundingBox (x + w, y + h); | |
1271 | } | |
1272 | ||
1273 | void wxGnomePrintDC::Clear() | |
1274 | { | |
1275 | } | |
1276 | ||
1277 | void wxGnomePrintDC::SetFont( const wxFont& font ) | |
1278 | { | |
1279 | m_font = font; | |
1280 | ||
1281 | if (m_font.Ok()) | |
1282 | { | |
1283 | if (m_fontdesc) | |
1284 | pango_font_description_free( m_fontdesc ); | |
1285 | ||
1286 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); | |
1287 | ||
1288 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1289 | } | |
1290 | } | |
1291 | ||
1292 | void wxGnomePrintDC::SetPen( const wxPen& pen ) | |
1293 | { | |
1294 | if (!pen.Ok()) return; | |
1295 | ||
1296 | m_pen = pen; | |
1297 | ||
1298 | gs_lgp->gnome_print_setlinewidth( m_gpc, XLOG2DEVREL( 1000 * m_pen.GetWidth() ) / 1000.0f ); | |
1299 | ||
1300 | static const double dotted[] = {2.0, 5.0}; | |
1301 | static const double short_dashed[] = {4.0, 4.0}; | |
1302 | static const double wxCoord_dashed[] = {4.0, 8.0}; | |
1303 | static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0}; | |
1304 | ||
1305 | switch (m_pen.GetStyle()) | |
1306 | { | |
1307 | case wxDOT: gs_lgp->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break; | |
1308 | case wxSHORT_DASH: gs_lgp->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break; | |
1309 | case wxLONG_DASH: gs_lgp->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break; | |
1310 | case wxDOT_DASH: gs_lgp->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break; | |
1311 | case wxSOLID: | |
1312 | case wxTRANSPARENT: | |
1313 | default: gs_lgp->gnome_print_setdash( m_gpc, 0, NULL, 0 ); break; | |
1314 | } | |
1315 | ||
1316 | ||
1317 | unsigned char red = m_pen.GetColour().Red(); | |
1318 | unsigned char blue = m_pen.GetColour().Blue(); | |
1319 | unsigned char green = m_pen.GetColour().Green(); | |
1320 | ||
1321 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1322 | { | |
1323 | double redPS = (double)(red) / 255.0; | |
1324 | double bluePS = (double)(blue) / 255.0; | |
1325 | double greenPS = (double)(green) / 255.0; | |
1326 | ||
1327 | gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); | |
1328 | ||
1329 | m_currentRed = red; | |
1330 | m_currentBlue = blue; | |
1331 | m_currentGreen = green; | |
1332 | } | |
1333 | } | |
1334 | ||
1335 | void wxGnomePrintDC::SetBrush( const wxBrush& brush ) | |
1336 | { | |
1337 | if (!brush.Ok()) return; | |
1338 | ||
1339 | m_brush = brush; | |
1340 | ||
1341 | // Brush colour | |
1342 | unsigned char red = m_brush.GetColour().Red(); | |
1343 | unsigned char blue = m_brush.GetColour().Blue(); | |
1344 | unsigned char green = m_brush.GetColour().Green(); | |
1345 | ||
1346 | if (!m_colour) | |
1347 | { | |
1348 | // Anything not white is black | |
1349 | if (! (red == (unsigned char) 255 && | |
1350 | blue == (unsigned char) 255 && | |
1351 | green == (unsigned char) 255) ) | |
1352 | { | |
1353 | red = (unsigned char) 0; | |
1354 | green = (unsigned char) 0; | |
1355 | blue = (unsigned char) 0; | |
1356 | } | |
1357 | // setgray here ? | |
1358 | } | |
1359 | ||
1360 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1361 | { | |
1362 | double redPS = (double)(red) / 255.0; | |
1363 | double bluePS = (double)(blue) / 255.0; | |
1364 | double greenPS = (double)(green) / 255.0; | |
1365 | ||
1366 | gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); | |
1367 | ||
1368 | m_currentRed = red; | |
1369 | m_currentBlue = blue; | |
1370 | m_currentGreen = green; | |
1371 | } | |
1372 | } | |
1373 | ||
1374 | void wxGnomePrintDC::SetLogicalFunction( int function ) | |
1375 | { | |
1376 | } | |
1377 | ||
1378 | void wxGnomePrintDC::SetBackground( const wxBrush& brush ) | |
1379 | { | |
1380 | } | |
1381 | ||
1382 | void wxGnomePrintDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1383 | { | |
1384 | } | |
1385 | ||
1386 | void wxGnomePrintDC::DestroyClippingRegion() | |
1387 | { | |
1388 | } | |
1389 | ||
1390 | bool wxGnomePrintDC::StartDoc(const wxString& message) | |
1391 | { | |
1392 | SetDeviceOrigin( 0,0 ); | |
1393 | ||
1394 | return true; | |
1395 | } | |
1396 | ||
1397 | void wxGnomePrintDC::EndDoc() | |
1398 | { | |
1399 | gs_lgp->gnome_print_end_doc( m_gpc ); | |
1400 | } | |
1401 | ||
1402 | void wxGnomePrintDC::StartPage() | |
1403 | { | |
1404 | gs_lgp->gnome_print_beginpage( m_gpc, (const guchar*) "page" ); | |
1405 | } | |
1406 | ||
1407 | void wxGnomePrintDC::EndPage() | |
1408 | { | |
1409 | gs_lgp->gnome_print_showpage( m_gpc ); | |
1410 | } | |
1411 | ||
1412 | wxCoord wxGnomePrintDC::GetCharHeight() const | |
1413 | { | |
1414 | pango_layout_set_text( m_layout, "H", 1 ); | |
1415 | ||
1416 | int w,h; | |
1417 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1418 | ||
1419 | return h; | |
1420 | } | |
1421 | ||
1422 | wxCoord wxGnomePrintDC::GetCharWidth() const | |
1423 | { | |
1424 | pango_layout_set_text( m_layout, "H", 1 ); | |
1425 | ||
1426 | int w,h; | |
1427 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1428 | ||
1429 | return w; | |
1430 | } | |
1431 | ||
1432 | void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, | |
1433 | wxCoord *descent, | |
1434 | wxCoord *externalLeading, | |
1435 | wxFont *theFont ) const | |
1436 | { | |
1437 | if ( width ) | |
1438 | *width = 0; | |
1439 | if ( height ) | |
1440 | *height = 0; | |
1441 | if ( descent ) | |
1442 | *descent = 0; | |
1443 | if ( externalLeading ) | |
1444 | *externalLeading = 0; | |
1445 | ||
1446 | if (string.IsEmpty()) | |
1447 | { | |
1448 | return; | |
1449 | } | |
1450 | ||
1451 | // Set new font description | |
1452 | if (theFont) | |
1453 | pango_layout_set_font_description( m_layout, theFont->GetNativeFontInfo()->description ); | |
1454 | ||
1455 | // Set layout's text | |
1456 | #if wxUSE_UNICODE | |
1457 | const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); | |
1458 | const char *dataUTF8 = (const char *)data; | |
1459 | #else | |
1460 | const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string ); | |
1461 | if ( !wdata ) | |
1462 | { | |
1463 | if (width) (*width) = 0; | |
1464 | if (height) (*height) = 0; | |
1465 | return; | |
1466 | } | |
1467 | const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); | |
1468 | const char *dataUTF8 = (const char *)data; | |
1469 | #endif | |
1470 | ||
1471 | if ( !dataUTF8 ) | |
1472 | { | |
1473 | // hardly ideal, but what else can we do if conversion failed? | |
1474 | return; | |
1475 | } | |
1476 | ||
1477 | pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); | |
1478 | ||
1479 | int w,h; | |
1480 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1481 | ||
1482 | if (width) | |
1483 | *width = (wxCoord)(w / m_scaleX); | |
1484 | if (height) | |
1485 | *height = (wxCoord)(h / m_scaleY); | |
1486 | if (descent) | |
1487 | { | |
1488 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); | |
1489 | int baseline = pango_layout_iter_get_baseline(iter); | |
1490 | pango_layout_iter_free(iter); | |
1491 | *descent = h - PANGO_PIXELS(baseline); | |
1492 | } | |
1493 | ||
1494 | // Reset old font description | |
1495 | if (theFont) | |
1496 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1497 | } | |
1498 | ||
1499 | void wxGnomePrintDC::DoGetSize(int* width, int* height) const | |
1500 | { | |
1501 | wxGnomePrintNativeData *native = | |
1502 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1503 | ||
1504 | // Query page size. This seems to omit the margins | |
1505 | // right now, although it shouldn't | |
1506 | double pw,ph; | |
1507 | gs_lgp->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); | |
1508 | ||
1509 | if (width) | |
1510 | *width = (int) (pw + 0.5); | |
1511 | if (height) | |
1512 | *height = (int) (ph + 0.5); | |
1513 | } | |
1514 | ||
1515 | void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const | |
1516 | { | |
1517 | wxGnomePrintNativeData *native = | |
1518 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1519 | ||
1520 | // This code assumes values in Pts. | |
1521 | ||
1522 | double pw,ph; | |
1523 | gs_lgp->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); | |
1524 | ||
1525 | // Convert to mm. | |
1526 | ||
1527 | const GnomePrintUnit *mm_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); | |
1528 | const GnomePrintUnit *pts_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
1529 | gs_lgp->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
1530 | gs_lgp->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
1531 | ||
1532 | if (width) | |
1533 | *width = (int) (pw + 0.5); | |
1534 | if (height) | |
1535 | *height = (int) (ph + 0.5); | |
1536 | } | |
1537 | ||
1538 | wxSize wxGnomePrintDC::GetPPI() const | |
1539 | { | |
1540 | return wxSize(72,72); | |
1541 | } | |
1542 | ||
1543 | void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
1544 | { | |
1545 | m_signX = (xLeftRight ? 1 : -1); | |
1546 | m_signY = (yBottomUp ? 1 : -1); | |
1547 | ||
1548 | ComputeScaleAndOrigin(); | |
1549 | } | |
1550 | ||
1551 | void wxGnomePrintDC::SetDeviceOrigin( wxCoord x, wxCoord y ) | |
1552 | { | |
1553 | int h = 0; | |
1554 | int w = 0; | |
1555 | GetSize( &w, &h ); | |
1556 | ||
1557 | wxDC::SetDeviceOrigin( x, h-y ); | |
1558 | } | |
1559 | ||
1560 | void wxGnomePrintDC::SetResolution(int ppi) | |
1561 | { | |
1562 | } | |
1563 | ||
1564 | int wxGnomePrintDC::GetResolution() | |
1565 | { | |
1566 | return 72; | |
1567 | } | |
1568 | ||
1569 | ||
1570 | class wxGnomePrintModule: public wxModule | |
1571 | { | |
1572 | public: | |
1573 | wxGnomePrintModule() {} | |
1574 | bool OnInit(); | |
1575 | void OnExit(); | |
1576 | ||
1577 | private: | |
1578 | DECLARE_DYNAMIC_CLASS(wxGnomePrintModule) | |
1579 | }; | |
1580 | ||
1581 | bool wxGnomePrintModule::OnInit() | |
1582 | { | |
1583 | gs_lgp = new wxGnomePrintLibrary; | |
1584 | if (gs_lgp->IsOk()) | |
1585 | wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory ); | |
1586 | return true; | |
1587 | } | |
1588 | ||
1589 | void wxGnomePrintModule::OnExit() | |
1590 | { | |
1591 | delete gs_lgp; | |
1592 | } | |
1593 | ||
1594 | IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule) | |
1595 | ||
1596 | #endif | |
1597 | // wxUSE_LIBGNOMEPRINT |