From 566e55e72e5382daa17b08066287bf2698f92090 Mon Sep 17 00:00:00 2001 From: Jehan Date: Sun, 20 Jun 2021 10:36:56 +0200 Subject: [PATCH] app: "Bend the text along the currently active path" multi-layer aware. It still only requires one single path selected to work, but I updated the internal API used. --- app/actions/text-tool-commands.c | 11 +++++++++- app/tools/gimptexttool.c | 36 ++++++++++++++++++++++++-------- app/tools/gimptexttool.h | 29 ++++++++++++------------- 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/app/actions/text-tool-commands.c b/app/actions/text-tool-commands.c index f32506a440..61fb9ed1eb 100644 --- a/app/actions/text-tool-commands.c +++ b/app/actions/text-tool-commands.c @@ -26,6 +26,7 @@ #include "actions-types.h" #include "core/gimp.h" +#include "core/gimpimage.h" #include "core/gimptoolinfo.h" #include "widgets/gimphelp-ids.h" @@ -178,8 +179,16 @@ text_tool_text_along_path_cmd_callback (GimpAction *action, gpointer data) { GimpTextTool *text_tool = GIMP_TEXT_TOOL (data); + GError *error = NULL; - gimp_text_tool_create_vectors_warped (text_tool); + if (! gimp_text_tool_create_vectors_warped (text_tool, &error)) + { + gimp_message (text_tool->image->gimp, G_OBJECT (text_tool), + GIMP_MESSAGE_ERROR, + _("Test along path failed: %s"), + error->message); + g_clear_error (&error); + } } void diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c index 2d7fc4f2e8..bc8309aa3e 100644 --- a/app/tools/gimptexttool.c +++ b/app/tools/gimptexttool.c @@ -2327,27 +2327,43 @@ gimp_text_tool_create_vectors (GimpTextTool *text_tool) gimp_image_flush (text_tool->image); } -void -gimp_text_tool_create_vectors_warped (GimpTextTool *text_tool) +gboolean +gimp_text_tool_create_vectors_warped (GimpTextTool *text_tool, + GError **error) { - GimpVectors *vectors0; + GList *vectors0; GimpVectors *vectors; gdouble box_width; gdouble box_height; GimpTextDirection dir; gdouble offset = 0.0; - g_return_if_fail (GIMP_IS_TEXT_TOOL (text_tool)); + g_return_val_if_fail (GIMP_IS_TEXT_TOOL (text_tool), FALSE); if (! text_tool->text || ! text_tool->image || ! text_tool->layer) - return; + { + if (! text_tool->text) + g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, + _("Text is required.")); + if (! text_tool->image) + g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, + _("No image.")); + if (! text_tool->layer) + g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, + _("No layer.")); + return FALSE; + } box_width = gimp_item_get_width (GIMP_ITEM (text_tool->layer)); box_height = gimp_item_get_height (GIMP_ITEM (text_tool->layer)); - vectors0 = gimp_image_get_active_vectors (text_tool->image); - if (! vectors0) - return; + vectors0 = gimp_image_get_selected_vectors (text_tool->image); + if (g_list_length (vectors0) != 1) + { + g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, + _("Exactly one path must be selected.")); + return FALSE; + } vectors = gimp_text_vectors_new (text_tool->image, text_tool->text); @@ -2376,7 +2392,7 @@ gimp_text_tool_create_vectors_warped (GimpTextTool *text_tool) break; } - gimp_vectors_warp_vectors (vectors0, vectors, offset); + gimp_vectors_warp_vectors (vectors0->data, vectors, offset); gimp_item_set_visible (GIMP_ITEM (vectors), TRUE, FALSE); @@ -2384,6 +2400,8 @@ gimp_text_tool_create_vectors_warped (GimpTextTool *text_tool) GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE); gimp_image_flush (text_tool->image); + + return TRUE; } GimpTextDirection diff --git a/app/tools/gimptexttool.h b/app/tools/gimptexttool.h index b939d1856b..cda2820eab 100644 --- a/app/tools/gimptexttool.h +++ b/app/tools/gimptexttool.h @@ -106,27 +106,28 @@ void gimp_text_tool_register (GimpToolRegisterCallback call GType gimp_text_tool_get_type (void) G_GNUC_CONST; -gboolean gimp_text_tool_set_layer (GimpTextTool *text_tool, - GimpLayer *layer); +gboolean gimp_text_tool_set_layer (GimpTextTool *text_tool, + GimpLayer *layer); -gboolean gimp_text_tool_get_has_text_selection (GimpTextTool *text_tool); +gboolean gimp_text_tool_get_has_text_selection (GimpTextTool *text_tool); -void gimp_text_tool_delete_selection (GimpTextTool *text_tool); -void gimp_text_tool_cut_clipboard (GimpTextTool *text_tool); -void gimp_text_tool_copy_clipboard (GimpTextTool *text_tool); -void gimp_text_tool_paste_clipboard (GimpTextTool *text_tool); +void gimp_text_tool_delete_selection (GimpTextTool *text_tool); +void gimp_text_tool_cut_clipboard (GimpTextTool *text_tool); +void gimp_text_tool_copy_clipboard (GimpTextTool *text_tool); +void gimp_text_tool_paste_clipboard (GimpTextTool *text_tool); -void gimp_text_tool_create_vectors (GimpTextTool *text_tool); -void gimp_text_tool_create_vectors_warped (GimpTextTool *text_tool); +void gimp_text_tool_create_vectors (GimpTextTool *text_tool); +gboolean gimp_text_tool_create_vectors_warped (GimpTextTool *text_tool, + GError **error); GimpTextDirection - gimp_text_tool_get_direction (GimpTextTool *text_tool); + gimp_text_tool_get_direction (GimpTextTool *text_tool); /* only for the text editor */ -void gimp_text_tool_clear_layout (GimpTextTool *text_tool); -gboolean gimp_text_tool_ensure_layout (GimpTextTool *text_tool); -void gimp_text_tool_apply (GimpTextTool *text_tool, - gboolean push_undo); +void gimp_text_tool_clear_layout (GimpTextTool *text_tool); +gboolean gimp_text_tool_ensure_layout (GimpTextTool *text_tool); +void gimp_text_tool_apply (GimpTextTool *text_tool, + gboolean push_undo); #endif /* __GIMP_TEXT_TOOL_H__ */