Issue #9987: text related functions crash using string for font name.

- Fonctions were renamed: s/gimp_text_fontname/gimp_text_font/ and
  s/gimp_text_get_extents_fontname/gimp_text_get_extents_font/
- The size_type arguments were removed. Even in 2.10, this argument was marked
  as "dead" and ignored. It was only kept for API compatibility.
- The font name (string) was replaced by a GimpFont argument.

gimp_text_font() is easily tested in the Python console with:

> Gimp.text_font(Gimp.list_images()[0], None, 10, 40, "Hello World!", 1.0, True, 100, Gimp.context_get_font())

And gimp_text_get_extents_font() with:

> Gimp.text_get_extents_font("Hello World!", 100, Gimp.context_get_font())
This commit is contained in:
Jehan 2023-10-02 20:38:18 +02:00
parent 0a77a8492f
commit 24a85eebd6
8 changed files with 150 additions and 212 deletions

View File

@ -35,6 +35,7 @@
#include "core/gimpimage.h" #include "core/gimpimage.h"
#include "core/gimplayer.h" #include "core/gimplayer.h"
#include "core/gimpparamspecs.h" #include "core/gimpparamspecs.h"
#include "text/gimpfont.h"
#include "text/gimptext-compat.h" #include "text/gimptext-compat.h"
#include "gimppdb.h" #include "gimppdb.h"
@ -44,12 +45,12 @@
static GimpValueArray * static GimpValueArray *
text_fontname_invoker (GimpProcedure *procedure, text_font_invoker (GimpProcedure *procedure,
Gimp *gimp, Gimp *gimp,
GimpContext *context, GimpContext *context,
GimpProgress *progress, GimpProgress *progress,
const GimpValueArray *args, const GimpValueArray *args,
GError **error) GError **error)
{ {
gboolean success = TRUE; gboolean success = TRUE;
GimpValueArray *return_vals; GimpValueArray *return_vals;
@ -61,7 +62,7 @@ text_fontname_invoker (GimpProcedure *procedure,
gint border; gint border;
gboolean antialias; gboolean antialias;
gdouble size; gdouble size;
const gchar *fontname; GimpFont *font;
GimpLayer *text_layer = NULL; GimpLayer *text_layer = NULL;
image = g_value_get_object (gimp_value_array_index (args, 0)); image = g_value_get_object (gimp_value_array_index (args, 0));
@ -72,7 +73,7 @@ text_fontname_invoker (GimpProcedure *procedure,
border = g_value_get_int (gimp_value_array_index (args, 5)); border = g_value_get_int (gimp_value_array_index (args, 5));
antialias = g_value_get_boolean (gimp_value_array_index (args, 6)); antialias = g_value_get_boolean (gimp_value_array_index (args, 6));
size = g_value_get_double (gimp_value_array_index (args, 7)); size = g_value_get_double (gimp_value_array_index (args, 7));
fontname = g_value_get_string (gimp_value_array_index (args, 9)); font = g_value_get_object (gimp_value_array_index (args, 8));
if (success) if (success)
{ {
@ -83,15 +84,9 @@ text_fontname_invoker (GimpProcedure *procedure,
success = FALSE; success = FALSE;
if (success) if (success)
{ text_layer = text_render (image, drawable, context,
gchar *real_fontname = g_strdup_printf ("%s %d", fontname, (gint) size); x, y, font, size, text,
border, antialias);
text_layer = text_render (image, drawable, context,
x, y, real_fontname, text,
border, antialias);
g_free (real_fontname);
}
} }
return_vals = gimp_procedure_get_return_values (procedure, success, return_vals = gimp_procedure_get_return_values (procedure, success,
@ -104,18 +99,18 @@ text_fontname_invoker (GimpProcedure *procedure,
} }
static GimpValueArray * static GimpValueArray *
text_get_extents_fontname_invoker (GimpProcedure *procedure, text_get_extents_font_invoker (GimpProcedure *procedure,
Gimp *gimp, Gimp *gimp,
GimpContext *context, GimpContext *context,
GimpProgress *progress, GimpProgress *progress,
const GimpValueArray *args, const GimpValueArray *args,
GError **error) GError **error)
{ {
gboolean success = TRUE; gboolean success = TRUE;
GimpValueArray *return_vals; GimpValueArray *return_vals;
const gchar *text; const gchar *text;
gdouble size; gdouble size;
const gchar *fontname; GimpFont *font;
gint width = 0; gint width = 0;
gint height = 0; gint height = 0;
gint ascent = 0; gint ascent = 0;
@ -123,18 +118,14 @@ text_get_extents_fontname_invoker (GimpProcedure *procedure,
text = g_value_get_string (gimp_value_array_index (args, 0)); text = g_value_get_string (gimp_value_array_index (args, 0));
size = g_value_get_double (gimp_value_array_index (args, 1)); size = g_value_get_double (gimp_value_array_index (args, 1));
fontname = g_value_get_string (gimp_value_array_index (args, 3)); font = g_value_get_object (gimp_value_array_index (args, 2));
if (success) if (success)
{ {
gchar *real_fontname = g_strdup_printf ("%s %d", fontname, (gint) size);
success = text_get_extents (gimp, success = text_get_extents (gimp,
real_fontname, text, font, size, text,
&width, &height, &width, &height,
&ascent, &descent); &ascent, &descent);
g_free (real_fontname);
} }
return_vals = gimp_procedure_get_return_values (procedure, success, return_vals = gimp_procedure_get_return_values (procedure, success,
@ -157,14 +148,15 @@ register_text_tool_procs (GimpPDB *pdb)
GimpProcedure *procedure; GimpProcedure *procedure;
/* /*
* gimp-text-fontname * gimp-text-font
*/ */
procedure = gimp_procedure_new (text_fontname_invoker); procedure = gimp_procedure_new (text_font_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure), gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-text-fontname"); "gimp-text-font");
gimp_procedure_set_static_help (procedure, gimp_procedure_set_static_help (procedure,
"Add text at the specified location as a floating selection or a new layer.", "Add text at the specified location as a floating selection or a new layer.",
"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 (%NULL), 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.", "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 (%NULL), 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.\n"
"The size is always in pixels. 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.",
NULL); NULL);
gimp_procedure_set_static_attribution (procedure, gimp_procedure_set_static_attribution (procedure,
"Martin Edlman & Sven Neumann", "Martin Edlman & Sven Neumann",
@ -216,23 +208,15 @@ register_text_tool_procs (GimpPDB *pdb)
gimp_procedure_add_argument (procedure, gimp_procedure_add_argument (procedure,
g_param_spec_double ("size", g_param_spec_double ("size",
"size", "size",
"The size of text in either pixels or points", "The size of text in pixels",
0, G_MAXDOUBLE, 0, 0, G_MAXDOUBLE, 0,
GIMP_PARAM_READWRITE)); GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure, gimp_procedure_add_argument (procedure,
g_param_spec_enum ("size-type", gimp_param_spec_font ("font",
"size type", "font",
"The units of specified size", "The font",
GIMP_TYPE_SIZE_TYPE, FALSE,
GIMP_PIXELS, GIMP_PARAM_READWRITE));
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("fontname",
"fontname",
"The name of the font",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure, gimp_procedure_add_return_value (procedure,
gimp_param_spec_layer ("text-layer", gimp_param_spec_layer ("text-layer",
"text layer", "text layer",
@ -243,14 +227,15 @@ register_text_tool_procs (GimpPDB *pdb)
g_object_unref (procedure); g_object_unref (procedure);
/* /*
* gimp-text-get-extents-fontname * gimp-text-get-extents-font
*/ */
procedure = gimp_procedure_new (text_get_extents_fontname_invoker); procedure = gimp_procedure_new (text_get_extents_font_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure), gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-text-get-extents-fontname"); "gimp-text-get-extents-font");
gimp_procedure_set_static_help (procedure, gimp_procedure_set_static_help (procedure,
"Get extents of the bounding box for the specified text.", "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 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.", "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.\n"
"The size is always in pixels. 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.",
NULL); NULL);
gimp_procedure_set_static_attribution (procedure, gimp_procedure_set_static_attribution (procedure,
"Martin Edlman & Sven Neumann", "Martin Edlman & Sven Neumann",
@ -270,19 +255,11 @@ register_text_tool_procs (GimpPDB *pdb)
0, G_MAXDOUBLE, 0, 0, G_MAXDOUBLE, 0,
GIMP_PARAM_READWRITE)); GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure, gimp_procedure_add_argument (procedure,
g_param_spec_enum ("size-type", gimp_param_spec_font ("font",
"size type", "font",
"The units of specified size", "The name of the font",
GIMP_TYPE_SIZE_TYPE, FALSE,
GIMP_PIXELS, GIMP_PARAM_READWRITE));
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("fontname",
"fontname",
"The name of the font",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure, gimp_procedure_add_return_value (procedure,
g_param_spec_int ("width", g_param_spec_int ("width",
"width", "width",

View File

@ -38,6 +38,7 @@
#include "core/gimpimage-undo.h" #include "core/gimpimage-undo.h"
#include "core/gimplayer-floating-selection.h" #include "core/gimplayer-floating-selection.h"
#include "gimpfont.h"
#include "gimptext.h" #include "gimptext.h"
#include "gimptext-compat.h" #include "gimptext-compat.h"
#include "gimptextlayer.h" #include "gimptextlayer.h"
@ -51,24 +52,22 @@ text_render (GimpImage *image,
GimpContext *context, GimpContext *context,
gint text_x, gint text_x,
gint text_y, gint text_y,
const gchar *fontname, GimpFont *font,
gdouble font_size,
const gchar *text, const gchar *text,
gint border, gint border,
gboolean antialias) gboolean antialias)
{ {
PangoFontDescription *desc; GimpText *gtext;
GimpText *gtext; GimpLayer *layer;
GimpLayer *layer; GimpRGB color;
GimpRGB color;
gchar *font;
gdouble size;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (drawable == NULL || g_return_val_if_fail (drawable == NULL ||
gimp_item_is_attached (GIMP_ITEM (drawable)), NULL); gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (fontname != NULL, NULL); g_return_val_if_fail (GIMP_IS_FONT (font), NULL);
g_return_val_if_fail (text != NULL, NULL); g_return_val_if_fail (text != NULL, NULL);
if (! gimp_data_factory_data_wait (image->gimp->font_factory)) if (! gimp_data_factory_data_wait (image->gimp->font_factory))
@ -77,27 +76,17 @@ text_render (GimpImage *image,
if (border < 0) if (border < 0)
border = 0; border = 0;
desc = pango_font_description_from_string (fontname);
size = PANGO_PIXELS (pango_font_description_get_size (desc));
pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE);
font = pango_font_description_to_string (desc);
pango_font_description_free (desc);
gimp_context_get_foreground (context, &color); gimp_context_get_foreground (context, &color);
gtext = g_object_new (GIMP_TYPE_TEXT, gtext = g_object_new (GIMP_TYPE_TEXT,
"text", text, "text", text,
"font", font, "font", font,
"font-size", size, "font-size", font_size,
"antialias", antialias, "antialias", antialias,
"border", border, "border", border,
"color", &color, "color", &color,
NULL); NULL);
g_free (font);
layer = gimp_text_layer_new (image, gtext); layer = gimp_text_layer_new (image, gtext);
g_object_unref (gtext); g_object_unref (gtext);
@ -138,7 +127,8 @@ text_render (GimpImage *image,
gboolean gboolean
text_get_extents (Gimp *gimp, text_get_extents (Gimp *gimp,
const gchar *fontname, GimpFont *font,
gdouble font_size,
const gchar *text, const gchar *text,
gint *width, gint *width,
gint *height, gint *height,
@ -150,9 +140,10 @@ text_get_extents (Gimp *gimp,
PangoLayout *layout; PangoLayout *layout;
PangoFontMap *fontmap; PangoFontMap *fontmap;
PangoRectangle rect; PangoRectangle rect;
gchar *real_fontname;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE); g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
g_return_val_if_fail (fontname != NULL, FALSE); g_return_val_if_fail (GIMP_IS_FONT (font), NULL);
g_return_val_if_fail (text != NULL, FALSE); g_return_val_if_fail (text != NULL, FALSE);
if (! gimp_data_factory_data_wait (gimp->font_factory)) if (! gimp_data_factory_data_wait (gimp->font_factory))
@ -171,9 +162,11 @@ text_get_extents (Gimp *gimp,
layout = pango_layout_new (context); layout = pango_layout_new (context);
g_object_unref (context); g_object_unref (context);
font_desc = pango_font_description_from_string (fontname); real_fontname = g_strdup_printf ("%s %d", gimp_font_get_lookup_name (font), (gint) font_size);
font_desc = pango_font_description_from_string (real_fontname);
pango_layout_set_font_description (layout, font_desc); pango_layout_set_font_description (layout, font_desc);
pango_font_description_free (font_desc); pango_font_description_free (font_desc);
g_free (real_fontname);
pango_layout_set_text (layout, text, -1); pango_layout_set_text (layout, text, -1);

View File

@ -29,12 +29,14 @@ GimpLayer * text_render (GimpImage *image,
GimpContext *context, GimpContext *context,
gint text_x, gint text_x,
gint text_y, gint text_y,
const gchar *fontname, GimpFont *font,
gdouble font_size,
const gchar *text, const gchar *text,
gint border, gint border,
gboolean antialias); gboolean antialias);
gboolean text_get_extents (Gimp *gimp, gboolean text_get_extents (Gimp *gimp,
const gchar *fontname, GimpFont *font,
gdouble font_size,
const gchar *text, const gchar *text,
gint *width, gint *width,
gint *height, gint *height,

View File

@ -855,8 +855,8 @@ EXPORTS
gimp_smudge gimp_smudge
gimp_smudge_default gimp_smudge_default
gimp_temp_file gimp_temp_file
gimp_text_fontname gimp_text_font
gimp_text_get_extents_fontname gimp_text_get_extents_font
gimp_text_layer_get_antialias gimp_text_layer_get_antialias
gimp_text_layer_get_base_direction gimp_text_layer_get_base_direction
gimp_text_layer_get_by_id gimp_text_layer_get_by_id

View File

@ -37,7 +37,7 @@
/** /**
* gimp_text_fontname: * gimp_text_font:
* @image: The image. * @image: The image.
* @drawable: (nullable): The affected drawable: (%NULL for a new text layer). * @drawable: (nullable): The affected drawable: (%NULL for a new text layer).
* @x: The x coordinate for the left of the text bounding box. * @x: The x coordinate for the left of the text bounding box.
@ -45,41 +45,36 @@
* @text: The text to generate (in UTF-8 encoding). * @text: The text to generate (in UTF-8 encoding).
* @border: The size of the border. * @border: The size of the border.
* @antialias: Antialiasing. * @antialias: Antialiasing.
* @size: The size of text in either pixels or points. * @size: The size of text in pixels.
* @size_type: The units of specified size. * @font: The font.
* @fontname: The name of the font.
* *
* Add text at the specified location as a floating selection or a new * Add text at the specified location as a floating selection or a new
* layer. * layer.
* *
* This tool requires a fontname matching an installed PangoFT2 font. * The x and y parameters together control the placement of the new
* You can specify the fontsize in units of pixels or points, and the * text by specifying the upper left corner of the text bounding box.
* appropriate metric is specified using the size_type argument. The x * If the specified drawable parameter is valid, the text will be
* and y parameters together control the placement of the new text by * created as a floating selection attached to the drawable. If the
* specifying the upper left corner of the text bounding box. If the * drawable parameter is not valid (%NULL), the text will appear as a
* specified drawable parameter is valid, the text will be created as a * new layer. Finally, a border can be specified around the final
* floating selection attached to the drawable. If the drawable * rendered text. The border is measured in pixels.
* parameter is not valid (%NULL), the text will appear as a new layer. * The size is always in pixels. If you need to display a font in
* Finally, a border can be specified around the final rendered text. * points, divide the size in points by 72.0 and multiply it by the
* The border is measured in pixels. Parameter size-type is not used * image's vertical resolution.
* 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.
* *
* Returns: (nullable) (transfer none): * Returns: (nullable) (transfer none):
* The new text layer or %NULL if no layer was created. * The new text layer or %NULL if no layer was created.
**/ **/
GimpLayer * GimpLayer *
gimp_text_fontname (GimpImage *image, gimp_text_font (GimpImage *image,
GimpDrawable *drawable, GimpDrawable *drawable,
gdouble x, gdouble x,
gdouble y, gdouble y,
const gchar *text, const gchar *text,
gint border, gint border,
gboolean antialias, gboolean antialias,
gdouble size, gdouble size,
GimpSizeType size_type, GimpFont *font)
const gchar *fontname)
{ {
GimpValueArray *args; GimpValueArray *args;
GimpValueArray *return_vals; GimpValueArray *return_vals;
@ -94,12 +89,11 @@ gimp_text_fontname (GimpImage *image,
G_TYPE_INT, border, G_TYPE_INT, border,
G_TYPE_BOOLEAN, antialias, G_TYPE_BOOLEAN, antialias,
G_TYPE_DOUBLE, size, G_TYPE_DOUBLE, size,
GIMP_TYPE_SIZE_TYPE, size_type, GIMP_TYPE_FONT, font,
G_TYPE_STRING, fontname,
G_TYPE_NONE); G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (), return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-text-fontname", "gimp-text-font",
args); args);
gimp_value_array_unref (args); gimp_value_array_unref (args);
@ -112,11 +106,10 @@ gimp_text_fontname (GimpImage *image,
} }
/** /**
* gimp_text_get_extents_fontname: * gimp_text_get_extents_font:
* @text: The text to generate (in UTF-8 encoding). * @text: The text to generate (in UTF-8 encoding).
* @size: The size of text in either pixels or points. * @size: The size of text in either pixels or points.
* @size_type: The units of specified size. * @font: The name of the font.
* @fontname: The name of the font.
* @width: (out): The width of the specified font. * @width: (out): The width of the specified font.
* @height: (out): The height of the specified font. * @height: (out): The height of the specified font.
* @ascent: (out): The ascent of the specified font. * @ascent: (out): The ascent of the specified font.
@ -126,23 +119,21 @@ gimp_text_fontname (GimpImage *image,
* *
* This tool returns the width and height of a bounding box for the * This tool returns the width and height of a bounding box for the
* specified text string with the specified font information. Ascent * specified text string with the specified font information. Ascent
* and descent for the specified font are returned as well. Parameter * and descent for the specified font are returned as well.
* size-type is not used and is currently ignored. If you need to * The size is always in pixels. If you need to display a font in
* display a font in points, divide the size in points by 72.0 and * points, divide the size in points by 72.0 and multiply it by the
* multiply it by the vertical resolution of the image you are taking * vertical resolution of the image you are taking into account.
* into account.
* *
* Returns: TRUE on success. * Returns: TRUE on success.
**/ **/
gboolean gboolean
gimp_text_get_extents_fontname (const gchar *text, gimp_text_get_extents_font (const gchar *text,
gdouble size, gdouble size,
GimpSizeType size_type, GimpFont *font,
const gchar *fontname, gint *width,
gint *width, gint *height,
gint *height, gint *ascent,
gint *ascent, gint *descent)
gint *descent)
{ {
GimpValueArray *args; GimpValueArray *args;
GimpValueArray *return_vals; GimpValueArray *return_vals;
@ -151,12 +142,11 @@ gimp_text_get_extents_fontname (const gchar *text,
args = gimp_value_array_new_from_types (NULL, args = gimp_value_array_new_from_types (NULL,
G_TYPE_STRING, text, G_TYPE_STRING, text,
G_TYPE_DOUBLE, size, G_TYPE_DOUBLE, size,
GIMP_TYPE_SIZE_TYPE, size_type, GIMP_TYPE_FONT, font,
G_TYPE_STRING, fontname,
G_TYPE_NONE); G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (), return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-text-get-extents-fontname", "gimp-text-get-extents-font",
args); args);
gimp_value_array_unref (args); gimp_value_array_unref (args);

View File

@ -32,24 +32,22 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */ /* For information look into the C source or the html documentation */
GimpLayer* gimp_text_fontname (GimpImage *image, GimpLayer* gimp_text_font (GimpImage *image,
GimpDrawable *drawable, GimpDrawable *drawable,
gdouble x, gdouble x,
gdouble y, gdouble y,
const gchar *text, const gchar *text,
gint border, gint border,
gboolean antialias, gboolean antialias,
gdouble size, gdouble size,
GimpSizeType size_type, GimpFont *font);
const gchar *fontname); gboolean gimp_text_get_extents_font (const gchar *text,
gboolean gimp_text_get_extents_fontname (const gchar *text, gdouble size,
gdouble size, GimpFont *font,
GimpSizeType size_type, gint *width,
const gchar *fontname, gint *height,
gint *width, gint *ascent,
gint *height, gint *descent);
gint *ascent,
gint *descent);
G_END_DECLS G_END_DECLS

View File

@ -16,24 +16,21 @@
# "Perlized" from C source by Manish Singh <yosh@gimp.org> # "Perlized" from C source by Manish Singh <yosh@gimp.org>
sub text_fontname { sub text_font {
$blurb = <<'BLURB'; $blurb = <<'BLURB';
Add text at the specified location as a floating selection or a new layer. Add text at the specified location as a floating selection or a new layer.
BLURB BLURB
$help = <<'HELP'; $help = <<'HELP';
This tool requires a fontname matching an installed PangoFT2 font. The x and y parameters together control the placement of the new text by
You can specify the fontsize in units of pixels specifying the upper left corner of the text bounding box. If the specified
or points, and the appropriate metric is specified using the size_type drawable parameter is valid, the text will be created as a floating selection
argument. The x and y parameters together control the placement of the new attached to the drawable. If the drawable parameter is not valid (%NULL), the
text by specifying the upper left corner of the text bounding box. If the text will appear as a new layer. Finally, a border can be specified around the
specified drawable parameter is valid, the text will be created as a floating final rendered text. The border is measured in pixels.
selection attached to the drawable. If the drawable parameter is not valid
(%NULL), the text will appear as a new layer. Finally, a border can be specified The size is always in pixels. If you need to display a font in points, divide
around the final rendered text. The border is measured in pixels. Parameter the size in points by 72.0 and multiply it by the image's vertical resolution.
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 HELP
&std_pdb_misc; &std_pdb_misc;
@ -57,11 +54,9 @@ HELP
{ name => 'antialias', type => 'boolean', { name => 'antialias', type => 'boolean',
desc => 'Antialiasing' }, desc => 'Antialiasing' },
{ name => 'size', type => '0 < float', { name => 'size', type => '0 < float',
desc => 'The size of text in either pixels or points' }, desc => 'The size of text in pixels' },
{ name => 'size_type', type => 'enum GimpSizeType', dead => 1, { name => 'font', type => 'font',
desc => 'The units of specified size' }, desc => 'The font' }
{ name => 'fontname', type => 'string',
desc => 'The name of the font' }
); );
@outargs = ( @outargs = (
@ -79,29 +74,24 @@ HELP
success = FALSE; success = FALSE;
if (success) if (success)
{ text_layer = text_render (image, drawable, context,
gchar *real_fontname = g_strdup_printf ("%s %d", fontname, (gint) size); x, y, font, size, text,
border, antialias);
text_layer = text_render (image, drawable, context,
x, y, real_fontname, text,
border, antialias);
g_free (real_fontname);
}
} }
CODE CODE
); );
} }
sub text_get_extents_fontname { sub text_get_extents_font {
$blurb = 'Get extents of the bounding box for the specified text.'; $blurb = 'Get extents of the bounding box for the specified text.';
$help = <<'HELP'; $help = <<'HELP';
This tool returns the width and height of a 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 and descent for the 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 specified font are returned as well.
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 The size is always in pixels. 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. image you are taking into account.
HELP HELP
@ -114,9 +104,7 @@ HELP
desc => 'The text to generate (in UTF-8 encoding)' }, desc => 'The text to generate (in UTF-8 encoding)' },
{ name => 'size', type => '0 < float', { name => 'size', type => '0 < float',
desc => 'The size of text in either pixels or points' }, desc => 'The size of text in either pixels or points' },
{ name => 'size_type', type => 'enum GimpSizeType', dead => 1, { name => 'font', type => 'font',
desc => 'The units of specified size' },
{ name => 'fontname', type => 'string',
desc => 'The name of the font' } desc => 'The name of the font' }
); );
@ -134,14 +122,10 @@ HELP
%invoke = ( %invoke = (
code => <<'CODE' code => <<'CODE'
{ {
gchar *real_fontname = g_strdup_printf ("%s %d", fontname, (gint) size);
success = text_get_extents (gimp, success = text_get_extents (gimp,
real_fontname, text, font, size, text,
&width, &height, &width, &height,
&ascent, &descent); &ascent, &descent);
g_free (real_fontname);
} }
CODE CODE
); );
@ -152,8 +136,8 @@ CODE
"text/gimptext-compat.h" "text/gimptext-compat.h"
"gimppdb-utils.h"); "gimppdb-utils.h");
@procs = qw(text_fontname @procs = qw(text_font
text_get_extents_fontname); text_get_extents_font);
%exports = (app => [@procs], lib => [@procs]); %exports = (app => [@procs], lib => [@procs]);

View File

@ -778,9 +778,6 @@ draw_number (GimpLayer *layer,
GimpImage *image; GimpImage *image;
GimpLayer *text_layer; GimpLayer *text_layer;
gint text_width, text_height, text_ascent, descent; gint text_width, text_height, text_ascent, descent;
gchar *fontname;
fontname = gimp_resource_get_name (GIMP_RESOURCE (font));
g_snprintf (buf, sizeof (buf), "%d", num); g_snprintf (buf, sizeof (buf), "%d", num);
@ -801,11 +798,9 @@ draw_number (GimpLayer *layer,
if ((k & 1) == 0) if ((k & 1) == 0)
delta = -delta; delta = -delta;
success = gimp_text_get_extents_fontname (buf, success = gimp_text_get_extents_font (buf, height + delta, font,
height + delta, GIMP_PIXELS, &text_width, &text_height,
fontname, &text_ascent, &descent);
&text_width, &text_height,
&text_ascent, &descent);
if (success) if (success)
{ {
@ -814,11 +809,10 @@ draw_number (GimpLayer *layer,
} }
} }
text_layer = gimp_text_fontname (image, GIMP_DRAWABLE (layer), text_layer = gimp_text_font (image, GIMP_DRAWABLE (layer),
x, y + descent / 2, x, y + descent / 2,
buf, 1, FALSE, buf, 1, FALSE,
height, GIMP_PIXELS, height, font);
fontname);
if (! text_layer) if (! text_layer)
g_message ("draw_number: Error in drawing text\n"); g_message ("draw_number: Error in drawing text\n");