app/text/text-enums.[ch] app/text/gimptext.[ch] added some more text

2003-04-09  Sven Neumann  <sven@gimp.org>

	* app/text/text-enums.[ch]
	* app/text/gimptext.[ch]
	* app/text/gimptextlayout.c: added some more text properties that
	can't be accessed from the GUI yet.
This commit is contained in:
Sven Neumann 2003-04-09 21:19:12 +00:00 committed by Sven Neumann
parent 30b303edb8
commit 6b581cc500
7 changed files with 132 additions and 42 deletions

View File

@ -1,3 +1,10 @@
2003-04-09 Sven Neumann <sven@gimp.org>
* app/text/text-enums.[ch]
* app/text/gimptext.[ch]
* app/text/gimptextlayout.c: added some more text properties that
can't be accessed from the GUI yet.
2003-04-09 Michael Natterer <mitch@gimp.org>
* app/tools/gimpeditselectiontool.c

View File

@ -58,8 +58,10 @@ enum
PROP_JUSTIFICATION,
PROP_INDENTATION,
PROP_LINE_SPACING,
PROP_LETTER_SPACING,
PROP_BOX_MODE,
PROP_BOX_WIDTH,
PROP_BOX_HEIGHT,
PROP_BOX_UNIT,
PROP_BORDER
};
@ -201,14 +203,24 @@ gimp_text_class_init (GimpTextClass *klass)
N_("Additional line spacing (in pixels)"),
-8192.0, 8192.0, 0.0,
0);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_LETTER_SPACING,
"letter-spacing", NULL,
-8192.0, 8192.0, 0.0,
0);
GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_BOX_WIDTH,
"box-width", NULL,
0, GIMP_MAX_IMAGE_SIZE, 0,
0);
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_BOX_MODE,
"box-mode",
NULL,
GIMP_TYPE_TEXT_BOX_MODE,
GIMP_TEXT_BOX_DYNAMIC,
0);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BOX_WIDTH,
"box-width", NULL,
0.0, GIMP_MAX_IMAGE_SIZE, 0.0,
0);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BOX_HEIGHT,
"box-height", NULL,
0.0, GIMP_MAX_IMAGE_SIZE, 0.0,
0);
GIMP_CONFIG_INSTALL_PROP_UNIT (object_class, PROP_BOX_UNIT,
"box-unit", NULL,
TRUE, GIMP_UNIT_PIXEL,
0);
/* border does only exist to implement the old text API */
param_spec = g_param_spec_int ("border", NULL, NULL,
@ -292,11 +304,17 @@ gimp_text_get_property (GObject *object,
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);
case PROP_BOX_MODE:
g_value_set_enum (value, text->box_mode);
break;
case PROP_BOX_WIDTH:
g_value_set_int (value, text->box_width);
g_value_set_double (value, text->box_width);
break;
case PROP_BOX_HEIGHT:
g_value_set_double (value, text->box_height);
break;
case PROP_BOX_UNIT:
g_value_set_int (value, text->box_unit);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -358,11 +376,17 @@ gimp_text_set_property (GObject *object,
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);
case PROP_BOX_MODE:
text->box_mode = g_value_get_enum (value);
break;
case PROP_BOX_WIDTH:
text->box_width = g_value_get_int (value);
text->box_width = g_value_get_double (value);
break;
case PROP_BOX_HEIGHT:
text->box_height = g_value_get_double (value);
break;
case PROP_BOX_UNIT:
text->box_unit = g_value_get_int (value);
break;
case PROP_BORDER:
text->border = g_value_get_int (value);

View File

@ -49,9 +49,10 @@ struct _GimpText
GimpTextJustification justify;
gdouble indent;
gdouble line_spacing;
gdouble letter_spacing;
gint box_width;
GimpTextBoxMode box_mode;
gdouble box_width;
gdouble box_height;
GimpUnit box_unit;
/* for historical reasons, don't use */
gint border;
};

View File

@ -299,8 +299,6 @@ gimp_text_layer_render (GimpTextLayer *layer)
layout = gimp_text_layout_new (layer->text, image);
gimp_text_layout_get_size (layout, &width, &height);
if (gimp_text_layout_get_size (layout, &width, &height))
{
if (width != gimp_drawable_width (drawable) ||

View File

@ -62,6 +62,10 @@ static PangoContext * gimp_text_get_pango_context (GimpText *text,
gdouble xres,
gdouble yres);
static gint gimp_text_layout_compute_size (gdouble value,
GimpUnit unit,
gdouble res);
static GObjectClass * parent_class = NULL;
@ -156,23 +160,8 @@ gimp_text_layout_new (GimpText *text,
gimp_image_get_resolution (image, &xres, &yres);
switch (text->font_size_unit)
{
case GIMP_UNIT_PIXEL:
size = PANGO_SCALE * text->font_size;
break;
default:
{
gdouble factor;
factor = gimp_unit_get_factor (text->font_size_unit);
g_return_val_if_fail (factor > 0.0, NULL);
size = (gdouble) PANGO_SCALE * text->font_size * yres / factor;
}
break;
}
size = gimp_text_layout_compute_size (text->font_size, text->font_size_unit,
yres);
pango_font_description_set_size (font_desc, MAX (1, size));
@ -211,15 +200,35 @@ gimp_text_layout_new (GimpText *text,
pango_layout_set_alignment (layout->layout, alignment);
pango_layout_set_width (layout->layout,
text->box_width > 0 ?
text->box_width * PANGO_SCALE : -1);
switch (text->box_mode)
{
case GIMP_TEXT_BOX_DYNAMIC:
break;
case GIMP_TEXT_BOX_FIXED:
pango_layout_set_width (layout->layout,
gimp_text_layout_compute_size (text->box_width,
text->box_unit,
xres));
break;
}
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);
switch (text->box_mode)
{
case GIMP_TEXT_BOX_DYNAMIC:
break;
case GIMP_TEXT_BOX_FIXED:
layout->extents.height =
PANGO_PIXELS (gimp_text_layout_compute_size (text->box_height,
text->box_unit,
yres));
break;
}
return layout;
}
@ -232,6 +241,7 @@ gimp_text_layout_get_size (GimpTextLayout *layout,
if (width)
*width = layout->extents.width;
if (height)
*height = layout->extents.height;
@ -387,3 +397,23 @@ gimp_text_get_pango_context (GimpText *text,
return context;
}
static gint
gimp_text_layout_compute_size (gdouble value,
GimpUnit unit,
gdouble res)
{
gdouble factor;
switch (unit)
{
case GIMP_UNIT_PIXEL:
return PANGO_SCALE * value;
default:
factor = gimp_unit_get_factor (unit);
g_return_val_if_fail (factor > 0.0, 0);
return (gdouble) PANGO_SCALE * value * res / factor;
}
}

View File

@ -8,6 +8,25 @@
/* enumerations from "./text-enums.h" */
static const GEnumValue gimp_text_box_mode_enum_values[] =
{
{ GIMP_TEXT_BOX_DYNAMIC, "GIMP_TEXT_BOX_DYNAMIC", "dynamic" },
{ GIMP_TEXT_BOX_FIXED, "GIMP_TEXT_BOX_FIXED", "fixed" },
{ 0, NULL, NULL }
};
GType
gimp_text_box_mode_get_type (void)
{
static GType enum_type = 0;
if (!enum_type)
enum_type = g_enum_register_static ("GimpTextBoxMode", gimp_text_box_mode_enum_values);
return enum_type;
}
static const GEnumValue gimp_text_direction_enum_values[] =
{
{ GIMP_TEXT_DIRECTION_LTR, N_("From Left to Right"), "ltr" },

View File

@ -20,14 +20,25 @@
#define __TEXT_ENUMS_H__
#define GIMP_TYPE_TEXT_BOX_MODE (gimp_text_box_mode_get_type ())
GType gimp_text_box_mode_get_type (void) G_GNUC_CONST;
typedef enum
{
GIMP_TEXT_BOX_DYNAMIC,
GIMP_TEXT_BOX_FIXED
} GimpTextBoxMode;
#define GIMP_TYPE_TEXT_DIRECTION (gimp_text_direction_get_type ())
GType gimp_text_direction_get_type (void) G_GNUC_CONST;
typedef enum
{
GIMP_TEXT_DIRECTION_LTR, /*< desc="From Left to Right" >*/
GIMP_TEXT_DIRECTION_RTL /*< desc="From Right to Left" >*/
GIMP_TEXT_DIRECTION_LTR, /*< desc="From Left to Right" >*/
GIMP_TEXT_DIRECTION_RTL /*< desc="From Right to Left" >*/
} GimpTextDirection;