2005-01-29 20:54:48 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
2001-11-27 11:52:11 +08:00
|
|
|
*
|
2001-12-14 04:19:41 +08:00
|
|
|
* Object properties serialization routines
|
2002-03-24 01:58:57 +08:00
|
|
|
* Copyright (C) 2001-2002 Sven Neumann <sven@gimp.org>
|
2001-11-27 11:52:11 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2007-03-02 16:38:13 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2001-11-27 11:52:11 +08:00
|
|
|
*
|
2007-03-02 16:38:13 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2001-11-27 11:52:11 +08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-03-02 16:38:13 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
2001-11-27 11:52:11 +08:00
|
|
|
*
|
2007-03-02 16:38:13 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2001-11-27 11:52:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2011-04-28 21:50:39 +08:00
|
|
|
#include <cairo.h>
|
2012-05-03 09:36:22 +08:00
|
|
|
#include <gegl.h>
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2002-05-22 01:33:04 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2003-07-08 00:22:45 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2002-05-21 23:01:57 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
2005-01-26 04:30:20 +08:00
|
|
|
#include "gimpconfigtypes.h"
|
|
|
|
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "gimpconfigwriter.h"
|
|
|
|
#include "gimpconfig-iface.h"
|
2002-05-22 01:33:04 +08:00
|
|
|
#include "gimpconfig-params.h"
|
2016-10-18 00:55:50 +08:00
|
|
|
#include "gimpconfig-path.h"
|
2001-11-27 11:52:11 +08:00
|
|
|
#include "gimpconfig-serialize.h"
|
2002-05-04 07:48:03 +08:00
|
|
|
#include "gimpconfig-utils.h"
|
2001-11-27 11:52:11 +08:00
|
|
|
|
|
|
|
|
2010-06-30 02:57:52 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpconfig-serialize
|
|
|
|
* @title: GimpConfig-serialize
|
|
|
|
* @short_description: Serializing for libgimpconfig.
|
|
|
|
*
|
|
|
|
* Serializing interface for libgimpconfig.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2024-10-24 23:43:09 +08:00
|
|
|
static gboolean gimp_config_serialize_strv (const GValue *value,
|
|
|
|
GString *str);
|
|
|
|
static gboolean gimp_config_serialize_array (const GValue *value,
|
|
|
|
GString *str);
|
2024-10-18 04:08:16 +08:00
|
|
|
|
|
|
|
|
2002-03-24 01:58:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_config_serialize_properties:
|
2003-10-11 22:30:18 +08:00
|
|
|
* @config: a #GimpConfig.
|
2003-03-06 04:21:50 +08:00
|
|
|
* @writer: a #GimpConfigWriter.
|
2003-09-16 21:12:50 +08:00
|
|
|
*
|
2003-03-06 04:21:50 +08:00
|
|
|
* This function writes all object properties to the @writer.
|
2003-08-09 03:30:23 +08:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if serialization succeeded, %FALSE otherwise
|
2005-01-29 20:54:48 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2002-03-24 01:58:57 +08:00
|
|
|
**/
|
2002-05-15 19:05:32 +08:00
|
|
|
gboolean
|
2005-01-29 20:54:48 +08:00
|
|
|
gimp_config_serialize_properties (GimpConfig *config,
|
2003-03-06 04:21:50 +08:00
|
|
|
GimpConfigWriter *writer)
|
2001-11-27 11:52:11 +08:00
|
|
|
{
|
2001-12-08 00:10:53 +08:00
|
|
|
GObjectClass *klass;
|
|
|
|
GParamSpec **property_specs;
|
|
|
|
guint n_property_specs;
|
|
|
|
guint i;
|
2023-07-18 22:29:47 +08:00
|
|
|
gboolean success = TRUE;
|
2001-12-13 09:55:37 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), FALSE);
|
2003-09-16 21:12:50 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
klass = G_OBJECT_GET_CLASS (config);
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
property_specs = g_object_class_list_properties (klass, &n_property_specs);
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2002-05-15 19:05:32 +08:00
|
|
|
if (! property_specs)
|
2023-07-18 22:29:47 +08:00
|
|
|
return success;
|
2001-12-13 09:55:37 +08:00
|
|
|
|
2001-11-27 11:52:11 +08:00
|
|
|
for (i = 0; i < n_property_specs; i++)
|
|
|
|
{
|
2002-12-02 06:31:36 +08:00
|
|
|
GParamSpec *prop_spec = property_specs[i];
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2005-02-05 22:52:58 +08:00
|
|
|
if (! (prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE))
|
2001-11-27 11:52:11 +08:00
|
|
|
continue;
|
|
|
|
|
2023-07-18 22:29:47 +08:00
|
|
|
/* Some properties may fail writing, which shouldn't break serializing
|
|
|
|
* more properties, yet final result would be a (partial) failure.
|
|
|
|
*/
|
2003-10-11 22:30:18 +08:00
|
|
|
if (! gimp_config_serialize_property (config, prop_spec, writer))
|
2023-07-18 22:29:47 +08:00
|
|
|
success = FALSE;
|
2001-12-13 09:55:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (property_specs);
|
2002-05-15 19:05:32 +08:00
|
|
|
|
2023-07-18 22:29:47 +08:00
|
|
|
return success;
|
2001-12-13 09:55:37 +08:00
|
|
|
}
|
|
|
|
|
2002-03-24 01:58:57 +08:00
|
|
|
/**
|
2003-02-28 21:58:19 +08:00
|
|
|
* gimp_config_serialize_changed_properties:
|
2003-10-11 22:30:18 +08:00
|
|
|
* @config: a #GimpConfig.
|
2003-03-06 04:21:50 +08:00
|
|
|
* @writer: a #GimpConfigWriter.
|
2003-09-16 21:12:50 +08:00
|
|
|
*
|
2003-02-28 21:58:19 +08:00
|
|
|
* This function writes all object properties that have been changed from
|
2003-03-06 04:21:50 +08:00
|
|
|
* their default values to the @writer.
|
2003-08-09 03:30:23 +08:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if serialization succeeded, %FALSE otherwise
|
2005-01-29 20:54:48 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2002-03-24 01:58:57 +08:00
|
|
|
**/
|
2002-05-15 19:05:32 +08:00
|
|
|
gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_serialize_changed_properties (GimpConfig *config,
|
2003-03-06 04:21:50 +08:00
|
|
|
GimpConfigWriter *writer)
|
2003-02-28 21:58:19 +08:00
|
|
|
{
|
|
|
|
GObjectClass *klass;
|
|
|
|
GParamSpec **property_specs;
|
|
|
|
guint n_property_specs;
|
|
|
|
guint i;
|
2023-07-18 22:29:47 +08:00
|
|
|
GValue value = G_VALUE_INIT;
|
|
|
|
gboolean success = TRUE;
|
2003-02-28 21:58:19 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), FALSE);
|
2003-02-28 21:58:19 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
klass = G_OBJECT_GET_CLASS (config);
|
2003-02-28 21:58:19 +08:00
|
|
|
|
|
|
|
property_specs = g_object_class_list_properties (klass, &n_property_specs);
|
|
|
|
|
|
|
|
if (! property_specs)
|
2023-07-18 22:29:47 +08:00
|
|
|
return success;
|
2003-02-28 21:58:19 +08:00
|
|
|
|
|
|
|
for (i = 0; i < n_property_specs; i++)
|
|
|
|
{
|
|
|
|
GParamSpec *prop_spec = property_specs[i];
|
|
|
|
|
2005-02-05 22:52:58 +08:00
|
|
|
if (! (prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE))
|
2003-02-28 21:58:19 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
g_value_init (&value, prop_spec->value_type);
|
2003-10-11 22:30:18 +08:00
|
|
|
g_object_get_property (G_OBJECT (config), prop_spec->name, &value);
|
2003-02-28 21:58:19 +08:00
|
|
|
|
|
|
|
if (! g_param_value_defaults (prop_spec, &value))
|
|
|
|
{
|
2023-07-18 22:29:47 +08:00
|
|
|
/* Some properties may fail writing, which shouldn't break serializing
|
|
|
|
* more properties, yet final result would be a (partial) failure.
|
|
|
|
*/
|
2003-10-11 22:30:18 +08:00
|
|
|
if (! gimp_config_serialize_property (config, prop_spec, writer))
|
2023-07-18 22:29:47 +08:00
|
|
|
success = FALSE;
|
2003-02-28 21:58:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (property_specs);
|
|
|
|
|
2023-07-18 22:29:47 +08:00
|
|
|
return success;
|
2003-02-28 21:58:19 +08:00
|
|
|
}
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
2008-01-29 02:55:21 +08:00
|
|
|
* gimp_config_serialize_property:
|
|
|
|
* @config: a #GimpConfig.
|
|
|
|
* @param_spec: a #GParamSpec.
|
|
|
|
* @writer: a #GimpConfigWriter.
|
2005-01-29 20:54:48 +08:00
|
|
|
*
|
|
|
|
* This function serializes a single object property to the @writer.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if serialization succeeded, %FALSE otherwise
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-01-29 20:54:48 +08:00
|
|
|
**/
|
2002-12-02 06:31:36 +08:00
|
|
|
gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_serialize_property (GimpConfig *config,
|
2003-03-06 04:21:50 +08:00
|
|
|
GParamSpec *param_spec,
|
|
|
|
GimpConfigWriter *writer)
|
2002-12-02 06:31:36 +08:00
|
|
|
{
|
2006-08-08 20:29:48 +08:00
|
|
|
GimpConfigInterface *config_iface = NULL;
|
2004-02-19 20:30:18 +08:00
|
|
|
GimpConfigInterface *parent_iface = NULL;
|
2016-03-26 22:59:26 +08:00
|
|
|
GValue value = G_VALUE_INIT;
|
|
|
|
gboolean success = FALSE;
|
2002-12-02 06:31:36 +08:00
|
|
|
|
2005-02-05 22:52:58 +08:00
|
|
|
if (! (param_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE))
|
2002-12-02 06:31:36 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2024-08-31 07:37:14 +08:00
|
|
|
if (param_spec->flags & GIMP_CONFIG_PARAM_IGNORE ||
|
|
|
|
param_spec->flags & GIMP_PARAM_DONT_SERIALIZE)
|
2003-10-26 08:03:16 +08:00
|
|
|
return TRUE;
|
|
|
|
|
2002-12-02 06:31:36 +08:00
|
|
|
g_value_init (&value, param_spec->value_type);
|
2003-10-11 22:30:18 +08:00
|
|
|
g_object_get_property (G_OBJECT (config), param_spec->name, &value);
|
2002-12-02 06:31:36 +08:00
|
|
|
|
2005-02-05 22:52:58 +08:00
|
|
|
if (param_spec->flags & GIMP_CONFIG_PARAM_DEFAULTS &&
|
2003-10-26 08:03:16 +08:00
|
|
|
g_param_value_defaults (param_spec, &value))
|
|
|
|
{
|
|
|
|
g_value_unset (&value);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-08-08 20:29:48 +08:00
|
|
|
if (G_TYPE_IS_OBJECT (param_spec->owner_type))
|
2004-02-19 20:30:18 +08:00
|
|
|
{
|
2006-08-08 20:29:48 +08:00
|
|
|
GTypeClass *owner_class = g_type_class_peek (param_spec->owner_type);
|
|
|
|
|
|
|
|
config_iface = g_type_interface_peek (owner_class, GIMP_TYPE_CONFIG);
|
|
|
|
|
|
|
|
/* We must call serialize_property() *only* if the *exact* class
|
|
|
|
* which implements it is param_spec->owner_type's class.
|
|
|
|
*
|
|
|
|
* Therefore, we ask param_spec->owner_type's immediate parent class
|
|
|
|
* for it's GimpConfigInterface and check if we get a different
|
|
|
|
* pointer.
|
|
|
|
*
|
|
|
|
* (if the pointers are the same, param_spec->owner_type's
|
|
|
|
* GimpConfigInterface is inherited from one of it's parent classes
|
|
|
|
* and thus not able to handle param_spec->owner_type's properties).
|
|
|
|
*/
|
|
|
|
if (config_iface)
|
|
|
|
{
|
|
|
|
GTypeClass *owner_parent_class;
|
2004-02-19 20:30:18 +08:00
|
|
|
|
2006-08-08 20:29:48 +08:00
|
|
|
owner_parent_class = g_type_class_peek_parent (owner_class);
|
2004-02-19 20:30:18 +08:00
|
|
|
|
2006-08-08 20:29:48 +08:00
|
|
|
parent_iface = g_type_interface_peek (owner_parent_class,
|
|
|
|
GIMP_TYPE_CONFIG);
|
|
|
|
}
|
2004-02-19 20:30:18 +08:00
|
|
|
}
|
|
|
|
|
2002-12-02 06:31:36 +08:00
|
|
|
if (config_iface &&
|
2004-02-19 20:30:18 +08:00
|
|
|
config_iface != parent_iface && /* see comment above */
|
2003-02-08 23:27:51 +08:00
|
|
|
config_iface->serialize_property &&
|
2003-10-11 22:30:18 +08:00
|
|
|
config_iface->serialize_property (config,
|
2003-02-08 23:27:51 +08:00
|
|
|
param_spec->param_id,
|
|
|
|
(const GValue *) &value,
|
|
|
|
param_spec,
|
2003-03-06 04:21:50 +08:00
|
|
|
writer))
|
2002-12-02 06:31:36 +08:00
|
|
|
{
|
2003-02-08 23:27:51 +08:00
|
|
|
success = TRUE;
|
2002-12-02 06:31:36 +08:00
|
|
|
}
|
2003-02-08 23:27:51 +08:00
|
|
|
|
|
|
|
/* If there is no serialize_property() method *or* if it returned
|
|
|
|
* FALSE, continue with the default implementation
|
|
|
|
*/
|
|
|
|
|
2003-03-01 01:01:13 +08:00
|
|
|
if (! success)
|
2002-12-02 06:31:36 +08:00
|
|
|
{
|
2021-04-06 03:49:41 +08:00
|
|
|
if (G_VALUE_TYPE (&value) == GIMP_TYPE_PARASITE)
|
|
|
|
{
|
|
|
|
GimpParasite *parasite = g_value_get_boxed (&value);
|
|
|
|
|
|
|
|
gimp_config_writer_open (writer, param_spec->name);
|
|
|
|
|
|
|
|
if (parasite)
|
|
|
|
{
|
|
|
|
const gchar *name;
|
|
|
|
gconstpointer data;
|
|
|
|
guint32 data_length;
|
|
|
|
gulong flags;
|
|
|
|
|
|
|
|
name = gimp_parasite_get_name (parasite);
|
|
|
|
gimp_config_writer_string (writer, name);
|
|
|
|
|
|
|
|
flags = gimp_parasite_get_flags (parasite);
|
|
|
|
data = gimp_parasite_get_data (parasite, &data_length);
|
|
|
|
gimp_config_writer_printf (writer, "%lu %u", flags, data_length);
|
|
|
|
gimp_config_writer_data (writer, data_length, data);
|
|
|
|
|
|
|
|
success = TRUE;
|
|
|
|
}
|
|
|
|
|
2023-07-23 23:32:25 +08:00
|
|
|
if (success)
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
else
|
|
|
|
gimp_config_writer_revert (writer);
|
|
|
|
}
|
|
|
|
else if (G_VALUE_TYPE (&value) == G_TYPE_BYTES)
|
|
|
|
{
|
|
|
|
GBytes *bytes = g_value_get_boxed (&value);
|
|
|
|
|
|
|
|
gimp_config_writer_open (writer, param_spec->name);
|
|
|
|
|
|
|
|
if (bytes)
|
|
|
|
{
|
|
|
|
gconstpointer data;
|
|
|
|
gsize data_length;
|
|
|
|
|
|
|
|
data = g_bytes_get_data (bytes, &data_length);
|
|
|
|
|
2024-01-26 20:08:18 +08:00
|
|
|
gimp_config_writer_printf (writer, "%" G_GSIZE_FORMAT, data_length);
|
2023-07-23 23:32:25 +08:00
|
|
|
gimp_config_writer_data (writer, data_length, data);
|
|
|
|
}
|
2021-04-06 03:49:41 +08:00
|
|
|
else
|
2023-08-31 00:30:13 +08:00
|
|
|
{
|
|
|
|
gimp_config_writer_printf (writer, "%s", "NULL");
|
|
|
|
}
|
|
|
|
|
2023-11-15 09:28:34 +08:00
|
|
|
success = TRUE;
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
}
|
|
|
|
else if (GIMP_VALUE_HOLDS_COLOR (&value))
|
|
|
|
{
|
2023-12-11 12:53:52 +08:00
|
|
|
GeglColor *color = g_value_get_object (&value);
|
|
|
|
gboolean free_color = FALSE;
|
2023-11-15 09:28:34 +08:00
|
|
|
|
|
|
|
gimp_config_writer_open (writer, param_spec->name);
|
|
|
|
|
|
|
|
if (color)
|
|
|
|
{
|
|
|
|
const gchar *encoding;
|
|
|
|
const Babl *format = gegl_color_get_format (color);
|
2023-12-11 23:34:24 +08:00
|
|
|
const Babl *space;
|
2023-12-11 12:53:52 +08:00
|
|
|
GBytes *bytes;
|
2023-11-15 09:28:34 +08:00
|
|
|
gconstpointer data;
|
|
|
|
gsize data_length;
|
|
|
|
int profile_length = 0;
|
|
|
|
|
2023-12-11 23:34:24 +08:00
|
|
|
gimp_config_writer_open (writer, "color");
|
|
|
|
|
2023-12-11 12:53:52 +08:00
|
|
|
if (babl_format_is_palette (format))
|
|
|
|
{
|
|
|
|
guint8 pixel[40];
|
|
|
|
|
|
|
|
/* As a special case, we don't want to serialize
|
|
|
|
* palette colors, because they are just too much
|
|
|
|
* dependent on external data and cannot be
|
|
|
|
* deserialized back safely. So we convert them first.
|
|
|
|
*/
|
|
|
|
free_color = TRUE;
|
|
|
|
color = gegl_color_duplicate (color);
|
|
|
|
|
|
|
|
format = babl_format_with_space ("R'G'B'A u8", format);
|
|
|
|
gegl_color_get_pixel (color, format, pixel);
|
|
|
|
gegl_color_set_pixel (color, format, pixel);
|
|
|
|
}
|
|
|
|
|
2023-11-15 09:28:34 +08:00
|
|
|
encoding = babl_format_get_encoding (format);
|
|
|
|
gimp_config_writer_string (writer, encoding);
|
|
|
|
|
2023-12-11 12:53:52 +08:00
|
|
|
bytes = gegl_color_get_bytes (color, format);
|
|
|
|
data = g_bytes_get_data (bytes, &data_length);
|
2023-11-15 09:28:34 +08:00
|
|
|
|
2024-02-12 20:03:03 +08:00
|
|
|
gimp_config_writer_printf (writer, "%" G_GSIZE_FORMAT, data_length);
|
2023-11-15 09:28:34 +08:00
|
|
|
gimp_config_writer_data (writer, data_length, data);
|
|
|
|
|
2023-12-11 23:34:24 +08:00
|
|
|
space = babl_format_get_space (format);
|
|
|
|
if (space != babl_space ("sRGB"))
|
|
|
|
{
|
|
|
|
guint8 *profile_data;
|
|
|
|
|
|
|
|
profile_data = (guint8 *) babl_space_get_icc (babl_format_get_space (format),
|
|
|
|
&profile_length);
|
|
|
|
gimp_config_writer_printf (writer, "%u", profile_length);
|
|
|
|
if (profile_data)
|
|
|
|
gimp_config_writer_data (writer, profile_length, profile_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_config_writer_printf (writer, "%u", profile_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_bytes_unref (bytes);
|
|
|
|
|
|
|
|
gimp_config_writer_close (writer);
|
2023-11-15 09:28:34 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_config_writer_printf (writer, "%s", "NULL");
|
|
|
|
}
|
|
|
|
|
2023-08-31 00:30:13 +08:00
|
|
|
success = TRUE;
|
|
|
|
gimp_config_writer_close (writer);
|
2023-12-11 12:53:52 +08:00
|
|
|
|
|
|
|
if (free_color)
|
|
|
|
g_object_unref (color);
|
2021-04-06 03:49:41 +08:00
|
|
|
}
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-26 02:55:21 +08:00
|
|
|
else if (GIMP_VALUE_HOLDS_UNIT (&value))
|
|
|
|
{
|
|
|
|
GimpUnit *unit = g_value_get_object (&value);
|
|
|
|
|
|
|
|
gimp_config_writer_open (writer, param_spec->name);
|
|
|
|
|
|
|
|
if (unit)
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 22:02:47 +08:00
|
|
|
gimp_config_writer_printf (writer, "%s", gimp_unit_get_name (unit));
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-26 02:55:21 +08:00
|
|
|
else
|
|
|
|
gimp_config_writer_printf (writer, "%s", "NULL");
|
|
|
|
|
|
|
|
success = TRUE;
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
}
|
2021-04-06 03:49:41 +08:00
|
|
|
else if (G_VALUE_HOLDS_OBJECT (&value) &&
|
|
|
|
G_VALUE_TYPE (&value) != G_TYPE_FILE)
|
2003-03-01 01:01:13 +08:00
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
GimpConfigInterface *config_iface = NULL;
|
|
|
|
GimpConfig *prop_object;
|
2003-03-01 01:01:13 +08:00
|
|
|
|
|
|
|
prop_object = g_value_get_object (&value);
|
|
|
|
|
|
|
|
if (prop_object)
|
2020-05-10 21:23:55 +08:00
|
|
|
config_iface = GIMP_CONFIG_GET_IFACE (prop_object);
|
2003-03-01 01:01:13 +08:00
|
|
|
else
|
|
|
|
success = TRUE;
|
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
if (config_iface)
|
2003-04-13 03:06:25 +08:00
|
|
|
{
|
|
|
|
gimp_config_writer_open (writer, param_spec->name);
|
|
|
|
|
2005-02-05 22:52:58 +08:00
|
|
|
/* if the object property is not GIMP_CONFIG_PARAM_AGGREGATE,
|
2004-06-17 02:14:44 +08:00
|
|
|
* deserializing will need to know the exact type
|
|
|
|
* in order to create the object
|
|
|
|
*/
|
2005-02-05 22:52:58 +08:00
|
|
|
if (! (param_spec->flags & GIMP_CONFIG_PARAM_AGGREGATE))
|
2004-06-17 02:14:44 +08:00
|
|
|
{
|
|
|
|
GType object_type = G_TYPE_FROM_INSTANCE (prop_object);
|
|
|
|
|
|
|
|
gimp_config_writer_string (writer, g_type_name (object_type));
|
|
|
|
}
|
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
success = config_iface->serialize (prop_object, writer, NULL);
|
2003-04-13 03:06:25 +08:00
|
|
|
|
|
|
|
if (success)
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
else
|
|
|
|
gimp_config_writer_revert (writer);
|
|
|
|
}
|
2003-03-01 01:01:13 +08:00
|
|
|
}
|
2006-04-27 23:19:59 +08:00
|
|
|
else
|
2003-03-01 01:01:13 +08:00
|
|
|
{
|
2006-04-12 18:53:28 +08:00
|
|
|
GString *str = g_string_new (NULL);
|
2003-03-06 04:21:50 +08:00
|
|
|
|
2024-10-18 04:08:16 +08:00
|
|
|
success = gimp_config_serialize_value (&value, str, TRUE);
|
2003-03-06 04:21:50 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
if (success)
|
2003-04-13 03:06:25 +08:00
|
|
|
{
|
|
|
|
gimp_config_writer_open (writer, param_spec->name);
|
|
|
|
gimp_config_writer_print (writer, str->str, str->len);
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
}
|
2003-03-06 04:21:50 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
g_string_free (str, TRUE);
|
|
|
|
}
|
2003-03-01 01:01:13 +08:00
|
|
|
|
2003-04-13 03:06:25 +08:00
|
|
|
if (! success)
|
|
|
|
{
|
|
|
|
/* don't warn for empty string properties */
|
|
|
|
if (G_VALUE_HOLDS_STRING (&value))
|
|
|
|
{
|
|
|
|
success = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("couldn't serialize property %s::%s of type %s",
|
2003-10-11 22:30:18 +08:00
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (config)),
|
2003-09-16 21:12:50 +08:00
|
|
|
param_spec->name,
|
2003-04-13 03:06:25 +08:00
|
|
|
g_type_name (param_spec->value_type));
|
|
|
|
}
|
|
|
|
}
|
2002-12-02 06:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
2003-02-08 23:27:51 +08:00
|
|
|
return success;
|
2002-12-02 06:31:36 +08:00
|
|
|
}
|
|
|
|
|
2008-05-19 03:13:28 +08:00
|
|
|
/**
|
|
|
|
* gimp_config_serialize_property_by_name:
|
|
|
|
* @config: a #GimpConfig.
|
|
|
|
* @prop_name: the property's name.
|
|
|
|
* @writer: a #GimpConfigWriter.
|
|
|
|
*
|
|
|
|
* This function serializes a single object property to the @writer.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if serialization succeeded, %FALSE otherwise
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.6
|
2008-05-19 03:13:28 +08:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gimp_config_serialize_property_by_name (GimpConfig *config,
|
|
|
|
const gchar *prop_name,
|
|
|
|
GimpConfigWriter *writer)
|
|
|
|
{
|
|
|
|
GParamSpec *pspec;
|
|
|
|
|
|
|
|
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (config),
|
|
|
|
prop_name);
|
|
|
|
|
|
|
|
if (! pspec)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return gimp_config_serialize_property (config, pspec, writer);
|
|
|
|
}
|
|
|
|
|
2002-03-24 01:58:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_config_serialize_value:
|
|
|
|
* @value: a #GValue.
|
2010-06-30 04:19:11 +08:00
|
|
|
* @str: a #GString.
|
2002-05-06 19:04:39 +08:00
|
|
|
* @escaped: whether to escape string values.
|
2002-05-06 06:11:34 +08:00
|
|
|
*
|
2002-03-24 01:58:57 +08:00
|
|
|
* This utility function appends a string representation of #GValue to @str.
|
2003-09-16 21:12:50 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: %TRUE if serialization succeeded, %FALSE otherwise.
|
2005-01-29 20:54:48 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2002-03-24 01:58:57 +08:00
|
|
|
**/
|
2001-12-29 00:26:54 +08:00
|
|
|
gboolean
|
|
|
|
gimp_config_serialize_value (const GValue *value,
|
2002-05-06 19:04:39 +08:00
|
|
|
GString *str,
|
|
|
|
gboolean escaped)
|
2001-12-13 09:55:37 +08:00
|
|
|
{
|
2024-10-18 04:08:16 +08:00
|
|
|
if (G_VALUE_TYPE (value) == G_TYPE_STRV)
|
|
|
|
{
|
|
|
|
return gimp_config_serialize_strv (value, str);
|
|
|
|
}
|
|
|
|
|
2024-10-25 04:18:20 +08:00
|
|
|
if (GIMP_VALUE_HOLDS_INT32_ARRAY (value) ||
|
app, libgimp*, pdb, plug-ins: rename various public API name s/float/double/.
Several types functions were using the wording "float" historically to
mean double-precision, e.g. the float array type (which was in fact a
double array). Or the scanner function gimp_scanner_parse_float() was in
fact returning a double value. What if we wanted someday to actually add
float (usually this naming means in C the single-precision IEEE 754
floating point representation) support? How would we name this?
Now technically it's not entirely wrong (a double is still a floating
point). So I've been wondering if that is because maybe we never planned
to have float and double precision may be good enough for all usage in a
plug-in API (which doesn't have to be as generic so the higher precision
is enough)? But how can we be sure? Also we already had some functions
using the wording double (e.g. gimp_procedure_add_double_argument()), so
let's just go the safe route and use the accurate wording.
The additional change in PDB is internal, but there too, I was also
finding very confusing that we were naming double-precision float as
'float' type. So I took the opportunity to update this. It doesn't
change any signature.
In fact the whole commit doesn't change any type or code logic, only
naming, except for one bug fix in the middle which I encountered while
renaming: in gimp_scanner_parse_deprecated_color(), I discovered a
hidden bug in scanning (color-hsv*) values, which was mistakenly using a
double type for an array of float.
2024-11-02 21:03:37 +08:00
|
|
|
GIMP_VALUE_HOLDS_DOUBLE_ARRAY (value))
|
2024-10-24 23:43:09 +08:00
|
|
|
{
|
|
|
|
return gimp_config_serialize_array (value, str);
|
|
|
|
}
|
|
|
|
|
2001-12-13 09:55:37 +08:00
|
|
|
if (G_VALUE_HOLDS_BOOLEAN (value))
|
|
|
|
{
|
|
|
|
gboolean bool;
|
2003-09-16 21:12:50 +08:00
|
|
|
|
2001-12-13 09:55:37 +08:00
|
|
|
bool = g_value_get_boolean (value);
|
2002-05-06 06:11:34 +08:00
|
|
|
g_string_append (str, bool ? "yes" : "no");
|
2001-12-13 09:55:37 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
2003-09-16 21:12:50 +08:00
|
|
|
|
2001-12-13 09:55:37 +08:00
|
|
|
if (G_VALUE_HOLDS_ENUM (value))
|
|
|
|
{
|
2004-07-08 08:09:41 +08:00
|
|
|
GEnumClass *enum_class = g_type_class_peek (G_VALUE_TYPE (value));
|
|
|
|
GEnumValue *enum_value = g_enum_get_value (enum_class,
|
|
|
|
g_value_get_enum (value));
|
2001-12-13 09:55:37 +08:00
|
|
|
|
|
|
|
if (enum_value && enum_value->value_nick)
|
2001-12-12 07:10:59 +08:00
|
|
|
{
|
2001-12-13 09:55:37 +08:00
|
|
|
g_string_append (str, enum_value->value_nick);
|
|
|
|
return TRUE;
|
2001-12-12 07:10:59 +08:00
|
|
|
}
|
2001-12-13 09:55:37 +08:00
|
|
|
else
|
|
|
|
{
|
2003-09-16 21:12:50 +08:00
|
|
|
g_warning ("Couldn't get nick for enum_value of %s",
|
2001-12-13 09:55:37 +08:00
|
|
|
G_ENUM_CLASS_TYPE_NAME (enum_class));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2003-09-16 21:12:50 +08:00
|
|
|
|
2001-12-13 09:55:37 +08:00
|
|
|
if (G_VALUE_HOLDS_STRING (value))
|
|
|
|
{
|
|
|
|
const gchar *cstr = g_value_get_string (value);
|
2001-12-12 07:10:59 +08:00
|
|
|
|
2001-12-13 09:55:37 +08:00
|
|
|
if (!cstr)
|
|
|
|
return FALSE;
|
|
|
|
|
2002-05-06 19:04:39 +08:00
|
|
|
if (escaped)
|
2003-03-17 22:23:42 +08:00
|
|
|
gimp_config_string_append_escaped (str, cstr);
|
2002-05-06 19:04:39 +08:00
|
|
|
else
|
2003-03-17 22:23:42 +08:00
|
|
|
g_string_append (str, cstr);
|
|
|
|
|
2001-12-13 09:55:37 +08:00
|
|
|
return TRUE;
|
2001-11-27 11:52:11 +08:00
|
|
|
}
|
2001-12-13 09:55:37 +08:00
|
|
|
|
2002-04-15 17:40:08 +08:00
|
|
|
if (G_VALUE_HOLDS_DOUBLE (value) || G_VALUE_HOLDS_FLOAT (value))
|
|
|
|
{
|
|
|
|
gdouble v_double;
|
|
|
|
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
|
|
|
|
|
|
|
if (G_VALUE_HOLDS_DOUBLE (value))
|
|
|
|
v_double = g_value_get_double (value);
|
|
|
|
else
|
|
|
|
v_double = (gdouble) g_value_get_float (value);
|
|
|
|
|
2019-07-30 21:57:36 +08:00
|
|
|
g_ascii_dtostr (buf, sizeof (buf), v_double);
|
2002-04-15 17:40:08 +08:00
|
|
|
g_string_append (str, buf);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-07-08 00:22:45 +08:00
|
|
|
if (GIMP_VALUE_HOLDS_MATRIX2 (value))
|
|
|
|
{
|
|
|
|
GimpMatrix2 *trafo;
|
|
|
|
|
|
|
|
trafo = g_value_get_boxed (value);
|
|
|
|
|
2010-09-25 22:02:02 +08:00
|
|
|
if (trafo)
|
|
|
|
{
|
|
|
|
gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE];
|
|
|
|
gint i, j, k;
|
|
|
|
|
|
|
|
for (i = 0, k = 0; i < 2; i++)
|
|
|
|
for (j = 0; j < 2; j++, k++)
|
2019-07-30 21:57:36 +08:00
|
|
|
g_ascii_dtostr (buf[k], G_ASCII_DTOSTR_BUF_SIZE,
|
|
|
|
trafo->coeff[i][j]);
|
2010-09-25 22:02:02 +08:00
|
|
|
|
|
|
|
g_string_append_printf (str, "(matrix %s %s %s %s)",
|
|
|
|
buf[0], buf[1], buf[2], buf[3]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_string_append (str, "(matrix 1.0 1.0 1.0 1.0)");
|
|
|
|
}
|
2003-07-08 00:22:45 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
if (G_VALUE_TYPE (value) == GIMP_TYPE_VALUE_ARRAY)
|
2002-05-24 21:07:12 +08:00
|
|
|
{
|
2012-05-04 06:50:23 +08:00
|
|
|
GimpValueArray *array;
|
2002-05-24 21:07:12 +08:00
|
|
|
|
|
|
|
array = g_value_get_boxed (value);
|
|
|
|
|
|
|
|
if (array)
|
|
|
|
{
|
2012-05-04 06:50:23 +08:00
|
|
|
gint length = gimp_value_array_length (array);
|
2002-05-24 21:07:12 +08:00
|
|
|
gint i;
|
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
g_string_append_printf (str, "%d", length);
|
2002-05-24 21:07:12 +08:00
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
for (i = 0; i < length; i++)
|
2002-05-24 21:07:12 +08:00
|
|
|
{
|
|
|
|
g_string_append (str, " ");
|
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
if (! gimp_config_serialize_value (gimp_value_array_index (array,
|
|
|
|
i),
|
2003-03-01 01:01:13 +08:00
|
|
|
str, TRUE))
|
2002-05-24 21:07:12 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-14 06:56:17 +08:00
|
|
|
g_string_append (str, "0");
|
2002-05-24 21:07:12 +08:00
|
|
|
}
|
|
|
|
|
2002-05-21 23:01:57 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-05-09 04:21:15 +08:00
|
|
|
if (G_VALUE_TYPE (value) == G_TYPE_FILE)
|
|
|
|
{
|
|
|
|
GFile *file = g_value_get_object (value);
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
{
|
2025-01-23 00:15:28 +08:00
|
|
|
gchar *path = g_file_get_uri (file);
|
2016-10-18 00:55:50 +08:00
|
|
|
gchar *unexpand = NULL;
|
2016-05-09 04:21:15 +08:00
|
|
|
|
2016-10-18 00:55:50 +08:00
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
unexpand = gimp_config_path_unexpand (path, TRUE, NULL);
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unexpand)
|
|
|
|
{
|
|
|
|
if (escaped)
|
|
|
|
gimp_config_string_append_escaped (str, unexpand);
|
|
|
|
else
|
|
|
|
g_string_append (str, unexpand);
|
2016-05-09 04:21:15 +08:00
|
|
|
|
2016-10-18 00:55:50 +08:00
|
|
|
g_free (unexpand);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_string_append (str, "NULL");
|
|
|
|
}
|
2016-05-09 04:21:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_string_append (str, "NULL");
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-12-13 09:55:37 +08:00
|
|
|
if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING))
|
|
|
|
{
|
2016-03-26 22:59:26 +08:00
|
|
|
GValue tmp_value = G_VALUE_INIT;
|
2003-09-16 21:12:50 +08:00
|
|
|
|
2001-12-13 09:55:37 +08:00
|
|
|
g_value_init (&tmp_value, G_TYPE_STRING);
|
|
|
|
g_value_transform (value, &tmp_value);
|
|
|
|
|
|
|
|
g_string_append (str, g_value_get_string (&tmp_value));
|
|
|
|
|
|
|
|
g_value_unset (&tmp_value);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-09-16 21:12:50 +08:00
|
|
|
|
2001-12-13 09:55:37 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2024-10-18 04:08:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Private functions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_config_serialize_strv:
|
|
|
|
* @value: source #GValue holding a #GStrv
|
|
|
|
* @str: destination string
|
|
|
|
*
|
|
|
|
* Appends a string repr of the #GStrv value of #GValue to @str.
|
|
|
|
* Repr is an integer literal greater than or equal to zero,
|
|
|
|
* followed by a possibly empty sequence
|
|
|
|
* of quoted and escaped string literals.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE always
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
static gboolean
|
|
|
|
gimp_config_serialize_strv (const GValue *value,
|
|
|
|
GString *str)
|
|
|
|
{
|
|
|
|
GStrv gstrv;
|
|
|
|
|
|
|
|
gstrv = g_value_get_boxed (value);
|
|
|
|
|
|
|
|
if (gstrv)
|
|
|
|
{
|
|
|
|
gint length = g_strv_length (gstrv);
|
|
|
|
|
|
|
|
/* Write length */
|
|
|
|
g_string_append_printf (str, "%d", length);
|
|
|
|
|
|
|
|
for (gint i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
g_string_append (str, " "); /* separator */
|
|
|
|
gimp_config_string_append_escaped (str, gstrv[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* GValue has NULL value. Not quite the same as an empty GStrv.
|
|
|
|
* But handle it quietly as an empty GStrv: write a length of zero.
|
|
|
|
*/
|
|
|
|
g_string_append (str, "0");
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2024-10-24 23:43:09 +08:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_config_serialize_array (const GValue *value,
|
|
|
|
GString *str)
|
|
|
|
{
|
|
|
|
GimpArray *array;
|
|
|
|
|
2024-10-25 04:18:20 +08:00
|
|
|
g_return_val_if_fail (GIMP_VALUE_HOLDS_INT32_ARRAY (value) ||
|
app, libgimp*, pdb, plug-ins: rename various public API name s/float/double/.
Several types functions were using the wording "float" historically to
mean double-precision, e.g. the float array type (which was in fact a
double array). Or the scanner function gimp_scanner_parse_float() was in
fact returning a double value. What if we wanted someday to actually add
float (usually this naming means in C the single-precision IEEE 754
floating point representation) support? How would we name this?
Now technically it's not entirely wrong (a double is still a floating
point). So I've been wondering if that is because maybe we never planned
to have float and double precision may be good enough for all usage in a
plug-in API (which doesn't have to be as generic so the higher precision
is enough)? But how can we be sure? Also we already had some functions
using the wording double (e.g. gimp_procedure_add_double_argument()), so
let's just go the safe route and use the accurate wording.
The additional change in PDB is internal, but there too, I was also
finding very confusing that we were naming double-precision float as
'float' type. So I took the opportunity to update this. It doesn't
change any signature.
In fact the whole commit doesn't change any type or code logic, only
naming, except for one bug fix in the middle which I encountered while
renaming: in gimp_scanner_parse_deprecated_color(), I discovered a
hidden bug in scanning (color-hsv*) values, which was mistakenly using a
double type for an array of float.
2024-11-02 21:03:37 +08:00
|
|
|
GIMP_VALUE_HOLDS_DOUBLE_ARRAY (value), FALSE);
|
2024-10-24 23:43:09 +08:00
|
|
|
|
|
|
|
array = g_value_get_boxed (value);
|
|
|
|
|
|
|
|
if (array)
|
|
|
|
{
|
|
|
|
gint32 *values = (gint32 *) array->data;
|
2024-10-25 04:18:20 +08:00
|
|
|
gint length;
|
|
|
|
|
|
|
|
if (GIMP_VALUE_HOLDS_INT32_ARRAY (value))
|
|
|
|
length = array->length / sizeof (gint32);
|
|
|
|
else
|
|
|
|
length = array->length / sizeof (gdouble);
|
2024-10-24 23:43:09 +08:00
|
|
|
|
|
|
|
/* Write length */
|
|
|
|
g_string_append_printf (str, "%d", length);
|
|
|
|
|
|
|
|
for (gint i = 0; i < length; i++)
|
|
|
|
{
|
2024-10-25 04:18:20 +08:00
|
|
|
gchar *num_str;
|
|
|
|
|
|
|
|
if (GIMP_VALUE_HOLDS_INT32_ARRAY (value))
|
|
|
|
{
|
|
|
|
num_str = g_strdup_printf (" %d", values[i]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
|
|
|
|
|
|
|
g_ascii_dtostr (buf, sizeof (buf), ((gdouble *) values)[i]);
|
|
|
|
num_str = g_strdup_printf (" %s", buf);
|
|
|
|
}
|
2024-10-24 23:43:09 +08:00
|
|
|
|
2024-10-25 04:18:20 +08:00
|
|
|
g_string_append (str, num_str);
|
|
|
|
g_free (num_str);
|
2024-10-24 23:43:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_string_append (str, "0");
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|