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