#include "wx/gtk/private.h"
#include "wx/dynlib.h"
#include "wx/paper.h"
-#include "wx/rawbmp.h"
#include <gtk/gtk.h>
-#include <gtk/gtkpagesetupunixdialog.h>
#if wxUSE_GRAPHICS_CONTEXT
#include "wx/graphics.h"
}
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();
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);
}
}
- 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_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 );
}
}
m_pen = pen;
double width;
-
+
if (m_pen.GetWidth() <= 0)
width = 0.1;
else
}
}
-void wxGtkPrinterDCImpl::SetLogicalFunction( int function )
+void wxGtkPrinterDCImpl::SetLogicalFunction( wxRasterOperationMode function )
{
if (function == wxCLEAR)
cairo_set_operator (m_cairo, CAIRO_OPERATOR_CLEAR);
return;
}
+ cairo_save( m_cairo );
+ cairo_scale(m_cairo, m_scaleX, m_scaleY);
+
// Set layout's text
const wxUTF8Buf dataUTF8 = string.utf8_str();
- PangoFontDescription *desc = m_fontdesc;
- if (theFont) desc = theFont->GetNativeFontInfo()->description;
-
- 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
// overriden 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;
}
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);