samj wrote:
Any suggestion faster than my new script running Gimp would be appreciated.
One way to speed up your script is to disable UNDO for the new image -- you are currently using 'gimp-undo-push-group-*'. The only thing that performing undo would accomplish on a
new image is take you back to an empty image. This is not worthwhile (you'll notice that all of the images created under "File->Create" menu have empty undo histories).
When you use gimp-undo-push, every operation you perform that modifies the image requires an additional step to save that operation in the UNDO history. By disabling UNDO, these additional steps are avoided. How much speed is gained by this depends upon what your script is doing.
I have been looking at your script and think you might also benefit by using lists and vectors to hold all of your car_### variables. Script-fu does not using any fancy symbol lookups for local variables (the theory being that you will typically only have a few) and so when you have hundreds of local variables (such as car_0 through car_188), it might have to traverse the entire list of variable assignments every time it needs to find or change a variable's value. (Script-fu does optimize lookups for global variables, since there can be expected to be thousands of those.)
By using lists for your car_### strings, you can use 'map' and 'apply' which will simplify some of your code (though maybe not improve its speed much). You can then convert the lists to vectors and use 'vector-ref' which I suspect would be faster than your current approach which requires linear searches of local variable bindings.
Here is some of the re-working of your code that I have done. It should give you an idea of what I mean (of course, the 'define' statements would be replaced with 'let' statements). I haven't reached the part of your code that actually places the characters, but it looks as though converting 'car_set' and the 'hauteur' and 'largeur' lists from lists to vectors would address what you are doing. If you decide to take this approach, be aware that I have used a string comprising the space character (" ") instead of the empty string ("") in 'car_set'; though I treat the space as an empty string when computing its width and height.
I normally wouldn't post such incomplete code but I probably won't be able to do anything further with it until after the holiday.
(define car_set
(case rendu
((1) (map (lambda (ch) (string (integer->char ch)))
(string->list (string-append
"w12346789abcdmefghilnkzv5jw12346789abcdmefghilnkzv5jw12346789ab"
"cdmefghilnkzv5jw12346789abcdmefghilnkzv5jw12346789abcdmefghilnk"
"zv5jw12346789abcdmefghilnkzv5jw12346789abcdmefghilnkzv5jw123467" ))))
((2) (map (lambda (ch) (string (integer->char ch)))
'(#x21 #x22 #x23 #x24 #x25 #x26 #x27 #x28 #x29 #x2a #x2b #x2c #x2d
#x2e #x2f #x30 #x31 #x32 #x33 #x34 #x35 #x36 #x37 #x38 #x39 #x3a
#x3b #x3c #x3d #x3e #x3f #x40 #x41 #x42 #x43 #x44 #x45 #x46 #x47
#x48 #x49 #x4a #x4b #x4c #x4d #x4e #x4f #x50 #x51 #x52 #x53 #x54
#x55 #x56 #x57 #x58 #x59 #x5a #x5b #x5c #x5d #x5e #x5f #x60 #x61
#x62 #x63 #x64 #x65 #x66 #x67 #x68 #x69 #x6a #x6b #x6c #x6d #x6e
#x6f #x70 #x71 #x72 #x73 #x74 #x75 #x76 #x77 #x78 #x79 #x7a #x7b
#x7c #x7d #x7e #x387 #x20AC #xB2 #xDB #xF4 #xCE #xCA #xB0 #x2248
#xF7 #x2321 #x2320 #x2265 #x2264 #xB1 #x2261 #x2252 #x3B5 #x3C6
#x221E #x3B4 #x3A9 #x3B8 #x3D5 #x3C4 #x3BC #x3C3 #x3A3 #x3C0
#x3B3 #x3B2 #x3B1 #xBB #xAB #xA1 #xBC #xBD #xAC #xD4 #xBF #xBA
#xAAA #xD1 #xF1 #xFA #xF3 #xED #xE1 #xAE #xC2 #xA5 #xA3 #xA2
#xDC #xD6 #xFF #xF9 #xFB #xF2 #xF6 #x25B6 #xC6 #xE6 #xC9 #xC5
#xC4 #xEC #xEE #xEF #xE8 #xEB #xEA #xE7 #xE5 #xE0 #xE4 #xE2
#xE9 #xFC #xC7 #x387 #x221A #x3A9r #x3F4 #x387 #x76 #x77 #x78
#x79 #x7a #x7b #x7c #x7d #x7e #x21 )))
((3) (map (lambda (ch) (string (integer->char ch)))
'(#x21 #x22 #x23 #x24 #x25 #x26 #x27 #x28 #x29 #x2a #x2b #x2c #x2d
#x2e #x2f #x30 #x31 #x32 #x33 #x34 #x35 #x36 #x37 #x38 #x39 #x3a
#x3b #x3c #x3d #x3e #x3f #x40 #x41 #x42 #x43 #x44 #x45 #x46 #x47
#x48 #x49 #x4a #x4b #x4c #x4d #x4e #x4f #x50 #x51 #x52 #x53 #x54
#x55 #x56 #x57 #x58 #x59 #x5a #x5b #x5c #x5d #x5e #x5f #x60 #x61
#x62 #x63 #x64 #x65 #x66 #x67 #x68 #x69 #x6a #x6b #x6c #x6d #x6e
#x6f #x70 #x71 #x72 #x73 #x74 #x75 #x76 #x77 #x78 #x79 #x7a #x7b
#x7c #x7d #x7e #xc2a1 #xc2a2 #xc2a3 #xc2a4 #xc2a5 #xc2a6 #xc2a7
#xc2a8 #xc2a9 #xc2aa #xc2ab #xc2ac #xc2ad #xc2ae #xc2af #xc2b0
#xc2b1 #xc2b2 #xc2b3 #xc2b4 #xc2b5 #xc2b6 #xc2b7 #xc2b8 #xc2b9
#xc2ba #xc2bb #xc2bc #xc2bd #xc2be #xc2bf #xc380 #xc381 #xc382
#xc383 #xc384 #xc385 #xc386 #xc387 #xc388 #xc389 #xc38a #xc38b
#xc38c #xc38d #xc38e #xc38f #xc390 #xc391 #xc392 #xc393 #xc394
#xc395 #xc396 #xc397 #xc398 #xc399 #xc39a #xc39b #xc39c #xc39d
#xc39e #xc39f #xc3a0 #xc3a1 #xc3a2 #xc3a3 #xc3a4 #xc3a5 #xc3a6
#xc3a7 #xc3a8 #xc3a9 #xc3aa #xc3ab #xc3ac #xc3ad #xc3ae #xc3af
#xc3b0 #xc3b1 #xc3b2 #xc3b3 #xc3b4 #xc3b5 #xc3b6 #xc3b7 #xc3b8
#xc3b9 #xc3ba #xc3bb #xc3bc #xc3bd #xc3be #xc3bf )))
((4) (reverse (map string (string->list (string-append
" $ : ; < = > ? [ \\ ] ^_ `{ | } ~ a b c d e f g h i j k l m n o"
" p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 @ A B C D E F G H I J"
" K L M N O P Q R S T U V W X Y Z : ; < = > ? [ \\ ] ^_ `{ | } ~ $ ")))))
((5) (map string (string->list (string-append
" $ : ; < = > ? [ \\ ] ^_ `{ | } ~ a b c d e f g h i j k l m n o"
" p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 @ A B C D E F G H I J K"
" L M N O P Q R S T U V W X Y Z : ; < = > ? [ \\ ] ^_ `{ | } ~ $ " ))))))
(define sizes (map (lambda (c)
(gimp-text-get-extents-fontname (if (string=? c " ") "" c)
Taille_Police
PIXELS
Police ))
car_set ))
(define largeurs (map car sizes))
(define hauteurs (map cadr sizes))
(define max_largeur_dans_car_set (apply max largeurs))
(define max_hauteur_dans_car_set (apply max hauteurs))
(define sizes (map (lambda (c)
(gimp-text-get-extents-fontname c
Taille_Police
PIXELS
Police ))
(map string (string->list La_Phrase)) ))
(define largeurs_dans_la_phrase (map car sizes))
(define hauteurs_dans_la_phrase (map cadr sizes))
(define max_largeur_dans_la_phrase (apply max largeurs_dans_la_phrase))
(define max_hauteur_dans_la_phrase (apply max hauteurs-dans-la-phrase))