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
00049 class Context
00050 {
00051 protected:
00052 explicit Context(const RefPtr<Surface>& target);
00053
00054 public:
00055
00063 explicit Context(cairo_t* cobject, bool has_reference = false);
00064
00065 static RefPtr<Context> create(const RefPtr<Surface>& target);
00066
00067 virtual ~Context();
00068
00080 void save();
00081
00087 void restore();
00088
00095 void set_operator(Operator op);
00096
00114 void set_source(const RefPtr<const Pattern>& source);
00115
00130 void set_source_rgb(double red, double green, double blue);
00131
00148 void set_source_rgba(double red, double green, double blue, double alpha);
00149
00169 void set_source(const RefPtr<Surface>& surface, double x, double y);
00170
00180 void set_tolerance(double tolerance);
00181
00192 void set_antialias(Antialias antialias);
00193
00202 void set_fill_rule(FillRule fill_rule);
00203
00213 void set_line_width(double width);
00214
00224 void set_line_cap(LineCap line_cap);
00225
00235 void set_line_join(LineJoin line_join);
00236
00254 void set_dash(std::valarray<double>& dashes, double offset);
00255
00258 void unset_dash();
00259 void set_miter_limit(double limit);
00260
00270 void translate(double tx, double ty);
00271
00279 void scale(double sx, double sy);
00280
00290 void rotate(double angle_radians);
00291
00297 void rotate_degrees(double angle_degres);
00298
00305 void transform(const Matrix& matrix);
00306
00312 void set_matrix(const Matrix& matrix);
00313
00318 void set_identity_matrix();
00319
00326 void user_to_device(double& x, double& y);
00327
00335 void user_to_device_distance(double& dx, double& dy);
00336
00343 void device_to_user(double& x, double& y);
00344
00352 void device_to_user_distance(double& dx, double& dy);
00353
00354
00357 void clear_path();
00358
00365 void move_to(double x, double y);
00366
00373 void line_to(double x, double y);
00374
00386 void curve_to(double x1, double y1, double x2, double y2, double x3, double y3);
00387
00427 void arc(double xc, double yc, double radius, double angle1, double angle2);
00428
00443 void arc_negative(double xc, double yc, double radius, double angle1, double angle2);
00444
00460 void rel_move_to(double dx, double dy);
00461
00479 void rel_line_to(double dx, double dy);
00480
00503 void rel_curve_to(double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);
00504
00523 void rectangle(double x, double y, double width, double height);
00524
00535 void close_path();
00536
00540 void paint();
00541
00549 void paint_with_alpha(double alpha);
00550
00557 void mask(const RefPtr<Pattern>& pattern);
00558
00567 void mask(const RefPtr<Surface>& surface, double surface_x, double surface_y);
00568
00579 void stroke();
00580
00591 void stroke_preserve();
00592
00600 void fill();
00601
00610 void fill_preserve();
00611 void copy_page();
00612 void show_page();
00613 bool in_stroke(double x, double y) const;
00614 bool in_fill(double x, double y) const;
00615 void get_stroke_extents(double& x1, double& y1, double& x2, double& y2) const;
00616 void get_fill_extents(double& x1, double& y1, double& x2, double& y2) const;
00617
00628 void reset_clip();
00629
00648 void clip();
00649
00660 void clip_preserve();
00661 void select_font_face(const std::string& family, FontSlant slant, FontWeight weight);
00662 void set_font_size(double size);
00663 void set_font_matrix(const Matrix& matrix);
00664 void get_font_matrix(Matrix& matrix) const;
00665 void set_font_options(const FontOptions& options);
00666 void show_text(const std::string& utf8);
00667 void show_glyphs(const std::vector<Glyph>& glyphs);
00668 RefPtr<FontFace> get_font_face();
00669 RefPtr<const FontFace> get_font_face() const;
00670 void get_font_extents(FontExtents& extents) const;
00671 void set_font_face(const RefPtr<const FontFace>& font_face);
00672 void get_text_extents(const std::string& utf8, TextExtents& extents) const;
00673 void get_glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents) const;
00674 void text_path(const std::string& utf8);
00675 void glyph_path(const std::vector<Glyph>& glyphs);
00676
00679 Operator get_operator() const;
00680
00683 RefPtr<Pattern> get_source();
00684 RefPtr<const Pattern> get_source() const;
00685
00688 double get_tolerance() const;
00689
00692 Antialias get_antialias() const;
00693
00708 void get_current_point (double& x, double& y) const;
00709
00712 FillRule get_fill_rule() const;
00713
00716 double get_line_width() const;
00717
00720 LineCap get_line_cap() const;
00721
00724 LineJoin get_line_join() const;
00725
00728 double get_miter_limit() const;
00729
00734 void get_matrix(Matrix& matrix);
00735
00740 RefPtr<Surface> get_target();
00741
00746 RefPtr<const Surface> get_target() const;
00747
00748
00749 Path* copy_path() const;
00750 Path* copy_path_flat() const;
00751
00758 void append_path(const Path& path);
00759
00762 typedef cairo_t cobject;
00763
00766 inline cobject* cobj() { return m_cobject; }
00767
00770 inline const cobject* cobj() const { return m_cobject; }
00771
00772 #ifndef DOXYGEN_IGNORE_THIS
00773
00774 inline ErrorStatus get_status() const
00775 { return cairo_status(const_cast<cairo_t*>(cobj())); }
00776
00777 void reference() const;
00778 void unreference() const;
00779 #endif //DOXYGEN_IGNORE_THIS
00780
00781 protected:
00782
00783
00784 cobject* m_cobject;
00785 };
00786
00787 }
00788
00789 #endif //__CAIROMM_CONTEXT_H
00790
00791