示例#1
0
GtkTextTag *
gimp_text_buffer_get_iter_font (GimpTextBuffer     *buffer,
                                const GtkTextIter  *iter,
                                gchar             **font)
{
  GList *list;

  for (list = buffer->font_tags; list; list = g_list_next (list))
    {
      GtkTextTag *tag = list->data;

      if (gtk_text_iter_has_tag (iter, tag))
        {
          if (font)
            *font = gimp_text_tag_get_font (tag);

          return tag;
        }
    }

  if (font)
    *font = NULL;

  return NULL;
}
示例#2
0
static void
gimp_text_style_editor_set_font (GimpTextStyleEditor *editor,
                                 GtkTextTag          *font_tag)
{
  gchar *font = NULL;

  if (font_tag)
    font = gimp_text_tag_get_font (font_tag);

  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);
}
示例#3
0
GtkTextTag *
gimp_text_buffer_get_font_tag (GimpTextBuffer *buffer,
                               const gchar    *font)
{
  GList      *list;
  GtkTextTag *tag;
  gchar       name[256];

  for (list = buffer->font_tags; list; list = g_list_next (list))
    {
      gchar *tag_font;

      tag = list->data;

      tag_font = gimp_text_tag_get_font (tag);

      if (! strcmp (font, tag_font))
        {
          g_free (tag_font);
          return tag;
        }

      g_free (tag_font);
    }

  g_snprintf (name, sizeof (name), "font-%s", font);

  tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer),
                                    name,
                                    "font", font,
                                    NULL);

  buffer->font_tags = g_list_prepend (buffer->font_tags, tag);

  return tag;
}
示例#4
0
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;
}