app, libgimp, pdb: port GimpRasterizable interface to libgimp too.

This commit is contained in:
Jehan 2025-10-13 15:33:21 +02:00
parent d593cb3230
commit 67a04ba3b2
24 changed files with 819 additions and 7 deletions

View file

@ -40,6 +40,7 @@
#include "gimppalette.h"
#include "gimpparamspecs.h"
#include "gimppattern.h"
#include "gimprasterizable.h"
#include "gimpselection.h"
#include "path/gimppath.h"

View file

@ -30,7 +30,7 @@
#include "internal-procs.h"
/* 777 procedures registered total */
/* 780 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
@ -90,6 +90,7 @@ internal_procs_init (GimpPDB *pdb)
register_pdb_procs (pdb);
register_plug_in_procs (pdb);
register_progress_procs (pdb);
register_rasterizable_procs (pdb);
register_resource_procs (pdb);
register_selection_procs (pdb);
register_text_layer_procs (pdb);

View file

@ -77,6 +77,7 @@ void register_patterns_procs (GimpPDB *pdb);
void register_pdb_procs (GimpPDB *pdb);
void register_plug_in_procs (GimpPDB *pdb);
void register_progress_procs (GimpPDB *pdb);
void register_rasterizable_procs (GimpPDB *pdb);
void register_resource_procs (GimpPDB *pdb);
void register_selection_procs (GimpPDB *pdb);
void register_text_layer_procs (GimpPDB *pdb);

View file

@ -62,6 +62,7 @@ libappinternalprocs_sources = [
'pdb-cmds.c',
'plug-in-cmds.c',
'progress-cmds.c',
'rasterizable-cmds.c',
'resource-cmds.c',
'selection-cmds.c',
'text-layer-cmds.c',

220
app/pdb/rasterizable-cmds.c Normal file
View file

@ -0,0 +1,220 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* NOTE: This file is auto-generated by pdbgen.pl. */
#include "config.h"
#include "stamp-pdbgen.h"
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "libgimpbase/gimpbase.h"
#include "pdb-types.h"
#include "core/gimpparamspecs.h"
#include "core/gimprasterizable.h"
#include "gimppdb.h"
#include "gimppdberror.h"
#include "gimpprocedure.h"
#include "internal-procs.h"
#include "gimp-intl.h"
static GimpValueArray *
rasterizable_rasterize_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpRasterizable *item;
item = g_value_get_object (gimp_value_array_index (args, 0));
if (success)
{
if (! gimp_rasterizable_is_rasterized (GIMP_RASTERIZABLE (item)))
{
gimp_rasterizable_rasterize (GIMP_RASTERIZABLE (item));
}
else
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
_("This item has already been rasterized."));
success = FALSE;
}
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
rasterizable_restore_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpRasterizable *item;
item = g_value_get_object (gimp_value_array_index (args, 0));
if (success)
{
if (gimp_rasterizable_is_rasterized (GIMP_RASTERIZABLE (item)))
{
gimp_rasterizable_restore (GIMP_RASTERIZABLE (item));
}
else
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
_("This item has not been rasterized."));
success = FALSE;
}
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
rasterizable_is_rasterized_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
GimpRasterizable *item;
gboolean is_rasterized = FALSE;
item = g_value_get_object (gimp_value_array_index (args, 0));
if (success)
{
is_rasterized = gimp_rasterizable_is_rasterized (GIMP_RASTERIZABLE (item));
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_boolean (gimp_value_array_index (return_vals, 1), is_rasterized);
return return_vals;
}
void
register_rasterizable_procs (GimpPDB *pdb)
{
GimpProcedure *procedure;
/*
* gimp-rasterizable-rasterize
*/
procedure = gimp_procedure_new (rasterizable_rasterize_invoker, FALSE);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-rasterizable-rasterize");
gimp_procedure_set_static_help (procedure,
"Rasterize the object.",
"This procedure makes the item behave like a typical raster layer.\n"
"\n"
"Note that the source information (text contents and properties for a text layer, source file for a link layer, path and render properties for a vector layer, etc.) are not actually discarded, and it is possible to retrieve the original behavior with [method@Gimp.Rasterizable.restore].",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2025");
gimp_procedure_add_argument (procedure,
gimp_param_spec_rasterizable ("item",
"item",
"The rasterizable item",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-rasterizable-restore
*/
procedure = gimp_procedure_new (rasterizable_restore_invoker, FALSE);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-rasterizable-restore");
gimp_procedure_set_static_help (procedure,
"Revert the rasterization of @item.",
"Restore the information making the item non-destructive, such as text contents and properties of a text layer, source file of a link layer, path and render properties of a vector layer, etc.\n"
"This item won't behave anymore like a raster item. In particular, it will prevent direct modification of its pixels and will be rendered when its properties are updated.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2025");
gimp_procedure_add_argument (procedure,
gimp_param_spec_rasterizable ("item",
"item",
"The rasterizable item",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-rasterizable-is-rasterized
*/
procedure = gimp_procedure_new (rasterizable_is_rasterized_invoker, FALSE);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-rasterizable-is-rasterized");
gimp_procedure_set_static_help (procedure,
"Return whether @item has been rasterized.",
"This procedure returns %TRUE if the specified @item has been previously rasterized. In this case, you should treat this @item as the generic raster variant.\n"
"\n"
"For instance, a [class@Gimp.TextLayer] object implements the %GimpRasterizable interface. If a text layer instance were to return %TRUE, you should only consider its rendering as returned by [method@Gimp.Drawable.get_buffer].\n"
"\n"
"On the other hand, if this returned %FALSE, depending on your intents, you may prefer to use the text contents and its properties with the various procedures provided by the [class@Gimp.TextLayer] class interface.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2025");
gimp_procedure_add_argument (procedure,
gimp_param_spec_rasterizable ("item",
"item",
"The rasterizable item",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("is-rasterized",
"is rasterized",
"TRUE if @item is rasterized",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
}

View file

@ -739,6 +739,7 @@ EXPORTS
gimp_param_palette_get_type
gimp_param_path_get_type
gimp_param_pattern_get_type
gimp_param_rasterizable_get_type
gimp_param_resource_get_type
gimp_param_selection_get_type
gimp_param_spec_brush
@ -762,6 +763,7 @@ EXPORTS
gimp_param_spec_palette
gimp_param_spec_path
gimp_param_spec_pattern
gimp_param_spec_rasterizable
gimp_param_spec_resource
gimp_param_spec_resource_defaults_to_context
gimp_param_spec_resource_none_allowed
@ -1003,6 +1005,10 @@ EXPORTS
gimp_progress_uninstall
gimp_progress_update
gimp_quit
gimp_rasterizable_get_type
gimp_rasterizable_is_rasterized
gimp_rasterizable_rasterize
gimp_rasterizable_restore
gimp_resource_delete
gimp_resource_duplicate
gimp_resource_get_by_id

View file

@ -68,6 +68,7 @@
#include <libgimp/gimpprocedureconfig.h>
#include <libgimp/gimpprocedure-params.h>
#include <libgimp/gimpprogress.h>
#include <libgimp/gimprasterizable.h>
#include <libgimp/gimpresource.h>
#include <libgimp/gimpselection.h>
#include <libgimp/gimptextlayer.h>

View file

@ -78,6 +78,7 @@
#include <libgimp/gimppatterns_pdb.h>
#include <libgimp/gimppatternselect_pdb.h>
#include <libgimp/gimpprogress_pdb.h>
#include <libgimp/gimprasterizable_pdb.h>
#include <libgimp/gimpresource_pdb.h>
#include <libgimp/gimpselection_pdb.h>
#include <libgimp/gimptextlayer_pdb.h>

View file

@ -30,8 +30,8 @@ struct _GimpLinkLayer
};
G_DEFINE_TYPE (GimpLinkLayer, gimp_link_layer, GIMP_TYPE_LAYER)
G_DEFINE_TYPE_WITH_CODE (GimpLinkLayer, gimp_link_layer, GIMP_TYPE_LAYER,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_RASTERIZABLE, NULL))
#define parent_class gimp_link_layer_parent_class

View file

@ -692,6 +692,87 @@ gimp_param_spec_link_layer (const gchar *name,
}
/*
* GIMP_TYPE_PARAM_RASTERIZABLE
*/
static void gimp_param_rasterizable_class_init (GParamSpecClass *klass);
static void gimp_param_rasterizable_init (GParamSpec *pspec);
GType
gimp_param_rasterizable_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_rasterizable_class_init,
NULL, NULL,
sizeof (GimpParamSpecItem),
0,
(GInstanceInitFunc) gimp_param_rasterizable_init
};
type = g_type_register_static (GIMP_TYPE_PARAM_DRAWABLE,
"GimpParamRasterizable", &info, 0);
}
return type;
}
static void
gimp_param_rasterizable_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_RASTERIZABLE;
}
static void
gimp_param_rasterizable_init (GParamSpec *pspec)
{
}
/**
* gimp_param_spec_rasterizable:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecRasterizable specifying a
* [type@Rasterizable] property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer floating): The newly created
* #GimpParamSpecRasterizable.
*
* Since: 3.2
**/
GParamSpec *
gimp_param_spec_rasterizable (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
GParamFlags flags)
{
GimpParamSpecItem *ispec;
ispec = g_param_spec_internal (GIMP_TYPE_PARAM_RASTERIZABLE,
name, nick, blurb, flags);
g_return_val_if_fail (ispec, NULL);
ispec->none_ok = none_ok ? TRUE : FALSE;
return G_PARAM_SPEC (ispec);
}
/*
* GIMP_TYPE_PARAM_GROUP_LAYER
*/

View file

@ -164,6 +164,24 @@ GParamSpec * gimp_param_spec_link_layer (const gchar *name,
gboolean none_ok,
GParamFlags flags);
/*
* GIMP_TYPE_PARAM_RASTERIZABLE
*/
#define GIMP_VALUE_HOLDS_RASTERIZABLE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_RASTERIZABLE))
#define GIMP_TYPE_PARAM_RASTERIZABLE (gimp_param_rasterizable_get_type ())
#define GIMP_IS_PARAM_SPEC_RASTERIZABLE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_RASTERIZABLE))
GType gimp_param_rasterizable_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_rasterizable (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
GParamFlags flags);
/*
* GIMP_TYPE_PARAM_GROUP_LAYER
*/

View file

@ -337,6 +337,18 @@ G_BEGIN_DECLS
g_value_set_object (gimp_value_array_index (args, n), value)
/* rasterizable */
#define GIMP_VALUES_GET_RASTERIZABLE(args, n) \
g_value_get_object (gimp_value_array_index (args, n))
#define GIMP_VALUES_GET_RASTERIZABLE_ID(args, n) \
gimp_item_get_id (g_value_get_object (gimp_value_array_index (args, n)))
#define GIMP_VALUES_SET_RASTERIZABLE(args, n, value) \
g_value_set_object (gimp_value_array_index (args, n), value)
/* group layer */
#define GIMP_VALUES_GET_GROUP_LAYER(args, n) \

View file

@ -0,0 +1,32 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimprasterizable.c
* Copyright (C) 2025 Jehan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gimp.h"
G_DEFINE_INTERFACE (GimpRasterizable, gimp_rasterizable, GIMP_TYPE_DRAWABLE)
static void
gimp_rasterizable_default_init (GimpRasterizableInterface *iface)
{
}

View file

@ -0,0 +1,48 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimprasterizable.h
* Copyright (C) 2025 Jehan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_H_INSIDE__) && !defined (GIMP_COMPILATION)
#error "Only <libgimp/gimp.h> can be included directly."
#endif
#ifndef __GIMP_RASTERIZABLE_H__
#define __GIMP_RASTERIZABLE_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
#include <libgimp/gimpdrawable.h>
#define GIMP_TYPE_RASTERIZABLE (gimp_rasterizable_get_type ())
G_DECLARE_INTERFACE (GimpRasterizable, gimp_rasterizable, GIMP, RASTERIZABLE, GimpDrawable)
struct _GimpRasterizableInterface
{
GTypeInterface base_iface;
};
G_END_DECLS
#endif /* __GIMP_RASTERIZABLE_H__ */

View file

@ -0,0 +1,166 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
*
* gimprasterizable_pdb.c
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
/* NOTE: This file is auto-generated by pdbgen.pl */
#include "config.h"
#include "stamp-pdbgen.h"
#include "gimp.h"
/**
* SECTION: gimprasterizable
* @title: gimprasterizable
* @short_description: Functions for querying and manipulating rasterizable items.
*
* Functions for querying and manipulating rasterizable items.
**/
/**
* gimp_rasterizable_rasterize:
* @item: The rasterizable item.
*
* Rasterize the object.
*
* This procedure makes the item behave like a typical raster layer.
*
* Note that the source information (text contents and properties for a
* text layer, source file for a link layer, path and render properties
* for a vector layer, etc.) are not actually discarded, and it is
* possible to retrieve the original behavior with
* [method@Gimp.Rasterizable.restore].
*
* Returns: TRUE on success.
*
* Since: 3.2
**/
gboolean
gimp_rasterizable_rasterize (GimpRasterizable *item)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean success = TRUE;
args = gimp_value_array_new_from_types (NULL,
GIMP_TYPE_RASTERIZABLE, item,
G_TYPE_NONE);
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-rasterizable-rasterize",
args);
gimp_value_array_unref (args);
success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
gimp_value_array_unref (return_vals);
return success;
}
/**
* gimp_rasterizable_restore:
* @item: The rasterizable item.
*
* Revert the rasterization of @item.
*
* Restore the information making the item non-destructive, such as
* text contents and properties of a text layer, source file of a link
* layer, path and render properties of a vector layer, etc.
* This item won't behave anymore like a raster item. In particular, it
* will prevent direct modification of its pixels and will be rendered
* when its properties are updated.
*
* Returns: TRUE on success.
*
* Since: 3.2
**/
gboolean
gimp_rasterizable_restore (GimpRasterizable *item)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean success = TRUE;
args = gimp_value_array_new_from_types (NULL,
GIMP_TYPE_RASTERIZABLE, item,
G_TYPE_NONE);
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-rasterizable-restore",
args);
gimp_value_array_unref (args);
success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
gimp_value_array_unref (return_vals);
return success;
}
/**
* gimp_rasterizable_is_rasterized:
* @item: The rasterizable item.
*
* Return whether @item has been rasterized.
*
* This procedure returns %TRUE if the specified @item has been
* previously rasterized. In this case, you should treat this @item as
* the generic raster variant.
*
* For instance, a [class@Gimp.TextLayer] object implements the
* %GimpRasterizable interface. If a text layer instance were to return
* %TRUE, you should only consider its rendering as returned by
* [method@Gimp.Drawable.get_buffer].
*
* On the other hand, if this returned %FALSE, depending on your
* intents, you may prefer to use the text contents and its properties
* with the various procedures provided by the [class@Gimp.TextLayer]
* class interface.
*
* Returns: TRUE if @item is rasterized.
*
* Since: 3.2
**/
gboolean
gimp_rasterizable_is_rasterized (GimpRasterizable *item)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean is_rasterized = FALSE;
args = gimp_value_array_new_from_types (NULL,
GIMP_TYPE_RASTERIZABLE, item,
G_TYPE_NONE);
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-rasterizable-is-rasterized",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
is_rasterized = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
gimp_value_array_unref (return_vals);
return is_rasterized;
}

View file

@ -0,0 +1,42 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
*
* gimprasterizable_pdb.h
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
/* NOTE: This file is auto-generated by pdbgen.pl */
#if !defined (__GIMP_H_INSIDE__) && !defined (GIMP_COMPILATION)
#error "Only <libgimp/gimp.h> can be included directly."
#endif
#ifndef __GIMP_RASTERIZABLE_PDB_H__
#define __GIMP_RASTERIZABLE_PDB_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
gboolean gimp_rasterizable_rasterize (GimpRasterizable *item);
gboolean gimp_rasterizable_restore (GimpRasterizable *item);
gboolean gimp_rasterizable_is_rasterized (GimpRasterizable *item);
G_END_DECLS
#endif /* __GIMP_RASTERIZABLE_PDB_H__ */

View file

@ -30,8 +30,8 @@ struct _GimpTextLayer
};
G_DEFINE_TYPE (GimpTextLayer, gimp_text_layer, GIMP_TYPE_LAYER)
G_DEFINE_TYPE_WITH_CODE (GimpTextLayer, gimp_text_layer, GIMP_TYPE_LAYER,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_RASTERIZABLE, NULL))
#define parent_class gimp_text_layer_parent_class

View file

@ -29,8 +29,8 @@ struct _GimpVectorLayer
};
G_DEFINE_TYPE (GimpVectorLayer, gimp_vector_layer, GIMP_TYPE_LAYER)
G_DEFINE_TYPE_WITH_CODE (GimpVectorLayer, gimp_vector_layer, GIMP_TYPE_LAYER,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_RASTERIZABLE, NULL))
#define parent_class gimp_vector_layer_parent_class

View file

@ -110,6 +110,7 @@ pdb_wrappers_sources = [
'gimppatterns_pdb.c',
'gimppatternselect_pdb.c',
'gimpprogress_pdb.c',
'gimprasterizable_pdb.c',
'gimpresource_pdb.c',
'gimpselection_pdb.c',
'gimptextlayer_pdb.c',
@ -171,6 +172,7 @@ pdb_wrappers_headers = [
'gimppatterns_pdb.h',
'gimppatternselect_pdb.h',
'gimpprogress_pdb.h',
'gimprasterizable_pdb.h',
'gimpresource_pdb.h',
'gimpselection_pdb.h',
'gimptextlayer_pdb.h',
@ -214,6 +216,7 @@ libgimp_sources_introspectable = [
'gimpprocedure-params.c',
'gimpprocedureconfig.c',
'gimpprogress.c',
'gimprasterizable.c',
'gimpresource.c',
'gimpexportprocedure.c',
'gimpselection.c',
@ -278,6 +281,7 @@ libgimp_headers_introspectable = [
'gimpprocedure-params.h',
'gimpprocedureconfig.h',
'gimpprogress.h',
'gimprasterizable.h',
'gimpresource.h',
'gimpexportprocedure.h',
'gimpselection.h',

View file

@ -401,6 +401,16 @@ gimp_param_spec_link_layer ("$name",
"$blurb",
$none_ok,
$flags)
CODE
}
elsif ($pdbtype eq 'rasterizable') {
$none_ok = exists $arg->{none_ok} ? 'TRUE' : 'FALSE';
$pspec = <<CODE;
gimp_param_spec_rasterizable ("$name",
"$nick",
"$blurb",
$none_ok,
$flags)
CODE
}
elsif ($pdbtype eq 'layer') {

View file

@ -53,6 +53,7 @@
pdb
plug_in
progress
rasterizable
resource
selection
text_layer

153
pdb/groups/rasterizable.pdb Normal file
View file

@ -0,0 +1,153 @@
# GIMP - The GNU Image Manipulation Program
# Copyright (C) 1995 Spencer Kimball and Peter Mattis
# Rasterizable PDB API
# Copyright (C) 2025 Jehan
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
sub rasterizable_rasterize {
$blurb = 'Rasterize the object.';
$help = <<'HELP';
This procedure makes the item behave like a typical raster layer.
Note that the source information (text contents and properties for a
text layer, source file for a link layer, path and render properties for
a vector layer, etc.) are not actually discarded, and it is possible to
retrieve the original behavior with [method@Gimp.Rasterizable.restore].
HELP
&jehan_pdb_misc('2025', '3.2');
@inargs = (
{ name => 'item', type => 'rasterizable',
desc => 'The rasterizable item' }
);
%invoke = (
code => <<'CODE'
{
if (! gimp_rasterizable_is_rasterized (GIMP_RASTERIZABLE (item)))
{
gimp_rasterizable_rasterize (GIMP_RASTERIZABLE (item));
}
else
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
_("This item has already been rasterized."));
success = FALSE;
}
}
CODE
);
}
sub rasterizable_restore {
$blurb = 'Revert the rasterization of @item.';
$help = <<'HELP';
Restore the information making the item non-destructive, such as text
contents and properties of a text layer, source file of a link layer,
path and render properties of a vector layer, etc.
This item won't behave anymore like a raster item. In particular, it
will prevent direct modification of its pixels and will be rendered when
its properties are updated.
HELP
&jehan_pdb_misc('2025', '3.2');
@inargs = (
{ name => 'item', type => 'rasterizable',
desc => 'The rasterizable item' }
);
%invoke = (
code => <<'CODE'
{
if (gimp_rasterizable_is_rasterized (GIMP_RASTERIZABLE (item)))
{
gimp_rasterizable_restore (GIMP_RASTERIZABLE (item));
}
else
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
_("This item has not been rasterized."));
success = FALSE;
}
}
CODE
);
}
sub rasterizable_is_rasterized {
$blurb = 'Return whether @item has been rasterized.';
$help = <<'HELP';
This procedure returns %TRUE if the specified @item has been previously
rasterized. In this case, you should treat this @item as the generic
raster variant.
For instance, a [class@Gimp.TextLayer] object implements the
%GimpRasterizable interface. If a text layer instance were to return
%TRUE, you should only consider its rendering as returned by
[method@Gimp.Drawable.get_buffer].
On the other hand, if this returned %FALSE, depending on your intents,
you may prefer to use the text contents and its properties with the
various procedures provided by the [class@Gimp.TextLayer] class interface.
HELP
&jehan_pdb_misc('2025', '3.2');
@inargs = (
{ name => 'item', type => 'rasterizable',
desc => 'The rasterizable item' }
);
@outargs = (
{ name => 'is_rasterized', type => 'boolean',
desc => 'TRUE if @item is rasterized' }
);
%invoke = (
code => <<'CODE'
{
is_rasterized = gimp_rasterizable_is_rasterized (GIMP_RASTERIZABLE (item));
}
CODE
);
}
@headers = qw("core/gimprasterizable.h"
"gimppdberror.h"
"gimp-intl.h");
@procs = qw(rasterizable_rasterize
rasterizable_restore
rasterizable_is_rasterized);
%exports = (app => [@procs], lib => [@procs]);
$desc = 'Rasterizable procedures';
$doc_title = 'gimprasterizable';
$doc_short_desc = 'Functions for querying and manipulating rasterizable items.';
$doc_long_desc = 'Functions for querying and manipulating rasterizable items.';
1;

View file

@ -55,6 +55,7 @@ pdb_names = [
'pdb',
'plug_in',
'progress',
'rasterizable',
'resource',
'selection',
'text_layer',

View file

@ -395,6 +395,18 @@ package Gimp::CodeGen::pdb;
take_value_func => 'g_value_set_object ($value, $var)',
headers => [ qw("core/gimplinklayer.h") ] },
rasterizable => { name => 'RASTERIZABLE',
gtype => 'GIMP_TYPE_RASTERIZABLE',
type => 'GimpRasterizable *',
const_type => 'GimpRasterizable *',
init_value => 'NULL',
out_annotate => '(transfer none)',
get_value_func => '$var = g_value_get_object ($value)',
dup_value_func => '$var = GIMP_VALUES_GET_RASTERIZABLE ($value)',
set_value_func => 'g_value_set_object ($value, $var)',
take_value_func => 'g_value_set_object ($value, $var)',
headers => [ qw("core/gimprasterizable.h") ] },
group_layer => { name => 'GROUP_LAYER',
gtype => 'GIMP_TYPE_GROUP_LAYER',
type => 'GimpGroupLayer *',