From 7422ae2e035b948294c9d7fa6210cf9249eaecec Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Mon, 10 Aug 1998 15:06:58 +0000 Subject: [PATCH] Finally a font-selector. --Sven --- ChangeLog | 12 ++ app/internal_procs.c | 2 + app/text_tool.c | 221 +++++++++++++++++++- app/text_tool.h | 2 + app/tools/gimptexttool.c | 221 +++++++++++++++++++- app/tools/gimptexttool.h | 2 + app/tools/text_tool.c | 221 +++++++++++++++++++- app/tools/text_tool.h | 2 + plug-ins/script-fu/.cvsignore | 1 - plug-ins/script-fu/script-fu-enums.h | 3 +- plug-ins/script-fu/script-fu-interface.c | 229 ++++++++++++++++++++- plug-ins/script-fu/script-fu-scripts.c | 229 ++++++++++++++++++++- plug-ins/script-fu/script-fu.c | 1 + plug-ins/script-fu/scripts/test-sphere.scm | 51 ++++- 14 files changed, 1162 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1675d79541..310277ec4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Mon Aug 10 16:20:33 MEST 1998 Sven Neumann + + * app/internal_procs.c + * app/text_tool.[ch]: Wrappers for gimp-text and + gimp-text-get-extents. + + * plug-ins/script-fu/script-fu-enums.h + * plug-ins/script-fu/script-fu-scripts.c + * plug-ins/script-fu/script-fu.c + * plug-ins/script-fu/scripts/test-sphere.scm: A font-selector + for the script-fu dialog. See documentation in test-sphere.scm. + Sun Aug 9 14:15:42 MEST 1998 Sven Neumann * plug-ins/script-fu/script-fu-scripts.c: The scripf-fu dialog diff --git a/app/internal_procs.c b/app/internal_procs.c index 3cbaba6e6d..9dffce277c 100644 --- a/app/internal_procs.c +++ b/app/internal_procs.c @@ -106,8 +106,10 @@ internal_procs_init () procedural_db_register (&shear_proc); pcount++; procedural_db_register (&text_tool_proc); pcount++; procedural_db_register (&text_tool_proc_ext); pcount++; + procedural_db_register (&text_tool_proc_fontname); pcount++; procedural_db_register (&text_tool_get_extents_proc); pcount++; procedural_db_register (&text_tool_get_extents_proc_ext); pcount++; + procedural_db_register (&text_tool_get_extents_proc_fontname); pcount++; app_init_update_status(NULL, "GDisplay procedures", pcount/total_pcount); diff --git a/app/text_tool.c b/app/text_tool.c index e506073335..93442c81e9 100644 --- a/app/text_tool.c +++ b/app/text_tool.c @@ -159,10 +159,12 @@ static Layer * text_render (GImage *, GimpDrawable *, int, int, c static int font_compare_func (gpointer, gpointer); -static Argument * text_tool_invoker (Argument *); -static Argument * text_tool_invoker_ext (Argument *); -static Argument * text_tool_get_extents_invoker (Argument *); -static Argument * text_tool_get_extents_invoker_ext (Argument *); +static Argument * text_tool_invoker (Argument *); +static Argument * text_tool_invoker_ext (Argument *); +static Argument * text_tool_invoker_fontname (Argument *); +static Argument * text_tool_get_extents_invoker (Argument *); +static Argument * text_tool_get_extents_invoker_ext (Argument *); +static Argument * text_tool_get_extents_invoker_fontname (Argument *); static ActionAreaItem action_items[] = { @@ -2197,6 +2199,84 @@ ProcRecord text_tool_proc_ext = { { text_tool_invoker_ext } }, }; +/*************************************************/ +/* The text_tool_fontname procedure definition */ +ProcArg text_tool_args_fontname[] = +{ + { PDB_IMAGE, + "image", + "The image" + }, + { PDB_DRAWABLE, + "drawable", + "The affected drawable: (-1 for a new text layer)" + }, + { PDB_FLOAT, + "x", + "the x coordinate for the left side of text bounding box" + }, + { PDB_FLOAT, + "y", + "the y coordinate for the top of text bounding box" + }, + { PDB_STRING, + "text", + "the text to generate" + }, + { PDB_INT32, + "border", + "the size of the border: border >= 0" + }, + { PDB_INT32, + "antialias", + "generate antialiased text" + }, + { PDB_FLOAT, + "size", + "the size of text in either pixels or points" + }, + { PDB_INT32, + "size_type", + "the units of the specified size: { PIXELS (0), POINTS (1) }" + }, + { PDB_STRING, + "fontname", + "the fontname (conforming to the X Logical Font Description Conventions)" + } +}; + +ProcArg text_tool_out_args_fontname[] = +{ + { PDB_LAYER, + "text_layer", + "the new text layer" + } +}; + +ProcRecord text_tool_proc_fontname = +{ + "gimp_text_fontname", + "Add text at the specified location as a floating selection or a new layer.", + "This tool requires font information as a fontname conforming to the 'X Logical Font Description Conventions'. You can specify the fontsize in units of pixels or points, and the appropriate metric is specified using the size_type argument. The fontsize specified in the fontname is silently ignored." + "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 antialias parameter is non-zero, the generated text will blend more smoothly with underlying layers. " + "This option requires more time and memory to compute than non-antialiased text; the resulting floating selection or layer, however, will require the same amount of memory with or without antialiasing. 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.", + "Martin Edlman, Sven Neumann", + "Spencer Kimball & Peter Mattis", + "1998", + PDB_INTERNAL, + + /* Input arguments */ + 10, + text_tool_args_fontname, + + /* Output arguments */ + 1, + text_tool_out_args_fontname, + + /* Exec method */ + { { text_tool_invoker_fontname } }, +}; /**********************/ /* TEXT_GET_EXTENTS */ @@ -2375,6 +2455,70 @@ ProcRecord text_tool_get_extents_proc_ext = { { text_tool_get_extents_invoker_ext } }, }; +/*******************************/ +/* TEXT_GET_EXTENTS_FONTNAME */ +ProcArg text_tool_get_extents_args_fontname[] = +{ + { PDB_STRING, + "text", + "the text to generate" + }, + { PDB_FLOAT, + "size", + "the size of text in either pixels or points" + }, + { PDB_INT32, + "size_type", + "the units of the specified size: { PIXELS (0), POINTS (1) }" + }, + { PDB_STRING, + "fontname", + "the fontname (conforming to the X Logical Font Description Conventions)" + } +}; + +ProcArg text_tool_get_extents_out_args_fontname[] = +{ + { PDB_INT32, + "width", + "the width of the specified text" + }, + { PDB_INT32, + "height", + "the height of the specified text" + }, + { PDB_INT32, + "ascent", + "the ascent of the specified font" + }, + { PDB_INT32, + "descent", + "the descent of the specified font" + } +}; + +ProcRecord text_tool_get_extents_proc_fontname = +{ + "gimp_text_get_extents_fontname", + "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.", + "Martin Edlman, Sven Neumann", + "Spencer Kimball & Peter Mattis", + "1998", + PDB_INTERNAL, + + /* Input arguments */ + 4, + text_tool_get_extents_args_fontname, + + /* Output arguments */ + 4, + text_tool_get_extents_out_args_fontname, + + /* Exec method */ + { { text_tool_get_extents_invoker_fontname } }, +}; + static Argument * text_tool_invoker (Argument *args) @@ -2391,6 +2535,43 @@ text_tool_invoker (Argument *args) return text_tool_invoker_ext (argv); } +static Argument * +text_tool_invoker_fontname (Argument *args) +{ + int i; + char *fontname; + Argument argv[17]; + + for (i=0; i<9; i++) + argv[i] = args[i]; + + fontname = (char *) args[9].value.pdb_pointer; + + /* + Should check for a valid fontname here, probably using + if (!text_is_xlfd_font_name (fontname)) return + */ + + argv[9].arg_type = PDB_STRING; + argv[9].value.pdb_pointer = text_get_field (fontname, FOUNDRY); + argv[10].arg_type = PDB_STRING; + argv[10].value.pdb_pointer = text_get_field (fontname, FAMILY); + argv[11].arg_type = PDB_STRING; + argv[11].value.pdb_pointer = text_get_field (fontname, WEIGHT); + argv[12].arg_type = PDB_STRING; + argv[12].value.pdb_pointer = text_get_field (fontname, SLANT); + argv[13].arg_type = PDB_STRING; + argv[13].value.pdb_pointer = text_get_field (fontname, SET_WIDTH); + argv[14].arg_type = PDB_STRING; + argv[14].value.pdb_pointer = text_get_field (fontname, SPACING); + argv[15].arg_type = PDB_STRING; + argv[15].value.pdb_pointer = text_get_field (fontname, REGISTRY); + argv[16].arg_type = PDB_STRING; + argv[16].value.pdb_pointer = text_get_field (fontname, ENCODING); + + return text_tool_invoker_ext (argv); +} + static Argument * text_tool_invoker_ext (Argument *args) { @@ -2545,6 +2726,38 @@ text_tool_get_extents_invoker (Argument *args) return text_tool_get_extents_invoker_ext (argv); } +static Argument * +text_tool_get_extents_invoker_fontname (Argument *args) +{ + int i; + gchar *fontname; + Argument argv[17]; + + for (i=0; i<3; i++) + argv[i] = args[i]; + + fontname = args[3].value.pdb_pointer; + + argv[3].arg_type = PDB_STRING; + argv[3].value.pdb_pointer = text_get_field (fontname, FOUNDRY); + argv[4].arg_type = PDB_STRING; + argv[4].value.pdb_pointer = text_get_field (fontname, FAMILY); + argv[5].arg_type = PDB_STRING; + argv[5].value.pdb_pointer = text_get_field (fontname, WEIGHT); + argv[6].arg_type = PDB_STRING; + argv[6].value.pdb_pointer = text_get_field (fontname, SLANT); + argv[7].arg_type = PDB_STRING; + argv[7].value.pdb_pointer = text_get_field (fontname, SET_WIDTH); + argv[8].arg_type = PDB_STRING; + argv[8].value.pdb_pointer = text_get_field (fontname, SPACING); + argv[9].arg_type = PDB_STRING; + argv[9].value.pdb_pointer = text_get_field (fontname, REGISTRY); + argv[10].arg_type = PDB_STRING; + argv[10].value.pdb_pointer = text_get_field (fontname, ENCODING); + + return text_tool_get_extents_invoker_ext (argv); +} + static Argument * text_tool_get_extents_invoker_ext (Argument *args) { diff --git a/app/text_tool.h b/app/text_tool.h index f9feb652b7..c4e82b1a44 100644 --- a/app/text_tool.h +++ b/app/text_tool.h @@ -27,7 +27,9 @@ void tools_free_text (Tool *); /* Procedure definition and marshalling function */ extern ProcRecord text_tool_proc; extern ProcRecord text_tool_proc_ext; +extern ProcRecord text_tool_proc_fontname; extern ProcRecord text_tool_get_extents_proc; extern ProcRecord text_tool_get_extents_proc_ext; +extern ProcRecord text_tool_get_extents_proc_fontname; #endif /* __TEXT_TOOL_H__ */ diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c index e506073335..93442c81e9 100644 --- a/app/tools/gimptexttool.c +++ b/app/tools/gimptexttool.c @@ -159,10 +159,12 @@ static Layer * text_render (GImage *, GimpDrawable *, int, int, c static int font_compare_func (gpointer, gpointer); -static Argument * text_tool_invoker (Argument *); -static Argument * text_tool_invoker_ext (Argument *); -static Argument * text_tool_get_extents_invoker (Argument *); -static Argument * text_tool_get_extents_invoker_ext (Argument *); +static Argument * text_tool_invoker (Argument *); +static Argument * text_tool_invoker_ext (Argument *); +static Argument * text_tool_invoker_fontname (Argument *); +static Argument * text_tool_get_extents_invoker (Argument *); +static Argument * text_tool_get_extents_invoker_ext (Argument *); +static Argument * text_tool_get_extents_invoker_fontname (Argument *); static ActionAreaItem action_items[] = { @@ -2197,6 +2199,84 @@ ProcRecord text_tool_proc_ext = { { text_tool_invoker_ext } }, }; +/*************************************************/ +/* The text_tool_fontname procedure definition */ +ProcArg text_tool_args_fontname[] = +{ + { PDB_IMAGE, + "image", + "The image" + }, + { PDB_DRAWABLE, + "drawable", + "The affected drawable: (-1 for a new text layer)" + }, + { PDB_FLOAT, + "x", + "the x coordinate for the left side of text bounding box" + }, + { PDB_FLOAT, + "y", + "the y coordinate for the top of text bounding box" + }, + { PDB_STRING, + "text", + "the text to generate" + }, + { PDB_INT32, + "border", + "the size of the border: border >= 0" + }, + { PDB_INT32, + "antialias", + "generate antialiased text" + }, + { PDB_FLOAT, + "size", + "the size of text in either pixels or points" + }, + { PDB_INT32, + "size_type", + "the units of the specified size: { PIXELS (0), POINTS (1) }" + }, + { PDB_STRING, + "fontname", + "the fontname (conforming to the X Logical Font Description Conventions)" + } +}; + +ProcArg text_tool_out_args_fontname[] = +{ + { PDB_LAYER, + "text_layer", + "the new text layer" + } +}; + +ProcRecord text_tool_proc_fontname = +{ + "gimp_text_fontname", + "Add text at the specified location as a floating selection or a new layer.", + "This tool requires font information as a fontname conforming to the 'X Logical Font Description Conventions'. You can specify the fontsize in units of pixels or points, and the appropriate metric is specified using the size_type argument. The fontsize specified in the fontname is silently ignored." + "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 antialias parameter is non-zero, the generated text will blend more smoothly with underlying layers. " + "This option requires more time and memory to compute than non-antialiased text; the resulting floating selection or layer, however, will require the same amount of memory with or without antialiasing. 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.", + "Martin Edlman, Sven Neumann", + "Spencer Kimball & Peter Mattis", + "1998", + PDB_INTERNAL, + + /* Input arguments */ + 10, + text_tool_args_fontname, + + /* Output arguments */ + 1, + text_tool_out_args_fontname, + + /* Exec method */ + { { text_tool_invoker_fontname } }, +}; /**********************/ /* TEXT_GET_EXTENTS */ @@ -2375,6 +2455,70 @@ ProcRecord text_tool_get_extents_proc_ext = { { text_tool_get_extents_invoker_ext } }, }; +/*******************************/ +/* TEXT_GET_EXTENTS_FONTNAME */ +ProcArg text_tool_get_extents_args_fontname[] = +{ + { PDB_STRING, + "text", + "the text to generate" + }, + { PDB_FLOAT, + "size", + "the size of text in either pixels or points" + }, + { PDB_INT32, + "size_type", + "the units of the specified size: { PIXELS (0), POINTS (1) }" + }, + { PDB_STRING, + "fontname", + "the fontname (conforming to the X Logical Font Description Conventions)" + } +}; + +ProcArg text_tool_get_extents_out_args_fontname[] = +{ + { PDB_INT32, + "width", + "the width of the specified text" + }, + { PDB_INT32, + "height", + "the height of the specified text" + }, + { PDB_INT32, + "ascent", + "the ascent of the specified font" + }, + { PDB_INT32, + "descent", + "the descent of the specified font" + } +}; + +ProcRecord text_tool_get_extents_proc_fontname = +{ + "gimp_text_get_extents_fontname", + "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.", + "Martin Edlman, Sven Neumann", + "Spencer Kimball & Peter Mattis", + "1998", + PDB_INTERNAL, + + /* Input arguments */ + 4, + text_tool_get_extents_args_fontname, + + /* Output arguments */ + 4, + text_tool_get_extents_out_args_fontname, + + /* Exec method */ + { { text_tool_get_extents_invoker_fontname } }, +}; + static Argument * text_tool_invoker (Argument *args) @@ -2391,6 +2535,43 @@ text_tool_invoker (Argument *args) return text_tool_invoker_ext (argv); } +static Argument * +text_tool_invoker_fontname (Argument *args) +{ + int i; + char *fontname; + Argument argv[17]; + + for (i=0; i<9; i++) + argv[i] = args[i]; + + fontname = (char *) args[9].value.pdb_pointer; + + /* + Should check for a valid fontname here, probably using + if (!text_is_xlfd_font_name (fontname)) return + */ + + argv[9].arg_type = PDB_STRING; + argv[9].value.pdb_pointer = text_get_field (fontname, FOUNDRY); + argv[10].arg_type = PDB_STRING; + argv[10].value.pdb_pointer = text_get_field (fontname, FAMILY); + argv[11].arg_type = PDB_STRING; + argv[11].value.pdb_pointer = text_get_field (fontname, WEIGHT); + argv[12].arg_type = PDB_STRING; + argv[12].value.pdb_pointer = text_get_field (fontname, SLANT); + argv[13].arg_type = PDB_STRING; + argv[13].value.pdb_pointer = text_get_field (fontname, SET_WIDTH); + argv[14].arg_type = PDB_STRING; + argv[14].value.pdb_pointer = text_get_field (fontname, SPACING); + argv[15].arg_type = PDB_STRING; + argv[15].value.pdb_pointer = text_get_field (fontname, REGISTRY); + argv[16].arg_type = PDB_STRING; + argv[16].value.pdb_pointer = text_get_field (fontname, ENCODING); + + return text_tool_invoker_ext (argv); +} + static Argument * text_tool_invoker_ext (Argument *args) { @@ -2545,6 +2726,38 @@ text_tool_get_extents_invoker (Argument *args) return text_tool_get_extents_invoker_ext (argv); } +static Argument * +text_tool_get_extents_invoker_fontname (Argument *args) +{ + int i; + gchar *fontname; + Argument argv[17]; + + for (i=0; i<3; i++) + argv[i] = args[i]; + + fontname = args[3].value.pdb_pointer; + + argv[3].arg_type = PDB_STRING; + argv[3].value.pdb_pointer = text_get_field (fontname, FOUNDRY); + argv[4].arg_type = PDB_STRING; + argv[4].value.pdb_pointer = text_get_field (fontname, FAMILY); + argv[5].arg_type = PDB_STRING; + argv[5].value.pdb_pointer = text_get_field (fontname, WEIGHT); + argv[6].arg_type = PDB_STRING; + argv[6].value.pdb_pointer = text_get_field (fontname, SLANT); + argv[7].arg_type = PDB_STRING; + argv[7].value.pdb_pointer = text_get_field (fontname, SET_WIDTH); + argv[8].arg_type = PDB_STRING; + argv[8].value.pdb_pointer = text_get_field (fontname, SPACING); + argv[9].arg_type = PDB_STRING; + argv[9].value.pdb_pointer = text_get_field (fontname, REGISTRY); + argv[10].arg_type = PDB_STRING; + argv[10].value.pdb_pointer = text_get_field (fontname, ENCODING); + + return text_tool_get_extents_invoker_ext (argv); +} + static Argument * text_tool_get_extents_invoker_ext (Argument *args) { diff --git a/app/tools/gimptexttool.h b/app/tools/gimptexttool.h index f9feb652b7..c4e82b1a44 100644 --- a/app/tools/gimptexttool.h +++ b/app/tools/gimptexttool.h @@ -27,7 +27,9 @@ void tools_free_text (Tool *); /* Procedure definition and marshalling function */ extern ProcRecord text_tool_proc; extern ProcRecord text_tool_proc_ext; +extern ProcRecord text_tool_proc_fontname; extern ProcRecord text_tool_get_extents_proc; extern ProcRecord text_tool_get_extents_proc_ext; +extern ProcRecord text_tool_get_extents_proc_fontname; #endif /* __TEXT_TOOL_H__ */ diff --git a/app/tools/text_tool.c b/app/tools/text_tool.c index e506073335..93442c81e9 100644 --- a/app/tools/text_tool.c +++ b/app/tools/text_tool.c @@ -159,10 +159,12 @@ static Layer * text_render (GImage *, GimpDrawable *, int, int, c static int font_compare_func (gpointer, gpointer); -static Argument * text_tool_invoker (Argument *); -static Argument * text_tool_invoker_ext (Argument *); -static Argument * text_tool_get_extents_invoker (Argument *); -static Argument * text_tool_get_extents_invoker_ext (Argument *); +static Argument * text_tool_invoker (Argument *); +static Argument * text_tool_invoker_ext (Argument *); +static Argument * text_tool_invoker_fontname (Argument *); +static Argument * text_tool_get_extents_invoker (Argument *); +static Argument * text_tool_get_extents_invoker_ext (Argument *); +static Argument * text_tool_get_extents_invoker_fontname (Argument *); static ActionAreaItem action_items[] = { @@ -2197,6 +2199,84 @@ ProcRecord text_tool_proc_ext = { { text_tool_invoker_ext } }, }; +/*************************************************/ +/* The text_tool_fontname procedure definition */ +ProcArg text_tool_args_fontname[] = +{ + { PDB_IMAGE, + "image", + "The image" + }, + { PDB_DRAWABLE, + "drawable", + "The affected drawable: (-1 for a new text layer)" + }, + { PDB_FLOAT, + "x", + "the x coordinate for the left side of text bounding box" + }, + { PDB_FLOAT, + "y", + "the y coordinate for the top of text bounding box" + }, + { PDB_STRING, + "text", + "the text to generate" + }, + { PDB_INT32, + "border", + "the size of the border: border >= 0" + }, + { PDB_INT32, + "antialias", + "generate antialiased text" + }, + { PDB_FLOAT, + "size", + "the size of text in either pixels or points" + }, + { PDB_INT32, + "size_type", + "the units of the specified size: { PIXELS (0), POINTS (1) }" + }, + { PDB_STRING, + "fontname", + "the fontname (conforming to the X Logical Font Description Conventions)" + } +}; + +ProcArg text_tool_out_args_fontname[] = +{ + { PDB_LAYER, + "text_layer", + "the new text layer" + } +}; + +ProcRecord text_tool_proc_fontname = +{ + "gimp_text_fontname", + "Add text at the specified location as a floating selection or a new layer.", + "This tool requires font information as a fontname conforming to the 'X Logical Font Description Conventions'. You can specify the fontsize in units of pixels or points, and the appropriate metric is specified using the size_type argument. The fontsize specified in the fontname is silently ignored." + "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 antialias parameter is non-zero, the generated text will blend more smoothly with underlying layers. " + "This option requires more time and memory to compute than non-antialiased text; the resulting floating selection or layer, however, will require the same amount of memory with or without antialiasing. 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.", + "Martin Edlman, Sven Neumann", + "Spencer Kimball & Peter Mattis", + "1998", + PDB_INTERNAL, + + /* Input arguments */ + 10, + text_tool_args_fontname, + + /* Output arguments */ + 1, + text_tool_out_args_fontname, + + /* Exec method */ + { { text_tool_invoker_fontname } }, +}; /**********************/ /* TEXT_GET_EXTENTS */ @@ -2375,6 +2455,70 @@ ProcRecord text_tool_get_extents_proc_ext = { { text_tool_get_extents_invoker_ext } }, }; +/*******************************/ +/* TEXT_GET_EXTENTS_FONTNAME */ +ProcArg text_tool_get_extents_args_fontname[] = +{ + { PDB_STRING, + "text", + "the text to generate" + }, + { PDB_FLOAT, + "size", + "the size of text in either pixels or points" + }, + { PDB_INT32, + "size_type", + "the units of the specified size: { PIXELS (0), POINTS (1) }" + }, + { PDB_STRING, + "fontname", + "the fontname (conforming to the X Logical Font Description Conventions)" + } +}; + +ProcArg text_tool_get_extents_out_args_fontname[] = +{ + { PDB_INT32, + "width", + "the width of the specified text" + }, + { PDB_INT32, + "height", + "the height of the specified text" + }, + { PDB_INT32, + "ascent", + "the ascent of the specified font" + }, + { PDB_INT32, + "descent", + "the descent of the specified font" + } +}; + +ProcRecord text_tool_get_extents_proc_fontname = +{ + "gimp_text_get_extents_fontname", + "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.", + "Martin Edlman, Sven Neumann", + "Spencer Kimball & Peter Mattis", + "1998", + PDB_INTERNAL, + + /* Input arguments */ + 4, + text_tool_get_extents_args_fontname, + + /* Output arguments */ + 4, + text_tool_get_extents_out_args_fontname, + + /* Exec method */ + { { text_tool_get_extents_invoker_fontname } }, +}; + static Argument * text_tool_invoker (Argument *args) @@ -2391,6 +2535,43 @@ text_tool_invoker (Argument *args) return text_tool_invoker_ext (argv); } +static Argument * +text_tool_invoker_fontname (Argument *args) +{ + int i; + char *fontname; + Argument argv[17]; + + for (i=0; i<9; i++) + argv[i] = args[i]; + + fontname = (char *) args[9].value.pdb_pointer; + + /* + Should check for a valid fontname here, probably using + if (!text_is_xlfd_font_name (fontname)) return + */ + + argv[9].arg_type = PDB_STRING; + argv[9].value.pdb_pointer = text_get_field (fontname, FOUNDRY); + argv[10].arg_type = PDB_STRING; + argv[10].value.pdb_pointer = text_get_field (fontname, FAMILY); + argv[11].arg_type = PDB_STRING; + argv[11].value.pdb_pointer = text_get_field (fontname, WEIGHT); + argv[12].arg_type = PDB_STRING; + argv[12].value.pdb_pointer = text_get_field (fontname, SLANT); + argv[13].arg_type = PDB_STRING; + argv[13].value.pdb_pointer = text_get_field (fontname, SET_WIDTH); + argv[14].arg_type = PDB_STRING; + argv[14].value.pdb_pointer = text_get_field (fontname, SPACING); + argv[15].arg_type = PDB_STRING; + argv[15].value.pdb_pointer = text_get_field (fontname, REGISTRY); + argv[16].arg_type = PDB_STRING; + argv[16].value.pdb_pointer = text_get_field (fontname, ENCODING); + + return text_tool_invoker_ext (argv); +} + static Argument * text_tool_invoker_ext (Argument *args) { @@ -2545,6 +2726,38 @@ text_tool_get_extents_invoker (Argument *args) return text_tool_get_extents_invoker_ext (argv); } +static Argument * +text_tool_get_extents_invoker_fontname (Argument *args) +{ + int i; + gchar *fontname; + Argument argv[17]; + + for (i=0; i<3; i++) + argv[i] = args[i]; + + fontname = args[3].value.pdb_pointer; + + argv[3].arg_type = PDB_STRING; + argv[3].value.pdb_pointer = text_get_field (fontname, FOUNDRY); + argv[4].arg_type = PDB_STRING; + argv[4].value.pdb_pointer = text_get_field (fontname, FAMILY); + argv[5].arg_type = PDB_STRING; + argv[5].value.pdb_pointer = text_get_field (fontname, WEIGHT); + argv[6].arg_type = PDB_STRING; + argv[6].value.pdb_pointer = text_get_field (fontname, SLANT); + argv[7].arg_type = PDB_STRING; + argv[7].value.pdb_pointer = text_get_field (fontname, SET_WIDTH); + argv[8].arg_type = PDB_STRING; + argv[8].value.pdb_pointer = text_get_field (fontname, SPACING); + argv[9].arg_type = PDB_STRING; + argv[9].value.pdb_pointer = text_get_field (fontname, REGISTRY); + argv[10].arg_type = PDB_STRING; + argv[10].value.pdb_pointer = text_get_field (fontname, ENCODING); + + return text_tool_get_extents_invoker_ext (argv); +} + static Argument * text_tool_get_extents_invoker_ext (Argument *args) { diff --git a/app/tools/text_tool.h b/app/tools/text_tool.h index f9feb652b7..c4e82b1a44 100644 --- a/app/tools/text_tool.h +++ b/app/tools/text_tool.h @@ -27,7 +27,9 @@ void tools_free_text (Tool *); /* Procedure definition and marshalling function */ extern ProcRecord text_tool_proc; extern ProcRecord text_tool_proc_ext; +extern ProcRecord text_tool_proc_fontname; extern ProcRecord text_tool_get_extents_proc; extern ProcRecord text_tool_get_extents_proc_ext; +extern ProcRecord text_tool_get_extents_proc_fontname; #endif /* __TEXT_TOOL_H__ */ diff --git a/plug-ins/script-fu/.cvsignore b/plug-ins/script-fu/.cvsignore index bb3ed850b9..df70a353e3 100644 --- a/plug-ins/script-fu/.cvsignore +++ b/plug-ins/script-fu/.cvsignore @@ -4,4 +4,3 @@ Makefile _libs .libs script-fu -convert-script diff --git a/plug-ins/script-fu/script-fu-enums.h b/plug-ins/script-fu/script-fu-enums.h index 4958b4bc7e..c70ae24e59 100644 --- a/plug-ins/script-fu/script-fu-enums.h +++ b/plug-ins/script-fu/script-fu-enums.h @@ -31,7 +31,8 @@ typedef enum SF_TOGGLE, SF_VALUE, SF_STRING, - SF_ADJUSTMENT + SF_ADJUSTMENT, + SF_FONT } SFArgType; typedef enum diff --git a/plug-ins/script-fu/script-fu-interface.c b/plug-ins/script-fu/script-fu-interface.c index 702427a3e0..6799dd04fc 100644 --- a/plug-ins/script-fu/script-fu-interface.c +++ b/plug-ins/script-fu/script-fu-interface.c @@ -21,6 +21,7 @@ #include #include #include +#include /* For toupper() */ #include "gtk/gtk.h" #include "libgimp/gimp.h" #include "libgimp/gimpui.h" @@ -34,6 +35,9 @@ #define SLIDER_WIDTH 100 #define SLIDER_HEIGHT 30 #define SPINNER_WIDTH 75 +#define FONT_PREVIEW_WIDTH 100 + +#define DEFAULT_FONT_SIZE 240 #define MAX_STRING_LENGTH 4096 @@ -57,6 +61,13 @@ typedef struct SFAdjustmentType type; } SFAdjustment; +typedef struct +{ + GtkWidget *preview; + GtkWidget *dialog; + gchar *fontname; +} SFFont; + typedef union { gint32 sfa_image; @@ -67,6 +78,7 @@ typedef union gint32 sfa_toggle; gchar * sfa_value; SFAdjustment sfa_adjustment; + SFFont sfa_font; } SFArgValue; typedef struct @@ -115,6 +127,8 @@ static void script_fu_disable_cc (gint err_msg); static void script_fu_interface (SFScript *script); static void script_fu_color_preview (GtkWidget *preview, gdouble *color); +static void script_fu_font_preview (GtkWidget *preview, + gchar *fontname); static void script_fu_cleanup_widgets (SFScript *script); static void script_fu_ok_callback (GtkWidget *widget, gpointer data); @@ -135,6 +149,15 @@ static void script_fu_color_preview_cancel (GtkWidget *widget, static gint script_fu_color_preview_delete (GtkWidget *widget, GdkEvent *event, gpointer data); +static void script_fu_font_preview_callback (GtkWidget *widget, + gpointer data); +static void script_fu_font_dialog_ok (GtkWidget *widget, + gpointer data); +static void script_fu_font_dialog_cancel (GtkWidget *widget, + gpointer data); +static gint script_fu_font_dialog_delete (GtkWidget *widget, + GdkEvent *event, + gpointer data); /* * Local variables @@ -459,7 +482,7 @@ script_fu_add_script (LISP a) args[i + 1].description = script->arg_labels[i]; break; - case SF_VALUE: + case SF_VALUE: if (!TYPEP (car (a), tc_string)) return my_err ("script-fu-register: value defaults must be string values", NIL); script->arg_defaults[i].sfa_value = g_strdup (get_c_string (car (a))); @@ -506,6 +529,21 @@ script_fu_add_script (LISP a) args[i + 1].description = script->arg_labels[i]; break; + case SF_FONT: + if (!TYPEP (car (a), tc_string)) + return my_err ("script-fu-register: font defaults must be string values", NIL); + script->arg_defaults[i].sfa_font.fontname = g_strdup (get_c_string (car (a))); + script->arg_values[i].sfa_font.fontname = g_strdup (script->arg_defaults[i].sfa_font.fontname); + script->arg_values[i].sfa_font.preview = NULL; + script->arg_values[i].sfa_font.dialog = NULL; + + args[i + 1].type = PARAM_STRING; + args[i + 1].name = "font"; + args[i + 1].description = script->arg_labels[i]; + break; + + break; + default: break; } @@ -651,6 +689,9 @@ script_fu_script_proc (char *name, case SF_ADJUSTMENT: length += strlen (params[i + 1].data.d_string) + 1; break; + case SF_FONT: + length += strlen (params[i + 1].data.d_string) + 3; + break; default: break; } @@ -693,6 +734,10 @@ script_fu_script_proc (char *name, case SF_ADJUSTMENT: text = params[i + 1].data.d_string; break; + case SF_FONT: + g_snprintf (buffer, MAX_STRING_LENGTH, "\"%s\"", params[i + 1].data.d_string); + text = buffer; + break; default: break; } @@ -776,12 +821,16 @@ script_fu_free_script (SFScript *script) case SF_COLOR: break; case SF_VALUE: - case SF_STRING: + case SF_STRING: g_free (script->arg_defaults[i].sfa_value); g_free (script->arg_values[i].sfa_value); break; case SF_ADJUSTMENT: break; + case SF_FONT: + g_free (script->arg_defaults[i].sfa_font.fontname); + g_free (script->arg_values[i].sfa_font.fontname); + break; default: break; } @@ -1011,21 +1060,35 @@ script_fu_interface (SFScript *script) default: /* this shouldn't happen */ script->args_widgets[i] = NULL; break; - } + } break; + case SF_FONT: + script->args_widgets[i] = gtk_button_new(); + script->arg_values[i].sfa_font.preview = gtk_label_new (""); + gtk_widget_set_usize (script->args_widgets[i], FONT_PREVIEW_WIDTH, 0); + gtk_container_add (GTK_CONTAINER (script->args_widgets[i]), + script->arg_values[i].sfa_font.preview); + gtk_widget_show (script->arg_values[i].sfa_font.preview); + script_fu_font_preview (script->arg_values[i].sfa_font.preview, + script->arg_values[i].sfa_font.fontname); + + gtk_signal_connect (GTK_OBJECT (script->args_widgets[i]), "clicked", + (GtkSignalFunc) script_fu_font_preview_callback, + &script->arg_values[i].sfa_font); + break; default: break; } hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), script->args_widgets[i], - ((script->arg_types[i] == SF_VALUE) || (script->arg_types[i] == SF_STRING)), - ((script->arg_types[i] == SF_VALUE) || (script->arg_types[i] == SF_STRING)), 0); + ((script->arg_types[i] == SF_VALUE) || (script->arg_types[i] == SF_STRING) || (script->arg_types[i] == SF_FONT)), + ((script->arg_types[i] == SF_VALUE) || (script->arg_types[i] == SF_STRING) || (script->arg_types[i] == SF_FONT)), 0); gtk_widget_show (hbox); gtk_table_attach (GTK_TABLE (table), hbox, /* script->args_widgets[i], */ 1, 2, i, i + 1, - GTK_FILL | (((script->arg_types[i] == SF_VALUE) || (script->arg_types[i] == SF_STRING)) + GTK_FILL | (((script->arg_types[i] == SF_VALUE) || (script->arg_types[i] == SF_STRING) || (script->arg_types[i] == SF_FONT)) ? GTK_EXPAND : 0), GTK_FILL, 4, 2); gtk_widget_show (script->args_widgets[i]); @@ -1105,6 +1168,44 @@ script_fu_color_preview (GtkWidget *preview, gtk_widget_draw (preview, NULL); } +static void +script_fu_font_preview (GtkWidget *preview, + gchar *data) +{ + GdkFont *font; + gchar *fontname; + gchar *family; + gchar *label; + + if (data == NULL) + return; + + fontname = g_strdup (data); + + /* Check if the fontname is valid and the font is present */ + font = gdk_font_load (fontname); + + if (font != NULL) + { + g_free (font); + + strtok (fontname, "-"); + family = strtok (NULL, "-"); + *family = toupper (*family); + + label = g_new (guchar, strlen (family) + 1); + sprintf (label, "%s", family); + gtk_label_set (GTK_LABEL (preview), label); + g_free (label); + } + else + { + gtk_label_set (GTK_LABEL (preview), "NOT SET"); + } + + g_free (fontname); +} + static void script_fu_cleanup_widgets (SFScript *script) { @@ -1120,6 +1221,13 @@ script_fu_cleanup_widgets (SFScript *script) script->arg_values[i].sfa_color.dialog = NULL; } break; + case SF_FONT: + if (script->arg_values[i].sfa_font.dialog != NULL) + { + gtk_widget_destroy (script->arg_values[i].sfa_font.dialog); + script->arg_values[i].sfa_font.dialog = NULL; + } + break; default: break; } @@ -1136,10 +1244,24 @@ script_fu_ok_callback (GtkWidget *widget, char buffer[MAX_STRING_LENGTH]; int length; int i; + GdkFont *font; if ((script = sf_interface.script) == NULL) return; + /* Check if choosen fonts are there */ + for (i = 0; i < script->num_args; i++) + if (script->arg_types[i] == SF_FONT) + { + font = gdk_font_load (script->arg_values[i].sfa_font.fontname); + if (font == NULL) + { + g_message (" At least one font you've choosen is invalid. \n Please check your settings.\n"); + return; + } + g_free (font); + } + length = strlen (script->script_name) + 3; for (i = 0; i < script->num_args; i++) @@ -1166,6 +1288,9 @@ script_fu_ok_callback (GtkWidget *widget, case SF_ADJUSTMENT: length += 24; /* Maximum size of float value should not exceed this many characters */ break; + case SF_FONT: + length += strlen (script->arg_values[i].sfa_font.fontname) + 3; + break; default: break; } @@ -1224,6 +1349,10 @@ script_fu_ok_callback (GtkWidget *widget, break; } break; + case SF_FONT: + g_snprintf (buffer, MAX_STRING_LENGTH, "\"%s\"", script->arg_values[i].sfa_font.fontname); + text = buffer; + break; default: break; } @@ -1297,7 +1426,6 @@ script_fu_reset_callback (GtkWidget *widget, case SF_STRING: g_free (script->arg_values[i].sfa_value); script->arg_values[i].sfa_value = g_strdup (script->arg_defaults[i].sfa_value); - gtk_entry_set_text (GTK_ENTRY (script->args_widgets[i]), script->arg_values[i].sfa_value); break; @@ -1306,6 +1434,16 @@ script_fu_reset_callback (GtkWidget *widget, gtk_adjustment_set_value (script->arg_values[i].sfa_adjustment.adj, script->arg_values[i].sfa_adjustment.value); break; + case SF_FONT: + g_free (script->arg_values[i].sfa_font.fontname); + script->arg_values[i].sfa_font.fontname = g_strdup (script->arg_defaults[i].sfa_font.fontname); + if (script->arg_values[i].sfa_font.dialog) + { + gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (script->arg_values[i].sfa_font.dialog), script->arg_values[i].sfa_font.fontname); + } + script_fu_font_preview (script->arg_values[i].sfa_font.preview, + script->arg_values[i].sfa_font.fontname); + break; default: break; } @@ -1332,6 +1470,7 @@ script_fu_toggle_update (GtkWidget *widget, *toggle_val = FALSE; } + static void script_fu_color_preview_callback (GtkWidget *widget, gpointer data) @@ -1415,3 +1554,79 @@ script_fu_color_preview_delete (GtkWidget *widget, script_fu_color_preview_cancel (widget, data); return TRUE; } + +static void +script_fu_font_preview_callback (GtkWidget *widget, + gpointer data) +{ + GtkFontSelectionDialog *fsd; + SFFont *font; + + font = (SFFont *) data; + + if (!font->dialog) + { + font->dialog = gtk_font_selection_dialog_new ("Script-Fu Font Selector"); + fsd = GTK_FONT_SELECTION_DIALOG (font->dialog); + + gtk_signal_connect (GTK_OBJECT (fsd->ok_button), "clicked", + (GtkSignalFunc) script_fu_font_dialog_ok, + font); + gtk_signal_connect (GTK_OBJECT (fsd), "delete_event", + (GtkSignalFunc) script_fu_font_dialog_delete, + font); + gtk_signal_connect (GTK_OBJECT (fsd->cancel_button), "clicked", + (GtkSignalFunc) script_fu_font_dialog_cancel, + font); + + } + else + fsd = GTK_FONT_SELECTION_DIALOG (font->dialog); + + gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (fsd), + font->fontname); + gtk_window_position (GTK_WINDOW (font->dialog), GTK_WIN_POS_MOUSE); + gtk_widget_show (font->dialog); +} + +static void +script_fu_font_dialog_ok (GtkWidget *widget, + gpointer data) +{ + SFFont *font; + gchar *fontname; + + font = (SFFont *) data; + + + fontname = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (font->dialog)); + if (fontname != NULL) + { + g_free (font->fontname); + font->fontname = fontname; + } + gtk_widget_hide(font->dialog); + + script_fu_font_preview (font->preview, font->fontname); +} + +static void +script_fu_font_dialog_cancel (GtkWidget *widget, + gpointer data) +{ + SFFont *font; + + font = (SFFont *) data; + + gtk_widget_hide(font->dialog); + gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (font->dialog), font->fontname); +} + +static gint +script_fu_font_dialog_delete (GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + script_fu_font_dialog_cancel (widget, data); + return TRUE; +} diff --git a/plug-ins/script-fu/script-fu-scripts.c b/plug-ins/script-fu/script-fu-scripts.c index 702427a3e0..6799dd04fc 100644 --- a/plug-ins/script-fu/script-fu-scripts.c +++ b/plug-ins/script-fu/script-fu-scripts.c @@ -21,6 +21,7 @@ #include #include #include +#include /* For toupper() */ #include "gtk/gtk.h" #include "libgimp/gimp.h" #include "libgimp/gimpui.h" @@ -34,6 +35,9 @@ #define SLIDER_WIDTH 100 #define SLIDER_HEIGHT 30 #define SPINNER_WIDTH 75 +#define FONT_PREVIEW_WIDTH 100 + +#define DEFAULT_FONT_SIZE 240 #define MAX_STRING_LENGTH 4096 @@ -57,6 +61,13 @@ typedef struct SFAdjustmentType type; } SFAdjustment; +typedef struct +{ + GtkWidget *preview; + GtkWidget *dialog; + gchar *fontname; +} SFFont; + typedef union { gint32 sfa_image; @@ -67,6 +78,7 @@ typedef union gint32 sfa_toggle; gchar * sfa_value; SFAdjustment sfa_adjustment; + SFFont sfa_font; } SFArgValue; typedef struct @@ -115,6 +127,8 @@ static void script_fu_disable_cc (gint err_msg); static void script_fu_interface (SFScript *script); static void script_fu_color_preview (GtkWidget *preview, gdouble *color); +static void script_fu_font_preview (GtkWidget *preview, + gchar *fontname); static void script_fu_cleanup_widgets (SFScript *script); static void script_fu_ok_callback (GtkWidget *widget, gpointer data); @@ -135,6 +149,15 @@ static void script_fu_color_preview_cancel (GtkWidget *widget, static gint script_fu_color_preview_delete (GtkWidget *widget, GdkEvent *event, gpointer data); +static void script_fu_font_preview_callback (GtkWidget *widget, + gpointer data); +static void script_fu_font_dialog_ok (GtkWidget *widget, + gpointer data); +static void script_fu_font_dialog_cancel (GtkWidget *widget, + gpointer data); +static gint script_fu_font_dialog_delete (GtkWidget *widget, + GdkEvent *event, + gpointer data); /* * Local variables @@ -459,7 +482,7 @@ script_fu_add_script (LISP a) args[i + 1].description = script->arg_labels[i]; break; - case SF_VALUE: + case SF_VALUE: if (!TYPEP (car (a), tc_string)) return my_err ("script-fu-register: value defaults must be string values", NIL); script->arg_defaults[i].sfa_value = g_strdup (get_c_string (car (a))); @@ -506,6 +529,21 @@ script_fu_add_script (LISP a) args[i + 1].description = script->arg_labels[i]; break; + case SF_FONT: + if (!TYPEP (car (a), tc_string)) + return my_err ("script-fu-register: font defaults must be string values", NIL); + script->arg_defaults[i].sfa_font.fontname = g_strdup (get_c_string (car (a))); + script->arg_values[i].sfa_font.fontname = g_strdup (script->arg_defaults[i].sfa_font.fontname); + script->arg_values[i].sfa_font.preview = NULL; + script->arg_values[i].sfa_font.dialog = NULL; + + args[i + 1].type = PARAM_STRING; + args[i + 1].name = "font"; + args[i + 1].description = script->arg_labels[i]; + break; + + break; + default: break; } @@ -651,6 +689,9 @@ script_fu_script_proc (char *name, case SF_ADJUSTMENT: length += strlen (params[i + 1].data.d_string) + 1; break; + case SF_FONT: + length += strlen (params[i + 1].data.d_string) + 3; + break; default: break; } @@ -693,6 +734,10 @@ script_fu_script_proc (char *name, case SF_ADJUSTMENT: text = params[i + 1].data.d_string; break; + case SF_FONT: + g_snprintf (buffer, MAX_STRING_LENGTH, "\"%s\"", params[i + 1].data.d_string); + text = buffer; + break; default: break; } @@ -776,12 +821,16 @@ script_fu_free_script (SFScript *script) case SF_COLOR: break; case SF_VALUE: - case SF_STRING: + case SF_STRING: g_free (script->arg_defaults[i].sfa_value); g_free (script->arg_values[i].sfa_value); break; case SF_ADJUSTMENT: break; + case SF_FONT: + g_free (script->arg_defaults[i].sfa_font.fontname); + g_free (script->arg_values[i].sfa_font.fontname); + break; default: break; } @@ -1011,21 +1060,35 @@ script_fu_interface (SFScript *script) default: /* this shouldn't happen */ script->args_widgets[i] = NULL; break; - } + } break; + case SF_FONT: + script->args_widgets[i] = gtk_button_new(); + script->arg_values[i].sfa_font.preview = gtk_label_new (""); + gtk_widget_set_usize (script->args_widgets[i], FONT_PREVIEW_WIDTH, 0); + gtk_container_add (GTK_CONTAINER (script->args_widgets[i]), + script->arg_values[i].sfa_font.preview); + gtk_widget_show (script->arg_values[i].sfa_font.preview); + script_fu_font_preview (script->arg_values[i].sfa_font.preview, + script->arg_values[i].sfa_font.fontname); + + gtk_signal_connect (GTK_OBJECT (script->args_widgets[i]), "clicked", + (GtkSignalFunc) script_fu_font_preview_callback, + &script->arg_values[i].sfa_font); + break; default: break; } hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), script->args_widgets[i], - ((script->arg_types[i] == SF_VALUE) || (script->arg_types[i] == SF_STRING)), - ((script->arg_types[i] == SF_VALUE) || (script->arg_types[i] == SF_STRING)), 0); + ((script->arg_types[i] == SF_VALUE) || (script->arg_types[i] == SF_STRING) || (script->arg_types[i] == SF_FONT)), + ((script->arg_types[i] == SF_VALUE) || (script->arg_types[i] == SF_STRING) || (script->arg_types[i] == SF_FONT)), 0); gtk_widget_show (hbox); gtk_table_attach (GTK_TABLE (table), hbox, /* script->args_widgets[i], */ 1, 2, i, i + 1, - GTK_FILL | (((script->arg_types[i] == SF_VALUE) || (script->arg_types[i] == SF_STRING)) + GTK_FILL | (((script->arg_types[i] == SF_VALUE) || (script->arg_types[i] == SF_STRING) || (script->arg_types[i] == SF_FONT)) ? GTK_EXPAND : 0), GTK_FILL, 4, 2); gtk_widget_show (script->args_widgets[i]); @@ -1105,6 +1168,44 @@ script_fu_color_preview (GtkWidget *preview, gtk_widget_draw (preview, NULL); } +static void +script_fu_font_preview (GtkWidget *preview, + gchar *data) +{ + GdkFont *font; + gchar *fontname; + gchar *family; + gchar *label; + + if (data == NULL) + return; + + fontname = g_strdup (data); + + /* Check if the fontname is valid and the font is present */ + font = gdk_font_load (fontname); + + if (font != NULL) + { + g_free (font); + + strtok (fontname, "-"); + family = strtok (NULL, "-"); + *family = toupper (*family); + + label = g_new (guchar, strlen (family) + 1); + sprintf (label, "%s", family); + gtk_label_set (GTK_LABEL (preview), label); + g_free (label); + } + else + { + gtk_label_set (GTK_LABEL (preview), "NOT SET"); + } + + g_free (fontname); +} + static void script_fu_cleanup_widgets (SFScript *script) { @@ -1120,6 +1221,13 @@ script_fu_cleanup_widgets (SFScript *script) script->arg_values[i].sfa_color.dialog = NULL; } break; + case SF_FONT: + if (script->arg_values[i].sfa_font.dialog != NULL) + { + gtk_widget_destroy (script->arg_values[i].sfa_font.dialog); + script->arg_values[i].sfa_font.dialog = NULL; + } + break; default: break; } @@ -1136,10 +1244,24 @@ script_fu_ok_callback (GtkWidget *widget, char buffer[MAX_STRING_LENGTH]; int length; int i; + GdkFont *font; if ((script = sf_interface.script) == NULL) return; + /* Check if choosen fonts are there */ + for (i = 0; i < script->num_args; i++) + if (script->arg_types[i] == SF_FONT) + { + font = gdk_font_load (script->arg_values[i].sfa_font.fontname); + if (font == NULL) + { + g_message (" At least one font you've choosen is invalid. \n Please check your settings.\n"); + return; + } + g_free (font); + } + length = strlen (script->script_name) + 3; for (i = 0; i < script->num_args; i++) @@ -1166,6 +1288,9 @@ script_fu_ok_callback (GtkWidget *widget, case SF_ADJUSTMENT: length += 24; /* Maximum size of float value should not exceed this many characters */ break; + case SF_FONT: + length += strlen (script->arg_values[i].sfa_font.fontname) + 3; + break; default: break; } @@ -1224,6 +1349,10 @@ script_fu_ok_callback (GtkWidget *widget, break; } break; + case SF_FONT: + g_snprintf (buffer, MAX_STRING_LENGTH, "\"%s\"", script->arg_values[i].sfa_font.fontname); + text = buffer; + break; default: break; } @@ -1297,7 +1426,6 @@ script_fu_reset_callback (GtkWidget *widget, case SF_STRING: g_free (script->arg_values[i].sfa_value); script->arg_values[i].sfa_value = g_strdup (script->arg_defaults[i].sfa_value); - gtk_entry_set_text (GTK_ENTRY (script->args_widgets[i]), script->arg_values[i].sfa_value); break; @@ -1306,6 +1434,16 @@ script_fu_reset_callback (GtkWidget *widget, gtk_adjustment_set_value (script->arg_values[i].sfa_adjustment.adj, script->arg_values[i].sfa_adjustment.value); break; + case SF_FONT: + g_free (script->arg_values[i].sfa_font.fontname); + script->arg_values[i].sfa_font.fontname = g_strdup (script->arg_defaults[i].sfa_font.fontname); + if (script->arg_values[i].sfa_font.dialog) + { + gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (script->arg_values[i].sfa_font.dialog), script->arg_values[i].sfa_font.fontname); + } + script_fu_font_preview (script->arg_values[i].sfa_font.preview, + script->arg_values[i].sfa_font.fontname); + break; default: break; } @@ -1332,6 +1470,7 @@ script_fu_toggle_update (GtkWidget *widget, *toggle_val = FALSE; } + static void script_fu_color_preview_callback (GtkWidget *widget, gpointer data) @@ -1415,3 +1554,79 @@ script_fu_color_preview_delete (GtkWidget *widget, script_fu_color_preview_cancel (widget, data); return TRUE; } + +static void +script_fu_font_preview_callback (GtkWidget *widget, + gpointer data) +{ + GtkFontSelectionDialog *fsd; + SFFont *font; + + font = (SFFont *) data; + + if (!font->dialog) + { + font->dialog = gtk_font_selection_dialog_new ("Script-Fu Font Selector"); + fsd = GTK_FONT_SELECTION_DIALOG (font->dialog); + + gtk_signal_connect (GTK_OBJECT (fsd->ok_button), "clicked", + (GtkSignalFunc) script_fu_font_dialog_ok, + font); + gtk_signal_connect (GTK_OBJECT (fsd), "delete_event", + (GtkSignalFunc) script_fu_font_dialog_delete, + font); + gtk_signal_connect (GTK_OBJECT (fsd->cancel_button), "clicked", + (GtkSignalFunc) script_fu_font_dialog_cancel, + font); + + } + else + fsd = GTK_FONT_SELECTION_DIALOG (font->dialog); + + gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (fsd), + font->fontname); + gtk_window_position (GTK_WINDOW (font->dialog), GTK_WIN_POS_MOUSE); + gtk_widget_show (font->dialog); +} + +static void +script_fu_font_dialog_ok (GtkWidget *widget, + gpointer data) +{ + SFFont *font; + gchar *fontname; + + font = (SFFont *) data; + + + fontname = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (font->dialog)); + if (fontname != NULL) + { + g_free (font->fontname); + font->fontname = fontname; + } + gtk_widget_hide(font->dialog); + + script_fu_font_preview (font->preview, font->fontname); +} + +static void +script_fu_font_dialog_cancel (GtkWidget *widget, + gpointer data) +{ + SFFont *font; + + font = (SFFont *) data; + + gtk_widget_hide(font->dialog); + gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (font->dialog), font->fontname); +} + +static gint +script_fu_font_dialog_delete (GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + script_fu_font_dialog_cancel (widget, data); + return TRUE; +} diff --git a/plug-ins/script-fu/script-fu.c b/plug-ins/script-fu/script-fu.c index 1d71d57071..3be6477337 100644 --- a/plug-ins/script-fu/script-fu.c +++ b/plug-ins/script-fu/script-fu.c @@ -448,6 +448,7 @@ init_constants () setvar (cintern ("SF-VALUE"), flocons (SF_VALUE), NIL); setvar (cintern ("SF-STRING"), flocons (SF_STRING), NIL); setvar (cintern ("SF-ADJUSTMENT"), flocons (SF_ADJUSTMENT), NIL); + setvar (cintern ("SF-FONT"), flocons (SF_FONT), NIL); /* for SF_ADJUSTMENT */ setvar (cintern ("SF-SLIDER"), flocons (SF_SLIDER), NIL); diff --git a/plug-ins/script-fu/scripts/test-sphere.scm b/plug-ins/script-fu/scripts/test-sphere.scm index 483af3ce91..fbb2062526 100644 --- a/plug-ins/script-fu/scripts/test-sphere.scm +++ b/plug-ins/script-fu/scripts/test-sphere.scm @@ -1,16 +1,36 @@ ; This is a slightly modified copy of the sphere script to show and test ; the possibilities of the new Script-Fu API extensions. ; -; SF-ADJUSTMENT is only useful in interactive mode, if you call a script from +; ---------------------------------------------------------------------- +; SF-ADJUSTMENT +; is only useful in interactive mode, if you call a script from ; the console, it acts just like a normal SF-VALUE ; In interactive mode it creates an adjustment widget in the dialog. ; ; Usage: ; SF-ADJUSTMENT "label" '(value, lower, upper, step_inc, page_inc, digits, type) ; -; type is one of: SLIDER(0), SPINNER(1) +; type is one of: SF-SLIDER(0), SF-SPINNER(1) +; ---------------------------------------------------------------------- +; SF-FONT +; creates a font-selection widget in the dialog. It returns a fontname as +; a string. There are two new gimp-text procedures to ease the use of this +; return parameter: ; -(define (script-fu-test-sphere radius light shadow bg-color sphere-color) +; (gimp-text-fontname image drawable x-pos y-pos text border antialias size unit font) +; (gimp-text-get-extents-fontname text size unit font)) +; +; where font is the fontname you get. The size specified in the fontname +; is silently ignored. It is only used in the font-selector. So you are asked to +; set it to a useful value (24 pixels is a good choice) when using SF-FONT. +; +; Usage: +; SF-FONT "label" "fontname" +; ---------------------------------------------------------------------- + + +; +(define (script-fu-test-sphere radius light shadow bg-color sphere-color text font size) (let* ((width (* radius 3.75)) (height (* radius 2.5)) (img (car (gimp-image-new width height RGB))) @@ -23,6 +43,9 @@ (light-end-x (+ cx (* radius (cos (+ *pi* radians))))) (light-end-y (- cy (* radius (sin (+ *pi* radians))))) (offset (* radius 0.1)) + (text-extents (gimp-text-get-extents-fontname text size PIXELS font)) + (x-position (- cx (/ (car text-extents) 2))) + (y-position (- cy (/ (cadr text-extents) 2))) (old-fg (car (gimp-palette-get-foreground))) (old-bg (car (gimp-palette-get-background)))) (gimp-image-disable-undo img) @@ -47,6 +70,15 @@ (gimp-blend img drawable FG-BG-RGB NORMAL RADIAL 100 offset REPEAT-NONE FALSE 0 0 light-x light-y light-end-x light-end-y) (gimp-selection-none img) + + (gimp-palette-set-foreground '(0 0 0)) + (gimp-floating-sel-anchor (car (gimp-text-fontname img drawable + x-position y-position + text + 0 TRUE + size PIXELS + font))) + (gimp-palette-set-background old-bg) (gimp-palette-set-foreground old-fg) (gimp-image-enable-undo img) @@ -54,13 +86,18 @@ (script-fu-register "script-fu-test-sphere" "/Xtns/Script-Fu/Test/Sphere" - "Simple spheres with drop shadows" + "Simple script to test and show the usage of the new Script-Fu API extensions" + "Spencer Kimball, Sven Neumann" "Spencer Kimball" - "Spencer Kimball" - "1996" + "1996, 1998" "" SF-ADJUSTMENT "Radius (in pixels)" '(100 1 5000 1 10 0 1) SF-ADJUSTMENT "Lighting (degrees)" '(45 0 360 1 10 1 0) SF-TOGGLE "Shadow" TRUE SF-COLOR "Background Color" '(255 255 255) - SF-COLOR "Sphere Color" '(255 0 0)) + SF-COLOR "Sphere Color" '(255 0 0) + SF-STRING "Text" "Script-Fu rocks!" + SF-FONT "Font" "-freefont-agate-normal-r-normal-*-24-*-*-*-p-*-*-*" + SF-ADJUSTMENT "Font size (in pixels)" '(50 1 1000 1 10 0 1)) + +