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 <vector>
00024 #include <cairomm/enums.h>
00025 #include <cairomm/exception.h>
00026 #include <cairomm/fontoptions.h>
00027 #include <cairomm/refptr.h>
00028 
00029 //See xlib_surface.h for XlibSurface.
00030 //See win32_surface.h for Win32Surface.
00031 //See quartz_surface.h for QuartzSurface (Mac OS X).
00032 
00033 #ifdef CAIRO_HAS_PDF_SURFACE
00034 #include <cairo-pdf.h>
00035 #endif // CAIRO_HAS_PDF_SURFACE
00036 #ifdef CAIRO_HAS_PS_SURFACE
00037 #include <cairo-ps.h>
00038 #endif // CAIRO_HAS_PS_SURFACE
00039 #ifdef CAIRO_HAS_SVG_SURFACE
00040 #include <cairo-svg.h>
00041 #endif // CAIRO_HAS_SVG_SURFACE
00042 
00043 // Experimental surfaces
00044 #ifdef CAIRO_HAS_GLITZ_SURFACE
00045 #include <cairo-glitz.h>
00046 #endif // CAIRO_HAS_GLITZ_SURFACE
00047 
00048 
00049 namespace Cairo
00050 {
00051 
00059 class Surface
00060 {
00061 public:
00069   explicit Surface(cairo_surface_t* cobject, bool has_reference = false);
00070 
00071   virtual ~Surface();
00072 
00081   void get_font_options(FontOptions& options) const;
00082 
00094   void finish();
00095 
00102   void flush();
00103 
00114   void mark_dirty();
00115 
00123   void mark_dirty(int x, int y, int width, int height);
00124 
00139   void set_device_offset(double x_offset, double y_offset);
00140 
00143   void get_device_offset(double& x_offset, double& y_offset) const;
00144 
00150   void set_fallback_resolution(double x_pixels_per_inch, double y_pixels_per_inch);
00151 
00152   SurfaceType get_type() const;
00153 
00154 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00155 
00163   void write_to_png(const std::string& filename);
00164 
00174   void write_to_png(cairo_write_func_t write_func, void *closure); //TODO: Use a sigc::slot?
00175 
00176 #endif // CAIRO_HAS_PNG_FUNCTIONS
00177 
00178 
00181   typedef cairo_surface_t cobject;
00184   inline cobject* cobj() { return m_cobject; }
00187   inline const cobject* cobj() const { return m_cobject; }
00188 
00189   #ifndef DOXYGEN_IGNORE_THIS
00191   inline ErrorStatus get_status() const
00192   { return cairo_surface_status(const_cast<cairo_surface_t*>(cobj())); }
00193 
00194   void reference() const;
00195   void unreference() const;
00196   #endif //DOXYGEN_IGNORE_THIS
00197 
00208   static RefPtr<Surface> create(const RefPtr<Surface> other, Content content, int width, int height);
00209 
00210 protected:
00213   cobject* m_cobject;
00214 };
00215 
00216 
00233 class ImageSurface : public Surface
00234 {
00235 protected:
00236   //TODO?: Surface(cairo_surface_t *target);
00237 
00238 public:
00239 
00246   explicit ImageSurface(cairo_surface_t* cobject, bool has_reference = false);
00247 
00248   virtual ~ImageSurface();
00249 
00252   int get_width() const;
00253 
00256   int get_height() const;
00257 
00265   unsigned char* get_data();
00266   const unsigned char* get_data() const;
00267 
00270   Format get_format() const;
00271 
00278   int get_stride() const;
00279 
00280 
00297   static RefPtr<ImageSurface> create(Format format, int width, int height);
00298 
00321   static RefPtr<ImageSurface> create(unsigned char* data, Format format, int width, int height, int stride);
00322 
00323 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00324 
00335   static RefPtr<ImageSurface> create_from_png(std::string filename);
00336 
00348   static RefPtr<ImageSurface> create_from_png(cairo_read_func_t read_func, void *closure);
00349 
00350 #endif // CAIRO_HAS_PNG_FUNCTIONS
00351 
00352 };
00353 
00354 
00355 #ifdef CAIRO_HAS_PDF_SURFACE
00356 
00364 class PdfSurface : public Surface
00365 {
00366 public:
00367 
00375   explicit PdfSurface(cairo_surface_t* cobject, bool has_reference = false);
00376   virtual ~PdfSurface();
00377 
00385   static RefPtr<PdfSurface> create(std::string filename, double width_in_points, double height_in_points);
00386 
00396   static RefPtr<PdfSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00397 
00409   void set_size(double width_in_points, double height_in_points);
00410 
00411 };
00412 
00413 #endif  // CAIRO_HAS_PDF_SURFACE
00414 
00415 
00416 #ifdef CAIRO_HAS_PS_SURFACE
00417 
00425 class PsSurface : public Surface
00426 {
00427 public:
00428 
00436   explicit PsSurface(cairo_surface_t* cobject, bool has_reference = false);
00437   virtual ~PsSurface();
00438 
00446   static RefPtr<PsSurface> create(std::string filename, double width_in_points, double height_in_points);
00447 
00457   static RefPtr<PsSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00458 
00471   void set_size(double width_in_points, double height_in_points);
00472 
00478   void dsc_comment(std::string comment);
00479 
00488   void dsc_begin_setup();
00489 
00497   void dsc_begin_page_setup();
00498 
00499 };
00500 
00501 #endif // CAIRO_HAS_PS_SURFACE
00502 
00503 
00504 #ifdef CAIRO_HAS_SVG_SURFACE
00505 
00506 typedef enum
00507 {
00508   SVG_VERSION_1_1 = CAIRO_SVG_VERSION_1_1,
00509   SVG_VERSION_1_2 = CAIRO_SVG_VERSION_1_2
00510 } SvgVersion;
00511 
00519 class SvgSurface : public Surface
00520 {
00521 public:
00522 
00530   explicit SvgSurface(cairo_surface_t* cobject, bool has_reference = false);
00531   virtual ~SvgSurface();
00532 
00533 
00541   static RefPtr<SvgSurface> create(std::string filename, double width_in_points, double height_in_points);
00542 
00552   static RefPtr<SvgSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00553 
00564   void restrict_to_version(SvgVersion version);
00565 
00571   static const std::vector<SvgVersion> get_versions();
00572 
00579   static std::string version_to_string(SvgVersion version);
00580 };
00581 
00582 #endif // CAIRO_HAS_SVG_SURFACE
00583 
00584 
00585 /*******************************************************************************
00586  * THE FOLLOWING SURFACE TYPES ARE EXPERIMENTAL AND NOT FULLY SUPPORTED
00587  ******************************************************************************/
00588 
00589 #ifdef CAIRO_HAS_GLITZ_SURFACE
00590 
00602 class GlitzSurface : public Surface
00603 {
00604 
00605 public:
00606 
00614   explicit GlitzSurface(cairo_surface_t* cobject, bool has_reference = false);
00615 
00616   virtual ~GlitzSurface();
00617 
00622   static RefPtr<GlitzSurface> create(glitz_surface_t *surface);
00623 
00624 };
00625 
00626 #endif // CAIRO_HAS_GLITZ_SURFACE
00627 
00628 } // namespace Cairo
00629 
00630 #endif //__CAIROMM_SURFACE_H
00631 
00632 // vim: ts=2 sw=2 et

Generated on Tue May 27 16:14:03 2008 for cairomm by  doxygen 1.5.1