context.h

Go to the documentation of this file.
00001 /* Copyright (C) 2005 The cairomm Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Library General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2 of the License, or (at your option) any later version.
00007  *
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Library General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Library General Public
00014  * License along with this library; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00016  * 02110-1301, USA.
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; //A simple struct.
00037 typedef cairo_font_extents_t FontExtents; //A simple struct.
00038 typedef cairo_text_extents_t TextExtents; //A simple struct.
00039 typedef cairo_matrix_t Matrix; //A simple struct. //TODO: Derive and add operator[] and operator. matrix multiplication?
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 
00752   void get_current_point (double& x, double& y) const;
00753 
00756   bool has_current_point() const;
00757 
00760   FillRule get_fill_rule() const;
00761 
00764   double get_line_width() const;
00765 
00768   LineCap get_line_cap() const;
00769 
00772   LineJoin get_line_join() const;
00773 
00776   double get_miter_limit() const;
00777 
00786   void get_dash(std::vector<double>& dashes, double& offset) const;
00787 
00788 
00793   void get_matrix(Matrix& matrix);
00794 
00799   RefPtr<Surface> get_target();
00800 
00805   RefPtr<const Surface> get_target() const;
00806 
00807   //TODO: Copy or reference-count a Path somethow instead of asking the caller to delete it?
00816   Path* copy_path() const;
00817 
00846   void get_path_extents(double& x1, double& y1, double& x2, double& y2) const;
00847 
00862   Path* copy_path_flat() const;
00863 
00870   void append_path(const Path& path);
00871 
00909   void push_group();
00910 
00924   void push_group_with_content(Content content);
00925 
00938   RefPtr<Pattern> pop_group();
00939 
00959   void pop_group_to_source();
00960 
00972   RefPtr<Surface> get_group_target();
00973 
00977   RefPtr<const Surface> get_group_target() const;
00978 
00981   typedef cairo_t cobject;
00982 
00985   inline cobject* cobj() { return m_cobject; }
00986 
00989   inline const cobject* cobj() const { return m_cobject; }
00990  
00991   #ifndef DOXYGEN_IGNORE_THIS
00993   inline ErrorStatus get_status() const
00994   { return cairo_status(const_cast<cairo_t*>(cobj())); }
00995 
00996   void reference() const;
00997   void unreference() const;
00998   #endif //DOXYGEN_IGNORE_THIS
00999 
01000 protected:
01001 
01002  
01003   cobject* m_cobject;
01004 };
01005 
01006 } // namespace Cairo
01007 
01008 #endif //__CAIROMM_CONTEXT_H
01009 
01010 // vim: ts=2 sw=2 et

Generated on Thu Sep 4 21:57:13 2008 for cairomm by  doxygen 1.5.5