00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CAIROMM_SURFACE_H
00020 #define __CAIROMM_SURFACE_H
00021
00022 #include <string>
00023 #include <vector>
00024 #include <sigc++/slot.h>
00025 #include <cairomm/enums.h>
00026 #include <cairomm/exception.h>
00027 #include <cairomm/fontoptions.h>
00028 #include <cairomm/refptr.h>
00029
00030
00031
00032
00033
00034 #ifdef CAIRO_HAS_PDF_SURFACE
00035 #include <cairo-pdf.h>
00036 #endif // CAIRO_HAS_PDF_SURFACE
00037 #ifdef CAIRO_HAS_PS_SURFACE
00038 #include <cairo-ps.h>
00039 #endif // CAIRO_HAS_PS_SURFACE
00040 #ifdef CAIRO_HAS_SVG_SURFACE
00041 #include <cairo-svg.h>
00042 #endif // CAIRO_HAS_SVG_SURFACE
00043
00044
00045 #ifdef CAIRO_HAS_GLITZ_SURFACE
00046 #include <cairo-glitz.h>
00047 #endif // CAIRO_HAS_GLITZ_SURFACE
00048
00049
00050 namespace Cairo
00051 {
00052
00060 class Surface
00061 {
00062 public:
00077 typedef sigc::slot<ErrorStatus, const unsigned char* , unsigned int > SlotWriteFunc;
00089 typedef sigc::slot<ErrorStatus, unsigned char* , unsigned int > SlotReadFunc;
00090
00098 explicit Surface(cairo_surface_t* cobject, bool has_reference = false);
00099
00100 virtual ~Surface();
00101
00110 void get_font_options(FontOptions& options) const;
00111
00123 void finish();
00124
00131 void flush();
00132
00143 void mark_dirty();
00144
00152 void mark_dirty(int x, int y, int width, int height);
00153
00168 void set_device_offset(double x_offset, double y_offset);
00169
00172 void get_device_offset(double& x_offset, double& y_offset) const;
00173
00179 void set_fallback_resolution(double x_pixels_per_inch, double y_pixels_per_inch);
00180
00189 void get_fallback_resolution(double& x_pixels_per_inch, double& y_pixels_per_inch) const;
00190
00191 SurfaceType get_type() const;
00192
00198 Content get_content() const;
00199
00208 void copy_page();
00209
00216 void show_page();
00217
00230 bool has_show_text_glyphs() const;
00231
00232 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00233
00241 void write_to_png(const std::string& filename);
00242
00253 void write_to_png_stream(const SlotWriteFunc& write_func);
00254
00256 void write_to_png(cairo_write_func_t write_func, void *closure);
00257
00258 #endif // CAIRO_HAS_PNG_FUNCTIONS
00259
00260
00263 typedef cairo_surface_t cobject;
00266 inline cobject* cobj() { return m_cobject; }
00269 inline const cobject* cobj() const { return m_cobject; }
00270
00271 #ifndef DOXYGEN_IGNORE_THIS
00273 inline ErrorStatus get_status() const
00274 { return cairo_surface_status(const_cast<cairo_surface_t*>(cobj())); }
00275
00276 void reference() const;
00277 void unreference() const;
00278 #endif //DOXYGEN_IGNORE_THIS
00279
00290 static RefPtr<Surface> create(const RefPtr<Surface> other, Content content, int width, int height);
00291
00292 protected:
00295 cobject* m_cobject;
00296 };
00297
00298
00315 class ImageSurface : public Surface
00316 {
00317 protected:
00318
00319
00320 public:
00321
00328 explicit ImageSurface(cairo_surface_t* cobject, bool has_reference = false);
00329
00330 virtual ~ImageSurface();
00331
00334 int get_width() const;
00335
00338 int get_height() const;
00339
00347 unsigned char* get_data();
00348 const unsigned char* get_data() const;
00349
00352 Format get_format() const;
00353
00360 int get_stride() const;
00361
00384 static int format_stride_for_width (Cairo::Format format, int width);
00385
00402 static RefPtr<ImageSurface> create(Format format, int width, int height);
00403
00426 static RefPtr<ImageSurface> create(unsigned char* data, Format format, int width, int height, int stride);
00427
00428 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00429
00440 static RefPtr<ImageSurface> create_from_png(std::string filename);
00441
00452 static RefPtr<ImageSurface> create_from_png_stream(const SlotReadFunc& read_func);
00454 static RefPtr<ImageSurface> create_from_png(cairo_read_func_t read_func, void *closure);
00455
00456 #endif // CAIRO_HAS_PNG_FUNCTIONS
00457
00458 };
00459
00460
00461 #ifdef CAIRO_HAS_PDF_SURFACE
00462
00470 class PdfSurface : public Surface
00471 {
00472 public:
00473
00481 explicit PdfSurface(cairo_surface_t* cobject, bool has_reference = false);
00482 virtual ~PdfSurface();
00483
00491 static RefPtr<PdfSurface> create(std::string filename, double width_in_points, double height_in_points);
00492
00503 static RefPtr<PdfSurface> create_for_stream(const SlotWriteFunc& write_func, double width_in_points, double height_in_points);
00505 static RefPtr<PdfSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00506
00518 void set_size(double width_in_points, double height_in_points);
00519
00520 };
00521
00522 #endif // CAIRO_HAS_PDF_SURFACE
00523
00524
00525 #ifdef CAIRO_HAS_PS_SURFACE
00526
00531 typedef enum {
00532 PS_LEVEL_2 = CAIRO_PS_LEVEL_2,
00533 PS_LEVEL_3 = CAIRO_PS_LEVEL_3
00534 } PsLevel;
00535
00543 class PsSurface : public Surface
00544 {
00545 public:
00546
00554 explicit PsSurface(cairo_surface_t* cobject, bool has_reference = false);
00555 virtual ~PsSurface();
00556
00564 static RefPtr<PsSurface> create(std::string filename, double width_in_points, double height_in_points);
00565
00576 static RefPtr<PsSurface> create_for_stream(const SlotWriteFunc& write_func, double width_in_points, double height_in_points);
00578 static RefPtr<PsSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00579
00592 void set_size(double width_in_points, double height_in_points);
00593
00599 void dsc_comment(std::string comment);
00600
00609 void dsc_begin_setup();
00610
00618 void dsc_begin_page_setup();
00619
00632 void set_eps(bool eps);
00633
00638 bool get_eps() const;
00639
00652 void restrict_to_level(PsLevel level);
00653
00660 static const std::vector<PsLevel> get_levels();
00661
00673 static std::string level_to_string(PsLevel level);
00674 };
00675
00676 #endif // CAIRO_HAS_PS_SURFACE
00677
00678
00679 #ifdef CAIRO_HAS_SVG_SURFACE
00680
00681 typedef enum
00682 {
00683 SVG_VERSION_1_1 = CAIRO_SVG_VERSION_1_1,
00684 SVG_VERSION_1_2 = CAIRO_SVG_VERSION_1_2
00685 } SvgVersion;
00686
00694 class SvgSurface : public Surface
00695 {
00696 public:
00697
00705 explicit SvgSurface(cairo_surface_t* cobject, bool has_reference = false);
00706 virtual ~SvgSurface();
00707
00708
00716 static RefPtr<SvgSurface> create(std::string filename, double width_in_points, double height_in_points);
00717
00728 static RefPtr<SvgSurface> create_for_stream(const SlotWriteFunc& write_func, double width_in_points, double height_in_points);
00729
00731 static RefPtr<SvgSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00732
00743 void restrict_to_version(SvgVersion version);
00744
00750 static const std::vector<SvgVersion> get_versions();
00751
00758 static std::string version_to_string(SvgVersion version);
00759 };
00760
00761 #endif // CAIRO_HAS_SVG_SURFACE
00762
00763
00764
00765
00766
00767
00768 #ifdef CAIRO_HAS_GLITZ_SURFACE
00769
00781 class GlitzSurface : public Surface
00782 {
00783
00784 public:
00785
00793 explicit GlitzSurface(cairo_surface_t* cobject, bool has_reference = false);
00794
00795 virtual ~GlitzSurface();
00796
00801 static RefPtr<GlitzSurface> create(glitz_surface_t *surface);
00802
00803 };
00804
00805 #endif // CAIRO_HAS_GLITZ_SURFACE
00806
00807 }
00808
00809 #endif //__CAIROMM_SURFACE_H
00810
00811