summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@gnome.org>2007-03-21 20:56:38 +0000
committerJonathon Jongsma <jjongsma@gnome.org>2007-03-21 20:56:38 +0000
commit0979205a3e0b8b6c36f62a211d19c7c1be9cf711 (patch)
tree4865f7dc22b813c51a8c6f0c2cc16aaee69be417
parentc569f5b7168b9259eff80c97ababc840d6e01fa5 (diff)
2007-03-21 Jonathon Jongsma <jjongsma@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.
-rw-r--r--ChangeLog11
-rw-r--r--cairomm/context.cc39
-rw-r--r--cairomm/context.h40
-rw-r--r--cairomm/enums.h8
-rw-r--r--cairomm/pattern.cc62
-rw-r--r--cairomm/pattern.h93
-rw-r--r--configure.in8
7 files changed, 252 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 267cd28..332cb50 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-03-21 Jonathon Jongsma <jjongsma@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.
+
2007-02-01 Jonathon Jongsma <jonathon.jongsma@gmail.com>
* configure.in: Fixes for building on Cygwin from
diff --git a/cairomm/context.cc b/cairomm/context.cc
index 5f502c5..b9ac881 100644
--- a/cairomm/context.cc
+++ b/cairomm/context.cc
@@ -405,6 +405,32 @@ void Context::clip_preserve()
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 @@ double Context::get_miter_limit() const
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);
diff --git a/cairomm/context.h b/cairomm/context.h
index dcd3d83..c94e77f 100644
--- a/cairomm/context.h
+++ b/cairomm/context.h
@@ -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_glyph_t Glyph; //A simple struct.
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 @@ public:
* @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 @@ public:
*/
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 @@ public:
* @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.
*
diff --git a/cairomm/enums.h b/cairomm/enums.h
index e2023ed..0b5c40f 100644
--- a/cairomm/enums.h
+++ b/cairomm/enums.h
@@ -110,8 +110,9 @@ typedef enum
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 @@ typedef enum
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
diff --git a/cairomm/pattern.cc b/cairomm/pattern.cc
index 27638cd..3c30948 100644
--- a/cairomm/pattern.cc
+++ b/cairomm/pattern.cc
@@ -77,6 +77,14 @@ SolidPattern::SolidPattern(cairo_pattern_t* cobject, bool has_reference)
: 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 @@ SurfacePattern::SurfacePattern(const RefPtr<Surface>& surface)
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 @@ void Gradient::add_color_stop_rgba(double offset, double red, double green, doub
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 @@ LinearGradient::LinearGradient(double x0, double y0, double x1, double y1)
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 @@ RadialGradient::RadialGradient(double cx0, double cy0, double radius0, double cx
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));
diff --git a/cairomm/pattern.h b/cairomm/pattern.h
index 2624d7a..c0f3a48 100644
--- a/cairomm/pattern.h
+++ b/cairomm/pattern.h
@@ -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 @@ public:
*/
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 @@ public:
*/
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 @@ public:
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 @@ public:
*/
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 @@ public:
*/
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();
diff --git a/configure.in b/configure.in
index 93c25f5..2a55412 100644
--- a/configure.in
+++ b/configure.in
@@ -2,8 +2,8 @@ AC_INIT(cairomm/cairomm.h)
#release versioning
GENERIC_MAJOR_VERSION=1
-GENERIC_MINOR_VERSION=2
-GENERIC_MICRO_VERSION=5
+GENERIC_MINOR_VERSION=3
+GENERIC_MICRO_VERSION=0
GENERIC_VERSION=$GENERIC_MAJOR_VERSION.$GENERIC_MINOR_VERSION.$GENERIC_MICRO_VERSION
AC_SUBST(GENERIC_MAJOR_VERSION)
AC_SUBST(GENERIC_MINOR_VERSION)
@@ -11,7 +11,7 @@ AC_SUBST(GENERIC_MICRO_VERSION)
AC_SUBST(GENERIC_VERSION)
#shared library versioning
-GENERIC_LIBRARY_VERSION=1:0:0
+GENERIC_LIBRARY_VERSION=1:1:1
# | | |
# +------+ | +---+
# | | |
@@ -101,7 +101,7 @@ fi
AC_CHECK_HEADERS(string list map, , exit)
-PKG_CHECK_MODULES(CAIROMM, cairo >= 1.2.0)
+PKG_CHECK_MODULES(CAIROMM, cairo >= 1.3.10)
dnl Check whether to build the documentation directory