gimptextstyleeditor.c 46.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * GimpTextStyleEditor
 * Copyright (C) 2010  Michael Natterer <mitch@gimp.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 20 21 22 23 24 25
 */

#include "config.h"

#include <gegl.h>
#include <gtk/gtk.h>

26
#include "libgimpbase/gimpbase.h"
27
#include "libgimpcolor/gimpcolor.h"
28
#include "libgimpwidgets/gimpwidgets.h"
29

30 31
#include "widgets-types.h"

32
#include "core/gimp.h"
33
#include "core/gimpcontainer.h"
34 35
#include "core/gimpcontext.h"

36
#include "text/gimptext.h"
37

38
#include "gimpcolorpanel.h"
39 40
#include "gimpcontainerentry.h"
#include "gimpcontainerview.h"
41 42
#include "gimptextbuffer.h"
#include "gimptextstyleeditor.h"
43
#include "gimptexttag.h"
44
#include "gimpwidgets-utils.h"
45

46 47
#include "gimp-intl.h"

48 49 50 51

enum
{
  PROP_0,
52
  PROP_GIMP,
53
  PROP_TEXT,
54
  PROP_BUFFER,
55
  PROP_FONTS,
56 57
  PROP_RESOLUTION_X,
  PROP_RESOLUTION_Y
58 59 60
};


61 62 63 64 65 66 67 68 69 70 71
static void      gimp_text_style_editor_constructed       (GObject             *object);
static void      gimp_text_style_editor_dispose           (GObject             *object);
static void      gimp_text_style_editor_finalize          (GObject             *object);
static void      gimp_text_style_editor_set_property      (GObject             *object,
                                                           guint                property_id,
                                                           const GValue        *value,
                                                           GParamSpec          *pspec);
static void      gimp_text_style_editor_get_property      (GObject             *object,
                                                           guint                property_id,
                                                           GValue              *value,
                                                           GParamSpec          *pspec);
72 73 74

static GtkWidget * gimp_text_style_editor_create_toggle   (GimpTextStyleEditor *editor,
                                                           GtkTextTag          *tag,
75
                                                           const gchar         *icon_name,
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
                                                           const gchar         *tooltip);

static void      gimp_text_style_editor_clear_tags        (GtkButton           *button,
                                                           GimpTextStyleEditor *editor);

static void      gimp_text_style_editor_font_changed      (GimpContext         *context,
                                                           GimpFont            *font,
                                                           GimpTextStyleEditor *editor);
static void      gimp_text_style_editor_set_font          (GimpTextStyleEditor *editor,
                                                           GtkTextTag          *font_tag);
static void      gimp_text_style_editor_set_default_font  (GimpTextStyleEditor *editor);

static void      gimp_text_style_editor_color_changed     (GimpColorButton     *button,
                                                           GimpTextStyleEditor *editor);
static void      gimp_text_style_editor_set_color         (GimpTextStyleEditor *editor,
                                                           GtkTextTag          *color_tag);
static void      gimp_text_style_editor_set_default_color (GimpTextStyleEditor *editor);

static void      gimp_text_style_editor_tag_toggled       (GtkToggleButton     *toggle,
                                                           GimpTextStyleEditor *editor);
static void      gimp_text_style_editor_set_toggle        (GimpTextStyleEditor *editor,
                                                           GtkToggleButton     *toggle,
                                                           gboolean             active);

100
static void      gimp_text_style_editor_size_changed      (GimpSizeEntry       *entry,
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
                                                           GimpTextStyleEditor *editor);
static void      gimp_text_style_editor_set_size          (GimpTextStyleEditor *editor,
                                                           GtkTextTag          *size_tag);
static void      gimp_text_style_editor_set_default_size  (GimpTextStyleEditor *editor);

static void      gimp_text_style_editor_baseline_changed  (GtkAdjustment       *adjustment,
                                                           GimpTextStyleEditor *editor);
static void      gimp_text_style_editor_set_baseline      (GimpTextStyleEditor *editor,
                                                           GtkTextTag          *baseline_tag);

static void      gimp_text_style_editor_kerning_changed   (GtkAdjustment       *adjustment,
                                                           GimpTextStyleEditor *editor);
static void      gimp_text_style_editor_set_kerning       (GimpTextStyleEditor *editor,
                                                           GtkTextTag          *kerning_tag);

static void      gimp_text_style_editor_update            (GimpTextStyleEditor *editor);
static gboolean  gimp_text_style_editor_update_idle       (GimpTextStyleEditor *editor);
118 119 120


G_DEFINE_TYPE (GimpTextStyleEditor, gimp_text_style_editor,
121
               GTK_TYPE_BOX)
122 123 124 125 126 127 128

#define parent_class gimp_text_style_editor_parent_class


static void
gimp_text_style_editor_class_init (GimpTextStyleEditorClass *klass)
{
129 130
  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
131

132
  object_class->constructed  = gimp_text_style_editor_constructed;
133 134 135 136 137
  object_class->dispose      = gimp_text_style_editor_dispose;
  object_class->finalize     = gimp_text_style_editor_finalize;
  object_class->set_property = gimp_text_style_editor_set_property;
  object_class->get_property = gimp_text_style_editor_get_property;

138 139 140 141 142 143 144
  g_object_class_install_property (object_class, PROP_GIMP,
                                   g_param_spec_object ("gimp",
                                                        NULL, NULL,
                                                        GIMP_TYPE_GIMP,
                                                        GIMP_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT_ONLY));

145 146 147 148 149 150 151
  g_object_class_install_property (object_class, PROP_TEXT,
                                   g_param_spec_object ("text",
                                                        NULL, NULL,
                                                        GIMP_TYPE_TEXT,
                                                        GIMP_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT_ONLY));

152 153 154 155 156 157
  g_object_class_install_property (object_class, PROP_BUFFER,
                                   g_param_spec_object ("buffer",
                                                        NULL, NULL,
                                                        GIMP_TYPE_TEXT_BUFFER,
                                                        GIMP_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT_ONLY));
158

159 160 161
  g_object_class_install_property (object_class, PROP_FONTS,
                                   g_param_spec_object ("fonts",
                                                        NULL, NULL,
162
                                                        GIMP_TYPE_CONTAINER,
163 164 165
                                                        GIMP_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT_ONLY));

166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
  g_object_class_install_property (object_class, PROP_RESOLUTION_X,
                                   g_param_spec_double ("resolution-x",
                                                        NULL, NULL,
                                                        GIMP_MIN_RESOLUTION,
                                                        GIMP_MAX_RESOLUTION,
                                                        1.0,
                                                        GIMP_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT));

  g_object_class_install_property (object_class, PROP_RESOLUTION_Y,
                                   g_param_spec_double ("resolution-y",
                                                        NULL, NULL,
                                                        GIMP_MIN_RESOLUTION,
                                                        GIMP_MAX_RESOLUTION,
                                                        1.0,
                                                        GIMP_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT));
183 184

  gtk_widget_class_set_css_name (widget_class, "GimpTextStyleEditor");
185 186 187 188 189 190
}

static void
gimp_text_style_editor_init (GimpTextStyleEditor *editor)
{
  GtkWidget *image;
191
  GimpRGB    color;
192

193 194
  gtk_orientable_set_orientation (GTK_ORIENTABLE (editor),
                                  GTK_ORIENTATION_VERTICAL);
195
  gtk_box_set_spacing (GTK_BOX (editor), 2);
196

197 198
  /*  upper row  */

199
  editor->upper_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
200 201 202
  gtk_box_pack_start (GTK_BOX (editor), editor->upper_hbox, FALSE, FALSE, 0);
  gtk_widget_show (editor->upper_hbox);

203 204
  editor->font_entry = gimp_container_entry_new (NULL, NULL,
                                                 GIMP_VIEW_SIZE_SMALL, 1);
205 206
  gtk_box_pack_start (GTK_BOX (editor->upper_hbox), editor->font_entry,
                      FALSE, FALSE, 0);
207 208
  gtk_widget_show (editor->font_entry);

209 210 211
  gimp_help_set_help_data (editor->font_entry,
                           _("Change font of selected text"), NULL);

212 213 214 215
  editor->size_entry =
    gimp_size_entry_new (1, 0, "%a", TRUE, FALSE, FALSE, 10,
                         GIMP_SIZE_ENTRY_UPDATE_SIZE);
  gtk_box_pack_start (GTK_BOX (editor->upper_hbox), editor->size_entry,
216
                      FALSE, FALSE, 0);
217
  gtk_widget_show (editor->size_entry);
218

219
  gimp_help_set_help_data (editor->size_entry,
220 221
                           _("Change size of selected text"), NULL);

222
  g_signal_connect (editor->size_entry, "value-changed",
223 224
                    G_CALLBACK (gimp_text_style_editor_size_changed),
                    editor);
225 226 227

  /*  lower row  */

228
  editor->lower_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
229 230 231
  gtk_box_pack_start (GTK_BOX (editor), editor->lower_hbox, FALSE, FALSE, 0);
  gtk_widget_show (editor->lower_hbox);

232 233
  editor->clear_button = gtk_button_new ();
  gtk_widget_set_can_focus (editor->clear_button, FALSE);
234 235
  gtk_box_pack_start (GTK_BOX (editor->lower_hbox), editor->clear_button,
                      FALSE, FALSE, 0);
236 237
  gtk_widget_show (editor->clear_button);

238 239 240
  gimp_help_set_help_data (editor->clear_button,
                           _("Clear style of selected text"), NULL);

241 242 243 244
  g_signal_connect (editor->clear_button, "clicked",
                    G_CALLBACK (gimp_text_style_editor_clear_tags),
                    editor);

245
  image = gtk_image_new_from_icon_name ("edit-clear", GTK_ICON_SIZE_MENU);
246 247
  gtk_container_add (GTK_CONTAINER (editor->clear_button), image);
  gtk_widget_show (image);
248

249 250 251 252
  gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
  editor->color_button = gimp_color_panel_new (_("Change color of selected text"),
                                               &color,
                                               GIMP_COLOR_AREA_FLAT, 20, 20);
253
  gimp_widget_set_fully_opaque (editor->color_button, TRUE);
254 255 256 257 258 259 260 261 262 263 264 265

  gtk_box_pack_end (GTK_BOX (editor->lower_hbox), editor->color_button,
                    FALSE, FALSE, 0);
  gtk_widget_show (editor->color_button);

  gimp_help_set_help_data (editor->color_button,
                           _("Change color of selected text"), NULL);

  g_signal_connect (editor->color_button, "color-changed",
                    G_CALLBACK (gimp_text_style_editor_color_changed),
                    editor);

266 267
  editor->kerning_adjustment = gtk_adjustment_new (0.0, -1000.0, 1000.0,
                                                   1.0, 10.0, 0.0);
268 269 270
  editor->kerning_spinbutton = gtk_spin_button_new (editor->kerning_adjustment,
                                                    1.0, 1);
  gtk_entry_set_width_chars (GTK_ENTRY (editor->kerning_spinbutton), 5);
271
  gtk_box_pack_end (GTK_BOX (editor->lower_hbox), editor->kerning_spinbutton,
272 273 274
                    FALSE, FALSE, 0);
  gtk_widget_show (editor->kerning_spinbutton);

275 276 277
  gimp_help_set_help_data (editor->kerning_spinbutton,
                           _("Change kerning of selected text"), NULL);

278 279 280 281
  g_signal_connect (editor->kerning_adjustment, "value-changed",
                    G_CALLBACK (gimp_text_style_editor_kerning_changed),
                    editor);

282 283
  editor->baseline_adjustment = gtk_adjustment_new (0.0, -1000.0, 1000.0,
                                                    1.0, 10.0, 0.0);
284 285 286
  editor->baseline_spinbutton = gtk_spin_button_new (editor->baseline_adjustment,
                                                     1.0, 1);
  gtk_entry_set_width_chars (GTK_ENTRY (editor->baseline_spinbutton), 5);
287
  gtk_box_pack_end (GTK_BOX (editor->lower_hbox), editor->baseline_spinbutton,
288 289 290
                    FALSE, FALSE, 0);
  gtk_widget_show (editor->baseline_spinbutton);

291 292 293
  gimp_help_set_help_data (editor->baseline_spinbutton,
                           _("Change baseline of selected text"), NULL);

294 295 296
  g_signal_connect (editor->baseline_adjustment, "value-changed",
                    G_CALLBACK (gimp_text_style_editor_baseline_changed),
                    editor);
297 298
}

299 300
static void
gimp_text_style_editor_constructed (GObject *object)
301
{
302
  GimpTextStyleEditor *editor = GIMP_TEXT_STYLE_EDITOR (object);
303

304
  G_OBJECT_CLASS (parent_class)->constructed (object);
305

306
  gimp_assert (GIMP_IS_GIMP (editor->gimp));
307
  gimp_assert (GIMP_IS_CONTAINER (editor->fonts));
308 309
  gimp_assert (GIMP_IS_TEXT (editor->text));
  gimp_assert (GIMP_IS_TEXT_BUFFER (editor->buffer));
310

311 312
  editor->context = gimp_context_new (editor->gimp, "text style editor", NULL);

313 314 315 316
  g_signal_connect (editor->context, "font-changed",
                    G_CALLBACK (gimp_text_style_editor_font_changed),
                    editor);

317 318 319
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (editor->size_entry), 0,
                                  editor->resolution_y, TRUE);

320 321 322 323
  /* use the global user context so we get the global FG/BG colors */
  gimp_color_panel_set_context (GIMP_COLOR_PANEL (editor->color_button),
                                gimp_get_user_context (editor->gimp));

324 325 326 327 328
  gimp_container_view_set_container (GIMP_CONTAINER_VIEW (editor->font_entry),
                                     editor->fonts);
  gimp_container_view_set_context (GIMP_CONTAINER_VIEW (editor->font_entry),
                                   editor->context);

329
  gimp_text_style_editor_create_toggle (editor, editor->buffer->bold_tag,
330
                                        GIMP_ICON_FORMAT_TEXT_BOLD,
331
                                        _("Bold"));
332
  gimp_text_style_editor_create_toggle (editor, editor->buffer->italic_tag,
333
                                        GIMP_ICON_FORMAT_TEXT_ITALIC,
334
                                        _("Italic"));
335
  gimp_text_style_editor_create_toggle (editor, editor->buffer->underline_tag,
336
                                        GIMP_ICON_FORMAT_TEXT_UNDERLINE,
337
                                        _("Underline"));
338
  gimp_text_style_editor_create_toggle (editor, editor->buffer->strikethrough_tag,
339
                                        GIMP_ICON_FORMAT_TEXT_STRIKETHROUGH,
340
                                        _("Strikethrough"));
341

342 343 344 345 346 347 348 349 350 351 352 353 354
  g_signal_connect_swapped (editor->text, "notify::font",
                            G_CALLBACK (gimp_text_style_editor_update),
                            editor);
  g_signal_connect_swapped (editor->text, "notify::font-size",
                            G_CALLBACK (gimp_text_style_editor_update),
                            editor);
  g_signal_connect_swapped (editor->text, "notify::font-size-unit",
                            G_CALLBACK (gimp_text_style_editor_update),
                            editor);
  g_signal_connect_swapped (editor->text, "notify::color",
                            G_CALLBACK (gimp_text_style_editor_update),
                            editor);

355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
  g_signal_connect_data (editor->buffer, "changed",
                         G_CALLBACK (gimp_text_style_editor_update),
                         editor, 0,
                         G_CONNECT_AFTER | G_CONNECT_SWAPPED);
  g_signal_connect_data (editor->buffer, "apply-tag",
                         G_CALLBACK (gimp_text_style_editor_update),
                         editor, 0,
                         G_CONNECT_AFTER | G_CONNECT_SWAPPED);
  g_signal_connect_data (editor->buffer, "remove-tag",
                         G_CALLBACK (gimp_text_style_editor_update),
                         editor, 0,
                         G_CONNECT_AFTER | G_CONNECT_SWAPPED);
  g_signal_connect_data (editor->buffer, "mark-set",
                         G_CALLBACK (gimp_text_style_editor_update),
                         editor, 0,
                         G_CONNECT_AFTER | G_CONNECT_SWAPPED);
371 372

  gimp_text_style_editor_update (editor);
373 374 375 376 377 378 379
}

static void
gimp_text_style_editor_dispose (GObject *object)
{
  GimpTextStyleEditor *editor = GIMP_TEXT_STYLE_EDITOR (object);

380 381 382 383 384 385 386
  if (editor->text)
    {
      g_signal_handlers_disconnect_by_func (editor->text,
                                            gimp_text_style_editor_update,
                                            editor);
    }

387 388 389
  if (editor->buffer)
    {
      g_signal_handlers_disconnect_by_func (editor->buffer,
390
                                            gimp_text_style_editor_update,
391 392 393
                                            editor);
    }

394 395 396 397 398 399
  if (editor->update_idle_id)
    {
      g_source_remove (editor->update_idle_id);
      editor->update_idle_id = 0;
    }

400 401 402 403 404 405 406 407
  G_OBJECT_CLASS (parent_class)->dispose (object);
}

static void
gimp_text_style_editor_finalize (GObject *object)
{
  GimpTextStyleEditor *editor = GIMP_TEXT_STYLE_EDITOR (object);

408 409 410 411
  g_clear_object (&editor->context);
  g_clear_object (&editor->text);
  g_clear_object (&editor->buffer);
  g_clear_object (&editor->fonts);
412

413 414 415 416 417 418
  if (editor->toggles)
    {
      g_list_free (editor->toggles);
      editor->toggles = NULL;
    }

419 420 421 422 423 424 425 426 427 428 429 430 431
  G_OBJECT_CLASS (parent_class)->finalize (object);
}

static void
gimp_text_style_editor_set_property (GObject      *object,
                                     guint         property_id,
                                     const GValue *value,
                                     GParamSpec   *pspec)
{
  GimpTextStyleEditor *editor = GIMP_TEXT_STYLE_EDITOR (object);

  switch (property_id)
    {
432 433 434
    case PROP_GIMP:
      editor->gimp = g_value_get_object (value); /* don't ref */
      break;
435 436 437
    case PROP_TEXT:
      editor->text = g_value_dup_object (value);
      break;
438 439 440
    case PROP_BUFFER:
      editor->buffer = g_value_dup_object (value);
      break;
441 442 443
    case PROP_FONTS:
      editor->fonts = g_value_dup_object (value);
      break;
444 445 446 447 448
    case PROP_RESOLUTION_X:
      editor->resolution_x = g_value_get_double (value);
      break;
    case PROP_RESOLUTION_Y:
      editor->resolution_y = g_value_get_double (value);
449 450 451
      if (editor->size_entry)
        gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (editor->size_entry), 0,
                                        editor->resolution_y, TRUE);
452
      break;
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
gimp_text_style_editor_get_property (GObject    *object,
                                     guint       property_id,
                                     GValue     *value,
                                     GParamSpec *pspec)
{
  GimpTextStyleEditor *editor = GIMP_TEXT_STYLE_EDITOR (object);

  switch (property_id)
    {
470 471 472
    case PROP_GIMP:
      g_value_set_object (value, editor->gimp);
      break;
473 474 475
    case PROP_TEXT:
      g_value_set_object (value, editor->text);
      break;
476 477 478
    case PROP_BUFFER:
      g_value_set_object (value, editor->buffer);
      break;
479 480 481
    case PROP_FONTS:
      g_value_set_object (value, editor->fonts);
      break;
482 483 484 485 486 487
    case PROP_RESOLUTION_X:
      g_value_set_double (value, editor->resolution_x);
      break;
    case PROP_RESOLUTION_Y:
      g_value_set_double (value, editor->resolution_y);
      break;
488 489 490 491 492 493 494 495 496 497 498

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}


/*  public functions  */

GtkWidget *
499
gimp_text_style_editor_new (Gimp           *gimp,
500
                            GimpText       *text,
501 502
                            GimpTextBuffer *buffer,
                            GimpContainer  *fonts,
503 504
                            gdouble         resolution_x,
                            gdouble         resolution_y)
505
{
506
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
507
  g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
508
  g_return_val_if_fail (GIMP_IS_TEXT_BUFFER (buffer), NULL);
509 510
  g_return_val_if_fail (resolution_x > 0.0, NULL);
  g_return_val_if_fail (resolution_y > 0.0, NULL);
511 512

  return g_object_new (GIMP_TYPE_TEXT_STYLE_EDITOR,
513
                       "gimp",         gimp,
514
                       "text",         text,
515
                       "buffer",       buffer,
516
                       "fonts",        fonts,
517 518
                       "resolution-x", resolution_x,
                       "resolution-y", resolution_y,
519 520 521
                       NULL);
}

522
GList *
523 524
gimp_text_style_editor_list_tags (GimpTextStyleEditor  *editor,
                                  GList               **remove_tags)
525 526 527 528 529
{
  GList *toggles;
  GList *tags = NULL;

  g_return_val_if_fail (GIMP_IS_TEXT_STYLE_EDITOR (editor), NULL);
530 531 532
  g_return_val_if_fail (remove_tags != NULL, NULL);

  *remove_tags = NULL;
533 534 535

  for (toggles = editor->toggles; toggles; toggles = g_list_next (toggles))
    {
536 537
      GtkTextTag *tag = g_object_get_data (toggles->data, "tag");

538 539
      if (gtk_toggle_button_get_active (toggles->data))
        {
540 541 542 543 544
          tags = g_list_prepend (tags, tag);
        }
      else
        {
          *remove_tags = g_list_prepend (*remove_tags, tag);
545 546 547
        }
    }

548
  {
549 550
    GList   *list;
    gdouble  pixels;
551 552 553 554 555 556

    for (list = editor->buffer->size_tags; list; list = g_list_next (list))
      *remove_tags = g_list_prepend (*remove_tags, list->data);

    pixels = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (editor->size_entry), 0);

557 558 559 560 561 562 563 564 565 566 567 568
    if (pixels != 0.0)
      {
        GtkTextTag *tag;
        gdouble     points;

        points = gimp_units_to_points (pixels,
                                       GIMP_UNIT_PIXEL,
                                       editor->resolution_y);
        tag = gimp_text_buffer_get_size_tag (editor->buffer,
                                             PANGO_SCALE * points);
        tags = g_list_prepend (tags, tag);
      }
569 570 571 572 573 574 575 576 577 578 579
  }

  {
    GList       *list;
    const gchar *font_name;

    for (list = editor->buffer->font_tags; list; list = g_list_next (list))
      *remove_tags = g_list_prepend (*remove_tags, list->data);

    font_name = gimp_context_get_font_name (editor->context);

580 581 582 583 584 585 586
    if (font_name)
      {
        GtkTextTag  *tag;

        tag = gimp_text_buffer_get_font_tag (editor->buffer, font_name);
        tags = g_list_prepend (tags, tag);
      }
587 588 589
  }

  {
590 591
    GList   *list;
    GimpRGB  color;
592 593 594 595 596 597 598

    for (list = editor->buffer->color_tags; list; list = g_list_next (list))
      *remove_tags = g_list_prepend (*remove_tags, list->data);

    gimp_color_button_get_color (GIMP_COLOR_BUTTON (editor->color_button),
                                 &color);

599 600 601 602 603 604 605
    if (TRUE) /* FIXME should have "inconsistent" state as for font and size */
      {
        GtkTextTag *tag;

        tag = gimp_text_buffer_get_color_tag (editor->buffer, &color);
        tags = g_list_prepend (tags, tag);
      }
606 607
  }

608 609
  *remove_tags = g_list_reverse (*remove_tags);

610 611 612
  return g_list_reverse (tags);
}

613 614 615 616 617 618

/*  private functions  */

static GtkWidget *
gimp_text_style_editor_create_toggle (GimpTextStyleEditor *editor,
                                      GtkTextTag          *tag,
619
                                      const gchar         *icon_name,
620
                                      const gchar         *tooltip)
621 622 623 624 625 626
{
  GtkWidget *toggle;
  GtkWidget *image;

  toggle = gtk_toggle_button_new ();
  gtk_widget_set_can_focus (toggle, FALSE);
627
  gtk_box_pack_start (GTK_BOX (editor->lower_hbox), toggle, FALSE, FALSE, 0);
628 629
  gtk_widget_show (toggle);

630 631
  gimp_help_set_help_data (toggle, tooltip, NULL);

632
  editor->toggles = g_list_append (editor->toggles, toggle);
633 634 635 636 637 638
  g_object_set_data (G_OBJECT (toggle), "tag", tag);

  g_signal_connect (toggle, "toggled",
                    G_CALLBACK (gimp_text_style_editor_tag_toggled),
                    editor);

639
  image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
  gtk_container_add (GTK_CONTAINER (toggle), image);
  gtk_widget_show (image);

  return toggle;
}

static void
gimp_text_style_editor_clear_tags (GtkButton           *button,
                                   GimpTextStyleEditor *editor)
{
  GtkTextBuffer *buffer = GTK_TEXT_BUFFER (editor->buffer);

  if (gtk_text_buffer_get_has_selection (buffer))
    {
      GtkTextIter start, end;

      gtk_text_buffer_get_selection_bounds (buffer, &start, &end);

658 659
      gtk_text_buffer_begin_user_action (buffer);

660
      gtk_text_buffer_remove_all_tags (buffer, &start, &end);
661 662

      gtk_text_buffer_end_user_action (buffer);
663 664 665
    }
}

666 667 668 669 670 671
static void
gimp_text_style_editor_font_changed (GimpContext         *context,
                                     GimpFont            *font,
                                     GimpTextStyleEditor *editor)
{
  GtkTextBuffer *buffer = GTK_TEXT_BUFFER (editor->buffer);
672 673
  GList         *insert_tags;
  GList         *remove_tags;
674

675
  if (gtk_text_buffer_get_has_selection (buffer))
676
    {
677 678 679 680 681 682
      GtkTextIter start, end;

      gtk_text_buffer_get_selection_bounds (buffer, &start, &end);

      gimp_text_buffer_set_font (editor->buffer, &start, &end,
                                 gimp_context_get_font_name (context));
683
    }
684

685 686
  insert_tags = gimp_text_style_editor_list_tags (editor, &remove_tags);
  gimp_text_buffer_set_insert_tags (editor->buffer, insert_tags, remove_tags);
687 688
}

689 690 691 692 693 694 695
static void
gimp_text_style_editor_set_font (GimpTextStyleEditor *editor,
                                 GtkTextTag          *font_tag)
{
  gchar *font = NULL;

  if (font_tag)
696
    font = gimp_text_tag_get_font (font_tag);
697 698 699 700 701 702 703 704 705 706 707 708 709 710

  g_signal_handlers_block_by_func (editor->context,
                                   gimp_text_style_editor_font_changed,
                                   editor);

  gimp_context_set_font_name (editor->context, font);

  g_signal_handlers_unblock_by_func (editor->context,
                                     gimp_text_style_editor_font_changed,
                                     editor);

  g_free (font);
}

711 712 713 714 715 716 717 718 719 720 721 722 723 724
static void
gimp_text_style_editor_set_default_font (GimpTextStyleEditor *editor)
{
  g_signal_handlers_block_by_func (editor->context,
                                   gimp_text_style_editor_font_changed,
                                   editor);

  gimp_context_set_font_name (editor->context, editor->text->font);

  g_signal_handlers_unblock_by_func (editor->context,
                                     gimp_text_style_editor_font_changed,
                                     editor);
}

725 726 727 728 729
static void
gimp_text_style_editor_color_changed (GimpColorButton     *button,
                                      GimpTextStyleEditor *editor)
{
  GtkTextBuffer *buffer = GTK_TEXT_BUFFER (editor->buffer);
730 731
  GList         *insert_tags;
  GList         *remove_tags;
732

733
  if (gtk_text_buffer_get_has_selection (buffer))
734
    {
735 736 737 738 739 740 741
      GtkTextIter start, end;
      GimpRGB     color;

      gtk_text_buffer_get_selection_bounds (buffer, &start, &end);

      gimp_color_button_get_color (button, &color);
      gimp_text_buffer_set_color (editor->buffer, &start, &end, &color);
742 743
    }

744 745
  insert_tags = gimp_text_style_editor_list_tags (editor, &remove_tags);
  gimp_text_buffer_set_insert_tags (editor->buffer, insert_tags, remove_tags);
746 747 748 749 750 751 752 753
}

static void
gimp_text_style_editor_set_color (GimpTextStyleEditor *editor,
                                  GtkTextTag          *color_tag)
{
  GimpRGB color;

754 755
  gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);

756
  if (color_tag)
757
    gimp_text_tag_get_fg_color (color_tag, &color);
758 759 760 761 762 763 764 765

  g_signal_handlers_block_by_func (editor->color_button,
                                   gimp_text_style_editor_color_changed,
                                   editor);

  gimp_color_button_set_color (GIMP_COLOR_BUTTON (editor->color_button),
                               &color);

766 767
  /* FIXME should have "inconsistent" state as for font and size */

768 769 770 771 772
  g_signal_handlers_unblock_by_func (editor->color_button,
                                     gimp_text_style_editor_color_changed,
                                     editor);
}

773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
static void
gimp_text_style_editor_set_default_color (GimpTextStyleEditor *editor)
{
  g_signal_handlers_block_by_func (editor->color_button,
                                   gimp_text_style_editor_color_changed,
                                   editor);

  gimp_color_button_set_color (GIMP_COLOR_BUTTON (editor->color_button),
                               &editor->text->color);

  g_signal_handlers_unblock_by_func (editor->color_button,
                                     gimp_text_style_editor_color_changed,
                                     editor);
}

788 789 790 791 792 793
static void
gimp_text_style_editor_tag_toggled (GtkToggleButton     *toggle,
                                    GimpTextStyleEditor *editor)
{
  GtkTextBuffer *buffer = GTK_TEXT_BUFFER (editor->buffer);
  GtkTextTag    *tag    = g_object_get_data (G_OBJECT (toggle), "tag");
794 795
  GList         *insert_tags;
  GList         *remove_tags;
796 797 798 799 800 801 802

  if (gtk_text_buffer_get_has_selection (buffer))
    {
      GtkTextIter start, end;

      gtk_text_buffer_get_selection_bounds (buffer, &start, &end);

803 804
      gtk_text_buffer_begin_user_action (buffer);

805 806 807 808 809 810 811 812
      if (gtk_toggle_button_get_active (toggle))
        {
          gtk_text_buffer_apply_tag (buffer, tag, &start, &end);
        }
      else
        {
          gtk_text_buffer_remove_tag (buffer, tag, &start, &end);
        }
813 814

      gtk_text_buffer_end_user_action (buffer);
815
    }
816

817 818
  insert_tags = gimp_text_style_editor_list_tags (editor, &remove_tags);
  gimp_text_buffer_set_insert_tags (editor->buffer, insert_tags, remove_tags);
819 820 821
}

static void
822 823 824
gimp_text_style_editor_set_toggle (GimpTextStyleEditor *editor,
                                   GtkToggleButton     *toggle,
                                   gboolean             active)
825 826 827 828 829
{
  g_signal_handlers_block_by_func (toggle,
                                   gimp_text_style_editor_tag_toggled,
                                   editor);

830
  gtk_toggle_button_set_active (toggle, active);
831 832 833 834 835 836

  g_signal_handlers_unblock_by_func (toggle,
                                     gimp_text_style_editor_tag_toggled,
                                     editor);
}

837
static void
838
gimp_text_style_editor_size_changed (GimpSizeEntry       *entry,
839 840 841
                                     GimpTextStyleEditor *editor)
{
  GtkTextBuffer *buffer = GTK_TEXT_BUFFER (editor->buffer);
842 843
  GList         *insert_tags;
  GList         *remove_tags;
844

845
  if (gtk_text_buffer_get_has_selection (buffer))
846
    {
847 848
      GtkTextIter start, end;
      gdouble     points;
849

850 851 852 853 854
      gtk_text_buffer_get_selection_bounds (buffer, &start, &end);

      points = gimp_units_to_points (gimp_size_entry_get_refval (entry, 0),
                                     GIMP_UNIT_PIXEL,
                                     editor->resolution_y);
855

856 857 858 859 860 861
      gimp_text_buffer_set_size (editor->buffer, &start, &end,
                                 PANGO_SCALE * points);
    }

  insert_tags = gimp_text_style_editor_list_tags (editor, &remove_tags);
  gimp_text_buffer_set_insert_tags (editor->buffer, insert_tags, remove_tags);
862 863 864 865
}

static void
gimp_text_style_editor_set_size (GimpTextStyleEditor *editor,
866
                                 GtkTextTag          *size_tag)
867
{
868 869
  gint    size = 0;
  gdouble pixels;
870 871

  if (size_tag)
872
    size = gimp_text_tag_get_size (size_tag);
873

874
  g_signal_handlers_block_by_func (editor->size_entry,
875 876 877
                                   gimp_text_style_editor_size_changed,
                                   editor);

878 879 880 881
  pixels = gimp_units_to_pixels ((gdouble) size / PANGO_SCALE,
                                 GIMP_UNIT_POINT,
                                 editor->resolution_y);
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (editor->size_entry), 0, pixels);
882

883 884 885 886 887 888 889 890
  if (size == 0)
    {
      GtkWidget *spinbutton;

      spinbutton = gimp_size_entry_get_help_widget (GIMP_SIZE_ENTRY (editor->size_entry), 0);

      gtk_entry_set_text (GTK_ENTRY (spinbutton), "");
    }
891

892
  g_signal_handlers_unblock_by_func (editor->size_entry,
893 894 895 896
                                     gimp_text_style_editor_size_changed,
                                     editor);
}

897 898 899
static void
gimp_text_style_editor_set_default_size (GimpTextStyleEditor *editor)
{
900
  gdouble pixels = gimp_units_to_pixels (editor->text->font_size,
901 902 903
                                         editor->text->unit,
                                         editor->resolution_y);

904
  g_signal_handlers_block_by_func (editor->size_entry,
905 906 907
                                   gimp_text_style_editor_size_changed,
                                   editor);

908
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (editor->size_entry), 0, pixels);
909

910
  g_signal_handlers_unblock_by_func (editor->size_entry,
911 912 913 914
                                     gimp_text_style_editor_size_changed,
                                     editor);
}

915
static void
916 917
gimp_text_style_editor_baseline_changed (GtkAdjustment       *adjustment,
                                         GimpTextStyleEditor *editor)
918
{
919 920
  GtkTextBuffer *buffer = GTK_TEXT_BUFFER (editor->buffer);
  GtkTextIter    start, end;
921

922 923 924 925 926 927
  if (! gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
    {
      gtk_text_buffer_get_iter_at_mark (buffer, &start,
                                        gtk_text_buffer_get_insert (buffer));
      gtk_text_buffer_get_end_iter (buffer, &end);
    }
928

929 930 931 932 933 934 935
  gimp_text_buffer_set_baseline (editor->buffer, &start, &end,
                                 gtk_adjustment_get_value (adjustment) *
                                 PANGO_SCALE);
}

static void
gimp_text_style_editor_set_baseline (GimpTextStyleEditor *editor,
936
                                     GtkTextTag          *baseline_tag)
937
{
938 939 940
  gint baseline = 0;

  if (baseline_tag)
941
    baseline = gimp_text_tag_get_baseline (baseline_tag);
942

943 944
  g_signal_handlers_block_by_func (editor->baseline_adjustment,
                                   gimp_text_style_editor_baseline_changed,
945 946
                                   editor);

947 948 949 950 951 952 953 954 955 956 957
  if (gtk_adjustment_get_value (editor->baseline_adjustment) !=
      (gdouble) baseline / PANGO_SCALE)
    {
      gtk_adjustment_set_value (editor->baseline_adjustment,
                                (gdouble) baseline / PANGO_SCALE);
    }
  else
    {
      /* make sure the "" really gets replaced */
      g_signal_emit_by_name (editor->baseline_adjustment, "value-changed");
    }
958

959 960
  g_signal_handlers_unblock_by_func (editor->baseline_adjustment,
                                     gimp_text_style_editor_baseline_changed,
961
                                     editor);
962
}
963

964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985
static void
gimp_text_style_editor_kerning_changed (GtkAdjustment       *adjustment,
                                        GimpTextStyleEditor *editor)
{
  GtkTextBuffer *buffer = GTK_TEXT_BUFFER (editor->buffer);
  GtkTextIter    start, end;

  if (! gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
    {
      gtk_text_buffer_get_iter_at_mark (buffer, &start,
                                        gtk_text_buffer_get_insert (buffer));
      end = start;
      gtk_text_iter_forward_char (&end);
    }

  gimp_text_buffer_set_kerning (editor->buffer, &start, &end,
                                gtk_adjustment_get_value (adjustment) *
                                PANGO_SCALE);
}

static void
gimp_text_style_editor_set_kerning (GimpTextStyleEditor *editor,
986
                                    GtkTextTag          *kerning_tag)
987
{
988 989 990
  gint kerning = 0;

  if (kerning_tag)
991
    kerning = gimp_text_tag_get_kerning (kerning_tag);
992

993 994 995 996
  g_signal_handlers_block_by_func (editor->kerning_adjustment,
                                   gimp_text_style_editor_kerning_changed,
                                   editor);

997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
  if (gtk_adjustment_get_value (editor->baseline_adjustment) !=
      (gdouble) kerning / PANGO_SCALE)
    {
      gtk_adjustment_set_value (editor->kerning_adjustment,
                                (gdouble) kerning / PANGO_SCALE);
    }
  else
    {
      /* make sure the "" really gets replaced */
      g_signal_emit_by_name (editor->kerning_adjustment, "value-changed");
    }
1008 1009 1010 1011

  g_signal_handlers_unblock_by_func (editor->kerning_adjustment,
                                     gimp_text_style_editor_kerning_changed,
                                     editor);
1012 1013
}

1014
static void
1015
gimp_text_style_editor_update (GimpTextStyleEditor *editor)
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
{
  if (editor->update_idle_id)
    g_source_remove (editor->update_idle_id);

  editor->update_idle_id =
    gdk_threads_add_idle ((GSourceFunc) gimp_text_style_editor_update_idle,
                          editor);
}

static gboolean
gimp_text_style_editor_update_idle (GimpTextStyleEditor *editor)
1027
{
1028 1029
  GtkTextBuffer *buffer = GTK_TEXT_BUFFER (editor->buffer);

1030 1031 1032 1033 1034 1035
  if (editor->update_idle_id)
    {
      g_source_remove (editor->update_idle_id);
      editor->update_idle_id = 0;
    }

1036 1037
  if (gtk_text_buffer_get_has_selection (buffer))
    {
1038 1039 1040
      GtkTextIter  start, end;
      GtkTextIter  iter;
      GList       *list;
1041 1042
      gboolean     any_toggle_active = TRUE;
      gboolean     font_differs      = FALSE;
1043
      gboolean     color_differs     = FALSE;
1044
      gboolean     size_differs      = FALSE;
1045 1046
      gboolean     baseline_differs  = FALSE;
      gboolean     kerning_differs   = FALSE;
1047
      GtkTextTag  *font_tag          = NULL;
1048
      GtkTextTag  *color_tag         = NULL;
1049
      GtkTextTag  *size_tag          = NULL;
1050
      GtkTextTag  *baseline_tag      = NULL;
1051
      GtkTextTag  *kerning_tag       = NULL;
1052 1053 1054 1055 1056

      gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
      gtk_text_iter_order (&start, &end);

      /*  first, switch all toggles on  */
1057 1058 1059 1060 1061 1062
      for (list = editor->toggles; list; list = g_list_next (list))
        {
          GtkToggleButton *toggle = list->data;

          gimp_text_style_editor_set_toggle (editor, toggle, TRUE);
        }
1063

1064
      /*  and get some initial values  */
1065 1066
      font_tag     = gimp_text_buffer_get_iter_font (editor->buffer,
                                                     &start, NULL);
1067 1068
      color_tag    = gimp_text_buffer_get_iter_color (editor->buffer,
                                                      &start, NULL);
1069 1070 1071 1072 1073 1074
      size_tag     = gimp_text_buffer_get_iter_size (editor->buffer,
                                                     &start, NULL);
      baseline_tag = gimp_text_buffer_get_iter_baseline (editor->buffer,
                                                         &start, NULL);
      kerning_tag  = gimp_text_buffer_get_iter_kerning (editor->buffer,
                                                        &start, NULL);
1075

1076 1077 1078 1079
      for (iter = start;
           gtk_text_iter_in_range (&iter, &start, &end);
           gtk_text_iter_forward_cursor_position (&iter))
        {
1080
          if (any_toggle_active)
1081
            {
1082
              any_toggle_active = FALSE;
1083

1084
              for (list = editor->toggles; list; list = g_list_next (list))
1085
                {
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
                  GtkToggleButton *toggle = list->data;
                  GtkTextTag      *tag    = g_object_get_data (G_OBJECT (toggle),
                                                               "tag");

                  if (! gtk_text_iter_has_tag (&iter, tag))
                    {
                      gimp_text_style_editor_set_toggle (editor, toggle, FALSE);
                    }
                  else
                    {
                      any_toggle_active = TRUE;
                    }
1098
                }
1099 1100 1101 1102
            }

          if (! font_differs)
            {
1103
              GtkTextTag *tag;
1104

1105 1106
              tag = gimp_text_buffer_get_iter_font (editor->buffer, &iter,
                                                    NULL);
1107

1108
              if (tag != font_tag)
1109
                font_differs = TRUE;
1110 1111
            }

1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
          if (! color_differs)
            {
              GtkTextTag *tag;

              tag = gimp_text_buffer_get_iter_color (editor->buffer, &iter,
                                                     NULL);

              if (tag != color_tag)
                color_differs = TRUE;
            }

1123 1124
          if (! size_differs)
            {
1125
              GtkTextTag *tag;
1126

1127 1128
              tag = gimp_text_buffer_get_iter_size (editor->buffer, &iter,
                                                    NULL);
1129

1130
              if (tag != size_tag)
1131 1132 1133
                size_differs = TRUE;
            }

1134 1135
          if (! baseline_differs)
            {
1136
              GtkTextTag *tag;
1137

1138 1139
              tag = gimp_text_buffer_get_iter_baseline (editor->buffer, &iter,
                                                        NULL);
1140

1141
              if (tag != baseline_tag)
1142 1143 1144 1145 1146
                baseline_differs = TRUE;
            }

          if (! kerning_differs)
            {
1147
              GtkTextTag *tag;
1148

1149 1150
              tag = gimp_text_buffer_get_iter_kerning (editor->buffer, &iter,
                                                       NULL);
1151

1152
              if (tag != kerning_tag)
1153 1154 1155 1156
                kerning_differs = TRUE;
            }

          if (! any_toggle_active &&
1157
              color_differs       &&
1158
              font_differs        &&
1159
              size_differs        &&
1160 1161
              baseline_differs    &&
              kerning_differs)
1162 1163
            break;
       }
1164

1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184
      if (font_differs)
        gimp_text_style_editor_set_font (editor, NULL);
      else if (font_tag)
        gimp_text_style_editor_set_font (editor, font_tag);
      else
        gimp_text_style_editor_set_default_font (editor);

      if (color_differs)
        gimp_text_style_editor_set_color (editor, NULL);
      else if (color_tag)
        gimp_text_style_editor_set_color (editor, color_tag);
      else
        gimp_text_style_editor_set_default_color (editor);

      if (size_differs)
        gimp_text_style_editor_set_size (editor, NULL);
      else if (size_tag)
        gimp_text_style_editor_set_size (editor, size_tag);
      else
        gimp_text_style_editor_set_default_size (editor);
1185

1186 1187 1188
      if (baseline_differs)
        gtk_entry_set_text (GTK_ENTRY (editor->baseline_spinbutton), "");
      else
1189
        gimp_text_style_editor_set_baseline (editor, baseline_tag);
1190 1191 1192 1193

      if (kerning_differs)
        gtk_entry_set_text (GTK_ENTRY (editor->kerning_spinbutton), "");
      else
1194
        gimp_text_style_editor_set_kerning (editor, kerning_tag);
1195
    }
1196
  else /* no selection */
1197
    {
1198 1199 1200 1201 1202
      GtkTextIter  cursor;
      GSList      *tags;
      GSList      *tags_on;
      GSList      *tags_off;
      GList       *list;
1203 1204 1205 1206

      gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
                                        gtk_text_buffer_get_insert (buffer));

1207 1208 1209
      tags     = gtk_text_iter_get_tags (&cursor);
      tags_on  = gtk_text_iter_get_toggled_tags (&cursor, TRUE);
      tags_off = gtk_text_iter_get_toggled_tags (&cursor, FALSE);
1210

1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224
      for (list = editor->buffer->font_tags; list; list = g_list_next (list))
        {
          GtkTextTag *tag = list->data;

          if ((g_slist_find (tags, tag) &&
               ! g_slist_find (tags_on, tag)) ||
              g_slist_find (tags_off, tag))
            {
              gimp_text_style_editor_set_font (editor, tag);
              break;
            }
        }

      if (! list)
1225
        gimp_text_style_editor_set_default_font (editor);
1226

1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
      for (list = editor->buffer->color_tags; list; list = g_list_next (list))
        {
          GtkTextTag *tag = list->data;

          if ((g_slist_find (tags, tag) &&
               ! g_slist_find (tags_on, tag)) ||
              g_slist_find (tags_off, tag))
            {
              gimp_text_style_editor_set_color (editor, tag);
              break;
            }
        }

      if (! list)
1241
        gimp_text_style_editor_set_default_color (editor);
1242

1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
      for (list = editor->buffer->size_tags; list; list = g_list_next (list))
        {
          GtkTextTag *tag = list->data;

          if ((g_slist_find (tags, tag) &&
               ! g_slist_find (tags_on, tag)) ||
              g_slist_find (tags_off, tag))
            {
              gimp_text_style_editor_set_size (editor, tag);
              break;
            }
        }

      if (! list)
1257
        gimp_text_style_editor_set_default_size (editor);
1258

1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
      for (list = editor->buffer->baseline_tags; list; list = g_list_next (list))
        {
          GtkTextTag *tag = list->data;

          if ((g_slist_find (tags, tag) &&
               ! g_slist_find (tags_on, tag)) ||
              g_slist_find (tags_off, tag))
            {
              gimp_text_style_editor_set_baseline (editor, tag);
              break;
            }
        }

      if (! list)
        gimp_text_style_editor_set_baseline (editor, NULL);

1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
      for (list = editor->toggles; list; list = g_list_next (list))
        {
          GtkToggleButton *toggle = list->data;
          GtkTextTag      *tag    = g_object_get_data (G_OBJECT (toggle),
                                                       "tag");

          gimp_text_style_editor_set_toggle (editor, toggle,
                                             (g_slist_find (tags, tag) &&
                                              ! g_slist_find (tags_on, tag)) ||
                                             g_slist_find (tags_off, tag));
        }
1286

1287 1288 1289 1290 1291 1292
      {
        GtkTextTag *tag;

        tag = gimp_text_buffer_get_iter_kerning (editor->buffer, &cursor, NULL);
        gimp_text_style_editor_set_kerning (editor, tag);
      }
1293

1294 1295 1296
      g_slist_free (tags);
      g_slist_free (tags_on);
      g_slist_free (tags_off);
1297
    }
1298

1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316
  if (editor->context->font_name &&
      g_strcmp0 (editor->context->font_name,
                 gimp_object_get_name (gimp_context_get_font (editor->context))))
    {
      /* A font is set, but is unavailable; change the help text. */
      gchar *help_text;

      help_text = g_strdup_printf (_("Font \"%s\" unavailable on this system"),
                                   editor->context->font_name);
      gimp_help_set_help_data (editor->font_entry, help_text, NULL);
      g_free (help_text);
    }
  else
    {
      gimp_help_set_help_data (editor->font_entry,
                               _("Change font of selected text"), NULL);
    }

1317
  return FALSE;
1318
}