diff options
author | Murray Cumming <murrayc@murrayc.com> | 2007-04-16 08:39:59 +0000 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2007-04-16 08:39:59 +0000 |
commit | 5f4ceb5ab27a32d9bc2cb6e592bf95f8380366e6 (patch) | |
tree | 3e357a7d6ef91b7f5a55ec48e8ce8d57794362dc | |
parent | 2d59e18935e5ea28814cc522c431c0caabe3cd84 (diff) |
2007-04-16 Hugo Vincent <hugo.vincent@gmail.com>
* Added QuartzSurface for MacOS X (when cairo is built with Quartz support),
similar to the existing Win32Surface and XlibSurface. These allow use of
platform-specific features and data structures.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | cairomm/Makefile.am | 4 | ||||
-rw-r--r-- | cairomm/quartz_surface.cc | 60 | ||||
-rw-r--r-- | cairomm/quartz_surface.h | 88 | ||||
-rw-r--r-- | cairomm/surface.h | 1 |
5 files changed, 157 insertions, 2 deletions
@@ -1,3 +1,9 @@ +2007-04-16 Hugo Vincent <hugo.vincent@gmail.com> + + * Added QuartzSurface for MacOS X (when cairo is built with Quartz support), + similar to the existing Win32Surface and XlibSurface. These allow use of + platform-specific features and data structures. + 2007-03-23 Jonathon Jongsma <jjongsma@gnome.org> * Makefile.am: diff --git a/cairomm/Makefile.am b/cairomm/Makefile.am index 35be984..d4de9bd 100644 --- a/cairomm/Makefile.am +++ b/cairomm/Makefile.am @@ -2,9 +2,9 @@ SUBDIRS = INCLUDES = -I$(top_srcdir) @CAIROMM_CFLAGS@ -h_sources_public = cairomm.h context.h enums.h fontface.h fontoptions.h path.h pattern.h surface.h xlib_surface.h win32_surface.h exception.h refptr.h scaledfont.h +h_sources_public = cairomm.h context.h enums.h fontface.h fontoptions.h path.h pattern.h quartz_surface.h surface.h xlib_surface.h win32_surface.h exception.h refptr.h scaledfont.h h_sources_private = private.h -cc_sources = context.cc fontface.cc fontoptions.cc path.cc pattern.cc surface.cc xlib_surface.cc win32_surface.cc exception.cc scaledfont.cc +cc_sources = context.cc fontface.cc fontoptions.cc path.cc pattern.cc quartz_surface.cc surface.cc xlib_surface.cc win32_surface.cc exception.cc scaledfont.cc cc_sources_private = private.cc # Support for DLL on cygwin/mingw using libtool > 1.4 diff --git a/cairomm/quartz_surface.cc b/cairomm/quartz_surface.cc new file mode 100644 index 0000000..b5000c6 --- /dev/null +++ b/cairomm/quartz_surface.cc @@ -0,0 +1,60 @@ +/* Copyright (C) 2007 The cairomm Development Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include <cairomm/quartz_surface.h> +#include <cairomm/private.h> + +namespace Cairo +{ + +#ifdef CAIRO_HAS_QUARTZ_SURFACE + +QuartzSurface::QuartzSurface(cairo_surface_t* cobject, bool has_reference) : + Surface(cobject, has_reference) +{} + +QuartzSurface::~QuartzSurface() +{ + // surface is destroyed in base class +} + +CGContextRef QuartzSurface::get_cg_context() const +{ + return cairo_quartz_surface_get_cg_context(m_cobject); +} + +RefPtr<QuartzSurface> QuartzSurface::create(CGContextRef cg_context, int width, int height) +{ + cairo_surface_t* cobject = cairo_quartz_surface_create_for_cg_context(cg_context, + width, height); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr<QuartzSurface>(new QuartzSurface(cobject, true /* has reference */)); +} + +RefPtr<QuartzSurface> QuartzSurface::create(Format format, int width, int height) +{ + cairo_surface_t* cobject = cairo_quartz_surface_create((cairo_format_t)format, width, height); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr<QuartzSurface>(new QuartzSurface(cobject, true /* has reference */)); +} + +#endif // CAIRO_HAS_QUARTZ_SURFACE + +} //namespace Cairo + +// vim: ts=2 sw=2 et diff --git a/cairomm/quartz_surface.h b/cairomm/quartz_surface.h new file mode 100644 index 0000000..246a45a --- /dev/null +++ b/cairomm/quartz_surface.h @@ -0,0 +1,88 @@ +/* Copyright (C) 2007 The cairomm Development Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __CAIROMM_QUARTZ_SURFACE_H +#define __CAIROMM_QUARTZ_SURFACE_H + +#include <cairomm/surface.h> + +#ifdef CAIRO_HAS_QUARTZ_SURFACE +#include <cairo-quartz.h> +#endif + +namespace Cairo +{ + +#ifdef CAIRO_HAS_QUARTZ_SURFACE + +/** A QuartzSurface provides a way to render within Apple Mac OS X. If you + * want to draw to the screen within a Mac OS X application, you + * should use this Surface type. + * + * @note For this Surface to be available, cairo must have been compiled with + * (native) Quartz support (requires Cairo > 1.4.0) + */ +class QuartzSurface : 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 QuartzSurface(cairo_surface_t* cobject, bool has_reference = false); + virtual ~QuartzSurface(); + + /** Returns the CGContextRef associated with this surface, or NULL if none. Also + * returns NULL if the surface is not a Quartz surface. + * + * @return CGContextRef or NULL if no CGContextRef available. + */ + CGContextRef get_cg_context() const; + + /** Creates a cairo surface that targets the given CGContext. + * + * @param cg_context the CGContext to create a surface for + * @return the newly created surface + */ + static RefPtr<QuartzSurface> create(CGContextRef cg_context, int width, int height); + + /** Creates a device-independent-bitmap surface not associated with any + * particular existing surface or device context. The created bitmap will be + * unititialized. + * + * @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 the newly created surface + */ + static RefPtr<QuartzSurface> create(Format format, int width, int height); + +}; + +#endif // CAIRO_HAS_QUARTZ_SURFACE + + +} // namespace Cairo + +#endif //__CAIROMM_QUARTZ_SURFACE_H + +// vim: ts=2 sw=2 et diff --git a/cairomm/surface.h b/cairomm/surface.h index 001f754..15f0f9b 100644 --- a/cairomm/surface.h +++ b/cairomm/surface.h @@ -28,6 +28,7 @@ //See xlib_surface.h for XlibSurface. //See win32_surface.h for Win32Surface. +//See quartz_surface.h for QuartzSurface (Mac OS X). #ifdef CAIRO_HAS_PDF_SURFACE #include <cairo-pdf.h> |