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 <cairomm/enums.h>
00025 #include <cairomm/exception.h>
00026 #include <cairomm/fontoptions.h>
00027 #include <cairomm/refptr.h>
00028
00029
00030
00031
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
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);
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
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
00298
00315 static RefPtr<ImageSurface> create(Format format, int width, int height);
00316
00339 static RefPtr<ImageSurface> create(unsigned char* data, Format format, int width, int height, int stride);
00340
00341 #ifdef CAIRO_HAS_PNG_FUNCTIONS
00342
00353 static RefPtr<ImageSurface> create_from_png(std::string filename);
00354
00366 static RefPtr<ImageSurface> create_from_png(cairo_read_func_t read_func, void *closure);
00367
00368 #endif // CAIRO_HAS_PNG_FUNCTIONS
00369
00370 };
00371
00372
00373 #ifdef CAIRO_HAS_PDF_SURFACE
00374
00382 class PdfSurface : public Surface
00383 {
00384 public:
00385
00393 explicit PdfSurface(cairo_surface_t* cobject, bool has_reference = false);
00394 virtual ~PdfSurface();
00395
00403 static RefPtr<PdfSurface> create(std::string filename, double width_in_points, double height_in_points);
00404
00414 static RefPtr<PdfSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00415
00427 void set_size(double width_in_points, double height_in_points);
00428
00429 };
00430
00431 #endif // CAIRO_HAS_PDF_SURFACE
00432
00433
00434 #ifdef CAIRO_HAS_PS_SURFACE
00435
00440 typedef enum {
00441 PS_LEVEL_2 = CAIRO_PS_LEVEL_2,
00442 PS_LEVEL_3 = CAIRO_PS_LEVEL_3
00443 } PsLevel;
00444
00452 class PsSurface : public Surface
00453 {
00454 public:
00455
00463 explicit PsSurface(cairo_surface_t* cobject, bool has_reference = false);
00464 virtual ~PsSurface();
00465
00473 static RefPtr<PsSurface> create(std::string filename, double width_in_points, double height_in_points);
00474
00484 static RefPtr<PsSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00485
00498 void set_size(double width_in_points, double height_in_points);
00499
00505 void dsc_comment(std::string comment);
00506
00515 void dsc_begin_setup();
00516
00524 void dsc_begin_page_setup();
00525
00538 void set_eps(bool eps);
00539
00552 void restrict_to_level(PsLevel level);
00553
00560 static const std::vector<PsLevel> get_levels();
00561
00573 static std::string level_to_string(PsLevel level);
00574 };
00575
00576 #endif // CAIRO_HAS_PS_SURFACE
00577
00578
00579 #ifdef CAIRO_HAS_SVG_SURFACE
00580
00581 typedef enum
00582 {
00583 SVG_VERSION_1_1 = CAIRO_SVG_VERSION_1_1,
00584 SVG_VERSION_1_2 = CAIRO_SVG_VERSION_1_2
00585 } SvgVersion;
00586
00594 class SvgSurface : public Surface
00595 {
00596 public:
00597
00605 explicit SvgSurface(cairo_surface_t* cobject, bool has_reference = false);
00606 virtual ~SvgSurface();
00607
00608
00616 static RefPtr<SvgSurface> create(std::string filename, double width_in_points, double height_in_points);
00617
00627 static RefPtr<SvgSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
00628
00639 void restrict_to_version(SvgVersion version);
00640
00646 static const std::vector<SvgVersion> get_versions();
00647
00654 static std::string version_to_string(SvgVersion version);
00655 };
00656
00657 #endif // CAIRO_HAS_SVG_SURFACE
00658
00659
00660
00661
00662
00663
00664 #ifdef CAIRO_HAS_GLITZ_SURFACE
00665
00677 class GlitzSurface : public Surface
00678 {
00679
00680 public:
00681
00689 explicit GlitzSurface(cairo_surface_t* cobject, bool has_reference = false);
00690
00691 virtual ~GlitzSurface();
00692
00697 static RefPtr<GlitzSurface> create(glitz_surface_t *surface);
00698
00699 };
00700
00701 #endif // CAIRO_HAS_GLITZ_SURFACE
00702
00703 }
00704
00705 #endif //__CAIROMM_SURFACE_H
00706
00707