2.99 ScriptFu: enhance: ignore default for declared resource arguments
This is part of ongoing enhancement/debugging of Resource on libgimp side.
Description of the problem
A script declaring an arg of SF-FONT (etc.) no longer works.
SF-FONT "Font to render" "Sans"
"Sans" purports to be a default. When run interactively, the font chooser widget doesn't show the intended initial font, but rather, the font in context. And if the user doesn't choose a font, the script fails.
Prior work in !1080 (merged) was incomplete; it fixed ScriptFu's binding of resource objects in calls to/from the PDB, but not the binding of these defaults. ScriptFu is saving the defaults as strings, and passing strings where int ID's are required.
If the name does not match an existing font, there are other errors.
Reproduction
Test case:
- Choose Filters>Dev>SF>Test>Sphere...
Expect: the dialog shows without gimp messages or warnings to stderr.
- Choose the OK button
Expect a sphere to be rendered, and text in the font in context.
Actual:
gimp-message Calling error for procedure 'gimp-resource-get-by-name':
Font 'Agate' not found
and
scriptfu-Message: 10:21:18.984: Error while executing script-fu-test-sphere:
Error: Procedure execution of gimp-text-get-extents-font failed on invalid input arguments: Procedure 'gimp-text-get-extents-font' has been called with value '<not transformable to string>' for argument 'font' (#3, type GimpFont). This value is out of range.
Test case:
Click RMB in the Fonts dockable and choose Render Font Map
scriptfu-Message: 12:15:35.567: Error while executing script-fu-font-map:
Error: in script, expected type: integer for argument 3 to gimp-text-get-extents-font
Proposed fix
In ScriptFu v3, in the declaration of a script's args of type Resource, the third term, that names a default, will be ignored. This term formerly set the initial choice in a chooser widget. Now the initial choice in the widget will be the resource in context.
This is a slight decrease in capability. A user can still get the script's effect using any specific resource, but they might now need an extra step to choose the specific resource that formerly was a default. For example, the contact sheet plugin, when the user made no choice in the font chooser widget, formerly would render text in say "Sans", the default font specified by the script, but now might render text in whatever font is in the current context.
The format of the arg spec in ScriptFu still requires a third term. But the third term will be ignored, and its type not checked. This is similar to the defaults for SF-IMAGE, where you usually see -1 as the third term.
Note especially that the third term for SF-BRUSH was formerly required to be a list. Now the third term will not be required to be a list. Any script that needs one of the things defaulted in the list (say opacity) will need to be revised to have a new argument for opacity. The brush chooser widget will now return only a brush, without other attributes such as opacity. Any attributes of the brush will need to be queried by the script.
Discussion
Alternatively, we could retain the current capability.
But this is a low priority capability. There are only three, infrequently used scripts in the repo that use args of type Resource, all font.
Also, plugins in other languages do not easily have the same capability (naming a default resource to be shown in the chooser widget.) IOW, it just dumbs down ScriptFu to the same level as plugins in other languages.
Also, there seem to be technical impediments. At plugin registration time, before a plugin is created, you can't call PDB procedures needed to get a resource object by name.
The decision to ignore defaults in arg specs of resource args is not irreversible: we can restore it later.
Some of the fix will be in the SF interface, which eventually may become deprecated (in favor of using GimpProcedureDialog.) The considerations are similar for both Test>Sphere and Test>Sphere 3 test plugins.