[gimp] Issue #534: add a function to set the Pango markup of a text layer
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Issue #534: add a function to set the Pango markup of a text layer
- Date: Thu, 29 Sep 2022 22:52:09 +0000 (UTC)
commit 445909bff5d7b0744e408074c1036b86d62215fd
Author: Ian Munsie <darkstarsword gmail com>
Date: Tue Feb 11 14:51:02 2014 +1100
Issue #534: add a function to set the Pango markup of a text layer
This complements the existing text_layer_get_markup function and allows
scripts to create and modify complex text layers.
It adds the <markup> root tag if it was not supplied and will run the
markup through pango_parse_markup() to check for errors.
Reviewer's (Jehan) note: this is a mostly untouched patch contributed in #534,
except that code moved around. I also fixed the header set in the .pdb, a link
to pango markup docs and added the meson changes.
app/pdb/Makefile.am | 1 +
app/pdb/internal-procs.c | 2 +-
app/pdb/meson.build | 2 +-
app/pdb/text-layer-cmds.c | 85 ++++++++++++++++++++++++++++++++++++++++++++-
libgimp/gimp.def | 1 +
libgimp/gimptextlayer_pdb.c | 43 +++++++++++++++++++++--
libgimp/gimptextlayer_pdb.h | 2 ++
pdb/groups/text_layer.pdb | 64 ++++++++++++++++++++++++++++++++--
8 files changed, 192 insertions(+), 8 deletions(-)
---
diff --git a/app/pdb/Makefile.am b/app/pdb/Makefile.am
index e74aad0604..6f1c496cc3 100644
--- a/app/pdb/Makefile.am
+++ b/app/pdb/Makefile.am
@@ -8,6 +8,7 @@ AM_CPPFLAGS = \
-I$(top_builddir)/pdb \
-I$(top_srcdir)/app \
$(CAIRO_CFLAGS) \
+ $(PANGOCAIRO_CFLAGS) \
$(GEGL_CFLAGS) \
$(GDK_PIXBUF_CFLAGS) \
-I$(includedir)
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 9671f5263b..2ad07ddfc3 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -30,7 +30,7 @@
#include "internal-procs.h"
-/* 762 procedures registered total */
+/* 763 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/app/pdb/meson.build b/app/pdb/meson.build
index e73a1f37a3..c88b376c85 100644
--- a/app/pdb/meson.build
+++ b/app/pdb/meson.build
@@ -78,7 +78,7 @@ libappinternalprocs = static_library('appinternalprocs',
include_directories: [ rootInclude, rootAppInclude, ],
c_args: '-DG_LOG_DOMAIN="Gimp-PDB"',
dependencies: [
- cairo, gegl, gdk_pixbuf,
+ cairo, gegl, gdk_pixbuf, pangocairo,
],
sources: [
pdbgen
diff --git a/app/pdb/text-layer-cmds.c b/app/pdb/text-layer-cmds.c
index cb15a5e7d3..b6c3c19a9d 100644
--- a/app/pdb/text-layer-cmds.c
+++ b/app/pdb/text-layer-cmds.c
@@ -22,6 +22,7 @@
#include "stamp-pdbgen.h"
#include <cairo.h>
+#include <pango/pango.h>
#include <gegl.h>
@@ -219,6 +220,58 @@ text_layer_get_markup_invoker (GimpProcedure *procedure,
return return_vals;
}
+static GimpValueArray *
+text_layer_set_markup_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpLayer *layer;
+ const gchar *markup;
+
+ layer = g_value_get_object (gimp_value_array_index (args, 0));
+ markup = g_value_get_string (gimp_value_array_index (args, 1));
+
+ if (success)
+ {
+ if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
+ {
+ gchar *markup_cat = NULL;
+ const gchar *markup_ptr = markup;
+
+ if (strstr(markup, "<markup>") == NULL || strstr(markup, "</markup>") == NULL)
+ {
+ markup_cat = g_strconcat("<markup>", markup, "</markup>", NULL);
+ markup_ptr = markup_cat;
+ }
+
+ if (pango_parse_markup (markup_ptr, -1, 0, NULL, NULL, NULL, error))
+ {
+ gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
+ _("Set text layer markup"),
+ "markup", markup_ptr,
+ NULL);
+ }
+ else
+ {
+ success = FALSE;
+ }
+
+ g_free(markup_cat);
+ }
+ else
+ {
+ success = FALSE;
+ }
+ }
+
+ return gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+}
+
static GimpValueArray *
text_layer_get_font_invoker (GimpProcedure *procedure,
Gimp *gimp,
@@ -1267,7 +1320,7 @@ register_text_layer_procs (GimpPDB *pdb)
"gimp-text-layer-get-markup");
gimp_procedure_set_static_help (procedure,
"Get the markup from a text layer as string.",
- "This procedure returns the markup of the styles from a text layer. The
markup will be in the form of Pango's markup - See https://www.pango.org/ for more information about Pango
and its markup. Note: Setting the markup of a text layer using Pango's markup is not supported for now.",
+ "This procedure returns the markup of the styles from a text layer. The
markup will be in the form of Pango's markup - See https://www.pango.org/ for more information about Pango
and its markup.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Barak Itkin <lightningismyname gmail com>",
@@ -1289,6 +1342,36 @@ register_text_layer_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
+ /*
+ * gimp-text-layer-set-markup
+ */
+ procedure = gimp_procedure_new (text_layer_set_markup_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-text-layer-set-markup");
+ gimp_procedure_set_static_help (procedure,
+ "Set the markup for a text layer from a string.",
+ "This procedure sets the markup of the styles for a text layer. The markup
should be in the form of Pango's markup - See https://docs.gtk.org/Pango/pango_markup.html for a reference.",
+ NULL);
+ gimp_procedure_set_static_attribution (procedure,
+ "Ian Munsie <darkstarsword gmail com>",
+ "Ian Munsie",
+ "2014");
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_layer ("layer",
+ "layer",
+ "The text layer",
+ FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_string ("markup",
+ "markup",
+ "The new markup to set",
+ FALSE, FALSE, FALSE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
/*
* gimp-text-layer-get-font
*/
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index b7223f35a8..5875cda1bb 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -845,6 +845,7 @@ EXPORTS
gimp_text_layer_set_language
gimp_text_layer_set_letter_spacing
gimp_text_layer_set_line_spacing
+ gimp_text_layer_set_markup
gimp_text_layer_set_text
gimp_thumbnail_procedure_get_type
gimp_thumbnail_procedure_new
diff --git a/libgimp/gimptextlayer_pdb.c b/libgimp/gimptextlayer_pdb.c
index cc3f40012d..03ebf73c88 100644
--- a/libgimp/gimptextlayer_pdb.c
+++ b/libgimp/gimptextlayer_pdb.c
@@ -173,8 +173,7 @@ gimp_text_layer_set_text (GimpLayer *layer,
* This procedure returns the markup of the styles from a text layer.
* The markup will be in the form of Pango's markup - See
* https://www.pango.org/ for more information about Pango and its
- * markup. Note: Setting the markup of a text layer using Pango's
- * markup is not supported for now.
+ * markup.
*
* Returns: (transfer full):
* The markup which represents the style of the specified text layer.
@@ -206,6 +205,46 @@ gimp_text_layer_get_markup (GimpLayer *layer)
return markup;
}
+/**
+ * gimp_text_layer_set_markup:
+ * @layer: The text layer.
+ * @markup: The new markup to set.
+ *
+ * Set the markup for a text layer from a string.
+ *
+ * This procedure sets the markup of the styles for a text layer. The
+ * markup should be in the form of Pango's markup - See
+ * https://docs.gtk.org/Pango/pango_markup.html for a reference.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gimp_text_layer_set_markup (GimpLayer *layer,
+ const gchar *markup)
+{
+ GimpValueArray *args;
+ GimpValueArray *return_vals;
+ gboolean success = TRUE;
+
+ args = gimp_value_array_new_from_types (NULL,
+ GIMP_TYPE_LAYER, layer,
+ G_TYPE_STRING, markup,
+ G_TYPE_NONE);
+
+ return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+ "gimp-text-layer-set-markup",
+ 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_text_layer_get_font:
* @layer: The text layer.
diff --git a/libgimp/gimptextlayer_pdb.h b/libgimp/gimptextlayer_pdb.h
index e9689bf082..14785c26e9 100644
--- a/libgimp/gimptextlayer_pdb.h
+++ b/libgimp/gimptextlayer_pdb.h
@@ -41,6 +41,8 @@ gchar* gimp_text_layer_get_text (GimpLayer
gboolean gimp_text_layer_set_text (GimpLayer *layer,
const gchar *text);
gchar* gimp_text_layer_get_markup (GimpLayer *layer);
+gboolean gimp_text_layer_set_markup (GimpLayer *layer,
+ const gchar *markup);
gchar* gimp_text_layer_get_font (GimpLayer *layer);
gboolean gimp_text_layer_set_font (GimpLayer *layer,
const gchar *font);
diff --git a/pdb/groups/text_layer.pdb b/pdb/groups/text_layer.pdb
index 04074d1558..fb44221d03 100644
--- a/pdb/groups/text_layer.pdb
+++ b/pdb/groups/text_layer.pdb
@@ -159,8 +159,6 @@ sub text_layer_get_markup {
This procedure returns the markup of the styles from a text layer.
The markup will be in the form of Pango's markup - See
https://www.pango.org/ for more information about Pango and its markup.
-Note: Setting the markup of a text layer using Pango's markup is not
-supported for now.
HELP
barak_pdb_misc('2010', '2.8');
@@ -193,6 +191,64 @@ CODE
);
}
+sub text_layer_set_markup {
+ $blurb = 'Set the markup for a text layer from a string.';
+
+ $help = <<'HELP';
+This procedure sets the markup of the styles for a text layer.
+The markup should be in the form of Pango's markup - See
+https://docs.gtk.org/Pango/pango_markup.html for a reference.
+HELP
+
+ $author = 'Ian Munsie <darkstarsword gmail com>';
+ $copyright = 'Ian Munsie';
+ $date = '2014';
+ $since = '3.0';
+
+ @inargs = (
+ { name => 'layer', type => 'layer',
+ desc => 'The text layer' },
+ { name => 'markup', type => 'string',
+ desc => 'The new markup to set' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
+ {
+ gchar *markup_cat = NULL;
+ const gchar *markup_ptr = markup;
+
+ if (strstr(markup, "<markup>") == NULL || strstr(markup, "</markup>") == NULL)
+ {
+ markup_cat = g_strconcat("<markup>", markup, "</markup>", NULL);
+ markup_ptr = markup_cat;
+ }
+
+ if (pango_parse_markup (markup_ptr, -1, 0, NULL, NULL, NULL, error))
+ {
+ gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
+ _("Set text layer markup"),
+ "markup", markup_ptr,
+ NULL);
+ }
+ else
+ {
+ success = FALSE;
+ }
+
+ g_free(markup_cat);
+ }
+ else
+ {
+ success = FALSE;
+ }
+}
+CODE
+ );
+}
+
sub text_layer_get_font {
$blurb = 'Get the font from a text layer as string.';
@@ -1128,7 +1184,8 @@ CODE
}
-@headers = qw("libgimpbase/gimpbase.h"
+@headers = qw(<pango/pango.h>
+ "libgimpbase/gimpbase.h"
"core/gimpcontext.h"
"text/gimptext.h"
"text/gimptextlayer.h"
@@ -1140,6 +1197,7 @@ CODE
text_layer_get_text
text_layer_set_text
text_layer_get_markup
+ text_layer_set_markup
text_layer_get_font
text_layer_set_font
text_layer_get_font_size
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]