gimptexttool_pdb.c 11.6 KB
Newer Older
1
/* LIBGIMP - The GIMP Library
2
 * Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
3 4 5
 *
 * gimptexttool_pdb.c
 *
6
 * This library is free software: you can redistribute it and/or
7 8
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
9
 * version 3 of the License, or (at your option) any later version.
10 11 12 13 14 15 16
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17 18
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
19 20
 */

21
/* NOTE: This file is auto-generated by pdbgen.pl */
22

Sven Neumann's avatar
Sven Neumann committed
23 24
#include "config.h"

25 26
#include "gimp.h"

27 28 29 30 31 32 33 34 35 36

/**
 * SECTION: gimptexttool
 * @title: gimptexttool
 * @short_description: Functions for controlling the text tool.
 *
 * Functions for controlling the text tool.
 **/


37 38 39 40 41 42
/**
 * gimp_text_fontname:
 * @image_ID: The image.
 * @drawable_ID: The affected drawable: (-1 for a new text layer).
 * @x: The x coordinate for the left of the text bounding box.
 * @y: The y coordinate for the top of the text bounding box.
43
 * @text: The text to generate (in UTF-8 encoding).
44 45 46 47
 * @border: The size of the border.
 * @antialias: Antialiasing.
 * @size: The size of text in either pixels or points.
 * @size_type: The units of specified size.
48
 * @fontname: The name of the font.
49 50 51 52
 *
 * Add text at the specified location as a floating selection or a new
 * layer.
 *
Sven Neumann's avatar
Sven Neumann committed
53 54 55 56 57 58 59 60 61
 * This tool requires a fontname matching an installed PangoFT2 font.
 * You can specify the fontsize in units of pixels or points, and the
 * appropriate metric is specified using the size_type argument. The x
 * and y parameters together control the placement of the new text by
 * specifying the upper left corner of the text bounding box. If the
 * specified drawable parameter is valid, the text will be created as a
 * floating selection attached to the drawable. If the drawable
 * parameter is not valid (-1), the text will appear as a new layer.
 * Finally, a border can be specified around the final rendered text.
62 63 64 65
 * The border is measured in pixels. Parameter size-type is not used
 * and is currently ignored. If you need to display a font in points,
 * divide the size in points by 72.0 and multiply it by the image's
 * vertical resolution.
66
 *
67
 * Returns: The new text layer or -1 if no layer was created.
68
 **/
69 70
gint32
gimp_text_fontname (gint32        image_ID,
71 72 73 74 75 76 77 78 79
                    gint32        drawable_ID,
                    gdouble       x,
                    gdouble       y,
                    const gchar  *text,
                    gint          border,
                    gboolean      antialias,
                    gdouble       size,
                    GimpSizeType  size_type,
                    const gchar  *fontname)
80
{
81
  GimpParam *return_vals;
82 83 84
  gint nreturn_vals;
  gint32 text_layer_ID = -1;

85
  return_vals = gimp_run_procedure ("gimp-text-fontname",
86 87 88 89 90 91 92 93 94 95 96 97
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_DRAWABLE, drawable_ID,
                                    GIMP_PDB_FLOAT, x,
                                    GIMP_PDB_FLOAT, y,
                                    GIMP_PDB_STRING, text,
                                    GIMP_PDB_INT32, border,
                                    GIMP_PDB_INT32, antialias,
                                    GIMP_PDB_FLOAT, size,
                                    GIMP_PDB_INT32, size_type,
                                    GIMP_PDB_STRING, fontname,
                                    GIMP_PDB_END);
98 99

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
100 101 102 103 104 105 106
    text_layer_ID = return_vals[1].data.d_layer;

  gimp_destroy_params (return_vals, nreturn_vals);

  return text_layer_ID;
}

107 108
/**
 * gimp_text_get_extents_fontname:
109
 * @text: The text to generate (in UTF-8 encoding).
110 111
 * @size: The size of text in either pixels or points.
 * @size_type: The units of specified size.
112
 * @fontname: The name of the font.
113 114 115 116 117 118 119 120 121
 * @width: The width of the specified font.
 * @height: The height of the specified font.
 * @ascent: The ascent of the specified font.
 * @descent: The descent of the specified font.
 *
 * Get extents of the bounding box for the specified text.
 *
 * This tool returns the width and height of a bounding box for the
 * specified text string with the specified font information. Ascent
122 123 124 125 126
 * and descent for the specified font are returned as well. Parameter
 * size-type is not used and is currently ignored. If you need to
 * display a font in points, divide the size in points by 72.0 and
 * multiply it by the vertical resolution of the image you are taking
 * into account.
127 128
 *
 * Returns: TRUE on success.
129
 **/
130
gboolean
131
gimp_text_get_extents_fontname (const gchar  *text,
132 133 134 135 136 137 138
                                gdouble       size,
                                GimpSizeType  size_type,
                                const gchar  *fontname,
                                gint         *width,
                                gint         *height,
                                gint         *ascent,
                                gint         *descent)
139
{
140
  GimpParam *return_vals;
141
  gint nreturn_vals;
142
  gboolean success = TRUE;
143

144
  return_vals = gimp_run_procedure ("gimp-text-get-extents-fontname",
145 146 147 148 149 150
                                    &nreturn_vals,
                                    GIMP_PDB_STRING, text,
                                    GIMP_PDB_FLOAT, size,
                                    GIMP_PDB_INT32, size_type,
                                    GIMP_PDB_STRING, fontname,
                                    GIMP_PDB_END);
151

152 153 154 155 156
  *width = 0;
  *height = 0;
  *ascent = 0;
  *descent = 0;

157 158 159
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  if (success)
160 161 162 163 164 165 166 167
    {
      *width = return_vals[1].data.d_int32;
      *height = return_vals[2].data.d_int32;
      *ascent = return_vals[3].data.d_int32;
      *descent = return_vals[4].data.d_int32;
    }

  gimp_destroy_params (return_vals, nreturn_vals);
168 169

  return success;
170 171
}

172 173 174 175 176 177
/**
 * gimp_text:
 * @image_ID: The image.
 * @drawable_ID: The affected drawable: (-1 for a new text layer).
 * @x: The x coordinate for the left of the text bounding box.
 * @y: The y coordinate for the top of the text bounding box.
178
 * @text: The text to generate (in UTF-8 encoding).
179 180 181 182
 * @border: The size of the border.
 * @antialias: Antialiasing.
 * @size: The size of text in either pixels or points.
 * @size_type: The units of specified size.
183 184 185 186 187 188 189 190
 * @foundry: The font foundry.
 * @family: The font family.
 * @weight: The font weight.
 * @slant: The font slant.
 * @set_width: The font set-width.
 * @spacing: The font spacing.
 * @registry: The font registry.
 * @encoding: The font encoding.
191
 *
192
 * Deprecated: Use gimp_text_fontname() instead.
193
 *
194
 * Returns: The new text layer or -1 if no layer was created.
195
 **/
196 197
gint32
gimp_text (gint32        image_ID,
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
           gint32        drawable_ID,
           gdouble       x,
           gdouble       y,
           const gchar  *text,
           gint          border,
           gboolean      antialias,
           gdouble       size,
           GimpSizeType  size_type,
           const gchar  *foundry,
           const gchar  *family,
           const gchar  *weight,
           const gchar  *slant,
           const gchar  *set_width,
           const gchar  *spacing,
           const gchar  *registry,
           const gchar  *encoding)
214
{
215
  GimpParam *return_vals;
216 217 218
  gint nreturn_vals;
  gint32 text_layer_ID = -1;

219
  return_vals = gimp_run_procedure ("gimp-text",
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_DRAWABLE, drawable_ID,
                                    GIMP_PDB_FLOAT, x,
                                    GIMP_PDB_FLOAT, y,
                                    GIMP_PDB_STRING, text,
                                    GIMP_PDB_INT32, border,
                                    GIMP_PDB_INT32, antialias,
                                    GIMP_PDB_FLOAT, size,
                                    GIMP_PDB_INT32, size_type,
                                    GIMP_PDB_STRING, foundry,
                                    GIMP_PDB_STRING, family,
                                    GIMP_PDB_STRING, weight,
                                    GIMP_PDB_STRING, slant,
                                    GIMP_PDB_STRING, set_width,
                                    GIMP_PDB_STRING, spacing,
                                    GIMP_PDB_STRING, registry,
                                    GIMP_PDB_STRING, encoding,
                                    GIMP_PDB_END);
239 240

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
241 242 243 244 245 246 247
    text_layer_ID = return_vals[1].data.d_layer;

  gimp_destroy_params (return_vals, nreturn_vals);

  return text_layer_ID;
}

248 249
/**
 * gimp_text_get_extents:
250
 * @text: The text to generate (in UTF-8 encoding).
251 252
 * @size: The size of text in either pixels or points.
 * @size_type: The units of specified size.
253 254 255 256 257 258 259 260
 * @foundry: The font foundry.
 * @family: The font family.
 * @weight: The font weight.
 * @slant: The font slant.
 * @set_width: The font set-width.
 * @spacing: The font spacing.
 * @registry: The font registry.
 * @encoding: The font encoding.
261 262 263 264 265
 * @width: The width of the specified font.
 * @height: The height of the specified font.
 * @ascent: The ascent of the specified font.
 * @descent: The descent of the specified font.
 *
266
 * Deprecated: Use gimp_text_get_extents_fontname() instead.
267 268
 *
 * Returns: TRUE on success.
269
 **/
270
gboolean
271
gimp_text_get_extents (const gchar  *text,
272 273 274 275 276 277 278 279 280 281 282 283 284 285
                       gdouble       size,
                       GimpSizeType  size_type,
                       const gchar  *foundry,
                       const gchar  *family,
                       const gchar  *weight,
                       const gchar  *slant,
                       const gchar  *set_width,
                       const gchar  *spacing,
                       const gchar  *registry,
                       const gchar  *encoding,
                       gint         *width,
                       gint         *height,
                       gint         *ascent,
                       gint         *descent)
286
{
287
  GimpParam *return_vals;
288
  gint nreturn_vals;
289
  gboolean success = TRUE;
290

291
  return_vals = gimp_run_procedure ("gimp-text-get-extents",
292 293 294 295 296 297 298 299 300 301 302 303 304
                                    &nreturn_vals,
                                    GIMP_PDB_STRING, text,
                                    GIMP_PDB_FLOAT, size,
                                    GIMP_PDB_INT32, size_type,
                                    GIMP_PDB_STRING, foundry,
                                    GIMP_PDB_STRING, family,
                                    GIMP_PDB_STRING, weight,
                                    GIMP_PDB_STRING, slant,
                                    GIMP_PDB_STRING, set_width,
                                    GIMP_PDB_STRING, spacing,
                                    GIMP_PDB_STRING, registry,
                                    GIMP_PDB_STRING, encoding,
                                    GIMP_PDB_END);
305

306 307 308 309 310
  *width = 0;
  *height = 0;
  *ascent = 0;
  *descent = 0;

311 312 313
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  if (success)
314 315 316 317 318 319 320 321
    {
      *width = return_vals[1].data.d_int32;
      *height = return_vals[2].data.d_int32;
      *ascent = return_vals[3].data.d_int32;
      *descent = return_vals[4].data.d_int32;
    }

  gimp_destroy_params (return_vals, nreturn_vals);
322 323

  return success;
324
}