#include "wx/dcclient.h"
#include "wx/dcmemory.h"
#include "wx/dcprint.h"
- #ifdef __WXGTK__
- #include "wx/window.h"
- #endif
+ #include "wx/window.h"
#endif
#include "wx/private/graphics.h"
#include <cairo.h>
#ifdef __WXMSW__
#include <cairo-win32.h>
+// Notice that the order is important: cairo-win32.h includes windows.h which
+// pollutes the global name space with macros so include our own header which
+// #undefines them after it.
+#include "wx/msw/private.h"
#endif
#ifdef __WXGTK__
#include "wx/gtk/dc.h"
#endif
-#ifdef __WXMSW__
-#include <cairo-win32.h>
-#endif
-
#ifdef __WXMAC__
#include "wx/osx/private.h"
#include <cairo-quartz.h>
virtual bool Apply( wxGraphicsContext* context );
#ifdef __WXGTK__
- const PangoFontDescription* GetFont() const { return m_font; }
- bool GetUnderlined() const { return m_underlined; }
- bool GetStrikethrough() const { return m_strikethrough; }
+ const wxFont& GetFont() const { return m_wxfont; }
#endif
private :
void InitColour(const wxColour& col);
#ifdef __WXMAC__
cairo_font_face_t *m_font;
#elif defined(__WXGTK__)
- PangoFontDescription* m_font;
- bool m_underlined;
- bool m_strikethrough;
+ wxFont m_wxfont;
#endif
// These members are used when the font is created from its face name and
cairo_font_weight_t m_weight;
};
-class wxCairoBitmapData : public wxGraphicsObjectRefData
+class wxCairoBitmapData : public wxGraphicsBitmapData
{
public:
wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp );
virtual cairo_surface_t* GetCairoSurface() { return m_surface; }
virtual cairo_pattern_t* GetCairoPattern() { return m_pattern; }
+ virtual void* GetNativeBitmap() const { return m_surface; }
virtual wxSize GetSize() { return wxSize(m_width, m_height); }
#if wxUSE_IMAGE
virtual void Clip( const wxRegion ®ion );
#ifdef __WXMSW__
cairo_surface_t* m_mswSurface;
+ WindowHDC m_mswWindowHDC;
#endif
// clips drawings to the rect
}
wxCairoFontData::wxCairoFontData( wxGraphicsRenderer* renderer, const wxFont &font,
- const wxColour& col ) : wxGraphicsObjectRefData(renderer)
+ const wxColour& col )
+ : wxGraphicsObjectRefData(renderer)
+#ifdef __WXGTK__
+ , m_wxfont(font)
+#endif
{
InitColour(col);
#ifdef __WXMAC__
m_font = cairo_quartz_font_face_create_for_cgfont( font.OSXGetCGFont() );
#elif defined(__WXGTK__)
- m_font = pango_font_description_copy( font.GetNativeFontInfo()->description );
- m_underlined = font.GetUnderlined();
- m_strikethrough = font.GetStrikethrough();
#else
InitFontComponents
(
// directly to cairo_set_font_size().
m_size = sizeInPixels;
-#if defined(__WXGTK__) || defined(__WXMAC__)
+#if defined(__WXMAC__)
m_font = NULL;
#endif
#ifdef __WXMAC__
if ( m_font )
cairo_font_face_destroy( m_font );
-#elif defined(__WXGTK__)
- if ( m_font )
- pango_font_description_free( m_font );
-#else
#endif
}
cairo_t * ctext = (cairo_t*) context->GetNativeContext();
cairo_set_source_rgba(ctext,m_red,m_green, m_blue,m_alpha);
#ifdef __WXGTK__
- if ( m_font )
+ if (m_wxfont.IsOk())
{
// Nothing to do, the caller uses Pango layout functions to do
// everything.
}
wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, cairo_surface_t* bitmap ) :
- wxGraphicsObjectRefData( renderer )
+ wxGraphicsBitmapData( renderer )
{
m_surface = bitmap;
m_pattern = cairo_pattern_create_for_surface(m_surface);
}
-wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp ) : wxGraphicsObjectRefData( renderer )
+wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp ) : wxGraphicsBitmapData( renderer )
{
wxCHECK_RET( bmp.IsOk(), wxT("Invalid bitmap in wxCairoContext::DrawBitmap"));
wxCairoBitmapData::wxCairoBitmapData(wxGraphicsRenderer* renderer,
const wxImage& image)
- : wxGraphicsObjectRefData(renderer)
+ : wxGraphicsBitmapData(renderer)
{
const cairo_format_t bufferFormat = image.HasAlpha()
? CAIRO_FORMAT_ARGB32
m_enableOffset = true;
#ifdef __WXMSW__
- m_mswSurface = cairo_win32_surface_create((HDC)dc.GetHDC());
+
+ HDC hdc = (HDC)dc.GetHDC();
+
+ HBITMAP bitmap = (HBITMAP)GetCurrentObject(hdc, OBJ_BITMAP);
+
+ BITMAP info;
+ bool hasBitmap = false;
+
+ // cairo_win32_surface_create creates a 24-bit bitmap,
+ // so if we have alpha, we need to create a 32-bit surface instead.
+ if (!GetObject(bitmap, sizeof(info), &info) || info.bmBitsPixel < 32)
+ m_mswSurface = cairo_win32_surface_create(hdc);
+ else {
+ hasBitmap = true;
+ m_mswSurface = cairo_image_surface_create_for_data((unsigned char*)info.bmBits,
+ CAIRO_FORMAT_ARGB32,
+ info.bmWidth,
+ info.bmHeight,
+ info.bmWidthBytes);
+ }
+
Init( cairo_create(m_mswSurface) );
+ // If we've created a image surface, we need to flip the Y axis so that
+ // all drawing will appear right side up.
+ if (hasBitmap) {
+ cairo_matrix_t matrix;
+ cairo_matrix_init(&matrix, 1.0, 0.0, 0.0, -1.0, 0.0, height);
+ cairo_set_matrix(m_context, &matrix);
+ }
#endif
#ifdef __WXGTK20__
}
wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, wxWindow *window)
-: wxGraphicsContext(renderer)
+ : wxGraphicsContext(renderer)
+#ifdef __WXMSW__
+ , m_mswWindowHDC(GetHwndOf(window))
+#endif
{
m_enableOffset = true;
#ifdef __WXGTK__
#endif
#ifdef __WXMSW__
- m_mswSurface = cairo_win32_surface_create((HDC)window->GetHandle());
+ m_mswSurface = cairo_win32_surface_create((HDC)m_mswWindowHDC);
Init(cairo_create(m_mswSurface));
#endif
if ( ((wxCairoFontData*)m_font.GetRefData())->Apply(this) )
{
#ifdef __WXGTK__
- size_t datalen = strlen(data);
-
PangoLayout *layout = pango_cairo_create_layout (m_context);
- wxCairoFontData* font_data = (wxCairoFontData*) m_font.GetRefData();
- pango_layout_set_font_description( layout, font_data->GetFont());
- pango_layout_set_text(layout, data, datalen);
-
- PangoAttrList* attrs = NULL;
- if (font_data->GetUnderlined())
- {
- attrs = pango_attr_list_new();
- PangoAttribute *attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
- pango_attr_list_insert(attrs, attr);
- }
- if (font_data->GetStrikethrough())
- {
- if (attrs == NULL)
- attrs = pango_attr_list_new();
- PangoAttribute* attr = pango_attr_strikethrough_new(true);
- pango_attr_list_insert(attrs, attr);
- }
- if (attrs)
- {
- pango_layout_set_attributes(layout, attrs);
- pango_attr_list_unref(attrs);
- }
+ const wxFont& font = static_cast<wxCairoFontData*>(m_font.GetRefData())->GetFont();
+ pango_layout_set_font_description(layout, font.GetNativeFontInfo()->description);
+ pango_layout_set_text(layout, data, data.length());
+ font.GTKSetPangoAttrs(layout);
cairo_move_to(m_context, x, y);
pango_cairo_show_layout (m_context, layout);
int w, h;
PangoLayout *layout = pango_cairo_create_layout (m_context);
- pango_layout_set_font_description( layout, ((wxCairoFontData*)m_font.GetRefData())->GetFont());
+ const wxFont& font = static_cast<wxCairoFontData*>(m_font.GetRefData())->GetFont();
+ pango_layout_set_font_description(layout, font.GetNativeFontInfo()->description);
const wxCharBuffer data = str.utf8_str();
if ( !data )
{
return;
}
- pango_layout_set_text( layout, data, strlen(data) );
+ pango_layout_set_text(layout, data, data.length());
pango_layout_get_pixel_size (layout, &w, &h);
if ( width )
*width = w;