]>
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" |
02761f6c | 28 | #include "wx/module.h" |
e4db172a WS |
29 | #endif |
30 | ||
ff910433 | 31 | #include "wx/fontutil.h" |
ff910433 | 32 | #include "wx/gtk/private.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 | { | |
147bf263 | 312 | return new wxGnomePrintPreview( preview, printout, data ); |
ff910433 RR |
313 | } |
314 | ||
389076f1 WS |
315 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, |
316 | wxPrintout *printout, | |
ff910433 RR |
317 | wxPrintData *data ) |
318 | { | |
147bf263 | 319 | return new wxGnomePrintPreview( preview, printout, data ); |
ff910433 RR |
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 | ||
147bf263 JS |
357 | wxDC* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData& data ) |
358 | { | |
359 | return new wxGnomePrintDC(data); | |
360 | } | |
361 | ||
ff910433 RR |
362 | bool wxGnomePrintFactory::HasOwnPrintToFile() |
363 | { | |
364 | return true; | |
365 | } | |
366 | ||
367 | bool wxGnomePrintFactory::HasPrinterLine() | |
368 | { | |
369 | return true; | |
370 | } | |
371 | ||
372 | wxString wxGnomePrintFactory::CreatePrinterLine() | |
373 | { | |
2934005d RR |
374 | // redundant now |
375 | return wxEmptyString; | |
ff910433 RR |
376 | } |
377 | ||
378 | bool wxGnomePrintFactory::HasStatusLine() | |
379 | { | |
2934005d | 380 | // redundant now |
389076f1 | 381 | return true; |
ff910433 RR |
382 | } |
383 | ||
384 | wxString wxGnomePrintFactory::CreateStatusLine() | |
385 | { | |
2934005d RR |
386 | // redundant now |
387 | return wxEmptyString; | |
ff910433 RR |
388 | } |
389 | ||
390 | wxPrintNativeDataBase *wxGnomePrintFactory::CreatePrintNativeData() | |
391 | { | |
392 | return new wxGnomePrintNativeData; | |
393 | } | |
394 | ||
395 | //---------------------------------------------------------------------------- | |
396 | // wxGnomePrintSetupDialog | |
397 | //---------------------------------------------------------------------------- | |
398 | ||
2934005d RR |
399 | IMPLEMENT_CLASS(wxGnomePrintDialog, wxPrintDialogBase) |
400 | ||
401 | wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintDialogData *data ) | |
402 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
403 | wxPoint(0, 0), wxSize(600, 600), | |
404 | wxDEFAULT_DIALOG_STYLE | | |
405 | wxTAB_TRAVERSAL) | |
406 | { | |
407 | if (data) | |
408 | m_printDialogData = *data; | |
389076f1 | 409 | |
2934005d RR |
410 | Init(); |
411 | } | |
412 | ||
413 | wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintData *data ) | |
414 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
415 | wxPoint(0, 0), wxSize(600, 600), | |
416 | wxDEFAULT_DIALOG_STYLE | | |
417 | wxTAB_TRAVERSAL) | |
418 | { | |
419 | if (data) | |
420 | m_printDialogData = *data; | |
421 | ||
422 | Init(); | |
423 | } | |
ff910433 | 424 | |
2934005d | 425 | void wxGnomePrintDialog::Init() |
ff910433 | 426 | { |
2934005d RR |
427 | wxPrintData data = m_printDialogData.GetPrintData(); |
428 | ||
ff910433 | 429 | wxGnomePrintNativeData *native = |
2934005d | 430 | (wxGnomePrintNativeData*) data.GetNativeData(); |
389076f1 WS |
431 | |
432 | m_widget = gs_lgp->gnome_print_dialog_new( native->GetPrintJob(), | |
433 | (guchar*)"Print", | |
2934005d | 434 | GNOME_PRINT_DIALOG_RANGE|GNOME_PRINT_DIALOG_COPIES ); |
b199de59 RR |
435 | |
436 | int flag = 0; | |
437 | if (m_printDialogData.GetEnableSelection()) | |
438 | flag |= GNOME_PRINT_RANGE_SELECTION; | |
439 | if (m_printDialogData.GetEnablePageNumbers()) | |
440 | flag |= GNOME_PRINT_RANGE_ALL|GNOME_PRINT_RANGE_RANGE; | |
441 | ||
59c73be8 | 442 | gs_lgp->gnome_print_dialog_construct_range_page( (GnomePrintDialog*) m_widget, |
b199de59 RR |
443 | flag, |
444 | m_printDialogData.GetMinPage(), | |
445 | m_printDialogData.GetMaxPage(), | |
446 | NULL, | |
447 | NULL ); | |
ff910433 RR |
448 | } |
449 | ||
2934005d | 450 | wxGnomePrintDialog::~wxGnomePrintDialog() |
ff910433 RR |
451 | { |
452 | m_widget = NULL; | |
453 | } | |
454 | ||
2934005d | 455 | int wxGnomePrintDialog::ShowModal() |
ff910433 | 456 | { |
2934005d RR |
457 | // Transfer data from m_printDalogData to dialog here |
458 | ||
ff910433 | 459 | int response = gtk_dialog_run (GTK_DIALOG (m_widget)); |
389076f1 WS |
460 | |
461 | if (response == GNOME_PRINT_DIALOG_RESPONSE_CANCEL) | |
b199de59 RR |
462 | { |
463 | gtk_widget_destroy(m_widget); | |
464 | m_widget = NULL; | |
389076f1 | 465 | |
ff910433 | 466 | return wxID_CANCEL; |
b199de59 | 467 | } |
ff910433 | 468 | |
b199de59 RR |
469 | gint copies = 1; |
470 | gboolean collate = false; | |
59c73be8 | 471 | gs_lgp->gnome_print_dialog_get_copies( (GnomePrintDialog*) m_widget, &copies, &collate ); |
b199de59 RR |
472 | m_printDialogData.SetNoCopies( copies ); |
473 | m_printDialogData.SetCollate( collate ); | |
2934005d | 474 | |
59c73be8 | 475 | switch (gs_lgp->gnome_print_dialog_get_range( (GnomePrintDialog*) m_widget )) |
b199de59 RR |
476 | { |
477 | case GNOME_PRINT_RANGE_SELECTION: | |
478 | m_printDialogData.SetSelection( true ); | |
479 | break; | |
480 | case GNOME_PRINT_RANGE_ALL: | |
481 | m_printDialogData.SetAllPages( true ); | |
482 | m_printDialogData.SetFromPage( 0 ); | |
483 | m_printDialogData.SetToPage( 9999 ); | |
484 | break; | |
485 | case GNOME_PRINT_RANGE_RANGE: | |
486 | default: | |
487 | gint start,end; | |
59c73be8 | 488 | gs_lgp->gnome_print_dialog_get_range_page( (GnomePrintDialog*) m_widget, &start, &end ); |
b199de59 RR |
489 | m_printDialogData.SetFromPage( start ); |
490 | m_printDialogData.SetToPage( end ); | |
491 | break; | |
492 | } | |
493 | ||
494 | gtk_widget_destroy(m_widget); | |
495 | m_widget = NULL; | |
389076f1 | 496 | |
0be7709e RR |
497 | if (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW) |
498 | return wxID_PREVIEW; | |
389076f1 | 499 | |
ff910433 RR |
500 | return wxID_OK; |
501 | } | |
502 | ||
2934005d | 503 | wxDC *wxGnomePrintDialog::GetPrintDC() |
ff910433 | 504 | { |
2934005d RR |
505 | // Later |
506 | return NULL; | |
ff910433 RR |
507 | } |
508 | ||
2934005d | 509 | bool wxGnomePrintDialog::Validate() |
ff910433 RR |
510 | { |
511 | return true; | |
512 | } | |
513 | ||
2934005d | 514 | bool wxGnomePrintDialog::TransferDataToWindow() |
ff910433 RR |
515 | { |
516 | return true; | |
517 | } | |
518 | ||
2934005d RR |
519 | bool wxGnomePrintDialog::TransferDataFromWindow() |
520 | { | |
521 | return true; | |
522 | } | |
ff910433 | 523 | |
08680429 RR |
524 | //---------------------------------------------------------------------------- |
525 | // wxGnomePageSetupDialog | |
526 | //---------------------------------------------------------------------------- | |
527 | ||
528 | IMPLEMENT_CLASS(wxGnomePageSetupDialog, wxPageSetupDialogBase) | |
529 | ||
530 | wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow *parent, | |
531 | wxPageSetupDialogData* data ) | |
532 | { | |
533 | if (data) | |
534 | m_pageDialogData = *data; | |
389076f1 | 535 | |
08680429 RR |
536 | wxGnomePrintNativeData *native = |
537 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
cffcf831 RR |
538 | |
539 | // This is required as the page setup dialog | |
540 | // calculates wrong values otherwise. | |
59c73be8 | 541 | gs_lgp->gnome_print_config_set( native->GetPrintConfig(), |
cffcf831 RR |
542 | (const guchar*) GNOME_PRINT_KEY_PREFERED_UNIT, |
543 | (const guchar*) "Pts" ); | |
389076f1 | 544 | |
08680429 | 545 | m_widget = gtk_dialog_new(); |
389076f1 | 546 | |
08680429 | 547 | gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( _("Page setup") ) ); |
cffcf831 | 548 | |
389076f1 | 549 | GtkWidget *main = gs_lgp->gnome_paper_selector_new_with_flags( native->GetPrintConfig(), |
08680429 RR |
550 | GNOME_PAPER_SELECTOR_MARGINS|GNOME_PAPER_SELECTOR_FEED_ORIENTATION ); |
551 | gtk_container_set_border_width (GTK_CONTAINER (main), 8); | |
552 | gtk_widget_show (main); | |
389076f1 | 553 | |
08680429 | 554 | gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget)->vbox), main ); |
08680429 | 555 | |
389076f1 | 556 | gtk_dialog_set_has_separator (GTK_DIALOG (m_widget), TRUE); |
08680429 | 557 | |
389076f1 WS |
558 | gtk_dialog_add_buttons (GTK_DIALOG (m_widget), |
559 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
560 | GTK_STOCK_OK, GTK_RESPONSE_OK, | |
561 | NULL); | |
562 | ||
563 | gtk_dialog_set_default_response (GTK_DIALOG (m_widget), | |
564 | GTK_RESPONSE_OK); | |
08680429 RR |
565 | } |
566 | ||
567 | wxGnomePageSetupDialog::~wxGnomePageSetupDialog() | |
568 | { | |
569 | } | |
570 | ||
571 | wxPageSetupDialogData& wxGnomePageSetupDialog::GetPageSetupDialogData() | |
572 | { | |
573 | return m_pageDialogData; | |
574 | } | |
575 | ||
576 | int wxGnomePageSetupDialog::ShowModal() | |
577 | { | |
06cfd325 RR |
578 | wxGnomePrintNativeData *native = |
579 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
580 | GnomePrintConfig *config = native->GetPrintConfig(); | |
389076f1 | 581 | |
08680429 RR |
582 | // Transfer data from m_pageDialogData to native dialog |
583 | ||
584 | int ret = gtk_dialog_run( GTK_DIALOG(m_widget) ); | |
585 | ||
586 | if (ret == GTK_RESPONSE_OK) | |
587 | { | |
588 | // Transfer data back to m_pageDialogData | |
cffcf831 RR |
589 | |
590 | // I don't know how querying the last parameter works | |
591 | // I cannot test it as the dialog is currently broken | |
389076f1 | 592 | // anyways (it only works for points). |
06cfd325 | 593 | double ml,mr,mt,mb,pw,ph; |
389076f1 WS |
594 | gs_lgp->gnome_print_config_get_length (config, |
595 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &ml, NULL); | |
596 | gs_lgp->gnome_print_config_get_length (config, | |
597 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &mr, NULL); | |
598 | gs_lgp->gnome_print_config_get_length (config, | |
599 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &mt, NULL); | |
600 | gs_lgp->gnome_print_config_get_length (config, | |
601 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &mb, NULL); | |
602 | gs_lgp->gnome_print_config_get_length (config, | |
603 | (const guchar*) GNOME_PRINT_KEY_PAPER_WIDTH, &pw, NULL); | |
604 | gs_lgp->gnome_print_config_get_length (config, | |
605 | (const guchar*) GNOME_PRINT_KEY_PAPER_HEIGHT, &ph, NULL); | |
606 | ||
607 | // This probably assumes that the user entered the | |
cffcf831 RR |
608 | // values in Pts. Since that is the only the dialog |
609 | // works right now, we need to fix this later. | |
59c73be8 RR |
610 | const GnomePrintUnit *mm_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); |
611 | const GnomePrintUnit *pts_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
612 | gs_lgp->gnome_print_convert_distance( &ml, pts_unit, mm_unit ); | |
613 | gs_lgp->gnome_print_convert_distance( &mr, pts_unit, mm_unit ); | |
614 | gs_lgp->gnome_print_convert_distance( &mt, pts_unit, mm_unit ); | |
615 | gs_lgp->gnome_print_convert_distance( &mb, pts_unit, mm_unit ); | |
616 | gs_lgp->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
617 | gs_lgp->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
cffcf831 RR |
618 | |
619 | m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) ); | |
06cfd325 | 620 | m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) ); |
389076f1 | 621 | |
06cfd325 | 622 | m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) ); |
cffcf831 | 623 | |
cac7ac30 | 624 | #if 0 |
389076f1 | 625 | wxPrintf( wxT("paper %d %d, top margin %d\n"), |
06cfd325 RR |
626 | m_pageDialogData.GetPaperSize().x, |
627 | m_pageDialogData.GetPaperSize().y, | |
628 | m_pageDialogData.GetMarginTopLeft().x ); | |
629 | #endif | |
389076f1 | 630 | |
08680429 RR |
631 | ret = wxID_OK; |
632 | } | |
633 | else | |
634 | { | |
635 | ret = wxID_CANCEL; | |
636 | } | |
389076f1 | 637 | |
08680429 RR |
638 | gtk_widget_destroy( m_widget ); |
639 | m_widget = NULL; | |
640 | ||
641 | return ret; | |
642 | } | |
643 | ||
644 | bool wxGnomePageSetupDialog::Validate() | |
645 | { | |
646 | return true; | |
647 | } | |
648 | ||
649 | bool wxGnomePageSetupDialog::TransferDataToWindow() | |
650 | { | |
651 | return true; | |
652 | } | |
653 | ||
654 | bool wxGnomePageSetupDialog::TransferDataFromWindow() | |
655 | { | |
656 | return true; | |
657 | } | |
658 | ||
ff910433 RR |
659 | //---------------------------------------------------------------------------- |
660 | // wxGnomePrinter | |
661 | //---------------------------------------------------------------------------- | |
662 | ||
663 | IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase) | |
664 | ||
665 | wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) : | |
666 | wxPrinterBase( data ) | |
667 | { | |
668 | m_gpc = NULL; | |
0be7709e | 669 | m_native_preview = false; |
ff910433 RR |
670 | } |
671 | ||
672 | wxGnomePrinter::~wxGnomePrinter() | |
673 | { | |
674 | } | |
675 | ||
676 | bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) | |
677 | { | |
678 | if (!printout) | |
679 | { | |
680 | sm_lastError = wxPRINTER_ERROR; | |
681 | return false; | |
682 | } | |
683 | ||
684 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); | |
389076f1 | 685 | wxGnomePrintNativeData *native = |
ff910433 RR |
686 | (wxGnomePrintNativeData*) printdata.GetNativeData(); |
687 | ||
59c73be8 RR |
688 | GnomePrintJob *job = gs_lgp->gnome_print_job_new( native->GetPrintConfig() ); |
689 | m_gpc = gs_lgp->gnome_print_job_get_context (job); | |
cffcf831 | 690 | |
389076f1 | 691 | // The GnomePrintJob is temporarily stored in the |
2934005d | 692 | // native print data as the native print dialog |
981a6af1 | 693 | // needs to access it. |
cffcf831 RR |
694 | native->SetPrintJob( job ); |
695 | ||
981a6af1 RR |
696 | |
697 | printout->SetIsPreview(false); | |
698 | ||
699 | if (m_printDialogData.GetMinPage() < 1) | |
700 | m_printDialogData.SetMinPage(1); | |
701 | if (m_printDialogData.GetMaxPage() < 1) | |
702 | m_printDialogData.SetMaxPage(9999); | |
389076f1 | 703 | |
ff910433 | 704 | wxDC *dc; |
ff910433 RR |
705 | if (prompt) |
706 | dc = PrintDialog( parent ); | |
707 | else | |
708 | dc = new wxGnomePrintDC( this ); | |
389076f1 | 709 | |
0be7709e RR |
710 | if (m_native_preview) |
711 | printout->SetIsPreview(true); | |
389076f1 | 712 | |
ff910433 RR |
713 | if (!dc) |
714 | { | |
59c73be8 | 715 | gs_lgp->gnome_print_job_close( job ); |
3fe39b0c | 716 | g_object_unref (job); |
981a6af1 | 717 | sm_lastError = wxPRINTER_ERROR; |
ff910433 RR |
718 | return false; |
719 | } | |
720 | ||
981a6af1 RR |
721 | wxSize ScreenPixels = wxGetDisplaySize(); |
722 | wxSize ScreenMM = wxGetDisplaySizeMM(); | |
723 | ||
724 | printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), | |
725 | (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); | |
b199de59 RR |
726 | printout->SetPPIPrinter( wxGnomePrintDC::GetResolution(), |
727 | wxGnomePrintDC::GetResolution() ); | |
389076f1 | 728 | |
ff910433 RR |
729 | printout->SetDC(dc); |
730 | ||
981a6af1 RR |
731 | int w, h; |
732 | dc->GetSize(&w, &h); | |
733 | printout->SetPageSizePixels((int)w, (int)h); | |
734 | dc->GetSizeMM(&w, &h); | |
735 | printout->SetPageSizeMM((int)w, (int)h); | |
389076f1 | 736 | |
ff910433 | 737 | printout->OnPreparePrinting(); |
389076f1 | 738 | |
b199de59 RR |
739 | // Get some parameters from the printout, if defined |
740 | int fromPage, toPage; | |
741 | int minPage, maxPage; | |
742 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
ff910433 | 743 | |
b199de59 | 744 | if (maxPage == 0) |
ff910433 | 745 | { |
59c73be8 | 746 | gs_lgp->gnome_print_job_close( job ); |
3fe39b0c | 747 | g_object_unref (job); |
ff910433 | 748 | sm_lastError = wxPRINTER_ERROR; |
b199de59 | 749 | return false; |
ff910433 | 750 | } |
389076f1 | 751 | |
b199de59 RR |
752 | printout->OnBeginPrinting(); |
753 | ||
754 | int minPageNum = minPage, maxPageNum = maxPage; | |
755 | ||
756 | if ( !m_printDialogData.GetAllPages() ) | |
ff910433 | 757 | { |
b199de59 RR |
758 | minPageNum = m_printDialogData.GetFromPage(); |
759 | maxPageNum = m_printDialogData.GetToPage(); | |
760 | } | |
761 | ||
389076f1 | 762 | |
b199de59 RR |
763 | int copyCount; |
764 | for ( copyCount = 1; | |
765 | copyCount <= m_printDialogData.GetNoCopies(); | |
766 | copyCount++ ) | |
767 | { | |
768 | if (!printout->OnBeginDocument(minPageNum, maxPageNum)) | |
ff910433 | 769 | { |
b199de59 RR |
770 | wxLogError(_("Could not start printing.")); |
771 | sm_lastError = wxPRINTER_ERROR; | |
772 | break; | |
773 | } | |
389076f1 | 774 | |
b199de59 RR |
775 | int pn; |
776 | for ( pn = minPageNum; | |
777 | pn <= maxPageNum && printout->HasPage(pn); | |
778 | pn++ ) | |
389076f1 | 779 | { |
ff910433 RR |
780 | dc->StartPage(); |
781 | printout->OnPrintPage(pn); | |
782 | dc->EndPage(); | |
783 | } | |
389076f1 | 784 | |
ff910433 RR |
785 | printout->OnEndDocument(); |
786 | printout->OnEndPrinting(); | |
787 | } | |
389076f1 | 788 | |
59c73be8 | 789 | gs_lgp->gnome_print_job_close( job ); |
0be7709e RR |
790 | if (m_native_preview) |
791 | { | |
46e86fc3 | 792 | const wxCharBuffer title(wxGTK_CONV_SYS(_("Print preview"))); |
b8f32576 VZ |
793 | GtkWidget *preview = gs_lgp->gnome_print_job_preview_new |
794 | ( | |
795 | job, | |
46e86fc3 | 796 | (const guchar *)title.data() |
b8f32576 VZ |
797 | ); |
798 | gtk_widget_show(preview); | |
0be7709e RR |
799 | } |
800 | else | |
801 | { | |
59c73be8 | 802 | gs_lgp->gnome_print_job_print( job ); |
0be7709e | 803 | } |
389076f1 | 804 | |
3fe39b0c | 805 | g_object_unref (job); |
ff910433 | 806 | delete dc; |
389076f1 | 807 | |
ff910433 RR |
808 | return (sm_lastError == wxPRINTER_NO_ERROR); |
809 | } | |
810 | ||
811 | wxDC* wxGnomePrinter::PrintDialog( wxWindow *parent ) | |
812 | { | |
2934005d | 813 | wxGnomePrintDialog dialog( parent, &m_printDialogData ); |
0be7709e RR |
814 | int ret = dialog.ShowModal(); |
815 | if (ret == wxID_CANCEL) | |
ff910433 | 816 | { |
4843cdfe | 817 | sm_lastError = wxPRINTER_CANCELLED; |
ff910433 RR |
818 | return NULL; |
819 | } | |
389076f1 | 820 | |
0be7709e | 821 | m_native_preview = ret == wxID_PREVIEW; |
389076f1 | 822 | |
b199de59 | 823 | m_printDialogData = dialog.GetPrintDialogData(); |
ff910433 RR |
824 | return new wxGnomePrintDC( this ); |
825 | } | |
826 | ||
827 | bool wxGnomePrinter::Setup( wxWindow *parent ) | |
828 | { | |
58c30cd8 | 829 | return false; |
ff910433 RR |
830 | } |
831 | ||
832 | //----------------------------------------------------------------------------- | |
833 | // wxGnomePrintDC | |
834 | //----------------------------------------------------------------------------- | |
835 | ||
62075bca | 836 | IMPLEMENT_CLASS(wxGnomePrintDC, wxDC) |
ff910433 RR |
837 | |
838 | wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter *printer ) | |
839 | { | |
840 | m_printer = printer; | |
389076f1 | 841 | |
ff910433 | 842 | m_gpc = printer->GetPrintContext(); |
147bf263 | 843 | m_job = NULL; // only used and destroyed when created with wxPrintData |
389076f1 | 844 | |
59c73be8 | 845 | m_layout = gs_lgp->gnome_print_pango_create_layout( m_gpc ); |
ff910433 | 846 | m_fontdesc = pango_font_description_from_string( "Sans 12" ); |
389076f1 | 847 | |
ff910433 RR |
848 | m_currentRed = 0; |
849 | m_currentBlue = 0; | |
850 | m_currentGreen = 0; | |
389076f1 | 851 | |
ff910433 RR |
852 | m_signX = 1; // default x-axis left to right |
853 | m_signY = -1; // default y-axis bottom up -> top down | |
854 | } | |
855 | ||
147bf263 JS |
856 | wxGnomePrintDC::wxGnomePrintDC( const wxPrintData& data ) |
857 | { | |
858 | m_printer = NULL; | |
859 | m_printData = data; | |
860 | ||
861 | wxGnomePrintNativeData *native = | |
862 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
863 | ||
864 | GnomePrintJob *job = gs_lgp->gnome_print_job_new( native->GetPrintConfig() ); | |
865 | m_gpc = gs_lgp->gnome_print_job_get_context (job); | |
866 | m_job = job; // only used and destroyed when created with wxPrintData | |
867 | ||
868 | m_layout = gs_lgp->gnome_print_pango_create_layout( m_gpc ); | |
869 | m_fontdesc = pango_font_description_from_string( "Sans 12" ); | |
870 | ||
871 | m_currentRed = 0; | |
872 | m_currentBlue = 0; | |
873 | m_currentGreen = 0; | |
874 | ||
875 | m_signX = 1; // default x-axis left to right | |
876 | m_signY = -1; // default y-axis bottom up -> top down | |
877 | } | |
878 | ||
ff910433 RR |
879 | wxGnomePrintDC::~wxGnomePrintDC() |
880 | { | |
147bf263 JS |
881 | if (m_job) |
882 | g_object_unref (job); | |
ff910433 RR |
883 | } |
884 | ||
b7cacb43 | 885 | bool wxGnomePrintDC::IsOk() const |
ff910433 RR |
886 | { |
887 | return true; | |
888 | } | |
889 | ||
890 | bool wxGnomePrintDC::DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style ) | |
891 | { | |
892 | return false; | |
893 | } | |
894 | ||
895 | bool wxGnomePrintDC::DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const | |
896 | { | |
897 | return false; | |
898 | } | |
899 | ||
900 | void wxGnomePrintDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
901 | { | |
902 | if (m_pen.GetStyle() == wxTRANSPARENT) return; | |
389076f1 | 903 | |
ff910433 RR |
904 | SetPen( m_pen ); |
905 | ||
c6efd6e0 RR |
906 | gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) ); |
907 | gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) ); | |
908 | gs_lgp->gnome_print_stroke ( m_gpc); | |
cac7ac30 | 909 | |
ff910433 RR |
910 | CalcBoundingBox( x1, y1 ); |
911 | CalcBoundingBox( x2, y2 ); | |
912 | } | |
913 | ||
914 | void wxGnomePrintDC::DoCrossHair(wxCoord x, wxCoord y) | |
915 | { | |
916 | } | |
917 | ||
918 | void wxGnomePrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) | |
919 | { | |
2f41910a RR |
920 | double dx = x1 - xc; |
921 | double dy = y1 - yc; | |
922 | double radius = sqrt((double)(dx*dx+dy*dy)); | |
923 | double alpha1, alpha2; | |
924 | if (x1 == x2 && y1 == y2) | |
925 | { | |
926 | alpha1 = 0.0; | |
927 | alpha2 = 360.0; | |
928 | } | |
929 | else | |
930 | if (radius == 0.0) | |
931 | { | |
932 | alpha1 = alpha2 = 0.0; | |
933 | } | |
934 | else | |
935 | { | |
936 | alpha1 = (x1 - xc == 0) ? | |
937 | (y1 - yc < 0) ? 90.0 : -90.0 : | |
938 | -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; | |
939 | alpha2 = (x2 - xc == 0) ? | |
940 | (y2 - yc < 0) ? 90.0 : -90.0 : | |
941 | -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; | |
389076f1 | 942 | |
2f41910a RR |
943 | while (alpha1 <= 0) alpha1 += 360; |
944 | while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between | |
945 | while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree | |
946 | while (alpha2 > 360) alpha2 -= 360; | |
947 | } | |
948 | ||
949 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
950 | { | |
951 | SetBrush( m_brush ); | |
952 | gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); | |
953 | gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); | |
389076f1 | 954 | |
2f41910a RR |
955 | gs_lgp->gnome_print_fill( m_gpc ); |
956 | } | |
957 | ||
958 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
959 | { | |
960 | SetPen (m_pen); | |
961 | gs_lgp->gnome_print_newpath( m_gpc ); | |
962 | gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); | |
963 | gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); | |
964 | gs_lgp->gnome_print_closepath( m_gpc ); | |
389076f1 | 965 | |
2f41910a RR |
966 | gs_lgp->gnome_print_stroke( m_gpc ); |
967 | } | |
968 | ||
969 | CalcBoundingBox (x1, y1); | |
970 | CalcBoundingBox (x2, y2); | |
971 | CalcBoundingBox (xc, yc); | |
ff910433 RR |
972 | } |
973 | ||
974 | void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) | |
975 | { | |
16744532 RR |
976 | x += w/2; |
977 | y += h/2; | |
978 | ||
979 | int xx = XLOG2DEV(x); | |
980 | int yy = YLOG2DEV(y); | |
981 | ||
389076f1 | 982 | gs_lgp->gnome_print_gsave( m_gpc ); |
16744532 RR |
983 | |
984 | gs_lgp->gnome_print_translate( m_gpc, xx, yy ); | |
985 | double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w); | |
986 | gs_lgp->gnome_print_scale( m_gpc, 1.0, scale ); | |
389076f1 | 987 | |
16744532 RR |
988 | xx = 0; |
989 | yy = 0; | |
990 | ||
991 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
992 | { | |
993 | SetBrush( m_brush ); | |
389076f1 | 994 | |
16744532 | 995 | gs_lgp->gnome_print_moveto ( m_gpc, xx, yy ); |
389076f1 | 996 | gs_lgp->gnome_print_arcto( m_gpc, xx, yy, |
16744532 RR |
997 | XLOG2DEVREL(w)/2, sa, ea, 0 ); |
998 | gs_lgp->gnome_print_moveto ( m_gpc, xx, yy ); | |
389076f1 | 999 | |
16744532 RR |
1000 | gs_lgp->gnome_print_fill( m_gpc ); |
1001 | } | |
389076f1 | 1002 | |
16744532 RR |
1003 | if (m_pen.GetStyle () != wxTRANSPARENT) |
1004 | { | |
1005 | SetPen (m_pen); | |
389076f1 WS |
1006 | |
1007 | gs_lgp->gnome_print_arcto( m_gpc, xx, yy, | |
16744532 | 1008 | XLOG2DEVREL(w)/2, sa, ea, 0 ); |
389076f1 | 1009 | |
16744532 RR |
1010 | gs_lgp->gnome_print_stroke( m_gpc ); |
1011 | } | |
389076f1 | 1012 | |
16744532 | 1013 | gs_lgp->gnome_print_grestore( m_gpc ); |
389076f1 | 1014 | |
16744532 RR |
1015 | CalcBoundingBox( x, y ); |
1016 | CalcBoundingBox( x+w, y+h ); | |
ff910433 RR |
1017 | } |
1018 | ||
1019 | void wxGnomePrintDC::DoDrawPoint(wxCoord x, wxCoord y) | |
1020 | { | |
1021 | } | |
1022 | ||
1023 | void wxGnomePrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) | |
1024 | { | |
cac7ac30 RR |
1025 | if (m_pen.GetStyle() == wxTRANSPARENT) return; |
1026 | ||
1027 | if (n <= 0) return; | |
1028 | ||
1029 | SetPen (m_pen); | |
1030 | ||
1031 | int i; | |
1032 | for ( i =0; i<n ; i++ ) | |
16744532 | 1033 | CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset); |
cac7ac30 | 1034 | |
c6efd6e0 | 1035 | gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) ); |
389076f1 | 1036 | |
cac7ac30 | 1037 | for (i = 1; i < n; i++) |
c6efd6e0 | 1038 | gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) ); |
cac7ac30 | 1039 | |
c6efd6e0 | 1040 | gs_lgp->gnome_print_stroke ( m_gpc); |
ff910433 RR |
1041 | } |
1042 | ||
1043 | void wxGnomePrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
1044 | { | |
a92964a2 RR |
1045 | if (n==0) return; |
1046 | ||
1047 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1048 | { | |
1049 | SetBrush( m_brush ); | |
389076f1 | 1050 | |
a92964a2 RR |
1051 | int x = points[0].x + xoffset; |
1052 | int y = points[0].y + yoffset; | |
1053 | CalcBoundingBox( x, y ); | |
1054 | gs_lgp->gnome_print_newpath( m_gpc ); | |
1055 | gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1056 | int i; | |
1057 | for (i = 1; i < n; i++) | |
1058 | { | |
1059 | int x = points[i].x + xoffset; | |
1060 | int y = points[i].y + yoffset; | |
1061 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1062 | CalcBoundingBox( x, y ); | |
1063 | } | |
1064 | gs_lgp->gnome_print_closepath( m_gpc ); | |
1065 | gs_lgp->gnome_print_fill( m_gpc ); | |
1066 | } | |
1067 | ||
1068 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1069 | { | |
1070 | SetPen (m_pen); | |
1071 | ||
1072 | int x = points[0].x + xoffset; | |
1073 | int y = points[0].y + yoffset; | |
1074 | gs_lgp->gnome_print_newpath( m_gpc ); | |
1075 | gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1076 | int i; | |
1077 | for (i = 1; i < n; i++) | |
1078 | { | |
1079 | int x = points[i].x + xoffset; | |
1080 | int y = points[i].y + yoffset; | |
1081 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1082 | CalcBoundingBox( x, y ); | |
1083 | } | |
1084 | gs_lgp->gnome_print_closepath( m_gpc ); | |
1085 | gs_lgp->gnome_print_stroke( m_gpc ); | |
1086 | } | |
ff910433 RR |
1087 | } |
1088 | ||
1089 | void wxGnomePrintDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
1090 | { | |
a92964a2 | 1091 | wxDC::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle ); |
ff910433 RR |
1092 | } |
1093 | ||
1094 | void wxGnomePrintDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1095 | { | |
1096 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1097 | { | |
1098 | SetBrush( m_brush ); | |
389076f1 | 1099 | |
c6efd6e0 RR |
1100 | gs_lgp->gnome_print_newpath( m_gpc ); |
1101 | gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1102 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1103 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1104 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1105 | gs_lgp->gnome_print_closepath( m_gpc ); | |
1106 | gs_lgp->gnome_print_fill( m_gpc ); | |
ff910433 RR |
1107 | |
1108 | CalcBoundingBox( x, y ); | |
1109 | CalcBoundingBox( x + width, y + height ); | |
1110 | } | |
1111 | ||
1112 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1113 | { | |
1114 | SetPen (m_pen); | |
1115 | ||
c6efd6e0 RR |
1116 | gs_lgp->gnome_print_newpath( m_gpc ); |
1117 | gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1118 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1119 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1120 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1121 | gs_lgp->gnome_print_closepath( m_gpc ); | |
1122 | gs_lgp->gnome_print_stroke( m_gpc ); | |
389076f1 | 1123 | |
ff910433 RR |
1124 | CalcBoundingBox( x, y ); |
1125 | CalcBoundingBox( x + width, y + height ); | |
1126 | } | |
1127 | } | |
1128 | ||
1129 | void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) | |
1130 | { | |
9a2fe010 RR |
1131 | wxCoord rad = (wxCoord) radius; |
1132 | ||
1133 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
1134 | { | |
1135 | SetBrush(m_brush); | |
1136 | gs_lgp->gnome_print_newpath(m_gpc); | |
1137 | gs_lgp->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1138 | gs_lgp->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1139 | XLOG2DEV(x + rad),YLOG2DEV(y), |
1140 | XLOG2DEV(x),YLOG2DEV(y), | |
1141 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
9a2fe010 RR |
1142 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); |
1143 | gs_lgp->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1144 | XLOG2DEV(x),YLOG2DEV(y + height - rad), |
1145 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1146 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
9a2fe010 RR |
1147 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); |
1148 | gs_lgp->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1149 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), |
1150 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1151 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
9a2fe010 RR |
1152 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); |
1153 | gs_lgp->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1154 | XLOG2DEV(x + width),YLOG2DEV(y + rad), |
1155 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1156 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
9a2fe010 RR |
1157 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); |
1158 | gs_lgp->gnome_print_closepath(m_gpc); | |
1159 | gs_lgp->gnome_print_fill(m_gpc); | |
389076f1 | 1160 | |
9a2fe010 RR |
1161 | CalcBoundingBox(x,y); |
1162 | CalcBoundingBox(x+width,y+height); | |
1163 | } | |
389076f1 | 1164 | |
9a2fe010 RR |
1165 | if (m_pen.GetStyle() != wxTRANSPARENT) |
1166 | { | |
1167 | SetPen(m_pen); | |
1168 | gs_lgp->gnome_print_newpath(m_gpc); | |
1169 | gs_lgp->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1170 | gs_lgp->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1171 | XLOG2DEV(x + rad),YLOG2DEV(y), |
1172 | XLOG2DEV(x),YLOG2DEV(y), | |
1173 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
9a2fe010 RR |
1174 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); |
1175 | gs_lgp->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1176 | XLOG2DEV(x),YLOG2DEV(y + height - rad), |
1177 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1178 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
9a2fe010 RR |
1179 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); |
1180 | gs_lgp->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1181 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), |
1182 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1183 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
9a2fe010 RR |
1184 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); |
1185 | gs_lgp->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1186 | XLOG2DEV(x + width),YLOG2DEV(y + rad), |
1187 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1188 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
9a2fe010 RR |
1189 | gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); |
1190 | gs_lgp->gnome_print_closepath(m_gpc); | |
1191 | gs_lgp->gnome_print_stroke(m_gpc); | |
389076f1 | 1192 | |
9a2fe010 RR |
1193 | CalcBoundingBox(x,y); |
1194 | CalcBoundingBox(x+width,y+height); | |
1195 | } | |
ff910433 RR |
1196 | } |
1197 | ||
e4db172a | 1198 | void wxGnomePrintDC::makeEllipticalPath(wxCoord x, wxCoord y, |
74ab0bfb RR |
1199 | wxCoord width, wxCoord height) |
1200 | { | |
1201 | double r = 4 * (sqrt (2) - 1) / 3; | |
1202 | double halfW = 0.5 * width, | |
1203 | halfH = 0.5 * height, | |
1204 | halfWR = r * halfW, | |
1205 | halfHR = r * halfH; | |
1206 | wxCoord halfWI = (wxCoord) halfW, | |
1207 | halfHI = (wxCoord) halfH; | |
e4db172a | 1208 | |
74ab0bfb | 1209 | gs_lgp->gnome_print_newpath( m_gpc ); |
e4db172a | 1210 | |
74ab0bfb RR |
1211 | // Approximate an ellipse using four cubic splines, clockwise from 0 deg */ |
1212 | gs_lgp->gnome_print_moveto( m_gpc, | |
e4db172a | 1213 | XLOG2DEV(x + width), |
74ab0bfb RR |
1214 | YLOG2DEV(y + halfHI) ); |
1215 | gs_lgp->gnome_print_curveto( m_gpc, | |
1216 | XLOG2DEV(x + width), | |
1217 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), | |
e4db172a | 1218 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), |
74ab0bfb | 1219 | YLOG2DEV(y + height), |
e4db172a | 1220 | XLOG2DEV(x + halfWI), |
74ab0bfb RR |
1221 | YLOG2DEV(y + height) ); |
1222 | gs_lgp->gnome_print_curveto( m_gpc, | |
e4db172a | 1223 | XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)), |
74ab0bfb RR |
1224 | YLOG2DEV(y + height), |
1225 | XLOG2DEV(x), | |
1226 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), | |
1227 | XLOG2DEV(x), YLOG2DEV(y+halfHI) ); | |
1228 | gs_lgp->gnome_print_curveto( m_gpc, | |
1229 | XLOG2DEV(x), | |
1230 | YLOG2DEV(y + (wxCoord) rint (halfH - halfHR)), | |
1231 | XLOG2DEV(x + (wxCoord) rint (halfW - halfWR)), | |
1232 | YLOG2DEV(y), | |
1233 | XLOG2DEV(x+halfWI), YLOG2DEV(y) ); | |
1234 | gs_lgp->gnome_print_curveto( m_gpc, | |
1235 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), | |
1236 | YLOG2DEV(y), | |
1237 | XLOG2DEV(x + width), | |
1238 | YLOG2DEV(y + (wxCoord) rint(halfH - halfHR)), | |
1239 | XLOG2DEV(x + width), YLOG2DEV(y + halfHI) ); | |
e4db172a | 1240 | |
74ab0bfb RR |
1241 | gs_lgp->gnome_print_closepath(m_gpc); |
1242 | } | |
1243 | ||
ff910433 RR |
1244 | void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
1245 | { | |
cac7ac30 RR |
1246 | if (m_brush.GetStyle () != wxTRANSPARENT) |
1247 | { | |
1248 | SetBrush( m_brush ); | |
74ab0bfb | 1249 | makeEllipticalPath( x, y, width, height ); |
c6efd6e0 | 1250 | gs_lgp->gnome_print_fill( m_gpc ); |
cac7ac30 RR |
1251 | CalcBoundingBox( x, y ); |
1252 | CalcBoundingBox( x + width, y + height ); | |
1253 | } | |
1254 | ||
1255 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1256 | { | |
1257 | SetPen (m_pen); | |
74ab0bfb | 1258 | makeEllipticalPath( x, y, width, height ); |
c6efd6e0 | 1259 | gs_lgp->gnome_print_stroke( m_gpc ); |
cac7ac30 RR |
1260 | CalcBoundingBox( x, y ); |
1261 | CalcBoundingBox( x + width, y + height ); | |
1262 | } | |
ff910433 RR |
1263 | } |
1264 | ||
389076f1 | 1265 | #if wxUSE_SPLINES |
ff910433 RR |
1266 | void wxGnomePrintDC::DoDrawSpline(wxList *points) |
1267 | { | |
121c09cd RR |
1268 | SetPen (m_pen); |
1269 | ||
1270 | double c, d, x1, y1, x2, y2, x3, y3; | |
1271 | wxPoint *p, *q; | |
1272 | ||
1273 | wxList::compatibility_iterator node = points->GetFirst(); | |
1274 | p = (wxPoint *)node->GetData(); | |
1275 | x1 = p->x; | |
1276 | y1 = p->y; | |
1277 | ||
1278 | node = node->GetNext(); | |
1279 | p = (wxPoint *)node->GetData(); | |
1280 | c = p->x; | |
1281 | d = p->y; | |
1282 | x3 = | |
1283 | (double)(x1 + c) / 2; | |
1284 | y3 = | |
1285 | (double)(y1 + d) / 2; | |
1286 | ||
1287 | gs_lgp->gnome_print_newpath( m_gpc ); | |
1288 | gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) ); | |
1289 | gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
389076f1 | 1290 | |
121c09cd RR |
1291 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); |
1292 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1293 | ||
1294 | node = node->GetNext(); | |
1295 | while (node) | |
1296 | { | |
1297 | q = (wxPoint *)node->GetData(); | |
1298 | ||
1299 | x1 = x3; | |
1300 | y1 = y3; | |
1301 | x2 = c; | |
1302 | y2 = d; | |
1303 | c = q->x; | |
1304 | d = q->y; | |
1305 | x3 = (double)(x2 + c) / 2; | |
1306 | y3 = (double)(y2 + d) / 2; | |
1307 | ||
1308 | gs_lgp->gnome_print_curveto(m_gpc, | |
1309 | XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1), | |
1310 | XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2), | |
1311 | XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
1312 | ||
1313 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1314 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1315 | ||
1316 | node = node->GetNext(); | |
1317 | } | |
389076f1 | 1318 | |
121c09cd | 1319 | gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) ); |
389076f1 | 1320 | |
121c09cd | 1321 | gs_lgp->gnome_print_stroke( m_gpc ); |
ff910433 | 1322 | } |
389076f1 | 1323 | #endif // wxUSE_SPLINES |
ff910433 RR |
1324 | |
1325 | bool wxGnomePrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
1326 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask, | |
1327 | wxCoord xsrcMask, wxCoord ysrcMask) | |
1328 | { | |
2f41910a RR |
1329 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); |
1330 | ||
1331 | // blit into a bitmap | |
1332 | wxBitmap bitmap( width, height ); | |
1333 | wxMemoryDC memDC; | |
1334 | memDC.SelectObject(bitmap); | |
1335 | memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */ | |
1336 | memDC.SelectObject(wxNullBitmap); | |
1337 | ||
1338 | // draw bitmap. scaling and positioning is done there | |
1339 | DrawBitmap( bitmap, xdest, ydest ); | |
1340 | ||
1341 | return true; | |
ff910433 RR |
1342 | } |
1343 | ||
1344 | void wxGnomePrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) | |
1345 | { | |
e1bf3ad3 | 1346 | DoDrawBitmap( icon, x, y, true ); |
ff910433 RR |
1347 | } |
1348 | ||
1349 | void wxGnomePrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask ) | |
1350 | { | |
e1bf3ad3 | 1351 | if (!bitmap.Ok()) return; |
389076f1 | 1352 | |
e1bf3ad3 RR |
1353 | if (bitmap.HasPixbuf()) |
1354 | { | |
2934005d | 1355 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); |
389076f1 WS |
1356 | guchar *raw_image = gdk_pixbuf_get_pixels( pixbuf ); |
1357 | bool has_alpha = gdk_pixbuf_get_has_alpha( pixbuf ); | |
1358 | int rowstride = gdk_pixbuf_get_rowstride( pixbuf ); | |
1359 | int height = gdk_pixbuf_get_height( pixbuf ); | |
1360 | int width = gdk_pixbuf_get_width( pixbuf ); | |
1361 | ||
1362 | gs_lgp->gnome_print_gsave( m_gpc ); | |
2934005d | 1363 | double matrix[6]; |
389076f1 WS |
1364 | matrix[0] = XLOG2DEVREL(width); |
1365 | matrix[1] = 0; | |
1366 | matrix[2] = 0; | |
1367 | matrix[3] = YLOG2DEVREL(height); | |
1368 | matrix[4] = XLOG2DEV(x); | |
2934005d | 1369 | matrix[5] = YLOG2DEV(y+height); |
389076f1 WS |
1370 | gs_lgp->gnome_print_concat( m_gpc, matrix ); |
1371 | gs_lgp->gnome_print_moveto( m_gpc, 0, 0 ); | |
2934005d | 1372 | if (has_alpha) |
59c73be8 | 1373 | gs_lgp->gnome_print_rgbaimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); |
2934005d | 1374 | else |
59c73be8 RR |
1375 | gs_lgp->gnome_print_rgbimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); |
1376 | gs_lgp->gnome_print_grestore( m_gpc ); | |
e1bf3ad3 RR |
1377 | } |
1378 | else | |
e1bf3ad3 RR |
1379 | { |
1380 | wxImage image = bitmap.ConvertToImage(); | |
1381 | ||
1382 | if (!image.Ok()) return; | |
2934005d | 1383 | |
389076f1 | 1384 | gs_lgp->gnome_print_gsave( m_gpc ); |
b4382784 | 1385 | double matrix[6]; |
389076f1 WS |
1386 | matrix[0] = XLOG2DEVREL(image.GetWidth()); |
1387 | matrix[1] = 0; | |
1388 | matrix[2] = 0; | |
1389 | matrix[3] = YLOG2DEVREL(image.GetHeight()); | |
1390 | matrix[4] = XLOG2DEV(x); | |
b4382784 | 1391 | matrix[5] = YLOG2DEV(y+image.GetHeight()); |
389076f1 WS |
1392 | gs_lgp->gnome_print_concat( m_gpc, matrix ); |
1393 | gs_lgp->gnome_print_moveto( m_gpc, 0, 0 ); | |
59c73be8 RR |
1394 | gs_lgp->gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 ); |
1395 | gs_lgp->gnome_print_grestore( m_gpc ); | |
e1bf3ad3 | 1396 | } |
ff910433 RR |
1397 | } |
1398 | ||
1399 | void wxGnomePrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y ) | |
b199de59 RR |
1400 | { |
1401 | DoDrawRotatedText( text, x, y, 0.0 ); | |
1402 | } | |
1403 | ||
1404 | void wxGnomePrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) | |
ff910433 | 1405 | { |
ff910433 RR |
1406 | x = XLOG2DEV(x); |
1407 | y = YLOG2DEV(y); | |
389076f1 | 1408 | |
ff910433 RR |
1409 | bool underlined = m_font.Ok() && m_font.GetUnderlined(); |
1410 | ||
1411 | #if wxUSE_UNICODE | |
1412 | const wxCharBuffer data = wxConvUTF8.cWC2MB( text ); | |
1413 | #else | |
1414 | const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text ); | |
1415 | if ( !wdata ) | |
1416 | return; | |
1417 | const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); | |
1418 | #endif | |
1419 | ||
1420 | size_t datalen = strlen((const char*)data); | |
1421 | pango_layout_set_text( m_layout, (const char*) data, datalen); | |
389076f1 | 1422 | |
ff910433 RR |
1423 | if (underlined) |
1424 | { | |
1425 | PangoAttrList *attrs = pango_attr_list_new(); | |
1426 | PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); | |
1427 | a->start_index = 0; | |
1428 | a->end_index = datalen; | |
1429 | pango_attr_list_insert(attrs, a); | |
1430 | pango_layout_set_attributes(m_layout, attrs); | |
1431 | pango_attr_list_unref(attrs); | |
1432 | } | |
1433 | ||
2934005d RR |
1434 | if (m_textForegroundColour.Ok()) |
1435 | { | |
1436 | unsigned char red = m_textForegroundColour.Red(); | |
1437 | unsigned char blue = m_textForegroundColour.Blue(); | |
1438 | unsigned char green = m_textForegroundColour.Green(); | |
1439 | ||
b199de59 RR |
1440 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) |
1441 | { | |
1442 | double redPS = (double)(red) / 255.0; | |
1443 | double bluePS = (double)(blue) / 255.0; | |
1444 | double greenPS = (double)(green) / 255.0; | |
1445 | ||
c6efd6e0 | 1446 | gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
b199de59 RR |
1447 | |
1448 | m_currentRed = red; | |
1449 | m_currentBlue = blue; | |
1450 | m_currentGreen = green; | |
1451 | } | |
2934005d RR |
1452 | } |
1453 | ||
fa499247 RR |
1454 | int w,h; |
1455 | ||
1456 | if (fabs(m_scaleY - 1.0) > 0.00001) | |
1457 | { | |
1458 | // If there is a user or actually any scale applied to | |
1459 | // the device context, scale the font. | |
389076f1 | 1460 | |
fa499247 RR |
1461 | // scale font description |
1462 | gint oldSize = pango_font_description_get_size( m_fontdesc ); | |
1463 | double size = oldSize; | |
1464 | size = size * m_scaleY; | |
1465 | pango_font_description_set_size( m_fontdesc, (gint)size ); | |
389076f1 | 1466 | |
fa499247 RR |
1467 | // actually apply scaled font |
1468 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
389076f1 | 1469 | |
fa499247 RR |
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 | } |
389076f1 | 1492 | |
fa499247 RR |
1493 | // reset unscaled size |
1494 | pango_font_description_set_size( m_fontdesc, oldSize ); | |
389076f1 | 1495 | |
fa499247 RR |
1496 | // actually apply unscaled font |
1497 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
1498 | } | |
1499 | else | |
1500 | { | |
1501 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1502 | #if 0 | |
1503 | if ( m_backgroundMode == wxSOLID ) | |
1504 | { | |
1505 | gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); | |
1506 | gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h); | |
1507 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); | |
1508 | } | |
389076f1 | 1509 | #endif |
fa499247 | 1510 | // Draw layout. |
389076f1 | 1511 | gs_lgp->gnome_print_moveto (m_gpc, x, y); |
b199de59 | 1512 | if (fabs(angle) > 0.00001) |
389076f1 | 1513 | { |
59c73be8 RR |
1514 | gs_lgp->gnome_print_gsave( m_gpc ); |
1515 | gs_lgp->gnome_print_rotate( m_gpc, angle ); | |
389076f1 | 1516 | gs_lgp->gnome_print_pango_layout( m_gpc, m_layout ); |
59c73be8 | 1517 | gs_lgp->gnome_print_grestore( m_gpc ); |
b199de59 RR |
1518 | } |
1519 | else | |
1520 | { | |
389076f1 | 1521 | gs_lgp->gnome_print_pango_layout( m_gpc, m_layout ); |
b199de59 | 1522 | } |
fa499247 RR |
1523 | } |
1524 | ||
ff910433 RR |
1525 | if (underlined) |
1526 | { | |
1527 | // undo underline attributes setting: | |
1528 | pango_layout_set_attributes(m_layout, NULL); | |
1529 | } | |
389076f1 | 1530 | |
b199de59 | 1531 | CalcBoundingBox (x + w, y + h); |
ff910433 RR |
1532 | } |
1533 | ||
1534 | void wxGnomePrintDC::Clear() | |
1535 | { | |
1536 | } | |
1537 | ||
1538 | void wxGnomePrintDC::SetFont( const wxFont& font ) | |
1539 | { | |
1540 | m_font = font; | |
389076f1 | 1541 | |
ff910433 RR |
1542 | if (m_font.Ok()) |
1543 | { | |
1544 | if (m_fontdesc) | |
1545 | pango_font_description_free( m_fontdesc ); | |
389076f1 | 1546 | |
ff910433 | 1547 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); |
389076f1 | 1548 | |
ff910433 RR |
1549 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
1550 | } | |
1551 | } | |
1552 | ||
1553 | void wxGnomePrintDC::SetPen( const wxPen& pen ) | |
1554 | { | |
1555 | if (!pen.Ok()) return; | |
1556 | ||
ff910433 RR |
1557 | m_pen = pen; |
1558 | ||
c6efd6e0 | 1559 | gs_lgp->gnome_print_setlinewidth( m_gpc, XLOG2DEVREL( 1000 * m_pen.GetWidth() ) / 1000.0f ); |
cac7ac30 RR |
1560 | |
1561 | static const double dotted[] = {2.0, 5.0}; | |
1562 | static const double short_dashed[] = {4.0, 4.0}; | |
1563 | static const double wxCoord_dashed[] = {4.0, 8.0}; | |
1564 | static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0}; | |
1565 | ||
1566 | switch (m_pen.GetStyle()) | |
1567 | { | |
59c73be8 RR |
1568 | case wxDOT: gs_lgp->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break; |
1569 | case wxSHORT_DASH: gs_lgp->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break; | |
1570 | case wxLONG_DASH: gs_lgp->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break; | |
1571 | case wxDOT_DASH: gs_lgp->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break; | |
e4db172a | 1572 | case wxUSER_DASH: |
8c419a5c RR |
1573 | { |
1574 | // It may be noted that libgnomeprint between at least | |
1575 | // versions 2.8.0 and 2.12.1 makes a copy of the dashes | |
1576 | // and then leak the memory since it doesn't set the | |
1577 | // internal flag "privatedash" to 0. | |
1578 | wxDash *wx_dashes; | |
1579 | int num = m_pen.GetDashes (&wx_dashes); | |
1580 | gdouble *g_dashes = g_new( gdouble, num ); | |
1581 | int i; | |
1582 | for (i = 0; i < num; ++i) | |
1583 | g_dashes[i] = (gdouble) wx_dashes[i]; | |
1584 | gs_lgp -> gnome_print_setdash( m_gpc, num, g_dashes, 0); | |
1585 | g_free( g_dashes ); | |
1586 | } | |
1587 | break; | |
cac7ac30 RR |
1588 | case wxSOLID: |
1589 | case wxTRANSPARENT: | |
59c73be8 | 1590 | default: gs_lgp->gnome_print_setdash( m_gpc, 0, NULL, 0 ); break; |
cac7ac30 RR |
1591 | } |
1592 | ||
389076f1 | 1593 | |
ff910433 RR |
1594 | unsigned char red = m_pen.GetColour().Red(); |
1595 | unsigned char blue = m_pen.GetColour().Blue(); | |
1596 | unsigned char green = m_pen.GetColour().Green(); | |
1597 | ||
1598 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1599 | { | |
1600 | double redPS = (double)(red) / 255.0; | |
1601 | double bluePS = (double)(blue) / 255.0; | |
1602 | double greenPS = (double)(green) / 255.0; | |
1603 | ||
c6efd6e0 | 1604 | gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
ff910433 RR |
1605 | |
1606 | m_currentRed = red; | |
1607 | m_currentBlue = blue; | |
1608 | m_currentGreen = green; | |
1609 | } | |
1610 | } | |
1611 | ||
1612 | void wxGnomePrintDC::SetBrush( const wxBrush& brush ) | |
1613 | { | |
fa499247 RR |
1614 | if (!brush.Ok()) return; |
1615 | ||
1616 | m_brush = brush; | |
1617 | ||
1618 | // Brush colour | |
1619 | unsigned char red = m_brush.GetColour().Red(); | |
1620 | unsigned char blue = m_brush.GetColour().Blue(); | |
1621 | unsigned char green = m_brush.GetColour().Green(); | |
1622 | ||
1623 | if (!m_colour) | |
1624 | { | |
1625 | // Anything not white is black | |
1626 | if (! (red == (unsigned char) 255 && | |
1627 | blue == (unsigned char) 255 && | |
1628 | green == (unsigned char) 255) ) | |
1629 | { | |
1630 | red = (unsigned char) 0; | |
1631 | green = (unsigned char) 0; | |
1632 | blue = (unsigned char) 0; | |
1633 | } | |
1634 | // setgray here ? | |
1635 | } | |
1636 | ||
1637 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1638 | { | |
1639 | double redPS = (double)(red) / 255.0; | |
1640 | double bluePS = (double)(blue) / 255.0; | |
1641 | double greenPS = (double)(green) / 255.0; | |
1642 | ||
c6efd6e0 | 1643 | gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
fa499247 RR |
1644 | |
1645 | m_currentRed = red; | |
1646 | m_currentBlue = blue; | |
1647 | m_currentGreen = green; | |
1648 | } | |
ff910433 RR |
1649 | } |
1650 | ||
1651 | void wxGnomePrintDC::SetLogicalFunction( int function ) | |
1652 | { | |
1653 | } | |
1654 | ||
1655 | void wxGnomePrintDC::SetBackground( const wxBrush& brush ) | |
1656 | { | |
1657 | } | |
1658 | ||
1659 | void wxGnomePrintDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1660 | { | |
1661 | } | |
1662 | ||
1663 | void wxGnomePrintDC::DestroyClippingRegion() | |
1664 | { | |
1665 | } | |
1666 | ||
1667 | bool wxGnomePrintDC::StartDoc(const wxString& message) | |
1668 | { | |
1669 | SetDeviceOrigin( 0,0 ); | |
389076f1 | 1670 | |
ff910433 RR |
1671 | return true; |
1672 | } | |
1673 | ||
1674 | void wxGnomePrintDC::EndDoc() | |
1675 | { | |
59c73be8 | 1676 | gs_lgp->gnome_print_end_doc( m_gpc ); |
ff910433 RR |
1677 | } |
1678 | ||
1679 | void wxGnomePrintDC::StartPage() | |
1680 | { | |
389076f1 | 1681 | gs_lgp->gnome_print_beginpage( m_gpc, (const guchar*) "page" ); |
ff910433 RR |
1682 | } |
1683 | ||
1684 | void wxGnomePrintDC::EndPage() | |
1685 | { | |
389076f1 | 1686 | gs_lgp->gnome_print_showpage( m_gpc ); |
ff910433 RR |
1687 | } |
1688 | ||
1689 | wxCoord wxGnomePrintDC::GetCharHeight() const | |
1690 | { | |
b199de59 | 1691 | pango_layout_set_text( m_layout, "H", 1 ); |
389076f1 | 1692 | |
b199de59 RR |
1693 | int w,h; |
1694 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
389076f1 | 1695 | |
b199de59 | 1696 | return h; |
ff910433 RR |
1697 | } |
1698 | ||
1699 | wxCoord wxGnomePrintDC::GetCharWidth() const | |
1700 | { | |
b199de59 | 1701 | pango_layout_set_text( m_layout, "H", 1 ); |
389076f1 | 1702 | |
b199de59 RR |
1703 | int w,h; |
1704 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
389076f1 | 1705 | |
b199de59 | 1706 | return w; |
ff910433 RR |
1707 | } |
1708 | ||
981a6af1 | 1709 | void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, |
ff910433 RR |
1710 | wxCoord *descent, |
1711 | wxCoord *externalLeading, | |
1712 | wxFont *theFont ) const | |
1713 | { | |
981a6af1 RR |
1714 | if ( width ) |
1715 | *width = 0; | |
1716 | if ( height ) | |
1717 | *height = 0; | |
1718 | if ( descent ) | |
1719 | *descent = 0; | |
1720 | if ( externalLeading ) | |
1721 | *externalLeading = 0; | |
1722 | ||
389076f1 | 1723 | if (string.empty()) |
981a6af1 RR |
1724 | { |
1725 | return; | |
1726 | } | |
389076f1 | 1727 | |
981a6af1 RR |
1728 | // Set new font description |
1729 | if (theFont) | |
1730 | pango_layout_set_font_description( m_layout, theFont->GetNativeFontInfo()->description ); | |
389076f1 | 1731 | |
981a6af1 RR |
1732 | // Set layout's text |
1733 | #if wxUSE_UNICODE | |
1734 | const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); | |
1735 | const char *dataUTF8 = (const char *)data; | |
1736 | #else | |
1737 | const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string ); | |
1738 | if ( !wdata ) | |
1739 | { | |
1740 | if (width) (*width) = 0; | |
1741 | if (height) (*height) = 0; | |
1742 | return; | |
1743 | } | |
1744 | const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); | |
1745 | const char *dataUTF8 = (const char *)data; | |
1746 | #endif | |
1747 | ||
1748 | if ( !dataUTF8 ) | |
1749 | { | |
1750 | // hardly ideal, but what else can we do if conversion failed? | |
1751 | return; | |
1752 | } | |
1753 | ||
1754 | pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); | |
389076f1 | 1755 | |
981a6af1 RR |
1756 | int w,h; |
1757 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
389076f1 | 1758 | |
981a6af1 | 1759 | if (width) |
389076f1 | 1760 | *width = (wxCoord)(w / m_scaleX); |
981a6af1 | 1761 | if (height) |
15236815 | 1762 | *height = (wxCoord)(h / m_scaleY); |
981a6af1 RR |
1763 | if (descent) |
1764 | { | |
1765 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); | |
1766 | int baseline = pango_layout_iter_get_baseline(iter); | |
1767 | pango_layout_iter_free(iter); | |
1768 | *descent = h - PANGO_PIXELS(baseline); | |
1769 | } | |
389076f1 | 1770 | |
981a6af1 RR |
1771 | // Reset old font description |
1772 | if (theFont) | |
1773 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
ff910433 RR |
1774 | } |
1775 | ||
1776 | void wxGnomePrintDC::DoGetSize(int* width, int* height) const | |
1777 | { | |
cffcf831 RR |
1778 | wxGnomePrintNativeData *native = |
1779 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1780 | ||
1781 | // Query page size. This seems to omit the margins | |
1782 | // right now, although it shouldn't | |
1783 | double pw,ph; | |
59c73be8 | 1784 | gs_lgp->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
ff910433 | 1785 | |
ff910433 | 1786 | if (width) |
cffcf831 | 1787 | *width = (int) (pw + 0.5); |
ff910433 | 1788 | if (height) |
cffcf831 | 1789 | *height = (int) (ph + 0.5); |
ff910433 RR |
1790 | } |
1791 | ||
1792 | void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const | |
1793 | { | |
cffcf831 RR |
1794 | wxGnomePrintNativeData *native = |
1795 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1796 | ||
389076f1 WS |
1797 | // This code assumes values in Pts. |
1798 | ||
cffcf831 | 1799 | double pw,ph; |
59c73be8 | 1800 | gs_lgp->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
cffcf831 RR |
1801 | |
1802 | // Convert to mm. | |
389076f1 | 1803 | |
59c73be8 RR |
1804 | const GnomePrintUnit *mm_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); |
1805 | const GnomePrintUnit *pts_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
1806 | gs_lgp->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
1807 | gs_lgp->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
389076f1 | 1808 | |
ff910433 | 1809 | if (width) |
cffcf831 | 1810 | *width = (int) (pw + 0.5); |
ff910433 | 1811 | if (height) |
cffcf831 | 1812 | *height = (int) (ph + 0.5); |
ff910433 RR |
1813 | } |
1814 | ||
1815 | wxSize wxGnomePrintDC::GetPPI() const | |
1816 | { | |
1817 | return wxSize(72,72); | |
1818 | } | |
1819 | ||
1820 | void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
1821 | { | |
1822 | m_signX = (xLeftRight ? 1 : -1); | |
1823 | m_signY = (yBottomUp ? 1 : -1); | |
1824 | ||
1825 | ComputeScaleAndOrigin(); | |
1826 | } | |
1827 | ||
1828 | void wxGnomePrintDC::SetDeviceOrigin( wxCoord x, wxCoord y ) | |
1829 | { | |
1830 | int h = 0; | |
1831 | int w = 0; | |
1832 | GetSize( &w, &h ); | |
1833 | ||
1834 | wxDC::SetDeviceOrigin( x, h-y ); | |
1835 | } | |
1836 | ||
1837 | void wxGnomePrintDC::SetResolution(int ppi) | |
1838 | { | |
1839 | } | |
1840 | ||
1841 | int wxGnomePrintDC::GetResolution() | |
1842 | { | |
1843 | return 72; | |
1844 | } | |
7c72311f | 1845 | |
58c30cd8 RR |
1846 | |
1847 | class wxGnomePrintModule: public wxModule | |
1848 | { | |
1849 | public: | |
1850 | wxGnomePrintModule() {} | |
c6efd6e0 RR |
1851 | bool OnInit(); |
1852 | void OnExit(); | |
389076f1 | 1853 | |
58c30cd8 RR |
1854 | private: |
1855 | DECLARE_DYNAMIC_CLASS(wxGnomePrintModule) | |
1856 | }; | |
1857 | ||
c6efd6e0 RR |
1858 | bool wxGnomePrintModule::OnInit() |
1859 | { | |
1860 | gs_lgp = new wxGnomePrintLibrary; | |
1861 | if (gs_lgp->IsOk()) | |
1862 | wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory ); | |
1863 | return true; | |
1864 | } | |
1865 | ||
1866 | void wxGnomePrintModule::OnExit() | |
1867 | { | |
1868 | delete gs_lgp; | |
1869 | } | |
1870 | ||
58c30cd8 | 1871 | IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule) |
389076f1 | 1872 | |
147bf263 JS |
1873 | // ---------------------------------------------------------------------------- |
1874 | // Print preview | |
1875 | // ---------------------------------------------------------------------------- | |
1876 | ||
1877 | IMPLEMENT_CLASS(wxGnomePrintPreview, wxPrintPreviewBase) | |
1878 | ||
1879 | void wxGnomePrintPreview::Init(wxPrintout * WXUNUSED(printout), | |
1880 | wxPrintout * WXUNUSED(printoutForPrinting)) | |
1881 | { | |
1882 | DetermineScaling(); | |
1883 | } | |
1884 | ||
1885 | wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, | |
1886 | wxPrintout *printoutForPrinting, | |
1887 | wxPrintDialogData *data) | |
1888 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
1889 | { | |
1890 | Init(printout, printoutForPrinting); | |
1891 | } | |
1892 | ||
1893 | wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, | |
1894 | wxPrintout *printoutForPrinting, | |
1895 | wxPrintData *data) | |
1896 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
1897 | { | |
1898 | Init(printout, printoutForPrinting); | |
1899 | } | |
1900 | ||
1901 | wxGnomePrintPreview::~wxGnomePrintPreview() | |
1902 | { | |
1903 | } | |
1904 | ||
1905 | bool wxGnomePrintPreview::Print(bool interactive) | |
1906 | { | |
1907 | if (!m_printPrintout) | |
1908 | return false; | |
1909 | ||
1910 | wxPrinter printer(& m_printDialogData); | |
1911 | return printer.Print(m_previewFrame, m_printPrintout, interactive); | |
1912 | } | |
1913 | ||
1914 | void wxGnomePrintPreview::DetermineScaling() | |
1915 | { | |
1916 | wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId(); | |
1917 | if (paperType == wxPAPER_NONE) | |
1918 | paperType = wxPAPER_NONE; | |
1919 | ||
1920 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType); | |
1921 | if (!paper) | |
1922 | paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); | |
1923 | ||
1924 | if (paper) | |
1925 | { | |
1926 | wxSize ScreenPixels = wxGetDisplaySize(); | |
1927 | wxSize ScreenMM = wxGetDisplaySizeMM(); | |
1928 | ||
1929 | m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), | |
1930 | (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); | |
1931 | m_previewPrintout->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution()); | |
1932 | ||
1933 | wxSize sizeDevUnits(paper->GetSizeDeviceUnits()); | |
1934 | ||
1935 | // TODO: get better resolution information from wxGnomePrintDC, if possible. | |
1936 | ||
1937 | sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * wxGnomePrintDC::GetResolution() / 72.0); | |
1938 | sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * wxGnomePrintDC::GetResolution() / 72.0); | |
1939 | wxSize sizeTenthsMM(paper->GetSize()); | |
1940 | wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10); | |
1941 | ||
1942 | // If in landscape mode, we need to swap the width and height. | |
1943 | if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE ) | |
1944 | { | |
1945 | m_pageWidth = sizeDevUnits.y; | |
1946 | m_pageHeight = sizeDevUnits.x; | |
1947 | m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x); | |
1948 | m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); | |
1949 | } | |
1950 | else | |
1951 | { | |
1952 | m_pageWidth = sizeDevUnits.x; | |
1953 | m_pageHeight = sizeDevUnits.y; | |
1954 | m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y); | |
1955 | m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); | |
1956 | } | |
1957 | ||
1958 | // At 100%, the page should look about page-size on the screen. | |
1959 | m_previewScale = (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution(); | |
1960 | } | |
1961 | } | |
1962 | ||
7c72311f RR |
1963 | #endif |
1964 | // wxUSE_LIBGNOMEPRINT |