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