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 
00025 /* following is required for OS X */
00026 
00027 #ifdef nil
00028 #undef nil
00029 #endif
00030 
00031 /* end OS X */
00032 
00033 #include <sigc++/slot.h>
00034 #include <cairomm/enums.h>
00035 #include <cairomm/exception.h>
00036 #include <cairomm/fontoptions.h>
00037 #include <cairomm/refptr.h>
00038 
00039 //See xlib_surface.h for XlibSurface.
00040 //See win32_surface.h for Win32Surface.
00041 //See quartz_surface.h for QuartzSurface (Mac OS X).
00042 
00043 #ifdef CAIRO_HAS_PDF_SURFACE
00044 #include <cairo-pdf.h>
00045 #endif // CAIRO_HAS_PDF_SURFACE
00046 #ifdef CAIRO_HAS_PS_SURFACE
00047 #include <cairo-ps.h>
00048 #endif // CAIRO_HAS_PS_SURFACE
00049 #ifdef CAIRO_HAS_SVG_SURFACE
00050 #include <cairo-svg.h>
00051 #endif // CAIRO_HAS_SVG_SURFACE
00052 
00053 // Experimental surfaces
00054 #ifdef CAIRO_HAS_GLITZ_SURFACE
00055 #include <cairo-glitz.h>
00056 #endif // CAIRO_HAS_GLITZ_SURFACE
00057 
00058 
00059 namespace Cairo
00060 {
00061 
00069 class Surface
00070 {
00071 public:
00086   typedef sigc::slot<ErrorStatus, const unsigned char* /*data*/, unsigned int /*length*/> SlotWriteFunc;
00098   typedef sigc::slot<ErrorStatus, unsigned char* /*data*/, unsigned int /*length*/> SlotReadFunc;
00099 
00107   explicit Surface(cairo_surface_t* cobject, bool has_reference = false);
00108 
00109   virtual ~Surface();
00110 
00119   void get_font_options(FontOptions& options) const;
00120 
00132   void finish();
00133 
00140   void flush();
00141 
00152   void mark_dirty();
00153 
00161   void mark_dirty(int x, int y, int width, int height);
00162 
00177   void set_device_offset(double x_offset, double y_offset);
00178 
00181   void get_device_offset(double& x_offset, double& y_offset) const;
00182 
00188   void set_fallback_resolution(double x_pixels_per_inch, double y_pixels_per_inch);
00189 
00198   void get_fallback_resolution(double& x_pixels_per_inch, double& y_pixels_per_inch) const;
00199 
00200   SurfaceType get_type() const;
00201 
00207   Content get_content() const;
00208 
00217   void copy_page();
00218 
00225   void show_page();
00226 
00239   bool has_show_text_glyphs() const;
00240 
00241 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00242 
00250   void write_to_png(const std::string& filename);
00251 
00262   void write_to_png_stream(const SlotWriteFunc& write_func);
00263 
00265   void write_to_png(cairo_write_func_t write_func, void *closure);
00266 
00267 #endif // CAIRO_HAS_PNG_FUNCTIONS
00268 
00269 
00272   typedef cairo_surface_t cobject;
00275   inline cobject* cobj() { return m_cobject; }
00278   inline const cobject* cobj() const { return m_cobject; }
00279 
00280   #ifndef DOXYGEN_IGNORE_THIS
00282   inline ErrorStatus get_status() const
00283   { return cairo_surface_status(const_cast<cairo_surface_t*>(cobj())); }
00284 
00285   void reference() const;
00286   void unreference() const;
00287   #endif //DOXYGEN_IGNORE_THIS
00288 
00299   static RefPtr<Surface> create(const RefPtr<Surface> other, Content content, int width, int height);
00300 
00301 protected:
00304   cobject* m_cobject;
00305 };
00306 
00327 class ImageSurface : public Surface
00328 {
00329 protected:
00330   //TODO?: Surface(cairo_surface_t *target);
00331 
00332 public:
00333 
00340   explicit ImageSurface(cairo_surface_t* cobject, bool has_reference = false);
00341 
00342   virtual ~ImageSurface();
00343 
00346   int get_width() const;
00347 
00350   int get_height() const;
00351 
00359   unsigned char* get_data();
00360   const unsigned char* get_data() const;
00361 
00364   Format get_format() const;
00365 
00372   int get_stride() const;
00373 
00396   static int format_stride_for_width (Cairo::Format format, int width);
00397 
00414   static RefPtr<ImageSurface> create(Format format, int width, int height);
00415 
00438   static RefPtr<ImageSurface> create(unsigned char* data, Format format, int width, int height, int stride);
00439 
00440 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00441 
00452   static RefPtr<ImageSurface> create_from_png(std::string filename);
00453 
00464   static RefPtr<ImageSurface> create_from_png_stream(const SlotReadFunc& read_func);
00466   static RefPtr<ImageSurface> create_from_png(cairo_read_func_t read_func, void *closure);
00467 
00468 #endif // CAIRO_HAS_PNG_FUNCTIONS
00469 
00470 };
00471 
00472 
00473 #ifdef CAIRO_HAS_PDF_SURFACE
00474 
00486 class PdfSurface : public Surface
00487 {
00488 public:
00489 
00497   explicit PdfSurface(cairo_surface_t* cobject, bool has_reference = false);
00498   virtual ~PdfSurface();
00499 
00507   static RefPtr<PdfSurface> create(std::string filename, double width_in_points, double height_in_points);
00508 
00519   static RefPtr<PdfSurface> create_for_stream(const SlotWriteFunc& write_func, double width_in_points, double height_in_points);
00521   static RefPtr<PdfSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00522 
00534   void set_size(double width_in_points, double height_in_points);
00535 
00536 };
00537 
00538 #endif  // CAIRO_HAS_PDF_SURFACE
00539 
00540 
00541 #ifdef CAIRO_HAS_PS_SURFACE
00542 
00551 typedef enum {
00552     PS_LEVEL_2 = CAIRO_PS_LEVEL_2,
00553     PS_LEVEL_3 = CAIRO_PS_LEVEL_3
00554 } PsLevel;
00555 
00563 class PsSurface : public Surface
00564 {
00565 public:
00566 
00574   explicit PsSurface(cairo_surface_t* cobject, bool has_reference = false);
00575   virtual ~PsSurface();
00576 
00584   static RefPtr<PsSurface> create(std::string filename, double width_in_points, double height_in_points);
00585 
00596   static RefPtr<PsSurface> create_for_stream(const SlotWriteFunc& write_func, double width_in_points, double height_in_points);
00598   static RefPtr<PsSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00599 
00612   void set_size(double width_in_points, double height_in_points);
00613 
00619   void dsc_comment(std::string comment);
00620 
00629   void dsc_begin_setup();
00630 
00638   void dsc_begin_page_setup();
00639 
00652   void set_eps(bool eps);
00653 
00658   bool get_eps() const;
00659 
00672   void restrict_to_level(PsLevel level);
00673 
00680   static const std::vector<PsLevel> get_levels();
00681 
00693   static std::string level_to_string(PsLevel level);
00694 };
00695 
00696 #endif // CAIRO_HAS_PS_SURFACE
00697 
00698 
00699 #ifdef CAIRO_HAS_SVG_SURFACE
00700 
00705 typedef enum
00706 {
00707   SVG_VERSION_1_1 = CAIRO_SVG_VERSION_1_1,
00708   SVG_VERSION_1_2 = CAIRO_SVG_VERSION_1_2
00709 } SvgVersion;
00710 
00718 class SvgSurface : public Surface
00719 {
00720 public:
00721 
00729   explicit SvgSurface(cairo_surface_t* cobject, bool has_reference = false);
00730   virtual ~SvgSurface();
00731 
00732 
00740   static RefPtr<SvgSurface> create(std::string filename, double width_in_points, double height_in_points);
00741 
00752   static RefPtr<SvgSurface> create_for_stream(const SlotWriteFunc& write_func, double width_in_points, double height_in_points);
00753 
00755   static RefPtr<SvgSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00756 
00767   void restrict_to_version(SvgVersion version);
00768 
00774   static const std::vector<SvgVersion> get_versions();
00775 
00782   static std::string version_to_string(SvgVersion version);
00783 };
00784 
00785 #endif // CAIRO_HAS_SVG_SURFACE
00786 
00787 
00788 /*******************************************************************************
00789  * THE FOLLOWING SURFACE TYPES ARE EXPERIMENTAL AND NOT FULLY SUPPORTED
00790  ******************************************************************************/
00791 
00792 #ifdef CAIRO_HAS_GLITZ_SURFACE
00793 
00805 class GlitzSurface : public Surface
00806 {
00807 
00808 public:
00809 
00817   explicit GlitzSurface(cairo_surface_t* cobject, bool has_reference = false);
00818 
00819   virtual ~GlitzSurface();
00820 
00825   static RefPtr<GlitzSurface> create(glitz_surface_t *surface);
00826 
00827 };
00828 
00829 #endif // CAIRO_HAS_GLITZ_SURFACE
00830 
00831 } // namespace Cairo
00832 
00833 #endif //__CAIROMM_SURFACE_H
00834 
00835 // vim: ts=2 sw=2 et

Generated on Sat Dec 20 16:52:04 2008 for cairomm by  doxygen 1.5.6