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
00310
00311 void transform(const cairo_matrix_t& matrix);
00312
00318 void set_matrix(const Matrix& matrix);
00319
00320
00321 void set_matrix(const cairo_matrix_t& matrix);
00322
00327 void set_identity_matrix();
00328
00335 void user_to_device(double& x, double& y);
00336
00344 void user_to_device_distance(double& dx, double& dy);
00345
00352 void device_to_user(double& x, double& y);
00353
00361 void device_to_user_distance(double& dx, double& dy);
00362
00365 void begin_new_path();
00366
00378 void begin_new_sub_path();
00379
00386 void move_to(double x, double y);
00387
00394 void line_to(double x, double y);
00395
00407 void curve_to(double x1, double y1, double x2, double y2, double x3, double y3);
00408
00448 void arc(double xc, double yc, double radius, double angle1, double angle2);
00449
00464 void arc_negative(double xc, double yc, double radius, double angle1, double angle2);
00465
00481 void rel_move_to(double dx, double dy);
00482
00500 void rel_line_to(double dx, double dy);
00501
00524 void rel_curve_to(double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);
00525
00544 void rectangle(double x, double y, double width, double height);
00545
00556 void close_path();
00557
00561 void paint();
00562
00570 void paint_with_alpha(double alpha);
00571
00578 void mask(const RefPtr<const Pattern>& pattern);
00579
00588 void mask(const RefPtr<const Surface>& surface, double surface_x, double surface_y);
00589
00600 void stroke();
00601
00612 void stroke_preserve();
00613
00621 void fill();
00622
00631 void fill_preserve();
00632 void copy_page();
00633 void show_page();
00634 bool in_stroke(double x, double y) const;
00635 bool in_fill(double x, double y) const;
00636 void get_stroke_extents(double& x1, double& y1, double& x2, double& y2) const;
00637 void get_fill_extents(double& x1, double& y1, double& x2, double& y2) const;
00638
00649 void reset_clip();
00650
00669 void clip();
00670
00681 void clip_preserve();
00682
00694 void get_clip_extents(double& x1, double& y1, double& x2, double& y2) const;
00695
00704 void copy_clip_rectangle_list(std::vector<Rectangle>& rectangles) const;
00705
00706 void select_font_face(const std::string& family, FontSlant slant, FontWeight weight);
00707 void set_font_size(double size);
00708 void set_font_matrix(const Matrix& matrix);
00709 void get_font_matrix(Matrix& matrix) const;
00710 void set_font_options(const FontOptions& options);
00711
00712
00713 void set_font_matrix(const cairo_matrix_t& matrix);
00714 void get_font_matrix(cairo_matrix_t& matrix) const;
00715
00716
00720 void get_font_options(FontOptions& options) const;
00721
00722
00726 void set_scaled_font(const RefPtr<const ScaledFont>& scaled_font);
00727
00728
00732 RefPtr<ScaledFont> get_scaled_font();
00733
00734
00735 void show_text(const std::string& utf8);
00736 void show_glyphs(const std::vector<Glyph>& glyphs);
00738 void show_text_glyphs(const std::string& utf8,
00739 const std::vector<Glyph>& glyphs,
00740 const std::vector<TextCluster>& clusters,
00741 TextClusterFlags cluster_flags);
00742
00743 RefPtr<FontFace> get_font_face();
00744 RefPtr<const FontFace> get_font_face() const;
00745
00746 void get_font_extents(FontExtents& extents) const;
00747 void set_font_face(const RefPtr<const FontFace>& font_face);
00748 void get_text_extents(const std::string& utf8, TextExtents& extents) const;
00749 void get_glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents) const;
00750 void text_path(const std::string& utf8);
00751 void glyph_path(const std::vector<Glyph>& glyphs);
00752
00755 Operator get_operator() const;
00756
00759 RefPtr<Pattern> get_source();
00760 RefPtr<const Pattern> get_source() const;
00761
00764 double get_tolerance() const;
00765
00768 Antialias get_antialias() const;
00769
00786 void get_current_point (double& x, double& y) const;
00787
00790 bool has_current_point() const;
00791
00794 FillRule get_fill_rule() const;
00795
00798 double get_line_width() const;
00799
00802 LineCap get_line_cap() const;
00803
00806 LineJoin get_line_join() const;
00807
00810 double get_miter_limit() const;
00811
00820 void get_dash(std::vector<double>& dashes, double& offset) const;
00821
00822
00827 void get_matrix(Matrix& matrix);
00828
00829
00830 void get_matrix(cairo_matrix_t& matrix);
00831
00834 Matrix get_matrix() const;
00835
00840 RefPtr<Surface> get_target();
00841
00846 RefPtr<const Surface> get_target() const;
00847
00848
00857 Path* copy_path() const;
00858
00887 void get_path_extents(double& x1, double& y1, double& x2, double& y2) const;
00888
00903 Path* copy_path_flat() const;
00904
00911 void append_path(const Path& path);
00912
00950 void push_group();
00951
00965 void push_group_with_content(Content content);
00966
00979 RefPtr<Pattern> pop_group();
00980
01000 void pop_group_to_source();
01001
01013 RefPtr<Surface> get_group_target();
01014
01018 RefPtr<const Surface> get_group_target() const;
01019
01022 typedef cairo_t cobject;
01023
01026 inline cobject* cobj() { return m_cobject; }
01027
01030 inline const cobject* cobj() const { return m_cobject; }
01031
01032 #ifndef DOXYGEN_IGNORE_THIS
01034 inline ErrorStatus get_status() const
01035 { return cairo_status(const_cast<cairo_t*>(cobj())); }
01036
01037 void reference() const;
01038 void unreference() const;
01039 #endif //DOXYGEN_IGNORE_THIS
01040
01041 protected:
01042
01043
01044 cobject* m_cobject;
01045 };
01046
01047 }
01048
01049 #endif //__CAIROMM_CONTEXT_H
01050
01051