summaryrefslogtreecommitdiffstats
path: root/pdb/groups/text_tool.pdb
blob: 4ad7e7ca26ba28e26d3532da0ed794f24c7f3f32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# GIMP - The GNU 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 3 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, see <https://www.gnu.org/licenses/>.

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

sub text_fontname {
    $blurb = <<'BLURB';
Add text at the specified location as a floating selection or a new layer.
BLURB

    $help = <<'HELP';
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. 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.
HELP

    &std_pdb_misc;
    $author = 'Martin Edlman & Sven Neumann';
    $date = '1998- 2001';

    @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', dead => 1,
          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_pdb_item_is_attached (GIMP_ITEM (drawable), image,
                                    GIMP_PDB_ITEM_CONTENT, error) ||
       ! gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)))
    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 {
    $blurb = 'Get extents of the bounding box for the specified text.';

    $help = <<'HELP';
This tool returns the width and height of a bounding box for the specified text
string with the specified font information. Ascent 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.
HELP

    &std_pdb_misc;
    $author = 'Martin Edlman & Sven Neumann';
    $date = '1998- 2001';

    @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', dead => 1,
          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 (gimp,
                              real_fontname, text,
                              &width, &height,
                              &ascent, &descent);

  g_free (real_fontname);
}
CODE
    );
}

sub text {
    &std_pdb_deprecated ('gimp-text-fontname');

    @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', dead => 1,
          desc => 'The units of specified size' },
        { name => 'foundry', type => 'string', allow_non_utf8 => 1, dead => 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, dead => 1,
          desc => 'The font weight' },
        { name => 'slant', type => 'string', allow_non_utf8 => 1, dead => 1,
          desc => 'The font slant' },
        { name => 'set_width', type => 'string', allow_non_utf8 => 1, dead => 1,
          desc => 'The font set-width' },
        { name => 'spacing', type => 'string', allow_non_utf8 => 1, dead => 1,
          desc => 'The font spacing' },
        { name => 'registry', type => 'string', allow_non_utf8 => 1, dead => 1,
          desc => 'The font registry' },
        { name => 'encoding', type => 'string', allow_non_utf8 => 1, dead => 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_pdb_item_is_attached (GIMP_ITEM (drawable), image,
                                    GIMP_PDB_ITEM_CONTENT, error) ||
       ! gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)))
    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-get-extents-fontname');

    @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', dead => 1,
          desc => 'The units of specified size' },
        { name => 'foundry', type => 'string', allow_non_utf8 => 1, dead => 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, dead => 1,
          desc => 'The font weight' },
        { name => 'slant', type => 'string', allow_non_utf8 => 1, dead => 1,
          desc => 'The font slant' },
        { name => 'set_width', type => 'string', allow_non_utf8 => 1, dead => 1,
          desc => 'The font set-width' },
        { name => 'spacing', type => 'string', allow_non_utf8 => 1, dead => 1,
          desc => 'The font spacing' },
        { name => 'registry', type => 'string', allow_non_utf8 => 1, dead => 1,
          desc => 'The font registry' },
        { name => 'encoding', type => 'string', allow_non_utf8 => 1, dead => 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 (gimp,
                              real_fontname, text,
                              &width, &height,
                              &ascent, &descent);

  g_free (real_fontname);
}
CODE
    );
}


@headers = qw("libgimpbase/gimpbase.h"
              "text/gimptext-compat.h"
              "gimppdb-utils.h");

@procs = qw(text_fontname text_get_extents_fontname
            text text_get_extents);

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

$desc = 'Text procedures';
$doc_title = 'gimptexttool';
$doc_short_desc = 'Functions for controlling the text tool.';
$doc_long_desc = 'Functions for controlling the text tool.';

1;