Fonts: render-sfont22.scm

File render-sfont22.scm, 3.5 KB (added by jordi, 4 years ago)

Mike Oliphan's script for GIMP to generate SFont font bitmaps.

Line 
1;
2; SFont Renderer
3;
4; Render a font to be used with the SFont library
5;
6; Written by Mike Oliphant (http://nostatic.org)
7; Based on other logo examples that came with the gimp
8;
9
10(define (apply-create-sfont-effect img
11                                   logo-layer
12                                   top-color
13                                   bottom-color
14                                   do-bumpmap)
15  (let* ((width (car (gimp-drawable-width logo-layer)))
16         (height (car (gimp-drawable-height logo-layer)))
17         (shadow-layer (car (gimp-layer-new img width height RGBA-IMAGE "Shadow" 100 MULTIPLY)))
18         (old-fg (car (gimp-palette-get-foreground)))
19         (old-bg (car (gimp-palette-get-background))))
20    (gimp-selection-none img)
21                                        ;    (script-fu-util-image-resize-from-layer img logo-layer)
22    (gimp-image-resize img width height 0 0)
23    (gimp-image-add-layer img shadow-layer 1)
24    (gimp-palette-set-foreground '(0 0 0))
25    (gimp-layer-set-preserve-trans logo-layer 100)
26    (gimp-edit-fill logo-layer FOREGROUND-FILL)
27    (gimp-edit-clear shadow-layer)
28    (gimp-selection-layer-alpha logo-layer)
29    (gimp-context-set-background '(0 0 0))
30    (gimp-selection-grow img 1)
31    (gimp-edit-fill shadow-layer BACKGROUND-FILL)
32    (gimp-selection-none img)
33    (gimp-context-set-foreground top-color)
34    (gimp-context-set-background bottom-color)
35    (gimp-edit-blend logo-layer FG-BG-RGB-MODE NORMAL-MODE GRADIENT-LINEAR 100 20 REPEAT-NONE FALSE FALSE 0 0 FALSE (/ width 2) 0 (/ width 2) height)
36
37    (gimp-layer-set-preserve-trans logo-layer 0)
38
39    (if (= do-bumpmap TRUE)
40        (plug-in-bump-map 1 img logo-layer logo-layer 115 40 1 0 0 0 15
41                          TRUE FALSE 0))
42
43    (gimp-context-set-background old-bg)
44    (gimp-context-set-foreground old-fg)))
45
46(define (script-fu-render-sfont size
47                                font
48                                top-color
49                                bottom-color
50                                do-bumpmap)
51  (let* ((text "! \" # $ % & ' ( ) * + , - . / 0 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 [ \\ ] ^ _ ` 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 { | } ~")
52         (img (car (gimp-image-new 256 256 RGB)))
53         (extents (gimp-text-get-extents-fontname text size PIXELS font))
54         (descent (cadr (cddr extents)))
55         (text-layer (car (gimp-text-fontname img -1 0 0 text 2 TRUE size PIXELS font)))
56         (width (car (gimp-drawable-width text-layer)))
57         (height (car (gimp-drawable-height text-layer))))
58    (gimp-image-undo-disable img)
59    (gimp-layer-set-name text-layer "font")
60    (gimp-layer-resize text-layer width (+ height descent) 0 descent)
61    (gimp-layer-set-offsets text-layer 0 0)
62    (apply-create-sfont-effect img text-layer top-color bottom-color
63                               do-bumpmap)
64    (gimp-image-undo-enable img)
65    (gimp-display-new img)))
66
67(script-fu-register "script-fu-render-sfont"
68                    _"<Toolbox>/Xtns/Script-Fu/SFont/Create SFont"
69                    "Creates font for use with the SFont library"
70                    "Mike Oliphant"
71                    "Mike Oliphant"
72                    "2004"
73                    ""
74                    SF-ADJUSTMENT _"Font Size (pixels)" '(28 2 1000 1 10 0 1)
75                    SF-FONT       _"Font" "Sans"
76                    SF-COLOR      _"Top Color" '(16 23 229)
77                    SF-COLOR      _"Bottom Color" '(156 241 244)
78                    SF-TOGGLE     _"Apply 3D effect" TRUE)