From ff141f9bb174c02bf87ff9786cb7f0e15f1a341b Mon Sep 17 00:00:00 2001 From: dvlierop2 Date: Wed, 25 Jul 2007 12:12:23 +0000 Subject: [PATCH] Add a method to create a rectangular curve --- src/display/curve.cpp | 17 +++++++++++++++++ src/display/curve.h | 2 ++ src/sp-image.cpp | 25 ++++++++----------------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/display/curve.cpp b/src/display/curve.cpp index 9e571fdd0..04af56990 100644 --- a/src/display/curve.cpp +++ b/src/display/curve.cpp @@ -124,6 +124,23 @@ SPCurve *sp_curve_new_from_foreign_bpath(NArtBpath const bpath[]) return curve; } +SPCurve *sp_curve_new_from_rect(NR::Maybe const &rect) +{ + g_return_val_if_fail(rect, NULL); + + SPCurve *c = sp_curve_new(); + + NR::Point p = rect->corner(0); + sp_curve_moveto(c, p); + + for (int i=3; i>=0; i--) { + sp_curve_lineto(c, rect->corner(i)); + } + sp_curve_closepath_current(c); + + return c; +} + /** * Increase refcount of curve. * diff --git a/src/display/curve.h b/src/display/curve.h index 5be8f5a4e..847d09f46 100644 --- a/src/display/curve.h +++ b/src/display/curve.h @@ -19,6 +19,7 @@ #include "libnr/nr-forward.h" #include "libnr/nr-point.h" +#include "libnr/nr-rect.h" /// Wrapper around NArtBpath. struct SPCurve { @@ -70,6 +71,7 @@ SPCurve *sp_curve_new(); SPCurve *sp_curve_new_sized(gint length); SPCurve *sp_curve_new_from_bpath(NArtBpath *bpath); SPCurve *sp_curve_new_from_foreign_bpath(NArtBpath const bpath[]); +SPCurve *sp_curve_new_from_rect(NR::Maybe const &rect); SPCurve *sp_curve_ref(SPCurve *curve); SPCurve *sp_curve_unref(SPCurve *curve); diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 9f6767050..d535874e9 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -36,6 +36,8 @@ #include "xml/quote.h" #include +#include "libnr/nr-matrix-fns.h" + #include "io/sys.h" #include #if ENABLE_LCMS @@ -1397,21 +1399,11 @@ sp_image_set_curve(SPImage *image) return; } - SPCurve *c = sp_curve_new(); - - double const x = image->x.computed; - double const y = image->y.computed; - double const w = image->width.computed; - double const h = image->height.computed; - - sp_curve_moveto(c, x, y); - sp_curve_lineto(c, x + w, y); - sp_curve_lineto(c, x + w, y + h); - sp_curve_lineto(c, x, y + h); - sp_curve_lineto(c, x, y); - - sp_curve_closepath_current(c); - + NRRect rect; + sp_image_bbox(image, &rect, NR::identity(), 0); + NR::Maybe rect2 = rect.upgrade(); + SPCurve *c = sp_curve_new_from_rect(rect2); + if (image->curve) { image->curve = sp_curve_unref(image->curve); } @@ -1420,8 +1412,7 @@ sp_image_set_curve(SPImage *image) image->curve = sp_curve_ref(c); } - sp_curve_unref(c); - + sp_curve_unref(c); } /** -- 2.30.2