Finally a font-selector.

--Sven
This commit is contained in:
Sven Neumann 1998-08-10 15:06:58 +00:00
parent 0c686e0288
commit 7422ae2e03
14 changed files with 1162 additions and 35 deletions

View File

@ -1,3 +1,15 @@
Mon Aug 10 16:20:33 MEST 1998 Sven Neumann <sven@gimp.org>
* 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 <sven@gimp.org> Sun Aug 9 14:15:42 MEST 1998 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/script-fu-scripts.c: The scripf-fu dialog * plug-ins/script-fu/script-fu-scripts.c: The scripf-fu dialog

View File

@ -106,8 +106,10 @@ internal_procs_init ()
procedural_db_register (&shear_proc); pcount++; procedural_db_register (&shear_proc); pcount++;
procedural_db_register (&text_tool_proc); pcount++; procedural_db_register (&text_tool_proc); pcount++;
procedural_db_register (&text_tool_proc_ext); 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); pcount++;
procedural_db_register (&text_tool_get_extents_proc_ext); 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", app_init_update_status(NULL, "GDisplay procedures",
pcount/total_pcount); pcount/total_pcount);

View File

@ -159,10 +159,12 @@ static Layer * text_render (GImage *, GimpDrawable *, int, int, c
static int font_compare_func (gpointer, gpointer); static int font_compare_func (gpointer, gpointer);
static Argument * text_tool_invoker (Argument *); static Argument * text_tool_invoker (Argument *);
static Argument * text_tool_invoker_ext (Argument *); static Argument * text_tool_invoker_ext (Argument *);
static Argument * text_tool_get_extents_invoker (Argument *); static Argument * text_tool_invoker_fontname (Argument *);
static Argument * text_tool_get_extents_invoker_ext (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[] = static ActionAreaItem action_items[] =
{ {
@ -2197,6 +2199,84 @@ ProcRecord text_tool_proc_ext =
{ { text_tool_invoker_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 */ /* TEXT_GET_EXTENTS */
@ -2375,6 +2455,70 @@ ProcRecord text_tool_get_extents_proc_ext =
{ { text_tool_get_extents_invoker_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 * static Argument *
text_tool_invoker (Argument *args) text_tool_invoker (Argument *args)
@ -2391,6 +2535,43 @@ text_tool_invoker (Argument *args)
return text_tool_invoker_ext (argv); 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 * static Argument *
text_tool_invoker_ext (Argument *args) 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); 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 * static Argument *
text_tool_get_extents_invoker_ext (Argument *args) text_tool_get_extents_invoker_ext (Argument *args)
{ {

View File

@ -27,7 +27,9 @@ void tools_free_text (Tool *);
/* Procedure definition and marshalling function */ /* Procedure definition and marshalling function */
extern ProcRecord text_tool_proc; extern ProcRecord text_tool_proc;
extern ProcRecord text_tool_proc_ext; 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;
extern ProcRecord text_tool_get_extents_proc_ext; extern ProcRecord text_tool_get_extents_proc_ext;
extern ProcRecord text_tool_get_extents_proc_fontname;
#endif /* __TEXT_TOOL_H__ */ #endif /* __TEXT_TOOL_H__ */

View File

@ -159,10 +159,12 @@ static Layer * text_render (GImage *, GimpDrawable *, int, int, c
static int font_compare_func (gpointer, gpointer); static int font_compare_func (gpointer, gpointer);
static Argument * text_tool_invoker (Argument *); static Argument * text_tool_invoker (Argument *);
static Argument * text_tool_invoker_ext (Argument *); static Argument * text_tool_invoker_ext (Argument *);
static Argument * text_tool_get_extents_invoker (Argument *); static Argument * text_tool_invoker_fontname (Argument *);
static Argument * text_tool_get_extents_invoker_ext (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[] = static ActionAreaItem action_items[] =
{ {
@ -2197,6 +2199,84 @@ ProcRecord text_tool_proc_ext =
{ { text_tool_invoker_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 */ /* TEXT_GET_EXTENTS */
@ -2375,6 +2455,70 @@ ProcRecord text_tool_get_extents_proc_ext =
{ { text_tool_get_extents_invoker_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 * static Argument *
text_tool_invoker (Argument *args) text_tool_invoker (Argument *args)
@ -2391,6 +2535,43 @@ text_tool_invoker (Argument *args)
return text_tool_invoker_ext (argv); 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 * static Argument *
text_tool_invoker_ext (Argument *args) 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); 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 * static Argument *
text_tool_get_extents_invoker_ext (Argument *args) text_tool_get_extents_invoker_ext (Argument *args)
{ {

View File

@ -27,7 +27,9 @@ void tools_free_text (Tool *);
/* Procedure definition and marshalling function */ /* Procedure definition and marshalling function */
extern ProcRecord text_tool_proc; extern ProcRecord text_tool_proc;
extern ProcRecord text_tool_proc_ext; 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;
extern ProcRecord text_tool_get_extents_proc_ext; extern ProcRecord text_tool_get_extents_proc_ext;
extern ProcRecord text_tool_get_extents_proc_fontname;
#endif /* __TEXT_TOOL_H__ */ #endif /* __TEXT_TOOL_H__ */

View File

@ -159,10 +159,12 @@ static Layer * text_render (GImage *, GimpDrawable *, int, int, c
static int font_compare_func (gpointer, gpointer); static int font_compare_func (gpointer, gpointer);
static Argument * text_tool_invoker (Argument *); static Argument * text_tool_invoker (Argument *);
static Argument * text_tool_invoker_ext (Argument *); static Argument * text_tool_invoker_ext (Argument *);
static Argument * text_tool_get_extents_invoker (Argument *); static Argument * text_tool_invoker_fontname (Argument *);
static Argument * text_tool_get_extents_invoker_ext (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[] = static ActionAreaItem action_items[] =
{ {
@ -2197,6 +2199,84 @@ ProcRecord text_tool_proc_ext =
{ { text_tool_invoker_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 */ /* TEXT_GET_EXTENTS */
@ -2375,6 +2455,70 @@ ProcRecord text_tool_get_extents_proc_ext =
{ { text_tool_get_extents_invoker_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 * static Argument *
text_tool_invoker (Argument *args) text_tool_invoker (Argument *args)
@ -2391,6 +2535,43 @@ text_tool_invoker (Argument *args)
return text_tool_invoker_ext (argv); 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 * static Argument *
text_tool_invoker_ext (Argument *args) 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); 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 * static Argument *
text_tool_get_extents_invoker_ext (Argument *args) text_tool_get_extents_invoker_ext (Argument *args)
{ {

View File

@ -27,7 +27,9 @@ void tools_free_text (Tool *);
/* Procedure definition and marshalling function */ /* Procedure definition and marshalling function */
extern ProcRecord text_tool_proc; extern ProcRecord text_tool_proc;
extern ProcRecord text_tool_proc_ext; 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;
extern ProcRecord text_tool_get_extents_proc_ext; extern ProcRecord text_tool_get_extents_proc_ext;
extern ProcRecord text_tool_get_extents_proc_fontname;
#endif /* __TEXT_TOOL_H__ */ #endif /* __TEXT_TOOL_H__ */

View File

@ -4,4 +4,3 @@ Makefile
_libs _libs
.libs .libs
script-fu script-fu
convert-script

View File

@ -31,7 +31,8 @@ typedef enum
SF_TOGGLE, SF_TOGGLE,
SF_VALUE, SF_VALUE,
SF_STRING, SF_STRING,
SF_ADJUSTMENT SF_ADJUSTMENT,
SF_FONT
} SFArgType; } SFArgType;
typedef enum typedef enum

View File

@ -21,6 +21,7 @@
#include <string.h> #include <string.h>
#include <dirent.h> #include <dirent.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <ctype.h> /* For toupper() */
#include "gtk/gtk.h" #include "gtk/gtk.h"
#include "libgimp/gimp.h" #include "libgimp/gimp.h"
#include "libgimp/gimpui.h" #include "libgimp/gimpui.h"
@ -34,6 +35,9 @@
#define SLIDER_WIDTH 100 #define SLIDER_WIDTH 100
#define SLIDER_HEIGHT 30 #define SLIDER_HEIGHT 30
#define SPINNER_WIDTH 75 #define SPINNER_WIDTH 75
#define FONT_PREVIEW_WIDTH 100
#define DEFAULT_FONT_SIZE 240
#define MAX_STRING_LENGTH 4096 #define MAX_STRING_LENGTH 4096
@ -57,6 +61,13 @@ typedef struct
SFAdjustmentType type; SFAdjustmentType type;
} SFAdjustment; } SFAdjustment;
typedef struct
{
GtkWidget *preview;
GtkWidget *dialog;
gchar *fontname;
} SFFont;
typedef union typedef union
{ {
gint32 sfa_image; gint32 sfa_image;
@ -67,6 +78,7 @@ typedef union
gint32 sfa_toggle; gint32 sfa_toggle;
gchar * sfa_value; gchar * sfa_value;
SFAdjustment sfa_adjustment; SFAdjustment sfa_adjustment;
SFFont sfa_font;
} SFArgValue; } SFArgValue;
typedef struct 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_interface (SFScript *script);
static void script_fu_color_preview (GtkWidget *preview, static void script_fu_color_preview (GtkWidget *preview,
gdouble *color); gdouble *color);
static void script_fu_font_preview (GtkWidget *preview,
gchar *fontname);
static void script_fu_cleanup_widgets (SFScript *script); static void script_fu_cleanup_widgets (SFScript *script);
static void script_fu_ok_callback (GtkWidget *widget, static void script_fu_ok_callback (GtkWidget *widget,
gpointer data); gpointer data);
@ -135,6 +149,15 @@ static void script_fu_color_preview_cancel (GtkWidget *widget,
static gint script_fu_color_preview_delete (GtkWidget *widget, static gint script_fu_color_preview_delete (GtkWidget *widget,
GdkEvent *event, GdkEvent *event,
gpointer data); 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 * Local variables
@ -459,7 +482,7 @@ script_fu_add_script (LISP a)
args[i + 1].description = script->arg_labels[i]; args[i + 1].description = script->arg_labels[i];
break; break;
case SF_VALUE: case SF_VALUE:
if (!TYPEP (car (a), tc_string)) if (!TYPEP (car (a), tc_string))
return my_err ("script-fu-register: value defaults must be string values", NIL); 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))); 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]; args[i + 1].description = script->arg_labels[i];
break; 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: default:
break; break;
} }
@ -651,6 +689,9 @@ script_fu_script_proc (char *name,
case SF_ADJUSTMENT: case SF_ADJUSTMENT:
length += strlen (params[i + 1].data.d_string) + 1; length += strlen (params[i + 1].data.d_string) + 1;
break; break;
case SF_FONT:
length += strlen (params[i + 1].data.d_string) + 3;
break;
default: default:
break; break;
} }
@ -693,6 +734,10 @@ script_fu_script_proc (char *name,
case SF_ADJUSTMENT: case SF_ADJUSTMENT:
text = params[i + 1].data.d_string; text = params[i + 1].data.d_string;
break; break;
case SF_FONT:
g_snprintf (buffer, MAX_STRING_LENGTH, "\"%s\"", params[i + 1].data.d_string);
text = buffer;
break;
default: default:
break; break;
} }
@ -776,12 +821,16 @@ script_fu_free_script (SFScript *script)
case SF_COLOR: case SF_COLOR:
break; break;
case SF_VALUE: case SF_VALUE:
case SF_STRING: case SF_STRING:
g_free (script->arg_defaults[i].sfa_value); g_free (script->arg_defaults[i].sfa_value);
g_free (script->arg_values[i].sfa_value); g_free (script->arg_values[i].sfa_value);
break; break;
case SF_ADJUSTMENT: case SF_ADJUSTMENT:
break; break;
case SF_FONT:
g_free (script->arg_defaults[i].sfa_font.fontname);
g_free (script->arg_values[i].sfa_font.fontname);
break;
default: default:
break; break;
} }
@ -1011,21 +1060,35 @@ script_fu_interface (SFScript *script)
default: /* this shouldn't happen */ default: /* this shouldn't happen */
script->args_widgets[i] = NULL; script->args_widgets[i] = NULL;
break; break;
} }
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: default:
break; break;
} }
hbox = gtk_hbox_new (FALSE, 0); hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), script->args_widgets[i], 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) || (script->arg_types[i] == SF_FONT)),
((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)), 0);
gtk_widget_show (hbox); gtk_widget_show (hbox);
gtk_table_attach (GTK_TABLE (table), hbox, /* script->args_widgets[i], */ gtk_table_attach (GTK_TABLE (table), hbox, /* script->args_widgets[i], */
1, 2, i, i + 1, 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_EXPAND : 0),
GTK_FILL, 4, 2); GTK_FILL, 4, 2);
gtk_widget_show (script->args_widgets[i]); gtk_widget_show (script->args_widgets[i]);
@ -1105,6 +1168,44 @@ script_fu_color_preview (GtkWidget *preview,
gtk_widget_draw (preview, NULL); 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 static void
script_fu_cleanup_widgets (SFScript *script) script_fu_cleanup_widgets (SFScript *script)
{ {
@ -1120,6 +1221,13 @@ script_fu_cleanup_widgets (SFScript *script)
script->arg_values[i].sfa_color.dialog = NULL; script->arg_values[i].sfa_color.dialog = NULL;
} }
break; 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: default:
break; break;
} }
@ -1136,10 +1244,24 @@ script_fu_ok_callback (GtkWidget *widget,
char buffer[MAX_STRING_LENGTH]; char buffer[MAX_STRING_LENGTH];
int length; int length;
int i; int i;
GdkFont *font;
if ((script = sf_interface.script) == NULL) if ((script = sf_interface.script) == NULL)
return; 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; length = strlen (script->script_name) + 3;
for (i = 0; i < script->num_args; i++) for (i = 0; i < script->num_args; i++)
@ -1166,6 +1288,9 @@ script_fu_ok_callback (GtkWidget *widget,
case SF_ADJUSTMENT: case SF_ADJUSTMENT:
length += 24; /* Maximum size of float value should not exceed this many characters */ length += 24; /* Maximum size of float value should not exceed this many characters */
break; break;
case SF_FONT:
length += strlen (script->arg_values[i].sfa_font.fontname) + 3;
break;
default: default:
break; break;
} }
@ -1224,6 +1349,10 @@ script_fu_ok_callback (GtkWidget *widget,
break; break;
} }
break; break;
case SF_FONT:
g_snprintf (buffer, MAX_STRING_LENGTH, "\"%s\"", script->arg_values[i].sfa_font.fontname);
text = buffer;
break;
default: default:
break; break;
} }
@ -1297,7 +1426,6 @@ script_fu_reset_callback (GtkWidget *widget,
case SF_STRING: case SF_STRING:
g_free (script->arg_values[i].sfa_value); g_free (script->arg_values[i].sfa_value);
script->arg_values[i].sfa_value = g_strdup (script->arg_defaults[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]), gtk_entry_set_text (GTK_ENTRY (script->args_widgets[i]),
script->arg_values[i].sfa_value); script->arg_values[i].sfa_value);
break; break;
@ -1306,6 +1434,16 @@ script_fu_reset_callback (GtkWidget *widget,
gtk_adjustment_set_value (script->arg_values[i].sfa_adjustment.adj, gtk_adjustment_set_value (script->arg_values[i].sfa_adjustment.adj,
script->arg_values[i].sfa_adjustment.value); script->arg_values[i].sfa_adjustment.value);
break; 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: default:
break; break;
} }
@ -1332,6 +1470,7 @@ script_fu_toggle_update (GtkWidget *widget,
*toggle_val = FALSE; *toggle_val = FALSE;
} }
static void static void
script_fu_color_preview_callback (GtkWidget *widget, script_fu_color_preview_callback (GtkWidget *widget,
gpointer data) gpointer data)
@ -1415,3 +1554,79 @@ script_fu_color_preview_delete (GtkWidget *widget,
script_fu_color_preview_cancel (widget, data); script_fu_color_preview_cancel (widget, data);
return TRUE; 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;
}

View File

@ -21,6 +21,7 @@
#include <string.h> #include <string.h>
#include <dirent.h> #include <dirent.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <ctype.h> /* For toupper() */
#include "gtk/gtk.h" #include "gtk/gtk.h"
#include "libgimp/gimp.h" #include "libgimp/gimp.h"
#include "libgimp/gimpui.h" #include "libgimp/gimpui.h"
@ -34,6 +35,9 @@
#define SLIDER_WIDTH 100 #define SLIDER_WIDTH 100
#define SLIDER_HEIGHT 30 #define SLIDER_HEIGHT 30
#define SPINNER_WIDTH 75 #define SPINNER_WIDTH 75
#define FONT_PREVIEW_WIDTH 100
#define DEFAULT_FONT_SIZE 240
#define MAX_STRING_LENGTH 4096 #define MAX_STRING_LENGTH 4096
@ -57,6 +61,13 @@ typedef struct
SFAdjustmentType type; SFAdjustmentType type;
} SFAdjustment; } SFAdjustment;
typedef struct
{
GtkWidget *preview;
GtkWidget *dialog;
gchar *fontname;
} SFFont;
typedef union typedef union
{ {
gint32 sfa_image; gint32 sfa_image;
@ -67,6 +78,7 @@ typedef union
gint32 sfa_toggle; gint32 sfa_toggle;
gchar * sfa_value; gchar * sfa_value;
SFAdjustment sfa_adjustment; SFAdjustment sfa_adjustment;
SFFont sfa_font;
} SFArgValue; } SFArgValue;
typedef struct 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_interface (SFScript *script);
static void script_fu_color_preview (GtkWidget *preview, static void script_fu_color_preview (GtkWidget *preview,
gdouble *color); gdouble *color);
static void script_fu_font_preview (GtkWidget *preview,
gchar *fontname);
static void script_fu_cleanup_widgets (SFScript *script); static void script_fu_cleanup_widgets (SFScript *script);
static void script_fu_ok_callback (GtkWidget *widget, static void script_fu_ok_callback (GtkWidget *widget,
gpointer data); gpointer data);
@ -135,6 +149,15 @@ static void script_fu_color_preview_cancel (GtkWidget *widget,
static gint script_fu_color_preview_delete (GtkWidget *widget, static gint script_fu_color_preview_delete (GtkWidget *widget,
GdkEvent *event, GdkEvent *event,
gpointer data); 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 * Local variables
@ -459,7 +482,7 @@ script_fu_add_script (LISP a)
args[i + 1].description = script->arg_labels[i]; args[i + 1].description = script->arg_labels[i];
break; break;
case SF_VALUE: case SF_VALUE:
if (!TYPEP (car (a), tc_string)) if (!TYPEP (car (a), tc_string))
return my_err ("script-fu-register: value defaults must be string values", NIL); 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))); 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]; args[i + 1].description = script->arg_labels[i];
break; 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: default:
break; break;
} }
@ -651,6 +689,9 @@ script_fu_script_proc (char *name,
case SF_ADJUSTMENT: case SF_ADJUSTMENT:
length += strlen (params[i + 1].data.d_string) + 1; length += strlen (params[i + 1].data.d_string) + 1;
break; break;
case SF_FONT:
length += strlen (params[i + 1].data.d_string) + 3;
break;
default: default:
break; break;
} }
@ -693,6 +734,10 @@ script_fu_script_proc (char *name,
case SF_ADJUSTMENT: case SF_ADJUSTMENT:
text = params[i + 1].data.d_string; text = params[i + 1].data.d_string;
break; break;
case SF_FONT:
g_snprintf (buffer, MAX_STRING_LENGTH, "\"%s\"", params[i + 1].data.d_string);
text = buffer;
break;
default: default:
break; break;
} }
@ -776,12 +821,16 @@ script_fu_free_script (SFScript *script)
case SF_COLOR: case SF_COLOR:
break; break;
case SF_VALUE: case SF_VALUE:
case SF_STRING: case SF_STRING:
g_free (script->arg_defaults[i].sfa_value); g_free (script->arg_defaults[i].sfa_value);
g_free (script->arg_values[i].sfa_value); g_free (script->arg_values[i].sfa_value);
break; break;
case SF_ADJUSTMENT: case SF_ADJUSTMENT:
break; break;
case SF_FONT:
g_free (script->arg_defaults[i].sfa_font.fontname);
g_free (script->arg_values[i].sfa_font.fontname);
break;
default: default:
break; break;
} }
@ -1011,21 +1060,35 @@ script_fu_interface (SFScript *script)
default: /* this shouldn't happen */ default: /* this shouldn't happen */
script->args_widgets[i] = NULL; script->args_widgets[i] = NULL;
break; break;
} }
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: default:
break; break;
} }
hbox = gtk_hbox_new (FALSE, 0); hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), script->args_widgets[i], 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) || (script->arg_types[i] == SF_FONT)),
((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)), 0);
gtk_widget_show (hbox); gtk_widget_show (hbox);
gtk_table_attach (GTK_TABLE (table), hbox, /* script->args_widgets[i], */ gtk_table_attach (GTK_TABLE (table), hbox, /* script->args_widgets[i], */
1, 2, i, i + 1, 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_EXPAND : 0),
GTK_FILL, 4, 2); GTK_FILL, 4, 2);
gtk_widget_show (script->args_widgets[i]); gtk_widget_show (script->args_widgets[i]);
@ -1105,6 +1168,44 @@ script_fu_color_preview (GtkWidget *preview,
gtk_widget_draw (preview, NULL); 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 static void
script_fu_cleanup_widgets (SFScript *script) script_fu_cleanup_widgets (SFScript *script)
{ {
@ -1120,6 +1221,13 @@ script_fu_cleanup_widgets (SFScript *script)
script->arg_values[i].sfa_color.dialog = NULL; script->arg_values[i].sfa_color.dialog = NULL;
} }
break; 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: default:
break; break;
} }
@ -1136,10 +1244,24 @@ script_fu_ok_callback (GtkWidget *widget,
char buffer[MAX_STRING_LENGTH]; char buffer[MAX_STRING_LENGTH];
int length; int length;
int i; int i;
GdkFont *font;
if ((script = sf_interface.script) == NULL) if ((script = sf_interface.script) == NULL)
return; 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; length = strlen (script->script_name) + 3;
for (i = 0; i < script->num_args; i++) for (i = 0; i < script->num_args; i++)
@ -1166,6 +1288,9 @@ script_fu_ok_callback (GtkWidget *widget,
case SF_ADJUSTMENT: case SF_ADJUSTMENT:
length += 24; /* Maximum size of float value should not exceed this many characters */ length += 24; /* Maximum size of float value should not exceed this many characters */
break; break;
case SF_FONT:
length += strlen (script->arg_values[i].sfa_font.fontname) + 3;
break;
default: default:
break; break;
} }
@ -1224,6 +1349,10 @@ script_fu_ok_callback (GtkWidget *widget,
break; break;
} }
break; break;
case SF_FONT:
g_snprintf (buffer, MAX_STRING_LENGTH, "\"%s\"", script->arg_values[i].sfa_font.fontname);
text = buffer;
break;
default: default:
break; break;
} }
@ -1297,7 +1426,6 @@ script_fu_reset_callback (GtkWidget *widget,
case SF_STRING: case SF_STRING:
g_free (script->arg_values[i].sfa_value); g_free (script->arg_values[i].sfa_value);
script->arg_values[i].sfa_value = g_strdup (script->arg_defaults[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]), gtk_entry_set_text (GTK_ENTRY (script->args_widgets[i]),
script->arg_values[i].sfa_value); script->arg_values[i].sfa_value);
break; break;
@ -1306,6 +1434,16 @@ script_fu_reset_callback (GtkWidget *widget,
gtk_adjustment_set_value (script->arg_values[i].sfa_adjustment.adj, gtk_adjustment_set_value (script->arg_values[i].sfa_adjustment.adj,
script->arg_values[i].sfa_adjustment.value); script->arg_values[i].sfa_adjustment.value);
break; 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: default:
break; break;
} }
@ -1332,6 +1470,7 @@ script_fu_toggle_update (GtkWidget *widget,
*toggle_val = FALSE; *toggle_val = FALSE;
} }
static void static void
script_fu_color_preview_callback (GtkWidget *widget, script_fu_color_preview_callback (GtkWidget *widget,
gpointer data) gpointer data)
@ -1415,3 +1554,79 @@ script_fu_color_preview_delete (GtkWidget *widget,
script_fu_color_preview_cancel (widget, data); script_fu_color_preview_cancel (widget, data);
return TRUE; 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;
}

View File

@ -448,6 +448,7 @@ init_constants ()
setvar (cintern ("SF-VALUE"), flocons (SF_VALUE), NIL); setvar (cintern ("SF-VALUE"), flocons (SF_VALUE), NIL);
setvar (cintern ("SF-STRING"), flocons (SF_STRING), NIL); setvar (cintern ("SF-STRING"), flocons (SF_STRING), NIL);
setvar (cintern ("SF-ADJUSTMENT"), flocons (SF_ADJUSTMENT), NIL); setvar (cintern ("SF-ADJUSTMENT"), flocons (SF_ADJUSTMENT), NIL);
setvar (cintern ("SF-FONT"), flocons (SF_FONT), NIL);
/* for SF_ADJUSTMENT */ /* for SF_ADJUSTMENT */
setvar (cintern ("SF-SLIDER"), flocons (SF_SLIDER), NIL); setvar (cintern ("SF-SLIDER"), flocons (SF_SLIDER), NIL);

View File

@ -1,16 +1,36 @@
; This is a slightly modified copy of the sphere script to show and test ; This is a slightly modified copy of the sphere script to show and test
; the possibilities of the new Script-Fu API extensions. ; 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 ; the console, it acts just like a normal SF-VALUE
; In interactive mode it creates an adjustment widget in the dialog. ; In interactive mode it creates an adjustment widget in the dialog.
; ;
; Usage: ; Usage:
; SF-ADJUSTMENT "label" '(value, lower, upper, step_inc, page_inc, digits, type) ; 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)) (let* ((width (* radius 3.75))
(height (* radius 2.5)) (height (* radius 2.5))
(img (car (gimp-image-new width height RGB))) (img (car (gimp-image-new width height RGB)))
@ -23,6 +43,9 @@
(light-end-x (+ cx (* radius (cos (+ *pi* radians))))) (light-end-x (+ cx (* radius (cos (+ *pi* radians)))))
(light-end-y (- cy (* radius (sin (+ *pi* radians))))) (light-end-y (- cy (* radius (sin (+ *pi* radians)))))
(offset (* radius 0.1)) (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-fg (car (gimp-palette-get-foreground)))
(old-bg (car (gimp-palette-get-background)))) (old-bg (car (gimp-palette-get-background))))
(gimp-image-disable-undo img) (gimp-image-disable-undo img)
@ -47,6 +70,15 @@
(gimp-blend img drawable FG-BG-RGB NORMAL RADIAL 100 offset REPEAT-NONE (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) FALSE 0 0 light-x light-y light-end-x light-end-y)
(gimp-selection-none img) (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-background old-bg)
(gimp-palette-set-foreground old-fg) (gimp-palette-set-foreground old-fg)
(gimp-image-enable-undo img) (gimp-image-enable-undo img)
@ -54,13 +86,18 @@
(script-fu-register "script-fu-test-sphere" (script-fu-register "script-fu-test-sphere"
"<Toolbox>/Xtns/Script-Fu/Test/Sphere" "<Toolbox>/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"
"Spencer Kimball" "1996, 1998"
"1996"
"" ""
SF-ADJUSTMENT "Radius (in pixels)" '(100 1 5000 1 10 0 1) SF-ADJUSTMENT "Radius (in pixels)" '(100 1 5000 1 10 0 1)
SF-ADJUSTMENT "Lighting (degrees)" '(45 0 360 1 10 1 0) SF-ADJUSTMENT "Lighting (degrees)" '(45 0 360 1 10 1 0)
SF-TOGGLE "Shadow" TRUE SF-TOGGLE "Shadow" TRUE
SF-COLOR "Background Color" '(255 255 255) 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))