]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/gtk/gnome/gprint.cpp | |
3 | // Author: Robert Roebling | |
4 | // Purpose: Implement GNOME printing support | |
5 | // Created: 09/20/04 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: Robert Roebling | |
8 | // Licence: wxWindows Licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // For compilers that support precompilation, includes "wx/wx.h". | |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | #if wxUSE_LIBGNOMEPRINT | |
19 | ||
20 | #include "wx/gtk/gnome/gprint.h" | |
21 | ||
22 | #ifndef WX_PRECOMP | |
23 | #include "wx/log.h" | |
24 | #include "wx/dcmemory.h" | |
25 | #include "wx/icon.h" | |
26 | #include "wx/math.h" | |
27 | #include "wx/image.h" | |
28 | #include "wx/module.h" | |
29 | #include "wx/crt.h" | |
30 | #endif | |
31 | ||
32 | #include "wx/fontutil.h" | |
33 | #include "wx/gtk/private.h" | |
34 | #include "wx/dynlib.h" | |
35 | #include "wx/paper.h" | |
36 | ||
37 | #include <libgnomeprint/gnome-print.h> | |
38 | #include <libgnomeprint/gnome-print-pango.h> | |
39 | #include <libgnomeprint/gnome-print-config.h> | |
40 | #include <libgnomeprintui/gnome-print-dialog.h> | |
41 | #include <libgnomeprintui/gnome-print-job-preview.h> | |
42 | #include <libgnomeprintui/gnome-print-paper-selector.h> | |
43 | ||
44 | #include "wx/link.h" | |
45 | wxFORCE_LINK_THIS_MODULE(gnome_print) | |
46 | ||
47 | //---------------------------------------------------------------------------- | |
48 | // wxGnomePrintLibrary | |
49 | //---------------------------------------------------------------------------- | |
50 | ||
51 | class wxGnomePrintLibrary | |
52 | { | |
53 | public: | |
54 | wxGnomePrintLibrary(); | |
55 | ~wxGnomePrintLibrary(); | |
56 | ||
57 | bool IsOk(); | |
58 | private: | |
59 | bool InitializeMethods(); | |
60 | ||
61 | wxDynamicLibrary m_libGnomePrint; | |
62 | wxDynamicLibrary m_libGnomePrintUI; | |
63 | ||
64 | // only true if we successfully loaded both libraries | |
65 | // | |
66 | // don't rename this field, it's used by wxDL_XXX macros internally | |
67 | bool m_ok; | |
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_arcto, | |
77 | (GnomePrintContext *pc, gdouble x, gdouble y, gdouble radius, gdouble angle1, gdouble angle2, gint direction ), (pc, x, y, radius, angle1, angle2, direction), 0 ) | |
78 | wxDL_METHOD_DEFINE( gint, gnome_print_curveto, | |
79 | (GnomePrintContext *pc, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble x3, gdouble y3), (pc, x1, y1, x2, y2, x3, y3), 0 ) | |
80 | wxDL_METHOD_DEFINE( gint, gnome_print_closepath, | |
81 | (GnomePrintContext *pc), (pc), 0 ) | |
82 | wxDL_METHOD_DEFINE( gint, gnome_print_stroke, | |
83 | (GnomePrintContext *pc), (pc), 0 ) | |
84 | wxDL_METHOD_DEFINE( gint, gnome_print_fill, | |
85 | (GnomePrintContext *pc), (pc), 0 ) | |
86 | wxDL_METHOD_DEFINE( gint, gnome_print_setrgbcolor, | |
87 | (GnomePrintContext *pc, gdouble r, gdouble g, gdouble b), (pc, r, g, b), 0 ) | |
88 | wxDL_METHOD_DEFINE( gint, gnome_print_setlinewidth, | |
89 | (GnomePrintContext *pc, gdouble width), (pc, width), 0 ) | |
90 | wxDL_METHOD_DEFINE( gint, gnome_print_setdash, | |
91 | (GnomePrintContext *pc, gint n_values, const gdouble *values, gdouble offset), (pc, n_values, values, offset), 0 ) | |
92 | ||
93 | wxDL_METHOD_DEFINE( gint, gnome_print_rgbimage, | |
94 | (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 ) | |
95 | wxDL_METHOD_DEFINE( gint, gnome_print_rgbaimage, | |
96 | (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 ) | |
97 | ||
98 | wxDL_METHOD_DEFINE( gint, gnome_print_concat, | |
99 | (GnomePrintContext *pc, const gdouble *matrix), (pc, matrix), 0 ) | |
100 | wxDL_METHOD_DEFINE( gint, gnome_print_scale, | |
101 | (GnomePrintContext *pc, gdouble sx, gdouble sy), (pc, sx, sy), 0 ) | |
102 | wxDL_METHOD_DEFINE( gint, gnome_print_rotate, | |
103 | (GnomePrintContext *pc, gdouble theta), (pc, theta), 0 ) | |
104 | wxDL_METHOD_DEFINE( gint, gnome_print_translate, | |
105 | (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 ) | |
106 | ||
107 | wxDL_METHOD_DEFINE( gint, gnome_print_gsave, | |
108 | (GnomePrintContext *pc), (pc), 0 ) | |
109 | wxDL_METHOD_DEFINE( gint, gnome_print_grestore, | |
110 | (GnomePrintContext *pc), (pc), 0 ) | |
111 | ||
112 | wxDL_METHOD_DEFINE( gint, gnome_print_clip, | |
113 | (GnomePrintContext *pc), (pc), 0 ) | |
114 | wxDL_METHOD_DEFINE( gint, gnome_print_eoclip, | |
115 | (GnomePrintContext *pc), (pc), 0 ) | |
116 | ||
117 | wxDL_METHOD_DEFINE( gint, gnome_print_beginpage, | |
118 | (GnomePrintContext *pc, const guchar* name), (pc, name), 0 ) | |
119 | wxDL_METHOD_DEFINE( gint, gnome_print_showpage, | |
120 | (GnomePrintContext *pc), (pc), 0 ) | |
121 | wxDL_METHOD_DEFINE( gint, gnome_print_end_doc, | |
122 | (GnomePrintContext *pc), (pc), 0 ) | |
123 | ||
124 | wxDL_METHOD_DEFINE( PangoLayout*, gnome_print_pango_create_layout, | |
125 | (GnomePrintContext *gpc), (gpc), NULL ) | |
126 | wxDL_VOIDMETHOD_DEFINE( gnome_print_pango_layout, | |
127 | (GnomePrintContext *gpc, PangoLayout *layout), (gpc, layout) ) | |
128 | ||
129 | wxDL_METHOD_DEFINE( GnomePrintJob*, gnome_print_job_new, | |
130 | (GnomePrintConfig *config), (config), NULL ) | |
131 | wxDL_METHOD_DEFINE( GnomePrintContext*, gnome_print_job_get_context, | |
132 | (GnomePrintJob *job), (job), NULL ) | |
133 | wxDL_METHOD_DEFINE( gint, gnome_print_job_close, | |
134 | (GnomePrintJob *job), (job), 0 ) | |
135 | wxDL_METHOD_DEFINE( gint, gnome_print_job_print, | |
136 | (GnomePrintJob *job), (job), 0 ) | |
137 | wxDL_METHOD_DEFINE( gboolean, gnome_print_job_get_page_size, | |
138 | (GnomePrintJob *job, gdouble *width, gdouble *height), (job, width, height), 0 ) | |
139 | ||
140 | wxDL_METHOD_DEFINE( GnomePrintUnit*, gnome_print_unit_get_by_abbreviation, | |
141 | (const guchar *abbreviation), (abbreviation), NULL ) | |
142 | wxDL_METHOD_DEFINE( gboolean, gnome_print_convert_distance, | |
143 | (gdouble *distance, const GnomePrintUnit *from, const GnomePrintUnit *to), (distance, from, to), false ) | |
144 | ||
145 | wxDL_METHOD_DEFINE( GnomePrintConfig*, gnome_print_config_default, | |
146 | (void), (), NULL ) | |
147 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set, | |
148 | (GnomePrintConfig *config, const guchar *key, const guchar *value), (config, key, value), false ) | |
149 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set_double, | |
150 | (GnomePrintConfig *config, const guchar *key, gdouble value), (config, key, value), false ) | |
151 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set_int, | |
152 | (GnomePrintConfig *config, const guchar *key, gint value), (config, key, value), false ) | |
153 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set_boolean, | |
154 | (GnomePrintConfig *config, const guchar *key, gboolean value), (config, key, value), false ) | |
155 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set_length, | |
156 | (GnomePrintConfig *config, const guchar *key, gdouble value, const GnomePrintUnit *unit), (config, key, value, unit), false ) | |
157 | ||
158 | wxDL_METHOD_DEFINE( guchar*, gnome_print_config_get, | |
159 | (GnomePrintConfig *config, const guchar *key), (config, key), NULL ) | |
160 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_get_length, | |
161 | (GnomePrintConfig *config, const guchar *key, gdouble *val, const GnomePrintUnit **unit), (config, key, val, unit), false ) | |
162 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_get_boolean, | |
163 | (GnomePrintConfig *config, const guchar *key, gboolean *val), (config, key, val), false ) | |
164 | ||
165 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_dialog_new, | |
166 | (GnomePrintJob *gpj, const guchar *title, gint flags), (gpj, title, flags), NULL ) | |
167 | wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_construct_range_page, | |
168 | (GnomePrintDialog *gpd, gint flags, gint start, gint end, | |
169 | const guchar *currentlabel, const guchar *rangelabel), | |
170 | (gpd, flags, start, end, currentlabel, rangelabel) ) | |
171 | wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_get_copies, | |
172 | (GnomePrintDialog *gpd, gint *copies, gboolean *collate), (gpd, copies, collate) ) | |
173 | wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_set_copies, | |
174 | (GnomePrintDialog *gpd, gint copies, gint collate), (gpd, copies, collate) ) | |
175 | wxDL_METHOD_DEFINE( GnomePrintRangeType, gnome_print_dialog_get_range, | |
176 | (GnomePrintDialog *gpd), (gpd), GNOME_PRINT_RANGETYPE_NONE ) | |
177 | wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page, | |
178 | (GnomePrintDialog *gpd, gint *start, gint *end), (gpd, start, end), 0 ) | |
179 | ||
180 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_paper_selector_new_with_flags, | |
181 | (GnomePrintConfig *config, gint flags), (config, flags), NULL ) | |
182 | ||
183 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_job_preview_new, | |
184 | (GnomePrintJob *gpm, const guchar *title), (gpm, title), NULL ) | |
185 | ||
186 | DECLARE_NO_COPY_CLASS(wxGnomePrintLibrary) | |
187 | }; | |
188 | ||
189 | wxGnomePrintLibrary::wxGnomePrintLibrary() | |
190 | { | |
191 | wxLogNull log; | |
192 | ||
193 | m_libGnomePrint.Load("libgnomeprint-2-2.so.0"); | |
194 | m_ok = m_libGnomePrint.IsLoaded(); | |
195 | if ( !m_ok ) | |
196 | return; | |
197 | ||
198 | m_libGnomePrintUI.Load("libgnomeprintui-2-2.so.0"); | |
199 | m_ok = m_libGnomePrintUI.IsLoaded(); | |
200 | if ( !m_ok ) | |
201 | { | |
202 | m_libGnomePrint.Unload(); | |
203 | return; | |
204 | } | |
205 | ||
206 | m_ok = InitializeMethods(); | |
207 | } | |
208 | ||
209 | wxGnomePrintLibrary::~wxGnomePrintLibrary() | |
210 | { | |
211 | } | |
212 | ||
213 | bool wxGnomePrintLibrary::IsOk() | |
214 | { | |
215 | return m_ok; | |
216 | } | |
217 | ||
218 | bool wxGnomePrintLibrary::InitializeMethods() | |
219 | { | |
220 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_newpath ); | |
221 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_moveto ); | |
222 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_lineto ); | |
223 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_curveto ); | |
224 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_arcto ); | |
225 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_closepath ); | |
226 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_stroke ); | |
227 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_fill ); | |
228 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_setrgbcolor ); | |
229 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_setlinewidth ); | |
230 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_setdash ); | |
231 | ||
232 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_rgbimage ); | |
233 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_rgbaimage ); | |
234 | ||
235 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_concat ); | |
236 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_scale ); | |
237 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_rotate ); | |
238 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_translate ); | |
239 | ||
240 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_gsave ); | |
241 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_grestore ); | |
242 | ||
243 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_clip ); | |
244 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_eoclip ); | |
245 | ||
246 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_beginpage ); | |
247 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_showpage ); | |
248 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_end_doc ); | |
249 | ||
250 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_pango_create_layout ); | |
251 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_pango_layout ); | |
252 | ||
253 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_new ); | |
254 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_get_context ); | |
255 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_close ); | |
256 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_print ); | |
257 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_get_page_size ); | |
258 | ||
259 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_unit_get_by_abbreviation ); | |
260 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_convert_distance ); | |
261 | ||
262 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_default ); | |
263 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set ); | |
264 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set_boolean ); | |
265 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set_double ); | |
266 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set_int ); | |
267 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set_length ); | |
268 | ||
269 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_get ); | |
270 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_get_length ); | |
271 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_get_boolean ); | |
272 | ||
273 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_new ); | |
274 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_construct_range_page ); | |
275 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_get_copies ); | |
276 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_set_copies ); | |
277 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_get_range ); | |
278 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_get_range_page ); | |
279 | ||
280 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_paper_selector_new_with_flags ); | |
281 | ||
282 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_job_preview_new ); | |
283 | ||
284 | return true; | |
285 | } | |
286 | ||
287 | static wxGnomePrintLibrary* gs_libGnomePrint = NULL; | |
288 | ||
289 | //---------------------------------------------------------------------------- | |
290 | // wxGnomePrintNativeData | |
291 | //---------------------------------------------------------------------------- | |
292 | ||
293 | IMPLEMENT_CLASS(wxGnomePrintNativeData, wxPrintNativeDataBase) | |
294 | ||
295 | wxGnomePrintNativeData::wxGnomePrintNativeData() | |
296 | { | |
297 | m_config = gs_libGnomePrint->gnome_print_config_default(); | |
298 | m_job = gs_libGnomePrint->gnome_print_job_new( m_config ); | |
299 | } | |
300 | ||
301 | wxGnomePrintNativeData::~wxGnomePrintNativeData() | |
302 | { | |
303 | g_object_unref (m_config); | |
304 | } | |
305 | ||
306 | bool wxGnomePrintNativeData::TransferTo( wxPrintData &data ) | |
307 | { | |
308 | guchar *res = gs_libGnomePrint->gnome_print_config_get( m_config, | |
309 | (guchar*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION ); | |
310 | if (g_ascii_strcasecmp((const gchar *)res,"R90") == 0) | |
311 | data.SetOrientation( wxLANDSCAPE ); | |
312 | else | |
313 | data.SetOrientation( wxPORTRAIT ); | |
314 | g_free( res ); | |
315 | ||
316 | res = gs_libGnomePrint->gnome_print_config_get( m_config, | |
317 | (guchar*)(char*)GNOME_PRINT_KEY_OUTPUT_FILENAME ); | |
318 | if (res) | |
319 | { | |
320 | data.SetFilename( wxConvFile.cMB2WX( (const char*) res ) ); | |
321 | wxPrintf( "filename %s\n", data.GetFilename() ); | |
322 | g_free( res ); | |
323 | } | |
324 | else | |
325 | { | |
326 | data.SetFilename( wxEmptyString ); | |
327 | } | |
328 | ||
329 | gboolean ret; | |
330 | if (gs_libGnomePrint->gnome_print_config_get_boolean( m_config, | |
331 | (guchar*)(char*)GNOME_PRINT_KEY_COLLATE, &ret)) | |
332 | { | |
333 | data.SetCollate( ret ); | |
334 | } | |
335 | ||
336 | // gnome_print_v | |
337 | ||
338 | return true; | |
339 | } | |
340 | ||
341 | bool wxGnomePrintNativeData::TransferFrom( const wxPrintData &data ) | |
342 | { | |
343 | if (data.GetOrientation() == wxLANDSCAPE) | |
344 | { | |
345 | gs_libGnomePrint->gnome_print_config_set( m_config, | |
346 | (guchar*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION, | |
347 | (guchar*)(char*)"R90" ); | |
348 | } | |
349 | else | |
350 | { | |
351 | gs_libGnomePrint->gnome_print_config_set( m_config, | |
352 | (guchar*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION, | |
353 | (guchar*)(char*)"R0" ); | |
354 | } | |
355 | ||
356 | if (data.GetCollate()) | |
357 | { | |
358 | gs_libGnomePrint->gnome_print_config_set_boolean( m_config, | |
359 | (guchar*)(char*)GNOME_PRINT_KEY_COLLATE, | |
360 | TRUE ); | |
361 | } | |
362 | else | |
363 | { | |
364 | gs_libGnomePrint->gnome_print_config_set_boolean( m_config, | |
365 | (guchar*)(char*)GNOME_PRINT_KEY_COLLATE, | |
366 | FALSE ); | |
367 | } | |
368 | ||
369 | switch (data.GetPaperId()) | |
370 | { | |
371 | case wxPAPER_A3: gs_libGnomePrint->gnome_print_config_set( m_config, | |
372 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, | |
373 | (guchar*)(char*)"A3" ); | |
374 | break; | |
375 | case wxPAPER_A5: gs_libGnomePrint->gnome_print_config_set( m_config, | |
376 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, | |
377 | (guchar*)(char*)"A5" ); | |
378 | break; | |
379 | case wxPAPER_B4: gs_libGnomePrint->gnome_print_config_set( m_config, | |
380 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, | |
381 | (guchar*)(char*)"B4" ); | |
382 | break; | |
383 | case wxPAPER_B5: gs_libGnomePrint->gnome_print_config_set( m_config, | |
384 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, | |
385 | (guchar*)(char*)"B5" ); | |
386 | break; | |
387 | case wxPAPER_LETTER: gs_libGnomePrint->gnome_print_config_set( m_config, | |
388 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, | |
389 | (guchar*)(char*)"USLetter" ); | |
390 | break; | |
391 | case wxPAPER_LEGAL: gs_libGnomePrint->gnome_print_config_set( m_config, | |
392 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, | |
393 | (guchar*)(char*)"USLegal" ); | |
394 | break; | |
395 | case wxPAPER_EXECUTIVE: gs_libGnomePrint->gnome_print_config_set( m_config, | |
396 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, | |
397 | (guchar*)(char*)"Executive" ); | |
398 | break; | |
399 | case wxPAPER_ENV_C5: gs_libGnomePrint->gnome_print_config_set( m_config, | |
400 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, | |
401 | (guchar*)(char*)"C5" ); | |
402 | break; | |
403 | case wxPAPER_ENV_C6: gs_libGnomePrint->gnome_print_config_set( m_config, | |
404 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, | |
405 | (guchar*)(char*)"C6" ); | |
406 | break; | |
407 | case wxPAPER_NONE: break; | |
408 | ||
409 | default: | |
410 | case wxPAPER_A4: gs_libGnomePrint->gnome_print_config_set( m_config, | |
411 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, | |
412 | (guchar*)(char*)"A4" ); | |
413 | break; | |
414 | } | |
415 | ||
416 | return true; | |
417 | } | |
418 | ||
419 | //---------------------------------------------------------------------------- | |
420 | // wxGnomePrintFactory | |
421 | //---------------------------------------------------------------------------- | |
422 | ||
423 | wxPrinterBase* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData *data ) | |
424 | { | |
425 | return new wxGnomePrinter( data ); | |
426 | } | |
427 | ||
428 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, | |
429 | wxPrintout *printout, | |
430 | wxPrintDialogData *data ) | |
431 | { | |
432 | return new wxGnomePrintPreview( preview, printout, data ); | |
433 | } | |
434 | ||
435 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, | |
436 | wxPrintout *printout, | |
437 | wxPrintData *data ) | |
438 | { | |
439 | return new wxGnomePrintPreview( preview, printout, data ); | |
440 | } | |
441 | ||
442 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, | |
443 | wxPrintDialogData *data ) | |
444 | { | |
445 | return new wxGnomePrintDialog( parent, data ); | |
446 | } | |
447 | ||
448 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, | |
449 | wxPrintData *data ) | |
450 | { | |
451 | return new wxGnomePrintDialog( parent, data ); | |
452 | } | |
453 | ||
454 | wxPageSetupDialogBase *wxGnomePrintFactory::CreatePageSetupDialog( wxWindow *parent, | |
455 | wxPageSetupDialogData * data ) | |
456 | { | |
457 | // The native page setup dialog is broken. It | |
458 | // miscalculates newly entered values for the | |
459 | // margins if you have not chose "points" but | |
460 | // e.g. centimerters. | |
461 | // This has been fixed in GNOME CVS (maybe | |
462 | // fixed in libgnomeprintui 2.8.1) | |
463 | ||
464 | return new wxGnomePageSetupDialog( parent, data ); | |
465 | } | |
466 | ||
467 | bool wxGnomePrintFactory::HasPrintSetupDialog() | |
468 | { | |
469 | return false; | |
470 | } | |
471 | ||
472 | wxDialog * | |
473 | wxGnomePrintFactory::CreatePrintSetupDialog(wxWindow * WXUNUSED(parent), | |
474 | wxPrintData * WXUNUSED(data)) | |
475 | { | |
476 | return NULL; | |
477 | } | |
478 | ||
479 | wxDC* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData& data ) | |
480 | { | |
481 | return new wxGnomePrinterDC(data); | |
482 | } | |
483 | ||
484 | bool wxGnomePrintFactory::HasOwnPrintToFile() | |
485 | { | |
486 | return true; | |
487 | } | |
488 | ||
489 | bool wxGnomePrintFactory::HasPrinterLine() | |
490 | { | |
491 | return true; | |
492 | } | |
493 | ||
494 | wxString wxGnomePrintFactory::CreatePrinterLine() | |
495 | { | |
496 | // redundant now | |
497 | return wxEmptyString; | |
498 | } | |
499 | ||
500 | bool wxGnomePrintFactory::HasStatusLine() | |
501 | { | |
502 | // redundant now | |
503 | return true; | |
504 | } | |
505 | ||
506 | wxString wxGnomePrintFactory::CreateStatusLine() | |
507 | { | |
508 | // redundant now | |
509 | return wxEmptyString; | |
510 | } | |
511 | ||
512 | wxPrintNativeDataBase *wxGnomePrintFactory::CreatePrintNativeData() | |
513 | { | |
514 | return new wxGnomePrintNativeData; | |
515 | } | |
516 | ||
517 | //---------------------------------------------------------------------------- | |
518 | // wxGnomePrintSetupDialog | |
519 | //---------------------------------------------------------------------------- | |
520 | ||
521 | IMPLEMENT_CLASS(wxGnomePrintDialog, wxPrintDialogBase) | |
522 | ||
523 | wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintDialogData *data ) | |
524 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
525 | wxPoint(0, 0), wxSize(600, 600), | |
526 | wxDEFAULT_DIALOG_STYLE | | |
527 | wxTAB_TRAVERSAL) | |
528 | { | |
529 | if (data) | |
530 | m_printDialogData = *data; | |
531 | ||
532 | Init(); | |
533 | } | |
534 | ||
535 | wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintData *data ) | |
536 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
537 | wxPoint(0, 0), wxSize(600, 600), | |
538 | wxDEFAULT_DIALOG_STYLE | | |
539 | wxTAB_TRAVERSAL) | |
540 | { | |
541 | if (data) | |
542 | m_printDialogData = *data; | |
543 | ||
544 | Init(); | |
545 | } | |
546 | ||
547 | void wxGnomePrintDialog::Init() | |
548 | { | |
549 | wxPrintData data = m_printDialogData.GetPrintData(); | |
550 | ||
551 | data.ConvertToNative(); | |
552 | ||
553 | wxGnomePrintNativeData *native = | |
554 | (wxGnomePrintNativeData*) data.GetNativeData(); | |
555 | ||
556 | m_widget = gs_libGnomePrint->gnome_print_dialog_new( native->GetPrintJob(), | |
557 | (guchar*)"Print", | |
558 | GNOME_PRINT_DIALOG_RANGE|GNOME_PRINT_DIALOG_COPIES ); | |
559 | ||
560 | int flag = 0; | |
561 | if (m_printDialogData.GetEnableSelection()) | |
562 | flag |= GNOME_PRINT_RANGE_SELECTION; | |
563 | if (m_printDialogData.GetEnablePageNumbers()) | |
564 | flag |= GNOME_PRINT_RANGE_ALL|GNOME_PRINT_RANGE_RANGE; | |
565 | ||
566 | gs_libGnomePrint->gnome_print_dialog_construct_range_page( (GnomePrintDialog*) m_widget, | |
567 | flag, | |
568 | m_printDialogData.GetMinPage(), | |
569 | m_printDialogData.GetMaxPage(), | |
570 | NULL, | |
571 | NULL ); | |
572 | } | |
573 | ||
574 | wxGnomePrintDialog::~wxGnomePrintDialog() | |
575 | { | |
576 | m_widget = NULL; | |
577 | } | |
578 | ||
579 | int wxGnomePrintDialog::ShowModal() | |
580 | { | |
581 | int response = gtk_dialog_run (GTK_DIALOG (m_widget)); | |
582 | ||
583 | if (response == GNOME_PRINT_DIALOG_RESPONSE_CANCEL) | |
584 | { | |
585 | gtk_widget_destroy(m_widget); | |
586 | m_widget = NULL; | |
587 | ||
588 | return wxID_CANCEL; | |
589 | } | |
590 | ||
591 | m_printDialogData.GetPrintData().ConvertFromNative(); | |
592 | ||
593 | gint copies = 1; | |
594 | gboolean collate = false; | |
595 | gs_libGnomePrint->gnome_print_dialog_get_copies( (GnomePrintDialog*) m_widget, &copies, &collate ); | |
596 | m_printDialogData.SetNoCopies( copies ); | |
597 | m_printDialogData.SetCollate( collate ); | |
598 | ||
599 | switch (gs_libGnomePrint->gnome_print_dialog_get_range( (GnomePrintDialog*) m_widget )) | |
600 | { | |
601 | case GNOME_PRINT_RANGE_SELECTION: | |
602 | m_printDialogData.SetSelection( true ); | |
603 | break; | |
604 | case GNOME_PRINT_RANGE_ALL: | |
605 | m_printDialogData.SetAllPages( true ); | |
606 | m_printDialogData.SetFromPage( 0 ); | |
607 | m_printDialogData.SetToPage( 9999 ); | |
608 | break; | |
609 | case GNOME_PRINT_RANGE_RANGE: | |
610 | default: | |
611 | gint start,end; | |
612 | gs_libGnomePrint->gnome_print_dialog_get_range_page( (GnomePrintDialog*) m_widget, &start, &end ); | |
613 | m_printDialogData.SetFromPage( start ); | |
614 | m_printDialogData.SetToPage( end ); | |
615 | break; | |
616 | } | |
617 | ||
618 | gtk_widget_destroy(m_widget); | |
619 | m_widget = NULL; | |
620 | ||
621 | if (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW) | |
622 | return wxID_PREVIEW; | |
623 | ||
624 | return wxID_OK; | |
625 | } | |
626 | ||
627 | wxDC *wxGnomePrintDialog::GetPrintDC() | |
628 | { | |
629 | // Later | |
630 | return NULL; | |
631 | } | |
632 | ||
633 | bool wxGnomePrintDialog::Validate() | |
634 | { | |
635 | return true; | |
636 | } | |
637 | ||
638 | bool wxGnomePrintDialog::TransferDataToWindow() | |
639 | { | |
640 | return true; | |
641 | } | |
642 | ||
643 | bool wxGnomePrintDialog::TransferDataFromWindow() | |
644 | { | |
645 | return true; | |
646 | } | |
647 | ||
648 | //---------------------------------------------------------------------------- | |
649 | // wxGnomePageSetupDialog | |
650 | //---------------------------------------------------------------------------- | |
651 | ||
652 | IMPLEMENT_CLASS(wxGnomePageSetupDialog, wxPageSetupDialogBase) | |
653 | ||
654 | wxGnomePageSetupDialog::wxGnomePageSetupDialog(wxWindow * WXUNUSED(parent), | |
655 | wxPageSetupDialogData *data) | |
656 | { | |
657 | if (data) | |
658 | m_pageDialogData = *data; | |
659 | ||
660 | m_pageDialogData.GetPrintData().ConvertToNative(); | |
661 | ||
662 | wxGnomePrintNativeData *native = | |
663 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
664 | ||
665 | // This *was* required as the page setup dialog | |
666 | // calculates wrong values otherwise. | |
667 | #if 0 | |
668 | gs_libGnomePrint->gnome_print_config_set( native->GetPrintConfig(), | |
669 | (const guchar*) GNOME_PRINT_KEY_PREFERED_UNIT, | |
670 | (const guchar*) "Pts" ); | |
671 | #endif | |
672 | ||
673 | GnomePrintConfig *config = native->GetPrintConfig(); | |
674 | ||
675 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); | |
676 | ||
677 | double ml = (double) m_pageDialogData.GetMarginTopLeft().x; | |
678 | double mt = (double) m_pageDialogData.GetMarginTopLeft().y; | |
679 | double mr = (double) m_pageDialogData.GetMarginBottomRight().x; | |
680 | double mb = (double) m_pageDialogData.GetMarginBottomRight().y; | |
681 | ||
682 | gs_libGnomePrint->gnome_print_config_set_length (config, | |
683 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, ml, mm_unit ); | |
684 | gs_libGnomePrint->gnome_print_config_set_length (config, | |
685 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, mr, mm_unit ); | |
686 | gs_libGnomePrint->gnome_print_config_set_length (config, | |
687 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, mt, mm_unit ); | |
688 | gs_libGnomePrint->gnome_print_config_set_length (config, | |
689 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, mb, mm_unit ); | |
690 | ||
691 | m_widget = gtk_dialog_new(); | |
692 | ||
693 | gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( _("Page setup") ) ); | |
694 | ||
695 | GtkWidget *main = gs_libGnomePrint->gnome_paper_selector_new_with_flags( native->GetPrintConfig(), | |
696 | GNOME_PAPER_SELECTOR_MARGINS|GNOME_PAPER_SELECTOR_FEED_ORIENTATION ); | |
697 | gtk_container_set_border_width (GTK_CONTAINER (main), 8); | |
698 | gtk_widget_show (main); | |
699 | ||
700 | gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget)->vbox), main ); | |
701 | ||
702 | gtk_dialog_set_has_separator (GTK_DIALOG (m_widget), TRUE); | |
703 | ||
704 | gtk_dialog_add_buttons (GTK_DIALOG (m_widget), | |
705 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
706 | GTK_STOCK_OK, GTK_RESPONSE_OK, | |
707 | NULL); | |
708 | ||
709 | gtk_dialog_set_default_response (GTK_DIALOG (m_widget), | |
710 | GTK_RESPONSE_OK); | |
711 | } | |
712 | ||
713 | wxGnomePageSetupDialog::~wxGnomePageSetupDialog() | |
714 | { | |
715 | } | |
716 | ||
717 | wxPageSetupDialogData& wxGnomePageSetupDialog::GetPageSetupDialogData() | |
718 | { | |
719 | return m_pageDialogData; | |
720 | } | |
721 | ||
722 | int wxGnomePageSetupDialog::ShowModal() | |
723 | { | |
724 | wxGnomePrintNativeData *native = | |
725 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
726 | ||
727 | GnomePrintConfig *config = native->GetPrintConfig(); | |
728 | ||
729 | ||
730 | int ret = gtk_dialog_run( GTK_DIALOG(m_widget) ); | |
731 | ||
732 | if (ret == GTK_RESPONSE_OK) | |
733 | { | |
734 | // Transfer data back to m_pageDialogData | |
735 | m_pageDialogData.GetPrintData().ConvertFromNative(); | |
736 | ||
737 | // I don't know how querying the last parameter works | |
738 | double ml,mr,mt,mb,pw,ph; | |
739 | gs_libGnomePrint->gnome_print_config_get_length (config, | |
740 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &ml, NULL); | |
741 | gs_libGnomePrint->gnome_print_config_get_length (config, | |
742 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &mr, NULL); | |
743 | gs_libGnomePrint->gnome_print_config_get_length (config, | |
744 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &mt, NULL); | |
745 | gs_libGnomePrint->gnome_print_config_get_length (config, | |
746 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &mb, NULL); | |
747 | gs_libGnomePrint->gnome_print_config_get_length (config, | |
748 | (const guchar*) GNOME_PRINT_KEY_PAPER_WIDTH, &pw, NULL); | |
749 | gs_libGnomePrint->gnome_print_config_get_length (config, | |
750 | (const guchar*) GNOME_PRINT_KEY_PAPER_HEIGHT, &ph, NULL); | |
751 | ||
752 | // This code converts correctly from what the user chose | |
753 | // as the unit although I query Pts here | |
754 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); | |
755 | const GnomePrintUnit *pts_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
756 | gs_libGnomePrint->gnome_print_convert_distance( &ml, pts_unit, mm_unit ); | |
757 | gs_libGnomePrint->gnome_print_convert_distance( &mr, pts_unit, mm_unit ); | |
758 | gs_libGnomePrint->gnome_print_convert_distance( &mt, pts_unit, mm_unit ); | |
759 | gs_libGnomePrint->gnome_print_convert_distance( &mb, pts_unit, mm_unit ); | |
760 | gs_libGnomePrint->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
761 | gs_libGnomePrint->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
762 | ||
763 | m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) ); | |
764 | m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) ); | |
765 | ||
766 | m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) ); | |
767 | ||
768 | ret = wxID_OK; | |
769 | } | |
770 | else | |
771 | { | |
772 | ret = wxID_CANCEL; | |
773 | } | |
774 | ||
775 | gtk_widget_destroy( m_widget ); | |
776 | m_widget = NULL; | |
777 | ||
778 | return ret; | |
779 | } | |
780 | ||
781 | bool wxGnomePageSetupDialog::Validate() | |
782 | { | |
783 | return true; | |
784 | } | |
785 | ||
786 | bool wxGnomePageSetupDialog::TransferDataToWindow() | |
787 | { | |
788 | return true; | |
789 | } | |
790 | ||
791 | bool wxGnomePageSetupDialog::TransferDataFromWindow() | |
792 | { | |
793 | return true; | |
794 | } | |
795 | ||
796 | //---------------------------------------------------------------------------- | |
797 | // wxGnomePrinter | |
798 | //---------------------------------------------------------------------------- | |
799 | ||
800 | IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase) | |
801 | ||
802 | wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) : | |
803 | wxPrinterBase( data ) | |
804 | { | |
805 | m_native_preview = false; | |
806 | } | |
807 | ||
808 | wxGnomePrinter::~wxGnomePrinter() | |
809 | { | |
810 | } | |
811 | ||
812 | bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) | |
813 | { | |
814 | if (!printout) | |
815 | { | |
816 | sm_lastError = wxPRINTER_ERROR; | |
817 | return false; | |
818 | } | |
819 | ||
820 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); | |
821 | ||
822 | wxGnomePrintNativeData *native = | |
823 | (wxGnomePrintNativeData*) printdata.GetNativeData(); | |
824 | ||
825 | GnomePrintJob *job = gs_libGnomePrint->gnome_print_job_new( native->GetPrintConfig() ); | |
826 | ||
827 | // The GnomePrintJob is temporarily stored in the | |
828 | // native print data as the native print dialog | |
829 | // needs to access it. | |
830 | native->SetPrintJob( job ); | |
831 | ||
832 | ||
833 | printout->SetIsPreview(false); | |
834 | ||
835 | if (m_printDialogData.GetMinPage() < 1) | |
836 | m_printDialogData.SetMinPage(1); | |
837 | if (m_printDialogData.GetMaxPage() < 1) | |
838 | m_printDialogData.SetMaxPage(9999); | |
839 | ||
840 | wxDC *dc; | |
841 | if (prompt) | |
842 | dc = PrintDialog( parent ); | |
843 | else | |
844 | dc = new wxGnomePrinterDC( printdata ); | |
845 | ||
846 | if (m_native_preview) | |
847 | printout->SetIsPreview(true); | |
848 | ||
849 | if (!dc) | |
850 | { | |
851 | gs_libGnomePrint->gnome_print_job_close( job ); | |
852 | g_object_unref (job); | |
853 | if (sm_lastError != wxPRINTER_CANCELLED) | |
854 | sm_lastError = wxPRINTER_ERROR; | |
855 | return false; | |
856 | } | |
857 | ||
858 | wxSize ScreenPixels = wxGetDisplaySize(); | |
859 | wxSize ScreenMM = wxGetDisplaySizeMM(); | |
860 | ||
861 | printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), | |
862 | (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); | |
863 | printout->SetPPIPrinter( wxGnomePrinterDC::GetResolution(), | |
864 | wxGnomePrinterDC::GetResolution() ); | |
865 | ||
866 | printout->SetDC(dc); | |
867 | ||
868 | int w, h; | |
869 | dc->GetSize(&w, &h); | |
870 | printout->SetPageSizePixels((int)w, (int)h); | |
871 | printout->SetPaperRectPixels(wxRect(0, 0, w, h)); | |
872 | int mw, mh; | |
873 | dc->GetSizeMM(&mw, &mh); | |
874 | printout->SetPageSizeMM((int)mw, (int)mh); | |
875 | printout->OnPreparePrinting(); | |
876 | ||
877 | // Get some parameters from the printout, if defined | |
878 | int fromPage, toPage; | |
879 | int minPage, maxPage; | |
880 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
881 | ||
882 | if (maxPage == 0) | |
883 | { | |
884 | gs_libGnomePrint->gnome_print_job_close( job ); | |
885 | g_object_unref (job); | |
886 | sm_lastError = wxPRINTER_ERROR; | |
887 | return false; | |
888 | } | |
889 | ||
890 | printout->OnBeginPrinting(); | |
891 | ||
892 | int minPageNum = minPage, maxPageNum = maxPage; | |
893 | ||
894 | if ( !m_printDialogData.GetAllPages() ) | |
895 | { | |
896 | minPageNum = m_printDialogData.GetFromPage(); | |
897 | maxPageNum = m_printDialogData.GetToPage(); | |
898 | } | |
899 | ||
900 | ||
901 | int copyCount; | |
902 | for ( copyCount = 1; | |
903 | copyCount <= m_printDialogData.GetNoCopies(); | |
904 | copyCount++ ) | |
905 | { | |
906 | if (!printout->OnBeginDocument(minPageNum, maxPageNum)) | |
907 | { | |
908 | wxLogError(_("Could not start printing.")); | |
909 | sm_lastError = wxPRINTER_ERROR; | |
910 | break; | |
911 | } | |
912 | ||
913 | int pn; | |
914 | for ( pn = minPageNum; | |
915 | pn <= maxPageNum && printout->HasPage(pn); | |
916 | pn++ ) | |
917 | { | |
918 | dc->StartPage(); | |
919 | printout->OnPrintPage(pn); | |
920 | dc->EndPage(); | |
921 | } | |
922 | ||
923 | printout->OnEndDocument(); | |
924 | printout->OnEndPrinting(); | |
925 | } | |
926 | ||
927 | gs_libGnomePrint->gnome_print_job_close( job ); | |
928 | if (m_native_preview) | |
929 | { | |
930 | const wxCharBuffer title(wxGTK_CONV_SYS(_("Print preview"))); | |
931 | GtkWidget *preview = gs_libGnomePrint->gnome_print_job_preview_new | |
932 | ( | |
933 | job, | |
934 | (const guchar *)title.data() | |
935 | ); | |
936 | gtk_widget_show(preview); | |
937 | } | |
938 | else | |
939 | { | |
940 | gs_libGnomePrint->gnome_print_job_print( job ); | |
941 | } | |
942 | ||
943 | g_object_unref (job); | |
944 | delete dc; | |
945 | ||
946 | return (sm_lastError == wxPRINTER_NO_ERROR); | |
947 | } | |
948 | ||
949 | wxDC* wxGnomePrinter::PrintDialog( wxWindow *parent ) | |
950 | { | |
951 | wxGnomePrintDialog dialog( parent, &m_printDialogData ); | |
952 | int ret = dialog.ShowModal(); | |
953 | if (ret == wxID_CANCEL) | |
954 | { | |
955 | sm_lastError = wxPRINTER_CANCELLED; | |
956 | return NULL; | |
957 | } | |
958 | ||
959 | m_native_preview = ret == wxID_PREVIEW; | |
960 | ||
961 | m_printDialogData = dialog.GetPrintDialogData(); | |
962 | return new wxGnomePrinterDC( m_printDialogData.GetPrintData() ); | |
963 | } | |
964 | ||
965 | bool wxGnomePrinter::Setup(wxWindow * WXUNUSED(parent)) | |
966 | { | |
967 | return false; | |
968 | } | |
969 | ||
970 | //----------------------------------------------------------------------------- | |
971 | // wxGnomePrinterDC | |
972 | //----------------------------------------------------------------------------- | |
973 | ||
974 | // conversion | |
975 | static const double RAD2DEG = 180.0 / M_PI; | |
976 | ||
977 | // we don't want to use only 72 dpi from GNOME print | |
978 | static const int DPI = 600; | |
979 | static const double PS2DEV = 600.0 / 72.0; | |
980 | static const double DEV2PS = 72.0 / 600.0; | |
981 | ||
982 | #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS) | |
983 | #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS) | |
984 | #define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS) | |
985 | #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS) | |
986 | ||
987 | IMPLEMENT_CLASS(wxGnomePrinterDC, wxDC) | |
988 | ||
989 | wxGnomePrinterDC::wxGnomePrinterDC( const wxPrintData& data ) | |
990 | { | |
991 | m_printData = data; | |
992 | ||
993 | wxGnomePrintNativeData *native = | |
994 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
995 | ||
996 | m_job = native->GetPrintJob(); | |
997 | m_gpc = gs_libGnomePrint->gnome_print_job_get_context (m_job); | |
998 | ||
999 | m_layout = gs_libGnomePrint->gnome_print_pango_create_layout( m_gpc ); | |
1000 | m_fontdesc = pango_font_description_from_string( "Sans 12" ); | |
1001 | m_context = NULL; | |
1002 | ||
1003 | m_currentRed = 0; | |
1004 | m_currentBlue = 0; | |
1005 | m_currentGreen = 0; | |
1006 | ||
1007 | // Query page size. This seems to omit the margins | |
1008 | double pw,ph; | |
1009 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); | |
1010 | ||
1011 | m_pageHeight = ph * PS2DEV; | |
1012 | } | |
1013 | ||
1014 | wxGnomePrinterDC::~wxGnomePrinterDC() | |
1015 | { | |
1016 | } | |
1017 | ||
1018 | bool wxGnomePrinterDC::IsOk() const | |
1019 | { | |
1020 | return true; | |
1021 | } | |
1022 | ||
1023 | bool | |
1024 | wxGnomePrinterDC::DoFloodFill(wxCoord WXUNUSED(x1), | |
1025 | wxCoord WXUNUSED(y1), | |
1026 | const wxColour& WXUNUSED(col), | |
1027 | int WXUNUSED(style)) | |
1028 | { | |
1029 | return false; | |
1030 | } | |
1031 | ||
1032 | bool | |
1033 | wxGnomePrinterDC::DoGetPixel(wxCoord WXUNUSED(x1), | |
1034 | wxCoord WXUNUSED(y1), | |
1035 | wxColour * WXUNUSED(col)) const | |
1036 | { | |
1037 | return false; | |
1038 | } | |
1039 | ||
1040 | void wxGnomePrinterDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
1041 | { | |
1042 | if (m_pen.GetStyle() == wxTRANSPARENT) return; | |
1043 | ||
1044 | SetPen( m_pen ); | |
1045 | ||
1046 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) ); | |
1047 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) ); | |
1048 | gs_libGnomePrint->gnome_print_stroke ( m_gpc); | |
1049 | ||
1050 | CalcBoundingBox( x1, y1 ); | |
1051 | CalcBoundingBox( x2, y2 ); | |
1052 | } | |
1053 | ||
1054 | void wxGnomePrinterDC::DoCrossHair(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) | |
1055 | { | |
1056 | } | |
1057 | ||
1058 | void wxGnomePrinterDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) | |
1059 | { | |
1060 | double dx = x1 - xc; | |
1061 | double dy = y1 - yc; | |
1062 | double radius = sqrt((double)(dx*dx+dy*dy)); | |
1063 | double alpha1, alpha2; | |
1064 | if (x1 == x2 && y1 == y2) | |
1065 | { | |
1066 | alpha1 = 0.0; | |
1067 | alpha2 = 360.0; | |
1068 | } | |
1069 | else if ( wxIsNullDouble(radius) ) | |
1070 | { | |
1071 | alpha1 = | |
1072 | alpha2 = 0.0; | |
1073 | } | |
1074 | else | |
1075 | { | |
1076 | alpha1 = (x1 - xc == 0) ? | |
1077 | (y1 - yc < 0) ? 90.0 : -90.0 : | |
1078 | -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; | |
1079 | alpha2 = (x2 - xc == 0) ? | |
1080 | (y2 - yc < 0) ? 90.0 : -90.0 : | |
1081 | -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; | |
1082 | ||
1083 | while (alpha1 <= 0) alpha1 += 360; | |
1084 | while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between | |
1085 | while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree | |
1086 | while (alpha2 > 360) alpha2 -= 360; | |
1087 | } | |
1088 | ||
1089 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
1090 | { | |
1091 | SetBrush( m_brush ); | |
1092 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); | |
1093 | gs_libGnomePrint->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); | |
1094 | ||
1095 | gs_libGnomePrint->gnome_print_fill( m_gpc ); | |
1096 | } | |
1097 | ||
1098 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
1099 | { | |
1100 | SetPen (m_pen); | |
1101 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); | |
1102 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); | |
1103 | gs_libGnomePrint->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); | |
1104 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1105 | ||
1106 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); | |
1107 | } | |
1108 | ||
1109 | CalcBoundingBox (x1, y1); | |
1110 | CalcBoundingBox (x2, y2); | |
1111 | CalcBoundingBox (xc, yc); | |
1112 | } | |
1113 | ||
1114 | void wxGnomePrinterDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) | |
1115 | { | |
1116 | x += w/2; | |
1117 | y += h/2; | |
1118 | ||
1119 | double xx = XLOG2DEV(x); | |
1120 | double yy = YLOG2DEV(y); | |
1121 | ||
1122 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); | |
1123 | ||
1124 | gs_libGnomePrint->gnome_print_translate( m_gpc, xx, yy ); | |
1125 | double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w); | |
1126 | gs_libGnomePrint->gnome_print_scale( m_gpc, 1.0, scale ); | |
1127 | ||
1128 | xx = 0.0; | |
1129 | yy = 0.0; | |
1130 | ||
1131 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1132 | { | |
1133 | SetBrush( m_brush ); | |
1134 | ||
1135 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, xx, yy ); | |
1136 | gs_libGnomePrint->gnome_print_arcto( m_gpc, xx, yy, | |
1137 | XLOG2DEVREL(w)/2, sa, ea, 0 ); | |
1138 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, xx, yy ); | |
1139 | ||
1140 | gs_libGnomePrint->gnome_print_fill( m_gpc ); | |
1141 | } | |
1142 | ||
1143 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1144 | { | |
1145 | SetPen (m_pen); | |
1146 | ||
1147 | gs_libGnomePrint->gnome_print_arcto( m_gpc, xx, yy, | |
1148 | XLOG2DEVREL(w)/2, sa, ea, 0 ); | |
1149 | ||
1150 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); | |
1151 | } | |
1152 | ||
1153 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
1154 | ||
1155 | CalcBoundingBox( x, y ); | |
1156 | CalcBoundingBox( x+w, y+h ); | |
1157 | } | |
1158 | ||
1159 | void wxGnomePrinterDC::DoDrawPoint(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) | |
1160 | { | |
1161 | } | |
1162 | ||
1163 | void wxGnomePrinterDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) | |
1164 | { | |
1165 | if (m_pen.GetStyle() == wxTRANSPARENT) return; | |
1166 | ||
1167 | if (n <= 0) return; | |
1168 | ||
1169 | SetPen (m_pen); | |
1170 | ||
1171 | int i; | |
1172 | for ( i =0; i<n ; i++ ) | |
1173 | CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset); | |
1174 | ||
1175 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) ); | |
1176 | ||
1177 | for (i = 1; i < n; i++) | |
1178 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) ); | |
1179 | ||
1180 | gs_libGnomePrint->gnome_print_stroke ( m_gpc); | |
1181 | } | |
1182 | ||
1183 | void wxGnomePrinterDC::DoDrawPolygon(int n, wxPoint points[], | |
1184 | wxCoord xoffset, wxCoord yoffset, | |
1185 | int WXUNUSED(fillStyle)) | |
1186 | { | |
1187 | if (n==0) return; | |
1188 | ||
1189 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1190 | { | |
1191 | SetBrush( m_brush ); | |
1192 | ||
1193 | int x = points[0].x + xoffset; | |
1194 | int y = points[0].y + yoffset; | |
1195 | CalcBoundingBox( x, y ); | |
1196 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); | |
1197 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1198 | int i; | |
1199 | for (i = 1; i < n; i++) | |
1200 | { | |
1201 | x = points[i].x + xoffset; | |
1202 | y = points[i].y + yoffset; | |
1203 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1204 | CalcBoundingBox( x, y ); | |
1205 | } | |
1206 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1207 | gs_libGnomePrint->gnome_print_fill( m_gpc ); | |
1208 | } | |
1209 | ||
1210 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1211 | { | |
1212 | SetPen (m_pen); | |
1213 | ||
1214 | int x = points[0].x + xoffset; | |
1215 | int y = points[0].y + yoffset; | |
1216 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); | |
1217 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1218 | int i; | |
1219 | for (i = 1; i < n; i++) | |
1220 | { | |
1221 | x = points[i].x + xoffset; | |
1222 | y = points[i].y + yoffset; | |
1223 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1224 | CalcBoundingBox( x, y ); | |
1225 | } | |
1226 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1227 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); | |
1228 | } | |
1229 | } | |
1230 | ||
1231 | void wxGnomePrinterDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
1232 | { | |
1233 | wxDC::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle ); | |
1234 | } | |
1235 | ||
1236 | void wxGnomePrinterDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1237 | { | |
1238 | width--; | |
1239 | height--; | |
1240 | ||
1241 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1242 | { | |
1243 | SetBrush( m_brush ); | |
1244 | ||
1245 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); | |
1246 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1247 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1248 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1249 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1250 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1251 | gs_libGnomePrint->gnome_print_fill( m_gpc ); | |
1252 | ||
1253 | CalcBoundingBox( x, y ); | |
1254 | CalcBoundingBox( x + width, y + height ); | |
1255 | } | |
1256 | ||
1257 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1258 | { | |
1259 | SetPen (m_pen); | |
1260 | ||
1261 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); | |
1262 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1263 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1264 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1265 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1266 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1267 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); | |
1268 | ||
1269 | CalcBoundingBox( x, y ); | |
1270 | CalcBoundingBox( x + width, y + height ); | |
1271 | } | |
1272 | } | |
1273 | ||
1274 | void wxGnomePrinterDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) | |
1275 | { | |
1276 | width--; | |
1277 | height--; | |
1278 | ||
1279 | wxCoord rad = wxRound( radius ); | |
1280 | ||
1281 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
1282 | { | |
1283 | SetBrush(m_brush); | |
1284 | gs_libGnomePrint->gnome_print_newpath(m_gpc); | |
1285 | gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1286 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
1287 | XLOG2DEV(x + rad),YLOG2DEV(y), | |
1288 | XLOG2DEV(x),YLOG2DEV(y), | |
1289 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
1290 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); | |
1291 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
1292 | XLOG2DEV(x),YLOG2DEV(y + height - rad), | |
1293 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1294 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
1295 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); | |
1296 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
1297 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), | |
1298 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1299 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
1300 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); | |
1301 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
1302 | XLOG2DEV(x + width),YLOG2DEV(y + rad), | |
1303 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1304 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
1305 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1306 | gs_libGnomePrint->gnome_print_closepath(m_gpc); | |
1307 | gs_libGnomePrint->gnome_print_fill(m_gpc); | |
1308 | ||
1309 | CalcBoundingBox(x,y); | |
1310 | CalcBoundingBox(x+width,y+height); | |
1311 | } | |
1312 | ||
1313 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
1314 | { | |
1315 | SetPen(m_pen); | |
1316 | gs_libGnomePrint->gnome_print_newpath(m_gpc); | |
1317 | gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1318 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
1319 | XLOG2DEV(x + rad),YLOG2DEV(y), | |
1320 | XLOG2DEV(x),YLOG2DEV(y), | |
1321 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
1322 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); | |
1323 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
1324 | XLOG2DEV(x),YLOG2DEV(y + height - rad), | |
1325 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1326 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
1327 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); | |
1328 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
1329 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), | |
1330 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1331 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
1332 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); | |
1333 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
1334 | XLOG2DEV(x + width),YLOG2DEV(y + rad), | |
1335 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1336 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
1337 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1338 | gs_libGnomePrint->gnome_print_closepath(m_gpc); | |
1339 | gs_libGnomePrint->gnome_print_stroke(m_gpc); | |
1340 | ||
1341 | CalcBoundingBox(x,y); | |
1342 | CalcBoundingBox(x+width,y+height); | |
1343 | } | |
1344 | } | |
1345 | ||
1346 | void wxGnomePrinterDC::makeEllipticalPath(wxCoord x, wxCoord y, | |
1347 | wxCoord width, wxCoord height) | |
1348 | { | |
1349 | double r = 4 * (sqrt(2.) - 1) / 3; | |
1350 | double halfW = 0.5 * width, | |
1351 | halfH = 0.5 * height, | |
1352 | halfWR = r * halfW, | |
1353 | halfHR = r * halfH; | |
1354 | wxCoord halfWI = (wxCoord) halfW, | |
1355 | halfHI = (wxCoord) halfH; | |
1356 | ||
1357 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); | |
1358 | ||
1359 | // Approximate an ellipse using four cubic splines, clockwise from 0 deg */ | |
1360 | gs_libGnomePrint->gnome_print_moveto( m_gpc, | |
1361 | XLOG2DEV(x + width), | |
1362 | YLOG2DEV(y + halfHI) ); | |
1363 | gs_libGnomePrint->gnome_print_curveto( m_gpc, | |
1364 | XLOG2DEV(x + width), | |
1365 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), | |
1366 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), | |
1367 | YLOG2DEV(y + height), | |
1368 | XLOG2DEV(x + halfWI), | |
1369 | YLOG2DEV(y + height) ); | |
1370 | gs_libGnomePrint->gnome_print_curveto( m_gpc, | |
1371 | XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)), | |
1372 | YLOG2DEV(y + height), | |
1373 | XLOG2DEV(x), | |
1374 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), | |
1375 | XLOG2DEV(x), YLOG2DEV(y+halfHI) ); | |
1376 | gs_libGnomePrint->gnome_print_curveto( m_gpc, | |
1377 | XLOG2DEV(x), | |
1378 | YLOG2DEV(y + (wxCoord) rint (halfH - halfHR)), | |
1379 | XLOG2DEV(x + (wxCoord) rint (halfW - halfWR)), | |
1380 | YLOG2DEV(y), | |
1381 | XLOG2DEV(x+halfWI), YLOG2DEV(y) ); | |
1382 | gs_libGnomePrint->gnome_print_curveto( m_gpc, | |
1383 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), | |
1384 | YLOG2DEV(y), | |
1385 | XLOG2DEV(x + width), | |
1386 | YLOG2DEV(y + (wxCoord) rint(halfH - halfHR)), | |
1387 | XLOG2DEV(x + width), YLOG2DEV(y + halfHI) ); | |
1388 | ||
1389 | gs_libGnomePrint->gnome_print_closepath(m_gpc); | |
1390 | } | |
1391 | ||
1392 | void wxGnomePrinterDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1393 | { | |
1394 | width--; | |
1395 | height--; | |
1396 | ||
1397 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1398 | { | |
1399 | SetBrush( m_brush ); | |
1400 | makeEllipticalPath( x, y, width, height ); | |
1401 | gs_libGnomePrint->gnome_print_fill( m_gpc ); | |
1402 | CalcBoundingBox( x, y ); | |
1403 | CalcBoundingBox( x + width, y + height ); | |
1404 | } | |
1405 | ||
1406 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1407 | { | |
1408 | SetPen (m_pen); | |
1409 | makeEllipticalPath( x, y, width, height ); | |
1410 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); | |
1411 | CalcBoundingBox( x, y ); | |
1412 | CalcBoundingBox( x + width, y + height ); | |
1413 | } | |
1414 | } | |
1415 | ||
1416 | #if wxUSE_SPLINES | |
1417 | void wxGnomePrinterDC::DoDrawSpline(const wxPointList *points) | |
1418 | { | |
1419 | SetPen (m_pen); | |
1420 | ||
1421 | double c, d, x1, y1, x2, y2, x3, y3; | |
1422 | wxPoint *p, *q; | |
1423 | ||
1424 | wxPointList::compatibility_iterator node = points->GetFirst(); | |
1425 | p = node->GetData(); | |
1426 | x1 = p->x; | |
1427 | y1 = p->y; | |
1428 | ||
1429 | node = node->GetNext(); | |
1430 | p = node->GetData(); | |
1431 | c = p->x; | |
1432 | d = p->y; | |
1433 | x3 = | |
1434 | (double)(x1 + c) / 2; | |
1435 | y3 = | |
1436 | (double)(y1 + d) / 2; | |
1437 | ||
1438 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); | |
1439 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) ); | |
1440 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
1441 | ||
1442 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1443 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1444 | ||
1445 | node = node->GetNext(); | |
1446 | while (node) | |
1447 | { | |
1448 | q = node->GetData(); | |
1449 | ||
1450 | x1 = x3; | |
1451 | y1 = y3; | |
1452 | x2 = c; | |
1453 | y2 = d; | |
1454 | c = q->x; | |
1455 | d = q->y; | |
1456 | x3 = (double)(x2 + c) / 2; | |
1457 | y3 = (double)(y2 + d) / 2; | |
1458 | ||
1459 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
1460 | XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1), | |
1461 | XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2), | |
1462 | XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
1463 | ||
1464 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1465 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1466 | ||
1467 | node = node->GetNext(); | |
1468 | } | |
1469 | ||
1470 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) ); | |
1471 | ||
1472 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); | |
1473 | } | |
1474 | #endif // wxUSE_SPLINES | |
1475 | ||
1476 | bool | |
1477 | wxGnomePrinterDC::DoBlit(wxCoord xdest, wxCoord ydest, | |
1478 | wxCoord width, wxCoord height, | |
1479 | wxDC *source, | |
1480 | wxCoord xsrc, wxCoord ysrc, | |
1481 | int rop, | |
1482 | bool WXUNUSED(useMask), | |
1483 | wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask)) | |
1484 | { | |
1485 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); | |
1486 | ||
1487 | // blit into a bitmap | |
1488 | wxBitmap bitmap( width, height ); | |
1489 | wxMemoryDC memDC; | |
1490 | memDC.SelectObject(bitmap); | |
1491 | memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */ | |
1492 | memDC.SelectObject(wxNullBitmap); | |
1493 | ||
1494 | // draw bitmap. scaling and positioning is done there | |
1495 | DrawBitmap( bitmap, xdest, ydest ); | |
1496 | ||
1497 | return true; | |
1498 | } | |
1499 | ||
1500 | void wxGnomePrinterDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) | |
1501 | { | |
1502 | DoDrawBitmap( icon, x, y, true ); | |
1503 | } | |
1504 | ||
1505 | void | |
1506 | wxGnomePrinterDC::DoDrawBitmap(const wxBitmap& bitmap, | |
1507 | wxCoord x, wxCoord y, | |
1508 | bool WXUNUSED(useMask)) | |
1509 | { | |
1510 | if (!bitmap.Ok()) return; | |
1511 | ||
1512 | if (bitmap.HasPixbuf()) | |
1513 | { | |
1514 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); | |
1515 | guchar *raw_image = gdk_pixbuf_get_pixels( pixbuf ); | |
1516 | bool has_alpha = gdk_pixbuf_get_has_alpha( pixbuf ); | |
1517 | int rowstride = gdk_pixbuf_get_rowstride( pixbuf ); | |
1518 | int height = gdk_pixbuf_get_height( pixbuf ); | |
1519 | int width = gdk_pixbuf_get_width( pixbuf ); | |
1520 | ||
1521 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); | |
1522 | double matrix[6]; | |
1523 | matrix[0] = XLOG2DEVREL(width); | |
1524 | matrix[1] = 0; | |
1525 | matrix[2] = 0; | |
1526 | matrix[3] = YLOG2DEVREL(height); | |
1527 | matrix[4] = XLOG2DEV(x); | |
1528 | matrix[5] = YLOG2DEV(y+height); | |
1529 | gs_libGnomePrint->gnome_print_concat( m_gpc, matrix ); | |
1530 | gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 ); | |
1531 | if (has_alpha) | |
1532 | gs_libGnomePrint->gnome_print_rgbaimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); | |
1533 | else | |
1534 | gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); | |
1535 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
1536 | } | |
1537 | else | |
1538 | { | |
1539 | wxImage image = bitmap.ConvertToImage(); | |
1540 | ||
1541 | if (!image.Ok()) return; | |
1542 | ||
1543 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); | |
1544 | double matrix[6]; | |
1545 | matrix[0] = XLOG2DEVREL(image.GetWidth()); | |
1546 | matrix[1] = 0; | |
1547 | matrix[2] = 0; | |
1548 | matrix[3] = YLOG2DEVREL(image.GetHeight()); | |
1549 | matrix[4] = XLOG2DEV(x); | |
1550 | matrix[5] = YLOG2DEV(y+image.GetHeight()); | |
1551 | gs_libGnomePrint->gnome_print_concat( m_gpc, matrix ); | |
1552 | gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 ); | |
1553 | gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 ); | |
1554 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
1555 | } | |
1556 | } | |
1557 | ||
1558 | void wxGnomePrinterDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y ) | |
1559 | { | |
1560 | DoDrawRotatedText( text, x, y, 0.0 ); | |
1561 | } | |
1562 | ||
1563 | void wxGnomePrinterDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) | |
1564 | { | |
1565 | double xx = XLOG2DEV(x); | |
1566 | double yy = YLOG2DEV(y); | |
1567 | ||
1568 | bool underlined = m_font.Ok() && m_font.GetUnderlined(); | |
1569 | ||
1570 | // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer | |
1571 | #if wxUSE_UNICODE_UTF8 | |
1572 | const char *data = text.utf8_str(); | |
1573 | #else | |
1574 | const wxCharBuffer data = text.utf8_str(); | |
1575 | #endif | |
1576 | ||
1577 | size_t datalen = strlen(data); | |
1578 | pango_layout_set_text( m_layout, data, datalen); | |
1579 | ||
1580 | if (underlined) | |
1581 | { | |
1582 | PangoAttrList *attrs = pango_attr_list_new(); | |
1583 | PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); | |
1584 | a->start_index = 0; | |
1585 | a->end_index = datalen; | |
1586 | pango_attr_list_insert(attrs, a); | |
1587 | pango_layout_set_attributes(m_layout, attrs); | |
1588 | pango_attr_list_unref(attrs); | |
1589 | } | |
1590 | ||
1591 | if (m_textForegroundColour.Ok()) | |
1592 | { | |
1593 | unsigned char red = m_textForegroundColour.Red(); | |
1594 | unsigned char blue = m_textForegroundColour.Blue(); | |
1595 | unsigned char green = m_textForegroundColour.Green(); | |
1596 | ||
1597 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1598 | { | |
1599 | double redPS = (double)(red) / 255.0; | |
1600 | double bluePS = (double)(blue) / 255.0; | |
1601 | double greenPS = (double)(green) / 255.0; | |
1602 | ||
1603 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); | |
1604 | ||
1605 | m_currentRed = red; | |
1606 | m_currentBlue = blue; | |
1607 | m_currentGreen = green; | |
1608 | } | |
1609 | } | |
1610 | ||
1611 | int w,h; | |
1612 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1613 | #if 0 | |
1614 | if ( m_backgroundMode == wxSOLID ) | |
1615 | { | |
1616 | gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); | |
1617 | gdk_draw_rectangle(m_window, m_textGC, TRUE, xx, yy, w, h); | |
1618 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); | |
1619 | } | |
1620 | #endif | |
1621 | ||
1622 | // Draw layout. | |
1623 | gs_libGnomePrint->gnome_print_moveto (m_gpc, xx, yy); | |
1624 | ||
1625 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); | |
1626 | ||
1627 | gs_libGnomePrint->gnome_print_scale( m_gpc, m_scaleX * DEV2PS, m_scaleY * DEV2PS ); | |
1628 | ||
1629 | if (fabs(angle) > 0.00001) | |
1630 | gs_libGnomePrint->gnome_print_rotate( m_gpc, angle ); | |
1631 | ||
1632 | gs_libGnomePrint->gnome_print_pango_layout( m_gpc, m_layout ); | |
1633 | ||
1634 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
1635 | ||
1636 | if (underlined) | |
1637 | { | |
1638 | // undo underline attributes setting: | |
1639 | pango_layout_set_attributes(m_layout, NULL); | |
1640 | } | |
1641 | ||
1642 | CalcBoundingBox (x + w, y + h); | |
1643 | } | |
1644 | ||
1645 | void wxGnomePrinterDC::Clear() | |
1646 | { | |
1647 | } | |
1648 | ||
1649 | void wxGnomePrinterDC::SetFont( const wxFont& font ) | |
1650 | { | |
1651 | m_font = font; | |
1652 | ||
1653 | if (m_font.Ok()) | |
1654 | { | |
1655 | if (m_fontdesc) | |
1656 | pango_font_description_free( m_fontdesc ); | |
1657 | ||
1658 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); | |
1659 | ||
1660 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1661 | } | |
1662 | } | |
1663 | ||
1664 | void wxGnomePrinterDC::SetPen( const wxPen& pen ) | |
1665 | { | |
1666 | if (!pen.Ok()) return; | |
1667 | ||
1668 | m_pen = pen; | |
1669 | ||
1670 | double width; | |
1671 | ||
1672 | if (m_pen.GetWidth() <= 0) | |
1673 | width = 0.1; | |
1674 | else | |
1675 | width = (double) m_pen.GetWidth(); | |
1676 | ||
1677 | gs_libGnomePrint->gnome_print_setlinewidth( m_gpc, width * DEV2PS * m_scaleX ); | |
1678 | ||
1679 | static const double dotted[] = {2.0, 5.0}; | |
1680 | static const double short_dashed[] = {4.0, 4.0}; | |
1681 | static const double wxCoord_dashed[] = {4.0, 8.0}; | |
1682 | static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0}; | |
1683 | ||
1684 | switch (m_pen.GetStyle()) | |
1685 | { | |
1686 | case wxDOT: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break; | |
1687 | case wxSHORT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break; | |
1688 | case wxLONG_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break; | |
1689 | case wxDOT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break; | |
1690 | case wxUSER_DASH: | |
1691 | { | |
1692 | // It may be noted that libgnomeprint between at least | |
1693 | // versions 2.8.0 and 2.12.1 makes a copy of the dashes | |
1694 | // and then leak the memory since it doesn't set the | |
1695 | // internal flag "privatedash" to 0. | |
1696 | wxDash *wx_dashes; | |
1697 | int num = m_pen.GetDashes (&wx_dashes); | |
1698 | gdouble *g_dashes = g_new( gdouble, num ); | |
1699 | int i; | |
1700 | for (i = 0; i < num; ++i) | |
1701 | g_dashes[i] = (gdouble) wx_dashes[i]; | |
1702 | gs_libGnomePrint -> gnome_print_setdash( m_gpc, num, g_dashes, 0); | |
1703 | g_free( g_dashes ); | |
1704 | } | |
1705 | break; | |
1706 | case wxSOLID: | |
1707 | case wxTRANSPARENT: | |
1708 | default: gs_libGnomePrint->gnome_print_setdash( m_gpc, 0, NULL, 0 ); break; | |
1709 | } | |
1710 | ||
1711 | ||
1712 | unsigned char red = m_pen.GetColour().Red(); | |
1713 | unsigned char blue = m_pen.GetColour().Blue(); | |
1714 | unsigned char green = m_pen.GetColour().Green(); | |
1715 | ||
1716 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1717 | { | |
1718 | double redPS = (double)(red) / 255.0; | |
1719 | double bluePS = (double)(blue) / 255.0; | |
1720 | double greenPS = (double)(green) / 255.0; | |
1721 | ||
1722 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); | |
1723 | ||
1724 | m_currentRed = red; | |
1725 | m_currentBlue = blue; | |
1726 | m_currentGreen = green; | |
1727 | } | |
1728 | } | |
1729 | ||
1730 | void wxGnomePrinterDC::SetBrush( const wxBrush& brush ) | |
1731 | { | |
1732 | if (!brush.Ok()) return; | |
1733 | ||
1734 | m_brush = brush; | |
1735 | ||
1736 | // Brush colour | |
1737 | unsigned char red = m_brush.GetColour().Red(); | |
1738 | unsigned char blue = m_brush.GetColour().Blue(); | |
1739 | unsigned char green = m_brush.GetColour().Green(); | |
1740 | ||
1741 | if (!m_colour) | |
1742 | { | |
1743 | // Anything not white is black | |
1744 | if (! (red == (unsigned char) 255 && | |
1745 | blue == (unsigned char) 255 && | |
1746 | green == (unsigned char) 255) ) | |
1747 | { | |
1748 | red = (unsigned char) 0; | |
1749 | green = (unsigned char) 0; | |
1750 | blue = (unsigned char) 0; | |
1751 | } | |
1752 | // setgray here ? | |
1753 | } | |
1754 | ||
1755 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1756 | { | |
1757 | double redPS = (double)(red) / 255.0; | |
1758 | double bluePS = (double)(blue) / 255.0; | |
1759 | double greenPS = (double)(green) / 255.0; | |
1760 | ||
1761 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); | |
1762 | ||
1763 | m_currentRed = red; | |
1764 | m_currentBlue = blue; | |
1765 | m_currentGreen = green; | |
1766 | } | |
1767 | } | |
1768 | ||
1769 | void wxGnomePrinterDC::SetLogicalFunction(int WXUNUSED(function)) | |
1770 | { | |
1771 | } | |
1772 | ||
1773 | void wxGnomePrinterDC::SetBackground(const wxBrush& WXUNUSED(brush)) | |
1774 | { | |
1775 | } | |
1776 | ||
1777 | void wxGnomePrinterDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1778 | { | |
1779 | wxDC::DoSetClippingRegion( x, y, width, height ); | |
1780 | ||
1781 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); | |
1782 | ||
1783 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); | |
1784 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1785 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1786 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1787 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1788 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1789 | gs_libGnomePrint->gnome_print_clip( m_gpc ); | |
1790 | } | |
1791 | ||
1792 | void wxGnomePrinterDC::DestroyClippingRegion() | |
1793 | { | |
1794 | wxDC::DestroyClippingRegion(); | |
1795 | ||
1796 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
1797 | ||
1798 | #if 0 | |
1799 | // not needed, we set the values in each | |
1800 | // drawing method anyways | |
1801 | SetPen( m_pen ); | |
1802 | SetBrush( m_brush ); | |
1803 | SetFont( m_font ); | |
1804 | #endif | |
1805 | } | |
1806 | ||
1807 | bool wxGnomePrinterDC::StartDoc(const wxString& WXUNUSED(message)) | |
1808 | { | |
1809 | return true; | |
1810 | } | |
1811 | ||
1812 | void wxGnomePrinterDC::EndDoc() | |
1813 | { | |
1814 | gs_libGnomePrint->gnome_print_end_doc( m_gpc ); | |
1815 | } | |
1816 | ||
1817 | void wxGnomePrinterDC::StartPage() | |
1818 | { | |
1819 | gs_libGnomePrint->gnome_print_beginpage( m_gpc, (const guchar*) "page" ); | |
1820 | } | |
1821 | ||
1822 | void wxGnomePrinterDC::EndPage() | |
1823 | { | |
1824 | gs_libGnomePrint->gnome_print_showpage( m_gpc ); | |
1825 | } | |
1826 | ||
1827 | wxCoord wxGnomePrinterDC::GetCharHeight() const | |
1828 | { | |
1829 | pango_layout_set_text( m_layout, "H", 1 ); | |
1830 | ||
1831 | int w,h; | |
1832 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1833 | ||
1834 | return h; | |
1835 | } | |
1836 | ||
1837 | wxCoord wxGnomePrinterDC::GetCharWidth() const | |
1838 | { | |
1839 | pango_layout_set_text( m_layout, "H", 1 ); | |
1840 | ||
1841 | int w,h; | |
1842 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1843 | ||
1844 | return w; | |
1845 | } | |
1846 | ||
1847 | void wxGnomePrinterDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, | |
1848 | wxCoord *descent, | |
1849 | wxCoord *externalLeading, | |
1850 | const wxFont *theFont ) const | |
1851 | { | |
1852 | if ( width ) | |
1853 | *width = 0; | |
1854 | if ( height ) | |
1855 | *height = 0; | |
1856 | if ( descent ) | |
1857 | *descent = 0; | |
1858 | if ( externalLeading ) | |
1859 | *externalLeading = 0; | |
1860 | ||
1861 | if (string.empty()) | |
1862 | { | |
1863 | return; | |
1864 | } | |
1865 | ||
1866 | // Set layout's text | |
1867 | ||
1868 | // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer | |
1869 | #if wxUSE_UNICODE_UTF8 | |
1870 | const char *dataUTF8 = string.utf8_str(); | |
1871 | #else | |
1872 | const wxCharBuffer dataUTF8 = string.utf8_str(); | |
1873 | #endif | |
1874 | ||
1875 | PangoFontDescription *desc = (theFont) ? theFont->GetNativeFontInfo()->description : m_fontdesc; | |
1876 | ||
1877 | gint oldSize = pango_font_description_get_size( desc ); | |
1878 | double size = oldSize; | |
1879 | size = size * m_scaleY; | |
1880 | pango_font_description_set_size( desc, (gint)size ); | |
1881 | ||
1882 | // apply scaled font | |
1883 | pango_layout_set_font_description( m_layout, desc ); | |
1884 | ||
1885 | pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); | |
1886 | ||
1887 | int w, h; | |
1888 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1889 | ||
1890 | ||
1891 | if (width) | |
1892 | *width = (wxCoord)(w / m_scaleX); | |
1893 | if (height) | |
1894 | *height = (wxCoord)(h / m_scaleY); | |
1895 | ||
1896 | if (descent) | |
1897 | { | |
1898 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); | |
1899 | int baseline = pango_layout_iter_get_baseline(iter); | |
1900 | pango_layout_iter_free(iter); | |
1901 | *descent = h - PANGO_PIXELS(baseline); | |
1902 | } | |
1903 | ||
1904 | // reset unscaled size | |
1905 | pango_font_description_set_size( desc, oldSize ); | |
1906 | ||
1907 | // reset unscaled font | |
1908 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1909 | } | |
1910 | ||
1911 | void wxGnomePrinterDC::DoGetSize(int* width, int* height) const | |
1912 | { | |
1913 | wxGnomePrintNativeData *native = | |
1914 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1915 | ||
1916 | // Query page size. This seems to omit the margins | |
1917 | double pw,ph; | |
1918 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); | |
1919 | ||
1920 | if (width) | |
1921 | *width = wxRound( pw * PS2DEV ); | |
1922 | ||
1923 | if (height) | |
1924 | *height = wxRound( ph * PS2DEV ); | |
1925 | } | |
1926 | ||
1927 | void wxGnomePrinterDC::DoGetSizeMM(int *width, int *height) const | |
1928 | { | |
1929 | wxGnomePrintNativeData *native = | |
1930 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1931 | ||
1932 | // This code assumes values in Pts. | |
1933 | ||
1934 | double pw,ph; | |
1935 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); | |
1936 | ||
1937 | // Convert to mm. | |
1938 | ||
1939 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); | |
1940 | const GnomePrintUnit *pts_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
1941 | gs_libGnomePrint->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
1942 | gs_libGnomePrint->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
1943 | ||
1944 | if (width) | |
1945 | *width = (int) (pw + 0.5); | |
1946 | if (height) | |
1947 | *height = (int) (ph + 0.5); | |
1948 | } | |
1949 | ||
1950 | wxSize wxGnomePrinterDC::GetPPI() const | |
1951 | { | |
1952 | return wxSize(DPI,DPI); | |
1953 | } | |
1954 | ||
1955 | void wxGnomePrinterDC::SetPrintData(const wxPrintData& data) | |
1956 | { | |
1957 | m_printData = data; | |
1958 | ||
1959 | int height; | |
1960 | if (m_printData.GetOrientation() == wxPORTRAIT) | |
1961 | GetSize( NULL, &height ); | |
1962 | else | |
1963 | GetSize( &height, NULL ); | |
1964 | m_deviceLocalOriginY = height; | |
1965 | } | |
1966 | ||
1967 | void wxGnomePrinterDC::SetResolution(int WXUNUSED(ppi)) | |
1968 | { | |
1969 | } | |
1970 | ||
1971 | int wxGnomePrinterDC::GetResolution() | |
1972 | { | |
1973 | return DPI; | |
1974 | } | |
1975 | ||
1976 | // ---------------------------------------------------------------------------- | |
1977 | // wxGnomePrintModule | |
1978 | // ---------------------------------------------------------------------------- | |
1979 | ||
1980 | bool wxGnomePrintModule::OnInit() | |
1981 | { | |
1982 | gs_libGnomePrint = new wxGnomePrintLibrary; | |
1983 | if (gs_libGnomePrint->IsOk()) | |
1984 | wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory ); | |
1985 | return true; | |
1986 | } | |
1987 | ||
1988 | void wxGnomePrintModule::OnExit() | |
1989 | { | |
1990 | delete gs_libGnomePrint; | |
1991 | gs_libGnomePrint = NULL; | |
1992 | } | |
1993 | ||
1994 | IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule) | |
1995 | ||
1996 | // ---------------------------------------------------------------------------- | |
1997 | // Print preview | |
1998 | // ---------------------------------------------------------------------------- | |
1999 | ||
2000 | IMPLEMENT_CLASS(wxGnomePrintPreview, wxPrintPreviewBase) | |
2001 | ||
2002 | void wxGnomePrintPreview::Init(wxPrintout * WXUNUSED(printout), | |
2003 | wxPrintout * WXUNUSED(printoutForPrinting)) | |
2004 | { | |
2005 | DetermineScaling(); | |
2006 | } | |
2007 | ||
2008 | wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, | |
2009 | wxPrintout *printoutForPrinting, | |
2010 | wxPrintDialogData *data) | |
2011 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
2012 | { | |
2013 | Init(printout, printoutForPrinting); | |
2014 | } | |
2015 | ||
2016 | wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, | |
2017 | wxPrintout *printoutForPrinting, | |
2018 | wxPrintData *data) | |
2019 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
2020 | { | |
2021 | Init(printout, printoutForPrinting); | |
2022 | } | |
2023 | ||
2024 | wxGnomePrintPreview::~wxGnomePrintPreview() | |
2025 | { | |
2026 | } | |
2027 | ||
2028 | bool wxGnomePrintPreview::Print(bool interactive) | |
2029 | { | |
2030 | if (!m_printPrintout) | |
2031 | return false; | |
2032 | ||
2033 | wxPrinter printer(& m_printDialogData); | |
2034 | return printer.Print(m_previewFrame, m_printPrintout, interactive); | |
2035 | } | |
2036 | ||
2037 | void wxGnomePrintPreview::DetermineScaling() | |
2038 | { | |
2039 | wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId(); | |
2040 | if (paperType == wxPAPER_NONE) | |
2041 | paperType = wxPAPER_NONE; | |
2042 | ||
2043 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType); | |
2044 | if (!paper) | |
2045 | paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); | |
2046 | ||
2047 | if (paper) | |
2048 | { | |
2049 | wxSize ScreenPixels = wxGetDisplaySize(); | |
2050 | wxSize ScreenMM = wxGetDisplaySizeMM(); | |
2051 | ||
2052 | m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), | |
2053 | (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); | |
2054 | m_previewPrintout->SetPPIPrinter(wxGnomePrinterDC::GetResolution(), wxGnomePrinterDC::GetResolution()); | |
2055 | ||
2056 | wxSize sizeDevUnits(paper->GetSizeDeviceUnits()); | |
2057 | ||
2058 | // TODO: get better resolution information from wxGnomePrinterDC, if possible. | |
2059 | ||
2060 | sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * wxGnomePrinterDC::GetResolution() / 72.0); | |
2061 | sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * wxGnomePrinterDC::GetResolution() / 72.0); | |
2062 | wxSize sizeTenthsMM(paper->GetSize()); | |
2063 | wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10); | |
2064 | ||
2065 | // If in landscape mode, we need to swap the width and height. | |
2066 | if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE ) | |
2067 | { | |
2068 | m_pageWidth = sizeDevUnits.y; | |
2069 | m_pageHeight = sizeDevUnits.x; | |
2070 | m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x); | |
2071 | } | |
2072 | else | |
2073 | { | |
2074 | m_pageWidth = sizeDevUnits.x; | |
2075 | m_pageHeight = sizeDevUnits.y; | |
2076 | m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y); | |
2077 | } | |
2078 | m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); | |
2079 | m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight)); | |
2080 | ||
2081 | // At 100%, the page should look about page-size on the screen. | |
2082 | m_previewScaleX = (float)0.8 * 72.0 / (float)wxGnomePrinterDC::GetResolution(); | |
2083 | m_previewScaleY = m_previewScaleX; | |
2084 | } | |
2085 | } | |
2086 | ||
2087 | #endif | |
2088 | // wxUSE_LIBGNOMEPRINT |