# GIMP - The GNU Image Manipulation Program
# Copyright (C) 1995 Spencer Kimball and Peter Mattis

# New Text PDB API
# Copyright (C) 2008 Marcus Heese <heese@cip.ifi.lmu.de>

# 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.

sub marcus_pdb_misc {
    contrib_pdb_misc('Marcus Heese', 'heese@cip.ifi.lmu.de', '2008', '2.6');
}

sub drawable_is_text_layer {
    $blurb = 'Checks if the drawable is a text layer.';

    $help = <<'HELP';
This procedure checks if your drawable is a text layer.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );

    @outargs = (
        { name => 'is_text_layer', type => 'boolean',
	  desc => 'TRUE if the drawable is a text layer, FALSE otherwise.' }
    );

    %invoke = (
        code => <<'CODE'
{
  is_text_layer = gimp_drawable_is_text_layer (drawable);
}
CODE
    );
}

sub text_layer_new {
    $blurb = 'Creates a new text layer.';

    $help = <<'HELP';
This procedure creates a new text layer. The arguments are kept as simple as necessary for the normal case. All text attributes, however, can be modified with the appropriate gimp_text_layer_set_*() procedures. The new layer still needs to be added to the image, as this is not automatic. Add the new layer using gimp_image_add_layer().
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'image', type => 'image',
          desc => 'The image' },
        { name => 'text', type => 'string',
          desc => 'The text to generate (in UTF-8 encoding)' },
        { name => 'fontname', type => 'string',
          desc => 'The name of the font' },
        { name => 'size', type => '0.0 <= float <= 8192.0',
          desc => 'The size of text in either pixels or points' },
        { name => 'unit', type => 'unit',
          desc => 'The units of specified size' }
    );

    @outargs = (
        { name => 'layer', type => 'layer',
          desc => 'The new text layer.' }
    );

    %invoke = (
        code => <<'CODE'
{
  GimpText *gimp_text;
  GimpRGB   color;

  gimp_context_get_foreground (context, &color);
  
  gimp_text = g_object_new (GIMP_TYPE_TEXT,
                            "text",           text,
			    "font",           fontname,
			    "font-size",      size,
			    "font-size-unit", unit,
			    "color",          &color,
			    NULL);
  
  layer = gimp_text_layer_new (image, gimp_text);
  g_object_unref (gimp_text);

  if (! layer)
    {
      success = FALSE;
      return NULL;
    }
}
CODE
    );
}

sub text_layer_set_text {
    $blurb = 'Set the text of a text layer.';

    $help = <<'HELP';
This procedure changes the text of a text layer.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'text', type => 'string',
	  desc => 'The new text to set' }
    );

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

sub text_layer_set_font {
    $blurb = 'Set the font of a text layer.';

    $help = <<'HELP';
This procedure modifies the font used in the specified text layer.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'font', type => 'string',
	  desc => 'The new font to use' }
    );

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

sub text_layer_set_fontsize {
    $blurb = 'Set the font size.';

    $help = <<'HELP';
This procedure changes the font size of a text layer. The size of your font will be a double 'font-size' of 'unit' units.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'font-size', type => 0.0 <= float <= 8192.0,
	  desc => 'The font size' },
	{ name => 'unit', type => 'unit',
	  desc => 'The unit to use for the font size' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
			   _("Set text layer attribute"),
                           "font-size-unit", unit,
		           "font-size",      font_size,
		           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_set_hinting {
    $blurb = 'Enable/disable the use of hinting in a text layer.';

    $help = <<'HELP';
This procedure enables or disables hinting on the text of a text layer. If you enable 'auto-hint', FreeType\'s automatic hinter will be used and hinting information from the font will be ignored.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'hinting', type => 'boolean',
	  desc => 'Enable/disable the use of hinting on the text' },
	{ name => 'auto-hint', type => 'boolean',
	  desc => 'Force the use of the autohinter provided through FreeType' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
			   _("Set text layer attribute"),
                           "hinting",  hinting,
                           "autohint", auto_hint,
	  	           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_set_antialias {
    $blurb = 'Enable/disable anti-aliasing in a text layer.';

    $help = <<'HELP';
This procedure enables or disables anti-aliasing of the text in a text layer.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'antialias', type => 'boolean',
	  desc => 'Enable/disable antialiasing of the text' }
    );

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

sub text_layer_set_kerning {
    $blurb = 'Enable/disable kerning in a text layer.';

    $help = <<'HELP';
This procedure enables or disables kerning in a text layer.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'kerning', type => 'boolean',
	  desc => 'Enable/disable kerning in the text' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer), undo_desc,
                           _("Set text layer attribute"),
                           "kerning", kerning,
	  	           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_set_language {
    $blurb = 'Set the language of the text layer.';

    $help = <<'HELP';
This procedure sets the language of the text in text layer. For some scripts the language has an influence of how the text is rendered.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'language', type => 'string',
	  desc => 'The new language to use for the text layer' }
    );

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

sub text_layer_set_base_direction {
    $blurb = 'Set the base direction in the text layer.';

    $help = <<'HELP';
This procedure sets the base direction used in applying the Unicode bidirectional algorithm when rendering the text.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'direction', type => 'enum GimpTextDirection',
	  desc => 'The base direction of the text.' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer), undo_desc,
                           _("Set text layer attribute"),
                           "base-direction", direction,
		           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_set_justification {
    $blurb = 'Set the justification of the text in a text layer.';

    $help = <<'HELP';
This procedure sets the alignment of the lines in the text layer relative to each other.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'justify', type => 'enum GimpTextJustification',
	  desc => 'The justification for your text.' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer), undo_desc,
                           _("Set text layer attribute"),
                           "justify", justify,
		           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_set_color {
    $blurb = 'Set the color of the text in the text layer.';

    $help = <<'HELP';
This procedure sets the text color in the text layer 'layer'.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'color', type => 'color',
	  desc => 'The color to use for the text' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer), undo_desc,
                           _("Set text layer attribute"),
                           "color", &color,
  		           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_set_indent {
    $blurb = 'Set the indentation of the first line in a text layer.';

    $help = <<'HELP';
This procedure sets the indentation of the first line in the text layer.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'indent', type => -8192.0 <= float <= 8192.0,
	  desc => 'The indentation for the first line.' }
     );

     %invoke = (
         code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer), undo_desc,
                           _("Set text layer attribute"),
                           "indent", indent,
		           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_set_line_spacing {
    $blurb = 'Adjust the line spacing in a text layer.';

    $help = <<'HELP';
This procedure sets the additional spacing used between lines a text layer.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'line-spacing', type => -8192.0 <= float <= 8192.0,
	  desc => 'The additional line spacing to use.' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer), undo_desc,
                           _("Set text layer attribute"),
                           "line-spacing", line_spacing,
		           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_set_letter_spacing {
    $blurb = 'Adjust the letter spacing in a text layer.';

    $help = <<'HELP';
This procedure sets the additional spacing between the single glyphs in a text layer.
HELP

    &marcus_pdb_misc;

    @inargs = (
        { name => 'layer', type => 'layer',
	  desc => 'The text layer' },
	{ name => 'letter-spacing', type => -8192.0 <= float <= 8192.0,
	  desc => 'The additional letter spacing to use.' }
    );
    
    %invoke = (    
	code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer), undo_desc,
                           _("Set text layer attribute"),
                           "letter-spacing", letter_spacing,
		           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_get_text {
    $blurb = 'Get the text from a text layer as string.';

    $help = <<'HELP';
With this procedure you can get the text from a text layer as a string. Just pass the text layer as argument and you will receive a string in return.
HELP

    &marcus_pdb_misc;

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

    @outargs = (
        { name => 'text', type => 'string',
	  desc => 'The text from the specified text layer.' }
    );
    
    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer),
                    "text", &text,
		    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_get_font {
    $blurb = 'Get the font from a text layer as string.';

    $help = <<'HELP';
With this procedure you can get the name of the font from a text layer as a string. Just pass the text layer as argument and you will receive a string in return.
HELP

    &marcus_pdb_misc;

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

    @outargs = (
        { name => 'font', type => 'string',
	  desc => 'The font which is used in the specified text layer.' }
    );
    
    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer),
                    "font", &font,
 		    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_get_fontsize {
    $blurb = 'Get the font size from a text layer.';

    $help = <<'HELP';
With this procedure you can get the size of the font which is used in a text layer. You will receive the size as a float 'font-size' in 'unit' units. Just pass a text layer as argument to achieve the eligible result.
HELP

    &marcus_pdb_misc;

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

    @outargs = (
        { name => 'font-size', type => 'float',
	  desc => 'The font size' },
	{ name => 'unit', type => 'unit',
	  desc => 'The unit used for the font size' }
    );
    
    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer),
                    "font-size",      &font_size,
		    "font-size-unit", &unit,
		    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_get_hinting {
    $blurb = 'Get information about the used hinting in the specified text layer.';

    $help = <<'HELP';
With this procedure you can check if hinting is used on the font. You will additionally get information if the automatic hinting from FreeType is used.  Just pass a text layer as argument to achieve the eligible result.
HELP

    &marcus_pdb_misc;

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

    @outargs = (
        { name => 'hinting', type => 'boolean',
	  desc => 'A flag which is true if hinting is used on the font.' },
	{ name => 'autohinter', type => 'boolean',
	  desc => 'A flag which is true if the text layer is forced to use the autohinter from FreeType.' }
    );
    
    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer),
                    "hinting",  &hinting,
		    "autohint", &autohinter,
		    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_get_antialias {
    $blurb = 'Check if Antialiasing is used in the text layer.';

    $help = <<'HELP';
With this procedure you can check if antialiasing is enabled in the specified text layer. Just pass a text layer as argument to achieve the eligible result.
HELP

    &marcus_pdb_misc;

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

    @outargs = (
        { name => 'antialias', type => 'boolean',
	  desc => 'A flag which is true if antialiasing is used for rendering the font in the text layer.' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer),
                    "antialias", &antialias,
		    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_get_kerning {
    $blurb = 'Check if kerning is used for the text in the text layer.';

    $help = <<'HELP';
With this procedure you can check if kerning is enabled in the specified text layer. Just pass a text layer as argument to achieve the eligible result.
HELP

    &marcus_pdb_misc;

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

    @outargs = (
        { name => 'kerning', type => 'boolean',
	  desc => 'A flag which is true if kerning is used in the text layer.' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer),
                    "kerning", &kerning,
		    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_get_language {
    $blurb = 'Get the language used in the text layer.';

    $help = <<'HELP';
With this procedure you can get the language string which is used in the text layer. Just pass a text layer as argument to achieve the eligible result.
HELP

    &marcus_pdb_misc;

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

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

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

sub text_layer_get_base_direction {
    $blurb = 'Get the base direction used for rendering the text layer.';

    $help = <<'HELP';
This procedure returns the base direction used for rendering the text in the text layer
HELP

    &marcus_pdb_misc;

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

    @outargs = (
        { name => 'direction', type => 'enum GimpTextDirection',
	  desc => 'The based direction used for the text layer.' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer),
                    "base-direction", &direction,
		    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}


sub text_layer_get_justification {
    $blurb = 'Get the text justification information of the text layer.';

    $help = <<'HELP';
This procedure returns the alignment of the lines in the text layer relative to each other.
HELP

    &marcus_pdb_misc;

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

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

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer),
                    "justify", &justify,
		    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_get_color {
    $blurb = 'Get the color of the text in a text layer.';

    $help = <<'HELP';
This procedure returns the color of the text in a text layer.
HELP

    &marcus_pdb_misc;

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

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

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer),
                    "color", &color,
		    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_get_indent {
    $blurb = 'Get the line indentation of text layer.';

    $help = <<'HELP';
This procedure returns the indentation of the first line in a text layer.
HELP

    &marcus_pdb_misc;

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

    @outargs = (
        { name => 'indent', type => 'float',
	  desc => 'The indentation value of the first line.' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer),
                    "indent", &indent,
		    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_get_line_spacing {
    $blurb = 'Get the spacing between lines of text.';

    $help = <<'HELP';
This procedure returns the line-spacing between lines of text in a text layer.
HELP

    &marcus_pdb_misc;

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

    @outargs = (
        { name => 'line-spacing', type => 'float',
	  desc => 'The line-spacing value.' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer),
                    "line-spacing", &line_spacing,
		    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_get_letter_spacing {
    $blurb = 'Get the letter spacing used in a text layer.';

    $help = <<'HELP';
This procedure returns the additional spacing between the single glyps in a text layer.
HELP

    &marcus_pdb_misc;

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

    @outargs = (
        { name => 'letter-spacing', type => 'float',
	  desc => 'The letter-spacing value.' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer),
                    "letter-spacing", &letter_spacing,
 		    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

# Get Vectors from text layer
sub vectors_from_text_layer {
    $blurb = 'Create vectors from a text layer.';

    $help = <<'HELP';
Creates vectors from a text layer.
HELP

    &marcus_pdb_misc;

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

    @outargs = (
        { name => 'vectors', type => 'vectors',
	  desc => 'The vectors of the text layer.' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
    {
      vectors = gimp_text_vectors_new (image,
				       gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)));
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

# Here is the deprecated api
sub text_fontname {
    &std_pdb_deprecated ('gimp-text-layer-new');

    @inargs = (
        { name => 'image', type => 'image',
          desc => 'The image' },
        { name => 'drawable', type => 'drawable',
          desc => 'The affected drawable: (-1 for a new text layer)',
          none_ok => 1 },
        { name => 'x', type => 'float',
          desc => 'The x coordinate for the left of the text bounding box' },
        { name => 'y', type => 'float',
          desc => 'The y coordinate for the top of the text bounding box' },
        { name => 'text', type => 'string',
          desc => 'The text to generate (in UTF-8 encoding)' },
        { name => 'border', type => '-1 <= int32',
          desc => 'The size of the border' },
        { name => 'antialias', type => 'boolean',
          desc => 'Antialiasing' },
        { name => 'size', type => '0 < float',
          desc => 'The size of text in either pixels or points' },
        { name => 'size_type', type => 'enum GimpSizeType',
          desc => 'The units of specified size' },
        { name => 'fontname', type => 'string',
          desc => 'The name of the font' }
    );

    @outargs = (
        { name => 'text_layer', type => 'layer',
          desc => 'The new text layer or -1 if no layer was created.' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (drawable && ! gimp_item_is_attached (GIMP_ITEM (drawable)))
    success = FALSE;

  if (success)
    {
      gchar *real_fontname = g_strdup_printf ("%s %d", fontname, (gint) size);

      text_layer = text_render (image, drawable, context,
                                x, y, real_fontname, text,
                                border, antialias);

      g_free (real_fontname);
    }
}
CODE
    );
}

sub text_get_extents_fontname {
    &std_pdb_deprecated ('gimp-text-layer-*');

    @inargs = (
        { name => 'text', type => 'string',
          desc => 'The text to generate (in UTF-8 encoding)' },
        { name => 'size', type => '0 < float',
          desc => 'The size of text in either pixels or points' },
        { name => 'size_type', type => 'enum GimpSizeType',
          desc => 'The units of specified size' },
        { name => 'fontname', type => 'string',
          desc => 'The name of the font' }
    );

    @outargs = (
        { name => 'width', type => 'int32', void_ret => 1,
          desc => 'The width of the specified font' },
        { name => 'height', type => 'int32',
          desc => 'The height of the specified font' },
        { name => 'ascent', type => 'int32',
          desc => 'The ascent of the specified font' },
        { name => 'descent', type => 'int32',
          desc => 'The descent of the specified font' }
    );

    %invoke = (
        code => <<'CODE'
{
  gchar *real_fontname = g_strdup_printf ("%s %d", fontname, (gint) size);

  success = text_get_extents (real_fontname, text,
                              &width, &height,
                              &ascent, &descent);

  g_free (real_fontname);
}
CODE
    );
}

sub text {
    &std_pdb_deprecated ('gimp-text-layer-new');

    @inargs = (
        { name => 'image', type => 'image',
          desc => 'The image' },
        { name => 'drawable', type => 'drawable',
          desc => 'The affected drawable: (-1 for a new text layer)',
          none_ok => 1 },
        { name => 'x', type => 'float',
          desc => 'The x coordinate for the left of the text bounding box' },
        { name => 'y', type => 'float',
          desc => 'The y coordinate for the top of the text bounding box' },
        { name => 'text', type => 'string',
          desc => 'The text to generate (in UTF-8 encoding)' },
        { name => 'border', type => '-1 <= int32',
          desc => 'The size of the border' },
        { name => 'antialias', type => 'boolean',
          desc => 'Antialiasing' },
        { name => 'size', type => '0 < float',
          desc => 'The size of text in either pixels or points' },
        { name => 'size_type', type => 'enum GimpSizeType',
          desc => 'The units of specified size' },
        { name => 'foundry', type => 'string', allow_non_utf8 => 1,
          desc => 'The font foundry' },
        { name => 'family', type => 'string', allow_non_utf8 => 1,
          desc => 'The font family' },
        { name => 'weight', type => 'string', allow_non_utf8 => 1,
          desc => 'The font weight' },
        { name => 'slant', type => 'string', allow_non_utf8 => 1,
          desc => 'The font slant' },
        { name => 'set_width', type => 'string', allow_non_utf8 => 1,
          desc => 'The font set-width' },
        { name => 'spacing', type => 'string', allow_non_utf8 => 1,
          desc => 'The font spacing' },
        { name => 'registry', type => 'string', allow_non_utf8 => 1,
          desc => 'The font registry' },
        { name => 'encoding', type => 'string', allow_non_utf8 => 1,
          desc => 'The font encoding' }
    );

    @outargs = (
        { name => 'text_layer', type => 'layer',
          desc => 'The new text layer or -1 if no layer was created.' }
    );

    %invoke = (
        code => <<'CODE'
{
  if (drawable && ! gimp_item_is_attached (GIMP_ITEM (drawable)))
    success = FALSE;

  if (success)
    {
      gchar *real_fontname = g_strdup_printf ("%s %d", family, (gint) size);

      text_layer = text_render (image, drawable, context,
                                x, y, real_fontname, text,
                                border, antialias);

      g_free (real_fontname);
    }
}
CODE
   );
}

sub text_get_extents {
    &std_pdb_deprecated ('gimp-text-layer-*');

    @inargs = (
        { name => 'text', type => 'string',
          desc => 'The text to generate (in UTF-8 encoding)' },
        { name => 'size', type => '0 < float',
          desc => 'The size of text in either pixels or points' },
        { name => 'size_type', type => 'enum GimpSizeType',
          desc => 'The units of specified size' },
        { name => 'foundry', type => 'string', allow_non_utf8 => 1,
          desc => 'The font foundry' },
        { name => 'family', type => 'string', allow_non_utf8 => 1,
          desc => 'The font family' },
        { name => 'weight', type => 'string', allow_non_utf8 => 1,
          desc => 'The font weight' },
        { name => 'slant', type => 'string', allow_non_utf8 => 1,
          desc => 'The font slant' },
        { name => 'set_width', type => 'string', allow_non_utf8 => 1,
          desc => 'The font set-width' },
        { name => 'spacing', type => 'string', allow_non_utf8 => 1,
          desc => 'The font spacing' },
        { name => 'registry', type => 'string', allow_non_utf8 => 1,
          desc => 'The font registry' },
        { name => 'encoding', type => 'string', allow_non_utf8 => 1,
          desc => 'The font encoding' }
    );

    @outargs = (
        { name => 'width', type => 'int32', void_ret => 1,
          desc => 'The width of the specified font' },
        { name => 'height', type => 'int32',
          desc => 'The height of the specified font' },
        { name => 'ascent', type => 'int32',
          desc => 'The ascent of the specified font' },
        { name => 'descent', type => 'int32',
          desc => 'The descent of the specified font' }
    );

    %invoke = (
        code => <<'CODE'
{
  gchar *real_fontname = g_strdup_printf ("%s %d", family, (gint) size);

  success = text_get_extents (real_fontname, text,
                              &width, &height,
                              &ascent, &descent);

  g_free (real_fontname);
}
CODE
    );
}


@headers = qw("libgimpbase/gimpbase.h"
              "core/gimpcontext.h"
              "vectors/gimpvectors.h"
              <pango/pangoft2.h>
              "text/gimptext-private.h"
              "text/gimptextlayout.h"
              "text/gimptext-vectors.h"
              "text/gimptext.h"
              "text/gimptextlayer.h"
              "text/text-enums.h"
              "text/gimptext-compat.h");

@procs = qw(drawable_is_text_layer
            text_layer_new
            text_layer_set_text
            text_layer_set_font
            text_layer_set_fontsize
            text_layer_set_hinting
            text_layer_set_antialias
            text_layer_set_kerning
            text_layer_set_language
            text_layer_set_base_direction
            text_layer_set_justification
            text_layer_set_color
            text_layer_set_indent
            text_layer_set_line_spacing
            text_layer_set_letter_spacing
            text_layer_get_text
            text_layer_get_font
            text_layer_get_fontsize
            text_layer_get_hinting
            text_layer_get_antialias
            text_layer_get_kerning
            text_layer_get_language
            text_layer_get_base_direction
            text_layer_get_justification
            text_layer_get_color
            text_layer_get_indent
            text_layer_get_line_spacing
            text_layer_get_letter_spacing
            vectors_from_text_layer
            text_fontname
            text_get_extents_fontname
            text
            text_get_extents);

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

$desc = 'Text procedures';

1;
