[gimp] plug-ins: fix script-fu-font-map error receiving GStrv



commit 5e9c92c5de39d777f804ba3014d08c23d7e3ee10
Author: lloyd konneker <konnekerl gmail com>
Date:   Sat May 7 15:10:42 2022 -0400

    plug-ins: fix script-fu-font-map error receiving GStrv
    
    Why: MR !389 changed the signature of PDB procedures to return GStrv instead of (int, GimpStringArray)
    This changes handling of results from a call to such a changed signature, in a Scheme script.
    
    The symptom was a cryptic TinyScheme "Error: car: argument 1 must be : pair"
    
    Most changed procedures are named like "-list".
    I did a cursory grep to look for other instances.
    
    Updated porting guide doc.

 .../porting_scriptfu_scripts.md                         | 17 +++++++++++++++++
 plug-ins/script-fu/scripts/font-map.scm                 | 17 +++++++++++++----
 2 files changed, 30 insertions(+), 4 deletions(-)
---
diff --git a/devel-docs/GIMP3-plug-in-porting-guide/porting_scriptfu_scripts.md 
b/devel-docs/GIMP3-plug-in-porting-guide/porting_scriptfu_scripts.md
index 8907059784..741c407637 100644
--- a/devel-docs/GIMP3-plug-in-porting-guide/porting_scriptfu_scripts.md
+++ b/devel-docs/GIMP3-plug-in-porting-guide/porting_scriptfu_scripts.md
@@ -28,6 +28,8 @@ This table summarizes the changes:
 | pass drawable  | GimpDrawable          | gint, GimpObjectArray | int   (an ID)   | int (a length) vector |
 | Pass obj array | gint, GimpInt32Array  | gint, GimpObjectArray | int  vector     | int vector            |
 | Recv obj array | gint, GimpInt32Array  | gint, GimpObjectArray | int  vector     | int vector            |
+| Pass set of str | gint, GimpStringArray | GStrv                 | int  list       | list                  |
+| Recv set of str | gint, GimpStringArray | GStrv                 | int  list       | list                  |
 
 (Where "obj" means an object of a GIMP type such as GimpDrawable or similar.)
 
@@ -123,6 +125,21 @@ would print:
 Meaning a list length of zero, and an empty vector.
 (Since a new image has no layers.)
 
+### Passing or receiving a set of strings
+
+Formerly, you passed an integer count of strings, and a list of strings.
+Now you only pass the list.
+ScriptFu converts to/from the C type GStrv
+(which is an object knowing its own length.)
+An example is the PDB procedure file-gih-save.
+
+Formerly, you received an integer count of strings, and a list of strings.
+Now you only receive the list
+(and subsequently get its length using "(length list)").
+Examples are the many PDB procedures whose name ends in "-list".
+Remember that the result of a call to the PDB is a list of values,
+in this case the result is a list containing a list,
+and for example you get the list of strings like "(car (gimp-fonts-get-list ".*"))"
 
 ## Changes in error messages
 
diff --git a/plug-ins/script-fu/scripts/font-map.scm b/plug-ins/script-fu/scripts/font-map.scm
index 7481d28892..b3b64fe4b1 100644
--- a/plug-ins/script-fu/scripts/font-map.scm
+++ b/plug-ins/script-fu/scripts/font-map.scm
@@ -1,6 +1,14 @@
-;; font-select
+;; font-map
 ;; Spencer Kimball
 
+;; To test, open the Font tool dialog,
+;; press right mouse button in the list of fonts, choose "Render Font Map"
+
+;; Test cases for font filter regex
+;;   ".*"  expect render all installed fonts
+;;   "foo" expect render blank image (no matching fonts)
+;;   "Sans" expect render subset of installed fonts
+
 (define (script-fu-font-map text
                             use-name
                             labels
@@ -64,9 +72,10 @@
   )
 
   (let* (
-        (font-data  (gimp-fonts-get-list font-filter))
-        (font-list  (cadr font-data))
-        (num-fonts  (car font-data))
+        ; gimp-fonts-get-list returns a one element list of results,
+        ; the only element is itself a list of fonts, possibly empty.
+        (font-list  (car (gimp-fonts-get-list font-filter)))
+        (num-fonts  (length font-list))
         (label-size (/ font-size 2))
         (border     (+ border (* labels (/ label-size 2))))
         (y          border)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]