static void gimp_text_style_editor_set_size (GimpTextStyleEditor *editor, GtkTextTag *size_tag) { gint size = 0; gdouble pixels; if (size_tag) size = gimp_text_tag_get_size (size_tag); g_signal_handlers_block_by_func (editor->size_entry, gimp_text_style_editor_size_changed, editor); 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); 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), ""); } g_signal_handlers_unblock_by_func (editor->size_entry, gimp_text_style_editor_size_changed, editor); }
GtkTextTag * gimp_text_buffer_get_iter_size (GimpTextBuffer *buffer, const GtkTextIter *iter, gint *size) { GList *list; for (list = buffer->size_tags; list; list = g_list_next (list)) { GtkTextTag *tag = list->data; if (gtk_text_iter_has_tag (iter, tag)) { if (size) *size = gimp_text_tag_get_size (tag); return tag; } } if (size) *size = 0; return NULL; }
GtkTextTag * gimp_text_buffer_get_size_tag (GimpTextBuffer *buffer, gint size) { GList *list; GtkTextTag *tag; gchar name[32]; for (list = buffer->size_tags; list; list = g_list_next (list)) { tag = list->data; if (size == gimp_text_tag_get_size (tag)) return tag; } g_snprintf (name, sizeof (name), "size-%d", size); tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer), name, GIMP_TEXT_PROP_NAME_SIZE, size, NULL); buffer->size_tags = g_list_prepend (buffer->size_tags, tag); return tag; }
const gchar * gimp_text_buffer_tag_to_name (GimpTextBuffer *buffer, GtkTextTag *tag, const gchar **attribute, gchar **value) { g_return_val_if_fail (GIMP_IS_TEXT_BUFFER (buffer), NULL); g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), NULL); if (attribute) *attribute = NULL; if (value) *value = NULL; if (tag == buffer->bold_tag) { return "b"; } else if (tag == buffer->italic_tag) { return "i"; } else if (tag == buffer->underline_tag) { return "u"; } else if (tag == buffer->strikethrough_tag) { return "s"; } else if (g_list_find (buffer->size_tags, tag)) { if (attribute) *attribute = GIMP_TEXT_ATTR_NAME_SIZE; if (value) *value = g_strdup_printf ("%d", gimp_text_tag_get_size (tag)); return "span"; } else if (g_list_find (buffer->baseline_tags, tag)) { if (attribute) *attribute = GIMP_TEXT_ATTR_NAME_BASELINE; if (value) *value = g_strdup_printf ("%d", gimp_text_tag_get_baseline (tag)); return "span"; } else if (g_list_find (buffer->kerning_tags, tag)) { if (attribute) *attribute = GIMP_TEXT_ATTR_NAME_KERNING; if (value) *value = g_strdup_printf ("%d", gimp_text_tag_get_kerning (tag)); return "span"; } else if (g_list_find (buffer->font_tags, tag)) { if (attribute) *attribute = GIMP_TEXT_ATTR_NAME_FONT; if (value) *value = gimp_text_tag_get_font (tag); return "span"; } else if (g_list_find (buffer->color_tags, tag)) { if (attribute) *attribute = GIMP_TEXT_ATTR_NAME_COLOR; if (value) { GimpRGB color; guchar r, g, b; gimp_text_tag_get_color (tag, &color); gimp_rgb_get_uchar (&color, &r, &g, &b); *value = g_strdup_printf ("#%02x%02x%02x", r, g, b); } return "span"; } return NULL; }