#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/dcmemory.h"
+#include "wx/dcprint.h"
#include "wx/icon.h"
#include "wx/math.h"
#include "wx/image.h"
#include <gtk/gtk.h>
#include <gtk/gtkpagesetupunixdialog.h>
+#if wxUSE_GRAPHICS_CONTEXT
+#include "wx/graphics.h"
+#endif
+
#include "wx/link.h"
wxFORCE_LINK_THIS_MODULE(gtk_print)
return NULL;
}
-wxDC* wxGtkPrintFactory::CreatePrinterDC( const wxPrintData& data )
+wxDCImpl* wxGtkPrintFactory::CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data )
{
- return new wxGtkPrinterDC(data);
+ return new wxGtkPrinterDCImpl( owner, data );
}
bool wxGtkPrintFactory::HasOwnPrintToFile()
if(!m_config)
return false;
- GtkPrintQuality quality = gtk_print_settings_get_quality(m_config);
- if (quality == GTK_PRINT_QUALITY_HIGH)
- data.SetQuality(wxPRINT_QUALITY_HIGH);
- else if (quality == GTK_PRINT_QUALITY_LOW)
- data.SetQuality(wxPRINT_QUALITY_LOW);
- else if (quality == GTK_PRINT_QUALITY_DRAFT)
- data.SetQuality(wxPRINT_QUALITY_DRAFT);
- else
- data.SetQuality(wxPRINT_QUALITY_MEDIUM);
+ int resolution = gtk_print_settings_get_resolution(m_config);
+ if ( resolution > 0 )
+ {
+ // if resolution is explicitly set, use it
+ data.SetQuality(resolution);
+ }
+ else // use more vague "quality"
+ {
+ GtkPrintQuality quality = gtk_print_settings_get_quality(m_config);
+ if (quality == GTK_PRINT_QUALITY_HIGH)
+ data.SetQuality(wxPRINT_QUALITY_HIGH);
+ else if (quality == GTK_PRINT_QUALITY_LOW)
+ data.SetQuality(wxPRINT_QUALITY_LOW);
+ else if (quality == GTK_PRINT_QUALITY_DRAFT)
+ data.SetQuality(wxPRINT_QUALITY_DRAFT);
+ else
+ data.SetQuality(wxPRINT_QUALITY_MEDIUM);
+ }
data.SetNoCopies(gtk_print_settings_get_n_copies(m_config));
wxPrintData printdata = GetPrintDialogData().GetPrintData();
wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData();
+ // We need to update printdata with the new data from the dialog and we
+ // have to do this here because this method needs this new data and we
+ // cannot update it earlier
+ native->SetPrintConfig(gtk_print_operation_get_print_settings(operation));
+ printdata.ConvertFromNative();
+
SetPrintContext(context);
native->SetPrintContext( context );
- wxGtkPrinterDC *printDC = new wxGtkPrinterDC( printdata );
+ wxPrinterDC *printDC = new wxPrinterDC( printdata );
m_dc = printDC;
if (!m_dc->IsOk())
}
m_printDialogData = dialog.GetPrintDialogData();
- return new wxGtkPrinterDC( m_printDialogData.GetPrintData() );
+
+ return new wxPrinterDC( m_printDialogData.GetPrintData() );
}
bool wxGtkPrinter::Setup( wxWindow * WXUNUSED(parent) )
// wxGtkPrinterDC
//-----------------------------------------------------------------------------
+#define wxCAIRO_SCALE 1
+
+#if wxCAIRO_SCALE
+
+#define XLOG2DEV(x) LogicalToDeviceX(x)
+#define XLOG2DEVREL(x) LogicalToDeviceXRel(x)
+#define YLOG2DEV(x) LogicalToDeviceY(x)
+#define YLOG2DEVREL(x) LogicalToDeviceYRel(x)
+
+#else
+
#define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
#define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
#define YLOG2DEV(x) ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
#define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
-IMPLEMENT_CLASS(wxGtkPrinterDC, wxDC)
+#endif
+
+IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl, wxDCImpl)
-wxGtkPrinterDC::wxGtkPrinterDC( const wxPrintData& data )
+wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC *owner, const wxPrintData& data)
+ : wxDCImpl( owner )
{
m_printData = data;
if (m_resolution < 0)
m_resolution = (1 << (m_resolution+4)) *150;
- m_PS2DEV = (double)m_resolution / 72.0;
- m_DEV2PS = 72.0 / (double)m_resolution;
-
m_context = gtk_print_context_create_pango_context( m_gpc );
m_layout = gtk_print_context_create_pango_layout ( m_gpc );
m_fontdesc = pango_font_description_from_string( "Sans 12" );
m_cairo = gtk_print_context_get_cairo_context ( m_gpc );
+#if wxCAIRO_SCALE
+ m_PS2DEV = 1.0;
+ m_DEV2PS = 1.0;
+
+ gs_cairo->cairo_scale( m_cairo, 72.0 / (double)m_resolution, 72.0 / (double)m_resolution );
+#else
+ m_PS2DEV = (double)m_resolution / 72.0;
+ m_DEV2PS = 72.0 / (double)m_resolution;
+#endif
+
m_currentRed = 0;
m_currentBlue = 0;
m_currentGreen = 0;
gs_cairo->cairo_translate(m_cairo, -ml, -mt);
}
-wxGtkPrinterDC::~wxGtkPrinterDC()
+wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
{
g_object_unref(m_context);
g_object_unref(m_layout);
}
-bool wxGtkPrinterDC::IsOk() const
+bool wxGtkPrinterDCImpl::IsOk() const
{
return m_gpc != NULL;
}
-bool wxGtkPrinterDC::DoFloodFill(wxCoord WXUNUSED(x1),
+void* wxGtkPrinterDCImpl::GetCairoContext() const
+{
+ return (void*) cairo_reference( m_cairo );
+}
+
+bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1),
wxCoord WXUNUSED(y1),
const wxColour& WXUNUSED(col),
int WXUNUSED(style))
return false;
}
-void wxGtkPrinterDC::DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter)
+void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter)
{
wxCoord xC = circleCenter.x;
wxCoord yC = circleCenter.y;
CalcBoundingBox(xR+w, yR+h);
}
-void wxGtkPrinterDC::DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, wxDirection nDirection)
+void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, wxDirection nDirection)
{
wxCoord x = rect.x;
wxCoord y = rect.y;
CalcBoundingBox(x+w, y+h);
}
-bool wxGtkPrinterDC::DoGetPixel(wxCoord WXUNUSED(x1),
+bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord WXUNUSED(x1),
wxCoord WXUNUSED(y1),
wxColour * WXUNUSED(col)) const
{
return false;
}
-void wxGtkPrinterDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
+void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
{
- if (m_pen.GetStyle() == wxTRANSPARENT) return;
+ if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
SetPen( m_pen );
gs_cairo->cairo_move_to ( m_cairo, XLOG2DEV(x1), YLOG2DEV(y1) );
CalcBoundingBox( x2, y2 );
}
-void wxGtkPrinterDC::DoCrossHair(wxCoord x, wxCoord y)
+void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x, wxCoord y)
{
int w, h;
DoGetSize(&w, &h);
CalcBoundingBox( w, h );
}
-void wxGtkPrinterDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc)
+void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc)
{
double dx = x1 - xc;
double dy = y1 - yc;
CalcBoundingBox (x2, y2);
}
-void wxGtkPrinterDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
+void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
{
gs_cairo->cairo_save( m_cairo );
CalcBoundingBox( x+w, y+h );
}
-void wxGtkPrinterDC::DoDrawPoint(wxCoord x, wxCoord y)
+void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x, wxCoord y)
{
- if (m_pen.GetStyle() == wxTRANSPARENT) return;
+ if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
SetPen( m_pen );
CalcBoundingBox( x, y );
}
-void wxGtkPrinterDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
+void wxGtkPrinterDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
{
- if (m_pen.GetStyle() == wxTRANSPARENT) return;
+ if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
if (n <= 0) return;
gs_cairo->cairo_stroke ( m_cairo);
}
-void wxGtkPrinterDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
+void wxGtkPrinterDCImpl::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
{
if (n==0) return;
gs_cairo->cairo_restore(m_cairo);
}
-void wxGtkPrinterDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
+void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
{
- wxDC::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle );
+ wxDCImpl::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle );
}
-void wxGtkPrinterDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
width--;
height--;
CalcBoundingBox( x + width, y + height );
}
-void wxGtkPrinterDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
+void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
{
width--;
height--;
CalcBoundingBox(x+width,y+height);
}
-void wxGtkPrinterDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
width--;
height--;
}
#if wxUSE_SPLINES
-void wxGtkPrinterDC::DoDrawSpline(const wxPointList *points)
+void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList *points)
{
SetPen (m_pen);
}
#endif // wxUSE_SPLINES
-bool wxGtkPrinterDC::DoBlit(wxCoord xdest, wxCoord ydest,
+bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest, wxCoord ydest,
wxCoord width, wxCoord height,
wxDC *source, wxCoord xsrc, wxCoord ysrc,
int rop, bool useMask,
memDC.SelectObject(wxNullBitmap);
// Draw bitmap. scaling and positioning is done there.
- DrawBitmap( bitmap, xdest, ydest, useMask );
+ GetOwner()->DrawBitmap( bitmap, xdest, ydest, useMask );
return true;
}
-void wxGtkPrinterDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y )
+void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y )
{
DoDrawBitmap( icon, x, y, true );
}
-void wxGtkPrinterDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask )
+void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask )
{
- wxCHECK_RET( bitmap.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDC::DoDrawBitmap"));
+ wxCHECK_RET( bitmap.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
cairo_surface_t* surface;
x = wxCoord(XLOG2DEV(x));
gs_cairo->cairo_restore(m_cairo);
}
-void wxGtkPrinterDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y )
+void wxGtkPrinterDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y )
{
DoDrawRotatedText( text, x, y, 0.0 );
}
-void wxGtkPrinterDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
+void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
{
double xx = XLOG2DEV(x);
double yy = YLOG2DEV(y);
pango_layout_get_pixel_size( m_layout, &w, &h );
- if ( m_backgroundMode == wxSOLID )
+ if ( m_backgroundMode == wxBRUSHSTYLE_SOLID )
{
unsigned char red = m_textBackgroundColour.Red();
unsigned char blue = m_textBackgroundColour.Blue();
CalcBoundingBox (x + w, y + h);
}
-void wxGtkPrinterDC::Clear()
+void wxGtkPrinterDCImpl::Clear()
{
// Clear does nothing for printing, but keep the code
// for later reuse
*/
}
-void wxGtkPrinterDC::SetFont( const wxFont& font )
+void wxGtkPrinterDCImpl::SetFont( const wxFont& font )
{
m_font = font;
}
}
-void wxGtkPrinterDC::SetPen( const wxPen& pen )
+void wxGtkPrinterDCImpl::SetPen( const wxPen& pen )
{
if (!pen.Ok()) return;
switch (m_pen.GetStyle())
{
- case wxDOT: gs_cairo->cairo_set_dash( m_cairo, dotted, 2, 0 ); break;
- case wxSHORT_DASH: gs_cairo->cairo_set_dash( m_cairo, short_dashed, 2, 0 ); break;
- case wxLONG_DASH: gs_cairo->cairo_set_dash( m_cairo, long_dashed, 2, 0 ); break;
- case wxDOT_DASH: gs_cairo->cairo_set_dash( m_cairo, dotted_dashed, 4, 0 ); break;
- case wxUSER_DASH:
+ case wxPENSTYLE_DOT: gs_cairo->cairo_set_dash( m_cairo, dotted, 2, 0 ); break;
+ case wxPENSTYLE_SHORT_DASH: gs_cairo->cairo_set_dash( m_cairo, short_dashed, 2, 0 ); break;
+ case wxPENSTYLE_LONG_DASH: gs_cairo->cairo_set_dash( m_cairo, long_dashed, 2, 0 ); break;
+ case wxPENSTYLE_DOT_DASH: gs_cairo->cairo_set_dash( m_cairo, dotted_dashed, 4, 0 ); break;
+ case wxPENSTYLE_USER_DASH:
{
wxDash *wx_dashes;
int num = m_pen.GetDashes (&wx_dashes);
g_free( g_dashes );
}
break;
- case wxSOLID:
- case wxTRANSPARENT:
+ case wxPENSTYLE_SOLID:
+ case wxPENSTYLE_TRANSPARENT:
default: gs_cairo->cairo_set_dash( m_cairo, NULL, 0, 0 ); break;
}
}
}
-void wxGtkPrinterDC::SetBrush( const wxBrush& brush )
+void wxGtkPrinterDCImpl::SetBrush( const wxBrush& brush )
{
if (!brush.Ok()) return;
m_brush = brush;
- if (m_brush.GetStyle() == wxTRANSPARENT)
+ if (m_brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT)
{
gs_cairo->cairo_set_source_rgba( m_cairo, 0, 0, 0, 0 );
m_currentRed = 0;
switch (m_brush.GetStyle())
{
- case wxCROSS_HATCH:
+ case wxBRUSHSTYLE_CROSS_HATCH:
gs_cairo->cairo_move_to(cr, 5, 0);
gs_cairo->cairo_line_to(cr, 5, 10);
gs_cairo->cairo_move_to(cr, 0, 5);
gs_cairo->cairo_line_to(cr, 10, 5);
break;
- case wxBDIAGONAL_HATCH:
+ case wxBRUSHSTYLE_BDIAGONAL_HATCH:
gs_cairo->cairo_move_to(cr, 0, 10);
gs_cairo->cairo_line_to(cr, 10, 0);
break;
- case wxFDIAGONAL_HATCH:
+ case wxBRUSHSTYLE_FDIAGONAL_HATCH:
gs_cairo->cairo_move_to(cr, 0, 0);
gs_cairo->cairo_line_to(cr, 10, 10);
break;
- case wxCROSSDIAG_HATCH:
+ case wxBRUSHSTYLE_CROSSDIAG_HATCH:
gs_cairo->cairo_move_to(cr, 0, 0);
gs_cairo->cairo_line_to(cr, 10, 10);
gs_cairo->cairo_move_to(cr, 10, 0);
gs_cairo->cairo_line_to(cr, 0, 10);
break;
- case wxHORIZONTAL_HATCH:
+ case wxBRUSHSTYLE_HORIZONTAL_HATCH:
gs_cairo->cairo_move_to(cr, 0, 5);
gs_cairo->cairo_line_to(cr, 10, 5);
break;
- case wxVERTICAL_HATCH:
+ case wxBRUSHSTYLE_VERTICAL_HATCH:
gs_cairo->cairo_move_to(cr, 5, 0);
gs_cairo->cairo_line_to(cr, 5, 10);
break;
}
}
-void wxGtkPrinterDC::SetLogicalFunction( int function )
+void wxGtkPrinterDCImpl::SetLogicalFunction( int function )
{
if (function == wxCLEAR)
gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_CLEAR);
gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
}
-void wxGtkPrinterDC::SetBackground( const wxBrush& brush )
+void wxGtkPrinterDCImpl::SetBackground( const wxBrush& brush )
{
m_backgroundBrush = brush;
gs_cairo->cairo_save(m_cairo);
gs_cairo->cairo_restore(m_cairo);
}
-void wxGtkPrinterDC::SetBackgroundMode(int mode)
+void wxGtkPrinterDCImpl::SetBackgroundMode(int mode)
{
- if (mode == wxSOLID)
- m_backgroundMode = wxSOLID;
+ if (mode == wxBRUSHSTYLE_SOLID)
+ m_backgroundMode = wxBRUSHSTYLE_SOLID;
else
- m_backgroundMode = wxTRANSPARENT;
+ m_backgroundMode = wxBRUSHSTYLE_TRANSPARENT;
}
-void wxGtkPrinterDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
gs_cairo->cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height));
gs_cairo->cairo_clip(m_cairo);
}
-void wxGtkPrinterDC::DestroyClippingRegion()
+void wxGtkPrinterDCImpl::DestroyClippingRegion()
{
gs_cairo->cairo_reset_clip(m_cairo);
}
-bool wxGtkPrinterDC::StartDoc(const wxString& WXUNUSED(message))
+bool wxGtkPrinterDCImpl::StartDoc(const wxString& WXUNUSED(message))
{
return true;
}
-void wxGtkPrinterDC::EndDoc()
+void wxGtkPrinterDCImpl::EndDoc()
{
return;
}
-void wxGtkPrinterDC::StartPage()
+void wxGtkPrinterDCImpl::StartPage()
{
return;
}
-void wxGtkPrinterDC::EndPage()
+void wxGtkPrinterDCImpl::EndPage()
{
return;
}
-wxCoord wxGtkPrinterDC::GetCharHeight() const
+wxCoord wxGtkPrinterDCImpl::GetCharHeight() const
{
pango_layout_set_text( m_layout, "H", 1 );
return wxRound( h * m_PS2DEV );
}
-wxCoord wxGtkPrinterDC::GetCharWidth() const
+wxCoord wxGtkPrinterDCImpl::GetCharWidth() const
{
pango_layout_set_text( m_layout, "H", 1 );
return wxRound( w * m_PS2DEV );
}
-void wxGtkPrinterDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height,
+void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height,
wxCoord *descent,
wxCoord *externalLeading,
const wxFont *theFont ) const
pango_layout_set_font_description( m_layout, m_fontdesc );
}
-void wxGtkPrinterDC::DoGetSize(int* width, int* height) const
+void wxGtkPrinterDCImpl::DoGetSize(int* width, int* height) const
{
GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc );
if (width)
- *width = wxRound( gtk_page_setup_get_paper_width( setup, GTK_UNIT_POINTS ) * m_PS2DEV );
+ *width = wxRound( (double)gtk_page_setup_get_paper_width( setup, GTK_UNIT_POINTS ) * (double)m_resolution / 72.0 );
if (height)
- *height = wxRound( gtk_page_setup_get_paper_height( setup, GTK_UNIT_POINTS ) * m_PS2DEV );
+ *height = wxRound( (double)gtk_page_setup_get_paper_height( setup, GTK_UNIT_POINTS ) * (double)m_resolution / 72.0 );
}
-void wxGtkPrinterDC::DoGetSizeMM(int *width, int *height) const
+void wxGtkPrinterDCImpl::DoGetSizeMM(int *width, int *height) const
{
GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc );
*height = wxRound( gtk_page_setup_get_paper_height( setup, GTK_UNIT_MM ) );
}
-wxSize wxGtkPrinterDC::GetPPI() const
+wxSize wxGtkPrinterDCImpl::GetPPI() const
{
return wxSize( (int)m_resolution, (int)m_resolution );
}
-void wxGtkPrinterDC::SetPrintData(const wxPrintData& data)
+void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData& data)
{
m_printData = data;
}
-void wxGtkPrinterDC::SetResolution(int WXUNUSED(ppi))
+// overriden for wxPrinterDC Impl
+
+wxRect wxGtkPrinterDCImpl::GetPaperRect()
{
- // We can't change ppi of the GtkPrintContext.
- // TODO: should we really support this?
+ // Does GtkPrint support printer margins?
+ int w = 0;
+ int h = 0;
+ DoGetSize( &w, &h );
+ return wxRect( 0,0,w,h );
}
-int wxGtkPrinterDC::GetResolution()
+int wxGtkPrinterDCImpl::GetResolution()
{
return m_resolution;
}
IMPLEMENT_CLASS(wxGtkPrintPreview, wxPrintPreviewBase)
void wxGtkPrintPreview::Init(wxPrintout * WXUNUSED(printout),
- wxPrintout * WXUNUSED(printoutForPrinting))
+ wxPrintout * WXUNUSED(printoutForPrinting),
+ wxPrintData *data)
{
+ // convert wxPrintQuality to resolution (input pointer can be NULL)
+ wxPrintQuality quality = data ? data->GetQuality() : wxPRINT_QUALITY_MEDIUM;
+ switch ( quality )
+ {
+ case wxPRINT_QUALITY_HIGH:
+ m_resolution = 1200;
+ break;
+
+ case wxPRINT_QUALITY_LOW:
+ m_resolution = 300;
+ break;
+
+ case wxPRINT_QUALITY_DRAFT:
+ m_resolution = 150;
+ break;
+
+ default:
+ if ( quality > 0 )
+ {
+ // positive values directly indicate print resolution
+ m_resolution = quality;
+ break;
+ }
+
+ wxFAIL_MSG( "unknown print quality" );
+ // fall through
+
+ case wxPRINT_QUALITY_MEDIUM:
+ m_resolution = 600;
+ break;
+
+ }
+
DetermineScaling();
}
wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout *printout,
- wxPrintout *printoutForPrinting,
- wxPrintDialogData *data)
- : wxPrintPreviewBase(printout, printoutForPrinting, data)
+ wxPrintout *printoutForPrinting,
+ wxPrintDialogData *data)
+ : wxPrintPreviewBase(printout, printoutForPrinting, data)
{
- Init(printout, printoutForPrinting);
+ Init(printout, printoutForPrinting, data ? &data->GetPrintData() : NULL);
}
wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout *printout,
- wxPrintout *printoutForPrinting,
- wxPrintData *data)
- : wxPrintPreviewBase(printout, printoutForPrinting, data)
+ wxPrintout *printoutForPrinting,
+ wxPrintData *data)
+ : wxPrintPreviewBase(printout, printoutForPrinting, data)
{
- Init(printout, printoutForPrinting);
+ Init(printout, printoutForPrinting, data);
}
wxGtkPrintPreview::~wxGtkPrintPreview()
m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
(int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
- // TODO !!!!!!!!!!!!!!!
- int resolution = 600;
- m_previewPrintout->SetPPIPrinter( resolution, resolution );
+ m_previewPrintout->SetPPIPrinter( m_resolution, m_resolution );
// Get width and height in points (1/72th of an inch)
wxSize sizeDevUnits(paper->GetSizeDeviceUnits());
-
- sizeDevUnits.x = wxRound((double)sizeDevUnits.x * (double)resolution / 72.0);
- sizeDevUnits.y = wxRound((double)sizeDevUnits.y * (double)resolution / 72.0);
+ sizeDevUnits.x = wxRound((double)sizeDevUnits.x * (double)m_resolution / 72.0);
+ sizeDevUnits.y = wxRound((double)sizeDevUnits.y * (double)m_resolution / 72.0);
+
wxSize sizeTenthsMM(paper->GetSize());
wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10);
m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight));
// At 100%, the page should look about page-size on the screen.
- m_previewScaleX = 0.8 * 72.0 / (double)resolution;
+ m_previewScaleX = 0.8 * 72.0 / (double)m_resolution;
m_previewScaleY = m_previewScaleX;
}
}