mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-10-06 01:12:40 +02:00
app, libgimp*, plug-ins: int32 array arguments don't need a size argument anymore.
GimpArray (and therefore the int32 array typedef) contains its own size. We don't need to store the array size in a preceding argument. Also adding gimp_int32_array_get_values() and gimp_int32_array_set_values() to edit an existing GimpArray. This comes with the fact we should start making the GimpArray type more explicit, because clearly by trying to hide this type so much, it was too much looking like the int32 array param spec was expecting a C array (as was visible in the file-ico plug-in where we were getting a C array, which was a bug only made invisible by the fact we were not setting the C array back in the config object in the end). Last but not least, I finally implemented int32 array (de)serialization. As a side fix, the "images" arg in file-pdf-export-multi procedure is now a proper image array (not an int32 array), and of course the "count" arg was removed.
This commit is contained in:
@@ -85,6 +85,8 @@ static GTokenType gimp_config_deserialize_value_array (GValue *value,
|
||||
GimpConfig *config,
|
||||
GParamSpec *prop_spec,
|
||||
GScanner *scanner);
|
||||
static GTokenType gimp_config_deserialize_array (GValue *value,
|
||||
GScanner *scanner);
|
||||
static GTokenType gimp_config_deserialize_strv (GValue *value,
|
||||
GScanner *scanner);
|
||||
static GimpUnit * gimp_config_get_unit_from_identifier (const gchar *identifier);
|
||||
@@ -382,6 +384,10 @@ gimp_config_deserialize_value (GValue *value,
|
||||
{
|
||||
return gimp_config_deserialize_strv (value, scanner);
|
||||
}
|
||||
else if (prop_spec->value_type == GIMP_TYPE_INT32_ARRAY)
|
||||
{
|
||||
return gimp_config_deserialize_array (value, scanner);
|
||||
}
|
||||
else if (prop_spec->value_type == GIMP_TYPE_UNIT)
|
||||
{
|
||||
return gimp_config_deserialize_unit (value, prop_spec, scanner);
|
||||
@@ -926,6 +932,44 @@ gimp_config_deserialize_strv (GValue *value,
|
||||
return result_token;
|
||||
}
|
||||
|
||||
static GTokenType
|
||||
gimp_config_deserialize_array (GValue *value,
|
||||
GScanner *scanner)
|
||||
{
|
||||
gint32 *values;
|
||||
gint n_values;
|
||||
GTokenType result_token = G_TOKEN_RIGHT_PAREN;
|
||||
|
||||
if (! gimp_scanner_parse_int (scanner, &n_values))
|
||||
return G_TOKEN_INT;
|
||||
|
||||
values = g_new0 (gint32, n_values);
|
||||
|
||||
for (gint i = 0; i < n_values; i++)
|
||||
{
|
||||
gint value;
|
||||
|
||||
if (! gimp_scanner_parse_int (scanner, &value))
|
||||
{
|
||||
result_token = G_TOKEN_INT;
|
||||
break;
|
||||
}
|
||||
|
||||
values[i] = value;
|
||||
}
|
||||
|
||||
if (result_token == G_TOKEN_RIGHT_PAREN)
|
||||
{
|
||||
gimp_value_take_int32_array (value, values, n_values);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_scanner_error (scanner, "Missing value.");
|
||||
}
|
||||
|
||||
return result_token;
|
||||
}
|
||||
|
||||
static GimpUnit *
|
||||
gimp_config_get_unit_from_identifier (const gchar *identifier)
|
||||
{
|
||||
|
@@ -48,8 +48,10 @@
|
||||
**/
|
||||
|
||||
|
||||
static gboolean gimp_config_serialize_strv (const GValue *value,
|
||||
GString *str);
|
||||
static gboolean gimp_config_serialize_strv (const GValue *value,
|
||||
GString *str);
|
||||
static gboolean gimp_config_serialize_array (const GValue *value,
|
||||
GString *str);
|
||||
|
||||
|
||||
/**
|
||||
@@ -512,6 +514,11 @@ gimp_config_serialize_value (const GValue *value,
|
||||
return gimp_config_serialize_strv (value, str);
|
||||
}
|
||||
|
||||
if (GIMP_VALUE_HOLDS_INT32_ARRAY (value))
|
||||
{
|
||||
return gimp_config_serialize_array (value, str);
|
||||
}
|
||||
|
||||
if (G_VALUE_HOLDS_BOOLEAN (value))
|
||||
{
|
||||
gboolean bool;
|
||||
@@ -729,3 +736,38 @@ gimp_config_serialize_strv (const GValue *value,
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_config_serialize_array (const GValue *value,
|
||||
GString *str)
|
||||
{
|
||||
GimpArray *array;
|
||||
|
||||
g_return_val_if_fail (GIMP_VALUE_HOLDS_INT32_ARRAY (value), FALSE);
|
||||
|
||||
array = g_value_get_boxed (value);
|
||||
|
||||
if (array)
|
||||
{
|
||||
gint32 *values = (gint32 *) array->data;
|
||||
gint length = array->length / sizeof (gint32);
|
||||
|
||||
/* Write length */
|
||||
g_string_append_printf (str, "%d", length);
|
||||
|
||||
for (gint i = 0; i < length; i++)
|
||||
{
|
||||
gchar *istr;
|
||||
|
||||
istr = g_strdup_printf (" %d", values[i]);
|
||||
g_string_append (str, istr);
|
||||
g_free (istr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_string_append (str, "0");
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user