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 <cairomm/surface.h>
00023 #include <cairomm/fontface.h>
00024 #include <cairomm/pattern.h>
00025 #include <cairomm/path.h>
00026 #include <valarray>
00027 #include <vector>
00028 #include <cairo.h>
00029
00030
00031 namespace Cairo
00032 {
00033
00034 typedef cairo_glyph_t Glyph;
00035 typedef cairo_font_extents_t FontExtents;
00036 typedef cairo_text_extents_t TextExtents;
00037 typedef cairo_matrix_t Matrix;
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
00252 void set_dash(std::valarray<double>& dashes, double offset);
00253
00256 void unset_dash();
00257 void set_miter_limit(double limit);
00258
00268 void translate(double tx, double ty);
00269
00277 void scale(double sx, double sy);
00278
00288 void rotate(double angle_radians);
00289
00295 void rotate_degrees(double angle_degres);
00296
00303 void transform(const Matrix& matrix);
00304
00310 void set_matrix(const Matrix& matrix);
00311
00316 void set_identity_matrix();
00317
00324 void user_to_device(double& x, double& y);
00325
00333 void user_to_device_distance(double& dx, double& dy);
00334
00341 void device_to_user(double& x, double& y);
00342
00350 void device_to_user_distance(double& dx, double& dy);
00351
00352
00355 void clear_path();
00356
00368 void new_sub_path();
00369
00376 void move_to(double x, double y);
00377
00384 void line_to(double x, double y);
00385
00397 void curve_to(double x1, double y1, double x2, double y2, double x3, double y3);
00398
00438 void arc(double xc, double yc, double radius, double angle1, double angle2);
00439
00454 void arc_negative(double xc, double yc, double radius, double angle1, double angle2);
00455
00471 void rel_move_to(double dx, double dy);
00472
00490 void rel_line_to(double dx, double dy);
00491
00514 void rel_curve_to(double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);
00515
00534 void rectangle(double x, double y, double width, double height);
00535
00546 void close_path();
00547
00551 void paint();
00552
00560 void paint_with_alpha(double alpha);
00561
00568 void mask(const RefPtr<const Pattern>& pattern);
00569
00578 void mask(const RefPtr<const Surface>& surface, double surface_x, double surface_y);
00579
00590 void stroke();
00591
00602 void stroke_preserve();
00603
00611 void fill();
00612
00621 void fill_preserve();
00622 void copy_page();
00623 void show_page();
00624 bool in_stroke(double x, double y) const;
00625 bool in_fill(double x, double y) const;
00626 void get_stroke_extents(double& x1, double& y1, double& x2, double& y2) const;
00627 void get_fill_extents(double& x1, double& y1, double& x2, double& y2) const;
00628
00639 void reset_clip();
00640
00659 void clip();
00660
00671 void clip_preserve();
00672 void select_font_face(const std::string& family, FontSlant slant, FontWeight weight);
00673 void set_font_size(double size);
00674 void set_font_matrix(const Matrix& matrix);
00675 void get_font_matrix(Matrix& matrix) const;
00676 void set_font_options(const FontOptions& options);
00677 void show_text(const std::string& utf8);
00678 void show_glyphs(const std::vector<Glyph>& glyphs);
00679 RefPtr<FontFace> get_font_face();
00680 RefPtr<const FontFace> get_font_face() const;
00681 void get_font_extents(FontExtents& extents) const;
00682 void set_font_face(const RefPtr<const FontFace>& font_face);
00683 void get_text_extents(const std::string& utf8, TextExtents& extents) const;
00684 void get_glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents) const;
00685 void text_path(const std::string& utf8);
00686 void glyph_path(const std::vector<Glyph>& glyphs);
00687
00690 Operator get_operator() const;
00691
00694 RefPtr<Pattern> get_source();
00695 RefPtr<const Pattern> get_source() const;
00696
00699 double get_tolerance() const;
00700
00703 Antialias get_antialias() const;
00704
00719 void get_current_point (double& x, double& y) const;
00720
00723 FillRule get_fill_rule() const;
00724
00727 double get_line_width() const;
00728
00731 LineCap get_line_cap() const;
00732
00735 LineJoin get_line_join() const;
00736
00739 double get_miter_limit() const;
00740
00745 void get_matrix(Matrix& matrix);
00746
00751 RefPtr<Surface> get_target();
00752
00757 RefPtr<const Surface> get_target() const;
00758
00759
00768 Path* copy_path() const;
00769
00784 Path* copy_path_flat() const;
00785
00792 void append_path(const Path& path);
00793
00831 void push_group();
00832
00846 void push_group_with_content(Content content);
00847
00860 RefPtr<Pattern> pop_group();
00861
00881 void pop_group_to_source();
00882
00894 RefPtr<Surface> get_group_target();
00895
00899 RefPtr<const Surface> get_group_target() const;
00900
00903 typedef cairo_t cobject;
00904
00907 inline cobject* cobj() { return m_cobject; }
00908
00911 inline const cobject* cobj() const { return m_cobject; }
00912
00913 #ifndef DOXYGEN_IGNORE_THIS
00914
00915 inline ErrorStatus get_status() const
00916 { return cairo_status(const_cast<cairo_t*>(cobj())); }
00917
00918 void reference() const;
00919 void unreference() const;
00920 #endif //DOXYGEN_IGNORE_THIS
00921
00922 protected:
00923
00924
00925 cobject* m_cobject;
00926 };
00927
00928 }
00929
00930 #endif //__CAIROMM_CONTEXT_H
00931
00932