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 
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 
00042 // Experimental surfaces
00043 #ifdef CAIRO_HAS_GLITZ_SURFACE
00044 #include <cairo-glitz.h>
00045 #endif // CAIRO_HAS_GLITZ_SURFACE
00046 
00047 
00048 namespace Cairo
00049 {
00050 
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 
00142   void get_device_offset(double& x_offset, double& y_offset) const;
00143 
00149   void set_fallback_resolution(double x_pixels_per_inch, double y_pixels_per_inch);
00150 
00151   SurfaceType get_type() const;
00152 
00153 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00154 
00162   void write_to_png(const std::string& filename);
00163 
00173   void write_to_png(cairo_write_func_t write_func, void *closure); //TODO: Use a sigc::slot?
00174 
00175 #endif // CAIRO_HAS_PNG_FUNCTIONS
00176 
00177 
00180   typedef cairo_surface_t cobject;
00183   inline cobject* cobj() { return m_cobject; }
00186   inline const cobject* cobj() const { return m_cobject; }
00187 
00188   #ifndef DOXYGEN_IGNORE_THIS
00190   inline ErrorStatus get_status() const
00191   { return cairo_surface_status(const_cast<cairo_surface_t*>(cobj())); }
00192 
00193   void reference() const;
00194   void unreference() const;
00195   #endif //DOXYGEN_IGNORE_THIS
00196 
00207   static RefPtr<Surface> create(const RefPtr<Surface> other, Content content, int width, int height);
00208 
00209 protected:
00212   cobject* m_cobject;
00213 };
00214 
00215 
00232 class ImageSurface : public Surface
00233 {
00234 protected:
00235   //TODO?: Surface(cairo_surface_t *target);
00236 
00237 public:
00238 
00245   explicit ImageSurface(cairo_surface_t* cobject, bool has_reference = false);
00246 
00247   virtual ~ImageSurface();
00248 
00251   int get_width() const;
00252 
00255   int get_height() const;
00256 
00264   unsigned char* get_data();
00265   const unsigned char* get_data() const;
00266 
00269   Format get_format() const;
00270 
00277   int get_stride() const;
00278 
00279 
00296   static RefPtr<ImageSurface> create(Format format, int width, int height);
00297 
00320   static RefPtr<ImageSurface> create(unsigned char* data, Format format, int width, int height, int stride);
00321 
00322 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00323 
00334   static RefPtr<ImageSurface> create_from_png(std::string filename);
00335 
00347   static RefPtr<ImageSurface> create_from_png(cairo_read_func_t read_func, void *closure);
00348 
00349 #endif // CAIRO_HAS_PNG_FUNCTIONS
00350 
00351 };
00352 
00353 
00354 #ifdef CAIRO_HAS_PDF_SURFACE
00355 
00363 class PdfSurface : public Surface
00364 {
00365 public:
00366 
00374   explicit PdfSurface(cairo_surface_t* cobject, bool has_reference = false);
00375   virtual ~PdfSurface();
00376 
00384   static RefPtr<PdfSurface> create(std::string filename, double width_in_points, double height_in_points);
00385 
00395   static RefPtr<PdfSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00396 
00408   void set_size(double width_in_points, double height_in_points);
00409 
00410 };
00411 
00412 #endif  // CAIRO_HAS_PDF_SURFACE
00413 
00414 
00415 #ifdef CAIRO_HAS_PS_SURFACE
00416 
00424 class PsSurface : public Surface
00425 {
00426 public:
00427 
00435   explicit PsSurface(cairo_surface_t* cobject, bool has_reference = false);
00436   virtual ~PsSurface();
00437 
00445   static RefPtr<PsSurface> create(std::string filename, double width_in_points, double height_in_points);
00446 
00456   static RefPtr<PsSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00457 
00470   void set_size(double width_in_points, double height_in_points);
00471 
00477   void dsc_comment(std::string comment);
00478 
00487   void dsc_begin_setup();
00488 
00496   void dsc_begin_page_setup();
00497 
00498 };
00499 
00500 #endif // CAIRO_HAS_PS_SURFACE
00501 
00502 
00503 #ifdef CAIRO_HAS_SVG_SURFACE
00504 
00505 typedef enum
00506 {
00507   SVG_VERSION_1_1 = CAIRO_SVG_VERSION_1_1,
00508   SVG_VERSION_1_2 = CAIRO_SVG_VERSION_1_2
00509 } SvgVersion;
00510 
00518 class SvgSurface : public Surface
00519 {
00520 public:
00521 
00529   explicit SvgSurface(cairo_surface_t* cobject, bool has_reference = false);
00530   virtual ~SvgSurface();
00531 
00532 
00540   static RefPtr<SvgSurface> create(std::string filename, double width_in_points, double height_in_points);
00541 
00551   static RefPtr<SvgSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00552 
00563   void restrict_to_version(SvgVersion version);
00564 
00570   static const std::vector<SvgVersion> get_versions();
00571 
00578   static std::string version_to_string(SvgVersion version);
00579 };
00580 
00581 #endif // CAIRO_HAS_SVG_SURFACE
00582 
00583 
00584 /*******************************************************************************
00585  * THE FOLLOWING SURFACE TYPES ARE EXPERIMENTAL AND NOT FULLY SUPPORTED
00586  ******************************************************************************/
00587 
00588 #ifdef CAIRO_HAS_GLITZ_SURFACE
00589 
00601 class GlitzSurface : public Surface
00602 {
00603 
00604 public:
00605 
00613   explicit GlitzSurface(cairo_surface_t* cobject, bool has_reference = false);
00614 
00615   virtual ~GlitzSurface();
00616 
00621   static RefPtr<GlitzSurface> create(glitz_surface_t *surface);
00622 
00623 };
00624 
00625 #endif // CAIRO_HAS_GLITZ_SURFACE
00626 
00627 } // namespace Cairo
00628 
00629 #endif //__CAIROMM_SURFACE_H
00630 
00631 // vim: ts=2 sw=2 et

Generated on Tue Aug 22 02:53:35 2006 for cairomm by  doxygen 1.4.7