00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CAIROMM_CONTEXT_H
00020 #define __CAIROMM_CONTEXT_H
00021
00022 #include <vector>
00023 #include <utility>
00024 #include <cairomm/surface.h>
00025 #include <cairomm/fontface.h>
00026 #include <cairomm/matrix.h>
00027 #include <cairomm/pattern.h>
00028 #include <cairomm/path.h>
00029 #include <cairomm/scaledfont.h>
00030 #include <cairomm/types.h>
00031 #include <valarray>
00032 #include <vector>
00033 #include <cairo.h>
00034
00035
00036 namespace Cairo
00037 {
00038
00047 class Context
00048 {
00049 protected:
00050 explicit Context(const RefPtr<Surface>& target);
00051
00052 public:
00053
00061 explicit Context(cairo_t* cobject, bool has_reference = false);
00062
00063 static RefPtr<Context> create(const RefPtr<Surface>& target);
00064
00065 virtual ~Context();
00066
00078 void save();
00079
00085 void restore();
00086
00093 void set_operator(Operator op);
00094
00112 void set_source(const RefPtr<const Pattern>& source);
00113
00128 void set_source_rgb(double red, double green, double blue);
00129
00146 void set_source_rgba(double red, double green, double blue, double alpha);
00147
00167 void set_source(const RefPtr<Surface>& surface, double x, double y);
00168
00178 void set_tolerance(double tolerance);
00179
00190 void set_antialias(Antialias antialias);
00191
00200 void set_fill_rule(FillRule fill_rule);
00201
00211 void set_line_width(double width);
00212
00222 void set_line_cap(LineCap line_cap);
00223
00233 void set_line_join(LineJoin line_join);
00234
00239 void set_dash(std::valarray<double>& dashes, double offset);
00257 void set_dash(std::vector<double>& dashes, double offset);
00258
00261 void unset_dash();
00262 void set_miter_limit(double limit);
00263
00273 void translate(double tx, double ty);
00274
00282 void scale(double sx, double sy);
00283
00293 void rotate(double angle_radians);
00294
00300 void rotate_degrees(double angle_degres);
00301
00308 void transform(const Matrix& matrix);
00309
00315 void set_matrix(const Matrix& matrix);
00316
00321 void set_identity_matrix();
00322
00329 void user_to_device(double& x, double& y);
00330
00338 void user_to_device_distance(double& dx, double& dy);
00339
00346 void device_to_user(double& x, double& y);
00347
00355 void device_to_user_distance(double& dx, double& dy);
00356
00359 void begin_new_path();
00360
00372 void begin_new_sub_path();
00373
00380 void move_to(double x, double y);
00381
00388 void line_to(double x, double y);
00389
00401 void curve_to(double x1, double y1, double x2, double y2, double x3, double y3);
00402
00442 void arc(double xc, double yc, double radius, double angle1, double angle2);
00443
00458 void arc_negative(double xc, double yc, double radius, double angle1, double angle2);
00459
00475 void rel_move_to(double dx, double dy);
00476
00494 void rel_line_to(double dx, double dy);
00495
00518 void rel_curve_to(double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);
00519
00538 void rectangle(double x, double y, double width, double height);
00539
00550 void close_path();
00551
00555 void paint();
00556
00564 void paint_with_alpha(double alpha);
00565
00572 void mask(const RefPtr<const Pattern>& pattern);
00573
00582 void mask(const RefPtr<const Surface>& surface, double surface_x, double surface_y);
00583
00594 void stroke();
00595
00606 void stroke_preserve();
00607
00615 void fill();
00616
00625 void fill_preserve();
00626 void copy_page();
00627 void show_page();
00628 bool in_stroke(double x, double y) const;
00629 bool in_fill(double x, double y) const;
00630 void get_stroke_extents(double& x1, double& y1, double& x2, double& y2) const;
00631 void get_fill_extents(double& x1, double& y1, double& x2, double& y2) const;
00632
00643 void reset_clip();
00644
00663 void clip();
00664
00675 void clip_preserve();
00676
00688 void get_clip_extents(double& x1, double& y1, double& x2, double& y2) const;
00689
00698 void copy_clip_rectangle_list(std::vector<Rectangle>& rectangles) const;
00699
00700 void select_font_face(const std::string& family, FontSlant slant, FontWeight weight);
00701 void set_font_size(double size);
00702 void set_font_matrix(const Matrix& matrix);
00703 void get_font_matrix(Matrix& matrix) const;
00704 void set_font_options(const FontOptions& options);
00705
00706
00710 void get_font_options(FontOptions& options) const;
00711
00712
00716 void set_scaled_font(const RefPtr<const ScaledFont>& scaled_font);
00717
00718
00722 RefPtr<ScaledFont> get_scaled_font();
00723
00724
00725 void show_text(const std::string& utf8);
00726 void show_glyphs(const std::vector<Glyph>& glyphs);
00728 void show_text_glyphs(const std::string& utf8,
00729 const std::vector<Glyph>& glyphs,
00730 const std::vector<TextCluster>& clusters,
00731 TextClusterFlags cluster_flags);
00732
00733 RefPtr<FontFace> get_font_face();
00734 RefPtr<const FontFace> get_font_face() const;
00735
00736 void get_font_extents(FontExtents& extents) const;
00737 void set_font_face(const RefPtr<const FontFace>& font_face);
00738 void get_text_extents(const std::string& utf8, TextExtents& extents) const;
00739 void get_glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents) const;
00740 void text_path(const std::string& utf8);
00741 void glyph_path(const std::vector<Glyph>& glyphs);
00742
00745 Operator get_operator() const;
00746
00749 RefPtr<Pattern> get_source();
00750 RefPtr<const Pattern> get_source() const;
00751
00754 double get_tolerance() const;
00755
00758 Antialias get_antialias() const;
00759
00776 void get_current_point (double& x, double& y) const;
00777
00780 bool has_current_point() const;
00781
00784 FillRule get_fill_rule() const;
00785
00788 double get_line_width() const;
00789
00792 LineCap get_line_cap() const;
00793
00796 LineJoin get_line_join() const;
00797
00800 double get_miter_limit() const;
00801
00810 void get_dash(std::vector<double>& dashes, double& offset) const;
00811
00812
00817 void get_matrix(Matrix& matrix);
00820 Matrix get_matrix() const;
00821
00826 RefPtr<Surface> get_target();
00827
00832 RefPtr<const Surface> get_target() const;
00833
00834
00843 Path* copy_path() const;
00844
00873 void get_path_extents(double& x1, double& y1, double& x2, double& y2) const;
00874
00889 Path* copy_path_flat() const;
00890
00897 void append_path(const Path& path);
00898
00936 void push_group();
00937
00951 void push_group_with_content(Content content);
00952
00965 RefPtr<Pattern> pop_group();
00966
00986 void pop_group_to_source();
00987
00999 RefPtr<Surface> get_group_target();
01000
01004 RefPtr<const Surface> get_group_target() const;
01005
01008 typedef cairo_t cobject;
01009
01012 inline cobject* cobj() { return m_cobject; }
01013
01016 inline const cobject* cobj() const { return m_cobject; }
01017
01018 #ifndef DOXYGEN_IGNORE_THIS
01020 inline ErrorStatus get_status() const
01021 { return cairo_status(const_cast<cairo_t*>(cobj())); }
01022
01023 void reference() const;
01024 void unreference() const;
01025 #endif //DOXYGEN_IGNORE_THIS
01026
01027 protected:
01028
01029
01030 cobject* m_cobject;
01031 };
01032
01033 }
01034
01035 #endif //__CAIROMM_CONTEXT_H
01036
01037