Commit aff83063 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

app/text/gimptext.[ch] added a language property to GimpText which

2003-02-24  Sven Neumann  <sven@gimp.org>

	* app/text/gimptext.[ch]
	* app/text/gimptextlayout.c: added a language property to GimpText
	which defaults to the language derived from the users locale. Set
	the language on the PangoContext.
parent f12dd3f1
2003-02-24 Sven Neumann <sven@gimp.org>
* app/text/gimptext.[ch]
* app/text/gimptextlayout.c: added a language property to GimpText
which defaults to the language derived from the users locale. Set
the language on the PangoContext.
2003-02-24 Sven Neumann <sven@gimp.org>
* plug-ins/common/mblur.c: added parentheses to please the
......
......@@ -21,6 +21,8 @@
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "libgimpbase/gimplimits.h"
......@@ -43,6 +45,7 @@ enum
PROP_FONT,
PROP_FONT_SIZE,
PROP_FONT_SIZE_UNIT,
PROP_LANGUAGE,
PROP_COLOR,
PROP_FIXED_WIDTH,
PROP_JUSTIFICATION,
......@@ -52,16 +55,18 @@ enum
PROP_BORDER
};
static void gimp_text_class_init (GimpTextClass *klass);
static void gimp_text_finalize (GObject *object);
static void gimp_text_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_text_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_text_class_init (GimpTextClass *klass);
static void gimp_text_finalize (GObject *object);
static void gimp_text_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_text_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gchar * gimp_text_get_default_language (void);
static GObjectClass *parent_class = NULL;
......@@ -109,6 +114,7 @@ gimp_text_class_init (GimpTextClass *klass)
GObjectClass *object_class;
GParamSpec *param_spec;
GimpRGB black;
gchar *language;
object_class = G_OBJECT_CLASS (klass);
......@@ -120,6 +126,8 @@ gimp_text_class_init (GimpTextClass *klass)
gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
language = gimp_text_get_default_language ();
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_TEXT,
"text", NULL,
NULL,
......@@ -136,6 +144,10 @@ gimp_text_class_init (GimpTextClass *klass)
"font-size-unit", NULL,
TRUE, GIMP_UNIT_PIXEL,
0);
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_LANGUAGE,
"language", NULL,
language,
0);
GIMP_CONFIG_INSTALL_PROP_COLOR (object_class, PROP_COLOR,
"color", NULL,
&black,
......@@ -172,6 +184,7 @@ gimp_text_class_init (GimpTextClass *klass)
G_PARAM_CONSTRUCT | G_PARAM_WRITABLE);
g_object_class_install_property (object_class, PROP_BORDER, param_spec);
g_free (language);
}
static void
......@@ -189,6 +202,11 @@ gimp_text_finalize (GObject *object)
g_free (text->font);
text->font = NULL;
}
if (text->language)
{
g_free (text->language);
text->language = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......@@ -215,6 +233,9 @@ gimp_text_get_property (GObject *object,
case PROP_FONT_SIZE_UNIT:
g_value_set_int (value, text->font_size_unit);
break;
case PROP_LANGUAGE:
g_value_set_string (value, text->language);
break;
case PROP_COLOR:
g_value_set_boxed (value, &text->color);
break;
......@@ -264,6 +285,10 @@ gimp_text_set_property (GObject *object,
case PROP_FONT_SIZE_UNIT:
text->font_size_unit = g_value_get_int (value);
break;
case PROP_LANGUAGE:
g_free (text->language);
text->language = g_value_dup_string (value);
break;
case PROP_COLOR:
color = g_value_get_boxed (value);
text->color = *color;
......@@ -291,3 +316,44 @@ gimp_text_set_property (GObject *object,
break;
}
}
/*
* basically copied from gtk_get_default_language()
*/
static gchar *
gimp_text_get_default_language (void)
{
gchar *lang;
gchar *p;
#ifdef G_OS_WIN32
p = getenv ("LC_ALL");
if (p != NULL)
lang = g_strdup (p);
else
{
p = getenv ("LANG");
if (p != NULL)
lang = g_strdup (p);
else
{
p = getenv ("LC_CTYPE");
if (p != NULL)
lang = g_strdup (p);
else
lang = g_win32_getlocale ();
}
}
#else
lang = g_strdup (setlocale (LC_CTYPE, NULL));
#endif
p = strchr (lang, '.');
if (p)
*p = '\0';
p = strchr (lang, '@');
if (p)
*p = '\0';
return lang;
}
......@@ -40,6 +40,7 @@ struct _GimpText
gchar *font;
gdouble font_size;
GimpUnit font_size_unit;
gchar *language;
GimpRGB color;
GimpTextJustification justify;
gdouble indent;
......
......@@ -177,6 +177,10 @@ gimp_text_layout_new (GimpText *text,
context = gimp_image_get_pango_context (image);
if (text->language)
pango_context_set_language (context,
pango_language_from_string (text->language));
layout = g_object_new (GIMP_TYPE_TEXT_LAYOUT, NULL);
layout->text = g_object_ref (text);
layout->layout = pango_layout_new (context);
......
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