? .swo ? cairomm-1.0.pc ? docs ? cairomm/.deps ? cairomm/.libs ? cairomm/context.lo ? cairomm/exception.lo ? cairomm/fontface.lo ? cairomm/fontoptions.lo ? cairomm/libcairomm-1.0.la ? cairomm/path.lo ? cairomm/pattern.lo ? cairomm/private.lo ? cairomm/surface.loT ? examples/example_png_file.png ? examples/pdf-surface ? examples/ps-surface ? examples/svg-surface ? examples/xlib-surface ? examples/png_file/.cvsignore ? examples/png_file/a.out Index: ChangeLog =================================================================== RCS file: /cvs/cairo/cairomm/ChangeLog,v retrieving revision 1.14 diff -u -r1.14 ChangeLog --- ChangeLog 7 Jan 2006 11:53:02 -0000 1.14 +++ ChangeLog 20 Jan 2006 23:36:53 -0000 @@ -1,3 +1,27 @@ +2006-01-15 Jonathon Jongsma + + * cairomm/surface.cc: + * cairomm/surface.h: backwards-incompatible API change for the Surface + types. Cairo::Surface is now a base class for all of the other surface + types, and should not be used directly. New Surface types include + ImageSurface, XlibSurface, Win32Surface, PdfSurface, PsSurface, + SvgSurface, and GlitzSurface. + Modified Surface::write_to_png() and Surface::write_to_png_stream() so + that they throw exceptions like the other functions instead of returning a + cairo_status_t value. + Added exception specifications to all Surface functions that can throw + exceptions. + Removed some status checks for all functions that don't change the + internal status of the Surface. + Added API documentation for all Surface classes and all member functions + of the Surface class heirarchy. + * examples/png_file/Makefile.am: added generated PNG file to CLEANFILES + * examples/png_file/main.cc: updated the PNG example to use the new + ImageSurface class instead of using the Surface class directly. + * cairomm/*: Renamed the Cairo::Status type to Cairo::ErrorStatus since it + conflicts with a #define Status in XLib and is not used exposed in the API + anyway. + 2006-01-06 Jonathon Jongsma * cairomm/surface.cc: Index: cairomm/context.h =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/context.h,v retrieving revision 1.7 diff -u -r1.7 context.h --- cairomm/context.h 20 Dec 2005 09:17:53 -0000 1.7 +++ cairomm/context.h 20 Jan 2006 23:36:54 -0000 @@ -167,7 +167,7 @@ #ifndef DOXYGEN_IGNORE_THIS ///For use only by the cairomm implementation. - inline Status get_status() const + inline ErrorStatus get_status() const { return cairo_status(const_cast(cobj())); } #endif //DOXYGEN_IGNORE_THIS Index: cairomm/enums.h =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/enums.h,v retrieving revision 1.2 diff -u -r1.2 enums.h --- cairomm/enums.h 2 Dec 2005 14:05:17 -0000 1.2 +++ cairomm/enums.h 20 Jan 2006 23:36:54 -0000 @@ -25,7 +25,7 @@ #ifndef DOXYGEN_IGNORE_THIS //This is only used internally, but it must be in a public header because we inline some methods. -typedef cairo_status_t Status; +typedef cairo_status_t ErrorStatus; #endif //DOXYGEN_IGNORE_THIS } // namespace Cairo Index: cairomm/exception.cc =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/exception.cc,v retrieving revision 1.3 diff -u -r1.3 exception.cc --- cairomm/exception.cc 7 Dec 2005 15:14:38 -0000 1.3 +++ cairomm/exception.cc 20 Jan 2006 23:36:54 -0000 @@ -26,7 +26,7 @@ } //TODO: Is it wise to assume that the string is ASCII, as expected by std::logic_error? -logic_error::logic_error(Status status) +logic_error::logic_error(ErrorStatus status) : std::logic_error( string_or_empty(cairo_status_to_string((cairo_status_t)m_status)) ), m_status(status) { Index: cairomm/exception.h =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/exception.h,v retrieving revision 1.3 diff -u -r1.3 exception.h --- cairomm/exception.h 7 Dec 2005 15:14:38 -0000 1.3 +++ cairomm/exception.h 20 Jan 2006 23:36:54 -0000 @@ -24,20 +24,20 @@ namespace Cairo { -typedef cairo_status_t Status; +typedef cairo_status_t ErrorStatus; /** */ class logic_error: public std::logic_error { public: - explicit logic_error(Status status); + explicit logic_error(ErrorStatus status); virtual ~logic_error() throw(); //virtual const char* what() const throw(); private: - Status m_status; + ErrorStatus m_status; }; } // namespace xmlpp Index: cairomm/fontface.cc =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/fontface.cc,v retrieving revision 1.4 diff -u -r1.4 fontface.cc --- cairomm/fontface.cc 20 Dec 2005 09:17:53 -0000 1.4 +++ cairomm/fontface.cc 20 Jan 2006 23:36:54 -0000 @@ -56,7 +56,7 @@ void FontFace::set_user_data(const cairo_user_data_key_t* key, void *user_data, cairo_destroy_func_t destroy) { - const Status status = (Status)cairo_font_face_set_user_data(m_cobject, key, user_data, destroy); + const ErrorStatus status = (ErrorStatus)cairo_font_face_set_user_data(m_cobject, key, user_data, destroy); check_status_and_throw_exception(status); } */ Index: cairomm/fontface.h =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/fontface.h,v retrieving revision 1.4 diff -u -r1.4 fontface.h --- cairomm/fontface.h 20 Dec 2005 09:17:53 -0000 1.4 +++ cairomm/fontface.h 20 Jan 2006 23:36:54 -0000 @@ -59,7 +59,7 @@ #ifndef DOXYGEN_IGNORE_THIS ///For use only by the cairomm implementation. - inline Status get_status() const + inline ErrorStatus get_status() const { return cairo_font_face_status(const_cast(cobj())); } #endif //DOXYGEN_IGNORE_THIS Index: cairomm/fontoptions.h =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/fontoptions.h,v retrieving revision 1.2 diff -u -r1.2 fontoptions.h --- cairomm/fontoptions.h 2 Dec 2005 14:05:17 -0000 1.2 +++ cairomm/fontoptions.h 20 Jan 2006 23:36:54 -0000 @@ -69,7 +69,7 @@ #ifndef DOXYGEN_IGNORE_THIS ///For use only by the cairomm implementation. - inline Status get_status() const + inline ErrorStatus get_status() const { return cairo_font_options_status(const_cast(cobj())); } #endif //DOXYGEN_IGNORE_THIS Index: cairomm/path.h =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/path.h,v retrieving revision 1.2 diff -u -r1.2 path.h --- cairomm/path.h 2 Dec 2005 14:05:17 -0000 1.2 +++ cairomm/path.h 20 Jan 2006 23:36:54 -0000 @@ -50,7 +50,7 @@ #ifndef DOXYGEN_IGNORE_THIS ///For use only by the cairomm implementation. //There is no *_status() function for this object: - //inline Status get_status() const + //inline ErrorStatus get_status() const //{ return cairo_path_status(const_cast(cobj())); } #endif //DOXYGEN_IGNORE_THIS Index: cairomm/pattern.h =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/pattern.h,v retrieving revision 1.4 diff -u -r1.4 pattern.h --- cairomm/pattern.h 20 Dec 2005 09:17:53 -0000 1.4 +++ cairomm/pattern.h 20 Jan 2006 23:36:54 -0000 @@ -59,7 +59,7 @@ #ifndef DOXYGEN_IGNORE_THIS ///For use only by the cairomm implementation. - inline Status get_status() const + inline ErrorStatus get_status() const { return cairo_pattern_status(const_cast(cobj())); } #endif //DOXYGEN_IGNORE_THIS Index: cairomm/private.cc =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/private.cc,v retrieving revision 1.3 diff -u -r1.3 private.cc --- cairomm/private.cc 7 Dec 2005 15:14:38 -0000 1.3 +++ cairomm/private.cc 20 Jan 2006 23:36:54 -0000 @@ -23,7 +23,7 @@ namespace Cairo { -void throw_exception(Status status) +void throw_exception(ErrorStatus status) { switch(status) { Index: cairomm/private.h =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/private.h,v retrieving revision 1.3 diff -u -r1.3 private.h --- cairomm/private.h 7 Dec 2005 15:14:38 -0000 1.3 +++ cairomm/private.h 20 Jan 2006 23:36:54 -0000 @@ -26,10 +26,10 @@ namespace Cairo { -void throw_exception(Status status); +void throw_exception(ErrorStatus status); //We inline this because it is called so often. -inline void check_status_and_throw_exception(Status status) +inline void check_status_and_throw_exception(ErrorStatus status) { if(status != CAIRO_STATUS_SUCCESS) throw_exception(status); //This part doesn't need to be inline because it would rarely be called. Index: cairomm/surface.cc =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/surface.cc,v retrieving revision 1.6 diff -u -r1.6 surface.cc --- cairomm/surface.cc 7 Jan 2006 11:53:02 -0000 1.6 +++ cairomm/surface.cc 20 Jan 2006 23:36:54 -0000 @@ -36,113 +36,343 @@ cairo_surface_destroy(m_cobject); } -RefPtr Surface::create(Format format, int width, int height) +void Surface::finish() throw() { - cairo_surface_t* cobject = cairo_image_surface_create((cairo_format_t)format, width, height); - check_status_and_throw_exception(cairo_surface_status(cobject)); - return RefPtr(new Surface(cobject, true /* has reference */)); + cairo_surface_finish(m_cobject); + check_object_status_and_throw_exception(*this); } -RefPtr Surface::create(unsigned char* data, Format format, int width, int height, int stride) +void* Surface::get_user_data(const cairo_user_data_key_t *key) const { - cairo_surface_t* cobject = cairo_image_surface_create_for_data(data, (cairo_format_t)format, width, height, stride); - check_status_and_throw_exception(cairo_surface_status(cobject)); - return RefPtr(new Surface(cobject, true /* has reference */)); + void* result = cairo_surface_get_user_data(m_cobject, key); + // XXX: This function doesn't seem to change status + //check_object_status_and_throw_exception(*this); + return result; } -RefPtr Surface::create(const Surface& other, Content content, int width, int height) +void Surface::set_user_data(const cairo_user_data_key_t* key, void *user_data, cairo_destroy_func_t destroy) throw(std::bad_alloc) { - cairo_surface_t* cobject = cairo_surface_create_similar(other.m_cobject, (cairo_content_t)content, width, height); - check_status_and_throw_exception(cairo_surface_status(cobject)); - return RefPtr(new Surface(cobject, true /* has reference */)); + const ErrorStatus status = (ErrorStatus)cairo_surface_set_user_data(m_cobject, key, user_data, destroy); + check_status_and_throw_exception(status); } -void Surface::finish() +void Surface::get_font_options(FontOptions& options) const { - cairo_surface_finish(m_cobject); + cairo_font_options_t* cfontoptions = cairo_font_options_create(); + cairo_surface_get_font_options(m_cobject, cfontoptions); + options = FontOptions(cfontoptions); + cairo_font_options_destroy(cfontoptions); + // XXX: This function doesn't seem to change status + //check_object_status_and_throw_exception(*this); +} + +void Surface::flush() throw() +{ + cairo_surface_flush(m_cobject); check_object_status_and_throw_exception(*this); } -#ifdef CAIRO_HAS_PNG_FUNCTIONS -Status Surface::write_to_png(const std::string& filename) +void Surface::mark_dirty() throw() { - return (Status)cairo_surface_write_to_png(m_cobject, filename.c_str()); + cairo_surface_mark_dirty(m_cobject); + check_object_status_and_throw_exception(*this); } -Status Surface::write_to_png_stream(cairo_write_func_t write_func, void *closure) +void Surface::mark_dirty(int x, int y, int width, int height) throw() { - return (Status)cairo_surface_write_to_png_stream(m_cobject, write_func, closure); + cairo_surface_mark_dirty_rectangle(m_cobject, x, y, width, height); + check_object_status_and_throw_exception(*this); } -#endif -void* Surface::get_user_data(const cairo_user_data_key_t *key) +void Surface::set_device_offset(double x_offset, double y_offset) throw(logic_error) { - void* result = cairo_surface_get_user_data(m_cobject, key); + cairo_surface_set_device_offset(m_cobject, x_offset, y_offset); check_object_status_and_throw_exception(*this); - return result; } -void Surface::set_user_data(const cairo_user_data_key_t* key, void *user_data, cairo_destroy_func_t destroy) +#ifdef CAIRO_HAS_PNG_FUNCTIONS +void Surface::write_to_png(const std::string& filename) throw(std::bad_alloc, logic_error, std::ios_base::failure) { - const Status status = (Status)cairo_surface_set_user_data(m_cobject, key, user_data, destroy); + ErrorStatus status = cairo_surface_write_to_png(m_cobject, filename.c_str()); check_status_and_throw_exception(status); } -void Surface::get_font_options(FontOptions& options) +void Surface::write_to_png(cairo_write_func_t write_func, void *closure) throw(std::bad_alloc, logic_error, std::ios_base::failure) { - cairo_font_options_t* cfontoptions = cairo_font_options_create(); - cairo_surface_get_font_options(m_cobject, cfontoptions); - options = FontOptions(cfontoptions); - cairo_font_options_destroy(cfontoptions); - check_object_status_and_throw_exception(*this); + ErrorStatus status = cairo_surface_write_to_png_stream(m_cobject, write_func, closure); + check_status_and_throw_exception(status); } +#endif -void Surface::flush() +void Surface::reference() const { - cairo_surface_flush(m_cobject); - check_object_status_and_throw_exception(*this); + cairo_surface_reference(m_cobject); } -void Surface::mark_dirty() +void Surface::unreference() const { - cairo_surface_mark_dirty(m_cobject); - check_object_status_and_throw_exception(*this); + cairo_surface_destroy(m_cobject); } -void Surface::mark_dirty(int x, int y, int width, int height) +RefPtr Surface::create(const Surface& other, Content content, int width, int height) throw(std::bad_alloc) { - cairo_surface_mark_dirty_rectangle(m_cobject, x, y, width, height); - check_object_status_and_throw_exception(*this); + cairo_surface_t* cobject = cairo_surface_create_similar(other.m_cobject, (cairo_content_t)content, width, height); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new Surface(cobject, true /* has reference */)); } -void Surface::set_device_offset(double x_offset, double y_offset) + + +ImageSurface::ImageSurface(cairo_surface_t* cobject, bool has_reference) +: Surface(cobject, has_reference) +{ } + +ImageSurface::~ImageSurface() { - cairo_surface_set_device_offset(m_cobject, x_offset, y_offset); - check_object_status_and_throw_exception(*this); + // surface is destroyed in base class } -int Surface::get_width() const +RefPtr ImageSurface::create(Format format, int width, int height) throw(std::bad_alloc) +{ + cairo_surface_t* cobject = cairo_image_surface_create((cairo_format_t)format, width, height); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new ImageSurface(cobject, true /* has reference */)); +} + +RefPtr ImageSurface::create(unsigned char* data, Format format, int width, int height, int stride) throw(std::bad_alloc) +{ + cairo_surface_t* cobject = cairo_image_surface_create_for_data(data, (cairo_format_t)format, width, height, stride); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new ImageSurface(cobject, true /* has reference */)); +} + +#ifdef CAIRO_HAS_PNG_FUNCTIONS + +RefPtr ImageSurface::create_from_png(std::string filename) throw(std::bad_alloc) +{ + cairo_surface_t* cobject = cairo_image_surface_create_from_png(filename.c_str()); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new ImageSurface(cobject, true /* has reference */)); +} + +RefPtr ImageSurface::create_from_png(cairo_read_func_t read_func, void *closure) throw(std::bad_alloc) +{ + cairo_surface_t* cobject = cairo_image_surface_create_from_png_stream(read_func, closure); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new ImageSurface(cobject, true /* has reference */)); +} + +#endif // CAIRO_HAS_PNG_FUNCTIONS + +int ImageSurface::get_width() const throw(logic_error) { const int result = cairo_image_surface_get_width(m_cobject); check_object_status_and_throw_exception(*this); return result; } -int Surface::get_height() const +int ImageSurface::get_height() const throw(logic_error) { const int result = cairo_image_surface_get_height(m_cobject); check_object_status_and_throw_exception(*this); return result; } -void Surface::reference() const + +#ifdef CAIRO_HAS_XLIB_SURFACE + +XlibSurface::XlibSurface(cairo_surface_t* cobject, bool has_reference) : + Surface(cobject, has_reference) +{} + +XlibSurface::~XlibSurface() { - cairo_surface_reference(m_cobject); + // surface is destroyed in base class } -void Surface::unreference() const +RefPtr XlibSurface::create(Display *dpy, Drawable drawable, Visual *visual, int width, int height) throw(std::bad_alloc) { - cairo_surface_destroy(m_cobject); + cairo_surface_t* cobject = cairo_xlib_surface_create(dpy, drawable, visual, width, height); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new XlibSurface(cobject, true /* has reference */)); } +RefPtr XlibSurface::create(Display *dpy, Pixmap bitmap, Screen *screen, int width, int height) throw(std::bad_alloc) +{ + cairo_surface_t* cobject = cairo_xlib_surface_create_for_bitmap(dpy, bitmap, screen, width, height); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new XlibSurface(cobject, true /* has reference */)); +} + +void XlibSurface::set_size(int width, int height) +{ + cairo_xlib_surface_set_size(m_cobject, width, height); + // XXX: This doesn't seem to change the surface's status + //check_object_status_and_throw_exception(*this); +} + +void XlibSurface::set_drawable(Drawable drawable, int width, int height) +{ + cairo_xlib_surface_set_drawable(m_cobject, drawable, width, height); + // XXX: This doesn't seem to change the surface's status + //check_object_status_and_throw_exception(*this); +} + +#endif // CAIRO_HAS_XLIB_SURFACE + + + +#ifdef CAIRO_HAS_WIN32_SURFACE + +Win32Surface::Win32Surface(cairo_surface_t* cobject, bool has_reference) : + Surface(cobject, has_reference) +{} + +Win32Surface::~Win32Surface() +{ + // surface is destroyed in base class +} + +RefPtr Win32Surface::create(HDC hdc) throw(std::bad_alloc); +{ + cairo_surface_t* cobject = cairo_win32_surface_create(hdc); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new Win32Surface(cobject, true /* has reference */)); +} + +#endif // CAIRO_HAS_WIN32_SURFACE + + +/******************************************************************************* + * THE FOLLOWING SURFACE TYPES ARE EXPERIMENTAL AND NOT FULLY SUPPORTED + ******************************************************************************/ + +#ifdef CAIRO_HAS_PDF_SURFACE + +PdfSurface::PdfSurface(cairo_surface_t* cobject, bool has_reference) : + Surface(cobject, has_reference) +{} + +PdfSurface::~PdfSurface() +{ + // surface is destroyed in base class +} + +RefPtr PdfSurface::create(std::string filename, double width_in_points, double height_in_points) throw(std::bad_alloc) +{ + cairo_surface_t* cobject = cairo_pdf_surface_create(filename.c_str(), width_in_points, height_in_points); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new PdfSurface(cobject, true /* has reference */)); +} + +RefPtr PdfSurface::create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points) throw(std::bad_alloc) +{ + cairo_surface_t* cobject = cairo_pdf_surface_create_for_stream(write_func, closure, width_in_points, height_in_points); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new PdfSurface(cobject, true /* has reference */)); +} + +void PdfSurface::set_dpi(double x_dpi, double y_dpi) throw(logic_error) +{ + cairo_pdf_surface_set_dpi(m_cobject, x_dpi, y_dpi); + check_object_status_and_throw_exception(*this); +} + +#endif // CAIRO_HAS_PDF_SURFACE + + + + +#ifdef CAIRO_HAS_PS_SURFACE + +PsSurface::PsSurface(cairo_surface_t* cobject, bool has_reference) : + Surface(cobject, has_reference) +{} + +PsSurface::~PsSurface() +{ + // surface is destroyed in base class +} + +RefPtr PsSurface::create(std::string filename, double width_in_points, double height_in_points) throw(std::bad_alloc) +{ + cairo_surface_t* cobject = cairo_ps_surface_create(filename.c_str(), width_in_points, height_in_points); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new PsSurface(cobject, true /* has reference */)); +} + +RefPtr PsSurface::create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points) throw(std::bad_alloc) +{ + cairo_surface_t* cobject = cairo_ps_surface_create_for_stream(write_func, closure, width_in_points, height_in_points); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new PsSurface(cobject, true /* has reference */)); +} + +void PsSurface::set_dpi(double x_dpi, double y_dpi) throw(logic_error) +{ + cairo_ps_surface_set_dpi(m_cobject, x_dpi, y_dpi); + check_object_status_and_throw_exception(*this); +} + +#endif // CAIRO_HAS_PS_SURFACE + + + + +#ifdef CAIRO_HAS_SVG_SURFACE + +SvgSurface::SvgSurface(cairo_surface_t* cobject, bool has_reference) : + Surface(cobject, has_reference) +{} + +SvgSurface::~SvgSurface() +{ + // surface is destroyed in base class +} + +RefPtr SvgSurface::create(std::string filename, double width_in_points, double height_in_points) throw(std::bad_alloc) +{ + cairo_surface_t* cobject = cairo_svg_surface_create(filename.c_str(), width_in_points, height_in_points); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new SvgSurface(cobject, true /* has reference */)); +} + +RefPtr SvgSurface::create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points) throw(std::bad_alloc) +{ + cairo_surface_t* cobject = cairo_svg_surface_create_for_stream(write_func, closure, width_in_points, height_in_points); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new SvgSurface(cobject, true /* has reference */)); +} + +void SvgSurface::set_dpi(double x_dpi, double y_dpi) throw(logic_error) +{ + cairo_svg_surface_set_dpi(m_cobject, x_dpi, y_dpi); + check_object_status_and_throw_exception(*this); +} + +#endif // CAIRO_HAS_SVG_SURFACE + + + + +#ifdef CAIRO_HAS_GLITZ_SURFACE + +GlitzSurface::GlitzSurface(cairo_surface_t* cobject, bool has_reference) +: Surface(cobject, has_reference) +{ } + +GlitzSurface::~GlitzSurface() +{ + // surface is destroyed in base class +} + +RefPtr GlitzSurface::create(glitz_surface_t *surface)) +{ + cairo_surface_t* cobject = cairo_glitz_surface_create(surface); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr(new GlitzSurface(cobject, true /* has reference */)); +} + +#endif // CAIRO_HAS_GLITZ_SURFACE + } //namespace Cairo Index: cairomm/surface.h =================================================================== RCS file: /cvs/cairo/cairomm/cairomm/surface.h,v retrieving revision 1.4 diff -u -r1.4 surface.h --- cairomm/surface.h 7 Jan 2006 11:53:02 -0000 1.4 +++ cairomm/surface.h 20 Jan 2006 23:36:54 -0000 @@ -18,10 +18,33 @@ #ifndef __CAIROMM_SURFACE_H #define __CAIROMM_SURFACE_H -#include +#include +#include // for ios_base::failure exception declaration #include +#include +#include #include -#include + +#ifdef CAIRO_HAS_XLIB_SURFACE +#include +#endif +#ifdef CAIRO_HAS_WIN32_SURFACE +#include +#endif + +// Experimental surfaces +#ifdef CAIRO_HAS_PDF_SURFACE +#include +#endif // CAIRO_HAS_PDF_SURFACE +#ifdef CAIRO_HAS_PS_SURFACE +#include +#endif // CAIRO_HAS_PS_SURFACE +#ifdef CAIRO_HAS_SVG_SURFACE +#include +#endif // CAIRO_HAS_SVG_SURFACE +#ifdef CAIRO_HAS_GLITZ_SURFACE +#include +#endif // CAIRO_HAS_GLITZ_SURFACE namespace Cairo @@ -30,72 +53,638 @@ typedef cairo_content_t Content; typedef cairo_format_t Format; -/** A cairo surface represents an image, either as the destination of a drawing operation or as source when - * drawing onto another surface. There are different subtypes of cairo surface for different drawing - * backends. +/** A cairo surface represents an image, either as the destination of a drawing + * operation or as source when drawing onto another surface. There are + * different subtypes of cairo surface for different drawing backends. This + * class is a base class for all subtypes and should not be used directly * - * This is a reference-counted object. The copy constructor creates a second reference to the object, instead of creating an independent copy of the object. + * Surfaces are reference-counted objects. The copy constructor creates a + * second reference to the object, instead of creating an independent copy of + * the object. */ class Surface { protected: //TODO?: Surface(cairo_surface_t *target); -public: + // According to the cairo documentation, the user_data functions are provided + // for use by bindings and shouldn't be directly exposed in the public API + + /** Return user data previously attached to surface using the specified key. + * If no user data has been attached with the given key this function returns + * NULL. + * + * key the address of the cairo_user_data_key_t the user data was attached to + * @return the user data previously attached or NULL. + */ + void *get_user_data(const cairo_user_data_key_t *key) const; - /** Create a C++ wrapper for the C instance. This C++ instance should then be given to a RefPtr. + /** Attach user data to surface. To remove user data from a surface, call + * this function with the key that was used to set it and NULL for data. + * + * @param key the address of a cairo_user_data_key_t to attach the user + * data to + * @param user_data the user data to attach to the surface + * @param destroy a cairo_destroy_func_t which will be called when the + * surface is destroyed or when new user data is attached using the same key. + * @return CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY if a slot could + * not be allocated for the user data. + */ + void set_user_data(const cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t destroy) throw(std::bad_alloc); //TODO: Use a sigc::slot? + +public: + /** Create a C++ wrapper for the C instance. This C++ instance should then be + * given to a RefPtr. + * * @param cobject The C instance. - * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference. + * @param has_reference Whether we already have a reference. Otherwise, the + * constructor will take an extra reference. */ explicit Surface(cairo_surface_t* cobject, bool has_reference = false); virtual ~Surface(); - static RefPtr create(const Surface& other, Content content, int width, int height); - static RefPtr create(Format format, int width, int height); - static RefPtr create(unsigned char* data, Format format, int width, int height, int stride); + /** Retrieves the default font rendering options for the surface. This allows + * display surfaces to report the correct subpixel order for rendering on + * them, print surfaces to disable hinting of metrics and so forth. The + * result can then be used with cairo_scaled_font_create(). + * + * @param options a FontOptions object into which to store the retrieved + * options. All existing values are overwritten + */ + void get_font_options(FontOptions& options) const; + + /** This function finishes the surface and drops all references to external + * resources. For example, for the Xlib backend it means that cairo will no + * longer access the drawable, which can be freed. After calling + * finish() the only valid operations on a surface are getting and setting + * user data and referencing and destroying it. Further drawing to the + * surface will not affect the surface but will instead trigger a + * CAIRO_STATUS_SURFACE_FINISHED error. + * + * When the Surface is destroyed, cairo will call finish() if it hasn't been + * called already, before freeing the resources associated with the Surface. + */ + void finish() throw(); - Status write_to_png(const std::string& filename); - Status write_to_png_stream(cairo_write_func_t write_func, void *closure); //TODO: Use a sigc::slot? + /** Do any pending drawing for the surface and also restore any temporary + * modifications cairo has made to the surface's state. This function must + * be called before switching from drawing on the surface with cairo to + * drawing on it directly with native APIs. If the surface doesn't support + * direct access, then this function does nothing. + */ + void flush() throw(); - void *get_user_data(const cairo_user_data_key_t *key); + /** Tells cairo to consider the data buffer dirty. + * + * In particular, if you've created an ImageSurface with a data buffer that + * you've allocated yourself and you draw to that data buffer using means + * other than cairo, you must call mark_dirty() before doing any additional + * drawing to that surface with cairo. + * + * Note that if you do draw to the Surface outside of cairo, you must call + * flush() before doing the drawing. + */ + void mark_dirty() throw(); - void set_user_data(const cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t destroy); //TODO: Use a sigc::slot? + /** Marks a rectangular area of the given surface dirty. + * + * @param x X coordinate of dirty rectangle + * @param y Y coordinate of dirty rectangle + * @param width width of dirty rectangle + * @param height height of dirty rectangle + */ + void mark_dirty(int x, int y, int width, int height) throw(); - void get_font_options(FontOptions& options); + /** Sets an offset that is added to the device coordinates determined by the + * CTM when drawing to surface. One use case for this function is when we + * want to create a Surface that redirects drawing for a portion of + * an onscreen surface to an offscreen surface in a way that is completely + * invisible to the user of the cairo API. Setting a transformation via + * cairo_translate() isn't sufficient to do this, since functions like + * Cairo::Context::device_to_user() will expose the hidden offset. + * + * Note that the offset only affects drawing to the surface, not using the + * surface in a surface pattern. + * + * @param x_offset the offset in the X direction, in device units + * @param y_offset the offset in the Y direction, in device units + */ + void set_device_offset(double x_offset, double y_offset) throw(logic_error); - void finish(); - void flush(); +#ifdef CAIRO_HAS_PNG_FUNCTIONS - void mark_dirty(); - void mark_dirty(int x, int y, int width, int height); + /** Writes the contents of surface to a new file filename as a PNG image. + * + * \note For this function to be available, cairo must have been compiled + * with PNG support + * + * @param filename the name of a file to write to + */ + void write_to_png(const std::string& filename) throw(std::bad_alloc, logic_error, std::ios_base::failure); - void set_device_offset(double x_offset, double y_offset); + /** Writes the Surface to the write function. + * + * \note For this function to be available, cairo must have been compiled + * with PNG support + * + * @param write_func The function to be called when the backend needs to + * write data to an output stream + * @param closure closure data for the write function + */ + void write_to_png(cairo_write_func_t write_func, void *closure) throw(std::bad_alloc, logic_error, std::ios_base::failure); //TODO: Use a sigc::slot? - int get_width() const; - int get_height() const; +#endif // CAIRO_HAS_PNG_FUNCTIONS - void create_from_png(const char* filename); - void create_from_png_stream(cairo_read_func_t read_func, void *closure); + /** The underlying C cairo surface type + */ typedef cairo_surface_t cobject; + /** Provides acces to the underlying C cairo surface + */ inline cobject* cobj() { return m_cobject; } + /** Provides acces to the underlying C cairo surface + */ inline const cobject* cobj() const { return m_cobject; } #ifndef DOXYGEN_IGNORE_THIS ///For use only by the cairomm implementation. - inline Status get_status() const + inline ErrorStatus get_status() const { return cairo_surface_status(const_cast(cobj())); } - #endif //DOXYGEN_IGNORE_THIS void reference() const; void unreference() const; + #endif //DOXYGEN_IGNORE_THIS + + /** Create a new surface that is as compatible as possible with an existing + * surface. The new surface will use the same backend as other unless that is + * not possible for some reason. + * + * @param other an existing surface used to select the backend of the new surface + * @param content the content for the new surface + * @param width width of the new surface, (in device-space units) + * @param height height of the new surface (in device-space units) + * @return a RefPtr to the newly allocated surface. + */ + static RefPtr create(const Surface& other, Content content, int width, int height) throw(std::bad_alloc); protected: + /** The underlying C cairo surface type that is wrapped by this Surface + */ cobject* m_cobject; }; + +/** Image surfaces provide the ability to render to memory buffers either + * allocated by cairo or by the calling code. The supported image formats are + * those defined in Cairo::Format + * + * An ImageSurface is the most generic type of Surface and the only one that is + * available by default. You can either create an ImageSurface whose data is + * managed by Cairo, or you can create an ImageSurface with a data buffer that + * you allocated yourself so that you can have full access to the data. + * + * When you create an ImageSurface with your own data buffer, you are free to + * examine the results at any point and do whatever you want with it. Note that + * if you modify anything and later want to continue to draw to the surface + * with cairo, you must let cairo know via Cairo::Surface::mark_dirty() + * + * Note that like all surfaces, an ImageSurface is a reference-counted object + * in which the copy constructor creates a second reference to the Surface + * instead of creating an independant copy + */ +class ImageSurface : public Surface +{ +protected: + //TODO?: Surface(cairo_surface_t *target); + +public: + + /** Create a C++ wrapper for the C instance. This C++ instance should then be + * given to a RefPtr. + * @param cobject The C instance. + * @param has_reference Whether we already have a reference. Otherwise, the + * constructor will take an extra reference. + */ + explicit ImageSurface(cairo_surface_t* cobject, bool has_reference = false); + + virtual ~ImageSurface(); + + /** Gets the width of the ImageSurface in pixels + */ + int get_width() const throw(logic_error); + + /** Gets the height of the ImageSurface in pixels + */ + int get_height() const throw(logic_error); + + /** Creates an image surface of the specified format and dimensions. The + * initial contents of the surface is undefined; you must explicitely clear + * the buffer, using, for example, Cairo::Context::rectangle() and + * Cairo::Context::fill() if you want it cleared. + * + * Use this function to create the surface if you don't need access to the + * internal data and want cairo to manage it for you. Since you don't have + * access to the internal data, the resulting surface can only be saved to a + * PNG image file (if cairo has been compiled with PNG support) or as a + * source surface (see Cairo::SurfacePattern). + * + * @param format format of pixels in the surface to create + * @param width width of the surface, in pixels + * @param height height of the surface, in pixels + * @return a RefPtr to the newly created surface. + */ + static RefPtr create(Format format, int width, int height) throw(std::bad_alloc); + + /** Creates an image surface for the provided pixel data. The output buffer + * must be kept around until the Surface is destroyed or finish() is called + * on the surface. The initial contents of buffer will be used as the inital + * image contents; you must explicitely clear the buffer, using, for example, + * Cairo::Context::rectangle() and Cairo::Context::fill() if you want it + * cleared. + * + * If you want to be able to manually manipulate or extract the data after + * drawing to the surface with Cairo, you should use this function to create + * the Surface. Since you own the internal data, you can do anything you + * want with it. + * + * @param data a pointer to a buffer supplied by the application in which + * to write contents. + * @param format the format of pixels in the buffer + * @param width the width of the image to be stored in the buffer + * @param height the height of the image to be stored in the buffer + * @param stride the number of bytes between the start of rows in the + * buffer. Having this be specified separate from width allows for padding at + * the end of rows, or for writing to a subportion of a larger image. + * @return a RefPtr to the newly created surface. + */ + static RefPtr create(unsigned char* data, Format format, int width, int height, int stride) throw(std::bad_alloc); + +#ifdef CAIRO_HAS_PNG_FUNCTIONS + + /** Creates a new image surface and initializes the contents to the given PNG + * file. + * + * \note For this function to be available, cairo must have been compiled + * with PNG support. + * + * @param filename name of PNG file to load + * @return a RefPtr to the new cairo_surface_t initialized with the + * contents of the PNG image file. + */ + static RefPtr create_from_png(std::string filename) throw(std::bad_alloc); + + /** Creates a new image surface from PNG data read incrementally via the + * read_func function. + * + * \note For this function to be available, cairo must have been compiled + * with PNG support. + * + * @param read_func function called to read the data of the file + * @param closure data to pass to read_func. + * @return a RefPtr to the new cairo_surface_t initialized with the + * contents of the PNG image file. + */ + static RefPtr create_from_png(cairo_read_func_t read_func, void *closure) throw(std::bad_alloc); + +#endif // CAIRO_HAS_PNG_FUNCTIONS + +}; + + +#ifdef CAIRO_HAS_XLIB_SURFACE + +/** An XlibSurface provides a way to render to the X Window System using XLib. + * If you want to draw to the screen within an application that uses the X + * Window system, you should use this Surface type. + * + * \note For this surface to be availabe, cairo must have been compiled with + * support for XLib Surfaces + */ +class XlibSurface : public Surface +{ +public: + + /** Create a C++ wrapper for the C instance. This C++ instance should then be + * given to a RefPtr. + * + * @param cobject The C instance. + * @param has_reference whether we already have a reference. Otherwise, the + * constructor will take an extra reference. + */ + explicit XlibSurface(cairo_surface_t* cobject, bool has_reference = false); + virtual ~XlibSurface(); + + /** Creates an Xlib surface that draws to the given drawable. The way that + * colors are represented in the drawable is specified by the provided + * visual. + * + * \note If drawable is a Window, then the function + * cairo_xlib_surface_set_size must be called whenever the size of the window + * changes. + * + * @param dpy an X Display + * @param drawable an X Drawable, (a Pixmap or a Window) + * @param visual the visual to use for drawing to drawable. The depth of the visual must match the depth of the drawable. Currently, only TrueColor visuals are fully supported. + * @param width the current width of drawable. + * @param height the current height of drawable. + * @return A RefPtr to the newly created surface + */ + static RefPtr create(Display *dpy, Drawable drawable, Visual *visual, int width, int height) throw(std::bad_alloc); + + /** Creates an Xlib surface that draws to the given bitmap. This will be + * drawn to as a CAIRO_FORMAT_A1 object. + * + * @param dpy an X Display + * @param bitmap an X Drawable, (a depth-1 Pixmap) + * @param screen the X Screen associated with bitmap + * @param width the current width of bitmap. + * @param height the current height of bitmap. + * @return A RefPtr to the newly created surface + */ + static RefPtr create(Display *dpy, Pixmap bitmap, Screen *screen, int width, int height) throw(std::bad_alloc); + + /** Informs cairo of the new size of the X Drawable underlying the surface. + * For a surface created for a Window (rather than a Pixmap), this function + * must be called each time the size of the window changes. (For a subwindow, + * you are normally resizing the window yourself, but for a toplevel window, + * it is necessary to listen for ConfigureNotify events.) + * + * A Pixmap can never change size, so it is never necessary to call this + * function on a surface created for a Pixmap. + * + * @param width the new width of the surface + * @param height the new height of the surface + */ + void set_size(int width, int height); + + /** Informs cairo of a new X Drawable underlying the surface. The drawable + * must match the display, screen and format of the existing drawable or the + * application will get X protocol errors and will probably terminate. No + * checks are done by this function to ensure this compatibility. + * + * @param drawable the new drawable for the surface + * @param width the width of the new drawable + * @param height the height of the new drawable + */ + void set_drawable(Drawable drawable, int width, int height); + +}; + +#endif // CAIRO_HAS_XLIB_SURFACE + + +#ifdef CAIRO_HAS_WIN32_SURFACE + +/** A Win32Surface provides a way to render within Microsoft Windows. If you + * want to draw to the screen within a Microsoft Windows application, you + * should use this Surface type. + * + * \note For this Surface to be available, cairo must have been compiled with + * Win32 support + */ +class Win32Surface : public Surface +{ +public: + + /** Create a C++ wrapper for the C instance. This C++ instance should then be + * given to a RefPtr. + * + * @param cobject The C instance. + * @param has_reference whether we already have a reference. Otherwise, the + * constructor will take an extra reference. + */ + explicit Win32Surface(cairo_surface_t* cobject, bool has_reference = false); + virtual ~Win32Surface(); + + /** Creates a Surface for drawing in Microsoft Windows + * + * @param hdc + * @return A RefPtr to the newly created surface + */ + static RefPtr create(HDC hdc) throw(std::bad_alloc); + +}; + +#endif // CAIRO_HAS_WIN32_SURFACE + + +/******************************************************************************* + * THE FOLLOWING SURFACE TYPES ARE EXPERIMENTAL AND NOT FULLY SUPPORTED + ******************************************************************************/ + +#ifdef CAIRO_HAS_PDF_SURFACE + +/** A PdfSurface provides a way to render PDF documents from cairo. This + * surface is not rendered to the screen but instead renders the drawing to a + * PDF file on disk. + * + * \note For this Surface to be available, cairo must have been compiled with + * PDF support + * + * \warning This is an experimental surface. It is not yet marked as a fully + * supported surface by the cairo library + */ +class PdfSurface : public Surface +{ +public: + + /** Create a C++ wrapper for the C instance. This C++ instance should then be + * given to a RefPtr. + * + * @param cobject The C instance. + * @param has_reference whether we already have a reference. Otherwise, the + * constructor will take an extra reference. + */ + explicit PdfSurface(cairo_surface_t* cobject, bool has_reference = false); + virtual ~PdfSurface(); + + /** Creates a PdfSurface with a specified dimensions that will be saved as + * the given filename + * + * @param filename The name of the PDF file to save the surface to + * @param width_in_points The width of the PDF document in points + * @param height_in_points The height of the PDF document in points + */ + static RefPtr create(std::string filename, double width_in_points, double height_in_points) throw(std::bad_alloc); + + /** Creates a PdfSurface with a specified dimensions that will be written to + * the given write function instead of saved directly to disk + * + * @param write_func The function to be called when the backend needs to + * write data to an output stream + * @param closure closure data for the write function + * @param width_in_points The width of the PDF document in points + * @param height_in_points The height of the PDF document in points + */ + static RefPtr create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points) throw(std::bad_alloc); + + /** Sets the resolution of the image in dots per inch + * + * @param x_dpi The dpi in the x direction + * @param y_dpi The dpi in the y direction + */ + void set_dpi(double x_dpi, double y_dpi) throw(logic_error); +}; + +#endif // CAIRO_HAS_PDF_SURFACE + + +#ifdef CAIRO_HAS_PS_SURFACE + +/** A PsSurface provides a way to render PostScript documents from cairo. This + * surface is not rendered to the screen but instead renders the drawing to a + * PostScript file on disk. + * + * \note For this Surface to be available, cairo must have been compiled with + * PostScript support + * + * \warning This is an experimental surface. It is not yet marked as a fully + * supported surface by the cairo library + */ +class PsSurface : public Surface +{ +public: + + /** Create a C++ wrapper for the C instance. This C++ instance should then be + * given to a RefPtr. + * + * @param cobject The C instance. + * @param has_reference whether we already have a reference. Otherwise, the + * constructor will take an extra reference. + */ + explicit PsSurface(cairo_surface_t* cobject, bool has_reference = false); + virtual ~PsSurface(); + + /** Creates a PsSurface with a specified dimensions that will be saved as the + * given filename + * + * @param filename The name of the PostScript file to save the surface to + * @param width_in_points The width of the PostScript document in points + * @param height_in_points The height of the PostScript document in points + */ + static RefPtr create(std::string filename, double width_in_points, double height_in_points) throw(std::bad_alloc); + + /** Creates a PsSurface with a specified dimensions that will be written to + * the given write function instead of saved directly to disk + * + * @param write_func The function to be called when the backend needs to + * write data to an output stream + * @param closure closure data for the write function + * @param width_in_points The width of the PostScript document in points + * @param height_in_points The height of the PostScript document in points + */ + static RefPtr create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points) throw(std::bad_alloc); + + /** Sets the resolution of the image in dots per inch + * + * @param x_dpi The dpi in the x direction + * @param y_dpi The dpi in the y direction + */ + void set_dpi(double x_dpi, double y_dpi) throw(logic_error); + +}; + +#endif // CAIRO_HAS_PS_SURFACE + + +#ifdef CAIRO_HAS_SVG_SURFACE + +/** A SvgSurface provides a way to render Scalable Vector Graphics (SVG) images + * from cairo. This surface is not rendered to the screen but instead renders + * the drawing to an SVG file on disk. + * + * \note For this Surface to be available, cairo must have been compiled with + * SVG support + * + * \warning This is an experimental surface. It is not yet marked as a fully + * supported surface by the cairo library + */ +class SvgSurface : public Surface +{ +public: + + /** Create a C++ wrapper for the C instance. This C++ instance should then be + * given to a RefPtr. + * + * @param cobject The C instance. + * @param has_reference whether we already have a reference. Otherwise, the + * constructor will take an extra reference. + */ + explicit SvgSurface(cairo_surface_t* cobject, bool has_reference = false); + virtual ~SvgSurface(); + + + /** Creates a SvgSurface with a specified dimensions that will be saved as the + * given filename + * + * @param filename The name of the SVG file to save the surface to + * @param width_in_points The width of the SVG document in points + * @param height_in_points The height of the SVG document in points + */ + static RefPtr create(std::string filename, double width_in_points, double height_in_points) throw(std::bad_alloc); + + /** Creates a SvgSurface with a specified dimensions that will be written to + * the given write function instead of saved directly to disk + * + * @param write_func The function to be called when the backend needs to + * write data to an output stream + * @param closure closure data for the write function + * @param width_in_points The width of the SVG document in points + * @param height_in_points The height of the SVG document in points + */ + static RefPtr create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points) throw(std::bad_alloc); + + /** Sets the resolution of the image in dots per inch + * + * @param x_dpi The dpi in the x direction + * @param y_dpi The dpi in the y direction + */ + void set_dpi(double x_dpi, double y_dpi) throw(logic_error); +}; + +#endif // CAIRO_HAS_SVG_SURFACE + + +#ifdef CAIRO_HAS_GLITZ_SURFACE + +/** A GlitzSurface provides a way to render to the X Window System using Glitz. + * This provides a way to use OpenGL-accelerated graphics from cairo. If you + * want to use hardware-accelerated graphics within the X Window system, you + * should use this Surface type. + * + * \note For this Surface to be available, cairo must have been compiled with + * Glitz support + * + * \warning This is an experimental surface. It is not yet marked as a fully + * supported surface by the cairo library + */ +class GlitzSurface : public Surface +{ + +public: + + /** Create a C++ wrapper for the C instance. This C++ instance should then be + * given to a RefPtr. + * + * @param cobject The C instance. + * @param has_reference whether we already have a reference. Otherwise, the + * constructor will take an extra reference. + */ + explicit GlitzSurface(cairo_surface_t* cobject, bool has_reference = false); + + virtual ~GlitzSurface(); + + /** Creates a new GlitzSurface + * + * @param surface a glitz surface type + */ + static RefPtr create(glitz_surface_t *surface) throw(std::bad_alloc); + +}; + +#endif // CAIRO_HAS_GLITZ_SURFACE + } // namespace Cairo #endif //__CAIROMM_SURFACE_H - Index: examples/png_file/Makefile.am =================================================================== RCS file: /cvs/cairo/cairomm/examples/png_file/Makefile.am,v retrieving revision 1.1 diff -u -r1.1 Makefile.am --- examples/png_file/Makefile.am 7 Jan 2006 11:53:02 -0000 1.1 +++ examples/png_file/Makefile.am 20 Jan 2006 23:36:54 -0000 @@ -3,3 +3,5 @@ # build the executable but don't install it noinst_PROGRAMS = example_png_file example_png_file_SOURCES = main.cc + +CLEANFILES = example_png_file.png \ No newline at end of file Index: examples/png_file/main.cc =================================================================== RCS file: /cvs/cairo/cairomm/examples/png_file/main.cc,v retrieving revision 1.1 diff -u -r1.1 main.cc --- examples/png_file/main.cc 7 Jan 2006 11:53:02 -0000 1.1 +++ examples/png_file/main.cc 20 Jan 2006 23:36:54 -0000 @@ -1,11 +1,12 @@ #include #include -#include +#include +#include int main(int argc, char** argv) { - Cairo::RefPtr surface = - Cairo::Surface::create(CAIRO_FORMAT_ARGB32, 600, 400); + Cairo::RefPtr surface = + Cairo::ImageSurface::create(CAIRO_FORMAT_ARGB32, 600, 400); Cairo::RefPtr cr = Cairo::Context::create(surface); @@ -34,7 +35,7 @@ #ifdef CAIRO_HAS_PNG_FUNCTIONS - std::string filename = "example_png_file.png"; + std::string filename = "image.png"; surface->write_to_png(filename); std::cout << "Wrote png file \"" << filename << "\"" << std::endl;