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 Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00016  * 02110-1301, USA.
00017  */
00018 
00019 #ifndef __CAIROMM_SURFACE_H
00020 #define __CAIROMM_SURFACE_H
00021 
00022 #include <string>
00023 #include <cairomm/enums.h>
00024 #include <cairomm/exception.h>
00025 #include <cairomm/fontoptions.h>
00026 #include <cairomm/refptr.h>
00027 
00028 //See xlib_surface.h for XlibSurface.
00029 //See win32_surface.h for Win32Surface.
00030 
00031 // Experimental surfaces
00032 #ifdef CAIRO_HAS_PDF_SURFACE
00033 #include <cairo-pdf.h>
00034 #endif // CAIRO_HAS_PDF_SURFACE
00035 #ifdef CAIRO_HAS_PS_SURFACE
00036 #include <cairo-ps.h>
00037 #endif // CAIRO_HAS_PS_SURFACE
00038 #ifdef CAIRO_HAS_SVG_SURFACE
00039 #include <cairo-svg.h>
00040 #endif // CAIRO_HAS_SVG_SURFACE
00041 #ifdef CAIRO_HAS_GLITZ_SURFACE
00042 #include <cairo-glitz.h>
00043 #endif // CAIRO_HAS_GLITZ_SURFACE
00044 
00045 
00046 namespace Cairo
00047 {
00048 
00058 class Surface
00059 {
00060 public:
00068   explicit Surface(cairo_surface_t* cobject, bool has_reference = false);
00069 
00070   virtual ~Surface();
00071 
00080   void get_font_options(FontOptions& options) const;
00081 
00093   void finish();
00094 
00101   void flush();
00102 
00113   void mark_dirty();
00114 
00122   void mark_dirty(int x, int y, int width, int height);
00123 
00138   void set_device_offset(double x_offset, double y_offset);
00139 
00140 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00141 
00149   void write_to_png(const std::string& filename);
00150 
00160   void write_to_png(cairo_write_func_t write_func, void *closure); //TODO: Use a sigc::slot?
00161 
00162 #endif // CAIRO_HAS_PNG_FUNCTIONS
00163 
00164 
00167   typedef cairo_surface_t cobject;
00170   inline cobject* cobj() { return m_cobject; }
00173   inline const cobject* cobj() const { return m_cobject; }
00174 
00175   #ifndef DOXYGEN_IGNORE_THIS
00176 
00177   inline ErrorStatus get_status() const
00178   { return cairo_surface_status(const_cast<cairo_surface_t*>(cobj())); }
00179 
00180   void reference() const;
00181   void unreference() const;
00182   #endif //DOXYGEN_IGNORE_THIS
00183 
00194   static RefPtr<Surface> create(const RefPtr<Surface> other, Content content, int width, int height);
00195 
00196 protected:
00199   cobject* m_cobject;
00200 };
00201 
00202 
00221 class ImageSurface : public Surface
00222 {
00223 protected:
00224   //TODO?: Surface(cairo_surface_t *target);
00225 
00226 public:
00227 
00234   explicit ImageSurface(cairo_surface_t* cobject, bool has_reference = false);
00235 
00236   virtual ~ImageSurface();
00237 
00240   int get_width() const;
00241 
00244   int get_height() const;
00245 
00262   static RefPtr<ImageSurface> create(Format format, int width, int height);
00263 
00286   static RefPtr<ImageSurface> create(unsigned char* data, Format format, int width, int height, int stride);
00287 
00288 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00289 
00300   static RefPtr<ImageSurface> create_from_png(std::string filename);
00301 
00313   static RefPtr<ImageSurface> create_from_png(cairo_read_func_t read_func, void *closure);
00314 
00315 #endif // CAIRO_HAS_PNG_FUNCTIONS
00316 
00317 };
00318 
00319 
00320 /*******************************************************************************
00321  * THE FOLLOWING SURFACE TYPES ARE EXPERIMENTAL AND NOT FULLY SUPPORTED
00322  ******************************************************************************/
00323 
00324 #ifdef CAIRO_HAS_PDF_SURFACE
00325 
00336 class PdfSurface : public Surface
00337 {
00338 public:
00339 
00347   explicit PdfSurface(cairo_surface_t* cobject, bool has_reference = false);
00348   virtual ~PdfSurface();
00349 
00357   static RefPtr<PdfSurface> create(std::string filename, double width_in_points, double height_in_points);
00358 
00368   static RefPtr<PdfSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00369 
00375   void set_dpi(double x_dpi, double y_dpi);
00376 };
00377 
00378 #endif  // CAIRO_HAS_PDF_SURFACE
00379 
00380 
00381 #ifdef CAIRO_HAS_PS_SURFACE
00382 
00393 class PsSurface : public Surface
00394 {
00395 public:
00396 
00404   explicit PsSurface(cairo_surface_t* cobject, bool has_reference = false);
00405   virtual ~PsSurface();
00406 
00414   static RefPtr<PsSurface> create(std::string filename, double width_in_points, double height_in_points);
00415 
00425   static RefPtr<PsSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00426 
00432   void set_dpi(double x_dpi, double y_dpi);
00433 
00434 };
00435 
00436 #endif // CAIRO_HAS_PS_SURFACE
00437 
00438 
00439 #ifdef CAIRO_HAS_SVG_SURFACE
00440 
00451 class SvgSurface : public Surface
00452 {
00453 public:
00454 
00462   explicit SvgSurface(cairo_surface_t* cobject, bool has_reference = false);
00463   virtual ~SvgSurface();
00464 
00465 
00473   static RefPtr<SvgSurface> create(std::string filename, double width_in_points, double height_in_points);
00474 
00484   static RefPtr<SvgSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00485 
00491   void set_dpi(double x_dpi, double y_dpi);
00492 };
00493 
00494 #endif // CAIRO_HAS_SVG_SURFACE
00495 
00496 
00497 #ifdef CAIRO_HAS_GLITZ_SURFACE
00498 
00510 class GlitzSurface : public Surface
00511 {
00512 
00513 public:
00514 
00522   explicit GlitzSurface(cairo_surface_t* cobject, bool has_reference = false);
00523 
00524   virtual ~GlitzSurface();
00525 
00530   static RefPtr<GlitzSurface> create(glitz_surface_t *surface);
00531 
00532 };
00533 
00534 #endif // CAIRO_HAS_GLITZ_SURFACE
00535 
00536 } // namespace Cairo
00537 
00538 #endif //__CAIROMM_SURFACE_H
00539 
00540 // vim: ts=2 sw=2 et

Generated on Tue Apr 4 20:48:32 2006 for cairomm by  doxygen 1.4.4