Commit a6b2d102 authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

app: add utility functions for getting GtkTextTag properties

and also #define the names of the properties we (ab)use, so we don't
have to use magic strings all over the place, and we don't have to use
g_object_get() either.
parent 0313ce3d
......@@ -306,6 +306,8 @@ libappwidgets_a_sources = \
gimptextproxy.h \
gimptextstyleeditor.c \
gimptextstyleeditor.h \
gimptexttag.c \
gimptexttag.h \
gimpthumbbox.c \
gimpthumbbox.h \
gimptoggleaction.c \
......
......@@ -47,6 +47,7 @@
#include "gimptextbuffer.h"
#include "gimptextbuffer-serialize.h"
#include "gimptexttag.h"
#include "gimp-intl.h"
......@@ -344,9 +345,7 @@ gimp_text_buffer_get_iter_size (GimpTextBuffer *buffer,
if (gtk_text_iter_has_tag (iter, tag))
{
if (size)
g_object_get (tag,
"size", size,
NULL);
*size = gimp_text_tag_get_size (tag);
return tag;
}
......@@ -368,15 +367,9 @@ gimp_text_buffer_get_size_tag (GimpTextBuffer *buffer,
for (list = buffer->size_tags; list; list = g_list_next (list))
{
gint tag_size;
tag = list->data;
g_object_get (tag,
"size", &tag_size,
NULL);
if (tag_size == size)
if (size == gimp_text_tag_get_size (tag))
return tag;
}
......@@ -384,7 +377,7 @@ gimp_text_buffer_get_size_tag (GimpTextBuffer *buffer,
tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer),
name,
"size", size,
GIMP_TEXT_PROP_NAME_SIZE, size,
NULL);
buffer->size_tags = g_list_prepend (buffer->size_tags, tag);
......@@ -512,9 +505,7 @@ gimp_text_buffer_get_iter_baseline (GimpTextBuffer *buffer,
if (gtk_text_iter_has_tag (iter, tag))
{
if (baseline)
g_object_get (tag,
"rise", baseline,
NULL);
*baseline = gimp_text_tag_get_baseline (tag);
return tag;
}
......@@ -536,15 +527,9 @@ gimp_text_buffer_get_baseline_tag (GimpTextBuffer *buffer,
for (list = buffer->baseline_tags; list; list = g_list_next (list))
{
gint tag_baseline;
tag = list->data;
g_object_get (tag,
"rise", &tag_baseline,
NULL);
if (tag_baseline == baseline)
if (baseline == gimp_text_tag_get_baseline (tag))
return tag;
}
......@@ -552,7 +537,7 @@ gimp_text_buffer_get_baseline_tag (GimpTextBuffer *buffer,
tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer),
name,
"rise", baseline,
GIMP_TEXT_PROP_NAME_BASELINE, baseline,
NULL);
buffer->baseline_tags = g_list_prepend (buffer->baseline_tags, tag);
......@@ -680,9 +665,7 @@ gimp_text_buffer_get_iter_kerning (GimpTextBuffer *buffer,
if (gtk_text_iter_has_tag (iter, tag))
{
if (kerning)
g_object_get (tag,
"rise", kerning, /* FIXME */
NULL);
*kerning = gimp_text_tag_get_kerning (tag);
return tag;
}
......@@ -704,15 +687,9 @@ gimp_text_buffer_get_kerning_tag (GimpTextBuffer *buffer,
for (list = buffer->kerning_tags; list; list = g_list_next (list))
{
gint tag_kerning;
tag = list->data;
g_object_get (tag,
"rise", &tag_kerning, /* FIXME */
NULL);
if (tag_kerning == kerning)
if (kerning == gimp_text_tag_get_kerning (tag))
return tag;
}
......@@ -720,7 +697,7 @@ gimp_text_buffer_get_kerning_tag (GimpTextBuffer *buffer,
tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer),
name,
"rise", kerning, /* FIXME */
GIMP_TEXT_PROP_NAME_KERNING, kerning,
NULL);
buffer->kerning_tags = g_list_prepend (buffer->kerning_tags, tag);
......@@ -848,9 +825,7 @@ gimp_text_buffer_get_iter_font (GimpTextBuffer *buffer,
if (gtk_text_iter_has_tag (iter, tag))
{
if (font)
g_object_get (tag,
"font", font,
NULL);
*font = gimp_text_tag_get_font (tag);
return tag;
}
......@@ -876,9 +851,7 @@ gimp_text_buffer_get_font_tag (GimpTextBuffer *buffer,
tag = list->data;
g_object_get (tag,
"font", &tag_font,
NULL);
tag_font = gimp_text_tag_get_font (tag);
if (! strcmp (font, tag_font))
{
......@@ -935,6 +908,13 @@ gimp_text_buffer_set_font (GimpTextBuffer *buffer,
gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
}
/* Pango markup attribute names */
#define GIMP_TEXT_ATTR_NAME_SIZE "size"
#define GIMP_TEXT_ATTR_NAME_BASELINE "rise"
#define GIMP_TEXT_ATTR_NAME_KERNING "letter_spacing"
#define GIMP_TEXT_ATTR_NAME_FONT "font"
const gchar *
gimp_text_buffer_tag_to_name (GimpTextBuffer *buffer,
GtkTextTag *tag,
......@@ -969,68 +949,40 @@ gimp_text_buffer_tag_to_name (GimpTextBuffer *buffer,
else if (g_list_find (buffer->size_tags, tag))
{
if (attribute)
*attribute = "size";
*attribute = GIMP_TEXT_ATTR_NAME_SIZE;
if (value)
{
gint size;
g_object_get (tag,
"size", &size,
NULL);
*value = g_strdup_printf ("%d", size);
}
*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 = "rise";
*attribute = GIMP_TEXT_ATTR_NAME_BASELINE;
if (value)
{
gint baseline;
g_object_get (tag,
"rise", &baseline,
NULL);
*value = g_strdup_printf ("%d", baseline);
}
*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 = "letter_spacing";
*attribute = GIMP_TEXT_ATTR_NAME_KERNING;
if (value)
{
gint kerning;
g_object_get (tag,
"rise", &kerning, /* FIXME */
NULL);
*value = g_strdup_printf ("%d", kerning);
}
*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 = "font";
*attribute = GIMP_TEXT_ATTR_NAME_FONT;
if (value)
{
g_object_get (tag,
"font", value,
NULL);
}
*value = gimp_text_tag_get_font (tag);
return "span";
}
......@@ -1067,19 +1019,19 @@ gimp_text_buffer_name_to_tag (GimpTextBuffer *buffer,
attribute != NULL &&
value != NULL)
{
if (! strcmp (attribute, "size"))
if (! strcmp (attribute, GIMP_TEXT_ATTR_NAME_SIZE))
{
return gimp_text_buffer_get_size_tag (buffer, atoi (value));
}
else if (! strcmp (attribute, "rise"))
else if (! strcmp (attribute, GIMP_TEXT_ATTR_NAME_BASELINE))
{
return gimp_text_buffer_get_baseline_tag (buffer, atoi (value));
}
else if (! strcmp (attribute, "letter_spacing"))
else if (! strcmp (attribute, GIMP_TEXT_ATTR_NAME_KERNING))
{
return gimp_text_buffer_get_kerning_tag (buffer, atoi (value));
}
else if (! strcmp (attribute, "font"))
else if (! strcmp (attribute, GIMP_TEXT_ATTR_NAME_FONT))
{
return gimp_text_buffer_get_font_tag (buffer, value);
}
......
......@@ -37,6 +37,7 @@
#include "gimpcontainerview.h"
#include "gimptextbuffer.h"
#include "gimptextstyleeditor.h"
#include "gimptexttag.h"
#include "gimp-intl.h"
......@@ -559,9 +560,7 @@ gimp_text_style_editor_set_font (GimpTextStyleEditor *editor,
gchar *font = NULL;
if (font_tag)
g_object_get (font_tag,
"font", &font,
NULL);
font = gimp_text_tag_get_font (font_tag);
g_signal_handlers_block_by_func (editor->context,
gimp_text_style_editor_font_changed,
......@@ -649,9 +648,7 @@ gimp_text_style_editor_set_size (GimpTextStyleEditor *editor,
gint size = 0;
if (size_tag)
g_object_get (size_tag,
"size", &size,
NULL);
size = gimp_text_tag_get_size (size_tag);
g_signal_handlers_block_by_func (editor->size_adjustment,
gimp_text_style_editor_size_changed,
......@@ -697,9 +694,7 @@ gimp_text_style_editor_set_baseline (GimpTextStyleEditor *editor,
gint baseline = 0;
if (baseline_tag)
g_object_get (baseline_tag,
"rise", &baseline,
NULL);
baseline = gimp_text_tag_get_baseline (baseline_tag);
g_signal_handlers_block_by_func (editor->baseline_adjustment,
gimp_text_style_editor_baseline_changed,
......@@ -742,9 +737,7 @@ gimp_text_style_editor_set_kerning (GimpTextStyleEditor *editor,
gint kerning = 0;
if (kerning_tag)
g_object_get (kerning_tag,
"rise", &kerning, /* FIXME */
NULL);
kerning = gimp_text_tag_get_kerning (kerning_tag);
g_signal_handlers_block_by_func (editor->kerning_adjustment,
gimp_text_style_editor_kerning_changed,
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpTextTag
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "gimptexttag.h"
gint
gimp_text_tag_get_size (GtkTextTag *tag)
{
gint size;
g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
g_object_get (tag,
GIMP_TEXT_PROP_NAME_SIZE, &size,
NULL);
return size;
}
gint
gimp_text_tag_get_baseline (GtkTextTag *tag)
{
gint baseline;
g_object_get (tag,
GIMP_TEXT_PROP_NAME_BASELINE, &baseline,
NULL);
return baseline;
}
gint
gimp_text_tag_get_kerning (GtkTextTag *tag)
{
gint kerning;
g_object_get (tag,
GIMP_TEXT_PROP_NAME_KERNING, &kerning,
NULL);
return kerning;
}
gchar *
gimp_text_tag_get_font (GtkTextTag *tag)
{
gchar *font;
g_object_get (tag,
GIMP_TEXT_PROP_NAME_FONT, &font,
NULL);
return font;
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpTextTag
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_TEXT_TAG_H__
#define __GIMP_TEXT_TAG_H__
/* GtkTextTag property names */
#define GIMP_TEXT_PROP_NAME_SIZE "size"
#define GIMP_TEXT_PROP_NAME_BASELINE "rise"
#define GIMP_TEXT_PROP_NAME_KERNING "rise" /* FIXME */
#define GIMP_TEXT_PROP_NAME_FONT "font"
gint gimp_text_tag_get_size (GtkTextTag *tag);
gint gimp_text_tag_get_baseline (GtkTextTag *tag);
gint gimp_text_tag_get_kerning (GtkTextTag *tag);
gchar * gimp_text_tag_get_font (GtkTextTag *tag);
#endif /* __GIMP_TEXT_TAG_H__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment