[cairo-commit] cairomm/cairomm context.cc, 1.16, 1.17 context.h, 1.19, 1.20 enums.h, 1.10, 1.11 pattern.cc, 1.8, 1.9 pattern.h, 1.11, 1.12

Jonathon Jongsma commit at pdx.freedesktop.org
Wed Mar 21 13:56:47 PDT 2007


Committed by: jjongsma

Update of /cvs/cairo/cairomm/cairomm
In directory kemper:/tmp/cvs-serv907/cairomm

Modified Files:
	context.cc context.h enums.h pattern.cc pattern.h 
Log Message:
2007-03-21  Jonathon Jongsma  <jjongsma at gnome.org>

	* cairomm/context.cc:
	* cairomm/context.h:
	* cairomm/enums.h:
	* cairomm/pattern.cc:
	* cairomm/pattern.h:
	* configure.in: Add initial support for new cairo 1.4.x API.  It will
	probably still need quite a bit of work, but I wanted to commit what I have
	now so that it doesn't keep sitting in my working directory.


Index: context.cc
===================================================================
RCS file: /cvs/cairo/cairomm/cairomm/context.cc,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- context.cc	19 Aug 2006 01:22:52 -0000	1.16
+++ context.cc	21 Mar 2007 20:56:39 -0000	1.17
@@ -405,6 +405,32 @@
   check_object_status_and_throw_exception(*this);
 }
 
+void Context::clip_extents(double& x1, double& y1, double& x2, double& y2)
+{
+  cairo_clip_extents(m_cobject, &x1, &y1, &x2, &y2);
+  check_object_status_and_throw_exception(*this);
+}
+
+void Context::copy_clip_rectangle_list(std::vector<Rectangle>& rectangles)
+{
+  cairo_rectangle_list_t* c_list = 0;
+  // FIXME: It would be nice if the cairo interface didn't copy it into a
+  // C array first and just let us do the copying...
+  c_list = cairo_copy_clip_rectangle_list(m_cobject);
+  // the rectangle list contains a status field that we need to check and the
+  // cairo context also has a status that we need to check
+  // FIXME: do we want to throw an exception if the clip can't be represented by
+  // rectangles?  or do we just want to return an empty list?
+  check_status_and_throw_exception(c_list->status);
+  check_object_status_and_throw_exception(*this);
+  // copy the C array into the passed C++ list
+  rectangles.assign(c_list->rectangles,
+                    c_list->rectangles + c_list->num_rectangles);
+  // free the memory allocated to the C array since we've copied it into a
+  // standard C++ container
+  cairo_rectangle_list_destroy(c_list);
+}
+
 void Context::select_font_face(const std::string& family, FontSlant slant, FontWeight weight)
 {
   cairo_select_font_face (m_cobject, family.c_str(),
@@ -575,6 +601,19 @@
   return result;
 }
 
+void
+Context::get_dash(std::vector<double>& dashes, double& offset)
+{
+  // FIXME: do we need to allocate this array dynamically?  I seem to remember
+  // some compilers have trouble with allocating arrays on the stack when the
+  // array size isn't a compiler constant...
+  const int cnt = cairo_get_dash_count(m_cobject);
+  double dash_array[cnt];
+  cairo_get_dash(m_cobject, dash_array, &offset);
+  check_object_status_and_throw_exception(*this);
+  dashes.assign(dash_array, dash_array + cnt);
+}
+
 void Context::get_matrix(Matrix& matrix)
 {
   cairo_get_matrix(m_cobject, &matrix);

Index: context.h
===================================================================
RCS file: /cvs/cairo/cairomm/cairomm/context.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- context.h	18 Aug 2006 17:03:33 -0000	1.19
+++ context.h	21 Mar 2007 20:56:39 -0000	1.20
@@ -19,6 +19,8 @@
 #ifndef __CAIROMM_CONTEXT_H
 #define __CAIROMM_CONTEXT_H
 
+#include <vector>
+#include <utility>
 #include <cairomm/surface.h>
 #include <cairomm/fontface.h>
 #include <cairomm/pattern.h>
@@ -35,6 +37,7 @@
 typedef cairo_font_extents_t FontExtents; //A simple struct.
 typedef cairo_text_extents_t TextExtents; //A simple struct.
 typedef cairo_matrix_t Matrix; //A simple struct. //TODO: Derive and add operator[] and operator. matrix multiplication?
+typedef cairo_rectangle_t Rectangle;
 
 /** Context is the main class used to draw in cairomm. 
  * In the simplest case, create a Context with its target Surface, set its
@@ -668,6 +671,30 @@
    * @sa set_fill_rule()
    */
   void clip_preserve();
+
+  /**
+   * Computes a bounding box in user coordinates covering the area inside the
+   * current clip.
+   *
+   * @param x1 left of the resulting extents
+   * @param y1 top of the resulting extents
+   * @param x2 right of the resulting extents
+   * @param y2 bottom of the resulting extents
+   *
+   * @since 1.4
+   **/
+  void clip_extents(double& x1, double& y1, double& x2, double& y2);
+
+  /**
+   * Returns the current clip region as a list of rectangles in user coordinates.
+   *
+   * This function will throw an exception if the clip region cannot be
+   * represented as a list of user-space rectangles.
+   *
+   * @Since 1.4
+   **/
+   void copy_clip_rectangle_list(std::vector<Rectangle>& rectangles);
+
   void select_font_face(const std::string& family, FontSlant slant, FontWeight weight);
   void set_font_size(double size);
   void set_font_matrix(const Matrix& matrix);
@@ -737,6 +764,17 @@
    */
   double get_miter_limit() const;
 
+  /**
+   * Gets the current dash array and offset.
+   *
+   * @param dashes return value for the dash array
+   * @param offset return value for the current dash offset
+   *
+   * Since: 1.4
+   **/
+  void get_dash(std::vector<double>& dashes, double& offset);
+
+
   /** Stores the current transformation matrix (CTM) into matrix.
    *
    * @param matrix	return value for the matrix
@@ -754,7 +792,7 @@
    * @exception
    */
   RefPtr<const Surface> get_target() const;
-  
+
   //TODO: Copy or reference-count a Path somethow instead of asking the caller to delete it?
   /** Creates a copy of the current path and returns it to the user.
    *

Index: enums.h
===================================================================
RCS file: /cvs/cairo/cairomm/cairomm/enums.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- enums.h	28 Jun 2006 00:26:10 -0000	1.10
+++ enums.h	21 Mar 2007 20:56:39 -0000	1.11
@@ -110,8 +110,9 @@
     FORMAT_ARGB32 = CAIRO_FORMAT_ARGB32,
     FORMAT_RGB24 = CAIRO_FORMAT_RGB24,
     FORMAT_A8 = CAIRO_FORMAT_A8,
-    FORMAT_A1 = CAIRO_FORMAT_A1,
-    FORMAT_RGB16_565 = CAIRO_FORMAT_RGB16_565
+    FORMAT_A1 = CAIRO_FORMAT_A1
+    // this enumeration has been deprecated
+    //FORMAT_RGB16_565 = CAIRO_FORMAT_RGB16_565
 } Format;
 
 
@@ -175,7 +176,8 @@
     SURFACE_TYPE_WIN32 = CAIRO_SURFACE_TYPE_WIN32,
     SURFACE_TYPE_BEOS = CAIRO_SURFACE_TYPE_BEOS,
     SURFACE_TYPE_DIRECTFB = CAIRO_SURFACE_TYPE_DIRECTFB,
-    SURFACE_TYPE_SVG = CAIRO_SURFACE_TYPE_SVG
+    SURFACE_TYPE_SVG = CAIRO_SURFACE_TYPE_SVG,
+    SURFACE_TYPE_OS2 = CAIRO_SURFACE_TYPE_OS2
 } SurfaceType;
 
 typedef enum

Index: pattern.cc
===================================================================
RCS file: /cvs/cairo/cairomm/cairomm/pattern.cc,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- pattern.cc	28 Jun 2006 00:26:10 -0000	1.8
+++ pattern.cc	21 Mar 2007 20:56:39 -0000	1.9
@@ -77,6 +77,14 @@
 : Pattern(cobject, has_reference)
 {
 }
+void
+SolidPattern::get_rgba (double& red, double& green,
+                        double& blue, double& alpha) const
+{
+  // ignore the return value since we know that this is a solid color pattern
+  cairo_pattern_get_rgba(m_cobject, &red, &green, &blue, &alpha);
+  check_object_status_and_throw_exception(*this);
+}
 
 SolidPattern::~SolidPattern()
 {
@@ -103,6 +111,16 @@
   check_object_status_and_throw_exception(*this); 
 }
 
+RefPtr<Surface>
+SurfacePattern::get_surface () const
+{
+  cairo_surface_t* surface = 0;
+  // we can ignore the return value since we know this is a surface pattern
+  cairo_pattern_get_surface(const_cast<cairo_pattern_t*>(m_cobject), &surface);
+  check_object_status_and_throw_exception(*this);
+  return RefPtr<Surface>(new Surface(surface, false /* does not have reference */));
+}
+
 RefPtr<SurfacePattern> SurfacePattern::create(const RefPtr<Surface>& surface)
 {
   return RefPtr<SurfacePattern>(new SurfacePattern(surface));
@@ -170,6 +188,27 @@
   check_object_status_and_throw_exception(*this);
 }
 
+std::vector<ColorStop>
+Gradient::get_color_stops ()
+{
+  // we could save a copy here by returning it as an output reference parameter
+  // instead of returning the array by value.
+  std::vector<ColorStop> stops;
+  int num_stops;
+  // we can ignore the return value since we know this is a gradient pattern
+  cairo_pattern_get_color_stop_count(m_cobject, &num_stops);
+  // since we know the total number of stops, we can avoid re-allocation with
+  // each addition to the vector
+  stops.reserve(num_stops);
+  for (int i = 0; i < num_stops; ++i)
+  {
+    ColorStop stop;
+    cairo_pattern_get_color_stop_rgba(m_cobject, i, &stop.offset, &stop.red,
+                                      &stop.green, &stop.blue, &stop.alpha);
+    stops.push_back(stop);
+  }
+  return stops;
+}
 
 
 LinearGradient::LinearGradient(double x0, double y0, double x1, double y1)
@@ -178,6 +217,17 @@
   check_object_status_and_throw_exception(*this); 
 }
 
+void
+LinearGradient::get_linear_points (double &x0, double &y0,
+                                   double &x1, double &y1) const
+{
+  // ignore the return value since we know that this is a linear gradient
+  // pattern
+  cairo_pattern_get_linear_points(m_cobject, &x0, &y0, &x1, &y1);
+  check_object_status_and_throw_exception(*this);
+}
+
+
 RefPtr<LinearGradient> LinearGradient::create(double x0, double y0, double x1, double y1)
 {
   return RefPtr<LinearGradient>(new LinearGradient(x0, y0, x1, y1));
@@ -199,6 +249,18 @@
   check_object_status_and_throw_exception(*this); 
 }
 
+void
+RadialGradient::get_radial_circles (double& x0, double& y0, double& r0,
+                                    double& x1, double& y1, double& r1) const
+{
+  // ignore the return value since we know that this is a radial gradient
+  // pattern
+  cairo_pattern_get_radial_circles (const_cast<cairo_pattern_t*>(m_cobject),
+                                    &x0, &y0, &r0, &x1, &y1, &r1);
+  check_object_status_and_throw_exception(*this); 
+}
+
+
 RefPtr<RadialGradient> RadialGradient::create(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1)
 {
   return RefPtr<RadialGradient>(new RadialGradient(cx0, cy0, radius0, cx1, cy1, radius1));

Index: pattern.h
===================================================================
RCS file: /cvs/cairo/cairomm/cairomm/pattern.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- pattern.h	5 Jul 2006 15:37:12 -0000	1.11
+++ pattern.h	21 Mar 2007 20:56:39 -0000	1.12
@@ -26,6 +26,11 @@
 
 namespace Cairo
 {
+struct ColorStop
+{
+  double offset;
+  double red, green, blue, alpha;
+};
 
 /**
  * This is a reference-counted object that should be used via Cairo::RefPtr.
@@ -83,8 +88,22 @@
    */
   explicit SolidPattern(cairo_pattern_t* cobject, bool has_reference = false);
 
+  /**
+   * Gets the solid color for a solid color pattern.
+   *
+   * @param red return value for red component of color
+   * @param green return value for green component of color
+   * @param blue return value for blue component of color
+   * @param alpha return value for alpha component of color
+   *
+   * @since 1.4
+   **/
+  void get_rgba (double& red, double& green,
+                 double& blue, double& alpha) const;
+
   static RefPtr<SolidPattern> create_rgb(double red, double green, double blue);
-  static RefPtr<SolidPattern> create_rgba(double red, double green, double blue, double alpha);
+  static RefPtr<SolidPattern> create_rgba(double red, double green,
+                                          double blue, double alpha);
 
   //TODO?: SolidPattern(cairo_pattern_t *target);
   virtual ~SolidPattern();
@@ -106,6 +125,12 @@
    */
   explicit SurfacePattern(cairo_pattern_t* cobject, bool has_reference = false);
 
+  /**
+   * Gets the surface associated with this pattern
+   *
+   * @since 1.4
+   **/
+  RefPtr<Surface> get_surface () const;
 
   virtual ~SurfacePattern();
 
@@ -134,9 +159,47 @@
 
   virtual ~Gradient();
 
+  /**
+   * Adds an opaque color stop to a gradient pattern. The offset
+   * specifies the location along the gradient's control vector. For
+   * example, a linear gradient's control vector is from (x0,y0) to
+   * (x1,y1) while a radial gradient's control vector is from any point
+   * on the start circle to the corresponding point on the end circle.
+   *
+   * The color is specified in the same way as in Context::set_source_rgb().
+   *
+   * @param offset an offset in the range [0.0 .. 1.0]
+   * @param red red component of color
+   * @param green green component of color
+   * @param blue blue component of color
+   **/
   void add_color_stop_rgb(double offset, double red, double green, double blue);
+
+  /**
+   * Adds a translucent color stop to a gradient pattern. The offset
+   * specifies the location along the gradient's control vector. For
+   * example, a linear gradient's control vector is from (x0,y0) to
+   * (x1,y1) while a radial gradient's control vector is from any point
+   * on the start circle to the corresponding point on the end circle.
+   *
+   * The color is specified in the same way as in Context::set_source_rgba().
+   *
+   * @param offset an offset in the range [0.0 .. 1.0]
+   * @param red red component of color
+   * @param green green component of color
+   * @param blue blue component of color
+   * @param alpha alpha component of color
+   */
   void add_color_stop_rgba(double offset, double red, double green, double blue, double alpha);
 
+  /*
+   * Gets the color stops and offsets for this Gradient
+   *
+   * @since 1.4
+   */
+  std::vector<ColorStop> get_color_stops ();
+
+
 protected:
   Gradient();
 };
@@ -155,6 +218,19 @@
    */
   explicit LinearGradient(cairo_pattern_t* cobject, bool has_reference = false);
 
+  /**
+   * @param x0 return value for the x coordinate of the first point
+   * @param y0 return value for the y coordinate of the first point
+   * @param x1 return value for the x coordinate of the second point
+   * @param y1 return value for the y coordinate of the second point
+   *
+   * Gets the gradient endpoints for a linear gradient.
+   *
+   * @since 1.4
+   **/
+  void get_linear_points (double &x0, double &y0,
+                          double &x1, double &y1) const;
+
   //TODO?: LinearGradient(cairo_pattern_t *target);
   virtual ~LinearGradient();
 
@@ -175,6 +251,21 @@
    */
   explicit RadialGradient(cairo_pattern_t* cobject, bool has_reference = false);
 
+  /**
+   * @param x0 return value for the x coordinate of the center of the first (inner) circle
+   * @param y0 return value for the y coordinate of the center of the first (inner) circle
+   * @param r0 return value for the radius of the first (inner) circle
+   * @param x1 return value for the x coordinate of the center of the second (outer) circle
+   * @param y1 return value for the y coordinate of the center of the second (outer) circle
+   * @param r1 return value for the radius of the second (outer) circle
+   *
+   * Gets the gradient endpoint circles for a radial gradient, each
+   * specified as a center coordinate and a radius.
+   *
+   * @since 1.4
+   **/
+  void get_radial_circles (double& x0, double& y0, double& r0,
+                           double& x1, double& y1, double& r1) const;
 
   //TODO?: RadialGradient(cairo_pattern_t *target);
   virtual ~RadialGradient();



More information about the cairo-commit mailing list