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