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/pattern.h>
00027 #include <cairomm/path.h>
00028 #include <valarray>
00029 #include <vector>
00030 #include <cairo.h>
00031
00032
00033 namespace Cairo
00034 {
00035
00036 typedef cairo_glyph_t Glyph;
00037 typedef cairo_font_extents_t FontExtents;
00038 typedef cairo_text_extents_t TextExtents;
00039 typedef cairo_matrix_t Matrix;
00040 typedef cairo_rectangle_t Rectangle;
00041
00050 class Context
00051 {
00052 protected:
00053 explicit Context(const RefPtr<Surface>& target);
00054
00055 public:
00056
00064 explicit Context(cairo_t* cobject, bool has_reference = false);
00065
00066 static RefPtr<Context> create(const RefPtr<Surface>& target);
00067
00068 virtual ~Context();
00069
00081 void save();
00082
00088 void restore();
00089
00096 void set_operator(Operator op);
00097
00115 void set_source(const RefPtr<const Pattern>& source);
00116
00131 void set_source_rgb(double red, double green, double blue);
00132
00149 void set_source_rgba(double red, double green, double blue, double alpha);
00150
00170 void set_source(const RefPtr<Surface>& surface, double x, double y);
00171
00181 void set_tolerance(double tolerance);
00182
00193 void set_antialias(Antialias antialias);
00194
00203 void set_fill_rule(FillRule fill_rule);
00204
00214 void set_line_width(double width);
00215
00225 void set_line_cap(LineCap line_cap);
00226
00236 void set_line_join(LineJoin line_join);
00237
00242 void set_dash(std::valarray<double>& dashes, double offset);
00260 void set_dash(std::vector<double>& dashes, double offset);
00261
00264 void unset_dash();
00265 void set_miter_limit(double limit);
00266
00276 void translate(double tx, double ty);
00277
00285 void scale(double sx, double sy);
00286
00296 void rotate(double angle_radians);
00297
00303 void rotate_degrees(double angle_degres);
00304
00311 void transform(const Matrix& matrix);
00312
00318 void set_matrix(const Matrix& matrix);
00319
00324 void set_identity_matrix();
00325
00332 void user_to_device(double& x, double& y);
00333
00341 void user_to_device_distance(double& dx, double& dy);
00342
00349 void device_to_user(double& x, double& y);
00350
00358 void device_to_user_distance(double& dx, double& dy);
00359
00362 void begin_new_path();
00363
00375 void begin_new_sub_path();
00376
00383 void move_to(double x, double y);
00384
00391 void line_to(double x, double y);
00392
00404 void curve_to(double x1, double y1, double x2, double y2, double x3, double y3);
00405
00445 void arc(double xc, double yc, double radius, double angle1, double angle2);
00446
00461 void arc_negative(double xc, double yc, double radius, double angle1, double angle2);
00462
00478 void rel_move_to(double dx, double dy);
00479
00497 void rel_line_to(double dx, double dy);
00498
00521 void rel_curve_to(double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);
00522
00541 void rectangle(double x, double y, double width, double height);
00542
00553 void close_path();
00554
00558 void paint();
00559
00567 void paint_with_alpha(double alpha);
00568
00575 void mask(const RefPtr<const Pattern>& pattern);
00576
00585 void mask(const RefPtr<const Surface>& surface, double surface_x, double surface_y);
00586
00597 void stroke();
00598
00609 void stroke_preserve();
00610
00618 void fill();
00619
00628 void fill_preserve();
00629 void copy_page();
00630 void show_page();
00631 bool in_stroke(double x, double y) const;
00632 bool in_fill(double x, double y) const;
00633 void get_stroke_extents(double& x1, double& y1, double& x2, double& y2) const;
00634 void get_fill_extents(double& x1, double& y1, double& x2, double& y2) const;
00635
00646 void reset_clip();
00647
00666 void clip();
00667
00678 void clip_preserve();
00679
00691 void get_clip_extents(double& x1, double& y1, double& x2, double& y2) const;
00692
00701 void copy_clip_rectangle_list(std::vector<Rectangle>& rectangles) const;
00702
00703 void select_font_face(const std::string& family, FontSlant slant, FontWeight weight);
00704 void set_font_size(double size);
00705 void set_font_matrix(const Matrix& matrix);
00706 void get_font_matrix(Matrix& matrix) const;
00707 void set_font_options(const FontOptions& options);
00708 void show_text(const std::string& utf8);
00709 void show_glyphs(const std::vector<Glyph>& glyphs);
00710 RefPtr<FontFace> get_font_face();
00711 RefPtr<const FontFace> get_font_face() const;
00712 void get_font_extents(FontExtents& extents) const;
00713 void set_font_face(const RefPtr<const FontFace>& font_face);
00714 void get_text_extents(const std::string& utf8, TextExtents& extents) const;
00715 void get_glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents) const;
00716 void text_path(const std::string& utf8);
00717 void glyph_path(const std::vector<Glyph>& glyphs);
00718
00721 Operator get_operator() const;
00722
00725 RefPtr<Pattern> get_source();
00726 RefPtr<const Pattern> get_source() const;
00727
00730 double get_tolerance() const;
00731
00734 Antialias get_antialias() const;
00735
00750 void get_current_point (double& x, double& y) const;
00751
00754 FillRule get_fill_rule() const;
00755
00758 double get_line_width() const;
00759
00762 LineCap get_line_cap() const;
00763
00766 LineJoin get_line_join() const;
00767
00770 double get_miter_limit() const;
00771
00780 void get_dash(std::vector<double>& dashes, double& offset) const;
00781
00782
00787 void get_matrix(Matrix& matrix);
00788
00793 RefPtr<Surface> get_target();
00794
00799 RefPtr<const Surface> get_target() const;
00800
00801
00810 Path* copy_path() const;
00811
00826 Path* copy_path_flat() const;
00827
00834 void append_path(const Path& path);
00835
00873 void push_group();
00874
00888 void push_group_with_content(Content content);
00889
00902 RefPtr<Pattern> pop_group();
00903
00923 void pop_group_to_source();
00924
00936 RefPtr<Surface> get_group_target();
00937
00941 RefPtr<const Surface> get_group_target() const;
00942
00945 typedef cairo_t cobject;
00946
00949 inline cobject* cobj() { return m_cobject; }
00950
00953 inline const cobject* cobj() const { return m_cobject; }
00954
00955 #ifndef DOXYGEN_IGNORE_THIS
00957 inline ErrorStatus get_status() const
00958 { return cairo_status(const_cast<cairo_t*>(cobj())); }
00959
00960 void reference() const;
00961 void unreference() const;
00962 #endif //DOXYGEN_IGNORE_THIS
00963
00964 protected:
00965
00966
00967 cobject* m_cobject;
00968 };
00969
00970 }
00971
00972 #endif //__CAIROMM_CONTEXT_H
00973
00974