# The GIMP -- an image manipulation program
# Copyright (C) 1995 Spencer Kimball and Peter Mattis

# 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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# "Perlized" from C source by Manish Singh <yosh@gimp.org>

sub layer_is_text {
    $blurb = 'Determine whether a layer is a text layer.';

    $help = <<'HELP';
This procedure determines whether the specified layer is a text layer
and can be manipulated as one.  It should be called before attempting
to perform any text-layer specific operations.  Always succeeds.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'The layer to check' }
    );

    @outargs = (
	{ name => 'is_text', type => 'boolean',
	  desc => 'Whether it is a text layer' }
    );

    %invoke = (
	code => <<'CODE'
{
    is_text = gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer));

    success = TRUE;
}
CODE
    );
}

sub text_layer_discard_text {
    $blurb = 'Convert a text layer into an ordinary layer.';

    $help = <<'HELP';
Discards the text information from a text layer. This makes the layer behave
like a normal layer.  If the layer is not a text layer, nothing happens.
Always succeeds.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'The layer to convert' }
    );

    @outargs = (
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
	gimp_text_layer_discard (GIMP_TEXT_LAYER (layer));

    success = TRUE;
}
CODE
    );
}

sub text_layer_get_text {
    $blurb = 'Returns the text from a text layer.';

    $help = <<'HELP';
Returns the text from a text layer, as a string.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' }
    );

    @outargs = (
	{ name => 'the_text', type => 'string',
	  desc => 'The text from the layer' }
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"text", &the_text,
			NULL);
	  success = (the_text != NULL);
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_set_text {
    $blurb = 'Changes the text in a text layer.';

    $help = <<'HELP';
Replaces the text in a text layer with the specified string.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' },
	{ name => 'new_text', type => 'string',
	  desc => 'A string of text' }
    );

    @outargs = (
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
			     "layer text",
			     "text", new_text,
			     NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_get_font {
    $blurb = 'Returns the font from a text layer.';

    $help = <<'HELP';
Returns the font used in a text layer, as a string.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' }
    );

    @outargs = (
	{ name => 'the_font', type => 'string',
	  desc => 'The font used in the layer' }
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"font", &the_font,
			NULL);
	  success = (the_font != NULL);
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_set_font {
    $blurb = 'Changes the text in a text layer.';

    $help = <<'HELP';
Changes the font for a text layer to the specified one.
Note that this function does not check to see that the font
name you specify is valid and available.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' },
	{ name => 'new_font', type => 'string',
	  desc => 'A font name' }
    );

    @outargs = (
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
			     "layer text",
			     "font", new_font,
			     NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_get_font_size {
    $blurb = 'Get the font size used in a text layer.';

    $help = <<'HELP';
Returns the size of the font used in a text layer, and also the type
of unit in which the size is encoded.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' }
    );

    @outargs = (
	{ name => 'size', type => 'float',
	  desc => 'Font size' },
	{ name => 'unit', type => 'unit',
	  desc => 'Font size unit' }
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"font-size", &size,
			"font-size-unit", &unit,
			NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_set_font_size {
    $blurb = 'Changes the font size for a text layer.';

    $help = <<'HELP';
Changes the font size and/or unit for a text layer to the specified values.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' },
	{ name => 'size', type => 'float',
	  desc => 'New font size' },
	{ name => 'unit', type => 'unit',
	  desc => 'New font size unit' }
    );

    @outargs = (
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;
	  gdouble   old_size;
	  GimpUnit  old_unit;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"font-size", &old_size,
			"font-size-unit", &old_unit,
			NULL);

	  if (old_size != size || old_unit != unit)
	      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
				   "Font size",
				   "font-size", size,
				   "font-size-unit", unit,
				   NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_get_color {
    $blurb = 'Returns the text color used in a text layer.';

    $help = <<'HELP';
Returns the color of the text in a text layer.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' }
    );

    @outargs = (
	{ name => 'color', type => 'color', void_ret => 1,
	  desc => 'The text color' }
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"color", &color,
			NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_set_color {
    $blurb = 'Changes the text color for a text layer.';

    $help = <<'HELP';
Changes the color for a text layer to the specified one.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' },
	{ name => 'new_color', type => 'color',
	  desc => 'New color' }
    );

    @outargs = (
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
			     "Text color",
			     "color", new_color,
			     NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_get_text_attributes {
    $blurb = 'Returns attributes of the text in a text layer.';

    $help = <<'HELP';
Returns several attributes of the style used to render the text in a text layer.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' }
    );

    @outargs = (
	{ name => 'hinting', type => 'boolean', void_ret => 1,
	  desc => 'Whether to use hinting' },
	{ name => 'autohint', type => 'boolean',
	  desc => 'Whether to use auto-hinting' },
	{ name => 'antialias', type => 'boolean',
	  desc => 'Whether the text is anti-aliased' },
	{ name => 'kerning', type => 'boolean',
	  desc => 'Whether to use kerning' }
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"hinting",   &hinting,
			"autohint",  &autohint,
			"antialias", &antialias,
			"kerning",   &kerning,
			NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_set_text_attributes {
    $blurb = 'Changes rendering style for a text layer.';

    $help = <<'HELP';
Changes several properties of the way text is rendered in a text layer.
You will usually want to use #gimp_text_layer_get_text_attributes to
get the existing values before using this function.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' },
	{ name => 'hinting', type => 'boolean', void_ret => 1,
	  desc => 'Whether to use hinting' },
	{ name => 'autohint', type => 'boolean',
	  desc => 'Whether to use auto-hinting' },
	{ name => 'antialias', type => 'boolean',
	  desc => 'Whether the text is anti-aliased' },
	{ name => 'kerning', type => 'boolean',
	  desc => 'Whether to use kerning' }
    );

    @outargs = (
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  gboolean  old_hinting;
	  gboolean  old_autohint;
	  gboolean  old_antialias;
	  gboolean  old_kerning;
	  GimpText *text_struct;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"hinting",   &old_hinting,
			"autohint",  &old_autohint,
			"antialias", &old_antialias,
			"kerning",   &old_kerning,
			NULL);

	  if (old_hinting   != hinting   ||
	      old_autohint  != autohint  ||
	      old_antialias != antialias ||
	      old_kerning   != kerning)
	    gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
				 "Text attributes",
				 "hinting",   hinting,
				 "autohint",  autohint,
				 "antialias", antialias,
				 "kerning",   kerning,
				 NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_get_language {
    $blurb = 'Returns the language from a text layer.';

    $help = <<'HELP';
Returns the language used in a text layer, as a string.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' }
    );

    @outargs = (
	{ name => 'language', type => 'string',
	  desc => 'The language used in the layer' }
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"language", &language,
			NULL);
	  success = (language != NULL);
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_set_language {
    $blurb = 'Changes the language in a text layer.';

    $help = <<'HELP';
Changes the language for a text layer to the specified one.
Note that this function does not check to see that the language
name you specify is valid and available.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' },
	{ name => 'language', type => 'string',
	  desc => 'A language name' }
    );

    @outargs = (
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
			     "layer text",
			     "language", language,
			     NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_get_justify {
    $blurb = 'Justification of a text layer.';

    $help = <<'HELP';
Returns the type of justification applied in a text layer.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' }
    );

    @outargs = (
	{ name => 'justify', type => 'enum GimpTextJustification',
	  desc => 'The text justification type' }
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"justify", &justify,
			NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_set_justify {
    $blurb = 'Set the justification for a text layer.';

    $help = <<'HELP';
Changes the type of justification applied to a text layer.  The options
are #GIMP_TEXT_JUSTIFY_LEFT, #GIMP_TEXT_JUSTIFY_RIGHT, #GIMP_TEXT_JUSTIFY_CENTER,
or #GIMP_TEXT_JUSTIFY_FILL.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' },
	{ name => 'justify', type => 'enum GimpTextJustification',
	  desc => 'New text justification type' }
    );

    @outargs = (
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText              *text_struct;
	  GimpTextJustification  old_justify;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"justify", &old_justify,
			NULL);

	  if (justify != old_justify)
	      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
				   "Text justify",
				   "justify", justify,
				   NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_get_outline {
    $blurb = 'Glyph outline mode for a text layer.';

    $help = <<'HELP';
Returns the type of outlining used for rendering glyphs in a text layer.
See #gimp_text_layer_set_outline for more information.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' }
    );

    @outargs = (
	{ name => 'outline', type => 'enum GimpTextOutline',
	  desc => 'The text outline mode' }
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"outline", &outline,
			NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_set_outline {
    $blurb = 'Set the glyph outline mode for a text layer.';

    $help = <<'HELP';
Changes the type of outlining used for rendering glyphs in a text layer.
The options are #GIMP_TEXT_OUTLINE_NONE, #GIMP_TEXT_OUTLINE_STROKE_ONLY,
and #GIMP_TEXT_OUTLINE_STROKE_FILL.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' },
	{ name => 'outline', type => 'enum GimpTextOutline',
	  desc => 'New text outline mode' }
    );

    @outargs = (
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText        *text_struct;
	  GimpTextOutline  old_outline;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"outline", &old_outline,
			NULL);

	  if (outline != old_outline)
	      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
				   "Text outline",
				   "outline", outline,
				   NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_get_direction {
    $blurb = 'Glyph outline mode for a text layer.';

    $help = <<'HELP';
Returns the type of outlining used for rendering glyphs in a text layer.
See #gimp_text_layer_set_direction for more information.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' }
    );

    @outargs = (
	{ name => 'direction', type => 'enum GimpTextDirection',
	  desc => 'The text direction' }
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"base-direction", &direction,
			NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_set_direction {
    $blurb = 'Set the glyph direction mode for a text layer.';

    $help = <<'HELP';
Changes the direction of text in a text layer.
The options are #GIMP_TEXT_DIRECTION_LTR and #GIMP_TEXT_DIRECTION_RTL,
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' },
	{ name => 'direction', type => 'enum GimpTextDirection',
	  desc => 'New text direction' }
    );

    @outargs = (
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText          *text_struct;
	  GimpTextDirection  old_direction;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"base-direction", &old_direction,
			NULL);

	  if (direction != old_direction)
	      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
				   "Text direction",
				   "base-direction", direction,
				   NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_get_spacing {
    $blurb = 'Get spacing settings for a text layer.';

    $help = <<'HELP';
Returns the values of indentation, line spacing, and character spacing 
used in a text layer.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' }
    );

    @outargs = (
	{ name => 'indent', type => 'float', void_ret => 1,
	  desc => 'Indentation' },
	{ name => 'line_spacing', type => 'float',
	  desc => 'Line spacing' },
	{ name => 'char_spacing', type => 'float',
	  desc => 'Character spacing' }
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"indent",         &indent,
			"line-spacing",   &line_spacing,
			"letter-spacing", &char_spacing,
			NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_set_spacing {
    $blurb = 'Set the spacing values for a text layer.';

    $help = <<'HELP';
Sets the amount of indentation, line spacing, and character spacing 
used in a text layer.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' },
	{ name => 'indent', type => 'float',
	  desc => 'Indentation' },
	{ name => 'line_spacing', type => 'float',
	  desc => 'Line spacing' },
	{ name => 'char_spacing', type => 'float',
	  desc => 'Character spacing' }
    );

    @outargs = (
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText          *text_struct;
	  gdouble   old_indent;
	  gdouble   old_line_spacing;
	  gdouble   old_char_spacing;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"indent",         &old_indent,
			"line-spacing",   &old_line_spacing,
			"letter-spacing", &old_char_spacing,
			NULL);

	  if (indent       != old_indent       ||
	      line_spacing != old_line_spacing ||
	      char_spacing != old_char_spacing)
	    gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
				 "Text spacing",
				 "indent",         indent,
				 "line-spacing",   line_spacing,
				 "letter-spacing", char_spacing,
				 NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_get_text_box {
    $blurb = 'Get box settings for a text layer.';

    $help = <<'HELP';
Returns the box mode for a text layer, as well as the values of width and
height, and the units in which they are encoded.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' }
    );

    @outargs = (
	{ name => 'box_mode', type => 'enum GimpTextBoxMode',
	  desc => 'Box mode' },
	{ name => 'box_width', type => 'float',
	  desc => 'Text box width' },
	{ name => 'box_height', type => 'float',
	  desc => 'Text box height' },
	{ name => 'box_unit', type => 'unit',
	  desc => 'Text box dimension units' }
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
	  g_object_get (text_struct,
			"box-mode",   &box_mode,
			"box-width",  &box_width,
			"box-height", &box_height,
			"box-unit",   &box_unit,
			NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

sub text_layer_set_text_box {
    $blurb = 'Change the text box for a text layer.';

    $help = <<'HELP';
Sets the text box mode for a text layer, as well as the width and
height of the box, and the units in which these are encoded.
HELP

    &bill_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'layer', type => 'layer',
	  desc => 'A text layer' },
	{ name => 'box_mode', type => 'enum GimpTextBoxMode',
	  desc => 'Box mode' },
	{ name => 'box_width', type => 'float',
	  desc => 'Text box width' },
	{ name => 'box_height', type => 'float',
	  desc => 'Text box height' },
	{ name => 'box_unit', type => 'unit',
	  desc => 'Text box dimension units' }
    );

    @outargs = (
    );

    %invoke = (
	code => <<'CODE'
{
    if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
      {
	  GimpText *text_struct;
	  gdouble   old_box_mode;
	  gdouble   old_box_width;
	  gdouble   old_box_height;
	  GimpUnit  old_box_unit;

	  text_struct = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));

	  g_object_get (text_struct,
			"box-mode",   &old_box_mode,
			"box-width",  &old_box_width,
			"box-height", &old_box_height,
			"box-unit",   &old_box_unit,
			NULL);
	  if (box_mode   != old_box_mode    ||
	      box_width  != old_box_width   ||
	      box_height != old_box_height  ||
	      box_unit   != old_box_unit)
	    gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
				 "Text box properties",
				 "box-mode",   box_mode,
				 "box-width",  box_width,
				 "box-height", box_height,
				 "box-unit",   box_unit,
				 NULL);
	  success = TRUE;
      }
    else
	success = FALSE;
}
CODE
    );
}

@headers = qw("libgimpbase/gimpbase.h" "text/gimptextlayer.h"
	      "text/gimptext.h" "gimp-intl.h");

@procs = qw(layer_is_text text_layer_discard_text
	    text_layer_get_text text_layer_set_text
	    text_layer_get_font text_layer_set_font
	    text_layer_get_font_size text_layer_set_font_size
	    text_layer_get_text_attributes text_layer_set_text_attributes
	    text_layer_get_language text_layer_set_language
	    text_layer_get_color text_layer_set_color
	    text_layer_get_justify text_layer_set_justify
	    text_layer_get_outline text_layer_set_outline
	    text_layer_get_direction text_layer_set_direction
	    text_layer_get_spacing text_layer_set_spacing
	    text_layer_get_text_box text_layer_set_text_box
	    );

%exports = (app => [@procs], lib => [@procs]);

$desc = 'Text layer';

1;
