]>
Commit | Line | Data |
---|---|---|
ff910433 | 1 | ///////////////////////////////////////////////////////////////////////////// |
f85b45fb RR |
2 | // Name: gprint.cpp |
3 | // Author: Robert Roebling | |
4 | // Purpose: Implement GNOME printing support | |
5 | // Created: 09/20/04 | |
6 | // Copyright: Robert Roebling | |
7 | // Licence: wxWindows Licence | |
ff910433 RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
58c30cd8 RR |
10 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
11 | #pragma implementation "gprint.h" | |
ff910433 RR |
12 | #endif |
13 | ||
14 | // For compilers that support precompilation, includes "wx/wx.h". | |
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
7c72311f RR |
21 | #include "wx/gtk/gnome/gprint.h" |
22 | ||
23 | #if wxUSE_LIBGNOMEPRINT | |
24 | ||
fa499247 RR |
25 | #include "math.h" |
26 | ||
ff910433 RR |
27 | #include "wx/fontutil.h" |
28 | #include "wx/printdlg.h" | |
29 | #include "wx/gtk/private.h" | |
30 | ||
31 | #include <libgnomeprint/gnome-print.h> | |
32 | #include <libgnomeprint/gnome-print-pango.h> | |
33 | #include <libgnomeprintui/gnome-print-dialog.h> | |
34 | ||
35 | //---------------------------------------------------------------------------- | |
36 | // wxGnomePrintNativeData | |
37 | //---------------------------------------------------------------------------- | |
38 | ||
39 | IMPLEMENT_CLASS(wxGnomePrintNativeData, wxPrintNativeDataBase) | |
40 | ||
41 | wxGnomePrintNativeData::wxGnomePrintNativeData() | |
42 | { | |
43 | m_config = gnome_print_config_default(); | |
44 | m_job = gnome_print_job_new( m_config ); | |
45 | } | |
46 | ||
47 | wxGnomePrintNativeData::~wxGnomePrintNativeData() | |
48 | { | |
49 | g_object_unref (G_OBJECT (m_config)); | |
50 | g_object_unref (G_OBJECT (m_job)); | |
51 | } | |
52 | ||
53 | bool wxGnomePrintNativeData::TransferTo( wxPrintData &data ) | |
54 | { | |
55 | // TODO | |
56 | return true; | |
57 | } | |
58 | ||
59 | bool wxGnomePrintNativeData::TransferFrom( const wxPrintData &data ) | |
60 | { | |
61 | // TODO | |
62 | return true; | |
63 | } | |
64 | ||
65 | //---------------------------------------------------------------------------- | |
66 | // wxGnomePrintFactory | |
67 | //---------------------------------------------------------------------------- | |
68 | ||
69 | wxPrinterBase* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData *data ) | |
70 | { | |
71 | return new wxGnomePrinter( data ); | |
72 | } | |
73 | ||
74 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, | |
75 | wxPrintout *printout, | |
76 | wxPrintDialogData *data ) | |
77 | { | |
78 | return new wxPostScriptPrintPreview( preview, printout, data ); | |
79 | } | |
80 | ||
81 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, | |
82 | wxPrintout *printout, | |
83 | wxPrintData *data ) | |
84 | { | |
85 | return new wxPostScriptPrintPreview( preview, printout, data ); | |
86 | } | |
87 | ||
88 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, | |
89 | wxPrintDialogData *data ) | |
90 | { | |
91 | return new wxGenericPrintDialog( parent, data ); | |
92 | } | |
93 | ||
94 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, | |
95 | wxPrintData *data ) | |
96 | { | |
97 | return new wxGenericPrintDialog( parent, data ); | |
98 | } | |
99 | ||
100 | bool wxGnomePrintFactory::HasPrintSetupDialog() | |
101 | { | |
102 | return true; | |
103 | } | |
104 | ||
105 | wxDialog *wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data ) | |
106 | { | |
107 | return new wxGnomePrintSetupDialog( parent, data ); | |
108 | } | |
109 | ||
110 | bool wxGnomePrintFactory::HasOwnPrintToFile() | |
111 | { | |
112 | return true; | |
113 | } | |
114 | ||
115 | bool wxGnomePrintFactory::HasPrinterLine() | |
116 | { | |
117 | return true; | |
118 | } | |
119 | ||
120 | wxString wxGnomePrintFactory::CreatePrinterLine() | |
121 | { | |
122 | // We should query "gnome_config_default" here | |
123 | return _("GNOME print"); | |
124 | } | |
125 | ||
126 | bool wxGnomePrintFactory::HasStatusLine() | |
127 | { | |
128 | return true; | |
129 | } | |
130 | ||
131 | wxString wxGnomePrintFactory::CreateStatusLine() | |
132 | { | |
133 | // We should query "gnome_config_default" here | |
134 | return _("Ready"); | |
135 | } | |
136 | ||
137 | wxPrintNativeDataBase *wxGnomePrintFactory::CreatePrintNativeData() | |
138 | { | |
139 | return new wxGnomePrintNativeData; | |
140 | } | |
141 | ||
142 | //---------------------------------------------------------------------------- | |
143 | // wxGnomePrintSetupDialog | |
144 | //---------------------------------------------------------------------------- | |
145 | ||
146 | IMPLEMENT_CLASS(wxGnomePrintSetupDialog, wxDialog) | |
147 | ||
148 | wxGnomePrintSetupDialog::wxGnomePrintSetupDialog( wxWindow *parent, wxPrintData *data ) | |
149 | { | |
150 | wxGnomePrintNativeData *native = | |
151 | (wxGnomePrintNativeData*) data->GetNativeData(); | |
152 | ||
153 | m_widget = gnome_print_dialog_new (native->GetPrintJob(), (guchar*)"Print setup", 0); | |
154 | } | |
155 | ||
156 | wxGnomePrintSetupDialog::~wxGnomePrintSetupDialog() | |
157 | { | |
158 | m_widget = NULL; | |
159 | } | |
160 | ||
161 | int wxGnomePrintSetupDialog::ShowModal() | |
162 | { | |
163 | int response = gtk_dialog_run (GTK_DIALOG (m_widget)); | |
164 | gtk_widget_destroy(m_widget); | |
165 | m_widget = NULL; | |
166 | ||
167 | if (response == GNOME_PRINT_DIALOG_RESPONSE_CANCEL) | |
168 | return wxID_CANCEL; | |
169 | ||
170 | return wxID_OK; | |
171 | } | |
172 | ||
173 | bool wxGnomePrintSetupDialog::Validate() | |
174 | { | |
175 | return true; | |
176 | } | |
177 | ||
178 | bool wxGnomePrintSetupDialog::TransferDataToWindow() | |
179 | { | |
180 | return true; | |
181 | } | |
182 | ||
183 | bool wxGnomePrintSetupDialog::TransferDataFromWindow() | |
184 | { | |
185 | return true; | |
186 | } | |
187 | ||
188 | ||
189 | //---------------------------------------------------------------------------- | |
190 | // wxGnomePrinter | |
191 | //---------------------------------------------------------------------------- | |
192 | ||
193 | IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase) | |
194 | ||
195 | wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) : | |
196 | wxPrinterBase( data ) | |
197 | { | |
198 | m_gpc = NULL; | |
199 | } | |
200 | ||
201 | wxGnomePrinter::~wxGnomePrinter() | |
202 | { | |
203 | } | |
204 | ||
205 | bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) | |
206 | { | |
207 | if (!printout) | |
208 | { | |
209 | sm_lastError = wxPRINTER_ERROR; | |
210 | return false; | |
211 | } | |
212 | ||
213 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); | |
214 | wxGnomePrintNativeData *data = | |
215 | (wxGnomePrintNativeData*) printdata.GetNativeData(); | |
216 | ||
981a6af1 RR |
217 | // The GnomePrintJob is temporarily stored in the |
218 | // native print data as the native print setup dialog | |
219 | // needs to access it. | |
ff910433 RR |
220 | GnomePrintJob *job = data->GetPrintJob(); |
221 | m_gpc = gnome_print_job_get_context (job); | |
981a6af1 RR |
222 | |
223 | printout->SetIsPreview(false); | |
224 | ||
225 | if (m_printDialogData.GetMinPage() < 1) | |
226 | m_printDialogData.SetMinPage(1); | |
227 | if (m_printDialogData.GetMaxPage() < 1) | |
228 | m_printDialogData.SetMaxPage(9999); | |
ff910433 RR |
229 | |
230 | wxDC *dc; | |
ff910433 RR |
231 | if (prompt) |
232 | dc = PrintDialog( parent ); | |
233 | else | |
234 | dc = new wxGnomePrintDC( this ); | |
235 | ||
236 | if (!dc) | |
237 | { | |
238 | gnome_print_job_close( job ); | |
981a6af1 | 239 | sm_lastError = wxPRINTER_ERROR; |
ff910433 RR |
240 | return false; |
241 | } | |
242 | ||
981a6af1 RR |
243 | wxSize ScreenPixels = wxGetDisplaySize(); |
244 | wxSize ScreenMM = wxGetDisplaySizeMM(); | |
245 | ||
246 | printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), | |
247 | (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); | |
248 | printout->SetPPIPrinter( wxPostScriptDC::GetResolution(), | |
249 | wxPostScriptDC::GetResolution() ); | |
250 | ||
ff910433 RR |
251 | printout->SetDC(dc); |
252 | ||
981a6af1 RR |
253 | int w, h; |
254 | dc->GetSize(&w, &h); | |
255 | printout->SetPageSizePixels((int)w, (int)h); | |
256 | dc->GetSizeMM(&w, &h); | |
257 | printout->SetPageSizeMM((int)w, (int)h); | |
258 | ||
ff910433 RR |
259 | printout->OnPreparePrinting(); |
260 | printout->OnBeginPrinting(); | |
261 | ||
262 | if (!printout->OnBeginDocument(0, 0)) | |
263 | { | |
264 | sm_lastError = wxPRINTER_ERROR; | |
265 | } | |
266 | else | |
267 | { | |
268 | int pn; | |
269 | for (pn = 1; pn <= 2; pn++) | |
270 | { | |
271 | dc->StartPage(); | |
272 | printout->OnPrintPage(pn); | |
273 | dc->EndPage(); | |
274 | } | |
275 | ||
276 | printout->OnEndDocument(); | |
277 | printout->OnEndPrinting(); | |
278 | } | |
279 | ||
280 | gnome_print_job_close( job ); | |
281 | gnome_print_job_print( job ); | |
282 | ||
283 | delete dc; | |
284 | ||
285 | return (sm_lastError == wxPRINTER_NO_ERROR); | |
286 | } | |
287 | ||
288 | wxDC* wxGnomePrinter::PrintDialog( wxWindow *parent ) | |
289 | { | |
290 | wxPrintDialog dialog( parent, &m_printDialogData ); | |
291 | if (dialog.ShowModal() == wxID_CANCEL) | |
292 | { | |
293 | sm_lastError = wxPRINTER_ERROR; | |
294 | return NULL; | |
295 | } | |
296 | ||
297 | return new wxGnomePrintDC( this ); | |
298 | } | |
299 | ||
300 | bool wxGnomePrinter::Setup( wxWindow *parent ) | |
301 | { | |
58c30cd8 | 302 | return false; |
ff910433 RR |
303 | } |
304 | ||
305 | //----------------------------------------------------------------------------- | |
306 | // wxGnomePrintDC | |
307 | //----------------------------------------------------------------------------- | |
308 | ||
309 | IMPLEMENT_CLASS(wxGnomePrintDC, wxDCBase) | |
310 | ||
311 | wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter *printer ) | |
312 | { | |
313 | m_printer = printer; | |
314 | ||
315 | m_gpc = printer->GetPrintContext(); | |
316 | ||
317 | m_layout = gnome_print_pango_create_layout( m_gpc ); | |
318 | m_fontdesc = pango_font_description_from_string( "Sans 12" ); | |
319 | ||
320 | m_currentRed = 0; | |
321 | m_currentBlue = 0; | |
322 | m_currentGreen = 0; | |
323 | ||
324 | m_signX = 1; // default x-axis left to right | |
325 | m_signY = -1; // default y-axis bottom up -> top down | |
326 | } | |
327 | ||
328 | wxGnomePrintDC::~wxGnomePrintDC() | |
329 | { | |
330 | } | |
331 | ||
332 | bool wxGnomePrintDC::Ok() const | |
333 | { | |
334 | return true; | |
335 | } | |
336 | ||
337 | bool wxGnomePrintDC::DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style ) | |
338 | { | |
339 | return false; | |
340 | } | |
341 | ||
342 | bool wxGnomePrintDC::DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const | |
343 | { | |
344 | return false; | |
345 | } | |
346 | ||
347 | void wxGnomePrintDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
348 | { | |
349 | if (m_pen.GetStyle() == wxTRANSPARENT) return; | |
350 | ||
351 | SetPen( m_pen ); | |
352 | ||
fa499247 RR |
353 | gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) ); |
354 | gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) ); | |
ff910433 RR |
355 | gnome_print_stroke ( m_gpc); |
356 | ||
357 | CalcBoundingBox( x1, y1 ); | |
358 | CalcBoundingBox( x2, y2 ); | |
359 | } | |
360 | ||
361 | void wxGnomePrintDC::DoCrossHair(wxCoord x, wxCoord y) | |
362 | { | |
363 | } | |
364 | ||
365 | void wxGnomePrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) | |
366 | { | |
367 | } | |
368 | ||
369 | void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) | |
370 | { | |
371 | } | |
372 | ||
373 | void wxGnomePrintDC::DoDrawPoint(wxCoord x, wxCoord y) | |
374 | { | |
375 | } | |
376 | ||
377 | void wxGnomePrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) | |
378 | { | |
379 | } | |
380 | ||
381 | void wxGnomePrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
382 | { | |
383 | } | |
384 | ||
385 | void wxGnomePrintDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
386 | { | |
387 | } | |
388 | ||
389 | void wxGnomePrintDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
390 | { | |
391 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
392 | { | |
393 | SetBrush( m_brush ); | |
394 | ||
395 | gnome_print_newpath( m_gpc ); | |
396 | gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
397 | gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
398 | gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
399 | gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
400 | gnome_print_closepath( m_gpc ); | |
401 | gnome_print_fill( m_gpc ); | |
402 | ||
403 | CalcBoundingBox( x, y ); | |
404 | CalcBoundingBox( x + width, y + height ); | |
405 | } | |
406 | ||
407 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
408 | { | |
409 | SetPen (m_pen); | |
410 | ||
411 | gnome_print_newpath( m_gpc ); | |
412 | gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
413 | gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
414 | gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
415 | gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
416 | gnome_print_closepath( m_gpc ); | |
417 | gnome_print_stroke( m_gpc ); | |
418 | ||
419 | CalcBoundingBox( x, y ); | |
420 | CalcBoundingBox( x + width, y + height ); | |
421 | } | |
422 | } | |
423 | ||
424 | void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) | |
425 | { | |
426 | } | |
427 | ||
428 | void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
429 | { | |
430 | } | |
431 | ||
432 | void wxGnomePrintDC::DoDrawSpline(wxList *points) | |
433 | { | |
434 | } | |
435 | ||
436 | bool wxGnomePrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
437 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask, | |
438 | wxCoord xsrcMask, wxCoord ysrcMask) | |
439 | { | |
440 | return false; | |
441 | } | |
442 | ||
443 | void wxGnomePrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) | |
444 | { | |
e1bf3ad3 | 445 | DoDrawBitmap( icon, x, y, true ); |
ff910433 RR |
446 | } |
447 | ||
448 | void wxGnomePrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask ) | |
449 | { | |
e1bf3ad3 RR |
450 | if (!bitmap.Ok()) return; |
451 | ||
452 | #if 0 | |
453 | // TODO do something clever here | |
454 | if (bitmap.HasPixbuf()) | |
455 | { | |
456 | } | |
457 | else | |
458 | #endif | |
459 | { | |
460 | wxImage image = bitmap.ConvertToImage(); | |
461 | ||
462 | if (!image.Ok()) return; | |
b4382784 RR |
463 | |
464 | double matrix[6]; | |
465 | matrix[0] = XLOG2DEVREL(image.GetWidth()); | |
466 | matrix[1] = 0; | |
467 | matrix[2] = 0; | |
468 | matrix[3] = YLOG2DEVREL(image.GetHeight()); | |
469 | matrix[4] = XLOG2DEV(x); | |
470 | matrix[5] = YLOG2DEV(y+image.GetHeight()); | |
471 | gnome_print_concat( m_gpc, matrix ); | |
472 | gnome_print_moveto( m_gpc, 0, 0 ); | |
e1bf3ad3 RR |
473 | gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 ); |
474 | } | |
ff910433 RR |
475 | } |
476 | ||
477 | void wxGnomePrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y ) | |
478 | { | |
479 | if (m_textForegroundColour.Ok()) | |
480 | { | |
481 | unsigned char red = m_textForegroundColour.Red(); | |
482 | unsigned char blue = m_textForegroundColour.Blue(); | |
483 | unsigned char green = m_textForegroundColour.Green(); | |
484 | ||
485 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
486 | { | |
487 | double redPS = (double)(red) / 255.0; | |
488 | double bluePS = (double)(blue) / 255.0; | |
489 | double greenPS = (double)(green) / 255.0; | |
490 | ||
491 | gnome_print_setrgbcolor( m_gpc, redPS, bluePS, greenPS ); | |
492 | ||
493 | m_currentRed = red; | |
494 | m_currentBlue = blue; | |
495 | m_currentGreen = green; | |
496 | } | |
497 | } | |
498 | ||
499 | x = XLOG2DEV(x); | |
500 | y = YLOG2DEV(y); | |
501 | ||
ff910433 RR |
502 | bool underlined = m_font.Ok() && m_font.GetUnderlined(); |
503 | ||
504 | #if wxUSE_UNICODE | |
505 | const wxCharBuffer data = wxConvUTF8.cWC2MB( text ); | |
506 | #else | |
507 | const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text ); | |
508 | if ( !wdata ) | |
509 | return; | |
510 | const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); | |
511 | #endif | |
512 | ||
513 | size_t datalen = strlen((const char*)data); | |
514 | pango_layout_set_text( m_layout, (const char*) data, datalen); | |
515 | ||
516 | if (underlined) | |
517 | { | |
518 | PangoAttrList *attrs = pango_attr_list_new(); | |
519 | PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); | |
520 | a->start_index = 0; | |
521 | a->end_index = datalen; | |
522 | pango_attr_list_insert(attrs, a); | |
523 | pango_layout_set_attributes(m_layout, attrs); | |
524 | pango_attr_list_unref(attrs); | |
525 | } | |
526 | ||
fa499247 RR |
527 | int w,h; |
528 | ||
529 | if (fabs(m_scaleY - 1.0) > 0.00001) | |
530 | { | |
531 | // If there is a user or actually any scale applied to | |
532 | // the device context, scale the font. | |
533 | ||
534 | // scale font description | |
535 | gint oldSize = pango_font_description_get_size( m_fontdesc ); | |
536 | double size = oldSize; | |
537 | size = size * m_scaleY; | |
538 | pango_font_description_set_size( m_fontdesc, (gint)size ); | |
539 | ||
540 | // actually apply scaled font | |
541 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
542 | ||
543 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
544 | #if 0 | |
545 | if ( m_backgroundMode == wxSOLID ) | |
546 | { | |
547 | gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); | |
548 | gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h); | |
549 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); | |
550 | } | |
551 | #endif | |
552 | // Draw layout. | |
553 | gnome_print_moveto (m_gpc, x, y); | |
554 | gnome_print_pango_layout( m_gpc, m_layout ); | |
555 | ||
556 | // reset unscaled size | |
557 | pango_font_description_set_size( m_fontdesc, oldSize ); | |
558 | ||
559 | // actually apply unscaled font | |
560 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
561 | } | |
562 | else | |
563 | { | |
564 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
565 | #if 0 | |
566 | if ( m_backgroundMode == wxSOLID ) | |
567 | { | |
568 | gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); | |
569 | gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h); | |
570 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); | |
571 | } | |
572 | #endif | |
573 | // Draw layout. | |
574 | gnome_print_moveto (m_gpc, x, y); | |
575 | gnome_print_pango_layout( m_gpc, m_layout ); | |
576 | } | |
577 | ||
578 | ||
ff910433 RR |
579 | |
580 | if (underlined) | |
581 | { | |
582 | // undo underline attributes setting: | |
583 | pango_layout_set_attributes(m_layout, NULL); | |
584 | } | |
585 | ||
586 | // CalcBoundingBox (x + width, y + height); | |
587 | CalcBoundingBox (x, y); | |
588 | } | |
589 | ||
590 | void wxGnomePrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) | |
591 | { | |
592 | } | |
593 | ||
594 | void wxGnomePrintDC::Clear() | |
595 | { | |
596 | } | |
597 | ||
598 | void wxGnomePrintDC::SetFont( const wxFont& font ) | |
599 | { | |
600 | m_font = font; | |
601 | ||
602 | if (m_font.Ok()) | |
603 | { | |
604 | if (m_fontdesc) | |
605 | pango_font_description_free( m_fontdesc ); | |
606 | ||
607 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); | |
608 | ||
609 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
610 | } | |
611 | } | |
612 | ||
613 | void wxGnomePrintDC::SetPen( const wxPen& pen ) | |
614 | { | |
615 | if (!pen.Ok()) return; | |
616 | ||
617 | int oldStyle = m_pen.GetStyle(); | |
618 | ||
619 | m_pen = pen; | |
620 | ||
621 | gnome_print_setlinewidth( m_gpc, XLOG2DEVREL( 1000 * m_pen.GetWidth() ) / 1000.0f ); | |
622 | ||
623 | unsigned char red = m_pen.GetColour().Red(); | |
624 | unsigned char blue = m_pen.GetColour().Blue(); | |
625 | unsigned char green = m_pen.GetColour().Green(); | |
626 | ||
627 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
628 | { | |
629 | double redPS = (double)(red) / 255.0; | |
630 | double bluePS = (double)(blue) / 255.0; | |
631 | double greenPS = (double)(green) / 255.0; | |
632 | ||
633 | gnome_print_setrgbcolor( m_gpc, redPS, bluePS, greenPS ); | |
634 | ||
635 | m_currentRed = red; | |
636 | m_currentBlue = blue; | |
637 | m_currentGreen = green; | |
638 | } | |
639 | } | |
640 | ||
641 | void wxGnomePrintDC::SetBrush( const wxBrush& brush ) | |
642 | { | |
fa499247 RR |
643 | if (!brush.Ok()) return; |
644 | ||
645 | m_brush = brush; | |
646 | ||
647 | // Brush colour | |
648 | unsigned char red = m_brush.GetColour().Red(); | |
649 | unsigned char blue = m_brush.GetColour().Blue(); | |
650 | unsigned char green = m_brush.GetColour().Green(); | |
651 | ||
652 | if (!m_colour) | |
653 | { | |
654 | // Anything not white is black | |
655 | if (! (red == (unsigned char) 255 && | |
656 | blue == (unsigned char) 255 && | |
657 | green == (unsigned char) 255) ) | |
658 | { | |
659 | red = (unsigned char) 0; | |
660 | green = (unsigned char) 0; | |
661 | blue = (unsigned char) 0; | |
662 | } | |
663 | // setgray here ? | |
664 | } | |
665 | ||
666 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
667 | { | |
668 | double redPS = (double)(red) / 255.0; | |
669 | double bluePS = (double)(blue) / 255.0; | |
670 | double greenPS = (double)(green) / 255.0; | |
671 | ||
672 | gnome_print_setrgbcolor( m_gpc, redPS, bluePS, greenPS ); | |
673 | ||
674 | m_currentRed = red; | |
675 | m_currentBlue = blue; | |
676 | m_currentGreen = green; | |
677 | } | |
ff910433 RR |
678 | } |
679 | ||
680 | void wxGnomePrintDC::SetLogicalFunction( int function ) | |
681 | { | |
682 | } | |
683 | ||
684 | void wxGnomePrintDC::SetBackground( const wxBrush& brush ) | |
685 | { | |
686 | } | |
687 | ||
688 | void wxGnomePrintDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
689 | { | |
690 | } | |
691 | ||
692 | void wxGnomePrintDC::DestroyClippingRegion() | |
693 | { | |
694 | } | |
695 | ||
696 | bool wxGnomePrintDC::StartDoc(const wxString& message) | |
697 | { | |
698 | SetDeviceOrigin( 0,0 ); | |
699 | ||
700 | return true; | |
701 | } | |
702 | ||
703 | void wxGnomePrintDC::EndDoc() | |
704 | { | |
705 | } | |
706 | ||
707 | void wxGnomePrintDC::StartPage() | |
708 | { | |
709 | gnome_print_beginpage( m_gpc, (const guchar*) "1" ); | |
710 | } | |
711 | ||
712 | void wxGnomePrintDC::EndPage() | |
713 | { | |
714 | gnome_print_showpage( m_gpc ); | |
715 | } | |
716 | ||
717 | wxCoord wxGnomePrintDC::GetCharHeight() const | |
718 | { | |
719 | return 0; | |
720 | } | |
721 | ||
722 | wxCoord wxGnomePrintDC::GetCharWidth() const | |
723 | { | |
724 | return 0; | |
725 | } | |
726 | ||
981a6af1 | 727 | void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, |
ff910433 RR |
728 | wxCoord *descent, |
729 | wxCoord *externalLeading, | |
730 | wxFont *theFont ) const | |
731 | { | |
981a6af1 RR |
732 | if ( width ) |
733 | *width = 0; | |
734 | if ( height ) | |
735 | *height = 0; | |
736 | if ( descent ) | |
737 | *descent = 0; | |
738 | if ( externalLeading ) | |
739 | *externalLeading = 0; | |
740 | ||
741 | if (string.IsEmpty()) | |
742 | { | |
743 | return; | |
744 | } | |
745 | ||
746 | // Set new font description | |
747 | if (theFont) | |
748 | pango_layout_set_font_description( m_layout, theFont->GetNativeFontInfo()->description ); | |
749 | ||
750 | // Set layout's text | |
751 | #if wxUSE_UNICODE | |
752 | const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); | |
753 | const char *dataUTF8 = (const char *)data; | |
754 | #else | |
755 | const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string ); | |
756 | if ( !wdata ) | |
757 | { | |
758 | if (width) (*width) = 0; | |
759 | if (height) (*height) = 0; | |
760 | return; | |
761 | } | |
762 | const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); | |
763 | const char *dataUTF8 = (const char *)data; | |
764 | #endif | |
765 | ||
766 | if ( !dataUTF8 ) | |
767 | { | |
768 | // hardly ideal, but what else can we do if conversion failed? | |
769 | return; | |
770 | } | |
771 | ||
772 | pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); | |
773 | ||
774 | int w,h; | |
775 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
776 | ||
777 | if (width) | |
778 | *width = (wxCoord) w; | |
779 | if (height) | |
780 | *height = (wxCoord) h; | |
781 | if (descent) | |
782 | { | |
783 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); | |
784 | int baseline = pango_layout_iter_get_baseline(iter); | |
785 | pango_layout_iter_free(iter); | |
786 | *descent = h - PANGO_PIXELS(baseline); | |
787 | } | |
788 | ||
789 | // Reset old font description | |
790 | if (theFont) | |
791 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
ff910433 RR |
792 | } |
793 | ||
794 | void wxGnomePrintDC::DoGetSize(int* width, int* height) const | |
795 | { | |
796 | // No idea if that is efficient | |
797 | GnomePrintConfig *config = gnome_print_config_default(); | |
798 | ||
799 | double w,h; | |
800 | bool result = gnome_print_config_get_page_size( config, &w, &h ); | |
801 | ||
802 | if (!result) | |
803 | { | |
804 | // Standard PS resolution DIN A4 size. | |
805 | w = 595.0; | |
806 | h = 842.0; | |
807 | } | |
808 | ||
809 | if (width) | |
810 | *width = (int) w; | |
811 | if (height) | |
812 | *height = (int) h; | |
ff910433 RR |
813 | } |
814 | ||
815 | void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const | |
816 | { | |
817 | double w,h; | |
818 | ||
819 | /// Later, for now DIN A4 | |
820 | w = 210.0; | |
821 | h = 297.0; | |
822 | ||
823 | if (width) | |
824 | *width = (int) w; | |
825 | if (height) | |
826 | *height = (int) h; | |
827 | } | |
828 | ||
829 | wxSize wxGnomePrintDC::GetPPI() const | |
830 | { | |
831 | return wxSize(72,72); | |
832 | } | |
833 | ||
834 | void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
835 | { | |
836 | m_signX = (xLeftRight ? 1 : -1); | |
837 | m_signY = (yBottomUp ? 1 : -1); | |
838 | ||
839 | ComputeScaleAndOrigin(); | |
840 | } | |
841 | ||
842 | void wxGnomePrintDC::SetDeviceOrigin( wxCoord x, wxCoord y ) | |
843 | { | |
844 | int h = 0; | |
845 | int w = 0; | |
846 | GetSize( &w, &h ); | |
847 | ||
848 | wxDC::SetDeviceOrigin( x, h-y ); | |
849 | } | |
850 | ||
851 | void wxGnomePrintDC::SetResolution(int ppi) | |
852 | { | |
853 | } | |
854 | ||
855 | int wxGnomePrintDC::GetResolution() | |
856 | { | |
857 | return 72; | |
858 | } | |
7c72311f | 859 | |
58c30cd8 RR |
860 | |
861 | class wxGnomePrintModule: public wxModule | |
862 | { | |
863 | public: | |
864 | wxGnomePrintModule() {} | |
865 | bool OnInit() { wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory ); return true; } | |
866 | void OnExit() { } | |
867 | ||
868 | private: | |
869 | DECLARE_DYNAMIC_CLASS(wxGnomePrintModule) | |
870 | }; | |
871 | ||
872 | IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule) | |
873 | ||
7c72311f RR |
874 | #endif |
875 | // wxUSE_LIBGNOMEPRINT |