Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

surface.h

Go to the documentation of this file.
00001 /* Copyright (C) 2005 The cairomm Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Library General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2 of the License, or (at your option) any later version.
00007  *
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Library General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Library General Public
00014  * License along with this library; if not, write to the Free
00015  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018 #ifndef __CAIROMM_SURFACE_H
00019 #define __CAIROMM_SURFACE_H
00020 
00021 #include <string>
00022 #include <cairomm/enums.h>
00023 #include <cairomm/exception.h>
00024 #include <cairomm/fontoptions.h>
00025 #include <cairomm/refptr.h>
00026 
00027 //See xlib_surface.h for XlibSurface.
00028 //See win32_surface.h for Win32Surface.
00029 
00030 // Experimental surfaces
00031 #ifdef CAIRO_HAS_PDF_SURFACE
00032 #include <cairo-pdf.h>
00033 #endif // CAIRO_HAS_PDF_SURFACE
00034 #ifdef CAIRO_HAS_PS_SURFACE
00035 #include <cairo-ps.h>
00036 #endif // CAIRO_HAS_PS_SURFACE
00037 #ifdef CAIRO_HAS_SVG_SURFACE
00038 #include <cairo-svg.h>
00039 #endif // CAIRO_HAS_SVG_SURFACE
00040 #ifdef CAIRO_HAS_GLITZ_SURFACE
00041 #include <cairo-glitz.h>
00042 #endif // CAIRO_HAS_GLITZ_SURFACE
00043 
00044 
00045 namespace Cairo
00046 {
00047 
00048 typedef cairo_content_t Content;
00049 typedef cairo_format_t Format;
00050 
00060 class Surface
00061 {
00062 public:
00070   explicit Surface(cairo_surface_t* cobject, bool has_reference = false);
00071 
00072   virtual ~Surface();
00073 
00082   void get_font_options(FontOptions& options) const;
00083 
00095   void finish();
00096 
00103   void flush();
00104 
00115   void mark_dirty();
00116 
00124   void mark_dirty(int x, int y, int width, int height);
00125 
00140   void set_device_offset(double x_offset, double y_offset);
00141 
00142 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00143 
00151   void write_to_png(const std::string& filename);
00152 
00162   void write_to_png(cairo_write_func_t write_func, void *closure); //TODO: Use a sigc::slot?
00163 
00164 #endif // CAIRO_HAS_PNG_FUNCTIONS
00165 
00166 
00169   typedef cairo_surface_t cobject;
00172   inline cobject* cobj() { return m_cobject; }
00175   inline const cobject* cobj() const { return m_cobject; }
00176 
00177   #ifndef DOXYGEN_IGNORE_THIS
00178 
00179   inline ErrorStatus get_status() const
00180   { return cairo_surface_status(const_cast<cairo_surface_t*>(cobj())); }
00181 
00182   void reference() const;
00183   void unreference() const;
00184   #endif //DOXYGEN_IGNORE_THIS
00185 
00196   static RefPtr<Surface> create(const RefPtr<Surface> other, Content content, int width, int height);
00197 
00198 protected:
00201   cobject* m_cobject;
00202 };
00203 
00204 
00223 class ImageSurface : public Surface
00224 {
00225 protected:
00226   //TODO?: Surface(cairo_surface_t *target);
00227 
00228 public:
00229 
00236   explicit ImageSurface(cairo_surface_t* cobject, bool has_reference = false);
00237 
00238   virtual ~ImageSurface();
00239 
00242   int get_width() const;
00243 
00246   int get_height() const;
00247 
00264   static RefPtr<ImageSurface> create(Format format, int width, int height);
00265 
00288   static RefPtr<ImageSurface> create(unsigned char* data, Format format, int width, int height, int stride);
00289 
00290 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00291 
00302   static RefPtr<ImageSurface> create_from_png(std::string filename);
00303 
00315   static RefPtr<ImageSurface> create_from_png(cairo_read_func_t read_func, void *closure);
00316 
00317 #endif // CAIRO_HAS_PNG_FUNCTIONS
00318 
00319 };
00320 
00321 
00322 /*******************************************************************************
00323  * THE FOLLOWING SURFACE TYPES ARE EXPERIMENTAL AND NOT FULLY SUPPORTED
00324  ******************************************************************************/
00325 
00326 #ifdef CAIRO_HAS_PDF_SURFACE
00327 
00338 class PdfSurface : public Surface
00339 {
00340 public:
00341 
00349   explicit PdfSurface(cairo_surface_t* cobject, bool has_reference = false);
00350   virtual ~PdfSurface();
00351 
00359   static RefPtr<PdfSurface> create(std::string filename, double width_in_points, double height_in_points);
00360 
00370   static RefPtr<PdfSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00371 
00377   void set_dpi(double x_dpi, double y_dpi);
00378 };
00379 
00380 #endif  // CAIRO_HAS_PDF_SURFACE
00381 
00382 
00383 #ifdef CAIRO_HAS_PS_SURFACE
00384 
00395 class PsSurface : public Surface
00396 {
00397 public:
00398 
00406   explicit PsSurface(cairo_surface_t* cobject, bool has_reference = false);
00407   virtual ~PsSurface();
00408 
00416   static RefPtr<PsSurface> create(std::string filename, double width_in_points, double height_in_points);
00417 
00427   static RefPtr<PsSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00428 
00434   void set_dpi(double x_dpi, double y_dpi);
00435 
00436 };
00437 
00438 #endif // CAIRO_HAS_PS_SURFACE
00439 
00440 
00441 #ifdef CAIRO_HAS_SVG_SURFACE
00442 
00453 class SvgSurface : public Surface
00454 {
00455 public:
00456 
00464   explicit SvgSurface(cairo_surface_t* cobject, bool has_reference = false);
00465   virtual ~SvgSurface();
00466 
00467 
00475   static RefPtr<SvgSurface> create(std::string filename, double width_in_points, double height_in_points);
00476 
00486   static RefPtr<SvgSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00487 
00493   void set_dpi(double x_dpi, double y_dpi);
00494 };
00495 
00496 #endif // CAIRO_HAS_SVG_SURFACE
00497 
00498 
00499 #ifdef CAIRO_HAS_GLITZ_SURFACE
00500 
00512 class GlitzSurface : public Surface
00513 {
00514 
00515 public:
00516 
00524   explicit GlitzSurface(cairo_surface_t* cobject, bool has_reference = false);
00525 
00526   virtual ~GlitzSurface();
00527 
00532   static RefPtr<GlitzSurface> create(glitz_surface_t *surface);
00533 
00534 };
00535 
00536 #endif // CAIRO_HAS_GLITZ_SURFACE
00537 
00538 } // namespace Cairo
00539 
00540 #endif //__CAIROMM_SURFACE_H

Generated on Thu Feb 9 12:47:13 2006 for cairomm by  doxygen 1.4.4