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.
This commit is contained in:
parent
d63687aefd
commit
8af15d525a
3 changed files with 18 additions and 5 deletions
|
|
@ -26,6 +26,7 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
#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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue