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 <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; //A simple struct.
00035 typedef cairo_font_extents_t FontExtents; //A simple struct.
00036 typedef cairo_text_extents_t TextExtents; //A simple struct.
00037 typedef cairo_matrix_t Matrix; //A simple struct. //TODO: Derive and add operator[] and operator. matrix multiplication?
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 
00354   void begin_new_path();
00355 
00367   void begin_new_sub_path();
00368 
00375   void move_to(double x, double y);
00376 
00383   void line_to(double x, double y);
00384 
00396   void curve_to(double x1, double y1, double x2, double y2, double x3, double y3);
00397 
00437   void arc(double xc, double yc, double radius, double angle1, double angle2);
00438 
00453   void arc_negative(double xc, double yc, double radius, double angle1, double angle2);
00454 
00470   void rel_move_to(double dx, double dy);
00471 
00489   void rel_line_to(double dx, double dy);
00490 
00513   void rel_curve_to(double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);
00514 
00533   void rectangle(double x, double y, double width, double height);
00534 
00545   void close_path();
00546 
00550   void paint();
00551 
00559   void paint_with_alpha(double alpha);
00560 
00567   void mask(const RefPtr<const Pattern>& pattern);
00568 
00577   void mask(const RefPtr<const Surface>& surface, double surface_x, double surface_y);
00578 
00589   void stroke();
00590 
00601   void stroke_preserve();
00602 
00610   void fill();
00611 
00620   void fill_preserve();
00621   void copy_page();
00622   void show_page();
00623   bool in_stroke(double x, double y) const;
00624   bool in_fill(double x, double y) const;
00625   void get_stroke_extents(double& x1, double& y1, double& x2, double& y2) const;
00626   void get_fill_extents(double& x1, double& y1, double& x2, double& y2) const;
00627 
00638   void reset_clip();
00639 
00658   void clip();
00659 
00670   void clip_preserve();
00671   void select_font_face(const std::string& family, FontSlant slant, FontWeight weight);
00672   void set_font_size(double size);
00673   void set_font_matrix(const Matrix& matrix);
00674   void get_font_matrix(Matrix& matrix) const;
00675   void set_font_options(const FontOptions& options);
00676   void show_text(const std::string& utf8);
00677   void show_glyphs(const std::vector<Glyph>& glyphs);
00678   RefPtr<FontFace> get_font_face();
00679   RefPtr<const FontFace> get_font_face() const;
00680   void get_font_extents(FontExtents& extents) const;
00681   void set_font_face(const RefPtr<const FontFace>& font_face);
00682   void get_text_extents(const std::string& utf8, TextExtents& extents) const;
00683   void get_glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents) const;
00684   void text_path(const std::string& utf8);
00685   void glyph_path(const std::vector<Glyph>& glyphs);
00686 
00689   Operator get_operator() const;
00690 
00693   RefPtr<Pattern> get_source();
00694   RefPtr<const Pattern> get_source() const;
00695 
00698   double get_tolerance() const;
00699 
00702   Antialias get_antialias() const;
00703 
00718   void get_current_point (double& x, double& y) const;
00719 
00722   FillRule get_fill_rule() const;
00723 
00726   double get_line_width() const;
00727 
00730   LineCap get_line_cap() const;
00731 
00734   LineJoin get_line_join() const;
00735 
00738   double get_miter_limit() const;
00739 
00744   void get_matrix(Matrix& matrix);
00745 
00750   RefPtr<Surface> get_target();
00751 
00756   RefPtr<const Surface> get_target() const;
00757   
00758   //TODO: Copy or reference-count a Path somethow instead of asking the caller to delete it?
00767   Path* copy_path() const;
00768 
00783   Path* copy_path_flat() const;
00784 
00791   void append_path(const Path& path);
00792 
00830   void push_group();
00831 
00845   void push_group_with_content(Content content);
00846 
00859   RefPtr<Pattern> pop_group();
00860 
00880   void pop_group_to_source();
00881 
00893   RefPtr<Surface> get_group_target();
00894 
00898   RefPtr<const Surface> get_group_target() const;
00899 
00902   typedef cairo_t cobject;
00903 
00906   inline cobject* cobj() { return m_cobject; }
00907 
00910   inline const cobject* cobj() const { return m_cobject; }
00911  
00912   #ifndef DOXYGEN_IGNORE_THIS
00914   inline ErrorStatus get_status() const
00915   { return cairo_status(const_cast<cairo_t*>(cobj())); }
00916 
00917   void reference() const;
00918   void unreference() const;
00919   #endif //DOXYGEN_IGNORE_THIS
00920 
00921 protected:
00922 
00923  
00924   cobject* m_cobject;
00925 };
00926 
00927 } // namespace Cairo
00928 
00929 #endif //__CAIROMM_CONTEXT_H
00930 
00931 // vim: ts=2 sw=2 et

Generated on Tue Aug 22 04:01:06 2006 for cairomm by  doxygen 1.4.7