From cf9cfbb4ab2a1086c51e57f55e522c7b7bb0c5ee Mon Sep 17 00:00:00 2001 From: Jehan Date: Wed, 15 Oct 2025 00:10:54 +0200 Subject: [PATCH] app, libgimp, pdb: new procedures gimp_vector_layer_get_(fill|stroke)_pattern(). --- app/pdb/internal-procs.c | 2 +- app/pdb/vector-layer-cmds.c | 187 ++++++++++++++++++++++++++++++++-- libgimp/gimp.def | 2 + libgimp/gimpvectorlayer_pdb.c | 88 ++++++++++++++++ libgimp/gimpvectorlayer_pdb.h | 2 + pdb/groups/vector_layer.pdb | 132 +++++++++++++++++++++++- 6 files changed, 400 insertions(+), 13 deletions(-) diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index 728af399f3..7745233b04 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -30,7 +30,7 @@ #include "internal-procs.h" -/* 777 procedures registered total */ +/* 779 procedures registered total */ void internal_procs_init (GimpPDB *pdb) diff --git a/app/pdb/vector-layer-cmds.c b/app/pdb/vector-layer-cmds.c index f50cb35157..b753cd2129 100644 --- a/app/pdb/vector-layer-cmds.c +++ b/app/pdb/vector-layer-cmds.c @@ -38,6 +38,7 @@ #include "core/gimpdashpattern.h" #include "core/gimpimage.h" #include "core/gimpparamspecs.h" +#include "core/gimppattern.h" #include "core/gimprasterizable.h" #include "core/gimpstrokeoptions.h" #include "path/gimppath.h" @@ -225,9 +226,16 @@ vector_layer_get_fill_color_invoker (GimpProcedure *procedure, success = FALSE; if (success) - color = - gegl_color_duplicate (gimp_context_get_foreground ( - GIMP_CONTEXT (options->fill_options))); + { + GimpCustomStyle style = gimp_fill_options_get_custom_style (options->fill_options); + + if (style == GIMP_CUSTOM_STYLE_SOLID_COLOR || + ! gimp_context_get_pattern (GIMP_CONTEXT (options->fill_options))) + color = + gegl_color_duplicate (gimp_context_get_foreground (GIMP_CONTEXT (options->fill_options))); + else + success = FALSE; + } } return_vals = gimp_procedure_get_return_values (procedure, success, @@ -239,6 +247,50 @@ vector_layer_get_fill_color_invoker (GimpProcedure *procedure, return return_vals; } +static GimpValueArray * +vector_layer_get_fill_pattern_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpValueArray *return_vals; + GimpVectorLayer *layer; + GimpPattern *pattern = NULL; + + layer = g_value_get_object (gimp_value_array_index (args, 0)); + + if (success) + { + GimpVectorLayerOptions *options; + + options = gimp_vector_layer_get_options (layer); + if (! options) + success = FALSE; + + if (success) + { + GimpCustomStyle style = gimp_fill_options_get_custom_style (options->fill_options); + + if (style == GIMP_CUSTOM_STYLE_PATTERN) + pattern = gimp_context_get_pattern (GIMP_CONTEXT (options->fill_options)); + + if (pattern == NULL) + success = FALSE; + } + } + + return_vals = gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); + + if (success) + g_value_set_object (gimp_value_array_index (return_vals, 1), pattern); + + return return_vals; +} + static GimpValueArray * vector_layer_get_path_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -331,8 +383,15 @@ vector_layer_get_stroke_color_invoker (GimpProcedure *procedure, success = FALSE; if (success) - color = gegl_color_duplicate (gimp_context_get_foreground ( - GIMP_CONTEXT (options->stroke_options))); + { + GimpCustomStyle style = gimp_fill_options_get_custom_style (GIMP_FILL_OPTIONS (options->stroke_options)); + + if (style == GIMP_CUSTOM_STYLE_SOLID_COLOR || + ! gimp_context_get_pattern (GIMP_CONTEXT (options->stroke_options))) + color = gegl_color_duplicate (gimp_context_get_foreground (GIMP_CONTEXT (options->stroke_options))); + else + success = FALSE; + } } return_vals = gimp_procedure_get_return_values (procedure, success, @@ -344,6 +403,50 @@ vector_layer_get_stroke_color_invoker (GimpProcedure *procedure, return return_vals; } +static GimpValueArray * +vector_layer_get_stroke_pattern_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpValueArray *return_vals; + GimpVectorLayer *layer; + GimpPattern *pattern = NULL; + + layer = g_value_get_object (gimp_value_array_index (args, 0)); + + if (success) + { + GimpVectorLayerOptions *options; + + options = gimp_vector_layer_get_options (layer); + if (! options) + success = FALSE; + + if (success) + { + GimpCustomStyle style = gimp_fill_options_get_custom_style (GIMP_FILL_OPTIONS (options->stroke_options)); + + if (style == GIMP_CUSTOM_STYLE_PATTERN) + pattern = gimp_context_get_pattern (GIMP_CONTEXT (options->stroke_options)); + + if (pattern == NULL) + success = FALSE; + } + } + + return_vals = gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); + + if (success) + g_value_set_object (gimp_value_array_index (return_vals, 1), pattern); + + return return_vals; +} + static GimpValueArray * vector_layer_get_stroke_dash_offset_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -1074,7 +1177,9 @@ register_vector_layer_procs (GimpPDB *pdb) "gimp-vector-layer-get-fill-color"); gimp_procedure_set_static_help (procedure, "Get the color of the fill in a vector layer.", - "This procedure returns the color of the fill in a vector layer.", + "This procedure returns the color of the fill in a vector layer.\n" + "\n" + "Note that there won't be both a fill color and pattern, so either this procedure or [method@Gimp.VectorLayer.get_fill_pattern] will return %NULL at any given time.", NULL); gimp_procedure_set_static_attribution (procedure, "Alex S.", @@ -1096,6 +1201,39 @@ register_vector_layer_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-vector-layer-get-fill-pattern + */ + procedure = gimp_procedure_new (vector_layer_get_fill_pattern_invoker, FALSE); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-vector-layer-get-fill-pattern"); + gimp_procedure_set_static_help (procedure, + "Get the pattern of the fill in a vector layer.", + "This procedure returns the pattern of the fill in a vector layer.\n" + "\n" + "Note that there won't be both a fill color and pattern, so either this procedure or [method@Gimp.VectorLayer.get_fill_color] will return %NULL at any given time.", + NULL); + gimp_procedure_set_static_attribution (procedure, + "Jehan", + "Jehan", + "2025"); + gimp_procedure_add_argument (procedure, + gimp_param_spec_vector_layer ("layer", + "layer", + "The vector layer.", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_pattern ("pattern", + "pattern", + "The pattern of the fill.", + FALSE, + NULL, + FALSE, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-vector-layer-get-path */ @@ -1163,7 +1301,9 @@ register_vector_layer_procs (GimpPDB *pdb) "gimp-vector-layer-get-stroke-color"); gimp_procedure_set_static_help (procedure, "Get the color of the stroke in a vector layer.", - "This procedure returns the color of the stroke in a vector layer.", + "This procedure returns the color of the stroke in a vector layer.\n" + "\n" + "Note that there won't be both a stroke color and pattern, so either this procedure or [method@Gimp.VectorLayer.get_stroke_pattern] will return %NULL at any given time.", NULL); gimp_procedure_set_static_attribution (procedure, "Alex S.", @@ -1185,6 +1325,39 @@ register_vector_layer_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-vector-layer-get-stroke-pattern + */ + procedure = gimp_procedure_new (vector_layer_get_stroke_pattern_invoker, FALSE); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-vector-layer-get-stroke-pattern"); + gimp_procedure_set_static_help (procedure, + "Get the pattern of the stroke in a vector layer.", + "This procedure returns the pattern of the fill in a vector layer.\n" + "\n" + "Note that there won't be both a stroke color and pattern, so either this procedure or [method@Gimp.VectorLayer.get_stroke_color] will return %NULL at any given time.", + NULL); + gimp_procedure_set_static_attribution (procedure, + "Jehan", + "Jehan", + "2025"); + gimp_procedure_add_argument (procedure, + gimp_param_spec_vector_layer ("layer", + "layer", + "The vector layer.", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_pattern ("pattern", + "pattern", + "The pattern of the fill.", + FALSE, + NULL, + FALSE, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-vector-layer-get-stroke-dash-offset */ diff --git a/libgimp/gimp.def b/libgimp/gimp.def index 94530ee13f..1c8b854073 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -1115,6 +1115,7 @@ EXPORTS gimp_vector_layer_get_enable_fill gimp_vector_layer_get_enable_stroke gimp_vector_layer_get_fill_color + gimp_vector_layer_get_fill_pattern gimp_vector_layer_get_path gimp_vector_layer_get_stroke_cap_style gimp_vector_layer_get_stroke_color @@ -1122,6 +1123,7 @@ EXPORTS gimp_vector_layer_get_stroke_dash_pattern gimp_vector_layer_get_stroke_join_style gimp_vector_layer_get_stroke_miter_limit + gimp_vector_layer_get_stroke_pattern gimp_vector_layer_get_stroke_width gimp_vector_layer_get_stroke_width_unit gimp_vector_layer_get_type diff --git a/libgimp/gimpvectorlayer_pdb.c b/libgimp/gimpvectorlayer_pdb.c index 0ec8e36215..a620bd9a79 100644 --- a/libgimp/gimpvectorlayer_pdb.c +++ b/libgimp/gimpvectorlayer_pdb.c @@ -204,6 +204,10 @@ gimp_vector_layer_get_enable_stroke (GimpVectorLayer *layer) * * This procedure returns the color of the fill in a vector layer. * + * Note that there won't be both a fill color and pattern, so either + * this procedure or [method@Gimp.VectorLayer.get_fill_pattern] will + * return %NULL at any given time. + * * Returns: (transfer full): The color of the fill. * * Since: 3.2 @@ -232,6 +236,46 @@ gimp_vector_layer_get_fill_color (GimpVectorLayer *layer) return color; } +/** + * gimp_vector_layer_get_fill_pattern: + * @layer: The vector layer. + * + * Get the pattern of the fill in a vector layer. + * + * This procedure returns the pattern of the fill in a vector layer. + * + * Note that there won't be both a fill color and pattern, so either + * this procedure or [method@Gimp.VectorLayer.get_fill_color] will + * return %NULL at any given time. + * + * Returns: (transfer none): The pattern of the fill. + * + * Since: 3.2 + **/ +GimpPattern * +gimp_vector_layer_get_fill_pattern (GimpVectorLayer *layer) +{ + GimpValueArray *args; + GimpValueArray *return_vals; + GimpPattern *pattern = NULL; + + args = gimp_value_array_new_from_types (NULL, + GIMP_TYPE_VECTOR_LAYER, layer, + G_TYPE_NONE); + + return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), + "gimp-vector-layer-get-fill-pattern", + args); + gimp_value_array_unref (args); + + if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) + pattern = GIMP_VALUES_GET_PATTERN (return_vals, 1); + + gimp_value_array_unref (return_vals); + + return pattern; +} + /** * gimp_vector_layer_get_path: * @layer: The vector layer. @@ -313,6 +357,10 @@ gimp_vector_layer_get_stroke_cap_style (GimpVectorLayer *layer) * * This procedure returns the color of the stroke in a vector layer. * + * Note that there won't be both a stroke color and pattern, so either + * this procedure or [method@Gimp.VectorLayer.get_stroke_pattern] will + * return %NULL at any given time. + * * Returns: (transfer full): The color of the stroke. * * Since: 3.2 @@ -341,6 +389,46 @@ gimp_vector_layer_get_stroke_color (GimpVectorLayer *layer) return color; } +/** + * gimp_vector_layer_get_stroke_pattern: + * @layer: The vector layer. + * + * Get the pattern of the stroke in a vector layer. + * + * This procedure returns the pattern of the fill in a vector layer. + * + * Note that there won't be both a stroke color and pattern, so either + * this procedure or [method@Gimp.VectorLayer.get_stroke_color] will + * return %NULL at any given time. + * + * Returns: (transfer none): The pattern of the fill. + * + * Since: 3.2 + **/ +GimpPattern * +gimp_vector_layer_get_stroke_pattern (GimpVectorLayer *layer) +{ + GimpValueArray *args; + GimpValueArray *return_vals; + GimpPattern *pattern = NULL; + + args = gimp_value_array_new_from_types (NULL, + GIMP_TYPE_VECTOR_LAYER, layer, + G_TYPE_NONE); + + return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), + "gimp-vector-layer-get-stroke-pattern", + args); + gimp_value_array_unref (args); + + if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) + pattern = GIMP_VALUES_GET_PATTERN (return_vals, 1); + + gimp_value_array_unref (return_vals); + + return pattern; +} + /** * gimp_vector_layer_get_stroke_dash_offset: * @layer: The vector layer. diff --git a/libgimp/gimpvectorlayer_pdb.h b/libgimp/gimpvectorlayer_pdb.h index c5af1bddf1..1d886f1a26 100644 --- a/libgimp/gimpvectorlayer_pdb.h +++ b/libgimp/gimpvectorlayer_pdb.h @@ -38,9 +38,11 @@ gboolean gimp_vector_layer_refresh (GimpVectorLayer *la gboolean gimp_vector_layer_get_enable_fill (GimpVectorLayer *layer); gboolean gimp_vector_layer_get_enable_stroke (GimpVectorLayer *layer); GeglColor* gimp_vector_layer_get_fill_color (GimpVectorLayer *layer); +GimpPattern* gimp_vector_layer_get_fill_pattern (GimpVectorLayer *layer); GimpPath* gimp_vector_layer_get_path (GimpVectorLayer *layer); GimpCapStyle gimp_vector_layer_get_stroke_cap_style (GimpVectorLayer *layer); GeglColor* gimp_vector_layer_get_stroke_color (GimpVectorLayer *layer); +GimpPattern* gimp_vector_layer_get_stroke_pattern (GimpVectorLayer *layer); gdouble gimp_vector_layer_get_stroke_dash_offset (GimpVectorLayer *layer); gboolean gimp_vector_layer_get_stroke_dash_pattern (GimpVectorLayer *layer, gsize *num_dashes, diff --git a/pdb/groups/vector_layer.pdb b/pdb/groups/vector_layer.pdb index caf60ebf80..074a77ab52 100644 --- a/pdb/groups/vector_layer.pdb +++ b/pdb/groups/vector_layer.pdb @@ -209,6 +209,11 @@ sub vector_layer_get_stroke_color { $help = <<'HELP'; This procedure returns the color of the stroke in a vector layer. + + +Note that there won't be both a stroke color and pattern, so either this +procedure or [method@Gimp.VectorLayer.get_stroke_pattern] will return +%NULL at any given time. HELP &alxsa_pdb_misc('2025', '3.2'); @@ -233,8 +238,63 @@ HELP success = FALSE; if (success) - color = gegl_color_duplicate (gimp_context_get_foreground ( - GIMP_CONTEXT (options->stroke_options))); + { + GimpCustomStyle style = gimp_fill_options_get_custom_style (GIMP_FILL_OPTIONS (options->stroke_options)); + + if (style == GIMP_CUSTOM_STYLE_SOLID_COLOR || + ! gimp_context_get_pattern (GIMP_CONTEXT (options->stroke_options))) + color = gegl_color_duplicate (gimp_context_get_foreground (GIMP_CONTEXT (options->stroke_options))); + else + success = FALSE; + } +} +CODE + ); +} + +sub vector_layer_get_stroke_pattern { + $blurb = 'Get the pattern of the stroke in a vector layer.'; + + $help = <<'HELP'; +This procedure returns the pattern of the fill in a vector layer. + + +Note that there won't be both a stroke color and pattern, so either this +procedure or [method@Gimp.VectorLayer.get_stroke_color] will return +%NULL at any given time. +HELP + + &jehan_pdb_misc('2025', '3.2'); + + @inargs = ( + { name => 'layer', type => 'vector_layer', + desc => 'The vector layer.' } + ); + + @outargs = ( + { name => 'pattern', type => 'pattern', + desc => 'The pattern of the fill.' } + ); + + %invoke = ( + code => <<'CODE' +{ + GimpVectorLayerOptions *options; + + options = gimp_vector_layer_get_options (layer); + if (! options) + success = FALSE; + + if (success) + { + GimpCustomStyle style = gimp_fill_options_get_custom_style (GIMP_FILL_OPTIONS (options->stroke_options)); + + if (style == GIMP_CUSTOM_STYLE_PATTERN) + pattern = gimp_context_get_pattern (GIMP_CONTEXT (options->stroke_options)); + + if (pattern == NULL) + success = FALSE; + } } CODE ); @@ -850,6 +910,11 @@ sub vector_layer_get_fill_color { $help = <<'HELP'; This procedure returns the color of the fill in a vector layer. + + +Note that there won't be both a fill color and pattern, so either this +procedure or [method@Gimp.VectorLayer.get_fill_pattern] will return +%NULL at any given time. HELP &alxsa_pdb_misc('2025', '3.2'); @@ -874,9 +939,64 @@ HELP success = FALSE; if (success) - color = - gegl_color_duplicate (gimp_context_get_foreground ( - GIMP_CONTEXT (options->fill_options))); + { + GimpCustomStyle style = gimp_fill_options_get_custom_style (options->fill_options); + + if (style == GIMP_CUSTOM_STYLE_SOLID_COLOR || + ! gimp_context_get_pattern (GIMP_CONTEXT (options->fill_options))) + color = + gegl_color_duplicate (gimp_context_get_foreground (GIMP_CONTEXT (options->fill_options))); + else + success = FALSE; + } +} +CODE + ); +} + +sub vector_layer_get_fill_pattern { + $blurb = 'Get the pattern of the fill in a vector layer.'; + + $help = <<'HELP'; +This procedure returns the pattern of the fill in a vector layer. + + +Note that there won't be both a fill color and pattern, so either this +procedure or [method@Gimp.VectorLayer.get_fill_color] will return +%NULL at any given time. +HELP + + &jehan_pdb_misc('2025', '3.2'); + + @inargs = ( + { name => 'layer', type => 'vector_layer', + desc => 'The vector layer.' } + ); + + @outargs = ( + { name => 'pattern', type => 'pattern', + desc => 'The pattern of the fill.' } + ); + + %invoke = ( + code => <<'CODE' +{ + GimpVectorLayerOptions *options; + + options = gimp_vector_layer_get_options (layer); + if (! options) + success = FALSE; + + if (success) + { + GimpCustomStyle style = gimp_fill_options_get_custom_style (options->fill_options); + + if (style == GIMP_CUSTOM_STYLE_PATTERN) + pattern = gimp_context_get_pattern (GIMP_CONTEXT (options->fill_options)); + + if (pattern == NULL) + success = FALSE; + } } CODE ); @@ -931,9 +1051,11 @@ CODE vector_layer_get_enable_fill vector_layer_get_enable_stroke vector_layer_get_fill_color + vector_layer_get_fill_pattern vector_layer_get_path vector_layer_get_stroke_cap_style vector_layer_get_stroke_color + vector_layer_get_stroke_pattern vector_layer_get_stroke_dash_offset vector_layer_get_stroke_dash_pattern vector_layer_get_stroke_join_style