# 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
    00409   static RefPtr<ImageSurface> create(Format format, int width, int height);
    00410
    00433   static RefPtr<ImageSurface> create(unsigned char* data, Format format, int width, int height, int stride);
    00434
    00435 #ifdef CAIRO_HAS_PNG_FUNCTIONS
    00436
    00447   static RefPtr<ImageSurface> create_from_png(std::string filename);
    00448
    00459   static RefPtr<ImageSurface> create_from_png_stream(const SlotReadFunc& read_func);
    00461   static RefPtr<ImageSurface> create_from_png(cairo_read_func_t read_func, void *closure);
    00462
    00463 #endif // CAIRO_HAS_PNG_FUNCTIONS
    00464
    00465 };
    00466
    00467
    00468 #ifdef CAIRO_HAS_PDF_SURFACE
    00469
    00481 class PdfSurface : public Surface
    00482 {
    00483 public:
    00484
    00492   explicit PdfSurface(cairo_surface_t* cobject, bool has_reference = false);
    00493   virtual ~PdfSurface();
    00494
    00502   static RefPtr<PdfSurface> create(std::string filename, double width_in_points, double height_in_points);
    00503
    00514   static RefPtr<PdfSurface> create_for_stream(const SlotWriteFunc& write_func, double width_in_points, double height_in_points);
    00516   static RefPtr<PdfSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
    00517
    00529   void set_size(double width_in_points, double height_in_points);
    00530
    00531 };
    00532
    00533 #endif  // CAIRO_HAS_PDF_SURFACE
    00534
    00535
    00536 #ifdef CAIRO_HAS_PS_SURFACE
    00537
    00546 typedef enum {
    00547     PS_LEVEL_2 = CAIRO_PS_LEVEL_2,
    00548     PS_LEVEL_3 = CAIRO_PS_LEVEL_3
    00549 } PsLevel;
    00550
    00558 class PsSurface : public Surface
    00559 {
    00560 public:
    00561
    00569   explicit PsSurface(cairo_surface_t* cobject, bool has_reference = false);
    00570   virtual ~PsSurface();
    00571
    00579   static RefPtr<PsSurface> create(std::string filename, double width_in_points, double height_in_points);
    00580
    00591   static RefPtr<PsSurface> create_for_stream(const SlotWriteFunc& write_func, double width_in_points, double height_in_points);
    00593   static RefPtr<PsSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
    00594
    00607   void set_size(double width_in_points, double height_in_points);
    00608
    00614   void dsc_comment(std::string comment);
    00615
    00624   void dsc_begin_setup();
    00625
    00633   void dsc_begin_page_setup();
    00634
    00647   void set_eps(bool eps);
    00648
    00653   bool get_eps() const;
    00654
    00667   void restrict_to_level(PsLevel level);
    00668
    00675   static const std::vector<PsLevel> get_levels();
    00676
    00688   static std::string level_to_string(PsLevel level);
    00689 };
    00690
    00691 #endif // CAIRO_HAS_PS_SURFACE
    00692
    00693
    00694 #ifdef CAIRO_HAS_SVG_SURFACE
    00695
    00700 typedef enum
    00701 {
    00702   SVG_VERSION_1_1 = CAIRO_SVG_VERSION_1_1,
    00703   SVG_VERSION_1_2 = CAIRO_SVG_VERSION_1_2
    00704 } SvgVersion;
    00705
    00713 class SvgSurface : public Surface
    00714 {
    00715 public:
    00716
    00724   explicit SvgSurface(cairo_surface_t* cobject, bool has_reference = false);
    00725   virtual ~SvgSurface();
    00726
    00727
    00735   static RefPtr<SvgSurface> create(std::string filename, double width_in_points, double height_in_points);
    00736
    00747   static RefPtr<SvgSurface> create_for_stream(const SlotWriteFunc& write_func, double width_in_points, double height_in_points);
    00748
    00750   static RefPtr<SvgSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
    00751
    00762   void restrict_to_version(SvgVersion version);
    00763
    00769   static const std::vector<SvgVersion> get_versions();
    00770
    00777   static std::string version_to_string(SvgVersion version);
    00778 };
    00779
    00780 #endif // CAIRO_HAS_SVG_SURFACE
    00781
    00782
    00783 /*******************************************************************************
    00784  * THE FOLLOWING SURFACE TYPES ARE EXPERIMENTAL AND NOT FULLY SUPPORTED
    00785  ******************************************************************************/
    00786
    00787 #ifdef CAIRO_HAS_GLITZ_SURFACE
    00788
    00800 class GlitzSurface : public Surface
    00801 {
    00802
    00803 public:
    00804
    00812   explicit GlitzSurface(cairo_surface_t* cobject, bool has_reference = false);
    00813
    00814   virtual ~GlitzSurface();
    00815
    00820   static RefPtr<GlitzSurface> create(glitz_surface_t *surface);
    00821
    00822 };
    00823
    00824 #endif // CAIRO_HAS_GLITZ_SURFACE
    00825
    00826 } // namespace Cairo
    00827
    00828 #endif //__CAIROMM_SURFACE_H
    00829
    00830 // vim: ts=2 sw=2 et