From 3d19e4acfb339c804daa3ecf9b97e48fea3265a8 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Wed, 11 Nov 2015 00:34:11 +0100 Subject: [PATCH] app: add imp_dash_pattern_from,to_double_array() which converts stroke dash pattern from/to arrays as used in the PDB. --- app/core/gimpdashpattern.c | 63 +++++++++++++++++++++++++++++++++++--- app/core/gimpdashpattern.h | 5 +++ 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/app/core/gimpdashpattern.c b/app/core/gimpdashpattern.c index 0d4d2f2612..60ffcf7c26 100644 --- a/app/core/gimpdashpattern.c +++ b/app/core/gimpdashpattern.c @@ -251,11 +251,7 @@ gimp_dash_pattern_from_value_array (GimpValueArray *value_array) GimpValueArray * gimp_dash_pattern_to_value_array (GArray *pattern) { - if (pattern == NULL || pattern->len == 0) - { - return NULL; - } - else + if (pattern != NULL && pattern->len > 0) { GimpValueArray *value_array = gimp_value_array_new (pattern->len); GValue item = { 0, }; @@ -273,6 +269,63 @@ gimp_dash_pattern_to_value_array (GArray *pattern) return value_array; } + + return NULL; +} + +GArray * +gimp_dash_pattern_from_double_array (gint n_dashes, + const gdouble *dashes) +{ + if (n_dashes > 0 && dashes != NULL) + { + GArray *pattern; + gint i; + + pattern = g_array_new (FALSE, FALSE, sizeof (gdouble)); + + for (i = 0; i < n_dashes; i++) + { + if (dashes[i] >= 0.0) + { + g_array_append_val (pattern, dashes[i]); + } + else + { + g_array_free (pattern, TRUE); + return NULL; + } + } + + return pattern; + } + + return NULL; +} + +gdouble * +gimp_dash_pattern_to_double_array (GArray *pattern, + gint *n_dashes) +{ + if (pattern != NULL && pattern->len > 0) + { + gdouble *dashes; + gint i; + + dashes = g_new0 (gdouble, pattern->len); + + for (i = 0; i < pattern->len; i++) + { + dashes[i] = g_array_index (pattern, gdouble, i); + } + + if (n_dashes) + *n_dashes = pattern->len; + + return dashes; + } + + return NULL; } GArray * diff --git a/app/core/gimpdashpattern.h b/app/core/gimpdashpattern.h index 24821c29a6..138cc4f01e 100644 --- a/app/core/gimpdashpattern.h +++ b/app/core/gimpdashpattern.h @@ -41,6 +41,11 @@ void gimp_dash_pattern_fill_segments (GArray *pattern, GArray * gimp_dash_pattern_from_value_array (GimpValueArray *value_array); GimpValueArray * gimp_dash_pattern_to_value_array (GArray *pattern); +GArray * gimp_dash_pattern_from_double_array (gint n_dashes, + const gdouble *dashes); +gdouble * gimp_dash_pattern_to_double_array (GArray *pattern, + gint *n_dashes); + GArray * gimp_dash_pattern_copy (GArray *pattern); void gimp_dash_pattern_free (GArray *pattern);