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 
00162   void copy_page();
00163 
00170   void show_page();
00171 
00172 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00173 
00181   void write_to_png(const std::string& filename);
00182 
00192   void write_to_png(cairo_write_func_t write_func, void *closure); //TODO: Use a sigc::slot?
00193 
00194 #endif // CAIRO_HAS_PNG_FUNCTIONS
00195 
00196 
00199   typedef cairo_surface_t cobject;
00202   inline cobject* cobj() { return m_cobject; }
00205   inline const cobject* cobj() const { return m_cobject; }
00206 
00207   #ifndef DOXYGEN_IGNORE_THIS
00209   inline ErrorStatus get_status() const
00210   { return cairo_surface_status(const_cast<cairo_surface_t*>(cobj())); }
00211 
00212   void reference() const;
00213   void unreference() const;
00214   #endif //DOXYGEN_IGNORE_THIS
00215 
00226   static RefPtr<Surface> create(const RefPtr<Surface> other, Content content, int width, int height);
00227 
00228 protected:
00231   cobject* m_cobject;
00232 };
00233 
00234 
00251 class ImageSurface : public Surface
00252 {
00253 protected:
00254   //TODO?: Surface(cairo_surface_t *target);
00255 
00256 public:
00257 
00264   explicit ImageSurface(cairo_surface_t* cobject, bool has_reference = false);
00265 
00266   virtual ~ImageSurface();
00267 
00270   int get_width() const;
00271 
00274   int get_height() const;
00275 
00283   unsigned char* get_data();
00284   const unsigned char* get_data() const;
00285 
00288   Format get_format() const;
00289 
00296   int get_stride() const;
00297 
00320   static int format_stride_for_width (Cairo::Format format, int width);
00321 
00338   static RefPtr<ImageSurface> create(Format format, int width, int height);
00339 
00362   static RefPtr<ImageSurface> create(unsigned char* data, Format format, int width, int height, int stride);
00363 
00364 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00365 
00376   static RefPtr<ImageSurface> create_from_png(std::string filename);
00377 
00389   static RefPtr<ImageSurface> create_from_png(cairo_read_func_t read_func, void *closure);
00390 
00391 #endif // CAIRO_HAS_PNG_FUNCTIONS
00392 
00393 };
00394 
00395 
00396 #ifdef CAIRO_HAS_PDF_SURFACE
00397 
00405 class PdfSurface : public Surface
00406 {
00407 public:
00408 
00416   explicit PdfSurface(cairo_surface_t* cobject, bool has_reference = false);
00417   virtual ~PdfSurface();
00418 
00426   static RefPtr<PdfSurface> create(std::string filename, double width_in_points, double height_in_points);
00427 
00437   static RefPtr<PdfSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00438 
00450   void set_size(double width_in_points, double height_in_points);
00451 
00452 };
00453 
00454 #endif  // CAIRO_HAS_PDF_SURFACE
00455 
00456 
00457 #ifdef CAIRO_HAS_PS_SURFACE
00458 
00463 typedef enum {
00464     PS_LEVEL_2 = CAIRO_PS_LEVEL_2,
00465     PS_LEVEL_3 = CAIRO_PS_LEVEL_3
00466 } PsLevel;
00467 
00475 class PsSurface : public Surface
00476 {
00477 public:
00478 
00486   explicit PsSurface(cairo_surface_t* cobject, bool has_reference = false);
00487   virtual ~PsSurface();
00488 
00496   static RefPtr<PsSurface> create(std::string filename, double width_in_points, double height_in_points);
00497 
00507   static RefPtr<PsSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00508 
00521   void set_size(double width_in_points, double height_in_points);
00522 
00528   void dsc_comment(std::string comment);
00529 
00538   void dsc_begin_setup();
00539 
00547   void dsc_begin_page_setup();
00548 
00561   void set_eps(bool eps);
00562 
00575   void restrict_to_level(PsLevel level);
00576 
00583   static const std::vector<PsLevel> get_levels();
00584 
00596   static std::string level_to_string(PsLevel level);
00597 };
00598 
00599 #endif // CAIRO_HAS_PS_SURFACE
00600 
00601 
00602 #ifdef CAIRO_HAS_SVG_SURFACE
00603 
00604 typedef enum
00605 {
00606   SVG_VERSION_1_1 = CAIRO_SVG_VERSION_1_1,
00607   SVG_VERSION_1_2 = CAIRO_SVG_VERSION_1_2
00608 } SvgVersion;
00609 
00617 class SvgSurface : public Surface
00618 {
00619 public:
00620 
00628   explicit SvgSurface(cairo_surface_t* cobject, bool has_reference = false);
00629   virtual ~SvgSurface();
00630 
00631 
00639   static RefPtr<SvgSurface> create(std::string filename, double width_in_points, double height_in_points);
00640 
00650   static RefPtr<SvgSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00651 
00662   void restrict_to_version(SvgVersion version);
00663 
00669   static const std::vector<SvgVersion> get_versions();
00670 
00677   static std::string version_to_string(SvgVersion version);
00678 };
00679 
00680 #endif // CAIRO_HAS_SVG_SURFACE
00681 
00682 
00683 /*******************************************************************************
00684  * THE FOLLOWING SURFACE TYPES ARE EXPERIMENTAL AND NOT FULLY SUPPORTED
00685  ******************************************************************************/
00686 
00687 #ifdef CAIRO_HAS_GLITZ_SURFACE
00688 
00700 class GlitzSurface : public Surface
00701 {
00702 
00703 public:
00704 
00712   explicit GlitzSurface(cairo_surface_t* cobject, bool has_reference = false);
00713 
00714   virtual ~GlitzSurface();
00715 
00720   static RefPtr<GlitzSurface> create(glitz_surface_t *surface);
00721 
00722 };
00723 
00724 #endif // CAIRO_HAS_GLITZ_SURFACE
00725 
00726 } // namespace Cairo
00727 
00728 #endif //__CAIROMM_SURFACE_H
00729 
00730 // vim: ts=2 sw=2 et

Generated on Thu Sep 4 21:57:13 2008 for cairomm by  doxygen 1.5.5