app/text/text-enums.[ch] replaced GimpTextAlignment with
2003-02-05 Sven Neumann <sven@gimp.org> * app/text/text-enums.[ch] * app/text/gimptext.[ch]: replaced GimpTextAlignment with GimpTextJustification. Added indentation property. * app/text/gimptextlayout.c: implemented text justification, indentation and line spacing as far as supported by Pango.
This commit is contained in:
committed by
Sven Neumann
parent
70c3ea651b
commit
aa48e6165e
@ -1,3 +1,12 @@
|
||||
2003-02-05 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/text/text-enums.[ch]
|
||||
* app/text/gimptext.[ch]: replaced GimpTextAlignment with
|
||||
GimpTextJustification. Added indentation property.
|
||||
|
||||
* app/text/gimptextlayout.c: implemented text justification,
|
||||
indentation and line spacing as far as supported by Pango.
|
||||
|
||||
2003-02-05 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/text/gimptextlayer.c
|
||||
|
||||
@ -41,9 +41,10 @@ enum
|
||||
PROP_FONT_SIZE,
|
||||
PROP_FONT_SIZE_UNIT,
|
||||
PROP_COLOR,
|
||||
PROP_ALIGNMENT,
|
||||
PROP_LETTER_SPACING,
|
||||
PROP_JUSTIFICATION,
|
||||
PROP_INDENTATION,
|
||||
PROP_LINE_SPACING,
|
||||
PROP_LETTER_SPACING,
|
||||
PROP_FIXED_WIDTH,
|
||||
PROP_FIXED_HEIGHT,
|
||||
PROP_GRAVITY,
|
||||
@ -138,19 +139,23 @@ gimp_text_class_init (GimpTextClass *klass)
|
||||
"color", NULL,
|
||||
&black,
|
||||
0);
|
||||
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_ALIGNMENT,
|
||||
"alignment", NULL,
|
||||
GIMP_TYPE_TEXT_ALIGNMENT,
|
||||
GIMP_TEXT_ALIGNMENT_LEFT,
|
||||
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_JUSTIFICATION,
|
||||
"justify", NULL,
|
||||
GIMP_TYPE_TEXT_JUSTIFICATION,
|
||||
GIMP_TEXT_JUSTIFY_LEFT,
|
||||
0);
|
||||
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_INDENTATION,
|
||||
"indent", NULL,
|
||||
-8192.0, 8192.0, 0.0,
|
||||
0);
|
||||
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_LINE_SPACING,
|
||||
"line-spacing", NULL,
|
||||
-8192.0, 8192.0, 0.0,
|
||||
0);
|
||||
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_LETTER_SPACING,
|
||||
"letter-spacing", NULL,
|
||||
0.0, 64.0, 1.0,
|
||||
0);
|
||||
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_LINE_SPACING,
|
||||
"line-spacing", NULL,
|
||||
0.0, 64.0, 1.0,
|
||||
0);
|
||||
GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_FIXED_WIDTH,
|
||||
"fixed-width", NULL,
|
||||
0, GIMP_MAX_IMAGE_SIZE, 0,
|
||||
@ -216,15 +221,18 @@ gimp_text_get_property (GObject *object,
|
||||
case PROP_COLOR:
|
||||
g_value_set_boxed (value, &text->color);
|
||||
break;
|
||||
case PROP_ALIGNMENT:
|
||||
g_value_set_enum (value, text->alignment);
|
||||
case PROP_JUSTIFICATION:
|
||||
g_value_set_enum (value, text->justify);
|
||||
break;
|
||||
case PROP_LETTER_SPACING:
|
||||
g_value_set_double (value, text->letter_spacing);
|
||||
case PROP_INDENTATION:
|
||||
g_value_set_double (value, text->indent);
|
||||
break;
|
||||
case PROP_LINE_SPACING:
|
||||
g_value_set_double (value, text->line_spacing);
|
||||
break;
|
||||
case PROP_LETTER_SPACING:
|
||||
g_value_set_double (value, text->letter_spacing);
|
||||
break;
|
||||
case PROP_FIXED_WIDTH:
|
||||
g_value_set_int (value, text->fixed_width);
|
||||
break;
|
||||
@ -269,15 +277,18 @@ gimp_text_set_property (GObject *object,
|
||||
color = g_value_get_boxed (value);
|
||||
text->color = *color;
|
||||
break;
|
||||
case PROP_ALIGNMENT:
|
||||
text->alignment = g_value_get_enum (value);
|
||||
case PROP_JUSTIFICATION:
|
||||
text->justify = g_value_get_enum (value);
|
||||
break;
|
||||
case PROP_LETTER_SPACING:
|
||||
text->letter_spacing = g_value_get_double (value);
|
||||
case PROP_INDENTATION:
|
||||
text->indent = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_LINE_SPACING:
|
||||
text->line_spacing = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_LETTER_SPACING:
|
||||
text->letter_spacing = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_FIXED_WIDTH:
|
||||
text->fixed_width = g_value_get_int (value);
|
||||
break;
|
||||
|
||||
@ -34,27 +34,28 @@ typedef struct _GimpTextClass GimpTextClass;
|
||||
|
||||
struct _GimpText
|
||||
{
|
||||
GObject parent_instance;
|
||||
GObject parent_instance;
|
||||
|
||||
gchar *text;
|
||||
gchar *font;
|
||||
gdouble font_size;
|
||||
GimpUnit font_size_unit;
|
||||
GimpRGB color;
|
||||
GimpTextAlignment alignment;
|
||||
gdouble letter_spacing;
|
||||
gdouble line_spacing;
|
||||
gint fixed_width;
|
||||
gint fixed_height;
|
||||
GimpGravityType gravity;
|
||||
gchar *text;
|
||||
gchar *font;
|
||||
gdouble font_size;
|
||||
GimpUnit font_size_unit;
|
||||
GimpRGB color;
|
||||
GimpTextJustification justify;
|
||||
gdouble indent;
|
||||
gdouble line_spacing;
|
||||
gdouble letter_spacing;
|
||||
gint fixed_width;
|
||||
gint fixed_height;
|
||||
GimpGravityType gravity;
|
||||
|
||||
/* for historical reasons, don't use */
|
||||
gint border;
|
||||
gint border;
|
||||
};
|
||||
|
||||
struct _GimpTextClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -141,6 +141,7 @@ gimp_text_layout_new (GimpText *text,
|
||||
GimpTextLayout *layout;
|
||||
PangoContext *context;
|
||||
PangoFontDescription *font_desc;
|
||||
PangoAlignment alignment = PANGO_ALIGN_LEFT;
|
||||
gint size;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
|
||||
@ -187,7 +188,33 @@ gimp_text_layout_new (GimpText *text,
|
||||
pango_font_description_free (font_desc);
|
||||
|
||||
pango_layout_set_text (layout->layout, text->text, -1);
|
||||
pango_layout_set_alignment (layout->layout, text->alignment);
|
||||
|
||||
switch (text->justify)
|
||||
{
|
||||
case GIMP_TEXT_JUSTIFY_LEFT:
|
||||
alignment = PANGO_ALIGN_LEFT;
|
||||
break;
|
||||
case GIMP_TEXT_JUSTIFY_RIGHT:
|
||||
alignment = PANGO_ALIGN_RIGHT;
|
||||
break;
|
||||
case GIMP_TEXT_JUSTIFY_CENTER:
|
||||
alignment = PANGO_ALIGN_CENTER;
|
||||
break;
|
||||
case GIMP_TEXT_JUSTIFY_FILL:
|
||||
/* FIXME: This just doesn't work to do this */
|
||||
alignment = PANGO_ALIGN_LEFT;
|
||||
pango_layout_set_justify (layout->layout, TRUE);
|
||||
break;
|
||||
}
|
||||
|
||||
pango_layout_set_alignment (layout->layout, alignment);
|
||||
|
||||
pango_layout_set_width (layout->layout,
|
||||
text->fixed_width > 0 ?
|
||||
text->fixed_width * PANGO_SCALE : -1);
|
||||
|
||||
pango_layout_set_indent (layout->layout, text->indent * PANGO_SCALE);
|
||||
pango_layout_set_spacing (layout->layout, text->line_spacing * PANGO_SCALE);
|
||||
|
||||
gimp_text_layout_position (layout);
|
||||
|
||||
|
||||
@ -8,21 +8,22 @@
|
||||
|
||||
/* enumerations from "./text-enums.h" */
|
||||
|
||||
static const GEnumValue gimp_text_alignment_enum_values[] =
|
||||
static const GEnumValue gimp_text_justification_enum_values[] =
|
||||
{
|
||||
{ GIMP_TEXT_ALIGNMENT_LEFT, N_("Left Aligned"), "left" },
|
||||
{ GIMP_TEXT_ALIGNMENT_CENTER, N_("Centered"), "center" },
|
||||
{ GIMP_TEXT_ALIGNMENT_RIGHT, N_("Right Aligned"), "right" },
|
||||
{ GIMP_TEXT_JUSTIFY_LEFT, N_("Left Justified"), "left" },
|
||||
{ GIMP_TEXT_JUSTIFY_RIGHT, N_("Right Justified"), "right" },
|
||||
{ GIMP_TEXT_JUSTIFY_CENTER, N_("Centered"), "center" },
|
||||
{ GIMP_TEXT_JUSTIFY_FILL, N_("Filled"), "fill" },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
GType
|
||||
gimp_text_alignment_get_type (void)
|
||||
gimp_text_justification_get_type (void)
|
||||
{
|
||||
static GType enum_type = 0;
|
||||
|
||||
if (!enum_type)
|
||||
enum_type = g_enum_register_static ("GimpTextAlignment", gimp_text_alignment_enum_values);
|
||||
enum_type = g_enum_register_static ("GimpTextJustification", gimp_text_justification_enum_values);
|
||||
|
||||
return enum_type;
|
||||
}
|
||||
|
||||
@ -20,17 +20,17 @@
|
||||
#define __TEXT_ENUMS_H__
|
||||
|
||||
|
||||
#define GIMP_TYPE_TEXT_ALIGNMENT (gimp_text_alignment_get_type ())
|
||||
#define GIMP_TYPE_TEXT_JUSTIFICATION (gimp_text_justification_get_type ())
|
||||
|
||||
GType gimp_text_alignment_get_type (void) G_GNUC_CONST;
|
||||
GType gimp_text_justification_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/* this enum must match the values of the PangoAlignment enum */
|
||||
typedef enum
|
||||
{
|
||||
GIMP_TEXT_ALIGNMENT_LEFT, /*< desc="Left Aligned" >*/
|
||||
GIMP_TEXT_ALIGNMENT_CENTER, /*< desc="Centered" >*/
|
||||
GIMP_TEXT_ALIGNMENT_RIGHT /*< desc="Right Aligned" >*/
|
||||
} GimpTextAlignment;
|
||||
GIMP_TEXT_JUSTIFY_LEFT, /*< desc="Left Justified" >*/
|
||||
GIMP_TEXT_JUSTIFY_RIGHT, /*< desc="Right Justified" >*/
|
||||
GIMP_TEXT_JUSTIFY_CENTER, /*< desc="Centered" >*/
|
||||
GIMP_TEXT_JUSTIFY_FILL /*< desc="Filled" >*/
|
||||
} GimpTextJustification;
|
||||
|
||||
|
||||
#endif /* __TEXT_ENUMS_H__ */
|
||||
|
||||
Reference in New Issue
Block a user