/////////////////////////////////////////////////////////////////////////////
-// Name: wx/gtk/print.cpp
+// Name: src/gtk/print.cpp
// Author: Anthony Bretaudeau
// Purpose: GTK printing support
// Created: 2007-08-25
-// RCS-ID: $Id: print.cpp,v 1 2007-08-25 05:44:44 PC Exp $
+// RCS-ID: $Id$
// Copyright: (c) 2007 wxWidgets development team
// Licence: wxWindows Licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/gtk/private.h"
#include "wx/dynlib.h"
#include "wx/paper.h"
-#include "wx/rawbmp.h"
#include <gtk/gtk.h>
+
+#if GTK_CHECK_VERSION(2,14,0)
+#include <gtk/gtkunixprint.h>
+#else
#include <gtk/gtkpagesetupunixdialog.h>
+#endif
+
#if wxUSE_GRAPHICS_CONTEXT
#include "wx/graphics.h"
#include "wx/gtk/gnome/gprint.h"
#endif
-// Usefull to convert angles from/to Rad to/from Deg.
+#include "wx/gtk/private/object.h"
+
+// Useful to convert angles from/to Rad to/from Deg.
static const double RAD2DEG = 180.0 / M_PI;
static const double DEG2RAD = M_PI / 180.0;
printout->OnEndPrinting();
}
-
- static gboolean
- gtk_preview_print_callback(GtkPrintOperation * WXUNUSED(operation),
- GtkPrintOperationPreview * WXUNUSED(preview),
- GtkPrintContext *context,
- GtkWindow *parent,
- gpointer user_data)
- {
- wxPrintout *printout = (wxPrintout *) user_data;
-
- printout->SetIsPreview(true);
-
- /* We create a Cairo context with 72dpi resolution. This resolution is
- * only used for positioning. */
- cairo_t *cairo = gdk_cairo_create(GTK_WIDGET(parent)->window);
- gtk_print_context_set_cairo_context(context, cairo, 72, 72);
-
- return false;
- }
}
//----------------------------------------------------------------------------
wxGtkPrintNativeData::wxGtkPrintNativeData()
{
m_config = gtk_print_settings_new();
+ m_job = gtk_print_operation_new();
+ m_context = NULL;
}
wxGtkPrintNativeData::~wxGtkPrintNativeData()
{
- g_object_unref (m_config);
+ g_object_unref(m_job);
+ g_object_unref(m_config);
}
// Convert datas stored in m_config to a wxPrintData.
data.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN);
else
data.SetPaperId(wxPAPER_NONE);
+
+ data.SetPrinterName(gtk_print_settings_get_printer(m_config));
+
return true;
}
default: break;
}
+ gtk_print_settings_set_printer(m_config, data.GetPrinterName().utf8_str());
+
return true;
}
gtk_print_settings_set_page_ranges (settings, range, 1);
}
+ GtkPrintOperation * const printOp = native->GetPrintJob();
+
// If the settings are OK, we restore it.
if (settings != NULL)
- gtk_print_operation_set_print_settings (native->GetPrintJob(), settings);
- gtk_print_operation_set_default_page_setup (native->GetPrintJob(), native->GetPageSetupFromSettings(settings));
+ gtk_print_operation_set_print_settings (printOp, settings);
+ gtk_print_operation_set_default_page_setup (printOp, native->GetPageSetupFromSettings(settings));
// Show the dialog if needed.
GError* gError = NULL;
if (GetShowDialog())
- response = gtk_print_operation_run (native->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget) ), &gError);
+ response = gtk_print_operation_run (printOp, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget) ), &gError);
else
- response = gtk_print_operation_run (native->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget)), &gError);
+ response = gtk_print_operation_run (printOp, GTK_PRINT_OPERATION_ACTION_PRINT, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget)), &gError);
// Does everything went well?
if (response == GTK_PRINT_OPERATION_RESULT_CANCEL)
}
else if (response == GTK_PRINT_OPERATION_RESULT_ERROR)
{
+ wxLogError(_("Error while printing: ") + wxString(gError ? gError->message : "???"));
g_error_free (gError);
- wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError->message));
return wxID_NO; // We use wxID_NO because there is no wxID_ERROR available
}
// Now get the settings and save it.
- GtkPrintSettings* newSettings = gtk_print_operation_get_print_settings (native->GetPrintJob());
+ GtkPrintSettings* newSettings = gtk_print_operation_get_print_settings(printOp);
native->SetPrintConfig(newSettings);
data.ConvertFromNative();
+ // Set PrintDialogData variables
+ m_printDialogData.SetPrintData(data);
+ m_printDialogData.SetCollate(data.GetCollate());
+ m_printDialogData.SetNoCopies(data.GetNoCopies());
+ m_printDialogData.SetPrintToFile(data.GetPrinterName() == "Print to File");
+
// Same problem as a few lines before.
switch (gtk_print_settings_get_print_pages(newSettings))
{
}
}
- // Now show the dialog.
- GtkPageSetup* newPageSetup = gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent->m_widget),
- oldPageSetup,
- nativeData);
- int ret;
- if (newPageSetup != oldPageSetup)
- {
- native->SetPageSetupToSettings(nativeData, newPageSetup);
- m_pageDialogData.GetPrintData().ConvertFromNative();
-
- // Store custom paper format if any.
- if (m_pageDialogData.GetPrintData().GetPaperId() == wxPAPER_NONE)
- {
- gdouble ml,mr,mt,mb,pw,ph;
- ml = gtk_page_setup_get_left_margin (newPageSetup, GTK_UNIT_MM);
- mr = gtk_page_setup_get_right_margin (newPageSetup, GTK_UNIT_MM);
- mt = gtk_page_setup_get_top_margin (newPageSetup, GTK_UNIT_MM);
- mb = gtk_page_setup_get_bottom_margin (newPageSetup, GTK_UNIT_MM);
+ // Set selected printer
+ gtk_print_settings_set(nativeData, "format-for-printer",
+ gtk_print_settings_get_printer(nativeData));
- pw = gtk_page_setup_get_paper_width (newPageSetup, GTK_UNIT_MM);
- ph = gtk_page_setup_get_paper_height (newPageSetup, GTK_UNIT_MM);
+ // Create custom dialog
+ wxString title(GetTitle());
+ if ( title.empty() )
+ title = _("Page Setup");
+ GtkWidget *
+ dlg = gtk_page_setup_unix_dialog_new(title.utf8_str(),
+ GTK_WINDOW(m_parent->m_widget));
- m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) );
- m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) );
+ gtk_page_setup_unix_dialog_set_print_settings(
+ GTK_PAGE_SETUP_UNIX_DIALOG(dlg), nativeData);
+ gtk_page_setup_unix_dialog_set_page_setup(
+ GTK_PAGE_SETUP_UNIX_DIALOG(dlg), oldPageSetup);
- m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) );
- }
+ int result = gtk_dialog_run(GTK_DIALOG(dlg));
+ gtk_widget_hide(dlg);
- ret = wxID_OK;
- }
- else
+ switch ( result )
{
- ret = wxID_CANCEL;
+ case GTK_RESPONSE_OK:
+ case GTK_RESPONSE_APPLY:
+ {
+ // Store Selected Printer Name
+ gtk_print_settings_set_printer
+ (
+ nativeData,
+ gtk_print_settings_get(nativeData, "format-for-printer")
+ );
+
+ wxGtkObject<GtkPageSetup>
+ newPageSetup(gtk_page_setup_unix_dialog_get_page_setup(
+ GTK_PAGE_SETUP_UNIX_DIALOG(dlg)));
+ native->SetPageSetupToSettings(nativeData, newPageSetup);
+
+ m_pageDialogData.GetPrintData().ConvertFromNative();
+
+ // Store custom paper format if any.
+ if ( m_pageDialogData.GetPrintData().GetPaperId() == wxPAPER_NONE )
+ {
+ gdouble ml,mr,mt,mb,pw,ph;
+ ml = gtk_page_setup_get_left_margin (newPageSetup, GTK_UNIT_MM);
+ mr = gtk_page_setup_get_right_margin (newPageSetup, GTK_UNIT_MM);
+ mt = gtk_page_setup_get_top_margin (newPageSetup, GTK_UNIT_MM);
+ mb = gtk_page_setup_get_bottom_margin (newPageSetup, GTK_UNIT_MM);
+
+ pw = gtk_page_setup_get_paper_width (newPageSetup, GTK_UNIT_MM);
+ ph = gtk_page_setup_get_paper_height (newPageSetup, GTK_UNIT_MM);
+
+ m_pageDialogData.SetMarginTopLeft(wxPoint((int)(ml+0.5),
+ (int)(mt+0.5)));
+ m_pageDialogData.SetMarginBottomRight(wxPoint((int)(mr+0.5),
+ (int)(mb+0.5)));
+
+ m_pageDialogData.SetPaperSize(wxSize((int)(pw+0.5),
+ (int)(ph+0.5)));
+ }
+
+ result = wxID_OK;
+ }
+ break;
+
+ default:
+ case GTK_RESPONSE_CANCEL:
+ result = wxID_CANCEL;
+ break;
}
- return ret;
+ gtk_widget_destroy(dlg);
+
+ return result;
}
//----------------------------------------------------------------------------
wxPrintData printdata = GetPrintDialogData().GetPrintData();
wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData();
- GtkPrintOperation *printOp = gtk_print_operation_new ();
-
- native->SetPrintJob( printOp );
-
- printout->SetIsPreview(false);
+ GtkPrintOperation * const printOp = native->GetPrintJob();
wxPrinterToGtkData dataToSend;
dataToSend.printer = this;
g_signal_connect (printOp, "begin-print", G_CALLBACK (gtk_begin_print_callback), &dataToSend);
g_signal_connect (printOp, "draw-page", G_CALLBACK (gtk_draw_page_print_callback), &dataToSend);
g_signal_connect (printOp, "end-print", G_CALLBACK (gtk_end_print_callback), printout);
- g_signal_connect (printOp, "preview", G_CALLBACK (gtk_preview_print_callback), printout);
// This is used to setup the DC and
// show the dialog if desired
wxFAIL_MSG(_("The print dialog returned an error."));
}
- g_object_unref (printOp);
-
return (sm_lastError == wxPRINTER_NO_ERROR);
}
}
m_printDialogData = dialog.GetPrintDialogData();
-
+
return new wxPrinterDC( m_printDialogData.GetPrintData() );
}
#if wxCAIRO_SCALE
m_PS2DEV = 1.0;
m_DEV2PS = 1.0;
-
+
cairo_scale( m_cairo, 72.0 / (double)m_resolution, 72.0 / (double)m_resolution );
#else
m_PS2DEV = (double)m_resolution / 72.0;
bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1),
wxCoord WXUNUSED(y1),
const wxColour& WXUNUSED(col),
- int WXUNUSED(style))
+ wxFloodFillStyle WXUNUSED(style))
{
// We can't access the given coord as a Cairo context is scalable, ie a
// coord doesn't mean anything in this context.
wxCoord w = rect.width;
wxCoord h = rect.height;
- double radius = sqrt((w/2)*(w/2)+(h/2)*(h/2));
+ const double r2 = (w/2)*(w/2)+(h/2)*(h/2);
+ double radius = sqrt(r2);
unsigned char redI = initialColour.Red();
unsigned char blueI = initialColour.Blue();
void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
{
- if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
+ if ( m_pen.IsTransparent() )
+ return;
SetPen( m_pen );
cairo_move_to ( m_cairo, XLOG2DEV(x1), YLOG2DEV(y1) );
void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x, wxCoord y)
{
- if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
+ if ( m_pen.IsTransparent() )
+ return;
SetPen( m_pen );
void wxGtkPrinterDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
{
- if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
+ if ( m_pen.IsTransparent() )
+ return;
+
if (n <= 0) return;
cairo_stroke ( m_cairo);
}
-void wxGtkPrinterDCImpl::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
+void wxGtkPrinterDCImpl::DoDrawPolygon(int n, wxPoint points[],
+ wxCoord xoffset, wxCoord yoffset,
+ wxPolygonFillMode fillStyle)
{
if (n==0) return;
cairo_restore(m_cairo);
}
-void wxGtkPrinterDCImpl::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,
+ wxPolygonFillMode fillStyle)
{
wxDCImpl::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle );
}
bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest, wxCoord ydest,
wxCoord width, wxCoord height,
wxDC *source, wxCoord xsrc, wxCoord ysrc,
- int rop, bool useMask,
+ wxRasterOperationMode rop, bool useMask,
wxCoord WXUNUSED_UNLESS_DEBUG(xsrcMask),
wxCoord WXUNUSED_UNLESS_DEBUG(ysrcMask))
{
{
wxCHECK_RET( bitmap.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
- cairo_surface_t* surface;
x = wxCoord(XLOG2DEV(x));
y = wxCoord(YLOG2DEV(y));
int bw = bitmap.GetWidth();
int bh = bitmap.GetHeight();
wxBitmap bmpSource = bitmap; // we need a non-const instance.
- unsigned char* buffer = new unsigned char[bw*bh*4];
- wxUint32* data = (wxUint32*)buffer;
-
- wxMask *mask = NULL;
- if (useMask) mask = bmpSource.GetMask();
-
- // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
- // then we'll use a different format and iterator than if it doesn't.
- if (bmpSource.HasAlpha() || mask)
- {
- surface = cairo_image_surface_create_for_data(
- buffer, CAIRO_FORMAT_ARGB32, bw, bh, bw*4);
- wxAlphaPixelData pixData(bmpSource, wxPoint(0,0), wxSize(bw, bh));
- wxCHECK_RET( pixData, wxT("Failed to gain raw access to bitmap data."));
-
- wxAlphaPixelData::Iterator p(pixData);
- int y, x;
- for (y=0; y<bh; y++)
- {
- wxAlphaPixelData::Iterator rowStart = p;
- for (x=0; x<bw; x++)
- {
- // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
- // with alpha in the upper 8 bits, then red, then green, then
- // blue. The 32-bit quantities are stored native-endian.
- // Pre-multiplied alpha is used.
- unsigned char alpha = p.Alpha();
-
- if (!bmpSource.HasAlpha() && mask)
- alpha = 255;
-
- if (alpha == 0)
- *data = 0;
- else
- *data = ( alpha << 24
- | (p.Red() * alpha/255) << 16
- | (p.Green() * alpha/255) << 8
- | (p.Blue() * alpha/255) );
- ++data;
- ++p;
- }
- p = rowStart;
- p.OffsetY(pixData, 1);
- }
- }
- else // no alpha
- {
- surface = cairo_image_surface_create_for_data(
- buffer, CAIRO_FORMAT_RGB24, bw, bh, bw*4);
- wxNativePixelData pixData(bmpSource, wxPoint(0,0), wxSize(bw, bh));
- wxCHECK_RET( pixData, wxT("Failed to gain raw access to bitmap data."));
-
- wxNativePixelData::Iterator p(pixData);
- int y, x;
- for (y=0; y<bh; y++)
- {
- wxNativePixelData::Iterator rowStart = p;
- for (x=0; x<bw; x++)
- {
- // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
- // the upper 8 bits unused. Red, Green, and Blue are stored in
- // the remaining 24 bits in that order. The 32-bit quantities
- // are stored native-endian.
- *data = ( p.Red() << 16 | p.Green() << 8 | p.Blue() );
- ++data;
- ++p;
- }
- p = rowStart;
- p.OffsetY(pixData, 1);
- }
- }
-
+ if (!useMask && !bitmap.HasPixbuf() && bitmap.GetMask())
+ bmpSource.SetMask(NULL);
cairo_save(m_cairo);
cairo_translate(m_cairo, x, y);
// Scale the image
- cairo_filter_t filter = CAIRO_FILTER_BILINEAR;
- cairo_pattern_t* pattern = cairo_pattern_create_for_surface(surface);
- cairo_pattern_set_filter(pattern,filter);
wxDouble scaleX = (wxDouble) XLOG2DEVREL(bw) / (wxDouble) bw;
wxDouble scaleY = (wxDouble) YLOG2DEVREL(bh) / (wxDouble) bh;
cairo_scale(m_cairo, scaleX, scaleY);
- cairo_set_source(m_cairo, pattern);
+ gdk_cairo_set_source_pixbuf(m_cairo, bmpSource.GetPixbuf(), 0, 0);
+ cairo_pattern_set_filter(cairo_get_source(m_cairo), CAIRO_FILTER_NEAREST);
// Use the original size here since the context is scaled already.
cairo_rectangle(m_cairo, 0, 0, bw, bh);
// Fill the rectangle using the pattern.
cairo_fill(m_cairo);
- // Clean up.
- cairo_pattern_destroy(pattern);
- cairo_surface_destroy(surface);
- delete [] buffer;
-
CalcBoundingBox(0,0);
CalcBoundingBox(bw,bh);
angle = -angle;
- bool underlined = m_font.Ok() && m_font.GetUnderlined();
+ bool underlined = m_font.IsOk() && m_font.GetUnderlined();
- const wxUTF8Buf data = text.utf8_str();
+ const wxScopedCharBuffer data = text.utf8_str();
size_t datalen = strlen(data);
pango_layout_set_text( m_layout, data, datalen);
pango_attr_list_unref(attrs);
}
- if (m_textForegroundColour.Ok())
+ if (m_textForegroundColour.IsOk())
{
unsigned char red = m_textForegroundColour.Red();
unsigned char blue = m_textForegroundColour.Blue();
}
}
- int w,h;
-
- // Scale font description.
- gint oldSize = pango_font_description_get_size( m_fontdesc );
- double size = oldSize;
- size = size * m_scaleX;
- pango_font_description_set_size( m_fontdesc, (gint)size );
-
- // Actually apply scaled font.
- pango_layout_set_font_description( m_layout, m_fontdesc );
-
- pango_layout_get_pixel_size( m_layout, &w, &h );
-
- if ( m_backgroundMode == wxBRUSHSTYLE_SOLID )
- {
- unsigned char red = m_textBackgroundColour.Red();
- unsigned char blue = m_textBackgroundColour.Blue();
- unsigned char green = m_textBackgroundColour.Green();
- unsigned char alpha = m_textBackgroundColour.Alpha();
-
- double redPS = (double)(red) / 255.0;
- double bluePS = (double)(blue) / 255.0;
- double greenPS = (double)(green) / 255.0;
- double alphaPS = (double)(alpha) / 255.0;
-
- cairo_save(m_cairo);
- cairo_translate(m_cairo, xx, yy);
- cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS );
- cairo_rotate(m_cairo,angle*DEG2RAD);
- cairo_rectangle(m_cairo, 0, 0, w, h); // still in cairo units
- cairo_fill(m_cairo);
- cairo_restore(m_cairo);
- }
-
// Draw layout.
cairo_move_to (m_cairo, xx, yy);
if (fabs(angle) > 0.00001)
cairo_rotate( m_cairo, angle*DEG2RAD );
+ cairo_scale(m_cairo, m_scaleX, m_scaleY);
+
+ int w,h;
+ pango_layout_get_pixel_size( m_layout, &w, &h );
+
+ if ( m_backgroundMode == wxBRUSHSTYLE_SOLID )
+ {
+ unsigned char red = m_textBackgroundColour.Red();
+ unsigned char blue = m_textBackgroundColour.Blue();
+ unsigned char green = m_textBackgroundColour.Green();
+ unsigned char alpha = m_textBackgroundColour.Alpha();
+
+ double redPS = (double)(red) / 255.0;
+ double bluePS = (double)(blue) / 255.0;
+ double greenPS = (double)(green) / 255.0;
+ double alphaPS = (double)(alpha) / 255.0;
+
+ cairo_save(m_cairo);
+ cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS );
+ cairo_rectangle(m_cairo, 0, 0, w, h); // still in cairo units
+ cairo_fill(m_cairo);
+ cairo_restore(m_cairo);
+ }
+
pango_cairo_update_layout (m_cairo, m_layout);
pango_cairo_show_layout (m_cairo, m_layout);
pango_layout_set_attributes(m_layout, NULL);
}
- // Reset unscaled size.
- pango_font_description_set_size( m_fontdesc, oldSize );
-
- // Actually apply unscaled font.
- pango_layout_set_font_description( m_layout, m_fontdesc );
-
// Back to device units:
CalcBoundingBox (x, y);
CalcBoundingBox (x + w, y + h);
void wxGtkPrinterDCImpl::Clear()
{
// Clear does nothing for printing, but keep the code
-// for later reuse
+// for later reuse
/*
cairo_save(m_cairo);
cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
{
m_font = font;
- if (m_font.Ok())
+ if (m_font.IsOk())
{
if (m_fontdesc)
pango_font_description_free( m_fontdesc );
m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description );
+ float size = pango_font_description_get_size( m_fontdesc );
+ size = size * GetFontPointSizeAdjustment(72.0);
+ pango_font_description_set_size( m_fontdesc, (gint)size );
+
pango_layout_set_font_description( m_layout, m_fontdesc );
}
}
void wxGtkPrinterDCImpl::SetPen( const wxPen& pen )
{
- if (!pen.Ok()) return;
+ if (!pen.IsOk()) return;
m_pen = pen;
double width;
-
+
if (m_pen.GetWidth() <= 0)
width = 0.1;
else
void wxGtkPrinterDCImpl::SetBrush( const wxBrush& brush )
{
- if (!brush.Ok()) return;
+ if (!brush.IsOk()) return;
m_brush = brush;
}
}
-void wxGtkPrinterDCImpl::SetLogicalFunction( int function )
+void wxGtkPrinterDCImpl::SetLogicalFunction( wxRasterOperationMode function )
{
if (function == wxCLEAR)
cairo_set_operator (m_cairo, CAIRO_OPERATOR_CLEAR);
return;
}
- // Set layout's text
- const wxUTF8Buf dataUTF8 = string.utf8_str();
+ cairo_save( m_cairo );
+ cairo_scale(m_cairo, m_scaleX, m_scaleY);
- PangoFontDescription *desc = m_fontdesc;
- if (theFont) desc = theFont->GetNativeFontInfo()->description;
+ // Set layout's text
+ const wxScopedCharBuffer dataUTF8 = string.utf8_str();
- gint oldSize = pango_font_description_get_size( desc );
- double size = oldSize;
- size = size * m_scaleY;
- pango_font_description_set_size( desc, (gint)size );
+ gint oldSize=0;
+ if ( theFont )
+ {
+ // scale the font and apply it
+ PangoFontDescription *desc = theFont->GetNativeFontInfo()->description;
+ float size = pango_font_description_get_size(desc);
+ size = size * GetFontPointSizeAdjustment(72.0);
+ pango_font_description_set_size(desc, (gint)size);
- // apply scaled font
- pango_layout_set_font_description( m_layout, desc );
+ pango_layout_set_font_description(m_layout, desc);
+ }
pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) );
- int w, h;
- pango_layout_get_pixel_size( m_layout, &w, &h );
-
- if (width)
- *width = wxRound( (double)w / m_scaleX * m_PS2DEV );
- if (height)
- *height = wxRound( (double)h / m_scaleY * m_PS2DEV );
+ int h;
+ pango_layout_get_pixel_size( m_layout, width, &h );
+ if ( height )
+ *height = h;
if (descent)
{
PangoLayoutIter *iter = pango_layout_get_iter(m_layout);
int baseline = pango_layout_iter_get_baseline(iter);
pango_layout_iter_free(iter);
- *descent = wxRound( (h - PANGO_PIXELS(baseline)) * m_PS2DEV );
+ *descent = h - PANGO_PIXELS(baseline);
}
- // Reset unscaled size.
- pango_font_description_set_size( desc, oldSize );
+ if ( theFont )
+ {
+ // restore font and reset font's size back
+ pango_layout_set_font_description(m_layout, m_fontdesc);
+
+ PangoFontDescription *desc = theFont->GetNativeFontInfo()->description;
+ pango_font_description_set_size(desc, oldSize);
+ }
- // Reset unscaled font.
- pango_layout_set_font_description( m_layout, m_fontdesc );
+ cairo_restore( m_cairo );
}
void wxGtkPrinterDCImpl::DoGetSize(int* width, int* height) const
m_printData = data;
}
-// overriden for wxPrinterDC Impl
+// overridden for wxPrinterDC Impl
-wxRect wxGtkPrinterDCImpl::GetPaperRect()
+wxRect wxGtkPrinterDCImpl::GetPaperRect() const
{
// Does GtkPrint support printer margins?
int w = 0;
return wxRect( 0,0,w,h );
}
-int wxGtkPrinterDCImpl::GetResolution()
+int wxGtkPrinterDCImpl::GetResolution() const
{
return m_resolution;
}
if (paper)
{
- m_previewPrintout->SetPPIScreen(wxGetDisplayPPI());
- m_previewPrintout->SetPPIPrinter( m_resolution, m_resolution );
+ const wxSize screenPPI = wxGetDisplayPPI();
+ int logPPIScreenX = screenPPI.GetWidth();
+ int logPPIScreenY = screenPPI.GetHeight();
+ int logPPIPrinterX = m_resolution;
+ int logPPIPrinterY = m_resolution;
+
+ m_previewPrintout->SetPPIScreen( logPPIScreenX, logPPIScreenY );
+ m_previewPrintout->SetPPIPrinter( logPPIPrinterX, logPPIPrinterY );
// Get width and height in points (1/72th of an inch)
wxSize sizeDevUnits(paper->GetSizeDeviceUnits());
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)m_resolution;
- m_previewScaleY = m_previewScaleX;
+ m_previewScaleX = float(logPPIScreenX) / logPPIPrinterX;
+ m_previewScaleY = float(logPPIScreenY) / logPPIPrinterY;
}
}