From 8af15d525af062ac4c033e0f5ea9305f4ad49bc9 Mon Sep 17 00:00:00 2001 From: Gabriele Barbero Date: Thu, 2 Apr 2026 00:24:26 +0200 Subject: [PATCH] tools: fix font size jump when using shortcuts Previously, when using shortcuts to increase or decrease the font size of the selected text, the size would jump to 0. This behavior occurred because, if the text did not yet have a font tag, the initial font size was evaluated as 0. This commit ensures that the text tool's default font size is used when no font tag is present. This prevents the font size from jumping to 0 the first time the shortcuts are used. --- app/tools/gimptexttool-editor.c | 10 +++++++++- app/widgets/gimptextbuffer.c | 10 +++++++--- app/widgets/gimptextbuffer.h | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/tools/gimptexttool-editor.c b/app/tools/gimptexttool-editor.c index 5e2153f7bc..c84a5006ef 100644 --- a/app/tools/gimptexttool-editor.c +++ b/app/tools/gimptexttool-editor.c @@ -26,6 +26,7 @@ #include #include +#include "libgimpbase/gimpbase.h" #include "libgimpwidgets/gimpwidgets.h" #include "tools-types.h" @@ -1357,6 +1358,13 @@ gimp_text_tool_change_size (GimpTextTool *text_tool, GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer); GtkTextIter start; GtkTextIter end; + gdouble default_size; + gdouble x_res, y_res; + + gimp_image_get_resolution (text_tool->image, &x_res, &y_res); + + default_size = gimp_units_to_points (text_tool->text->font_size, + text_tool->text->unit, y_res); if (! gtk_text_buffer_get_selection_bounds (buffer, &start, &end)) { @@ -1365,7 +1373,7 @@ gimp_text_tool_change_size (GimpTextTool *text_tool, gtk_text_iter_order (&start, &end); gimp_text_buffer_change_size (text_tool->buffer, &start, &end, - amount * PANGO_SCALE); + amount * PANGO_SCALE, default_size * PANGO_SCALE); } static void diff --git a/app/widgets/gimptextbuffer.c b/app/widgets/gimptextbuffer.c index bfbeefe95b..ddd4a8f67e 100644 --- a/app/widgets/gimptextbuffer.c +++ b/app/widgets/gimptextbuffer.c @@ -442,7 +442,8 @@ void gimp_text_buffer_change_size (GimpTextBuffer *buffer, const GtkTextIter *start, const GtkTextIter *end, - gint count) + gint count, + gint default_size) { GtkTextIter iter; GtkTextIter span_start; @@ -479,16 +480,19 @@ gimp_text_buffer_change_size (GimpTextBuffer *buffer, if (iter_size != span_size || gtk_text_iter_compare (&iter, end) >= 0) { + gint base_size = (span_size == 0) ? default_size : span_size; + gint new_size = base_size + count; + if (span_size != 0) { gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (buffer), span_tag, &span_start, &span_end); } - if ((span_size + count) > 0) + if (new_size > 0) { span_tag = gimp_text_buffer_get_size_tag (buffer, - span_size + count); + new_size); gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), span_tag, &span_start, &span_end); diff --git a/app/widgets/gimptextbuffer.h b/app/widgets/gimptextbuffer.h index e3b818a36f..b5e64d0eb1 100644 --- a/app/widgets/gimptextbuffer.h +++ b/app/widgets/gimptextbuffer.h @@ -91,7 +91,8 @@ void gimp_text_buffer_set_size (GimpTextBuffer *buff void gimp_text_buffer_change_size (GimpTextBuffer *buffer, const GtkTextIter *start, const GtkTextIter *end, - gint amount); + gint amount, + gint default_size); GtkTextTag * gimp_text_buffer_get_iter_baseline (GimpTextBuffer *buffer, const GtkTextIter *iter,