display: Fix titlebar regression after 7e7828e4

The previous commit did not fully convert the title/status bar
format string to be UTF8-clean, due to a misunderstanding
of the logic behind the symbol used to indicate an image
was dirty.

Rather than always grabbing the 2nd character in the format
string, this patch now grabs the next character in the format
string after the %D, %N, %C, and %E commands.
This commit is contained in:
Alx Sa 2024-01-09 14:59:29 +00:00
parent 1666f82b20
commit 2db73f82ac
1 changed files with 48 additions and 31 deletions

View File

@ -59,6 +59,11 @@ static gint gimp_display_shell_format_title (GimpDisplayShell *display,
gint title_len,
const gchar *format);
static gint print_unichar (gunichar c,
gchar *title,
gint title_len,
gint index);
/* public functions */
@ -169,6 +174,21 @@ print (gchar *buf,
return printed;
}
static gint
print_unichar (gunichar c,
gchar *title,
gint title_len,
gint index)
{
gchar letter[8];
gint len;
len = g_unichar_to_utf8 (c, letter);
letter[len] = '\0';
return print (title, title_len, index, "%s", letter);
}
static gint
gimp_display_shell_format_title (GimpDisplayShell *shell,
gchar *title,
@ -180,7 +200,6 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
GList *drawables;
gint num, denom;
gint i = 0;
gchar *temp;
gunichar c;
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), 0);
@ -205,8 +224,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
gimp_zoom_model_get_fraction (shell->zoom, &num, &denom);
temp = g_strdup (format);
c = g_utf8_get_char (format);
c = g_utf8_get_char (format);
while (i < title_len && c)
{
switch (c)
@ -277,25 +295,33 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
break;
case 'D': /* dirty flag */
if (temp[1] == 0)
format = g_utf8_next_char (format);
c = g_utf8_get_char (format);
if (c == 0)
{
/* format string ends within %D-sequence, print literal '%D' */
i += print (title, title_len, i, "%%D");
break;
}
if (gimp_image_is_dirty (image))
title[i++] = temp[1];
i += print_unichar (c, title, title_len, i);
break;
case 'C': /* clean flag */
if (temp[1] == 0)
format = g_utf8_next_char (format);
c = g_utf8_get_char (format);
if (c == 0)
{
/* format string ends within %C-sequence, print literal '%C' */
i += print (title, title_len, i, "%%C");
break;
}
if (! gimp_image_is_dirty (image))
title[i++] = temp[1];
i += print_unichar (c, title, title_len, i);
break;
case 'B': /* dirty flag (long) */
@ -309,25 +335,33 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
break;
case 'N': /* not-exported flag */
if (format[1] == 0)
format = g_utf8_next_char (format);
c = g_utf8_get_char (format);
if (c == 0)
{
/* format string ends within %E-sequence, print literal '%E' */
i += print (title, title_len, i, "%%N");
break;
}
if (gimp_image_is_export_dirty (image))
title[i++] = format[1];
i += print_unichar (c, title, title_len, i);
break;
case 'E': /* exported flag */
if (temp[1] == 0)
format = g_utf8_next_char (format);
c = g_utf8_get_char (format);
if (c == 0)
{
/* format string ends within %E-sequence, print literal '%E' */
i += print (title, title_len, i, "%%E");
break;
}
if (! gimp_image_is_export_dirty (image))
title[i++] = temp[1];
i += print_unichar (c, title, title_len, i);
break;
case 'm': /* memory used by image */
@ -549,37 +583,20 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
*/
default:
{
/* format string contains unknown %-sequence, print it literally */
gchar letter[8];
gint len;
len = g_unichar_to_utf8 (c, letter);
letter[len] = '\0';
i += print (title, title_len, i, "%%%s", letter);
}
/* format string contains unknown %-sequence, print it literally */
i += print_unichar (c, title, title_len, i);
break;
}
break;
default:
{
gchar letter[8];
gint len;
len = g_unichar_to_utf8 (c, letter);
letter[len] = '\0';
i += print (title, title_len, i, "%s", letter);
}
i += print_unichar (c, title, title_len, i);
break;
}
format = g_utf8_next_char (format);
c = g_utf8_get_char (format);
}
g_free (temp);
title[MIN (i, title_len - 1)] = '\0';